2 //===----------------------------------------------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.txt for details.
9 //===----------------------------------------------------------------------===//
11 #ifndef _ITTNOTIFY_CONFIG_H_
12 #define _ITTNOTIFY_CONFIG_H_
14 /** @cond exclude_from_documentation */
17 #endif /* ITT_OS_WIN */
20 # define ITT_OS_LINUX 2
21 #endif /* ITT_OS_LINUX */
25 #endif /* ITT_OS_MAC */
27 #ifndef ITT_OS_FREEBSD
28 # define ITT_OS_FREEBSD 4
29 #endif /* ITT_OS_FREEBSD */
32 # if defined WIN32 || defined _WIN32
33 # define ITT_OS ITT_OS_WIN
34 # elif defined( __APPLE__ ) && defined( __MACH__ )
35 # define ITT_OS ITT_OS_MAC
36 # elif defined( __FreeBSD__ )
37 # define ITT_OS ITT_OS_FREEBSD
39 # define ITT_OS ITT_OS_LINUX
43 #ifndef ITT_PLATFORM_WIN
44 # define ITT_PLATFORM_WIN 1
45 #endif /* ITT_PLATFORM_WIN */
47 #ifndef ITT_PLATFORM_POSIX
48 # define ITT_PLATFORM_POSIX 2
49 #endif /* ITT_PLATFORM_POSIX */
51 #ifndef ITT_PLATFORM_MAC
52 # define ITT_PLATFORM_MAC 3
53 #endif /* ITT_PLATFORM_MAC */
55 #ifndef ITT_PLATFORM_FREEBSD
56 # define ITT_PLATFORM_FREEBSD 4
57 #endif /* ITT_PLATFORM_FREEBSD */
60 # if ITT_OS==ITT_OS_WIN
61 # define ITT_PLATFORM ITT_PLATFORM_WIN
62 # elif ITT_OS==ITT_OS_MAC
63 # define ITT_PLATFORM ITT_PLATFORM_MAC
64 # elif ITT_OS==ITT_OS_FREEBSD
65 # define ITT_PLATFORM ITT_PLATFORM_FREEBSD
67 # define ITT_PLATFORM ITT_PLATFORM_POSIX
69 #endif /* ITT_PLATFORM */
71 #if defined(_UNICODE) && !defined(UNICODE)
76 #if ITT_PLATFORM==ITT_PLATFORM_WIN
78 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
80 #if defined(UNICODE) || defined(_UNICODE)
82 #endif /* UNICODE || _UNICODE */
83 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
86 # if ITT_PLATFORM==ITT_PLATFORM_WIN
87 # define ITTAPI_CDECL __cdecl
88 # else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
89 # if defined _M_IX86 || defined __i386__
90 # define ITTAPI_CDECL __attribute__ ((cdecl))
91 # else /* _M_IX86 || __i386__ */
92 # define ITTAPI_CDECL /* actual only on x86 platform */
93 # endif /* _M_IX86 || __i386__ */
94 # endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
95 #endif /* ITTAPI_CDECL */
98 # if ITT_PLATFORM==ITT_PLATFORM_WIN
99 # define STDCALL __stdcall
100 # else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
101 # if defined _M_IX86 || defined __i386__
102 # define STDCALL __attribute__ ((stdcall))
103 # else /* _M_IX86 || __i386__ */
104 # define STDCALL /* supported only on x86 platform */
105 # endif /* _M_IX86 || __i386__ */
106 # endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
109 #define ITTAPI ITTAPI_CDECL
110 #define LIBITTAPI ITTAPI_CDECL
112 /* TODO: Temporary for compatibility! */
113 #define ITTAPI_CALL ITTAPI_CDECL
114 #define LIBITTAPI_CALL ITTAPI_CDECL
116 #if ITT_PLATFORM==ITT_PLATFORM_WIN
117 /* use __forceinline (VC++ specific) */
118 #define ITT_INLINE __forceinline
119 #define ITT_INLINE_ATTRIBUTE /* nothing */
120 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
122 * Generally, functions are not inlined unless optimization is specified.
123 * For functions declared inline, this attribute inlines the function even
124 * if no optimization level was specified.
126 #ifdef __STRICT_ANSI__
127 #define ITT_INLINE static
128 #define ITT_INLINE_ATTRIBUTE __attribute__((unused))
129 #else /* __STRICT_ANSI__ */
130 #define ITT_INLINE static inline
131 #define ITT_INLINE_ATTRIBUTE __attribute__((always_inline, unused))
132 #endif /* __STRICT_ANSI__ */
133 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
136 #ifndef ITT_ARCH_IA32
137 # define ITT_ARCH_IA32 1
138 #endif /* ITT_ARCH_IA32 */
140 #ifndef ITT_ARCH_IA32E
141 # define ITT_ARCH_IA32E 2
142 #endif /* ITT_ARCH_IA32E */
144 /* Was there a magical reason we didn't have 3 here before? */
145 #ifndef ITT_ARCH_AARCH64
146 # define ITT_ARCH_AARCH64 3
147 #endif /* ITT_ARCH_AARCH64 */
150 # define ITT_ARCH_ARM 4
151 #endif /* ITT_ARCH_ARM */
153 #ifndef ITT_ARCH_PPC64
154 # define ITT_ARCH_PPC64 5
155 #endif /* ITT_ARCH_PPC64 */
157 #ifndef ITT_ARCH_MIPS
158 # define ITT_ARCH_MIPS 6
159 #endif /* ITT_ARCH_MIPS */
161 #ifndef ITT_ARCH_MIPS64
162 # define ITT_ARCH_MIPS64 6
163 #endif /* ITT_ARCH_MIPS64 */
166 # if defined _M_IX86 || defined __i386__
167 # define ITT_ARCH ITT_ARCH_IA32
168 # elif defined _M_X64 || defined _M_AMD64 || defined __x86_64__
169 # define ITT_ARCH ITT_ARCH_IA32E
170 # elif defined _M_IA64 || defined __ia64__
171 # define ITT_ARCH ITT_ARCH_IA64
172 # elif defined _M_ARM || defined __arm__
173 # define ITT_ARCH ITT_ARCH_ARM
174 # elif defined __powerpc64__
175 # define ITT_ARCH ITT_ARCH_PPC64
176 # elif defined __aarch64__
177 # define ITT_ARCH ITT_ARCH_AARCH64
178 # elif defined __mips__ && !defined __mips64
179 # define ITT_ARCH ITT_ARCH_MIPS
180 # elif defined __mips__ && defined __mips64
181 # define ITT_ARCH ITT_ARCH_MIPS64
186 # define ITT_EXTERN_C extern "C"
187 # define ITT_EXTERN_C_BEGIN extern "C" {
188 # define ITT_EXTERN_C_END }
190 # define ITT_EXTERN_C /* nothing */
191 # define ITT_EXTERN_C_BEGIN /* nothing */
192 # define ITT_EXTERN_C_END /* nothing */
193 #endif /* __cplusplus */
195 #define ITT_TO_STR_AUX(x) #x
196 #define ITT_TO_STR(x) ITT_TO_STR_AUX(x)
198 #define __ITT_BUILD_ASSERT(expr, suffix) do { \
199 static char __itt_build_check_##suffix[(expr) ? 1 : -1]; \
200 __itt_build_check_##suffix[0] = 0; \
202 #define _ITT_BUILD_ASSERT(expr, suffix) __ITT_BUILD_ASSERT((expr), suffix)
203 #define ITT_BUILD_ASSERT(expr) _ITT_BUILD_ASSERT((expr), __LINE__)
205 #define ITT_MAGIC { 0xED, 0xAB, 0xAB, 0xEC, 0x0D, 0xEE, 0xDA, 0x30 }
207 /* Replace with snapshot date YYYYMMDD for promotion build. */
208 #define API_VERSION_BUILD 20151119
210 #ifndef API_VERSION_NUM
211 #define API_VERSION_NUM 0.0.0
212 #endif /* API_VERSION_NUM */
214 #define API_VERSION "ITT-API-Version " ITT_TO_STR(API_VERSION_NUM) \
215 " (" ITT_TO_STR(API_VERSION_BUILD) ")"
217 /* OS communication functions */
218 #if ITT_PLATFORM==ITT_PLATFORM_WIN
220 typedef HMODULE lib_t;
222 typedef CRITICAL_SECTION mutex_t;
223 #define MUTEX_INITIALIZER { 0 }
224 #define strong_alias(name, aliasname) /* empty for Windows */
225 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
227 #if defined(UNICODE) || defined(_UNICODE)
231 #define _GNU_SOURCE 1 /* need for PTHREAD_MUTEX_RECURSIVE */
232 #endif /* _GNU_SOURCE */
234 #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 */
235 #endif /*__USE_UNIX98*/
238 typedef pthread_t TIDT;
239 typedef pthread_mutex_t mutex_t;
240 #define MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
241 #define _strong_alias(name, aliasname) \
242 extern __typeof (name) aliasname __attribute__ ((alias (#name)));
243 #define strong_alias(name, aliasname) _strong_alias(name, aliasname)
244 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
246 #if ITT_PLATFORM==ITT_PLATFORM_WIN
247 #define __itt_get_proc(lib, name) GetProcAddress(lib, name)
248 #define __itt_mutex_init(mutex) InitializeCriticalSection(mutex)
249 #define __itt_mutex_lock(mutex) EnterCriticalSection(mutex)
250 #define __itt_mutex_unlock(mutex) LeaveCriticalSection(mutex)
251 #define __itt_load_lib(name) LoadLibraryA(name)
252 #define __itt_unload_lib(handle) FreeLibrary(handle)
253 #define __itt_system_error() (int)GetLastError()
254 #define __itt_fstrcmp(s1, s2) lstrcmpA(s1, s2)
255 #define __itt_fstrnlen(s, l) strnlen_s(s, l)
256 #define __itt_fstrcpyn(s1, b, s2, l) strncpy_s(s1, b, s2, l)
257 #define __itt_fstrdup(s) _strdup(s)
258 #define __itt_thread_id() GetCurrentThreadId()
259 #define __itt_thread_yield() SwitchToThread()
260 #ifndef ITT_SIMPLE_INIT
262 __itt_interlocked_increment(volatile long* ptr) ITT_INLINE_ATTRIBUTE;
263 ITT_INLINE long __itt_interlocked_increment(volatile long* ptr)
265 return InterlockedIncrement(ptr);
267 #endif /* ITT_SIMPLE_INIT */
269 #define DL_SYMBOLS (1)
270 #define PTHREAD_SYMBOLS (1)
272 #else /* ITT_PLATFORM!=ITT_PLATFORM_WIN */
273 #define __itt_get_proc(lib, name) dlsym(lib, name)
274 #define __itt_mutex_init(mutex) {\
275 pthread_mutexattr_t mutex_attr; \
276 int error_code = pthread_mutexattr_init(&mutex_attr); \
278 __itt_report_error(__itt_error_system, "pthread_mutexattr_init", \
280 error_code = pthread_mutexattr_settype(&mutex_attr, \
281 PTHREAD_MUTEX_RECURSIVE); \
283 __itt_report_error(__itt_error_system, "pthread_mutexattr_settype", \
285 error_code = pthread_mutex_init(mutex, &mutex_attr); \
287 __itt_report_error(__itt_error_system, "pthread_mutex_init", \
289 error_code = pthread_mutexattr_destroy(&mutex_attr); \
291 __itt_report_error(__itt_error_system, "pthread_mutexattr_destroy", \
294 #define __itt_mutex_lock(mutex) pthread_mutex_lock(mutex)
295 #define __itt_mutex_unlock(mutex) pthread_mutex_unlock(mutex)
296 #define __itt_load_lib(name) dlopen(name, RTLD_LAZY)
297 #define __itt_unload_lib(handle) dlclose(handle)
298 #define __itt_system_error() errno
299 #define __itt_fstrcmp(s1, s2) strcmp(s1, s2)
301 /* makes customer code define safe APIs for SDL_STRNLEN_S and SDL_STRNCPY_S */
303 #define __itt_fstrnlen(s, l) SDL_STRNLEN_S(s, l)
305 #define __itt_fstrnlen(s, l) strlen(s)
306 #endif /* SDL_STRNLEN_S */
308 #define __itt_fstrcpyn(s1, b, s2, l) SDL_STRNCPY_S(s1, b, s2, l)
310 #define __itt_fstrcpyn(s1, b, s2, l) strncpy(s1, s2, l)
311 #endif /* SDL_STRNCPY_S */
313 #define __itt_fstrdup(s) strdup(s)
314 #define __itt_thread_id() pthread_self()
315 #define __itt_thread_yield() sched_yield()
316 #if ITT_ARCH==ITT_ARCH_IA64
317 #ifdef __INTEL_COMPILER
318 #define __TBB_machine_fetchadd4(addr, val) __fetchadd4_acq((void *)addr, val)
319 #else /* __INTEL_COMPILER */
320 /* TODO: Add Support for not Intel compilers for IA-64 architecture */
321 #endif /* __INTEL_COMPILER */
322 #elif ITT_ARCH==ITT_ARCH_IA32 || ITT_ARCH==ITT_ARCH_IA32E /* ITT_ARCH!=ITT_ARCH_IA64 */
324 __TBB_machine_fetchadd4(volatile void* ptr, long addend) ITT_INLINE_ATTRIBUTE;
325 ITT_INLINE long __TBB_machine_fetchadd4(volatile void* ptr, long addend)
328 __asm__ __volatile__("lock\nxadd %0,%1"
329 : "=r"(result),"=m"(*(volatile int*)ptr)
330 : "0"(addend), "m"(*(volatile int*)ptr)
334 #elif ITT_ARCH==ITT_ARCH_ARM || ITT_ARCH==ITT_ARCH_PPC64 || ITT_ARCH==ITT_ARCH_AARCH64 || ITT_ARCH==ITT_ARCH_MIPS || ITT_ARCH==ITT_ARCH_MIPS64
335 #define __TBB_machine_fetchadd4(addr, val) __sync_fetch_and_add(addr, val)
336 #endif /* ITT_ARCH==ITT_ARCH_IA64 */
337 #ifndef ITT_SIMPLE_INIT
339 __itt_interlocked_increment(volatile long* ptr) ITT_INLINE_ATTRIBUTE;
340 ITT_INLINE long __itt_interlocked_increment(volatile long* ptr)
342 return __TBB_machine_fetchadd4(ptr, 1) + 1L;
344 #endif /* ITT_SIMPLE_INIT */
346 void* dlopen(const char*, int) __attribute__((weak));
347 void* dlsym(void*, const char*) __attribute__((weak));
348 int dlclose(void*) __attribute__((weak));
349 #define DL_SYMBOLS (dlopen && dlsym && dlclose)
351 int pthread_mutex_init(pthread_mutex_t*, const pthread_mutexattr_t*) __attribute__((weak));
352 int pthread_mutex_lock(pthread_mutex_t*) __attribute__((weak));
353 int pthread_mutex_unlock(pthread_mutex_t*) __attribute__((weak));
354 int pthread_mutex_destroy(pthread_mutex_t*) __attribute__((weak));
355 int pthread_mutexattr_init(pthread_mutexattr_t*) __attribute__((weak));
356 int pthread_mutexattr_settype(pthread_mutexattr_t*, int) __attribute__((weak));
357 int pthread_mutexattr_destroy(pthread_mutexattr_t*) __attribute__((weak));
358 pthread_t pthread_self(void) __attribute__((weak));
359 #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)
361 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
364 __itt_collection_normal = 0,
365 __itt_collection_paused = 1
366 } __itt_collection_state;
369 __itt_thread_normal = 0,
370 __itt_thread_ignored = 1
371 } __itt_thread_state;
373 #pragma pack(push, 8)
375 typedef struct ___itt_thread_info
377 const char* nameA; /*!< Copy of original name in ASCII. */
378 #if defined(UNICODE) || defined(_UNICODE)
379 const wchar_t* nameW; /*!< Copy of original name in UNICODE. */
380 #else /* UNICODE || _UNICODE */
382 #endif /* UNICODE || _UNICODE */
384 __itt_thread_state state; /*!< Thread state (paused or normal) */
385 int extra1; /*!< Reserved to the runtime */
386 void* extra2; /*!< Reserved to the runtime */
387 struct ___itt_thread_info* next;
390 #include "ittnotify_types.h" /* For __itt_group_id definition */
392 typedef struct ___itt_api_info_20101001
397 __itt_group_id group;
398 } __itt_api_info_20101001;
400 typedef struct ___itt_api_info
406 __itt_group_id group;
409 typedef struct __itt_counter_info
411 const char* nameA; /*!< Copy of original name in ASCII. */
412 #if defined(UNICODE) || defined(_UNICODE)
413 const wchar_t* nameW; /*!< Copy of original name in UNICODE. */
414 #else /* UNICODE || _UNICODE */
416 #endif /* UNICODE || _UNICODE */
417 const char* domainA; /*!< Copy of original name in ASCII. */
418 #if defined(UNICODE) || defined(_UNICODE)
419 const wchar_t* domainW; /*!< Copy of original name in UNICODE. */
420 #else /* UNICODE || _UNICODE */
422 #endif /* UNICODE || _UNICODE */
425 int extra1; /*!< Reserved to the runtime */
426 void* extra2; /*!< Reserved to the runtime */
427 struct __itt_counter_info* next;
428 } __itt_counter_info_t;
430 struct ___itt_domain;
431 struct ___itt_string_handle;
433 typedef struct ___itt_global
435 unsigned char magic[8];
436 unsigned long version_major;
437 unsigned long version_minor;
438 unsigned long version_build;
439 volatile long api_initialized;
440 volatile long mutex_initialized;
441 volatile long atomic_counter;
445 const char** dll_path_ptr;
446 __itt_api_info* api_list_ptr;
447 struct ___itt_global* next;
448 /* Joinable structures below */
449 __itt_thread_info* thread_list;
450 struct ___itt_domain* domain_list;
451 struct ___itt_string_handle* string_list;
452 __itt_collection_state state;
453 __itt_counter_info_t* counter_list;
458 #define NEW_THREAD_INFO_W(gptr,h,h_tail,t,s,n) { \
459 h = (__itt_thread_info*)malloc(sizeof(__itt_thread_info)); \
463 h->nameW = n ? _wcsdup(n) : NULL; \
465 h->extra1 = 0; /* reserved */ \
466 h->extra2 = NULL; /* reserved */ \
468 if (h_tail == NULL) \
469 (gptr)->thread_list = h; \
475 #define NEW_THREAD_INFO_A(gptr,h,h_tail,t,s,n) { \
476 h = (__itt_thread_info*)malloc(sizeof(__itt_thread_info)); \
479 h->nameA = n ? __itt_fstrdup(n) : NULL; \
482 h->extra1 = 0; /* reserved */ \
483 h->extra2 = NULL; /* reserved */ \
485 if (h_tail == NULL) \
486 (gptr)->thread_list = h; \
492 #define NEW_DOMAIN_W(gptr,h,h_tail,name) { \
493 h = (__itt_domain*)malloc(sizeof(__itt_domain)); \
495 h->flags = 1; /* domain is enabled by default */ \
497 h->nameW = name ? _wcsdup(name) : NULL; \
498 h->extra1 = 0; /* reserved */ \
499 h->extra2 = NULL; /* reserved */ \
501 if (h_tail == NULL) \
502 (gptr)->domain_list = h; \
508 #define NEW_DOMAIN_A(gptr,h,h_tail,name) { \
509 h = (__itt_domain*)malloc(sizeof(__itt_domain)); \
511 h->flags = 1; /* domain is enabled by default */ \
512 h->nameA = name ? __itt_fstrdup(name) : NULL; \
514 h->extra1 = 0; /* reserved */ \
515 h->extra2 = NULL; /* reserved */ \
517 if (h_tail == NULL) \
518 (gptr)->domain_list = h; \
524 #define NEW_STRING_HANDLE_W(gptr,h,h_tail,name) { \
525 h = (__itt_string_handle*)malloc(sizeof(__itt_string_handle)); \
528 h->strW = name ? _wcsdup(name) : NULL; \
529 h->extra1 = 0; /* reserved */ \
530 h->extra2 = NULL; /* reserved */ \
532 if (h_tail == NULL) \
533 (gptr)->string_list = h; \
539 #define NEW_STRING_HANDLE_A(gptr,h,h_tail,name) { \
540 h = (__itt_string_handle*)malloc(sizeof(__itt_string_handle)); \
542 h->strA = name ? __itt_fstrdup(name) : NULL; \
544 h->extra1 = 0; /* reserved */ \
545 h->extra2 = NULL; /* reserved */ \
547 if (h_tail == NULL) \
548 (gptr)->string_list = h; \
554 #define NEW_COUNTER_W(gptr,h,h_tail,name,domain,type) { \
555 h = (__itt_counter_info_t*)malloc(sizeof(__itt_counter_info_t)); \
558 h->nameW = name ? _wcsdup(name) : NULL; \
560 h->domainW = name ? _wcsdup(domain) : NULL; \
564 if (h_tail == NULL) \
565 (gptr)->counter_list = h; \
571 #define NEW_COUNTER_A(gptr,h,h_tail,name,domain,type) { \
572 h = (__itt_counter_info_t*)malloc(sizeof(__itt_counter_info_t)); \
574 h->nameA = name ? __itt_fstrdup(name) : NULL; \
576 h->domainA = domain ? __itt_fstrdup(domain) : NULL; \
581 if (h_tail == NULL) \
582 (gptr)->counter_list = h; \
588 #endif /* _ITTNOTIFY_CONFIG_H_ */