-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Moore] Add AssignedVarOp and a graph region for SVModule.
- Loading branch information
1 parent
d360917
commit 843f558
Showing
9 changed files
with
141 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
add_circt_dialect_library(CIRCTMooreTransforms | ||
LowerConcatRef.cpp | ||
MergeAssignments.cpp | ||
SimplifyProcedures.cpp | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
//===- MergeAssignments.cpp - Merge declaration and assignment ------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file defines the MergeAssignments pass. | ||
// Find easy uses of declaration and assignments and merge them into | ||
// assigned_variable. Easy use represents the declaration doesn't be performed | ||
// bit slice. Like bit [127:0] b; assign b = 128'b0; | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "circt/Dialect/Moore/MooreOps.h" | ||
#include "circt/Dialect/Moore/MoorePasses.h" | ||
#include "mlir/IR/Dialect.h" | ||
#include "llvm/ADT/TypeSwitch.h" | ||
|
||
namespace circt { | ||
namespace moore { | ||
#define GEN_PASS_DEF_MERGEASSIGNMENTS | ||
#include "circt/Dialect/Moore/MoorePasses.h.inc" | ||
} // namespace moore | ||
} // namespace circt | ||
|
||
using namespace circt; | ||
using namespace moore; | ||
|
||
namespace { | ||
struct MergeAssignmentsPass | ||
: public circt::moore::impl::MergeAssignmentsBase<MergeAssignmentsPass> { | ||
void runOnOperation() override; | ||
}; | ||
} // namespace | ||
|
||
std::unique_ptr<mlir::Pass> circt::moore::createMergeAssignmentsPass() { | ||
return std::make_unique<MergeAssignmentsPass>(); | ||
} | ||
|
||
// TODO: The net can be driven multiple times. However, the related rule is | ||
// complicated. So we will implement this in the future. | ||
|
||
// Only collect the easy declaration and its value at module level. | ||
static void collectAssignmets(SVModuleOp moduleOp, | ||
DenseMap<Value, Value> &assignments) { | ||
moduleOp->walk([&](Operation *op) { | ||
TypeSwitch<Operation *>(op).Case<ContinuousAssignOp>([&](auto op) { | ||
if (isa<VariableOp, NetOp>(op.getDst().getDefiningOp())) { | ||
if (!assignments.lookup(op.getDst())) | ||
assignments[op.getDst()] = op.getSrc(); | ||
else | ||
mlir::emitError(op.getLoc()) | ||
<< "Unsupported drive the same wire '" | ||
<< op.getDst().template getDefiningOp<NetOp>().getName() | ||
<< "' two times now"; | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
void MergeAssignmentsPass::runOnOperation() { | ||
OpBuilder builder(&getContext()); | ||
|
||
// Use to collect the easy declaration and its value. | ||
DenseMap<Value, Value> assignments; | ||
|
||
collectAssignmets(getOperation(), assignments); | ||
for (auto assignment : assignments) { | ||
auto varName = | ||
assignment.first.getDefiningOp()->getAttrOfType<StringAttr>("name"); | ||
|
||
builder.setInsertionPointAfterValue(assignment.first); | ||
builder.create<AssignedVarOp>(assignment.first.getLoc(), | ||
assignment.first.getType(), varName, | ||
assignment.second); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// RUN: circt-opt --moore-merge-assignments %s | FileCheck %s | ||
|
||
// CHECK-LABEL: moore.module @Foo() | ||
moore.module @Foo() { | ||
// CHECK: %a = moore.variable : <i32> | ||
// CHECK: %a_0 = moore.assigned_variable name "a" %0 : <i32> | ||
%a = moore.variable : <i32> | ||
|
||
// CHECK: %l = moore.net wire : <l1> | ||
// CHECK: %l_1 = moore.assigned_variable name "l" %2 : <l1> | ||
%l = moore.net wire : <l1> | ||
|
||
// CHECK: %0 = moore.constant 32 : i32 | ||
%0 = moore.constant 32 : i32 | ||
moore.assign %a, %0 : i32 | ||
%1 = moore.constant true : i1 | ||
%2 = moore.conversion %1 : !moore.i1 -> !moore.l1 | ||
moore.assign %l, %2 : l1 | ||
moore.output | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters