Skip to content

Commit

Permalink
Make Visitor more robust on instruction iteration (#79)
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 authored Jan 19, 2024
1 parent 8fca758 commit 69e114f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/Dialect/Visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,12 @@ 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;) {
auto nextInst = inst->getNextNode();
visit(payload, *inst);
inst = nextInst;
}
}
return;
}
Expand Down

0 comments on commit 69e114f

Please sign in to comment.