[PATCH] D121910: [Instruction] Introduce getAtomicSyncScopeID()
Marco Elver via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 17 07:23:49 PDT 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcbe1e67eade9: [Instruction] Introduce getAtomicSyncScopeID() (authored by melver).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D121910/new/
https://reviews.llvm.org/D121910
Files:
llvm/include/llvm/IR/Instructions.h
llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
Index: llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
===================================================================
--- llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
@@ -526,19 +526,14 @@
Local.clear();
}
-static bool isAtomic(Instruction *I) {
+static bool isTsanAtomic(const Instruction *I) {
// TODO: Ask TTI whether synchronization scope is between threads.
- if (LoadInst *LI = dyn_cast<LoadInst>(I))
- return LI->isAtomic() && LI->getSyncScopeID() != SyncScope::SingleThread;
- if (StoreInst *SI = dyn_cast<StoreInst>(I))
- return SI->isAtomic() && SI->getSyncScopeID() != SyncScope::SingleThread;
- if (isa<AtomicRMWInst>(I))
- return true;
- if (isa<AtomicCmpXchgInst>(I))
- return true;
- if (isa<FenceInst>(I))
- return true;
- return false;
+ auto SSID = getAtomicSyncScopeID(I);
+ if (!SSID.hasValue())
+ return false;
+ if (isa<LoadInst>(I) || isa<StoreInst>(I))
+ return SSID.getValue() != SyncScope::SingleThread;
+ return true;
}
void ThreadSanitizer::InsertRuntimeIgnores(Function &F) {
@@ -580,7 +575,7 @@
// Traverse all instructions, collect loads/stores/returns, check for calls.
for (auto &BB : F) {
for (auto &Inst : BB) {
- if (isAtomic(&Inst))
+ if (isTsanAtomic(&Inst))
AtomicAccesses.push_back(&Inst);
else if (isa<LoadInst>(Inst) || isa<StoreInst>(Inst))
LocalLoadsAndStores.push_back(&Inst);
Index: llvm/include/llvm/IR/Instructions.h
===================================================================
--- llvm/include/llvm/IR/Instructions.h
+++ llvm/include/llvm/IR/Instructions.h
@@ -5310,6 +5310,10 @@
}
};
+//===----------------------------------------------------------------------===//
+// Helper functions
+//===----------------------------------------------------------------------===//
+
/// A helper function that returns the pointer operand of a load or store
/// instruction. Returns nullptr if not load or store.
inline const Value *getLoadStorePointerOperand(const Value *V) {
@@ -5365,6 +5369,24 @@
return cast<StoreInst>(I)->getValueOperand()->getType();
}
+/// A helper function that returns an atomic operation's sync scope; returns
+/// None if it is not an atomic operation.
+inline Optional<SyncScope::ID> getAtomicSyncScopeID(const Instruction *I) {
+ if (!I->isAtomic())
+ return None;
+ if (auto *AI = dyn_cast<LoadInst>(I))
+ return AI->getSyncScopeID();
+ if (auto *AI = dyn_cast<StoreInst>(I))
+ return AI->getSyncScopeID();
+ if (auto *AI = dyn_cast<FenceInst>(I))
+ return AI->getSyncScopeID();
+ if (auto *AI = dyn_cast<AtomicCmpXchgInst>(I))
+ return AI->getSyncScopeID();
+ if (auto *AI = dyn_cast<AtomicRMWInst>(I))
+ return AI->getSyncScopeID();
+ llvm_unreachable("unhandled atomic operation");
+}
+
//===----------------------------------------------------------------------===//
// FreezeInst Class
//===----------------------------------------------------------------------===//
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121910.416174.patch
Type: text/x-patch
Size: 3119 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220317/2f0f4ece/attachment.bin>
More information about the llvm-commits
mailing list