19 #include "mlir/IR/ImplicitLocOpBuilder.h"
20 #include "mlir/Pass/Pass.h"
21 #include "llvm/Support/Debug.h"
23 #define DEBUG_TYPE "firrtl-passive-wires"
27 #define GEN_PASS_DEF_PASSIVEWIRES
28 #include "circt/Dialect/FIRRTL/Passes.h.inc"
32 using namespace circt;
33 using namespace firrtl;
36 if (
auto type = type_dyn_cast<FIRRTLBaseType>(t))
37 return !type.isPassive();
46 struct PassiveWiresPass
47 :
public circt::firrtl::impl::PassiveWiresBase<PassiveWiresPass> {
48 void runOnOperation()
override;
53 void PassiveWiresPass::runOnOperation() {
55 auto module = getOperation();
58 SmallVector<Operation *> worklist;
59 module.walk([&](Operation *op) -> WalkResult {
60 if (
auto wire = dyn_cast<WireOp>(op)) {
62 worklist.push_back(wire);
63 return WalkResult::advance();
65 if (!isa<ConnectOp, MatchingConnectOp>(op))
66 return WalkResult::advance();
68 if (!
hasFlip(op->getOperand(0).getType()))
69 return WalkResult::advance();
71 mlir::ImplicitLocOpBuilder builder(op->getLoc(), op);
73 emitConnect(builder, op->getOperand(0), op->getOperand(1));
75 return WalkResult::advance();
79 while (!worklist.empty()) {
80 auto *op = worklist.back();
82 auto r = op->getResult(0);
85 for (
auto users : r.getUsers())
86 worklist.push_back(users);
88 r.setType(type_cast<FIRRTLBaseType>(r.getType()).getPassiveType());
94 return std::make_unique<PassiveWiresPass>();
static bool hasFlip(Type t)
std::unique_ptr< mlir::Pass > createPassiveWiresPass()
This is the pass constructor.
void emitConnect(OpBuilder &builder, Location loc, Value lhs, Value rhs)
Emit a connect between two values.
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.