19 #include "mlir/IR/ImplicitLocOpBuilder.h"
20 #include "llvm/Support/Debug.h"
22 #define DEBUG_TYPE "firrtl-passive-wires"
24 using namespace circt;
25 using namespace firrtl;
28 if (
auto type = type_dyn_cast<FIRRTLBaseType>(t))
29 return !type.isPassive();
38 struct PassiveWiresPass :
public PassiveWiresBase<PassiveWiresPass> {
39 void runOnOperation()
override;
44 void PassiveWiresPass::runOnOperation() {
46 auto module = getOperation();
49 SmallVector<Operation *> worklist;
50 module.walk([&](Operation *op) -> WalkResult {
51 if (
auto wire = dyn_cast<WireOp>(op)) {
53 worklist.push_back(wire);
54 return WalkResult::advance();
56 if (!isa<ConnectOp, StrictConnectOp>(op))
57 return WalkResult::advance();
59 if (!
hasFlip(op->getOperand(0).getType()))
60 return WalkResult::advance();
62 mlir::ImplicitLocOpBuilder
builder(op->getLoc(), op);
66 return WalkResult::advance();
70 while (!worklist.empty()) {
71 auto *op = worklist.back();
73 auto r = op->getResult(0);
76 for (
auto users : r.getUsers())
77 worklist.push_back(users);
79 r.setType(type_cast<FIRRTLBaseType>(r.getType()).getPassiveType());
85 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.