aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/AtomicExpandPass.cpp
diff options
context:
space:
mode:
authorMatt Arsenault <Matthew.Arsenault@amd.com>2025-07-09 15:28:10 +0900
committerGitHub <noreply@github.com>2025-07-09 15:28:10 +0900
commited1ee9a9bf6deb5ec147e79a156e2f8d9465616d (patch)
tree60f1b4c5643f2526085d3eeb5cf4917b8b2ae530 /llvm/lib/CodeGen/AtomicExpandPass.cpp
parent356dcf25265048ce688c2814a752ccd866acd359 (diff)
downloadllvm-ed1ee9a9bf6deb5ec147e79a156e2f8d9465616d.zip
llvm-ed1ee9a9bf6deb5ec147e79a156e2f8d9465616d.tar.gz
llvm-ed1ee9a9bf6deb5ec147e79a156e2f8d9465616d.tar.bz2
AtomicExpand: Stop using report_fatal_error (#147300)
Emit a context error and delete the instruction. This allows removing the AMDGPU hack where some atomic libcalls are falsely added. NVPTX also later copied the same hack, so remove it there too. For now just emit the generic error, which is not good. It's missing any useful context information (despite taking the instruction). It's also confusing in the failed atomicrmw case, since it's reporting failure at the intermediate failed cmpxchg instead of the original atomicrmw.
Diffstat (limited to 'llvm/lib/CodeGen/AtomicExpandPass.cpp')
-rw-r--r--llvm/lib/CodeGen/AtomicExpandPass.cpp17
1 files changed, 14 insertions, 3 deletions
diff --git a/llvm/lib/CodeGen/AtomicExpandPass.cpp b/llvm/lib/CodeGen/AtomicExpandPass.cpp
index 044f073..3f3d5dc9 100644
--- a/llvm/lib/CodeGen/AtomicExpandPass.cpp
+++ b/llvm/lib/CodeGen/AtomicExpandPass.cpp
@@ -65,6 +65,17 @@ class AtomicExpandImpl {
const DataLayout *DL = nullptr;
private:
+ void handleFailure(Instruction &FailedInst, const Twine &Msg) const {
+ LLVMContext &Ctx = FailedInst.getContext();
+
+ // TODO: Do not use generic error type.
+ Ctx.emitError(&FailedInst, Msg);
+
+ if (!FailedInst.getType()->isVoidTy())
+ FailedInst.replaceAllUsesWith(PoisonValue::get(FailedInst.getType()));
+ FailedInst.eraseFromParent();
+ }
+
bool bracketInstWithFences(Instruction *I, AtomicOrdering Order);
IntegerType *getCorrespondingIntegerType(Type *T, const DataLayout &DL);
LoadInst *convertAtomicLoadToIntegerType(LoadInst *LI);
@@ -1744,7 +1755,7 @@ void AtomicExpandImpl::expandAtomicLoadToLibcall(LoadInst *I) {
I, Size, I->getAlign(), I->getPointerOperand(), nullptr, nullptr,
I->getOrdering(), AtomicOrdering::NotAtomic, Libcalls);
if (!expanded)
- report_fatal_error("expandAtomicOpToLibcall shouldn't fail for Load");
+ handleFailure(*I, "unsupported atomic load");
}
void AtomicExpandImpl::expandAtomicStoreToLibcall(StoreInst *I) {
@@ -1757,7 +1768,7 @@ void AtomicExpandImpl::expandAtomicStoreToLibcall(StoreInst *I) {
I, Size, I->getAlign(), I->getPointerOperand(), I->getValueOperand(),
nullptr, I->getOrdering(), AtomicOrdering::NotAtomic, Libcalls);
if (!expanded)
- report_fatal_error("expandAtomicOpToLibcall shouldn't fail for Store");
+ handleFailure(*I, "unsupported atomic store");
}
void AtomicExpandImpl::expandAtomicCASToLibcall(AtomicCmpXchgInst *I) {
@@ -1772,7 +1783,7 @@ void AtomicExpandImpl::expandAtomicCASToLibcall(AtomicCmpXchgInst *I) {
I->getCompareOperand(), I->getSuccessOrdering(), I->getFailureOrdering(),
Libcalls);
if (!expanded)
- report_fatal_error("expandAtomicOpToLibcall shouldn't fail for CAS");
+ handleFailure(*I, "unsupported cmpxchg");
}
static ArrayRef<RTLIB::Libcall> GetRMWLibcall(AtomicRMWInst::BinOp Op) {