xref: /llvm-project/compiler-rt/lib/tsan/benchmarks/func_entry_exit.cpp (revision d11b16e1fef5886c73a7a6701b6e0264ae6b44d4)
1*d11b16e1SNico Weber // Synthetic benchmark for __tsan_func_entry/exit (spends ~75% there).
2*d11b16e1SNico Weber 
3*d11b16e1SNico Weber void foo(bool x);
4*d11b16e1SNico Weber 
main()5*d11b16e1SNico Weber int main() {
6*d11b16e1SNico Weber   volatile int kRepeat1 = 1 << 30;
7*d11b16e1SNico Weber   const int kRepeat = kRepeat1;
8*d11b16e1SNico Weber   for (int i = 0; i < kRepeat; i++)
9*d11b16e1SNico Weber     foo(false);
10*d11b16e1SNico Weber }
11*d11b16e1SNico Weber 
bar(volatile bool x)12*d11b16e1SNico Weber __attribute__((noinline)) void bar(volatile bool x) {
13*d11b16e1SNico Weber   if (x)
14*d11b16e1SNico Weber     foo(x);
15*d11b16e1SNico Weber }
16*d11b16e1SNico Weber 
foo(bool x)17*d11b16e1SNico Weber __attribute__((noinline)) void foo(bool x) {
18*d11b16e1SNico Weber   if (__builtin_expect(x, false))
19*d11b16e1SNico Weber     bar(x);
20*d11b16e1SNico Weber }
21