r339955 - [InstrProf] Use atomic profile counter updates for TSan
Vedant Kumar via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 16 15:24:48 PDT 2018
Author: vedantk
Date: Thu Aug 16 15:24:47 2018
New Revision: 339955
URL: http://llvm.org/viewvc/llvm-project?rev=339955&view=rev
Log:
[InstrProf] Use atomic profile counter updates for TSan
Thread sanitizer instrumentation fails to skip all loads and stores to
profile counters. This can happen if profile counter updates are merged:
%.sink = phi i64* ...
%pgocount5 = load i64, i64* %.sink
%27 = add i64 %pgocount5, 1
%28 = bitcast i64* %.sink to i8*
call void @__tsan_write8(i8* %28)
store i64 %27, i64* %.sink
To suppress TSan diagnostics about racy counter updates, make the
counter updates atomic when TSan is enabled. If there's general interest
in this mode it can be surfaced as a clang/swift driver option.
Testing: check-{llvm,clang,profile}
rdar://40477803
Differential Revision: https://reviews.llvm.org/D50867
Added:
cfe/trunk/test/CodeGen/tsan-instrprof-atomic.c
Modified:
cfe/trunk/lib/CodeGen/BackendUtil.cpp
Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=339955&r1=339954&r2=339955&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Thu Aug 16 15:24:47 2018
@@ -653,6 +653,11 @@ void EmitAssemblyHelper::CreatePasses(le
InstrProfOptions Options;
Options.NoRedZone = CodeGenOpts.DisableRedZone;
Options.InstrProfileOutput = CodeGenOpts.InstrProfileOutput;
+
+ // TODO: Surface the option to emit atomic profile counter increments at
+ // the driver level.
+ Options.Atomic = LangOpts.Sanitize.has(SanitizerKind::Thread);
+
MPM.add(createInstrProfilingLegacyPass(Options));
}
if (CodeGenOpts.hasProfileIRInstr()) {
Added: cfe/trunk/test/CodeGen/tsan-instrprof-atomic.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/tsan-instrprof-atomic.c?rev=339955&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/tsan-instrprof-atomic.c (added)
+++ cfe/trunk/test/CodeGen/tsan-instrprof-atomic.c Thu Aug 16 15:24:47 2018
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 %s -emit-llvm -fprofile-instrument=clang -fsanitize=thread -o - | FileCheck %s
+
+// CHECK: define void @foo
+// CHECK-NOT: load {{.*}}foo
+// CHECK: ret void
+void foo() {}
More information about the cfe-commits
mailing list