[llvm] AtomicExpand: Allow incrementally legalizing atomicrmw (PR #103371)
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 4 13:52:01 PDT 2024
================
@@ -351,17 +351,30 @@ bool AtomicExpandImpl::run(Function &F, const TargetMachine *TM) {
bool MadeChange = false;
- SmallVector<Instruction *, 1> AtomicInsts;
-
- // Changing control-flow while iterating through it is a bad idea, so gather a
- // list of all atomic instructions before we start.
- for (Instruction &I : instructions(F))
- if (I.isAtomic() && !isa<FenceInst>(&I))
- AtomicInsts.push_back(&I);
-
- for (auto *I : AtomicInsts) {
- if (processAtomicInstr(I))
- MadeChange = true;
+ for (Function::iterator BBI = F.begin(), BBE = F.end(); BBI != BBE;) {
+ BasicBlock *BB = &*BBI;
+ ++BBI;
+
+ BasicBlock::iterator Next;
+
+ for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E;
+ I = Next) {
+ Instruction &Inst = *I;
+ Next = std::next(I);
+
+ if (processAtomicInstr(&Inst)) {
+ MadeChange = true;
----------------
vitalybuka wrote:
Heads up, I reverted the patch again
`processAtomicInstr` may erase `Next`
https://github.com/llvm/llvm-project/pull/103371
More information about the llvm-commits
mailing list