1 /*===-- ittnotify_config.h - JIT Profiling API internal config-----*- C -*-===*
3 * The LLVM Compiler Infrastructure
5 * This file is distributed under the University of Illinois Open Source
6 * License. See LICENSE.TXT for details.
8 *===----------------------------------------------------------------------===*
10 * This file provides Intel(R) Performance Analyzer JIT (Just-In-Time)
11 * Profiling API internal config.
13 * NOTE: This file comes in a style different from the rest of LLVM
14 * source base since this is a piece of code shared from Intel(R)
15 * products. Please do not reformat / re-style this code to make
16 * subsequent merges and contributions from the original source base eaiser.
18 *===----------------------------------------------------------------------===*/
19 #ifndef _ITTNOTIFY_CONFIG_H_
20 #define _ITTNOTIFY_CONFIG_H_
22 /** @cond exclude_from_documentation */
25 #endif /* ITT_OS_WIN */
28 # define ITT_OS_LINUX 2
29 #endif /* ITT_OS_LINUX */
33 #endif /* ITT_OS_MAC */
36 # if defined WIN32 || defined _WIN32
37 # define ITT_OS ITT_OS_WIN
38 # elif defined( __APPLE__ ) && defined( __MACH__ )
39 # define ITT_OS ITT_OS_MAC
41 # define ITT_OS ITT_OS_LINUX
45 #ifndef ITT_PLATFORM_WIN
46 # define ITT_PLATFORM_WIN 1
47 #endif /* ITT_PLATFORM_WIN */
49 #ifndef ITT_PLATFORM_POSIX
50 # define ITT_PLATFORM_POSIX 2
51 #endif /* ITT_PLATFORM_POSIX */
54 # if ITT_OS==ITT_OS_WIN
55 # define ITT_PLATFORM ITT_PLATFORM_WIN
57 # define ITT_PLATFORM ITT_PLATFORM_POSIX
59 #endif /* ITT_PLATFORM */
61 #if defined(_UNICODE) && !defined(UNICODE)
66 #if ITT_PLATFORM==ITT_PLATFORM_WIN
68 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
70 #if defined(UNICODE) || defined(_UNICODE)
72 #endif /* UNICODE || _UNICODE */
73 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
76 # if ITT_PLATFORM==ITT_PLATFORM_WIN
77 # define CDECL __cdecl
78 # else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
79 # if defined _M_X64 || defined _M_AMD64 || defined __x86_64__
80 # define CDECL /* not actual on x86_64 platform */
81 # else /* _M_X64 || _M_AMD64 || __x86_64__ */
82 # define CDECL __attribute__ ((cdecl))
83 # endif /* _M_X64 || _M_AMD64 || __x86_64__ */
84 # endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
88 # if ITT_PLATFORM==ITT_PLATFORM_WIN
89 # define STDCALL __stdcall
90 # else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
91 # if defined _M_X64 || defined _M_AMD64 || defined __x86_64__
92 # define STDCALL /* not supported on x86_64 platform */
93 # else /* _M_X64 || _M_AMD64 || __x86_64__ */
94 # define STDCALL __attribute__ ((stdcall))
95 # endif /* _M_X64 || _M_AMD64 || __x86_64__ */
96 # endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
100 #define LIBITTAPI CDECL
102 /* TODO: Temporary for compatibility! */
103 #define ITTAPI_CALL CDECL
104 #define LIBITTAPI_CALL CDECL
106 #if ITT_PLATFORM==ITT_PLATFORM_WIN
107 /* use __forceinline (VC++ specific) */
108 #define ITT_INLINE __forceinline
109 #define ITT_INLINE_ATTRIBUTE /* nothing */
110 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
112 * Generally, functions are not inlined unless optimization is specified.
113 * For functions declared inline, this attribute inlines the function even
114 * if no optimization level was specified.
116 #ifdef __STRICT_ANSI__
117 #define ITT_INLINE static
118 #else /* __STRICT_ANSI__ */
119 #define ITT_INLINE static inline
120 #endif /* __STRICT_ANSI__ */
121 #define ITT_INLINE_ATTRIBUTE __attribute__ ((always_inline))
122 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
125 #ifndef ITT_ARCH_IA32
126 # define ITT_ARCH_IA32 1
127 #endif /* ITT_ARCH_IA32 */
129 #ifndef ITT_ARCH_IA32E
130 # define ITT_ARCH_IA32E 2
131 #endif /* ITT_ARCH_IA32E */
133 #ifndef ITT_ARCH_IA64
134 # define ITT_ARCH_IA64 3
135 #endif /* ITT_ARCH_IA64 */
138 # if defined _M_X64 || defined _M_AMD64 || defined __x86_64__
139 # define ITT_ARCH ITT_ARCH_IA32E
140 # elif defined _M_IA64 || defined __ia64
141 # define ITT_ARCH ITT_ARCH_IA64
143 # define ITT_ARCH ITT_ARCH_IA32
148 # define ITT_EXTERN_C extern "C"
150 # define ITT_EXTERN_C /* nothing */
151 #endif /* __cplusplus */
153 #define ITT_TO_STR_AUX(x) #x
154 #define ITT_TO_STR(x) ITT_TO_STR_AUX(x)
156 #define __ITT_BUILD_ASSERT(expr, suffix) do { \
157 static char __itt_build_check_##suffix[(expr) ? 1 : -1]; \
158 __itt_build_check_##suffix[0] = 0; \
160 #define _ITT_BUILD_ASSERT(expr, suffix) __ITT_BUILD_ASSERT((expr), suffix)
161 #define ITT_BUILD_ASSERT(expr) _ITT_BUILD_ASSERT((expr), __LINE__)
163 #define ITT_MAGIC { 0xED, 0xAB, 0xAB, 0xEC, 0x0D, 0xEE, 0xDA, 0x30 }
165 /* Replace with snapshot date YYYYMMDD for promotion build. */
166 #define API_VERSION_BUILD 20111111
168 #ifndef API_VERSION_NUM
169 #define API_VERSION_NUM 0.0.0
170 #endif /* API_VERSION_NUM */
172 #define API_VERSION "ITT-API-Version " ITT_TO_STR(API_VERSION_NUM) \
173 " (" ITT_TO_STR(API_VERSION_BUILD) ")"
175 /* OS communication functions */
176 #if ITT_PLATFORM==ITT_PLATFORM_WIN
178 typedef HMODULE lib_t;
180 typedef CRITICAL_SECTION mutex_t;
181 #define MUTEX_INITIALIZER { 0 }
182 #define strong_alias(name, aliasname) /* empty for Windows */
183 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
185 #if defined(UNICODE) || defined(_UNICODE)
189 #define _GNU_SOURCE 1 /* need for PTHREAD_MUTEX_RECURSIVE */
190 #endif /* _GNU_SOURCE */
193 typedef pthread_t TIDT;
194 typedef pthread_mutex_t mutex_t;
195 #define MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
196 #define _strong_alias(name, aliasname) \
197 extern __typeof (name) aliasname __attribute__ ((alias (#name)));
198 #define strong_alias(name, aliasname) _strong_alias(name, aliasname)
199 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
201 #if ITT_PLATFORM==ITT_PLATFORM_WIN
202 #define __itt_get_proc(lib, name) GetProcAddress(lib, name)
203 #define __itt_mutex_init(mutex) InitializeCriticalSection(mutex)
204 #define __itt_mutex_lock(mutex) EnterCriticalSection(mutex)
205 #define __itt_mutex_unlock(mutex) LeaveCriticalSection(mutex)
206 #define __itt_load_lib(name) LoadLibraryA(name)
207 #define __itt_unload_lib(handle) FreeLibrary(handle)
208 #define __itt_system_error() (int)GetLastError()
209 #define __itt_fstrcmp(s1, s2) lstrcmpA(s1, s2)
210 #define __itt_fstrlen(s) lstrlenA(s)
211 #define __itt_fstrcpyn(s1, s2, l) lstrcpynA(s1, s2, l)
212 #define __itt_fstrdup(s) _strdup(s)
213 #define __itt_thread_id() GetCurrentThreadId()
214 #define __itt_thread_yield() SwitchToThread()
215 #ifndef ITT_SIMPLE_INIT
217 __itt_interlocked_increment(volatile long* ptr) ITT_INLINE_ATTRIBUTE;
218 ITT_INLINE long __itt_interlocked_increment(volatile long* ptr)
220 return InterlockedIncrement(ptr);
222 #endif /* ITT_SIMPLE_INIT */
223 #else /* ITT_PLATFORM!=ITT_PLATFORM_WIN */
224 #define __itt_get_proc(lib, name) dlsym(lib, name)
225 #define __itt_mutex_init(mutex) {\
226 pthread_mutexattr_t mutex_attr; \
227 int error_code = pthread_mutexattr_init(&mutex_attr); \
229 __itt_report_error(__itt_error_system, "pthread_mutexattr_init", \
231 error_code = pthread_mutexattr_settype(&mutex_attr, \
232 PTHREAD_MUTEX_RECURSIVE); \
234 __itt_report_error(__itt_error_system, "pthread_mutexattr_settype", \
236 error_code = pthread_mutex_init(mutex, &mutex_attr); \
238 __itt_report_error(__itt_error_system, "pthread_mutex_init", \
240 error_code = pthread_mutexattr_destroy(&mutex_attr); \
242 __itt_report_error(__itt_error_system, "pthread_mutexattr_destroy", \
245 #define __itt_mutex_lock(mutex) pthread_mutex_lock(mutex)
246 #define __itt_mutex_unlock(mutex) pthread_mutex_unlock(mutex)
247 #define __itt_load_lib(name) dlopen(name, RTLD_LAZY)
248 #define __itt_unload_lib(handle) dlclose(handle)
249 #define __itt_system_error() errno
250 #define __itt_fstrcmp(s1, s2) strcmp(s1, s2)
251 #define __itt_fstrlen(s) strlen(s)
252 #define __itt_fstrcpyn(s1, s2, l) strncpy(s1, s2, l)
253 #define __itt_fstrdup(s) strdup(s)
254 #define __itt_thread_id() pthread_self()
255 #define __itt_thread_yield() sched_yield()
256 #if ITT_ARCH==ITT_ARCH_IA64
257 #ifdef __INTEL_COMPILER
258 #define __TBB_machine_fetchadd4(addr, val) __fetchadd4_acq((void *)addr, val)
259 #else /* __INTEL_COMPILER */
260 /* TODO: Add Support for not Intel compilers for IA64 */
261 #endif /* __INTEL_COMPILER */
262 #else /* ITT_ARCH!=ITT_ARCH_IA64 */
264 __TBB_machine_fetchadd4(volatile void* ptr, long addend) ITT_INLINE_ATTRIBUTE;
265 ITT_INLINE long __TBB_machine_fetchadd4(volatile void* ptr, long addend)
268 __asm__ __volatile__("lock\nxadd %0,%1"
269 : "=r"(result),"=m"(*(long*)ptr)
270 : "0"(addend), "m"(*(long*)ptr)
274 #endif /* ITT_ARCH==ITT_ARCH_IA64 */
275 #ifndef ITT_SIMPLE_INIT
277 __itt_interlocked_increment(volatile long* ptr) ITT_INLINE_ATTRIBUTE;
278 ITT_INLINE long __itt_interlocked_increment(volatile long* ptr)
280 return __TBB_machine_fetchadd4(ptr, 1) + 1L;
282 #endif /* ITT_SIMPLE_INIT */
283 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
286 __itt_collection_normal = 0,
287 __itt_collection_paused = 1
288 } __itt_collection_state;
291 __itt_thread_normal = 0,
292 __itt_thread_ignored = 1
293 } __itt_thread_state;
295 #pragma pack(push, 8)
297 typedef struct ___itt_thread_info
299 const char* nameA; /*!< Copy of original name in ASCII. */
300 #if defined(UNICODE) || defined(_UNICODE)
301 const wchar_t* nameW; /*!< Copy of original name in UNICODE. */
302 #else /* UNICODE || _UNICODE */
304 #endif /* UNICODE || _UNICODE */
306 __itt_thread_state state; /*!< Thread state (paused or normal) */
307 int extra1; /*!< Reserved to the runtime */
308 void* extra2; /*!< Reserved to the runtime */
309 struct ___itt_thread_info* next;
312 #include "ittnotify_types.h" /* For __itt_group_id definition */
314 typedef struct ___itt_api_info_20101001
319 __itt_group_id group;
320 } __itt_api_info_20101001;
322 typedef struct ___itt_api_info
328 __itt_group_id group;
331 struct ___itt_domain;
332 struct ___itt_string_handle;
334 typedef struct ___itt_global
336 unsigned char magic[8];
337 unsigned long version_major;
338 unsigned long version_minor;
339 unsigned long version_build;
340 volatile long api_initialized;
341 volatile long mutex_initialized;
342 volatile long atomic_counter;
346 const char** dll_path_ptr;
347 __itt_api_info* api_list_ptr;
348 struct ___itt_global* next;
349 /* Joinable structures below */
350 __itt_thread_info* thread_list;
351 struct ___itt_domain* domain_list;
352 struct ___itt_string_handle* string_list;
353 __itt_collection_state state;
358 #define NEW_THREAD_INFO_W(gptr,h,h_tail,t,s,n) { \
359 h = (__itt_thread_info*)malloc(sizeof(__itt_thread_info)); \
363 h->nameW = n ? _wcsdup(n) : NULL; \
365 h->extra1 = 0; /* reserved */ \
366 h->extra2 = NULL; /* reserved */ \
368 if (h_tail == NULL) \
369 (gptr)->thread_list = h; \
375 #define NEW_THREAD_INFO_A(gptr,h,h_tail,t,s,n) { \
376 h = (__itt_thread_info*)malloc(sizeof(__itt_thread_info)); \
379 h->nameA = n ? __itt_fstrdup(n) : NULL; \
382 h->extra1 = 0; /* reserved */ \
383 h->extra2 = NULL; /* reserved */ \
385 if (h_tail == NULL) \
386 (gptr)->thread_list = h; \
392 #define NEW_DOMAIN_W(gptr,h,h_tail,name) { \
393 h = (__itt_domain*)malloc(sizeof(__itt_domain)); \
395 h->flags = 0; /* domain is disabled by default */ \
397 h->nameW = name ? _wcsdup(name) : NULL; \
398 h->extra1 = 0; /* reserved */ \
399 h->extra2 = NULL; /* reserved */ \
401 if (h_tail == NULL) \
402 (gptr)->domain_list = h; \
408 #define NEW_DOMAIN_A(gptr,h,h_tail,name) { \
409 h = (__itt_domain*)malloc(sizeof(__itt_domain)); \
411 h->flags = 0; /* domain is disabled by default */ \
412 h->nameA = name ? __itt_fstrdup(name) : NULL; \
414 h->extra1 = 0; /* reserved */ \
415 h->extra2 = NULL; /* reserved */ \
417 if (h_tail == NULL) \
418 (gptr)->domain_list = h; \
424 #define NEW_STRING_HANDLE_W(gptr,h,h_tail,name) { \
425 h = (__itt_string_handle*)malloc(sizeof(__itt_string_handle)); \
428 h->strW = name ? _wcsdup(name) : NULL; \
429 h->extra1 = 0; /* reserved */ \
430 h->extra2 = NULL; /* reserved */ \
432 if (h_tail == NULL) \
433 (gptr)->string_list = h; \
439 #define NEW_STRING_HANDLE_A(gptr,h,h_tail,name) { \
440 h = (__itt_string_handle*)malloc(sizeof(__itt_string_handle)); \
442 h->strA = name ? __itt_fstrdup(name) : NULL; \
444 h->extra1 = 0; /* reserved */ \
445 h->extra2 = NULL; /* reserved */ \
447 if (h_tail == NULL) \
448 (gptr)->string_list = h; \
454 #endif /* _ITTNOTIFY_CONFIG_H_ */