aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
diff options
context:
space:
mode:
authorMarco Elver <elver@google.com>2022-03-17 14:56:29 +0100
committerMarco Elver <elver@google.com>2022-03-17 14:59:37 +0100
commitcbe1e67eade900fa73f29b88ab49fcb6fc29bbb0 (patch)
tree76b917ce73f23e189238ba80ed0071e119893ea1 /llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
parent799643f7f0bebbc4e45767cfea5e8e227af7ef9c (diff)
downloadllvm-cbe1e67eade900fa73f29b88ab49fcb6fc29bbb0.zip
llvm-cbe1e67eade900fa73f29b88ab49fcb6fc29bbb0.tar.gz
llvm-cbe1e67eade900fa73f29b88ab49fcb6fc29bbb0.tar.bz2
[Instruction] Introduce getAtomicSyncScopeID()
An analysis may just be interested in checking if an instruction is atomic but system scoped or single-thread scoped, like ThreadSanitizer's isAtomic(). Unfortunately Instruction::isAtomic() can only answer the "atomic" part of the question, but to also check scope becomes rather verbose. To simplify and reduce redundancy, introduce a common helper getAtomicSyncScopeID() which returns the scope of an atomic operation. Start using it in ThreadSanitizer. NFCI. Reviewed By: dvyukov Differential Revision: https://reviews.llvm.org/D121910
Diffstat (limited to 'llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp')
-rw-r--r--llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp21
1 files changed, 8 insertions, 13 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
index cd1e854..ade0316 100644
--- a/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
@@ -526,19 +526,14 @@ void ThreadSanitizer::chooseInstructionsToInstrument(
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 @@ bool ThreadSanitizer::sanitizeFunction(Function &F,
// 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);