summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2014-12-20 01:45:28 +0000
committerKostya Serebryany <kcc@google.com>2014-12-20 01:45:28 +0000
commitbaae9d2df1baed52d3ef9ef4b61fe270e9104327 (patch)
tree8ee2878f28adb25676d4ab1cc692ce0875ff2220 /compiler-rt/lib
parent7863991945e5fbfeb33d32a7702f9e5ce34e2051 (diff)
downloadbcm5719-llvm-baae9d2df1baed52d3ef9ef4b61fe270e9104327.tar.gz
bcm5719-llvm-baae9d2df1baed52d3ef9ef4b61fe270e9104327.zip
[sanitizer] fix a performance regression in sanitizer coverage: move a small perf-critical function to a header. ALso set the coverage guard to 1 before the early return from CoverageData::Add
llvm-svn: 224660
Diffstat (limited to 'compiler-rt/lib')
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_coverage_libcdep.cc6
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cc15
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h19
3 files changed, 21 insertions, 19 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_coverage_libcdep.cc b/compiler-rt/lib/sanitizer_common/sanitizer_coverage_libcdep.cc
index 3fa8a18696f..3e521d1620a 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_coverage_libcdep.cc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_coverage_libcdep.cc
@@ -234,15 +234,15 @@ void CoverageData::Extend(uptr npcs) {
// If the function is called more than once for a given PC it will
// be inserted multiple times, which is fine.
void CoverageData::Add(uptr pc, u8 *guard) {
+ // Set the guard.
+ atomic_uint8_t *atomic_guard = reinterpret_cast<atomic_uint8_t*>(guard);
+ atomic_store(atomic_guard, 1, memory_order_relaxed);
if (!pc_array) return;
uptr idx = atomic_fetch_add(&pc_array_index, 1, memory_order_relaxed);
CHECK_LT(idx * sizeof(uptr),
atomic_load(&pc_array_size, memory_order_acquire));
pc_array[idx] = pc;
atomic_fetch_add(&coverage_counter, 1, memory_order_relaxed);
- // Set the guard.
- atomic_uint8_t *atomic_guard = reinterpret_cast<atomic_uint8_t*>(guard);
- atomic_store(atomic_guard, 1, memory_order_relaxed);
}
// Registers a pair caller=>callee.
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cc b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cc
index 13549c4f80a..17b2ef3576a 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cc
@@ -17,21 +17,6 @@
namespace __sanitizer {
-uptr StackTrace::GetPreviousInstructionPc(uptr pc) {
-#if defined(__arm__)
- // Cancel Thumb bit.
- pc = pc & (~1);
-#endif
-#if defined(__powerpc__) || defined(__powerpc64__)
- // PCs are always 4 byte aligned.
- return pc - 4;
-#elif defined(__sparc__) || defined(__mips__)
- return pc - 8;
-#else
- return pc - 1;
-#endif
-}
-
uptr StackTrace::GetNextInstructionPc(uptr pc) {
#if defined(__mips__)
return pc + 8;
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h
index e755c052cb7..79be2879248 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h
@@ -57,12 +57,29 @@ struct StackTrace {
}
static uptr GetCurrentPc();
- static uptr GetPreviousInstructionPc(uptr pc);
+ static inline uptr GetPreviousInstructionPc(uptr pc);
static uptr GetNextInstructionPc(uptr pc);
typedef bool (*SymbolizeCallback)(const void *pc, char *out_buffer,
int out_size);
};
+// Performance-critical, must be in the header.
+ALWAYS_INLINE
+uptr StackTrace::GetPreviousInstructionPc(uptr pc) {
+#if defined(__arm__)
+ // Cancel Thumb bit.
+ pc = pc & (~1);
+#endif
+#if defined(__powerpc__) || defined(__powerpc64__)
+ // PCs are always 4 byte aligned.
+ return pc - 4;
+#elif defined(__sparc__) || defined(__mips__)
+ return pc - 8;
+#else
+ return pc - 1;
+#endif
+}
+
// StackTrace that owns the buffer used to store the addresses.
struct BufferedStackTrace : public StackTrace {
uptr trace_buffer[kStackTraceMax];
OpenPOWER on IntegriCloud