Skip to content

Commit

Permalink
Reland "Revert "AtomicExpand: Allow incrementally legalizing atomicrm…
Browse files Browse the repository at this point in the history
…w"" (#106793)

Reverts #106792

The first commit of PR is pure revert, the rest is a possible fix.
  • Loading branch information
vitalybuka authored Sep 4, 2024
1 parent 7deda4e commit 0628683
Show file tree
Hide file tree
Showing 5 changed files with 836 additions and 691 deletions.
35 changes: 24 additions & 11 deletions llvm/lib/CodeGen/AtomicExpandPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

return MadeChange;
Expand Down
Loading

0 comments on commit 0628683

Please sign in to comment.