17 #include "mlir/Pass/Pass.h"
21 #include "mlir/IR/ImplicitLocOpBuilder.h"
22 #include "llvm/Support/Debug.h"
24 #define DEBUG_TYPE "firrtl-passive-wires"
28 #define GEN_PASS_DEF_PASSIVEWIRES
29 #include "circt/Dialect/FIRRTL/Passes.h.inc"
33 using namespace circt;
34 using namespace firrtl;
37 if (
auto type = type_dyn_cast<FIRRTLBaseType>(t))
38 return !type.isPassive();
47 struct PassiveWiresPass
48 :
public circt::firrtl::impl::PassiveWiresBase<PassiveWiresPass> {
49 void runOnOperation()
override;
54 void PassiveWiresPass::runOnOperation() {
56 auto module = getOperation();
59 SmallVector<Operation *> worklist;
60 module.walk([&](Operation *op) -> WalkResult {
61 if (
auto wire = dyn_cast<WireOp>(op)) {
63 worklist.push_back(wire);
64 return WalkResult::advance();
66 if (!isa<ConnectOp, MatchingConnectOp>(op))
67 return WalkResult::advance();
69 if (!
hasFlip(op->getOperand(0).getType()))
70 return WalkResult::advance();
72 mlir::ImplicitLocOpBuilder builder(op->getLoc(), op);
74 emitConnect(builder, op->getOperand(0), op->getOperand(1));
76 return WalkResult::advance();
80 while (!worklist.empty()) {
81 auto *op = worklist.back();
83 auto r = op->getResult(0);
86 for (
auto users : r.getUsers())
87 worklist.push_back(users);
89 r.setType(type_cast<FIRRTLBaseType>(r.getType()).getPassiveType());
95 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.