Skip to content

Commit

Permalink
Revert "AtomicExpand: Allow incrementally legalizing atomicrmw" (#106792
Browse files Browse the repository at this point in the history
)

Reverts #103371

There is `heap-use-after-free`, commented on
206b5af

Maybe `if (Next == E || BB != Next->getParent()) {` is enough,
but not sure, what was the intent there,
  • Loading branch information
vitalybuka authored Aug 30, 2024
1 parent 432e9f4 commit 982d244
Show file tree
Hide file tree
Showing 5 changed files with 691 additions and 836 deletions.
35 changes: 11 additions & 24 deletions llvm/lib/CodeGen/AtomicExpandPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,30 +351,17 @@ bool AtomicExpandImpl::run(Function &F, const TargetMachine *TM) {

bool MadeChange = false;

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;

// Detect control flow change and resume iteration from the original
// block to inspect any newly inserted blocks. This allows incremental
// legalizaton of atomicrmw and cmpxchg.
if (BB != Next->getParent()) {
BBI = BB->getIterator();
BBE = F.end();
break;
}
}
}
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;
}

return MadeChange;
Expand Down
Loading

0 comments on commit 982d244

Please sign in to comment.