19#include "mlir/IR/Dominance.h"
20#include "mlir/IR/ImplicitLocOpBuilder.h"
21#include "mlir/Pass/Pass.h"
22#include "llvm/Support/Debug.h"
26#define DEBUG_TYPE "firrtl-eliminate-wires"
30#define GEN_PASS_DEF_ELIMINATEWIRES
31#include "circt/Dialect/FIRRTL/Passes.h.inc"
36using namespace firrtl;
43struct EliminateWiresPass
44 :
public circt::firrtl::impl::EliminateWiresBase<EliminateWiresPass> {
45 void runOnOperation()
override;
49void EliminateWiresPass::runOnOperation() {
51 auto module = getOperation();
52 auto &dominance = getAnalysis<mlir::DominanceInfo>();
54 std::deque<std::pair<WireOp, MatchingConnectOp>> worklist;
56 for (
auto wire : module.getOps<WireOp>()) {
57 auto type = type_dyn_cast<FIRRTLBaseType>(wire.getResult().getType());
58 if (!type || !type.isPassive()) {
72 for (
auto *user : wire->getUsers()) {
73 if (!dominance.dominates(writer, user)) {
81 worklist.emplace_back(wire, writer);
84 for (
auto [wire, writer] : worklist) {
85 mlir::ImplicitLocOpBuilder builder(wire->getLoc(), writer);
86 auto node = builder.create<NodeOp>(
87 writer.getSrc(), wire.getName(), wire.getNameKind(),
88 wire.getAnnotations(), wire.getInnerSymAttr(), wire.getForceable());
89 wire.replaceAllUsesWith(node);
98 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.