Skip to content

Commit

Permalink
Make Vistor more robust on instruction iteration
Browse files Browse the repository at this point in the history
Use a fixed end guard for the instruction iteration is not robust for
callbacks to add a basic block. Use `Instruction::getNextNode()` for the
iteration to allow callbacks to directly edit the code.
  • Loading branch information
xuechen417 committed Jan 12, 2024
1 parent 8fca758 commit 4a3764c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/Dialect/Visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,9 @@ void VisitorBase::visit(void *payload, Function &fn) const {
if (m_strategy == VisitorStrategy::ReversePostOrder) {
ReversePostOrderTraversal<Function *> rpot(&fn);
for (BasicBlock *bb : rpot) {
for (Instruction &inst : make_early_inc_range(*bb))
visit(payload, inst);
// Allow callbacks to directly edit the code adding basic blocks
for (Instruction *inst = &*bb->begin(); inst != nullptr; inst = inst->getNextNode())
visit(payload, *inst);
}
return;
}
Expand Down

0 comments on commit 4a3764c

Please sign in to comment.