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 *===----------------------------------------------------------------------===*/
14 #ifndef _ITTNOTIFY_CONFIG_H_
15 #define _ITTNOTIFY_CONFIG_H_
17 /** @cond exclude_from_documentation */
20 #endif /* ITT_OS_WIN */
23 # define ITT_OS_LINUX 2
24 #endif /* ITT_OS_LINUX */
28 #endif /* ITT_OS_MAC */
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
36 # define ITT_OS ITT_OS_LINUX
40 #ifndef ITT_PLATFORM_WIN
41 # define ITT_PLATFORM_WIN 1
42 #endif /* ITT_PLATFORM_WIN */
44 #ifndef ITT_PLATFORM_POSIX
45 # define ITT_PLATFORM_POSIX 2
46 #endif /* ITT_PLATFORM_POSIX */
49 # if ITT_OS==ITT_OS_WIN
50 # define ITT_PLATFORM ITT_PLATFORM_WIN
52 # define ITT_PLATFORM ITT_PLATFORM_POSIX
54 #endif /* ITT_PLATFORM */
56 #if defined(_UNICODE) && !defined(UNICODE)
61 #if ITT_PLATFORM==ITT_PLATFORM_WIN
63 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
65 #if defined(UNICODE) || defined(_UNICODE)
67 #endif /* UNICODE || _UNICODE */
68 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
71 # if ITT_PLATFORM==ITT_PLATFORM_WIN
72 # define CDECL __cdecl
73 # else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
74 # if defined _M_X64 || defined _M_AMD64 || defined __x86_64__
75 # define CDECL /* not actual on x86_64 platform */
76 # else /* _M_X64 || _M_AMD64 || __x86_64__ */
77 # define CDECL __attribute__ ((cdecl))
78 # endif /* _M_X64 || _M_AMD64 || __x86_64__ */
79 # endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
83 # if ITT_PLATFORM==ITT_PLATFORM_WIN
84 # define STDCALL __stdcall
85 # else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
86 # if defined _M_X64 || defined _M_AMD64 || defined __x86_64__
87 # define STDCALL /* not supported on x86_64 platform */
88 # else /* _M_X64 || _M_AMD64 || __x86_64__ */
89 # define STDCALL __attribute__ ((stdcall))
90 # endif /* _M_X64 || _M_AMD64 || __x86_64__ */
91 # endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
95 #define LIBITTAPI CDECL
97 /* TODO: Temporary for compatibility! */
98 #define ITTAPI_CALL CDECL
99 #define LIBITTAPI_CALL CDECL
101 #if ITT_PLATFORM==ITT_PLATFORM_WIN
102 /* use __forceinline (VC++ specific) */
103 #define ITT_INLINE __forceinline
104 #define ITT_INLINE_ATTRIBUTE /* nothing */
105 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
107 * Generally, functions are not inlined unless optimization is specified.
108 * For functions declared inline, this attribute inlines the function even
109 * if no optimization level was specified.
111 #ifdef __STRICT_ANSI__
112 #define ITT_INLINE static
113 #else /* __STRICT_ANSI__ */
114 #define ITT_INLINE static inline
115 #endif /* __STRICT_ANSI__ */
116 #define ITT_INLINE_ATTRIBUTE __attribute__ ((always_inline))
117 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
120 #ifndef ITT_ARCH_IA32
121 # define ITT_ARCH_IA32 1
122 #endif /* ITT_ARCH_IA32 */
124 #ifndef ITT_ARCH_IA32E
125 # define ITT_ARCH_IA32E 2
126 #endif /* ITT_ARCH_IA32E */
128 #ifndef ITT_ARCH_IA64
129 # define ITT_ARCH_IA64 3
130 #endif /* ITT_ARCH_IA64 */
133 # if defined _M_X64 || defined _M_AMD64 || defined __x86_64__
134 # define ITT_ARCH ITT_ARCH_IA32E
135 # elif defined _M_IA64 || defined __ia64
136 # define ITT_ARCH ITT_ARCH_IA64
138 # define ITT_ARCH ITT_ARCH_IA32
143 # define ITT_EXTERN_C extern "C"
145 # define ITT_EXTERN_C /* nothing */
146 #endif /* __cplusplus */
148 #define ITT_TO_STR_AUX(x) #x
149 #define ITT_TO_STR(x) ITT_TO_STR_AUX(x)
151 #define __ITT_BUILD_ASSERT(expr, suffix) do { \
152 static char __itt_build_check_##suffix[(expr) ? 1 : -1]; \
153 __itt_build_check_##suffix[0] = 0; \
155 #define _ITT_BUILD_ASSERT(expr, suffix) __ITT_BUILD_ASSERT((expr), suffix)
156 #define ITT_BUILD_ASSERT(expr) _ITT_BUILD_ASSERT((expr), __LINE__)
158 #define ITT_MAGIC { 0xED, 0xAB, 0xAB, 0xEC, 0x0D, 0xEE, 0xDA, 0x30 }
160 /* Replace with snapshot date YYYYMMDD for promotion build. */
161 #define API_VERSION_BUILD 20111111
163 #ifndef API_VERSION_NUM
164 #define API_VERSION_NUM 0.0.0
165 #endif /* API_VERSION_NUM */
167 #define API_VERSION "ITT-API-Version " ITT_TO_STR(API_VERSION_NUM) \
168 " (" ITT_TO_STR(API_VERSION_BUILD) ")"
170 /* OS communication functions */
171 #if ITT_PLATFORM==ITT_PLATFORM_WIN
173 typedef HMODULE lib_t;
175 typedef CRITICAL_SECTION mutex_t;
176 #define MUTEX_INITIALIZER { 0 }
177 #define strong_alias(name, aliasname) /* empty for Windows */
178 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
180 #if defined(UNICODE) || defined(_UNICODE)
184 #define _GNU_SOURCE 1 /* need for PTHREAD_MUTEX_RECURSIVE */
185 #endif /* _GNU_SOURCE */
188 typedef pthread_t TIDT;
189 typedef pthread_mutex_t mutex_t;
190 #define MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
191 #define _strong_alias(name, aliasname) \
192 extern __typeof (name) aliasname __attribute__ ((alias (#name)));
193 #define strong_alias(name, aliasname) _strong_alias(name, aliasname)
194 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
196 #if ITT_PLATFORM==ITT_PLATFORM_WIN
197 #define __itt_get_proc(lib, name) GetProcAddress(lib, name)
198 #define __itt_mutex_init(mutex) InitializeCriticalSection(mutex)
199 #define __itt_mutex_lock(mutex) EnterCriticalSection(mutex)
200 #define __itt_mutex_unlock(mutex) LeaveCriticalSection(mutex)
201 #define __itt_load_lib(name) LoadLibraryA(name)
202 #define __itt_unload_lib(handle) FreeLibrary(handle)
203 #define __itt_system_error() (int)GetLastError()
204 #define __itt_fstrcmp(s1, s2) lstrcmpA(s1, s2)
205 #define __itt_fstrlen(s) lstrlenA(s)
206 #define __itt_fstrcpyn(s1, s2, l) lstrcpynA(s1, s2, l)
207 #define __itt_fstrdup(s) _strdup(s)
208 #define __itt_thread_id() GetCurrentThreadId()
209 #define __itt_thread_yield() SwitchToThread()
210 #ifndef ITT_SIMPLE_INIT
212 __itt_interlocked_increment(volatile long* ptr) ITT_INLINE_ATTRIBUTE;
213 ITT_INLINE long __itt_interlocked_increment(volatile long* ptr)
215 return InterlockedIncrement(ptr);
217 #endif /* ITT_SIMPLE_INIT */
218 #else /* ITT_PLATFORM!=ITT_PLATFORM_WIN */
219 #define __itt_get_proc(lib, name) dlsym(lib, name)
220 #define __itt_mutex_init(mutex) {\
221 pthread_mutexattr_t mutex_attr; \
222 int error_code = pthread_mutexattr_init(&mutex_attr); \
224 __itt_report_error(__itt_error_system, "pthread_mutexattr_init", \
226 error_code = pthread_mutexattr_settype(&mutex_attr, \
227 PTHREAD_MUTEX_RECURSIVE); \
229 __itt_report_error(__itt_error_system, "pthread_mutexattr_settype", \
231 error_code = pthread_mutex_init(mutex, &mutex_attr); \
233 __itt_report_error(__itt_error_system, "pthread_mutex_init", \
235 error_code = pthread_mutexattr_destroy(&mutex_attr); \
237 __itt_report_error(__itt_error_system, "pthread_mutexattr_destroy", \
240 #define __itt_mutex_lock(mutex) pthread_mutex_lock(mutex)
241 #define __itt_mutex_unlock(mutex) pthread_mutex_unlock(mutex)
242 #define __itt_load_lib(name) dlopen(name, RTLD_LAZY)
243 #define __itt_unload_lib(handle) dlclose(handle)
244 #define __itt_system_error() errno
245 #define __itt_fstrcmp(s1, s2) strcmp(s1, s2)
246 #define __itt_fstrlen(s) strlen(s)
247 #define __itt_fstrcpyn(s1, s2, l) strncpy(s1, s2, l)
248 #define __itt_fstrdup(s) strdup(s)
249 #define __itt_thread_id() pthread_self()
250 #define __itt_thread_yield() sched_yield()
251 #if ITT_ARCH==ITT_ARCH_IA64
252 #ifdef __INTEL_COMPILER
253 #define __TBB_machine_fetchadd4(addr, val) __fetchadd4_acq((void *)addr, val)
254 #else /* __INTEL_COMPILER */
255 /* TODO: Add Support for not Intel compilers for IA64 */
256 #endif /* __INTEL_COMPILER */
257 #else /* ITT_ARCH!=ITT_ARCH_IA64 */
259 __TBB_machine_fetchadd4(volatile void* ptr, long addend) ITT_INLINE_ATTRIBUTE;
260 ITT_INLINE long __TBB_machine_fetchadd4(volatile void* ptr, long addend)
263 __asm__ __volatile__("lock\nxadd %0,%1"
264 : "=r"(result),"=m"(*(long*)ptr)
265 : "0"(addend), "m"(*(long*)ptr)
269 #endif /* ITT_ARCH==ITT_ARCH_IA64 */
270 #ifndef ITT_SIMPLE_INIT
272 __itt_interlocked_increment(volatile long* ptr) ITT_INLINE_ATTRIBUTE;
273 ITT_INLINE long __itt_interlocked_increment(volatile long* ptr)
275 return __TBB_machine_fetchadd4(ptr, 1) + 1L;
277 #endif /* ITT_SIMPLE_INIT */
278 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
281 __itt_collection_normal = 0,
282 __itt_collection_paused = 1
283 } __itt_collection_state;
286 __itt_thread_normal = 0,
287 __itt_thread_ignored = 1
288 } __itt_thread_state;
290 #pragma pack(push, 8)
292 typedef struct ___itt_thread_info
294 const char* nameA; /*!< Copy of original name in ASCII. */
295 #if defined(UNICODE) || defined(_UNICODE)
296 const wchar_t* nameW; /*!< Copy of original name in UNICODE. */
297 #else /* UNICODE || _UNICODE */
299 #endif /* UNICODE || _UNICODE */
301 __itt_thread_state state; /*!< Thread state (paused or normal) */
302 int extra1; /*!< Reserved to the runtime */
303 void* extra2; /*!< Reserved to the runtime */
304 struct ___itt_thread_info* next;
307 #include "ittnotify_types.h" /* For __itt_group_id definition */
309 typedef struct ___itt_api_info_20101001
314 __itt_group_id group;
315 } __itt_api_info_20101001;
317 typedef struct ___itt_api_info
323 __itt_group_id group;
326 struct ___itt_domain;
327 struct ___itt_string_handle;
329 typedef struct ___itt_global
331 unsigned char magic[8];
332 unsigned long version_major;
333 unsigned long version_minor;
334 unsigned long version_build;
335 volatile long api_initialized;
336 volatile long mutex_initialized;
337 volatile long atomic_counter;
341 const char** dll_path_ptr;
342 __itt_api_info* api_list_ptr;
343 struct ___itt_global* next;
344 /* Joinable structures below */
345 __itt_thread_info* thread_list;
346 struct ___itt_domain* domain_list;
347 struct ___itt_string_handle* string_list;
348 __itt_collection_state state;
353 #define NEW_THREAD_INFO_W(gptr,h,h_tail,t,s,n) { \
354 h = (__itt_thread_info*)malloc(sizeof(__itt_thread_info)); \
358 h->nameW = n ? _wcsdup(n) : NULL; \
360 h->extra1 = 0; /* reserved */ \
361 h->extra2 = NULL; /* reserved */ \
363 if (h_tail == NULL) \
364 (gptr)->thread_list = h; \
370 #define NEW_THREAD_INFO_A(gptr,h,h_tail,t,s,n) { \
371 h = (__itt_thread_info*)malloc(sizeof(__itt_thread_info)); \
374 h->nameA = n ? __itt_fstrdup(n) : NULL; \
377 h->extra1 = 0; /* reserved */ \
378 h->extra2 = NULL; /* reserved */ \
380 if (h_tail == NULL) \
381 (gptr)->thread_list = h; \
387 #define NEW_DOMAIN_W(gptr,h,h_tail,name) { \
388 h = (__itt_domain*)malloc(sizeof(__itt_domain)); \
390 h->flags = 0; /* domain is disabled by default */ \
392 h->nameW = name ? _wcsdup(name) : NULL; \
393 h->extra1 = 0; /* reserved */ \
394 h->extra2 = NULL; /* reserved */ \
396 if (h_tail == NULL) \
397 (gptr)->domain_list = h; \
403 #define NEW_DOMAIN_A(gptr,h,h_tail,name) { \
404 h = (__itt_domain*)malloc(sizeof(__itt_domain)); \
406 h->flags = 0; /* domain is disabled by default */ \
407 h->nameA = name ? __itt_fstrdup(name) : NULL; \
409 h->extra1 = 0; /* reserved */ \
410 h->extra2 = NULL; /* reserved */ \
412 if (h_tail == NULL) \
413 (gptr)->domain_list = h; \
419 #define NEW_STRING_HANDLE_W(gptr,h,h_tail,name) { \
420 h = (__itt_string_handle*)malloc(sizeof(__itt_string_handle)); \
423 h->strW = name ? _wcsdup(name) : NULL; \
424 h->extra1 = 0; /* reserved */ \
425 h->extra2 = NULL; /* reserved */ \
427 if (h_tail == NULL) \
428 (gptr)->string_list = h; \
434 #define NEW_STRING_HANDLE_A(gptr,h,h_tail,name) { \
435 h = (__itt_string_handle*)malloc(sizeof(__itt_string_handle)); \
437 h->strA = name ? __itt_fstrdup(name) : NULL; \
439 h->extra1 = 0; /* reserved */ \
440 h->extra2 = NULL; /* reserved */ \
442 if (h_tail == NULL) \
443 (gptr)->string_list = h; \
449 #endif /* _ITTNOTIFY_CONFIG_H_ */