17 #include "mlir/IR/BuiltinTypes.h"
18 #include "mlir/IR/OperationSupport.h"
22 #define GEN_PASS_DEF_REMOVEGROUPS
23 #include "circt/Dialect/Calyx/CalyxPasses.h.inc"
27 using namespace circt;
28 using namespace calyx;
39 auto control = component.getControlOp();
41 auto topLevel = *control.getRegion().getOps<EnableOp>().begin();
42 auto topLevelName = topLevel.getGroupName();
44 auto wires = component.getWiresOp();
45 Value componentGoPort = component.getGoPort();
46 wires.walk([&](GroupOp group) {
47 auto &groupRegion = group->getRegion(0);
48 OpBuilder builder(groupRegion);
52 auto groupDone = group.getDoneOp();
53 if (topLevelName == group.getSymName()) {
57 builder.create<AssignOp>(group->getLoc(), component.getDonePort(),
58 groupDone.getSrc(), groupDone.getGuard());
59 groupDone->replaceAllUsesWith(assignOp);
66 auto groupGo = group.getGoOp();
67 auto groupGoGuard = groupGo.getGuard();
68 groupGo.replaceAllUsesWith(groupGoGuard);
78 auto &wiresRegion = component.getWiresOp().getRegion();
79 auto &wireBlocks = wiresRegion.getBlocks();
80 auto lastBlock = wiresRegion.end();
83 wiresRegion.walk([&](GroupOp group) {
84 wireBlocks.splice(lastBlock, group.getRegion().getBlocks());
89 auto firstBlock = wireBlocks.begin();
90 for (
auto it = firstBlock, e = lastBlock; it != e; ++it) {
93 firstBlock->getOperations().splice(firstBlock->end(), it->getOperations());
97 while (&wiresRegion.front() != &wiresRegion.back())
98 wiresRegion.back().erase();
103 struct RemoveGroupsPass
104 :
public circt::calyx::impl::RemoveGroupsBase<RemoveGroupsPass> {
105 void runOnOperation()
override;
110 void RemoveGroupsPass::runOnOperation() {
111 ComponentOp component = getOperation();
114 if (component.getControlOp().getOps().empty())
124 auto control = component.getControlOp();
125 control.walk([&](EnableOp enable) { enable->erase(); });
129 return std::make_unique<RemoveGroupsPass>();
static void modifyGroupOperations(ComponentOp component)
Makes several modifications to the operations of a GroupOp:
void inlineGroups(ComponentOp component)
Inlines each group in the WiresOp.
static void updateGroupAssignmentGuards(OpBuilder &builder, GroupOp &group, Op &op)
Updates the guard of each assignment within a group with op.
std::unique_ptr< mlir::Pass > createRemoveGroupsPass()
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.