Skip to content

Commit bc5d060

Browse files
JanRehders-AMDFlakebi
authored andcommitted
Allow replacing instrs while visiting
This reduces the need to keep around lists of instructions to be replaced later until the visitor finished and will avoid some memory allocations.
1 parent 93de71f commit bc5d060

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lib/Dialect/Visitor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ void VisitorBase::visitByDeclarations(void *payload, llvm::Module &module,
244244
continue;
245245
}
246246

247-
for (Use &use : decl.uses()) {
247+
for (Use &use : make_early_inc_range(decl.uses())) {
248248
if (auto *inst = dyn_cast<Instruction>(use.getUser())) {
249249
if (!filter(*inst))
250250
continue;
@@ -260,7 +260,7 @@ void VisitorBase::visitByDeclarations(void *payload, llvm::Module &module,
260260
void VisitorBase::visit(void *payload, Function &fn) const {
261261
if (m_strategy == VisitorStrategy::ByInstruction) {
262262
for (BasicBlock &bb : fn) {
263-
for (Instruction &inst : bb)
263+
for (Instruction &inst : make_early_inc_range(bb))
264264
visit(payload, inst);
265265
}
266266
return;
@@ -269,7 +269,7 @@ 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 : *bb)
272+
for (Instruction &inst : make_early_inc_range(*bb))
273273
visit(payload, inst);
274274
}
275275
return;

0 commit comments

Comments
 (0)