Skip to content

Commit

Permalink
Allow replacing instrs while visiting
Browse files Browse the repository at this point in the history
This reduces the need to keep around lists of instructions to be replaced later
until the visitor finished and will avoid some memory allocations.
  • Loading branch information
JanRehders-AMD authored and Flakebi committed Dec 22, 2023
1 parent 93de71f commit bc5d060
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/Dialect/Visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ void VisitorBase::visitByDeclarations(void *payload, llvm::Module &module,
continue;
}

for (Use &use : decl.uses()) {
for (Use &use : make_early_inc_range(decl.uses())) {
if (auto *inst = dyn_cast<Instruction>(use.getUser())) {
if (!filter(*inst))
continue;
Expand All @@ -260,7 +260,7 @@ void VisitorBase::visitByDeclarations(void *payload, llvm::Module &module,
void VisitorBase::visit(void *payload, Function &fn) const {
if (m_strategy == VisitorStrategy::ByInstruction) {
for (BasicBlock &bb : fn) {
for (Instruction &inst : bb)
for (Instruction &inst : make_early_inc_range(bb))
visit(payload, inst);
}
return;
Expand All @@ -269,7 +269,7 @@ void VisitorBase::visit(void *payload, Function &fn) const {
if (m_strategy == VisitorStrategy::ReversePostOrder) {
ReversePostOrderTraversal<Function *> rpot(&fn);
for (BasicBlock *bb : rpot) {
for (Instruction &inst : *bb)
for (Instruction &inst : make_early_inc_range(*bb))
visit(payload, inst);
}
return;
Expand Down

0 comments on commit bc5d060

Please sign in to comment.