2 //===----------------------------------------------------------------------===//
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 #ifndef _ITTNOTIFY_CONFIG_H_
11 #define _ITTNOTIFY_CONFIG_H_
13 /** @cond exclude_from_documentation */
16 #endif /* ITT_OS_WIN */
19 # define ITT_OS_LINUX 2
20 #endif /* ITT_OS_LINUX */
24 #endif /* ITT_OS_MAC */
26 #ifndef ITT_OS_FREEBSD
27 # define ITT_OS_FREEBSD 4
28 #endif /* ITT_OS_FREEBSD */
31 # if defined WIN32 || defined _WIN32
32 # define ITT_OS ITT_OS_WIN
33 # elif defined( __APPLE__ ) && defined( __MACH__ )
34 # define ITT_OS ITT_OS_MAC
35 # elif defined( __FreeBSD__ )
36 # define ITT_OS ITT_OS_FREEBSD
38 # define ITT_OS ITT_OS_LINUX
42 #ifndef ITT_PLATFORM_WIN
43 # define ITT_PLATFORM_WIN 1
44 #endif /* ITT_PLATFORM_WIN */
46 #ifndef ITT_PLATFORM_POSIX
47 # define ITT_PLATFORM_POSIX 2
48 #endif /* ITT_PLATFORM_POSIX */
50 #ifndef ITT_PLATFORM_MAC
51 # define ITT_PLATFORM_MAC 3
52 #endif /* ITT_PLATFORM_MAC */
54 #ifndef ITT_PLATFORM_FREEBSD
55 # define ITT_PLATFORM_FREEBSD 4
56 #endif /* ITT_PLATFORM_FREEBSD */
59 # if ITT_OS==ITT_OS_WIN
60 # define ITT_PLATFORM ITT_PLATFORM_WIN
61 # elif ITT_OS==ITT_OS_MAC
62 # define ITT_PLATFORM ITT_PLATFORM_MAC
63 # elif ITT_OS==ITT_OS_FREEBSD
64 # define ITT_PLATFORM ITT_PLATFORM_FREEBSD
66 # define ITT_PLATFORM ITT_PLATFORM_POSIX
68 #endif /* ITT_PLATFORM */
70 #if defined(_UNICODE) && !defined(UNICODE)
75 #if ITT_PLATFORM==ITT_PLATFORM_WIN
77 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
79 #if defined(UNICODE) || defined(_UNICODE)
81 #endif /* UNICODE || _UNICODE */
82 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
85 # if ITT_PLATFORM==ITT_PLATFORM_WIN
86 # define ITTAPI_CDECL __cdecl
87 # else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
88 # if defined _M_IX86 || defined __i386__
89 # define ITTAPI_CDECL __attribute__ ((cdecl))
90 # else /* _M_IX86 || __i386__ */
91 # define ITTAPI_CDECL /* actual only on x86 platform */
92 # endif /* _M_IX86 || __i386__ */
93 # endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
94 #endif /* ITTAPI_CDECL */
97 # if ITT_PLATFORM==ITT_PLATFORM_WIN
98 # define STDCALL __stdcall
99 # else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
100 # if defined _M_IX86 || defined __i386__
101 # define STDCALL __attribute__ ((stdcall))
102 # else /* _M_IX86 || __i386__ */
103 # define STDCALL /* supported only on x86 platform */
104 # endif /* _M_IX86 || __i386__ */
105 # endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
108 #define ITTAPI ITTAPI_CDECL
109 #define LIBITTAPI ITTAPI_CDECL
111 /* TODO: Temporary for compatibility! */
112 #define ITTAPI_CALL ITTAPI_CDECL
113 #define LIBITTAPI_CALL ITTAPI_CDECL
115 #if ITT_PLATFORM==ITT_PLATFORM_WIN
116 /* use __forceinline (VC++ specific) */
117 #define ITT_INLINE __forceinline
118 #define ITT_INLINE_ATTRIBUTE /* nothing */
119 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
121 * Generally, functions are not inlined unless optimization is specified.
122 * For functions declared inline, this attribute inlines the function even
123 * if no optimization level was specified.
125 #ifdef __STRICT_ANSI__
126 #define ITT_INLINE static
127 #define ITT_INLINE_ATTRIBUTE __attribute__((unused))
128 #else /* __STRICT_ANSI__ */
129 #define ITT_INLINE static inline
130 #define ITT_INLINE_ATTRIBUTE __attribute__((always_inline, unused))
131 #endif /* __STRICT_ANSI__ */
132 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
135 #ifndef ITT_ARCH_IA32
136 # define ITT_ARCH_IA32 1
137 #endif /* ITT_ARCH_IA32 */
139 #ifndef ITT_ARCH_IA32E
140 # define ITT_ARCH_IA32E 2
141 #endif /* ITT_ARCH_IA32E */
143 /* Was there a magical reason we didn't have 3 here before? */
144 #ifndef ITT_ARCH_AARCH64
145 # define ITT_ARCH_AARCH64 3
146 #endif /* ITT_ARCH_AARCH64 */
149 # define ITT_ARCH_ARM 4
150 #endif /* ITT_ARCH_ARM */
152 #ifndef ITT_ARCH_PPC64
153 # define ITT_ARCH_PPC64 5
154 #endif /* ITT_ARCH_PPC64 */
156 #ifndef ITT_ARCH_MIPS
157 # define ITT_ARCH_MIPS 6
158 #endif /* ITT_ARCH_MIPS */
160 #ifndef ITT_ARCH_MIPS64
161 # define ITT_ARCH_MIPS64 6
162 #endif /* ITT_ARCH_MIPS64 */
164 #ifndef ITT_ARCH_RISCV64
165 # define ITT_ARCH_RISCV64 7
166 #endif /* ITT_ARCH_RISCV64 */
169 # if defined _M_IX86 || defined __i386__
170 # define ITT_ARCH ITT_ARCH_IA32
171 # elif defined _M_X64 || defined _M_AMD64 || defined __x86_64__
172 # define ITT_ARCH ITT_ARCH_IA32E
173 # elif defined _M_IA64 || defined __ia64__
174 # define ITT_ARCH ITT_ARCH_IA64
175 # elif defined _M_ARM || defined __arm__
176 # define ITT_ARCH ITT_ARCH_ARM
177 # elif defined __powerpc64__
178 # define ITT_ARCH ITT_ARCH_PPC64
179 # elif defined __aarch64__
180 # define ITT_ARCH ITT_ARCH_AARCH64
181 # elif defined __mips__ && !defined __mips64
182 # define ITT_ARCH ITT_ARCH_MIPS
183 # elif defined __mips__ && defined __mips64
184 # define ITT_ARCH ITT_ARCH_MIPS64
185 # elif defined __riscv && __riscv_xlen == 64
186 # define ITT_ARCH ITT_ARCH_RISCV64
191 # define ITT_EXTERN_C extern "C"
192 # define ITT_EXTERN_C_BEGIN extern "C" {
193 # define ITT_EXTERN_C_END }
195 # define ITT_EXTERN_C /* nothing */
196 # define ITT_EXTERN_C_BEGIN /* nothing */
197 # define ITT_EXTERN_C_END /* nothing */
198 #endif /* __cplusplus */
200 #define ITT_TO_STR_AUX(x) #x
201 #define ITT_TO_STR(x) ITT_TO_STR_AUX(x)
203 #define __ITT_BUILD_ASSERT(expr, suffix) do { \
204 static char __itt_build_check_##suffix[(expr) ? 1 : -1]; \
205 __itt_build_check_##suffix[0] = 0; \
207 #define _ITT_BUILD_ASSERT(expr, suffix) __ITT_BUILD_ASSERT((expr), suffix)
208 #define ITT_BUILD_ASSERT(expr) _ITT_BUILD_ASSERT((expr), __LINE__)
210 #define ITT_MAGIC { 0xED, 0xAB, 0xAB, 0xEC, 0x0D, 0xEE, 0xDA, 0x30 }
212 /* Replace with snapshot date YYYYMMDD for promotion build. */
213 #define API_VERSION_BUILD 20151119
215 #ifndef API_VERSION_NUM
216 #define API_VERSION_NUM 0.0.0
217 #endif /* API_VERSION_NUM */
219 #define API_VERSION "ITT-API-Version " ITT_TO_STR(API_VERSION_NUM) \
220 " (" ITT_TO_STR(API_VERSION_BUILD) ")"
222 /* OS communication functions */
223 #if ITT_PLATFORM==ITT_PLATFORM_WIN
225 typedef HMODULE lib_t;
227 typedef CRITICAL_SECTION mutex_t;
228 #define MUTEX_INITIALIZER { 0 }
229 #define strong_alias(name, aliasname) /* empty for Windows */
230 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
232 #if defined(UNICODE) || defined(_UNICODE)
236 #define _GNU_SOURCE 1 /* need for PTHREAD_MUTEX_RECURSIVE */
237 #endif /* _GNU_SOURCE */
239 #define __USE_UNIX98 1 /* need for PTHREAD_MUTEX_RECURSIVE, on SLES11.1 with gcc 4.3.4 wherein pthread.h missing dependency on __USE_XOPEN2K8 */
240 #endif /*__USE_UNIX98*/
243 typedef pthread_t TIDT;
244 typedef pthread_mutex_t mutex_t;
245 #define MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
246 #define _strong_alias(name, aliasname) \
247 extern __typeof (name) aliasname __attribute__ ((alias (#name)));
248 #define strong_alias(name, aliasname) _strong_alias(name, aliasname)
249 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
251 #if ITT_PLATFORM==ITT_PLATFORM_WIN
252 #define __itt_get_proc(lib, name) GetProcAddress(lib, name)
253 #define __itt_mutex_init(mutex) InitializeCriticalSection(mutex)
254 #define __itt_mutex_lock(mutex) EnterCriticalSection(mutex)
255 #define __itt_mutex_unlock(mutex) LeaveCriticalSection(mutex)
256 #define __itt_load_lib(name) LoadLibraryA(name)
257 #define __itt_unload_lib(handle) FreeLibrary(handle)
258 #define __itt_system_error() (int)GetLastError()
259 #define __itt_fstrcmp(s1, s2) lstrcmpA(s1, s2)
260 #define __itt_fstrnlen(s, l) strnlen_s(s, l)
261 #define __itt_fstrcpyn(s1, b, s2, l) strncpy_s(s1, b, s2, l)
262 #define __itt_fstrdup(s) _strdup(s)
263 #define __itt_thread_id() GetCurrentThreadId()
264 #define __itt_thread_yield() SwitchToThread()
265 #ifndef ITT_SIMPLE_INIT
267 __itt_interlocked_increment(volatile long* ptr) ITT_INLINE_ATTRIBUTE;
268 ITT_INLINE long __itt_interlocked_increment(volatile long* ptr)
270 return InterlockedIncrement(ptr);
272 #endif /* ITT_SIMPLE_INIT */
274 #define DL_SYMBOLS (1)
275 #define PTHREAD_SYMBOLS (1)
277 #else /* ITT_PLATFORM!=ITT_PLATFORM_WIN */
278 #define __itt_get_proc(lib, name) dlsym(lib, name)
279 #define __itt_mutex_init(mutex) {\
280 pthread_mutexattr_t mutex_attr; \
281 int error_code = pthread_mutexattr_init(&mutex_attr); \
283 __itt_report_error(__itt_error_system, "pthread_mutexattr_init", \
285 error_code = pthread_mutexattr_settype(&mutex_attr, \
286 PTHREAD_MUTEX_RECURSIVE); \
288 __itt_report_error(__itt_error_system, "pthread_mutexattr_settype", \
290 error_code = pthread_mutex_init(mutex, &mutex_attr); \
292 __itt_report_error(__itt_error_system, "pthread_mutex_init", \
294 error_code = pthread_mutexattr_destroy(&mutex_attr); \
296 __itt_report_error(__itt_error_system, "pthread_mutexattr_destroy", \
299 #define __itt_mutex_lock(mutex) pthread_mutex_lock(mutex)
300 #define __itt_mutex_unlock(mutex) pthread_mutex_unlock(mutex)
301 #define __itt_load_lib(name) dlopen(name, RTLD_LAZY)
302 #define __itt_unload_lib(handle) dlclose(handle)
303 #define __itt_system_error() errno
304 #define __itt_fstrcmp(s1, s2) strcmp(s1, s2)
306 /* makes customer code define safe APIs for SDL_STRNLEN_S and SDL_STRNCPY_S */
308 #define __itt_fstrnlen(s, l) SDL_STRNLEN_S(s, l)
310 #define __itt_fstrnlen(s, l) strlen(s)
311 #endif /* SDL_STRNLEN_S */
313 #define __itt_fstrcpyn(s1, b, s2, l) SDL_STRNCPY_S(s1, b, s2, l)
315 #define __itt_fstrcpyn(s1, b, s2, l) strncpy(s1, s2, l)
316 #endif /* SDL_STRNCPY_S */
318 #define __itt_fstrdup(s) strdup(s)
319 #define __itt_thread_id() pthread_self()
320 #define __itt_thread_yield() sched_yield()
321 #if ITT_ARCH==ITT_ARCH_IA64
322 #ifdef __INTEL_COMPILER
323 #define __TBB_machine_fetchadd4(addr, val) __fetchadd4_acq((void *)addr, val)
324 #else /* __INTEL_COMPILER */
325 /* TODO: Add Support for not Intel compilers for IA-64 architecture */
326 #endif /* __INTEL_COMPILER */
327 #elif ITT_ARCH==ITT_ARCH_IA32 || ITT_ARCH==ITT_ARCH_IA32E /* ITT_ARCH!=ITT_ARCH_IA64 */
329 __TBB_machine_fetchadd4(volatile void* ptr, long addend) ITT_INLINE_ATTRIBUTE;
330 ITT_INLINE long __TBB_machine_fetchadd4(volatile void* ptr, long addend)
333 __asm__ __volatile__("lock\nxadd %0,%1"
334 : "=r"(result),"=m"(*(volatile int*)ptr)
335 : "0"(addend), "m"(*(volatile int*)ptr)
339 #elif ITT_ARCH == ITT_ARCH_ARM || ITT_ARCH == ITT_ARCH_PPC64 || \
340 ITT_ARCH == ITT_ARCH_AARCH64 || ITT_ARCH == ITT_ARCH_MIPS || \
341 ITT_ARCH == ITT_ARCH_MIPS64 || ITT_ARCH == ITT_ARCH_RISCV64
342 #define __TBB_machine_fetchadd4(addr, val) __sync_fetch_and_add(addr, val)
343 #endif /* ITT_ARCH==ITT_ARCH_IA64 */
344 #ifndef ITT_SIMPLE_INIT
346 __itt_interlocked_increment(volatile long* ptr) ITT_INLINE_ATTRIBUTE;
347 ITT_INLINE long __itt_interlocked_increment(volatile long* ptr)
349 return __TBB_machine_fetchadd4(ptr, 1) + 1L;
351 #endif /* ITT_SIMPLE_INIT */
353 void* dlopen(const char*, int) __attribute__((weak));
354 void* dlsym(void*, const char*) __attribute__((weak));
355 int dlclose(void*) __attribute__((weak));
356 #define DL_SYMBOLS (dlopen && dlsym && dlclose)
358 int pthread_mutex_init(pthread_mutex_t*, const pthread_mutexattr_t*) __attribute__((weak));
359 int pthread_mutex_lock(pthread_mutex_t*) __attribute__((weak));
360 int pthread_mutex_unlock(pthread_mutex_t*) __attribute__((weak));
361 int pthread_mutex_destroy(pthread_mutex_t*) __attribute__((weak));
362 int pthread_mutexattr_init(pthread_mutexattr_t*) __attribute__((weak));
363 int pthread_mutexattr_settype(pthread_mutexattr_t*, int) __attribute__((weak));
364 int pthread_mutexattr_destroy(pthread_mutexattr_t*) __attribute__((weak));
365 pthread_t pthread_self(void) __attribute__((weak));
366 #define PTHREAD_SYMBOLS (pthread_mutex_init && pthread_mutex_lock && pthread_mutex_unlock && pthread_mutex_destroy && pthread_mutexattr_init && pthread_mutexattr_settype && pthread_mutexattr_destroy && pthread_self)
368 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
371 __itt_collection_normal = 0,
372 __itt_collection_paused = 1
373 } __itt_collection_state;
376 __itt_thread_normal = 0,
377 __itt_thread_ignored = 1
378 } __itt_thread_state;
380 #pragma pack(push, 8)
382 typedef struct ___itt_thread_info
384 const char* nameA; /*!< Copy of original name in ASCII. */
385 #if defined(UNICODE) || defined(_UNICODE)
386 const wchar_t* nameW; /*!< Copy of original name in UNICODE. */
387 #else /* UNICODE || _UNICODE */
389 #endif /* UNICODE || _UNICODE */
391 __itt_thread_state state; /*!< Thread state (paused or normal) */
392 int extra1; /*!< Reserved to the runtime */
393 void* extra2; /*!< Reserved to the runtime */
394 struct ___itt_thread_info* next;
397 #include "ittnotify_types.h" /* For __itt_group_id definition */
399 typedef struct ___itt_api_info_20101001
404 __itt_group_id group;
405 } __itt_api_info_20101001;
407 typedef struct ___itt_api_info
413 __itt_group_id group;
416 typedef struct __itt_counter_info
418 const char* nameA; /*!< Copy of original name in ASCII. */
419 #if defined(UNICODE) || defined(_UNICODE)
420 const wchar_t* nameW; /*!< Copy of original name in UNICODE. */
421 #else /* UNICODE || _UNICODE */
423 #endif /* UNICODE || _UNICODE */
424 const char* domainA; /*!< Copy of original name in ASCII. */
425 #if defined(UNICODE) || defined(_UNICODE)
426 const wchar_t* domainW; /*!< Copy of original name in UNICODE. */
427 #else /* UNICODE || _UNICODE */
429 #endif /* UNICODE || _UNICODE */
432 int extra1; /*!< Reserved to the runtime */
433 void* extra2; /*!< Reserved to the runtime */
434 struct __itt_counter_info* next;
435 } __itt_counter_info_t;
437 struct ___itt_domain;
438 struct ___itt_string_handle;
440 typedef struct ___itt_global
442 unsigned char magic[8];
443 unsigned long version_major;
444 unsigned long version_minor;
445 unsigned long version_build;
446 volatile long api_initialized;
447 volatile long mutex_initialized;
448 volatile long atomic_counter;
452 const char** dll_path_ptr;
453 __itt_api_info* api_list_ptr;
454 struct ___itt_global* next;
455 /* Joinable structures below */
456 __itt_thread_info* thread_list;
457 struct ___itt_domain* domain_list;
458 struct ___itt_string_handle* string_list;
459 __itt_collection_state state;
460 __itt_counter_info_t* counter_list;
465 #define NEW_THREAD_INFO_W(gptr,h,h_tail,t,s,n) { \
466 h = (__itt_thread_info*)malloc(sizeof(__itt_thread_info)); \
470 h->nameW = n ? _wcsdup(n) : NULL; \
472 h->extra1 = 0; /* reserved */ \
473 h->extra2 = NULL; /* reserved */ \
475 if (h_tail == NULL) \
476 (gptr)->thread_list = h; \
482 #define NEW_THREAD_INFO_A(gptr,h,h_tail,t,s,n) { \
483 h = (__itt_thread_info*)malloc(sizeof(__itt_thread_info)); \
486 h->nameA = n ? __itt_fstrdup(n) : NULL; \
489 h->extra1 = 0; /* reserved */ \
490 h->extra2 = NULL; /* reserved */ \
492 if (h_tail == NULL) \
493 (gptr)->thread_list = h; \
499 #define NEW_DOMAIN_W(gptr,h,h_tail,name) { \
500 h = (__itt_domain*)malloc(sizeof(__itt_domain)); \
502 h->flags = 1; /* domain is enabled by default */ \
504 h->nameW = name ? _wcsdup(name) : NULL; \
505 h->extra1 = 0; /* reserved */ \
506 h->extra2 = NULL; /* reserved */ \
508 if (h_tail == NULL) \
509 (gptr)->domain_list = h; \
515 #define NEW_DOMAIN_A(gptr,h,h_tail,name) { \
516 h = (__itt_domain*)malloc(sizeof(__itt_domain)); \
518 h->flags = 1; /* domain is enabled by default */ \
519 h->nameA = name ? __itt_fstrdup(name) : NULL; \
521 h->extra1 = 0; /* reserved */ \
522 h->extra2 = NULL; /* reserved */ \
524 if (h_tail == NULL) \
525 (gptr)->domain_list = h; \
531 #define NEW_STRING_HANDLE_W(gptr,h,h_tail,name) { \
532 h = (__itt_string_handle*)malloc(sizeof(__itt_string_handle)); \
535 h->strW = name ? _wcsdup(name) : NULL; \
536 h->extra1 = 0; /* reserved */ \
537 h->extra2 = NULL; /* reserved */ \
539 if (h_tail == NULL) \
540 (gptr)->string_list = h; \
546 #define NEW_STRING_HANDLE_A(gptr,h,h_tail,name) { \
547 h = (__itt_string_handle*)malloc(sizeof(__itt_string_handle)); \
549 h->strA = name ? __itt_fstrdup(name) : NULL; \
551 h->extra1 = 0; /* reserved */ \
552 h->extra2 = NULL; /* reserved */ \
554 if (h_tail == NULL) \
555 (gptr)->string_list = h; \
561 #define NEW_COUNTER_W(gptr,h,h_tail,name,domain,type) { \
562 h = (__itt_counter_info_t*)malloc(sizeof(__itt_counter_info_t)); \
565 h->nameW = name ? _wcsdup(name) : NULL; \
567 h->domainW = name ? _wcsdup(domain) : NULL; \
571 if (h_tail == NULL) \
572 (gptr)->counter_list = h; \
578 #define NEW_COUNTER_A(gptr,h,h_tail,name,domain,type) { \
579 h = (__itt_counter_info_t*)malloc(sizeof(__itt_counter_info_t)); \
581 h->nameA = name ? __itt_fstrdup(name) : NULL; \
583 h->domainA = domain ? __itt_fstrdup(domain) : NULL; \
588 if (h_tail == NULL) \
589 (gptr)->counter_list = h; \
595 #endif /* _ITTNOTIFY_CONFIG_H_ */