[llvm] 7f14a1d - AtomicExpand: Add NotAtomic lowering strategy
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 6 19:47:47 PDT 2022
Author: Matt Arsenault
Date: 2022-04-06T22:34:35-04:00
New Revision: 7f14a1d46b8e2233cbfb959e55ac9b7d33449c7e
URL: https://github.com/llvm/llvm-project/commit/7f14a1d46b8e2233cbfb959e55ac9b7d33449c7e
DIFF: https://github.com/llvm/llvm-project/commit/7f14a1d46b8e2233cbfb959e55ac9b7d33449c7e.diff
LOG: AtomicExpand: Add NotAtomic lowering strategy
Currently LowerAtomics exists as a separate pass which blindly
replaces all atomics. Add a new lowering strategy option to eliminate
the atomics which the target can control on a per-instruction level.
Added:
Modified:
llvm/include/llvm/CodeGen/TargetLowering.h
llvm/lib/CodeGen/AtomicExpandPass.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/CodeGen/TargetLowering.h b/llvm/include/llvm/CodeGen/TargetLowering.h
index a2ca4595c32b8..ca60a3861b64e 100644
--- a/llvm/include/llvm/CodeGen/TargetLowering.h
+++ b/llvm/include/llvm/CodeGen/TargetLowering.h
@@ -257,6 +257,10 @@ class TargetLoweringBase {
BitTestIntrinsic, // Use a target-specific intrinsic for special bit
// operations; used by X86.
Expand, // Generic expansion in terms of other atomic operations.
+
+ // Rewrite to a non-atomic form for use in a known non-preemptible
+ // environment.
+ NotAtomic
};
/// Enum that specifies when a multiplication should be expanded.
diff --git a/llvm/lib/CodeGen/AtomicExpandPass.cpp b/llvm/lib/CodeGen/AtomicExpandPass.cpp
index 05b140b8174e9..dbf49fc53e10c 100644
--- a/llvm/lib/CodeGen/AtomicExpandPass.cpp
+++ b/llvm/lib/CodeGen/AtomicExpandPass.cpp
@@ -47,6 +47,7 @@
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetMachine.h"
+#include "llvm/Transforms/Utils/LowerAtomic.h"
#include <cassert>
#include <cstdint>
#include <iterator>
@@ -412,6 +413,9 @@ bool AtomicExpand::tryExpandAtomicLoad(LoadInst *LI) {
return expandAtomicLoadToLL(LI);
case TargetLoweringBase::AtomicExpansionKind::CmpXChg:
return expandAtomicLoadToCmpXchg(LI);
+ case TargetLoweringBase::AtomicExpansionKind::NotAtomic:
+ LI->setAtomic(AtomicOrdering::NotAtomic);
+ return true;
default:
llvm_unreachable("Unhandled case in tryExpandAtomicLoad");
}
@@ -424,6 +428,9 @@ bool AtomicExpand::tryExpandAtomicStore(StoreInst *SI) {
case TargetLoweringBase::AtomicExpansionKind::Expand:
expandAtomicStore(SI);
return true;
+ case TargetLoweringBase::AtomicExpansionKind::NotAtomic:
+ SI->setAtomic(AtomicOrdering::NotAtomic);
+ return true;
default:
llvm_unreachable("Unhandled case in tryExpandAtomicStore");
}
@@ -635,6 +642,8 @@ bool AtomicExpand::tryExpandAtomicRMW(AtomicRMWInst *AI) {
TLI->emitBitTestAtomicRMWIntrinsic(AI);
return true;
}
+ case TargetLoweringBase::AtomicExpansionKind::NotAtomic:
+ return lowerAtomicRMWInst(AI);
default:
llvm_unreachable("Unhandled case in tryExpandAtomicRMW");
}
@@ -1536,6 +1545,8 @@ bool AtomicExpand::tryExpandAtomicCmpXchg(AtomicCmpXchgInst *CI) {
case TargetLoweringBase::AtomicExpansionKind::MaskedIntrinsic:
expandAtomicCmpXchgToMaskedIntrinsic(CI);
return true;
+ case TargetLoweringBase::AtomicExpansionKind::NotAtomic:
+ return lowerAtomicCmpXchgInst(CI);
}
}
More information about the llvm-commits
mailing list