ittnotify_config.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. /*===-- ittnotify_config.h - JIT Profiling API internal config-----*- C -*-===*
  2. *
  3. * The LLVM Compiler Infrastructure
  4. *
  5. * This file is distributed under the University of Illinois Open Source
  6. * License. See LICENSE.TXT for details.
  7. *
  8. *===----------------------------------------------------------------------===*
  9. *
  10. * This file provides Intel(R) Performance Analyzer JIT (Just-In-Time)
  11. * Profiling API internal config.
  12. *
  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.
  17. *
  18. *===----------------------------------------------------------------------===*/
  19. #ifndef _ITTNOTIFY_CONFIG_H_
  20. #define _ITTNOTIFY_CONFIG_H_
  21. /** @cond exclude_from_documentation */
  22. #ifndef ITT_OS_WIN
  23. # define ITT_OS_WIN 1
  24. #endif /* ITT_OS_WIN */
  25. #ifndef ITT_OS_LINUX
  26. # define ITT_OS_LINUX 2
  27. #endif /* ITT_OS_LINUX */
  28. #ifndef ITT_OS_MAC
  29. # define ITT_OS_MAC 3
  30. #endif /* ITT_OS_MAC */
  31. #ifndef ITT_OS
  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. # else
  37. # define ITT_OS ITT_OS_LINUX
  38. # endif
  39. #endif /* ITT_OS */
  40. #ifndef ITT_PLATFORM_WIN
  41. # define ITT_PLATFORM_WIN 1
  42. #endif /* ITT_PLATFORM_WIN */
  43. #ifndef ITT_PLATFORM_POSIX
  44. # define ITT_PLATFORM_POSIX 2
  45. #endif /* ITT_PLATFORM_POSIX */
  46. #ifndef ITT_PLATFORM
  47. # if ITT_OS==ITT_OS_WIN
  48. # define ITT_PLATFORM ITT_PLATFORM_WIN
  49. # else
  50. # define ITT_PLATFORM ITT_PLATFORM_POSIX
  51. # endif /* _WIN32 */
  52. #endif /* ITT_PLATFORM */
  53. #if defined(_UNICODE) && !defined(UNICODE)
  54. #define UNICODE
  55. #endif
  56. #include <stddef.h>
  57. #if ITT_PLATFORM==ITT_PLATFORM_WIN
  58. #include <tchar.h>
  59. #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
  60. #include <stdint.h>
  61. #if defined(UNICODE) || defined(_UNICODE)
  62. #include <wchar.h>
  63. #endif /* UNICODE || _UNICODE */
  64. #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
  65. #ifndef CDECL
  66. # if ITT_PLATFORM==ITT_PLATFORM_WIN
  67. # define CDECL __cdecl
  68. # else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
  69. # if defined _M_X64 || defined _M_AMD64 || defined __x86_64__
  70. # define CDECL /* not actual on x86_64 platform */
  71. # else /* _M_X64 || _M_AMD64 || __x86_64__ */
  72. # define CDECL __attribute__ ((cdecl))
  73. # endif /* _M_X64 || _M_AMD64 || __x86_64__ */
  74. # endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
  75. #endif /* CDECL */
  76. #ifndef STDCALL
  77. # if ITT_PLATFORM==ITT_PLATFORM_WIN
  78. # define STDCALL __stdcall
  79. # else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
  80. # if defined _M_X64 || defined _M_AMD64 || defined __x86_64__
  81. # define STDCALL /* not supported on x86_64 platform */
  82. # else /* _M_X64 || _M_AMD64 || __x86_64__ */
  83. # define STDCALL __attribute__ ((stdcall))
  84. # endif /* _M_X64 || _M_AMD64 || __x86_64__ */
  85. # endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
  86. #endif /* STDCALL */
  87. #define ITTAPI CDECL
  88. #define LIBITTAPI CDECL
  89. /* TODO: Temporary for compatibility! */
  90. #define ITTAPI_CALL CDECL
  91. #define LIBITTAPI_CALL CDECL
  92. #if ITT_PLATFORM==ITT_PLATFORM_WIN
  93. /* use __forceinline (VC++ specific) */
  94. #define ITT_INLINE __forceinline
  95. #define ITT_INLINE_ATTRIBUTE /* nothing */
  96. #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
  97. /*
  98. * Generally, functions are not inlined unless optimization is specified.
  99. * For functions declared inline, this attribute inlines the function even
  100. * if no optimization level was specified.
  101. */
  102. #ifdef __STRICT_ANSI__
  103. #define ITT_INLINE static
  104. #else /* __STRICT_ANSI__ */
  105. #define ITT_INLINE static inline
  106. #endif /* __STRICT_ANSI__ */
  107. #define ITT_INLINE_ATTRIBUTE __attribute__ ((always_inline))
  108. #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
  109. /** @endcond */
  110. #ifndef ITT_ARCH_IA32
  111. # define ITT_ARCH_IA32 1
  112. #endif /* ITT_ARCH_IA32 */
  113. #ifndef ITT_ARCH_IA32E
  114. # define ITT_ARCH_IA32E 2
  115. #endif /* ITT_ARCH_IA32E */
  116. #ifndef ITT_ARCH_IA64
  117. # define ITT_ARCH_IA64 3
  118. #endif /* ITT_ARCH_IA64 */
  119. #ifndef ITT_ARCH
  120. # if defined _M_X64 || defined _M_AMD64 || defined __x86_64__
  121. # define ITT_ARCH ITT_ARCH_IA32E
  122. # elif defined _M_IA64 || defined __ia64
  123. # define ITT_ARCH ITT_ARCH_IA64
  124. # else
  125. # define ITT_ARCH ITT_ARCH_IA32
  126. # endif
  127. #endif
  128. #ifdef __cplusplus
  129. # define ITT_EXTERN_C extern "C"
  130. #else
  131. # define ITT_EXTERN_C /* nothing */
  132. #endif /* __cplusplus */
  133. #define ITT_TO_STR_AUX(x) #x
  134. #define ITT_TO_STR(x) ITT_TO_STR_AUX(x)
  135. #define __ITT_BUILD_ASSERT(expr, suffix) do { \
  136. static char __itt_build_check_##suffix[(expr) ? 1 : -1]; \
  137. __itt_build_check_##suffix[0] = 0; \
  138. } while(0)
  139. #define _ITT_BUILD_ASSERT(expr, suffix) __ITT_BUILD_ASSERT((expr), suffix)
  140. #define ITT_BUILD_ASSERT(expr) _ITT_BUILD_ASSERT((expr), __LINE__)
  141. #define ITT_MAGIC { 0xED, 0xAB, 0xAB, 0xEC, 0x0D, 0xEE, 0xDA, 0x30 }
  142. /* Replace with snapshot date YYYYMMDD for promotion build. */
  143. #define API_VERSION_BUILD 20111111
  144. #ifndef API_VERSION_NUM
  145. #define API_VERSION_NUM 0.0.0
  146. #endif /* API_VERSION_NUM */
  147. #define API_VERSION "ITT-API-Version " ITT_TO_STR(API_VERSION_NUM) \
  148. " (" ITT_TO_STR(API_VERSION_BUILD) ")"
  149. /* OS communication functions */
  150. #if ITT_PLATFORM==ITT_PLATFORM_WIN
  151. #include <windows.h>
  152. typedef HMODULE lib_t;
  153. typedef DWORD TIDT;
  154. typedef CRITICAL_SECTION mutex_t;
  155. #define MUTEX_INITIALIZER { 0 }
  156. #define strong_alias(name, aliasname) /* empty for Windows */
  157. #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
  158. #include <dlfcn.h>
  159. #if defined(UNICODE) || defined(_UNICODE)
  160. #include <wchar.h>
  161. #endif /* UNICODE */
  162. #ifndef _GNU_SOURCE
  163. #define _GNU_SOURCE 1 /* need for PTHREAD_MUTEX_RECURSIVE */
  164. #endif /* _GNU_SOURCE */
  165. #include <pthread.h>
  166. typedef void* lib_t;
  167. typedef pthread_t TIDT;
  168. typedef pthread_mutex_t mutex_t;
  169. #define MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
  170. #define _strong_alias(name, aliasname) \
  171. extern __typeof (name) aliasname __attribute__ ((alias (#name)));
  172. #define strong_alias(name, aliasname) _strong_alias(name, aliasname)
  173. #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
  174. #if ITT_PLATFORM==ITT_PLATFORM_WIN
  175. #define __itt_get_proc(lib, name) GetProcAddress(lib, name)
  176. #define __itt_mutex_init(mutex) InitializeCriticalSection(mutex)
  177. #define __itt_mutex_lock(mutex) EnterCriticalSection(mutex)
  178. #define __itt_mutex_unlock(mutex) LeaveCriticalSection(mutex)
  179. #define __itt_load_lib(name) LoadLibraryA(name)
  180. #define __itt_unload_lib(handle) FreeLibrary(handle)
  181. #define __itt_system_error() (int)GetLastError()
  182. #define __itt_fstrcmp(s1, s2) lstrcmpA(s1, s2)
  183. #define __itt_fstrlen(s) lstrlenA(s)
  184. #define __itt_fstrcpyn(s1, s2, l) lstrcpynA(s1, s2, l)
  185. #define __itt_fstrdup(s) _strdup(s)
  186. #define __itt_thread_id() GetCurrentThreadId()
  187. #define __itt_thread_yield() SwitchToThread()
  188. #ifndef ITT_SIMPLE_INIT
  189. ITT_INLINE long
  190. __itt_interlocked_increment(volatile long* ptr) ITT_INLINE_ATTRIBUTE;
  191. ITT_INLINE long __itt_interlocked_increment(volatile long* ptr)
  192. {
  193. return InterlockedIncrement(ptr);
  194. }
  195. #endif /* ITT_SIMPLE_INIT */
  196. #else /* ITT_PLATFORM!=ITT_PLATFORM_WIN */
  197. #define __itt_get_proc(lib, name) dlsym(lib, name)
  198. #define __itt_mutex_init(mutex) {\
  199. pthread_mutexattr_t mutex_attr; \
  200. int error_code = pthread_mutexattr_init(&mutex_attr); \
  201. if (error_code) \
  202. __itt_report_error(__itt_error_system, "pthread_mutexattr_init", \
  203. error_code); \
  204. error_code = pthread_mutexattr_settype(&mutex_attr, \
  205. PTHREAD_MUTEX_RECURSIVE); \
  206. if (error_code) \
  207. __itt_report_error(__itt_error_system, "pthread_mutexattr_settype", \
  208. error_code); \
  209. error_code = pthread_mutex_init(mutex, &mutex_attr); \
  210. if (error_code) \
  211. __itt_report_error(__itt_error_system, "pthread_mutex_init", \
  212. error_code); \
  213. error_code = pthread_mutexattr_destroy(&mutex_attr); \
  214. if (error_code) \
  215. __itt_report_error(__itt_error_system, "pthread_mutexattr_destroy", \
  216. error_code); \
  217. }
  218. #define __itt_mutex_lock(mutex) pthread_mutex_lock(mutex)
  219. #define __itt_mutex_unlock(mutex) pthread_mutex_unlock(mutex)
  220. #define __itt_load_lib(name) dlopen(name, RTLD_LAZY)
  221. #define __itt_unload_lib(handle) dlclose(handle)
  222. #define __itt_system_error() errno
  223. #define __itt_fstrcmp(s1, s2) strcmp(s1, s2)
  224. #define __itt_fstrlen(s) strlen(s)
  225. #define __itt_fstrcpyn(s1, s2, l) strncpy(s1, s2, l)
  226. #define __itt_fstrdup(s) strdup(s)
  227. #define __itt_thread_id() pthread_self()
  228. #define __itt_thread_yield() sched_yield()
  229. #if ITT_ARCH==ITT_ARCH_IA64
  230. #ifdef __INTEL_COMPILER
  231. #define __TBB_machine_fetchadd4(addr, val) __fetchadd4_acq((void *)addr, val)
  232. #else /* __INTEL_COMPILER */
  233. /* TODO: Add Support for not Intel compilers for IA64 */
  234. #endif /* __INTEL_COMPILER */
  235. #else /* ITT_ARCH!=ITT_ARCH_IA64 */
  236. ITT_INLINE long
  237. __TBB_machine_fetchadd4(volatile void* ptr, long addend) ITT_INLINE_ATTRIBUTE;
  238. ITT_INLINE long __TBB_machine_fetchadd4(volatile void* ptr, long addend)
  239. {
  240. long result;
  241. __asm__ __volatile__("lock\nxadd %0,%1"
  242. : "=r"(result),"=m"(*(long*)ptr)
  243. : "0"(addend), "m"(*(long*)ptr)
  244. : "memory");
  245. return result;
  246. }
  247. #endif /* ITT_ARCH==ITT_ARCH_IA64 */
  248. #ifndef ITT_SIMPLE_INIT
  249. ITT_INLINE long
  250. __itt_interlocked_increment(volatile long* ptr) ITT_INLINE_ATTRIBUTE;
  251. ITT_INLINE long __itt_interlocked_increment(volatile long* ptr)
  252. {
  253. return __TBB_machine_fetchadd4(ptr, 1) + 1L;
  254. }
  255. #endif /* ITT_SIMPLE_INIT */
  256. #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
  257. typedef enum {
  258. __itt_collection_normal = 0,
  259. __itt_collection_paused = 1
  260. } __itt_collection_state;
  261. typedef enum {
  262. __itt_thread_normal = 0,
  263. __itt_thread_ignored = 1
  264. } __itt_thread_state;
  265. #pragma pack(push, 8)
  266. typedef struct ___itt_thread_info
  267. {
  268. const char* nameA; /*!< Copy of original name in ASCII. */
  269. #if defined(UNICODE) || defined(_UNICODE)
  270. const wchar_t* nameW; /*!< Copy of original name in UNICODE. */
  271. #else /* UNICODE || _UNICODE */
  272. void* nameW;
  273. #endif /* UNICODE || _UNICODE */
  274. TIDT tid;
  275. __itt_thread_state state; /*!< Thread state (paused or normal) */
  276. int extra1; /*!< Reserved to the runtime */
  277. void* extra2; /*!< Reserved to the runtime */
  278. struct ___itt_thread_info* next;
  279. } __itt_thread_info;
  280. #include "ittnotify_types.h" /* For __itt_group_id definition */
  281. typedef struct ___itt_api_info_20101001
  282. {
  283. const char* name;
  284. void** func_ptr;
  285. void* init_func;
  286. __itt_group_id group;
  287. } __itt_api_info_20101001;
  288. typedef struct ___itt_api_info
  289. {
  290. const char* name;
  291. void** func_ptr;
  292. void* init_func;
  293. void* null_func;
  294. __itt_group_id group;
  295. } __itt_api_info;
  296. struct ___itt_domain;
  297. struct ___itt_string_handle;
  298. typedef struct ___itt_global
  299. {
  300. unsigned char magic[8];
  301. unsigned long version_major;
  302. unsigned long version_minor;
  303. unsigned long version_build;
  304. volatile long api_initialized;
  305. volatile long mutex_initialized;
  306. volatile long atomic_counter;
  307. mutex_t mutex;
  308. lib_t lib;
  309. void* error_handler;
  310. const char** dll_path_ptr;
  311. __itt_api_info* api_list_ptr;
  312. struct ___itt_global* next;
  313. /* Joinable structures below */
  314. __itt_thread_info* thread_list;
  315. struct ___itt_domain* domain_list;
  316. struct ___itt_string_handle* string_list;
  317. __itt_collection_state state;
  318. } __itt_global;
  319. #pragma pack(pop)
  320. #define NEW_THREAD_INFO_W(gptr,h,h_tail,t,s,n) { \
  321. h = (__itt_thread_info*)malloc(sizeof(__itt_thread_info)); \
  322. if (h != NULL) { \
  323. h->tid = t; \
  324. h->nameA = NULL; \
  325. h->nameW = n ? _wcsdup(n) : NULL; \
  326. h->state = s; \
  327. h->extra1 = 0; /* reserved */ \
  328. h->extra2 = NULL; /* reserved */ \
  329. h->next = NULL; \
  330. if (h_tail == NULL) \
  331. (gptr)->thread_list = h; \
  332. else \
  333. h_tail->next = h; \
  334. } \
  335. }
  336. #define NEW_THREAD_INFO_A(gptr,h,h_tail,t,s,n) { \
  337. h = (__itt_thread_info*)malloc(sizeof(__itt_thread_info)); \
  338. if (h != NULL) { \
  339. h->tid = t; \
  340. h->nameA = n ? __itt_fstrdup(n) : NULL; \
  341. h->nameW = NULL; \
  342. h->state = s; \
  343. h->extra1 = 0; /* reserved */ \
  344. h->extra2 = NULL; /* reserved */ \
  345. h->next = NULL; \
  346. if (h_tail == NULL) \
  347. (gptr)->thread_list = h; \
  348. else \
  349. h_tail->next = h; \
  350. } \
  351. }
  352. #define NEW_DOMAIN_W(gptr,h,h_tail,name) { \
  353. h = (__itt_domain*)malloc(sizeof(__itt_domain)); \
  354. if (h != NULL) { \
  355. h->flags = 0; /* domain is disabled by default */ \
  356. h->nameA = NULL; \
  357. h->nameW = name ? _wcsdup(name) : NULL; \
  358. h->extra1 = 0; /* reserved */ \
  359. h->extra2 = NULL; /* reserved */ \
  360. h->next = NULL; \
  361. if (h_tail == NULL) \
  362. (gptr)->domain_list = h; \
  363. else \
  364. h_tail->next = h; \
  365. } \
  366. }
  367. #define NEW_DOMAIN_A(gptr,h,h_tail,name) { \
  368. h = (__itt_domain*)malloc(sizeof(__itt_domain)); \
  369. if (h != NULL) { \
  370. h->flags = 0; /* domain is disabled by default */ \
  371. h->nameA = name ? __itt_fstrdup(name) : NULL; \
  372. h->nameW = NULL; \
  373. h->extra1 = 0; /* reserved */ \
  374. h->extra2 = NULL; /* reserved */ \
  375. h->next = NULL; \
  376. if (h_tail == NULL) \
  377. (gptr)->domain_list = h; \
  378. else \
  379. h_tail->next = h; \
  380. } \
  381. }
  382. #define NEW_STRING_HANDLE_W(gptr,h,h_tail,name) { \
  383. h = (__itt_string_handle*)malloc(sizeof(__itt_string_handle)); \
  384. if (h != NULL) { \
  385. h->strA = NULL; \
  386. h->strW = name ? _wcsdup(name) : NULL; \
  387. h->extra1 = 0; /* reserved */ \
  388. h->extra2 = NULL; /* reserved */ \
  389. h->next = NULL; \
  390. if (h_tail == NULL) \
  391. (gptr)->string_list = h; \
  392. else \
  393. h_tail->next = h; \
  394. } \
  395. }
  396. #define NEW_STRING_HANDLE_A(gptr,h,h_tail,name) { \
  397. h = (__itt_string_handle*)malloc(sizeof(__itt_string_handle)); \
  398. if (h != NULL) { \
  399. h->strA = name ? __itt_fstrdup(name) : NULL; \
  400. h->strW = NULL; \
  401. h->extra1 = 0; /* reserved */ \
  402. h->extra2 = NULL; /* reserved */ \
  403. h->next = NULL; \
  404. if (h_tail == NULL) \
  405. (gptr)->string_list = h; \
  406. else \
  407. h_tail->next = h; \
  408. } \
  409. }
  410. #endif /* _ITTNOTIFY_CONFIG_H_ */