LLVM API Documentation
00001 /*===-- ittnotify_config.h - JIT Profiling API internal config-----*- C -*-===* 00002 * 00003 * The LLVM Compiler Infrastructure 00004 * 00005 * This file is distributed under the University of Illinois Open Source 00006 * License. See LICENSE.TXT for details. 00007 * 00008 *===----------------------------------------------------------------------===* 00009 * 00010 * This file provides Intel(R) Performance Analyzer JIT (Just-In-Time) 00011 * Profiling API internal config. 00012 * 00013 * NOTE: This file comes in a style different from the rest of LLVM 00014 * source base since this is a piece of code shared from Intel(R) 00015 * products. Please do not reformat / re-style this code to make 00016 * subsequent merges and contributions from the original source base eaiser. 00017 * 00018 *===----------------------------------------------------------------------===*/ 00019 #ifndef _ITTNOTIFY_CONFIG_H_ 00020 #define _ITTNOTIFY_CONFIG_H_ 00021 00022 /** @cond exclude_from_documentation */ 00023 #ifndef ITT_OS_WIN 00024 # define ITT_OS_WIN 1 00025 #endif /* ITT_OS_WIN */ 00026 00027 #ifndef ITT_OS_LINUX 00028 # define ITT_OS_LINUX 2 00029 #endif /* ITT_OS_LINUX */ 00030 00031 #ifndef ITT_OS_MAC 00032 # define ITT_OS_MAC 3 00033 #endif /* ITT_OS_MAC */ 00034 00035 #ifndef ITT_OS 00036 # if defined WIN32 || defined _WIN32 00037 # define ITT_OS ITT_OS_WIN 00038 # elif defined( __APPLE__ ) && defined( __MACH__ ) 00039 # define ITT_OS ITT_OS_MAC 00040 # else 00041 # define ITT_OS ITT_OS_LINUX 00042 # endif 00043 #endif /* ITT_OS */ 00044 00045 #ifndef ITT_PLATFORM_WIN 00046 # define ITT_PLATFORM_WIN 1 00047 #endif /* ITT_PLATFORM_WIN */ 00048 00049 #ifndef ITT_PLATFORM_POSIX 00050 # define ITT_PLATFORM_POSIX 2 00051 #endif /* ITT_PLATFORM_POSIX */ 00052 00053 #ifndef ITT_PLATFORM 00054 # if ITT_OS==ITT_OS_WIN 00055 # define ITT_PLATFORM ITT_PLATFORM_WIN 00056 # else 00057 # define ITT_PLATFORM ITT_PLATFORM_POSIX 00058 # endif /* _WIN32 */ 00059 #endif /* ITT_PLATFORM */ 00060 00061 #if defined(_UNICODE) && !defined(UNICODE) 00062 #define UNICODE 00063 #endif 00064 00065 #include <stddef.h> 00066 #if ITT_PLATFORM==ITT_PLATFORM_WIN 00067 #include <tchar.h> 00068 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */ 00069 #include <stdint.h> 00070 #if defined(UNICODE) || defined(_UNICODE) 00071 #include <wchar.h> 00072 #endif /* UNICODE || _UNICODE */ 00073 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */ 00074 00075 #ifndef CDECL 00076 # if ITT_PLATFORM==ITT_PLATFORM_WIN 00077 # define CDECL __cdecl 00078 # else /* ITT_PLATFORM==ITT_PLATFORM_WIN */ 00079 # if defined _M_X64 || defined _M_AMD64 || defined __x86_64__ 00080 # define CDECL /* not actual on x86_64 platform */ 00081 # else /* _M_X64 || _M_AMD64 || __x86_64__ */ 00082 # define CDECL __attribute__ ((cdecl)) 00083 # endif /* _M_X64 || _M_AMD64 || __x86_64__ */ 00084 # endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */ 00085 #endif /* CDECL */ 00086 00087 #ifndef STDCALL 00088 # if ITT_PLATFORM==ITT_PLATFORM_WIN 00089 # define STDCALL __stdcall 00090 # else /* ITT_PLATFORM==ITT_PLATFORM_WIN */ 00091 # if defined _M_X64 || defined _M_AMD64 || defined __x86_64__ 00092 # define STDCALL /* not supported on x86_64 platform */ 00093 # else /* _M_X64 || _M_AMD64 || __x86_64__ */ 00094 # define STDCALL __attribute__ ((stdcall)) 00095 # endif /* _M_X64 || _M_AMD64 || __x86_64__ */ 00096 # endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */ 00097 #endif /* STDCALL */ 00098 00099 #define ITTAPI CDECL 00100 #define LIBITTAPI CDECL 00101 00102 /* TODO: Temporary for compatibility! */ 00103 #define ITTAPI_CALL CDECL 00104 #define LIBITTAPI_CALL CDECL 00105 00106 #if ITT_PLATFORM==ITT_PLATFORM_WIN 00107 /* use __forceinline (VC++ specific) */ 00108 #define ITT_INLINE __forceinline 00109 #define ITT_INLINE_ATTRIBUTE /* nothing */ 00110 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */ 00111 /* 00112 * Generally, functions are not inlined unless optimization is specified. 00113 * For functions declared inline, this attribute inlines the function even 00114 * if no optimization level was specified. 00115 */ 00116 #ifdef __STRICT_ANSI__ 00117 #define ITT_INLINE static 00118 #else /* __STRICT_ANSI__ */ 00119 #define ITT_INLINE static inline 00120 #endif /* __STRICT_ANSI__ */ 00121 #define ITT_INLINE_ATTRIBUTE __attribute__ ((always_inline)) 00122 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */ 00123 /** @endcond */ 00124 00125 #ifndef ITT_ARCH_IA32 00126 # define ITT_ARCH_IA32 1 00127 #endif /* ITT_ARCH_IA32 */ 00128 00129 #ifndef ITT_ARCH_IA32E 00130 # define ITT_ARCH_IA32E 2 00131 #endif /* ITT_ARCH_IA32E */ 00132 00133 #ifndef ITT_ARCH_IA64 00134 # define ITT_ARCH_IA64 3 00135 #endif /* ITT_ARCH_IA64 */ 00136 00137 #ifndef ITT_ARCH 00138 # if defined _M_X64 || defined _M_AMD64 || defined __x86_64__ 00139 # define ITT_ARCH ITT_ARCH_IA32E 00140 # elif defined _M_IA64 || defined __ia64 00141 # define ITT_ARCH ITT_ARCH_IA64 00142 # else 00143 # define ITT_ARCH ITT_ARCH_IA32 00144 # endif 00145 #endif 00146 00147 #ifdef __cplusplus 00148 # define ITT_EXTERN_C extern "C" 00149 #else 00150 # define ITT_EXTERN_C /* nothing */ 00151 #endif /* __cplusplus */ 00152 00153 #define ITT_TO_STR_AUX(x) #x 00154 #define ITT_TO_STR(x) ITT_TO_STR_AUX(x) 00155 00156 #define __ITT_BUILD_ASSERT(expr, suffix) do { \ 00157 static char __itt_build_check_##suffix[(expr) ? 1 : -1]; \ 00158 __itt_build_check_##suffix[0] = 0; \ 00159 } while(0) 00160 #define _ITT_BUILD_ASSERT(expr, suffix) __ITT_BUILD_ASSERT((expr), suffix) 00161 #define ITT_BUILD_ASSERT(expr) _ITT_BUILD_ASSERT((expr), __LINE__) 00162 00163 #define ITT_MAGIC { 0xED, 0xAB, 0xAB, 0xEC, 0x0D, 0xEE, 0xDA, 0x30 } 00164 00165 /* Replace with snapshot date YYYYMMDD for promotion build. */ 00166 #define API_VERSION_BUILD 20111111 00167 00168 #ifndef API_VERSION_NUM 00169 #define API_VERSION_NUM 0.0.0 00170 #endif /* API_VERSION_NUM */ 00171 00172 #define API_VERSION "ITT-API-Version " ITT_TO_STR(API_VERSION_NUM) \ 00173 " (" ITT_TO_STR(API_VERSION_BUILD) ")" 00174 00175 /* OS communication functions */ 00176 #if ITT_PLATFORM==ITT_PLATFORM_WIN 00177 #include <windows.h> 00178 typedef HMODULE lib_t; 00179 typedef DWORD TIDT; 00180 typedef CRITICAL_SECTION mutex_t; 00181 #define MUTEX_INITIALIZER { 0 } 00182 #define strong_alias(name, aliasname) /* empty for Windows */ 00183 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */ 00184 #include <dlfcn.h> 00185 #if defined(UNICODE) || defined(_UNICODE) 00186 #include <wchar.h> 00187 #endif /* UNICODE */ 00188 #ifndef _GNU_SOURCE 00189 #define _GNU_SOURCE 1 /* need for PTHREAD_MUTEX_RECURSIVE */ 00190 #endif /* _GNU_SOURCE */ 00191 #include <pthread.h> 00192 typedef void* lib_t; 00193 typedef pthread_t TIDT; 00194 typedef pthread_mutex_t mutex_t; 00195 #define MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER 00196 #define _strong_alias(name, aliasname) \ 00197 extern __typeof (name) aliasname __attribute__ ((alias (#name))); 00198 #define strong_alias(name, aliasname) _strong_alias(name, aliasname) 00199 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */ 00200 00201 #if ITT_PLATFORM==ITT_PLATFORM_WIN 00202 #define __itt_get_proc(lib, name) GetProcAddress(lib, name) 00203 #define __itt_mutex_init(mutex) InitializeCriticalSection(mutex) 00204 #define __itt_mutex_lock(mutex) EnterCriticalSection(mutex) 00205 #define __itt_mutex_unlock(mutex) LeaveCriticalSection(mutex) 00206 #define __itt_load_lib(name) LoadLibraryA(name) 00207 #define __itt_unload_lib(handle) FreeLibrary(handle) 00208 #define __itt_system_error() (int)GetLastError() 00209 #define __itt_fstrcmp(s1, s2) lstrcmpA(s1, s2) 00210 #define __itt_fstrlen(s) lstrlenA(s) 00211 #define __itt_fstrcpyn(s1, s2, l) lstrcpynA(s1, s2, l) 00212 #define __itt_fstrdup(s) _strdup(s) 00213 #define __itt_thread_id() GetCurrentThreadId() 00214 #define __itt_thread_yield() SwitchToThread() 00215 #ifndef ITT_SIMPLE_INIT 00216 ITT_INLINE long 00217 __itt_interlocked_increment(volatile long* ptr) ITT_INLINE_ATTRIBUTE; 00218 ITT_INLINE long __itt_interlocked_increment(volatile long* ptr) 00219 { 00220 return InterlockedIncrement(ptr); 00221 } 00222 #endif /* ITT_SIMPLE_INIT */ 00223 #else /* ITT_PLATFORM!=ITT_PLATFORM_WIN */ 00224 #define __itt_get_proc(lib, name) dlsym(lib, name) 00225 #define __itt_mutex_init(mutex) {\ 00226 pthread_mutexattr_t mutex_attr; \ 00227 int error_code = pthread_mutexattr_init(&mutex_attr); \ 00228 if (error_code) \ 00229 __itt_report_error(__itt_error_system, "pthread_mutexattr_init", \ 00230 error_code); \ 00231 error_code = pthread_mutexattr_settype(&mutex_attr, \ 00232 PTHREAD_MUTEX_RECURSIVE); \ 00233 if (error_code) \ 00234 __itt_report_error(__itt_error_system, "pthread_mutexattr_settype", \ 00235 error_code); \ 00236 error_code = pthread_mutex_init(mutex, &mutex_attr); \ 00237 if (error_code) \ 00238 __itt_report_error(__itt_error_system, "pthread_mutex_init", \ 00239 error_code); \ 00240 error_code = pthread_mutexattr_destroy(&mutex_attr); \ 00241 if (error_code) \ 00242 __itt_report_error(__itt_error_system, "pthread_mutexattr_destroy", \ 00243 error_code); \ 00244 } 00245 #define __itt_mutex_lock(mutex) pthread_mutex_lock(mutex) 00246 #define __itt_mutex_unlock(mutex) pthread_mutex_unlock(mutex) 00247 #define __itt_load_lib(name) dlopen(name, RTLD_LAZY) 00248 #define __itt_unload_lib(handle) dlclose(handle) 00249 #define __itt_system_error() errno 00250 #define __itt_fstrcmp(s1, s2) strcmp(s1, s2) 00251 #define __itt_fstrlen(s) strlen(s) 00252 #define __itt_fstrcpyn(s1, s2, l) strncpy(s1, s2, l) 00253 #define __itt_fstrdup(s) strdup(s) 00254 #define __itt_thread_id() pthread_self() 00255 #define __itt_thread_yield() sched_yield() 00256 #if ITT_ARCH==ITT_ARCH_IA64 00257 #ifdef __INTEL_COMPILER 00258 #define __TBB_machine_fetchadd4(addr, val) __fetchadd4_acq((void *)addr, val) 00259 #else /* __INTEL_COMPILER */ 00260 /* TODO: Add Support for not Intel compilers for IA64 */ 00261 #endif /* __INTEL_COMPILER */ 00262 #else /* ITT_ARCH!=ITT_ARCH_IA64 */ 00263 ITT_INLINE long 00264 __TBB_machine_fetchadd4(volatile void* ptr, long addend) ITT_INLINE_ATTRIBUTE; 00265 ITT_INLINE long __TBB_machine_fetchadd4(volatile void* ptr, long addend) 00266 { 00267 long result; 00268 __asm__ __volatile__("lock\nxadd %0,%1" 00269 : "=r"(result),"=m"(*(long*)ptr) 00270 : "0"(addend), "m"(*(long*)ptr) 00271 : "memory"); 00272 return result; 00273 } 00274 #endif /* ITT_ARCH==ITT_ARCH_IA64 */ 00275 #ifndef ITT_SIMPLE_INIT 00276 ITT_INLINE long 00277 __itt_interlocked_increment(volatile long* ptr) ITT_INLINE_ATTRIBUTE; 00278 ITT_INLINE long __itt_interlocked_increment(volatile long* ptr) 00279 { 00280 return __TBB_machine_fetchadd4(ptr, 1) + 1L; 00281 } 00282 #endif /* ITT_SIMPLE_INIT */ 00283 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */ 00284 00285 typedef enum { 00286 __itt_collection_normal = 0, 00287 __itt_collection_paused = 1 00288 } __itt_collection_state; 00289 00290 typedef enum { 00291 __itt_thread_normal = 0, 00292 __itt_thread_ignored = 1 00293 } __itt_thread_state; 00294 00295 #pragma pack(push, 8) 00296 00297 typedef struct ___itt_thread_info 00298 { 00299 const char* nameA; /*!< Copy of original name in ASCII. */ 00300 #if defined(UNICODE) || defined(_UNICODE) 00301 const wchar_t* nameW; /*!< Copy of original name in UNICODE. */ 00302 #else /* UNICODE || _UNICODE */ 00303 void* nameW; 00304 #endif /* UNICODE || _UNICODE */ 00305 TIDT tid; 00306 __itt_thread_state state; /*!< Thread state (paused or normal) */ 00307 int extra1; /*!< Reserved to the runtime */ 00308 void* extra2; /*!< Reserved to the runtime */ 00309 struct ___itt_thread_info* next; 00310 } __itt_thread_info; 00311 00312 #include "ittnotify_types.h" /* For __itt_group_id definition */ 00313 00314 typedef struct ___itt_api_info_20101001 00315 { 00316 const char* name; 00317 void** func_ptr; 00318 void* init_func; 00319 __itt_group_id group; 00320 } __itt_api_info_20101001; 00321 00322 typedef struct ___itt_api_info 00323 { 00324 const char* name; 00325 void** func_ptr; 00326 void* init_func; 00327 void* null_func; 00328 __itt_group_id group; 00329 } __itt_api_info; 00330 00331 struct ___itt_domain; 00332 struct ___itt_string_handle; 00333 00334 typedef struct ___itt_global 00335 { 00336 unsigned char magic[8]; 00337 unsigned long version_major; 00338 unsigned long version_minor; 00339 unsigned long version_build; 00340 volatile long api_initialized; 00341 volatile long mutex_initialized; 00342 volatile long atomic_counter; 00343 mutex_t mutex; 00344 lib_t lib; 00345 void* error_handler; 00346 const char** dll_path_ptr; 00347 __itt_api_info* api_list_ptr; 00348 struct ___itt_global* next; 00349 /* Joinable structures below */ 00350 __itt_thread_info* thread_list; 00351 struct ___itt_domain* domain_list; 00352 struct ___itt_string_handle* string_list; 00353 __itt_collection_state state; 00354 } __itt_global; 00355 00356 #pragma pack(pop) 00357 00358 #define NEW_THREAD_INFO_W(gptr,h,h_tail,t,s,n) { \ 00359 h = (__itt_thread_info*)malloc(sizeof(__itt_thread_info)); \ 00360 if (h != NULL) { \ 00361 h->tid = t; \ 00362 h->nameA = NULL; \ 00363 h->nameW = n ? _wcsdup(n) : NULL; \ 00364 h->state = s; \ 00365 h->extra1 = 0; /* reserved */ \ 00366 h->extra2 = NULL; /* reserved */ \ 00367 h->next = NULL; \ 00368 if (h_tail == NULL) \ 00369 (gptr)->thread_list = h; \ 00370 else \ 00371 h_tail->next = h; \ 00372 } \ 00373 } 00374 00375 #define NEW_THREAD_INFO_A(gptr,h,h_tail,t,s,n) { \ 00376 h = (__itt_thread_info*)malloc(sizeof(__itt_thread_info)); \ 00377 if (h != NULL) { \ 00378 h->tid = t; \ 00379 h->nameA = n ? __itt_fstrdup(n) : NULL; \ 00380 h->nameW = NULL; \ 00381 h->state = s; \ 00382 h->extra1 = 0; /* reserved */ \ 00383 h->extra2 = NULL; /* reserved */ \ 00384 h->next = NULL; \ 00385 if (h_tail == NULL) \ 00386 (gptr)->thread_list = h; \ 00387 else \ 00388 h_tail->next = h; \ 00389 } \ 00390 } 00391 00392 #define NEW_DOMAIN_W(gptr,h,h_tail,name) { \ 00393 h = (__itt_domain*)malloc(sizeof(__itt_domain)); \ 00394 if (h != NULL) { \ 00395 h->flags = 0; /* domain is disabled by default */ \ 00396 h->nameA = NULL; \ 00397 h->nameW = name ? _wcsdup(name) : NULL; \ 00398 h->extra1 = 0; /* reserved */ \ 00399 h->extra2 = NULL; /* reserved */ \ 00400 h->next = NULL; \ 00401 if (h_tail == NULL) \ 00402 (gptr)->domain_list = h; \ 00403 else \ 00404 h_tail->next = h; \ 00405 } \ 00406 } 00407 00408 #define NEW_DOMAIN_A(gptr,h,h_tail,name) { \ 00409 h = (__itt_domain*)malloc(sizeof(__itt_domain)); \ 00410 if (h != NULL) { \ 00411 h->flags = 0; /* domain is disabled by default */ \ 00412 h->nameA = name ? __itt_fstrdup(name) : NULL; \ 00413 h->nameW = NULL; \ 00414 h->extra1 = 0; /* reserved */ \ 00415 h->extra2 = NULL; /* reserved */ \ 00416 h->next = NULL; \ 00417 if (h_tail == NULL) \ 00418 (gptr)->domain_list = h; \ 00419 else \ 00420 h_tail->next = h; \ 00421 } \ 00422 } 00423 00424 #define NEW_STRING_HANDLE_W(gptr,h,h_tail,name) { \ 00425 h = (__itt_string_handle*)malloc(sizeof(__itt_string_handle)); \ 00426 if (h != NULL) { \ 00427 h->strA = NULL; \ 00428 h->strW = name ? _wcsdup(name) : NULL; \ 00429 h->extra1 = 0; /* reserved */ \ 00430 h->extra2 = NULL; /* reserved */ \ 00431 h->next = NULL; \ 00432 if (h_tail == NULL) \ 00433 (gptr)->string_list = h; \ 00434 else \ 00435 h_tail->next = h; \ 00436 } \ 00437 } 00438 00439 #define NEW_STRING_HANDLE_A(gptr,h,h_tail,name) { \ 00440 h = (__itt_string_handle*)malloc(sizeof(__itt_string_handle)); \ 00441 if (h != NULL) { \ 00442 h->strA = name ? __itt_fstrdup(name) : NULL; \ 00443 h->strW = NULL; \ 00444 h->extra1 = 0; /* reserved */ \ 00445 h->extra2 = NULL; /* reserved */ \ 00446 h->next = NULL; \ 00447 if (h_tail == NULL) \ 00448 (gptr)->string_list = h; \ 00449 else \ 00450 h_tail->next = h; \ 00451 } \ 00452 } 00453 00454 #endif /* _ITTNOTIFY_CONFIG_H_ */