18#include "mlir/IR/PatternMatch.h"
22#define GEN_PASS_DEF_LOWERUNIQUELABELSPASS
23#include "circt/Dialect/RTG/Transforms/RTGPasses.h.inc"
36struct LowerUniqueLabelsPass
37 :
public rtg::impl::LowerUniqueLabelsPassBase<LowerUniqueLabelsPass> {
40 void runOnOperation()
override;
44void LowerUniqueLabelsPass::runOnOperation() {
45 auto moduleOp = getOperation();
49 moduleOp.walk([&](Operation *op) {
50 if (
auto labelDecl = dyn_cast<LabelDeclOp>(op))
51 labelNames.
add(labelDecl.getFormatString());
52 else if (
auto labelDecl = dyn_cast<LabelUniqueDeclOp>(op))
53 labelNames.
add(labelDecl.getFormatString());
57 moduleOp.walk([&](LabelUniqueDeclOp op) {
60 IRRewriter rewriter(op);
61 auto newName = labelNames.
newName(op.getFormatString());
62 rewriter.replaceOpWithNewOp<LabelDeclOp>(op, newName, ValueRange());
A namespace that is used to store existing names and generate new names in some scope within the IR.
void add(mlir::ModuleOp module)
StringRef newName(const Twine &name)
Return a unique name, derived from the input name, and add the new name to the internal namespace.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.