19 #include "mlir/IR/BuiltinOps.h"
20 #include "mlir/IR/PatternMatch.h"
21 #include "mlir/Pass/Pass.h"
22 #include "mlir/Pass/PassRegistry.h"
23 #include "mlir/Transforms/DialectConversion.h"
24 #include "mlir/Transforms/GreedyPatternRewriteDriver.h"
28 #define GEN_PASS_DEF_LOWERINSTANCES
29 #include "circt/Dialect/MSFT/MSFTPasses.h.inc"
33 using namespace circt;
41 struct LowerInstancesPass
42 :
public circt::msft::impl::LowerInstancesBase<LowerInstancesPass> {
43 void runOnOperation()
override;
58 hw::HierPathOp ref =
nullptr;
62 if (llvm::any_of(inst.getOps(), [](Operation &op) {
63 return isa<DynInstDataOpInterface>(op);
68 auto origRefSym = refSym;
70 while (topSyms.getDefinition(refSym))
72 origRefSym.getValue() +
"_" + Twine(++ctr));
75 ArrayAttr hierPath = inst.getPath();
76 ref = b.
create<hw::HierPathOp>(inst.getLoc(), refSym, hierPath);
79 topSyms.addDefinition(refSym, ref);
83 OpBuilder hierBlock(&hier.getBody().front().front());
84 for (Operation &op : llvm::make_early_inc_range(inst.getOps())) {
86 assert(!isa<DynamicInstanceOp>(op));
88 hierBlock.insert(&op);
91 if (
auto specOp = dyn_cast<UnaryDynInstDataOpInterface>(op)) {
93 specOp.setPathOp(ref);
100 void LowerInstancesPass::runOnOperation() {
101 auto top = getOperation();
102 auto *
ctxt = &getContext();
105 topSyms.addDefinitions(top);
107 size_t numFailed = 0;
108 OpBuilder builder(
ctxt);
111 for (Operation &op : llvm::make_early_inc_range(top.getOps())) {
112 auto instHierOp = dyn_cast<InstanceHierarchyOp>(op);
115 builder.setInsertionPoint(&op);
119 if (failed(lower(inst, instHierOp, builder)))
130 return std::make_unique<LowerInstancesPass>();
assert(baseType &&"element must be base type")
Default symbol cache implementation; stores associations between names (StringAttr's) to mlir::Operat...
Direction get(bool isOutput)
Returns an output direction if isOutput is true, otherwise returns an input direction.
std::unique_ptr< mlir::Pass > createLowerInstancesPass()
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.