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() {
52 auto module = getOperation();
53 auto &dominance = getAnalysis<mlir::DominanceInfo>();
55 std::deque<std::pair<WireOp, MatchingConnectOp>> worklist;
57 for (
auto wire : module.getOps<WireOp>()) {
58 auto type = type_dyn_cast<FIRRTLBaseType>(wire.getResult().getType());
59 if (!type || !type.isPassive()) {
73 for (
auto *user : wire->getUsers()) {
74 if (!dominance.dominates(writer, user)) {
82 worklist.emplace_back(wire, writer);
85 for (
auto [wire, writer] : worklist) {
86 mlir::ImplicitLocOpBuilder builder(wire->getLoc(), writer);
87 auto node = NodeOp::create(builder, writer.getSrc(), wire.getName(),
88 wire.getNameKind(), wire.getAnnotations(),
89 wire.getInnerSymAttr(), wire.getForceable());
90 wire.replaceAllUsesWith(node);
#define CIRCT_DEBUG_SCOPED_PASS_LOGGER(PASS)
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.