-
Notifications
You must be signed in to change notification settings - Fork 299
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 MergeAssignments pass.
- Loading branch information
1 parent
2ec4a1c
commit c8c19f6
Showing
8 changed files
with
123 additions
and
1 deletion.
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
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,68 @@ | ||
//===- 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/MapVector.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>(); | ||
} | ||
|
||
// Only collect the easy declaration and its value at module level. | ||
static void collectAssignmets(SVModuleOp moduleOp, | ||
llvm::MapVector<Value, Value> &assignments) { | ||
moduleOp->walk([&](ContinuousAssignOp op) { | ||
if (auto varOp = op.getDst().getDefiningOp<VariableOp>()) | ||
assignments[varOp] = op.getSrc(); | ||
}); | ||
} | ||
|
||
void MergeAssignmentsPass::runOnOperation() { | ||
OpBuilder builder(&getContext()); | ||
|
||
// Use to collect the easy declaration and its value. | ||
llvm::MapVector<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: %b = moore.variable : <l32> | ||
// CHECK: %b_1 = moore.assigned_variable name "b" %2 : <l32> | ||
%b = moore.variable : <l32> | ||
|
||
%0 = moore.constant 32 : i32 | ||
moore.assign %a, %0 : i32 | ||
%1 = moore.constant 32 : i32 | ||
%2 = moore.conversion %1 : !moore.i32 -> !moore.l32 | ||
moore.assign %b, %2 : l32 | ||
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