18 #include "mlir/Pass/Pass.h"
22 #include "mlir/IR/Dominance.h"
23 #include "mlir/IR/ImplicitLocOpBuilder.h"
24 #include "llvm/Support/Debug.h"
28 #define DEBUG_TYPE "firrtl-eliminate-wires"
32 #define GEN_PASS_DEF_ELIMINATEWIRES
33 #include "circt/Dialect/FIRRTL/Passes.h.inc"
37 using namespace circt;
38 using namespace firrtl;
45 struct EliminateWiresPass
46 :
public circt::firrtl::impl::EliminateWiresBase<EliminateWiresPass> {
47 void runOnOperation()
override;
51 void EliminateWiresPass::runOnOperation() {
53 auto module = getOperation();
54 auto &dominance = getAnalysis<mlir::DominanceInfo>();
56 std::deque<std::pair<WireOp, MatchingConnectOp>> worklist;
58 for (
auto wire : module.getOps<WireOp>()) {
59 auto type = type_dyn_cast<FIRRTLBaseType>(wire.getResult().getType());
60 if (!type || !type.isPassive()) {
74 for (
auto *user : wire->getUsers()) {
75 if (!dominance.dominates(writer, user)) {
83 worklist.emplace_back(wire, writer);
86 for (
auto [wire, writer] : worklist) {
87 mlir::ImplicitLocOpBuilder builder(wire->getLoc(), writer);
88 auto node = builder.create<NodeOp>(
89 writer.getSrc(), wire.getName(), wire.getNameKind(),
90 wire.getAnnotations(), wire.getInnerSymAttr(), wire.getForceable());
91 wire.replaceAllUsesWith(node);
100 return std::make_unique<EliminateWiresPass>();
std::unique_ptr< mlir::Pass > createEliminateWiresPass()
This is the pass constructor.
MatchingConnectOp getSingleConnectUserOf(Value value)
Scan all the uses of the specified value, checking to see if there is exactly one connect that has th...
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
llvm::raw_ostream & debugPassHeader(const mlir::Pass *pass, int width=80)
Write a boilerplate header for a pass to the debug stream.