1 #include "HalideRuntime.h" 2 3 extern "C" { 4 halide_profiler_set_current_func(halide_profiler_state * state,int tok,int t)5WEAK_INLINE int halide_profiler_set_current_func(halide_profiler_state *state, int tok, int t) { 6 // Use empty volatile asm blocks to prevent code motion. Otherwise 7 // llvm reorders or elides the stores. 8 volatile int *ptr = &(state->current_func); 9 // clang-format off 10 asm volatile ("":::); 11 *ptr = tok + t; 12 asm volatile ("":::); 13 // clang-format on 14 return 0; 15 } 16 halide_profiler_incr_active_threads(halide_profiler_state * state)17WEAK_INLINE int halide_profiler_incr_active_threads(halide_profiler_state *state) { 18 volatile int *ptr = &(state->active_threads); 19 // clang-format off 20 asm volatile ("":::); 21 int ret = __sync_fetch_and_add(ptr, 1); 22 asm volatile ("":::); 23 // clang-format on 24 return ret; 25 } 26 halide_profiler_decr_active_threads(halide_profiler_state * state)27WEAK_INLINE int halide_profiler_decr_active_threads(halide_profiler_state *state) { 28 volatile int *ptr = &(state->active_threads); 29 // clang-format off 30 asm volatile ("":::); 31 int ret = __sync_fetch_and_sub(ptr, 1); 32 asm volatile ("":::); 33 // clang-format on 34 return ret; 35 } 36 } 37