brintos

brintos / llvm-project-archived public Read only

0
0
Text · 15.0 KiB · 16ce672 Raw
454 lines · c
1/*===-- ittnotify_config.h - JIT Profiling API internal config-----*- C -*-===*2 *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-exception6 *7 *===----------------------------------------------------------------------===*8 *9 * This file provides Intel(R) Performance Analyzer JIT (Just-In-Time)10 * Profiling API internal config.11 *12 * NOTE: This file comes in a style different from the rest of LLVM13 * source base since  this is a piece of code shared from Intel(R)14 * products.  Please do not reformat / re-style this code to make15 * subsequent merges and contributions from the original source base eaiser.16 *17 *===----------------------------------------------------------------------===*/18#ifndef _ITTNOTIFY_CONFIG_H_19#define _ITTNOTIFY_CONFIG_H_20 21/** @cond exclude_from_documentation */22#ifndef ITT_OS_WIN23#  define ITT_OS_WIN   124#endif /* ITT_OS_WIN */25 26#ifndef ITT_OS_LINUX27#  define ITT_OS_LINUX 228#endif /* ITT_OS_LINUX */29 30#ifndef ITT_OS_MAC31#  define ITT_OS_MAC   332#endif /* ITT_OS_MAC */33 34#ifndef ITT_OS35#  if defined WIN32 || defined _WIN3236#    define ITT_OS ITT_OS_WIN37#  elif defined( __APPLE__ ) && defined( __MACH__ )38#    define ITT_OS ITT_OS_MAC39#  else40#    define ITT_OS ITT_OS_LINUX41#  endif42#endif /* ITT_OS */43 44#ifndef ITT_PLATFORM_WIN45#  define ITT_PLATFORM_WIN 146#endif /* ITT_PLATFORM_WIN */47 48#ifndef ITT_PLATFORM_POSIX49#  define ITT_PLATFORM_POSIX 250#endif /* ITT_PLATFORM_POSIX */51 52#ifndef ITT_PLATFORM53#  if ITT_OS==ITT_OS_WIN54#    define ITT_PLATFORM ITT_PLATFORM_WIN55#  else56#    define ITT_PLATFORM ITT_PLATFORM_POSIX57#  endif /* _WIN32 */58#endif /* ITT_PLATFORM */59 60#if defined(_UNICODE) && !defined(UNICODE)61#define UNICODE62#endif63 64#include <stddef.h>65#if ITT_PLATFORM==ITT_PLATFORM_WIN66#include <tchar.h>67#else  /* ITT_PLATFORM==ITT_PLATFORM_WIN */68#include <stdint.h>69#if defined(UNICODE) || defined(_UNICODE)70#include <wchar.h>71#endif /* UNICODE || _UNICODE */72#endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */73 74#ifndef CDECL75#  if ITT_PLATFORM==ITT_PLATFORM_WIN76#    define CDECL __cdecl77#  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 */84#endif /* CDECL */85 86#ifndef STDCALL87#  if ITT_PLATFORM==ITT_PLATFORM_WIN88#    define STDCALL __stdcall89#  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 */96#endif /* STDCALL */97 98#define ITTAPI    CDECL99#define LIBITTAPI CDECL100 101/* TODO: Temporary for compatibility! */102#define ITTAPI_CALL    CDECL103#define LIBITTAPI_CALL CDECL104 105#if ITT_PLATFORM==ITT_PLATFORM_WIN106/* use __forceinline (VC++ specific) */107#define ITT_INLINE           __forceinline108#define ITT_INLINE_ATTRIBUTE /* nothing */109#else  /* ITT_PLATFORM==ITT_PLATFORM_WIN */110/*111 * Generally, functions are not inlined unless optimization is specified.112 * For functions declared inline, this attribute inlines the function even113 * if no optimization level was specified.114 */115#ifdef __STRICT_ANSI__116#define ITT_INLINE           static117#else  /* __STRICT_ANSI__ */118#define ITT_INLINE           static inline119#endif /* __STRICT_ANSI__ */120#define ITT_INLINE_ATTRIBUTE __attribute__ ((always_inline))121#endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */122/** @endcond */123 124#ifndef ITT_ARCH_IA32125#  define ITT_ARCH_IA32  1126#endif /* ITT_ARCH_IA32 */127 128#ifndef ITT_ARCH_IA32E129#  define ITT_ARCH_IA32E 2130#endif /* ITT_ARCH_IA32E */131 132#ifndef ITT_ARCH_IA64133#  define ITT_ARCH_IA64  3134#endif /* ITT_ARCH_IA64 */135 136#ifndef ITT_ARCH137#  if defined _M_X64 || defined _M_AMD64 || defined __x86_64__138#    define ITT_ARCH ITT_ARCH_IA32E139#  elif defined _M_IA64 || defined __ia64140#    define ITT_ARCH ITT_ARCH_IA64141#  else142#    define ITT_ARCH ITT_ARCH_IA32143#  endif144#endif145 146#ifdef __cplusplus147#  define ITT_EXTERN_C extern "C"148#else149#  define ITT_EXTERN_C /* nothing */150#endif /* __cplusplus */151 152#define ITT_TO_STR_AUX(x) #x153#define ITT_TO_STR(x)     ITT_TO_STR_AUX(x)154 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; \158} while(0)159#define _ITT_BUILD_ASSERT(expr, suffix)  __ITT_BUILD_ASSERT((expr), suffix)160#define ITT_BUILD_ASSERT(expr)           _ITT_BUILD_ASSERT((expr), __LINE__)161 162#define ITT_MAGIC { 0xED, 0xAB, 0xAB, 0xEC, 0x0D, 0xEE, 0xDA, 0x30 }163 164/* Replace with snapshot date YYYYMMDD for promotion build. */165#define API_VERSION_BUILD    20111111166 167#ifndef API_VERSION_NUM168#define API_VERSION_NUM 0.0.0169#endif /* API_VERSION_NUM */170 171#define API_VERSION "ITT-API-Version " ITT_TO_STR(API_VERSION_NUM) \172                                " (" ITT_TO_STR(API_VERSION_BUILD) ")"173 174/* OS communication functions */175#if ITT_PLATFORM==ITT_PLATFORM_WIN176#include <windows.h>177typedef HMODULE           lib_t;178typedef DWORD             TIDT;179typedef 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 */183#include <dlfcn.h>184#if defined(UNICODE) || defined(_UNICODE)185#include <wchar.h>186#endif /* UNICODE */187#ifndef _GNU_SOURCE188#define _GNU_SOURCE 1 /* need for PTHREAD_MUTEX_RECURSIVE */189#endif /* _GNU_SOURCE */190#include <pthread.h>191typedef void*             lib_t;192typedef pthread_t         TIDT;193typedef pthread_mutex_t   mutex_t;194#define MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER195#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 */199 200#if ITT_PLATFORM==ITT_PLATFORM_WIN201#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_INIT215ITT_INLINE long216__itt_interlocked_increment(volatile long* ptr) ITT_INLINE_ATTRIBUTE;217ITT_INLINE long __itt_interlocked_increment(volatile long* ptr)218{219    return InterlockedIncrement(ptr);220}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);                   \227    if (error_code)                                                         \228        __itt_report_error(__itt_error_system, "pthread_mutexattr_init",    \229                           error_code);                                     \230    error_code = pthread_mutexattr_settype(&mutex_attr,                     \231                                           PTHREAD_MUTEX_RECURSIVE);        \232    if (error_code)                                                         \233        __itt_report_error(__itt_error_system, "pthread_mutexattr_settype", \234                           error_code);                                     \235    error_code = pthread_mutex_init(mutex, &mutex_attr);                    \236    if (error_code)                                                         \237        __itt_report_error(__itt_error_system, "pthread_mutex_init",        \238                           error_code);                                     \239    error_code = pthread_mutexattr_destroy(&mutex_attr);                    \240    if (error_code)                                                         \241        __itt_report_error(__itt_error_system, "pthread_mutexattr_destroy", \242                           error_code);                                     \243}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()      errno249#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_IA64256#ifdef __INTEL_COMPILER257#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 */262ITT_INLINE long263__TBB_machine_fetchadd4(volatile void* ptr, long addend) ITT_INLINE_ATTRIBUTE;264ITT_INLINE long __TBB_machine_fetchadd4(volatile void* ptr, long addend)265{266    long result;267    __asm__ __volatile__("lock\nxadd %0,%1"268                          : "=r"(result),"=m"(*(long*)ptr)269                          : "0"(addend), "m"(*(long*)ptr)270                          : "memory");271    return result;272}273#endif /* ITT_ARCH==ITT_ARCH_IA64 */274#ifndef ITT_SIMPLE_INIT275ITT_INLINE long276__itt_interlocked_increment(volatile long* ptr) ITT_INLINE_ATTRIBUTE;277ITT_INLINE long __itt_interlocked_increment(volatile long* ptr)278{279    return __TBB_machine_fetchadd4(ptr, 1) + 1L;280}281#endif /* ITT_SIMPLE_INIT */282#endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */283 284typedef enum {285    __itt_collection_normal = 0,286    __itt_collection_paused = 1287} __itt_collection_state;288 289typedef enum {290    __itt_thread_normal  = 0,291    __itt_thread_ignored = 1292} __itt_thread_state;293 294#pragma pack(push, 8)295 296typedef struct ___itt_thread_info297{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 */302    void* nameW;303#endif /* UNICODE || _UNICODE */304    TIDT               tid;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;309} __itt_thread_info;310 311#include "ittnotify_types.h" /* For __itt_group_id definition */312 313typedef struct ___itt_api_info_20101001314{315    const char*    name;316    void**         func_ptr;317    void*          init_func;318    __itt_group_id group;319}  __itt_api_info_20101001;320 321typedef struct ___itt_api_info322{323    const char*    name;324    void**         func_ptr;325    void*          init_func;326    void*          null_func;327    __itt_group_id group;328}  __itt_api_info;329 330struct ___itt_domain;331struct ___itt_string_handle;332 333typedef struct ___itt_global334{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;342    mutex_t                mutex;343    lib_t                  lib;344    void*                  error_handler;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;353} __itt_global;354 355#pragma pack(pop)356 357#define NEW_THREAD_INFO_W(gptr,h,h_tail,t,s,n) { \358    h = (__itt_thread_info*)malloc(sizeof(__itt_thread_info)); \359    if (h != NULL) { \360        h->tid    = t; \361        h->nameA  = NULL; \362        h->nameW  = n ? _wcsdup(n) : NULL; \363        h->state  = s; \364        h->extra1 = 0;    /* reserved */ \365        h->extra2 = NULL; /* reserved */ \366        h->next   = NULL; \367        if (h_tail == NULL) \368            (gptr)->thread_list = h; \369        else \370            h_tail->next = h; \371    } \372}373 374#define NEW_THREAD_INFO_A(gptr,h,h_tail,t,s,n) { \375    h = (__itt_thread_info*)malloc(sizeof(__itt_thread_info)); \376    if (h != NULL) { \377        h->tid    = t; \378        h->nameA  = n ? __itt_fstrdup(n) : NULL; \379        h->nameW  = NULL; \380        h->state  = s; \381        h->extra1 = 0;    /* reserved */ \382        h->extra2 = NULL; /* reserved */ \383        h->next   = NULL; \384        if (h_tail == NULL) \385            (gptr)->thread_list = h; \386        else \387            h_tail->next = h; \388    } \389}390 391#define NEW_DOMAIN_W(gptr,h,h_tail,name) { \392    h = (__itt_domain*)malloc(sizeof(__itt_domain)); \393    if (h != NULL) { \394        h->flags  = 0;    /* domain is disabled by default */ \395        h->nameA  = NULL; \396        h->nameW  = name ? _wcsdup(name) : NULL; \397        h->extra1 = 0;    /* reserved */ \398        h->extra2 = NULL; /* reserved */ \399        h->next   = NULL; \400        if (h_tail == NULL) \401            (gptr)->domain_list = h; \402        else \403            h_tail->next = h; \404    } \405}406 407#define NEW_DOMAIN_A(gptr,h,h_tail,name) { \408    h = (__itt_domain*)malloc(sizeof(__itt_domain)); \409    if (h != NULL) { \410        h->flags  = 0;    /* domain is disabled by default */ \411        h->nameA  = name ? __itt_fstrdup(name) : NULL; \412        h->nameW  = NULL; \413        h->extra1 = 0;    /* reserved */ \414        h->extra2 = NULL; /* reserved */ \415        h->next   = NULL; \416        if (h_tail == NULL) \417            (gptr)->domain_list = h; \418        else \419            h_tail->next = h; \420    } \421}422 423#define NEW_STRING_HANDLE_W(gptr,h,h_tail,name) { \424    h = (__itt_string_handle*)malloc(sizeof(__itt_string_handle)); \425    if (h != NULL) { \426        h->strA   = NULL; \427        h->strW   = name ? _wcsdup(name) : NULL; \428        h->extra1 = 0;    /* reserved */ \429        h->extra2 = NULL; /* reserved */ \430        h->next   = NULL; \431        if (h_tail == NULL) \432            (gptr)->string_list = h; \433        else \434            h_tail->next = h; \435    } \436}437 438#define NEW_STRING_HANDLE_A(gptr,h,h_tail,name) { \439    h = (__itt_string_handle*)malloc(sizeof(__itt_string_handle)); \440    if (h != NULL) { \441        h->strA   = name ? __itt_fstrdup(name) : NULL; \442        h->strW   = NULL; \443        h->extra1 = 0;    /* reserved */ \444        h->extra2 = NULL; /* reserved */ \445        h->next   = NULL; \446        if (h_tail == NULL) \447            (gptr)->string_list = h; \448        else \449            h_tail->next = h; \450    } \451}452 453#endif /* _ITTNOTIFY_CONFIG_H_ */454