13 #include "mlir/Pass/Pass.h"
17 #define GEN_PASS_DEF_ADDTAPS
18 #include "circt/Dialect/Arc/ArcPasses.h.inc"
22 using namespace circt;
27 struct AddTapsPass :
public arc::impl::AddTapsBase<AddTapsPass> {
28 using AddTapsBase::AddTapsBase;
30 void runOnOperation()
override {
31 getOperation().walk([&](Operation *op) {
32 TypeSwitch<Operation *>(op)
34 .Default([&](
auto) { tapIfNamed(op); });
42 auto *outputOp = moduleOp.getBodyBlock()->getTerminator();
46 auto builder = OpBuilder::atBlockBegin(moduleOp.getBodyBlock());
47 for (
auto [port, arg] :
48 llvm::zip(ports.getInputs(), moduleOp.getBodyBlock()->getArguments()))
49 buildTap(builder, arg.getLoc(), arg, port.getName());
52 builder.setInsertionPoint(outputOp);
53 for (
auto [port, result] :
54 llvm::zip(ports.getOutputs(), outputOp->getOperands()))
55 buildTap(builder, result.getLoc(), result, port.getName());
63 for (
auto *user : wireOp->getUsers())
64 if (
auto op = dyn_cast<sv::ReadInOutOp>(user))
67 OpBuilder builder(wireOp);
70 buildTap(builder, readOp.getLoc(), readOp, wireOp.getName());
74 void tap(hw::WireOp wireOp) {
75 if (
auto name = wireOp.getName(); name && tapWires) {
76 OpBuilder builder(wireOp);
77 buildTap(builder, wireOp.getLoc(), wireOp, *name);
79 wireOp.getResult().replaceAllUsesWith(wireOp.getInput());
84 void tapIfNamed(Operation *op) {
85 if (!tapNamedValues || op->getNumResults() != 1)
87 if (
auto name = op->getAttrOfType<StringAttr>(
"sv.namehint")) {
88 OpBuilder builder(op);
89 buildTap(builder, op->getLoc(), op->getResult(0), name);
93 void buildTap(OpBuilder &builder, Location loc, Value value, StringRef name) {
96 if (isa<seq::ClockType>(value.getType()))
97 value = builder.createOrFold<seq::FromClockOp>(loc, value);
98 builder.create<arc::TapOp>(loc, value, name);
104 return std::make_unique<AddTapsPass>(options);
std::unique_ptr< mlir::Pass > createAddTapsPass(const AddTapsOptions &options={})
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
This holds a decoded list of input/inout and output ports for a module or instance.