1 /*===-- ittnotify_config.h - JIT Profiling API internal config-----*- C -*-===*
3 * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 * See https://llvm.org/LICENSE.txt for license information.
5 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 *===----------------------------------------------------------------------===*
9 * This file provides Intel(R) Performance Analyzer JIT (Just-In-Time)
10 * Profiling API internal config.
12 * NOTE: This file comes in a style different from the rest of LLVM
13 * source base since this is a piece of code shared from Intel(R)
14 * products. Please do not reformat / re-style this code to make
15 * subsequent merges and contributions from the original source base eaiser.
17 *===----------------------------------------------------------------------===*/
18 #ifndef _ITTNOTIFY_CONFIG_H_
19 #define _ITTNOTIFY_CONFIG_H_
21 /** @cond exclude_from_documentation */
24 #endif /* ITT_OS_WIN */
27 # define ITT_OS_LINUX 2
28 #endif /* ITT_OS_LINUX */
32 #endif /* ITT_OS_MAC */
35 # if defined WIN32 || defined _WIN32
36 # define ITT_OS ITT_OS_WIN
37 # elif defined( __APPLE__ ) && defined( __MACH__ )
38 # define ITT_OS ITT_OS_MAC
40 # define ITT_OS ITT_OS_LINUX
44 #ifndef ITT_PLATFORM_WIN
45 # define ITT_PLATFORM_WIN 1
46 #endif /* ITT_PLATFORM_WIN */
48 #ifndef ITT_PLATFORM_POSIX
49 # define ITT_PLATFORM_POSIX 2
50 #endif /* ITT_PLATFORM_POSIX */
53 # if ITT_OS==ITT_OS_WIN
54 # define ITT_PLATFORM ITT_PLATFORM_WIN
56 # define ITT_PLATFORM ITT_PLATFORM_POSIX
58 #endif /* ITT_PLATFORM */
60 #if defined(_UNICODE) && !defined(UNICODE)
65 #if ITT_PLATFORM==ITT_PLATFORM_WIN
67 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
69 #if defined(UNICODE) || defined(_UNICODE)
71 #endif /* UNICODE || _UNICODE */
72 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
75 # if ITT_PLATFORM==ITT_PLATFORM_WIN
76 # define CDECL __cdecl
77 # else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
78 # if defined _M_X64 || defined _M_AMD64 || defined __x86_64__
79 # define CDECL /* not actual on x86_64 platform */
80 # else /* _M_X64 || _M_AMD64 || __x86_64__ */
81 # define CDECL __attribute__ ((cdecl))
82 # endif /* _M_X64 || _M_AMD64 || __x86_64__ */
83 # endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
87 # if ITT_PLATFORM==ITT_PLATFORM_WIN
88 # define STDCALL __stdcall
89 # else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
90 # if defined _M_X64 || defined _M_AMD64 || defined __x86_64__
91 # define STDCALL /* not supported on x86_64 platform */
92 # else /* _M_X64 || _M_AMD64 || __x86_64__ */
93 # define STDCALL __attribute__ ((stdcall))
94 # endif /* _M_X64 || _M_AMD64 || __x86_64__ */
95 # endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
99 #define LIBITTAPI CDECL
101 /* TODO: Temporary for compatibility! */
102 #define ITTAPI_CALL CDECL
103 #define LIBITTAPI_CALL CDECL
105 #if ITT_PLATFORM==ITT_PLATFORM_WIN
106 /* use __forceinline (VC++ specific) */
107 #define ITT_INLINE __forceinline
108 #define ITT_INLINE_ATTRIBUTE /* nothing */
109 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
111 * Generally, functions are not inlined unless optimization is specified.
112 * For functions declared inline, this attribute inlines the function even
113 * if no optimization level was specified.
115 #ifdef __STRICT_ANSI__
116 #define ITT_INLINE static
117 #else /* __STRICT_ANSI__ */
118 #define ITT_INLINE static inline
119 #endif /* __STRICT_ANSI__ */
120 #define ITT_INLINE_ATTRIBUTE __attribute__ ((always_inline))
121 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
124 #ifndef ITT_ARCH_IA32
125 # define ITT_ARCH_IA32 1
126 #endif /* ITT_ARCH_IA32 */
128 #ifndef ITT_ARCH_IA32E
129 # define ITT_ARCH_IA32E 2
130 #endif /* ITT_ARCH_IA32E */
132 #ifndef ITT_ARCH_IA64
133 # define ITT_ARCH_IA64 3
134 #endif /* ITT_ARCH_IA64 */
137 # if defined _M_X64 || defined _M_AMD64 || defined __x86_64__
138 # define ITT_ARCH ITT_ARCH_IA32E
139 # elif defined _M_IA64 || defined __ia64
140 # define ITT_ARCH ITT_ARCH_IA64
142 # define ITT_ARCH ITT_ARCH_IA32
147 # define ITT_EXTERN_C extern "C"
149 # define ITT_EXTERN_C /* nothing */
150 #endif /* __cplusplus */
152 #define ITT_TO_STR_AUX(x) #x
153 #define ITT_TO_STR(x) ITT_TO_STR_AUX(x)
155 #define __ITT_BUILD_ASSERT(expr, suffix) do { \
156 static char __itt_build_check_##suffix[(expr) ? 1 : -1]; \
157 __itt_build_check_##suffix[0] = 0; \
159 #define _ITT_BUILD_ASSERT(expr, suffix) __ITT_BUILD_ASSERT((expr), suffix)
160 #define ITT_BUILD_ASSERT(expr) _ITT_BUILD_ASSERT((expr), __LINE__)
162 #define ITT_MAGIC { 0xED, 0xAB, 0xAB, 0xEC, 0x0D, 0xEE, 0xDA, 0x30 }
164 /* Replace with snapshot date YYYYMMDD for promotion build. */
165 #define API_VERSION_BUILD 20111111
167 #ifndef API_VERSION_NUM
168 #define API_VERSION_NUM 0.0.0
169 #endif /* API_VERSION_NUM */
171 #define API_VERSION "ITT-API-Version " ITT_TO_STR(API_VERSION_NUM) \
172 " (" ITT_TO_STR(API_VERSION_BUILD) ")"
174 /* OS communication functions */
175 #if ITT_PLATFORM==ITT_PLATFORM_WIN
177 typedef HMODULE lib_t
;
179 typedef CRITICAL_SECTION mutex_t
;
180 #define MUTEX_INITIALIZER { 0 }
181 #define strong_alias(name, aliasname) /* empty for Windows */
182 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
184 #if defined(UNICODE) || defined(_UNICODE)
188 #define _GNU_SOURCE 1 /* need for PTHREAD_MUTEX_RECURSIVE */
189 #endif /* _GNU_SOURCE */
192 typedef pthread_t TIDT
;
193 typedef pthread_mutex_t mutex_t
;
194 #define MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
195 #define _strong_alias(name, aliasname) \
196 extern __typeof (name) aliasname __attribute__ ((alias (#name)));
197 #define strong_alias(name, aliasname) _strong_alias(name, aliasname)
198 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
200 #if ITT_PLATFORM==ITT_PLATFORM_WIN
201 #define __itt_get_proc(lib, name) GetProcAddress(lib, name)
202 #define __itt_mutex_init(mutex) InitializeCriticalSection(mutex)
203 #define __itt_mutex_lock(mutex) EnterCriticalSection(mutex)
204 #define __itt_mutex_unlock(mutex) LeaveCriticalSection(mutex)
205 #define __itt_load_lib(name) LoadLibraryA(name)
206 #define __itt_unload_lib(handle) FreeLibrary(handle)
207 #define __itt_system_error() (int)GetLastError()
208 #define __itt_fstrcmp(s1, s2) lstrcmpA(s1, s2)
209 #define __itt_fstrlen(s) lstrlenA(s)
210 #define __itt_fstrcpyn(s1, s2, l) lstrcpynA(s1, s2, l)
211 #define __itt_fstrdup(s) _strdup(s)
212 #define __itt_thread_id() GetCurrentThreadId()
213 #define __itt_thread_yield() SwitchToThread()
214 #ifndef ITT_SIMPLE_INIT
216 __itt_interlocked_increment(volatile long* ptr
) ITT_INLINE_ATTRIBUTE
;
217 ITT_INLINE
long __itt_interlocked_increment(volatile long* ptr
)
219 return InterlockedIncrement(ptr
);
221 #endif /* ITT_SIMPLE_INIT */
222 #else /* ITT_PLATFORM!=ITT_PLATFORM_WIN */
223 #define __itt_get_proc(lib, name) dlsym(lib, name)
224 #define __itt_mutex_init(mutex) {\
225 pthread_mutexattr_t mutex_attr; \
226 int error_code = pthread_mutexattr_init(&mutex_attr); \
228 __itt_report_error(__itt_error_system, "pthread_mutexattr_init", \
230 error_code = pthread_mutexattr_settype(&mutex_attr, \
231 PTHREAD_MUTEX_RECURSIVE); \
233 __itt_report_error(__itt_error_system, "pthread_mutexattr_settype", \
235 error_code = pthread_mutex_init(mutex, &mutex_attr); \
237 __itt_report_error(__itt_error_system, "pthread_mutex_init", \
239 error_code = pthread_mutexattr_destroy(&mutex_attr); \
241 __itt_report_error(__itt_error_system, "pthread_mutexattr_destroy", \
244 #define __itt_mutex_lock(mutex) pthread_mutex_lock(mutex)
245 #define __itt_mutex_unlock(mutex) pthread_mutex_unlock(mutex)
246 #define __itt_load_lib(name) dlopen(name, RTLD_LAZY)
247 #define __itt_unload_lib(handle) dlclose(handle)
248 #define __itt_system_error() errno
249 #define __itt_fstrcmp(s1, s2) strcmp(s1, s2)
250 #define __itt_fstrlen(s) strlen(s)
251 #define __itt_fstrcpyn(s1, s2, l) strncpy(s1, s2, l)
252 #define __itt_fstrdup(s) strdup(s)
253 #define __itt_thread_id() pthread_self()
254 #define __itt_thread_yield() sched_yield()
255 #if ITT_ARCH==ITT_ARCH_IA64
256 #ifdef __INTEL_COMPILER
257 #define __TBB_machine_fetchadd4(addr, val) __fetchadd4_acq((void *)addr, val)
258 #else /* __INTEL_COMPILER */
259 /* TODO: Add Support for not Intel compilers for IA64 */
260 #endif /* __INTEL_COMPILER */
261 #else /* ITT_ARCH!=ITT_ARCH_IA64 */
263 __TBB_machine_fetchadd4(volatile void* ptr
, long addend
) ITT_INLINE_ATTRIBUTE
;
264 ITT_INLINE
long __TBB_machine_fetchadd4(volatile void* ptr
, long addend
)
267 __asm__
__volatile__("lock\nxadd %0,%1"
268 : "=r"(result
),"=m"(*(long*)ptr
)
269 : "0"(addend
), "m"(*(long*)ptr
)
273 #endif /* ITT_ARCH==ITT_ARCH_IA64 */
274 #ifndef ITT_SIMPLE_INIT
276 __itt_interlocked_increment(volatile long* ptr
) ITT_INLINE_ATTRIBUTE
;
277 ITT_INLINE
long __itt_interlocked_increment(volatile long* ptr
)
279 return __TBB_machine_fetchadd4(ptr
, 1) + 1L;
281 #endif /* ITT_SIMPLE_INIT */
282 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
285 __itt_collection_normal
= 0,
286 __itt_collection_paused
= 1
287 } __itt_collection_state
;
290 __itt_thread_normal
= 0,
291 __itt_thread_ignored
= 1
292 } __itt_thread_state
;
294 #pragma pack(push, 8)
296 typedef struct ___itt_thread_info
298 const char* nameA
; /*!< Copy of original name in ASCII. */
299 #if defined(UNICODE) || defined(_UNICODE)
300 const wchar_t* nameW
; /*!< Copy of original name in UNICODE. */
301 #else /* UNICODE || _UNICODE */
303 #endif /* UNICODE || _UNICODE */
305 __itt_thread_state state
; /*!< Thread state (paused or normal) */
306 int extra1
; /*!< Reserved to the runtime */
307 void* extra2
; /*!< Reserved to the runtime */
308 struct ___itt_thread_info
* next
;
311 #include "ittnotify_types.h" /* For __itt_group_id definition */
313 typedef struct ___itt_api_info_20101001
318 __itt_group_id group
;
319 } __itt_api_info_20101001
;
321 typedef struct ___itt_api_info
327 __itt_group_id group
;
330 struct ___itt_domain
;
331 struct ___itt_string_handle
;
333 typedef struct ___itt_global
335 unsigned char magic
[8];
336 unsigned long version_major
;
337 unsigned long version_minor
;
338 unsigned long version_build
;
339 volatile long api_initialized
;
340 volatile long mutex_initialized
;
341 volatile long atomic_counter
;
345 const char** dll_path_ptr
;
346 __itt_api_info
* api_list_ptr
;
347 struct ___itt_global
* next
;
348 /* Joinable structures below */
349 __itt_thread_info
* thread_list
;
350 struct ___itt_domain
* domain_list
;
351 struct ___itt_string_handle
* string_list
;
352 __itt_collection_state state
;
357 #define NEW_THREAD_INFO_W(gptr,h,h_tail,t,s,n) { \
358 h = (__itt_thread_info*)malloc(sizeof(__itt_thread_info)); \
362 h->nameW = n ? _wcsdup(n) : NULL; \
364 h->extra1 = 0; /* reserved */ \
365 h->extra2 = NULL; /* reserved */ \
367 if (h_tail == NULL) \
368 (gptr)->thread_list = h; \
374 #define NEW_THREAD_INFO_A(gptr,h,h_tail,t,s,n) { \
375 h = (__itt_thread_info*)malloc(sizeof(__itt_thread_info)); \
378 h->nameA = n ? __itt_fstrdup(n) : NULL; \
381 h->extra1 = 0; /* reserved */ \
382 h->extra2 = NULL; /* reserved */ \
384 if (h_tail == NULL) \
385 (gptr)->thread_list = h; \
391 #define NEW_DOMAIN_W(gptr,h,h_tail,name) { \
392 h = (__itt_domain*)malloc(sizeof(__itt_domain)); \
394 h->flags = 0; /* domain is disabled by default */ \
396 h->nameW = name ? _wcsdup(name) : NULL; \
397 h->extra1 = 0; /* reserved */ \
398 h->extra2 = NULL; /* reserved */ \
400 if (h_tail == NULL) \
401 (gptr)->domain_list = h; \
407 #define NEW_DOMAIN_A(gptr,h,h_tail,name) { \
408 h = (__itt_domain*)malloc(sizeof(__itt_domain)); \
410 h->flags = 0; /* domain is disabled by default */ \
411 h->nameA = name ? __itt_fstrdup(name) : NULL; \
413 h->extra1 = 0; /* reserved */ \
414 h->extra2 = NULL; /* reserved */ \
416 if (h_tail == NULL) \
417 (gptr)->domain_list = h; \
423 #define NEW_STRING_HANDLE_W(gptr,h,h_tail,name) { \
424 h = (__itt_string_handle*)malloc(sizeof(__itt_string_handle)); \
427 h->strW = name ? _wcsdup(name) : NULL; \
428 h->extra1 = 0; /* reserved */ \
429 h->extra2 = NULL; /* reserved */ \
431 if (h_tail == NULL) \
432 (gptr)->string_list = h; \
438 #define NEW_STRING_HANDLE_A(gptr,h,h_tail,name) { \
439 h = (__itt_string_handle*)malloc(sizeof(__itt_string_handle)); \
441 h->strA = name ? __itt_fstrdup(name) : NULL; \
443 h->extra1 = 0; /* reserved */ \
444 h->extra2 = NULL; /* reserved */ \
446 if (h_tail == NULL) \
447 (gptr)->string_list = h; \
453 #endif /* _ITTNOTIFY_CONFIG_H_ */