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 #if defined(__MINGW32__) && !defined(__cplusplus)
119 static __inline__ __attribute__((__always_inline__, __gnu_inline__))
121 #define ITT_INLINE static __forceinline
122 #endif /* __MINGW32__ */
124 #define ITT_INLINE_ATTRIBUTE /* nothing */
125 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
127 * Generally, functions are not inlined unless optimization is specified.
128 * For functions declared inline, this attribute inlines the function even
129 * if no optimization level was specified.
131 #ifdef __STRICT_ANSI__
132 #define ITT_INLINE static
133 #define ITT_INLINE_ATTRIBUTE __attribute__((unused))
134 #else /* __STRICT_ANSI__ */
135 #define ITT_INLINE static inline
136 #define ITT_INLINE_ATTRIBUTE __attribute__((always_inline, unused))
137 #endif /* __STRICT_ANSI__ */
138 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
141 #ifndef ITT_ARCH_IA32
142 #define ITT_ARCH_IA32 1
143 #endif /* ITT_ARCH_IA32 */
145 #ifndef ITT_ARCH_IA32E
146 #define ITT_ARCH_IA32E 2
147 #endif /* ITT_ARCH_IA32E */
149 #ifndef ITT_ARCH_IA64
150 #define ITT_ARCH_IA64 3
151 #endif /* ITT_ARCH_IA64 */
154 #define ITT_ARCH_ARM 4
155 #endif /* ITT_ARCH_ARM */
157 #ifndef ITT_ARCH_PPC64
158 #define ITT_ARCH_PPC64 5
159 #endif /* ITT_ARCH_PPC64 */
161 #ifndef ITT_ARCH_ARM64
162 #define ITT_ARCH_ARM64 6
163 #endif /* ITT_ARCH_ARM64 */
166 #define ITT_ARCH_VE 8
167 #endif /* ITT_ARCH_VE */
170 #if defined _M_IX86 || defined __i386__
171 #define ITT_ARCH ITT_ARCH_IA32
172 #elif defined _M_X64 || defined _M_AMD64 || defined __x86_64__
173 #define ITT_ARCH ITT_ARCH_IA32E
174 #elif defined _M_IA64 || defined __ia64__
175 #define ITT_ARCH ITT_ARCH_IA64
176 #elif defined _M_ARM || defined __arm__
177 #define ITT_ARCH ITT_ARCH_ARM
178 #elif defined __aarch64__
179 #define ITT_ARCH ITT_ARCH_ARM64
180 #elif defined __powerpc64__
181 #define ITT_ARCH ITT_ARCH_PPC64
183 #define ITT_ARCH ITT_ARCH_VE
188 #define ITT_EXTERN_C extern "C"
189 #define ITT_EXTERN_C_BEGIN extern "C" {
190 #define ITT_EXTERN_C_END }
192 #define ITT_EXTERN_C /* nothing */
193 #define ITT_EXTERN_C_BEGIN /* nothing */
194 #define ITT_EXTERN_C_END /* nothing */
195 #endif /* __cplusplus */
197 #define ITT_TO_STR_AUX(x) #x
198 #define ITT_TO_STR(x) ITT_TO_STR_AUX(x)
200 #define __ITT_BUILD_ASSERT(expr, suffix) \
202 static char __itt_build_check_##suffix[(expr) ? 1 : -1]; \
203 __itt_build_check_##suffix[0] = 0; \
205 #define _ITT_BUILD_ASSERT(expr, suffix) __ITT_BUILD_ASSERT((expr), suffix)
206 #define ITT_BUILD_ASSERT(expr) _ITT_BUILD_ASSERT((expr), __LINE__)
209 { 0xED, 0xAB, 0xAB, 0xEC, 0x0D, 0xEE, 0xDA, 0x30 }
211 /* Replace with snapshot date YYYYMMDD for promotion build. */
212 #define API_VERSION_BUILD 20180723
214 #ifndef API_VERSION_NUM
215 #define API_VERSION_NUM 3.20.1
216 #endif /* API_VERSION_NUM */
218 #define API_VERSION \
219 "ITT-API-Version " ITT_TO_STR(API_VERSION_NUM) " (" ITT_TO_STR( \
220 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
;
229 #define MUTEX_INITIALIZER \
232 #define MUTEX_INITIALIZER \
235 #define strong_alias(name, aliasname) /* empty for Windows */
236 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
238 #if defined(UNICODE) || defined(_UNICODE)
242 #define _GNU_SOURCE 1 /* need for PTHREAD_MUTEX_RECURSIVE */
243 #endif /* _GNU_SOURCE */
245 #define __USE_UNIX98 \
246 1 /* need for PTHREAD_MUTEX_RECURSIVE, on SLES11.1 with gcc 4.3.4 wherein \
247 pthread.h missing dependency on __USE_XOPEN2K8 */
248 #endif /*__USE_UNIX98*/
251 typedef pthread_t TIDT
;
252 typedef pthread_mutex_t mutex_t
;
253 #define MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
254 #define _strong_alias(name, aliasname) \
255 extern __typeof(name) aliasname __attribute__((alias(#name)));
256 #define strong_alias(name, aliasname) _strong_alias(name, aliasname)
257 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
259 #if ITT_PLATFORM == ITT_PLATFORM_WIN
260 #define __itt_get_proc(lib, name) GetProcAddress(lib, name)
261 #define __itt_mutex_init(mutex) InitializeCriticalSection(mutex)
262 #define __itt_mutex_lock(mutex) EnterCriticalSection(mutex)
263 #define __itt_mutex_unlock(mutex) LeaveCriticalSection(mutex)
264 #define __itt_load_lib(name) LoadLibraryA(name)
265 #define __itt_unload_lib(handle) FreeLibrary(handle)
266 #define __itt_system_error() (int)GetLastError()
267 #define __itt_fstrcmp(s1, s2) lstrcmpA(s1, s2)
268 #define __itt_fstrnlen(s, l) strnlen_s(s, l)
269 #define __itt_fstrcpyn(s1, b, s2, l) strncpy_s(s1, b, s2, l)
270 #define __itt_fstrdup(s) _strdup(s)
271 #define __itt_thread_id() GetCurrentThreadId()
272 #define __itt_thread_yield() SwitchToThread()
273 #ifndef ITT_SIMPLE_INIT
275 __itt_interlocked_increment(volatile long *ptr
) ITT_INLINE_ATTRIBUTE
;
276 ITT_INLINE
long __itt_interlocked_increment(volatile long *ptr
) {
277 return InterlockedIncrement(ptr
);
279 #endif /* ITT_SIMPLE_INIT */
281 #define DL_SYMBOLS (1)
282 #define PTHREAD_SYMBOLS (1)
284 #else /* ITT_PLATFORM!=ITT_PLATFORM_WIN */
285 #define __itt_get_proc(lib, name) dlsym(lib, name)
286 #define __itt_mutex_init(mutex) \
288 pthread_mutexattr_t mutex_attr; \
289 int error_code = pthread_mutexattr_init(&mutex_attr); \
291 __itt_report_error(__itt_error_system, "pthread_mutexattr_init", \
294 pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE); \
296 __itt_report_error(__itt_error_system, "pthread_mutexattr_settype", \
298 error_code = pthread_mutex_init(mutex, &mutex_attr); \
300 __itt_report_error(__itt_error_system, "pthread_mutex_init", \
302 error_code = pthread_mutexattr_destroy(&mutex_attr); \
304 __itt_report_error(__itt_error_system, "pthread_mutexattr_destroy", \
307 #define __itt_mutex_lock(mutex) pthread_mutex_lock(mutex)
308 #define __itt_mutex_unlock(mutex) pthread_mutex_unlock(mutex)
309 #define __itt_load_lib(name) dlopen(name, RTLD_LAZY)
310 #define __itt_unload_lib(handle) dlclose(handle)
311 #define __itt_system_error() errno
312 #define __itt_fstrcmp(s1, s2) strcmp(s1, s2)
314 /* makes customer code define safe APIs for SDL_STRNLEN_S and SDL_STRNCPY_S */
316 #define __itt_fstrnlen(s, l) SDL_STRNLEN_S(s, l)
318 #define __itt_fstrnlen(s, l) strlen(s)
319 #endif /* SDL_STRNLEN_S */
321 #define __itt_fstrcpyn(s1, b, s2, l) SDL_STRNCPY_S(s1, b, s2, l)
323 #define __itt_fstrcpyn(s1, b, s2, l) \
326 /* 'volatile' is used to suppress the warning that a destination */ \
327 /* bound depends on the length of the source. */ \
328 volatile size_t num_to_copy = \
329 (size_t)(b - 1) < (size_t)(l) ? (size_t)(b - 1) : (size_t)(l); \
330 strncpy(s1, s2, num_to_copy); \
331 s1[num_to_copy] = 0; \
334 #endif /* SDL_STRNCPY_S */
336 #define __itt_fstrdup(s) strdup(s)
337 #define __itt_thread_id() pthread_self()
338 #define __itt_thread_yield() sched_yield()
339 #if ITT_ARCH == ITT_ARCH_IA64
340 #ifdef __INTEL_COMPILER
341 #define __TBB_machine_fetchadd4(addr, val) __fetchadd4_acq((void *)addr, val)
342 #else /* __INTEL_COMPILER */
343 /* TODO: Add Support for not Intel compilers for IA-64 architecture */
344 #endif /* __INTEL_COMPILER */
345 #elif ITT_ARCH == ITT_ARCH_IA32 || \
346 ITT_ARCH == ITT_ARCH_IA32E /* ITT_ARCH!=ITT_ARCH_IA64 */
347 ITT_INLINE
long __TBB_machine_fetchadd4(volatile void *ptr
,
348 long addend
) ITT_INLINE_ATTRIBUTE
;
349 ITT_INLINE
long __TBB_machine_fetchadd4(volatile void *ptr
, long addend
) {
351 __asm__
__volatile__("lock\nxadd %0,%1"
352 : "=r"(result
), "=m"(*(volatile int *)ptr
)
353 : "0"(addend
), "m"(*(volatile int *)ptr
)
358 #define __TBB_machine_fetchadd4(addr, val) __sync_fetch_and_add(addr, val)
359 #endif /* ITT_ARCH==ITT_ARCH_IA64 */
360 #ifndef ITT_SIMPLE_INIT
362 __itt_interlocked_increment(volatile long *ptr
) ITT_INLINE_ATTRIBUTE
;
363 ITT_INLINE
long __itt_interlocked_increment(volatile long *ptr
) {
364 return __TBB_machine_fetchadd4(ptr
, 1) + 1L;
366 #endif /* ITT_SIMPLE_INIT */
368 void *dlopen(const char *, int) __attribute__((weak
));
369 void *dlsym(void *, const char *) __attribute__((weak
));
370 int dlclose(void *) __attribute__((weak
));
371 #define DL_SYMBOLS (dlopen && dlsym && dlclose)
373 int pthread_mutex_init(pthread_mutex_t
*, const pthread_mutexattr_t
*)
374 __attribute__((weak
));
375 int pthread_mutex_lock(pthread_mutex_t
*) __attribute__((weak
));
376 int pthread_mutex_unlock(pthread_mutex_t
*) __attribute__((weak
));
377 int pthread_mutex_destroy(pthread_mutex_t
*) __attribute__((weak
));
378 int pthread_mutexattr_init(pthread_mutexattr_t
*) __attribute__((weak
));
379 int pthread_mutexattr_settype(pthread_mutexattr_t
*, int) __attribute__((weak
));
380 int pthread_mutexattr_destroy(pthread_mutexattr_t
*) __attribute__((weak
));
381 pthread_t
pthread_self(void) __attribute__((weak
));
382 #define PTHREAD_SYMBOLS \
383 (pthread_mutex_init && pthread_mutex_lock && pthread_mutex_unlock && \
384 pthread_mutex_destroy && pthread_mutexattr_init && \
385 pthread_mutexattr_settype && pthread_mutexattr_destroy && pthread_self)
387 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
390 __itt_collection_normal
= 0,
391 __itt_collection_paused
= 1
392 } __itt_collection_state
;
395 __itt_thread_normal
= 0,
396 __itt_thread_ignored
= 1
397 } __itt_thread_state
;
399 #pragma pack(push, 8)
401 typedef struct ___itt_thread_info
{
402 const char *nameA
; /*!< Copy of original name in ASCII. */
403 #if defined(UNICODE) || defined(_UNICODE)
404 const wchar_t *nameW
; /*!< Copy of original name in UNICODE. */
405 #else /* UNICODE || _UNICODE */
407 #endif /* UNICODE || _UNICODE */
409 __itt_thread_state state
; /*!< Thread state (paused or normal) */
410 int extra1
; /*!< Reserved to the runtime */
411 void *extra2
; /*!< Reserved to the runtime */
412 struct ___itt_thread_info
*next
;
415 #include "ittnotify_types.h" /* For __itt_group_id definition */
417 typedef struct ___itt_api_info_20101001
{
421 __itt_group_id group
;
422 } __itt_api_info_20101001
;
424 typedef struct ___itt_api_info
{
429 __itt_group_id group
;
432 typedef struct __itt_counter_info
{
433 const char *nameA
; /*!< Copy of original name in ASCII. */
434 #if defined(UNICODE) || defined(_UNICODE)
435 const wchar_t *nameW
; /*!< Copy of original name in UNICODE. */
436 #else /* UNICODE || _UNICODE */
438 #endif /* UNICODE || _UNICODE */
439 const char *domainA
; /*!< Copy of original name in ASCII. */
440 #if defined(UNICODE) || defined(_UNICODE)
441 const wchar_t *domainW
; /*!< Copy of original name in UNICODE. */
442 #else /* UNICODE || _UNICODE */
444 #endif /* UNICODE || _UNICODE */
447 int extra1
; /*!< Reserved to the runtime */
448 void *extra2
; /*!< Reserved to the runtime */
449 struct __itt_counter_info
*next
;
450 } __itt_counter_info_t
;
452 struct ___itt_domain
;
453 struct ___itt_string_handle
;
454 struct ___itt_histogram
;
456 typedef struct ___itt_global
{
457 unsigned char magic
[8];
458 unsigned long version_major
;
459 unsigned long version_minor
;
460 unsigned long version_build
;
461 volatile long api_initialized
;
462 volatile long mutex_initialized
;
463 volatile long atomic_counter
;
467 const char **dll_path_ptr
;
468 __itt_api_info
*api_list_ptr
;
469 struct ___itt_global
*next
;
470 /* Joinable structures below */
471 __itt_thread_info
*thread_list
;
472 struct ___itt_domain
*domain_list
;
473 struct ___itt_string_handle
*string_list
;
474 __itt_collection_state state
;
475 __itt_counter_info_t
*counter_list
;
476 unsigned int ipt_collect_events
;
477 struct ___itt_histogram
*histogram_list
;
482 #define NEW_THREAD_INFO_W(gptr, h, h_tail, t, s, n) \
484 h = (__itt_thread_info *)malloc(sizeof(__itt_thread_info)); \
488 h->nameW = n ? _wcsdup(n) : NULL; \
490 h->extra1 = 0; /* reserved */ \
491 h->extra2 = NULL; /* reserved */ \
493 if (h_tail == NULL) \
494 (gptr)->thread_list = h; \
500 #define NEW_THREAD_INFO_A(gptr, h, h_tail, t, s, n) \
502 h = (__itt_thread_info *)malloc(sizeof(__itt_thread_info)); \
505 h->nameA = n ? __itt_fstrdup(n) : NULL; \
508 h->extra1 = 0; /* reserved */ \
509 h->extra2 = NULL; /* reserved */ \
511 if (h_tail == NULL) \
512 (gptr)->thread_list = h; \
518 #define NEW_DOMAIN_W(gptr, h, h_tail, name) \
520 h = (__itt_domain *)malloc(sizeof(__itt_domain)); \
522 h->flags = 1; /* domain is enabled by default */ \
524 h->nameW = name ? _wcsdup(name) : NULL; \
525 h->extra1 = 0; /* reserved */ \
526 h->extra2 = NULL; /* reserved */ \
528 if (h_tail == NULL) \
529 (gptr)->domain_list = h; \
535 #define NEW_DOMAIN_A(gptr, h, h_tail, name) \
537 h = (__itt_domain *)malloc(sizeof(__itt_domain)); \
539 h->flags = 1; /* domain is enabled by default */ \
540 h->nameA = name ? __itt_fstrdup(name) : NULL; \
542 h->extra1 = 0; /* reserved */ \
543 h->extra2 = NULL; /* reserved */ \
545 if (h_tail == NULL) \
546 (gptr)->domain_list = h; \
552 #define NEW_STRING_HANDLE_W(gptr, h, h_tail, name) \
554 h = (__itt_string_handle *)malloc(sizeof(__itt_string_handle)); \
557 h->strW = name ? _wcsdup(name) : NULL; \
558 h->extra1 = 0; /* reserved */ \
559 h->extra2 = NULL; /* reserved */ \
561 if (h_tail == NULL) \
562 (gptr)->string_list = h; \
568 #define NEW_STRING_HANDLE_A(gptr, h, h_tail, name) \
570 h = (__itt_string_handle *)malloc(sizeof(__itt_string_handle)); \
572 h->strA = name ? __itt_fstrdup(name) : NULL; \
574 h->extra1 = 0; /* reserved */ \
575 h->extra2 = NULL; /* reserved */ \
577 if (h_tail == NULL) \
578 (gptr)->string_list = h; \
584 #define NEW_COUNTER_W(gptr, h, h_tail, name, domain, type) \
586 h = (__itt_counter_info_t *)malloc(sizeof(__itt_counter_info_t)); \
589 h->nameW = name ? _wcsdup(name) : NULL; \
591 h->domainW = name ? _wcsdup(domain) : NULL; \
595 if (h_tail == NULL) \
596 (gptr)->counter_list = h; \
602 #define NEW_COUNTER_A(gptr, h, h_tail, name, domain, type) \
604 h = (__itt_counter_info_t *)malloc(sizeof(__itt_counter_info_t)); \
606 h->nameA = name ? __itt_fstrdup(name) : NULL; \
608 h->domainA = domain ? __itt_fstrdup(domain) : NULL; \
613 if (h_tail == NULL) \
614 (gptr)->counter_list = h; \
620 #define NEW_HISTOGRAM_W(gptr, h, h_tail, domain, name, x_type, y_type) \
622 h = (__itt_histogram *)malloc(sizeof(__itt_histogram)); \
624 h->domain = domain; \
626 h->nameW = name ? _wcsdup(name) : NULL; \
627 h->x_type = x_type; \
628 h->y_type = y_type; \
631 if (h_tail == NULL) \
632 (gptr)->histogram_list = h; \
638 #define NEW_HISTOGRAM_A(gptr, h, h_tail, domain, name, x_type, y_type) \
640 h = (__itt_histogram *)malloc(sizeof(__itt_histogram)); \
642 h->domain = domain; \
643 h->nameA = name ? __itt_fstrdup(name) : NULL; \
645 h->x_type = x_type; \
646 h->y_type = y_type; \
649 if (h_tail == NULL) \
650 (gptr)->histogram_list = h; \
656 #endif /* _ITTNOTIFY_CONFIG_H_ */