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