Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AtomicExpand: Allow incrementally legalizing atomicrmw #103371

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heads up, I reverted the patch again
processAtomicInstr may erase Next


// 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;
}
}
}
}

return MadeChange;
Expand Down
Loading
Loading