9#include "../PassDetails.h"
17#define GEN_PASS_DEF_ESIAPPIDHIER
18#include "circt/Dialect/ESI/ESIPasses.h.inc"
26struct ESIAppIDHierPass
27 :
public circt::esi::impl::ESIAppIDHierBase<ESIAppIDHierPass> {
28 void runOnOperation()
override;
32 DenseMap<AppIDPathAttr, Block *> nodeBlock;
37 Block *getBlock(AppIDPathAttr path, ArrayRef<Operation *> opStack) {
38 Block *&block = nodeBlock[path];
43 if (path.getPath().empty()) {
44 auto rootOp = OpBuilder::atBlockEnd(getOperation().getBody())
45 .create<AppIDHierRootOp>(UnknownLoc::get(&getContext()),
47 block = &rootOp.getChildren().emplaceBlock();
49 Block *parentBlock = getBlock(path.getParent(), opStack.drop_back());
50 Operation *op = opStack.back();
51 if (
auto inst = dyn_cast<hw::InstanceOp>(op)) {
53 auto node = OpBuilder::atBlockEnd(parentBlock)
54 .create<AppIDHierNodeOp>(UnknownLoc::get(&getContext()),
55 path.getPath().back(),
56 inst.getModuleNameAttr());
57 block = &node.getChildren().emplaceBlock();
67void ESIAppIDHierPass::runOnOperation() {
68 auto mod = getOperation();
69 AppIDIndex index(mod);
71 return signalPassFailure();
74 LogicalResult rc = index.walk(
75 top, [&](AppIDPathAttr appidPath, ArrayRef<Operation *> opStack) {
76 assert(appidPath.getPath().size() == opStack.size() &&
77 "path and opStack must be the same size.");
78 auto *block = getBlock(appidPath, opStack);
79 auto *op = opStack.back();
80 if (isa<IsManifestData>(op))
81 OpBuilder::atBlockEnd(block).clone(*op);
84 return signalPassFailure();
88 return std::make_unique<ESIAppIDHierPass>();
assert(baseType &&"element must be base type")
std::unique_ptr< OperationPass< ModuleOp > > createESIAppIDHierPass()
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.