Skip to content

Commit 69e114f

Browse files
author
xuechenAMD
authored
Make Visitor more robust on instruction iteration (#79)
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.
1 parent 8fca758 commit 69e114f

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/Dialect/Visitor.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,12 @@ void VisitorBase::visit(void *payload, Function &fn) const {
269269
if (m_strategy == VisitorStrategy::ReversePostOrder) {
270270
ReversePostOrderTraversal<Function *> rpot(&fn);
271271
for (BasicBlock *bb : rpot) {
272-
for (Instruction &inst : make_early_inc_range(*bb))
273-
visit(payload, inst);
272+
// Allow callbacks to directly edit the code adding basic blocks
273+
for (Instruction *inst = &*bb->begin(); inst != nullptr;) {
274+
auto nextInst = inst->getNextNode();
275+
visit(payload, *inst);
276+
inst = nextInst;
277+
}
274278
}
275279
return;
276280
}

0 commit comments

Comments
 (0)