Path: blob/main/contrib/llvm-project/llvm/lib/ExecutionEngine/IntelJITProfiling/ittnotify_config.h
35271 views
/*===-- ittnotify_config.h - JIT Profiling API internal config-----*- C -*-===*1*2* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3* See https://llvm.org/LICENSE.txt for license information.4* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5*6*===----------------------------------------------------------------------===*7*8* This file provides Intel(R) Performance Analyzer JIT (Just-In-Time)9* Profiling API internal config.10*11* NOTE: This file comes in a style different from the rest of LLVM12* source base since this is a piece of code shared from Intel(R)13* products. Please do not reformat / re-style this code to make14* subsequent merges and contributions from the original source base eaiser.15*16*===----------------------------------------------------------------------===*/17#ifndef _ITTNOTIFY_CONFIG_H_18#define _ITTNOTIFY_CONFIG_H_1920/** @cond exclude_from_documentation */21#ifndef ITT_OS_WIN22# define ITT_OS_WIN 123#endif /* ITT_OS_WIN */2425#ifndef ITT_OS_LINUX26# define ITT_OS_LINUX 227#endif /* ITT_OS_LINUX */2829#ifndef ITT_OS_MAC30# define ITT_OS_MAC 331#endif /* ITT_OS_MAC */3233#ifndef ITT_OS34# if defined WIN32 || defined _WIN3235# define ITT_OS ITT_OS_WIN36# elif defined( __APPLE__ ) && defined( __MACH__ )37# define ITT_OS ITT_OS_MAC38# else39# define ITT_OS ITT_OS_LINUX40# endif41#endif /* ITT_OS */4243#ifndef ITT_PLATFORM_WIN44# define ITT_PLATFORM_WIN 145#endif /* ITT_PLATFORM_WIN */4647#ifndef ITT_PLATFORM_POSIX48# define ITT_PLATFORM_POSIX 249#endif /* ITT_PLATFORM_POSIX */5051#ifndef ITT_PLATFORM52# if ITT_OS==ITT_OS_WIN53# define ITT_PLATFORM ITT_PLATFORM_WIN54# else55# define ITT_PLATFORM ITT_PLATFORM_POSIX56# endif /* _WIN32 */57#endif /* ITT_PLATFORM */5859#if defined(_UNICODE) && !defined(UNICODE)60#define UNICODE61#endif6263#include <stddef.h>64#if ITT_PLATFORM==ITT_PLATFORM_WIN65#include <tchar.h>66#else /* ITT_PLATFORM==ITT_PLATFORM_WIN */67#include <stdint.h>68#if defined(UNICODE) || defined(_UNICODE)69#include <wchar.h>70#endif /* UNICODE || _UNICODE */71#endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */7273#ifndef CDECL74# if ITT_PLATFORM==ITT_PLATFORM_WIN75# define CDECL __cdecl76# else /* ITT_PLATFORM==ITT_PLATFORM_WIN */77# if defined _M_X64 || defined _M_AMD64 || defined __x86_64__78# define CDECL /* not actual on x86_64 platform */79# else /* _M_X64 || _M_AMD64 || __x86_64__ */80# define CDECL __attribute__ ((cdecl))81# endif /* _M_X64 || _M_AMD64 || __x86_64__ */82# endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */83#endif /* CDECL */8485#ifndef STDCALL86# if ITT_PLATFORM==ITT_PLATFORM_WIN87# define STDCALL __stdcall88# else /* ITT_PLATFORM==ITT_PLATFORM_WIN */89# if defined _M_X64 || defined _M_AMD64 || defined __x86_64__90# define STDCALL /* not supported on x86_64 platform */91# else /* _M_X64 || _M_AMD64 || __x86_64__ */92# define STDCALL __attribute__ ((stdcall))93# endif /* _M_X64 || _M_AMD64 || __x86_64__ */94# endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */95#endif /* STDCALL */9697#define ITTAPI CDECL98#define LIBITTAPI CDECL99100/* TODO: Temporary for compatibility! */101#define ITTAPI_CALL CDECL102#define LIBITTAPI_CALL CDECL103104#if ITT_PLATFORM==ITT_PLATFORM_WIN105/* use __forceinline (VC++ specific) */106#define ITT_INLINE __forceinline107#define ITT_INLINE_ATTRIBUTE /* nothing */108#else /* ITT_PLATFORM==ITT_PLATFORM_WIN */109/*110* Generally, functions are not inlined unless optimization is specified.111* For functions declared inline, this attribute inlines the function even112* if no optimization level was specified.113*/114#ifdef __STRICT_ANSI__115#define ITT_INLINE static116#else /* __STRICT_ANSI__ */117#define ITT_INLINE static inline118#endif /* __STRICT_ANSI__ */119#define ITT_INLINE_ATTRIBUTE __attribute__ ((always_inline))120#endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */121/** @endcond */122123#ifndef ITT_ARCH_IA32124# define ITT_ARCH_IA32 1125#endif /* ITT_ARCH_IA32 */126127#ifndef ITT_ARCH_IA32E128# define ITT_ARCH_IA32E 2129#endif /* ITT_ARCH_IA32E */130131#ifndef ITT_ARCH_IA64132# define ITT_ARCH_IA64 3133#endif /* ITT_ARCH_IA64 */134135#ifndef ITT_ARCH136# if defined _M_X64 || defined _M_AMD64 || defined __x86_64__137# define ITT_ARCH ITT_ARCH_IA32E138# elif defined _M_IA64 || defined __ia64139# define ITT_ARCH ITT_ARCH_IA64140# else141# define ITT_ARCH ITT_ARCH_IA32142# endif143#endif144145#ifdef __cplusplus146# define ITT_EXTERN_C extern "C"147#else148# define ITT_EXTERN_C /* nothing */149#endif /* __cplusplus */150151#define ITT_TO_STR_AUX(x) #x152#define ITT_TO_STR(x) ITT_TO_STR_AUX(x)153154#define __ITT_BUILD_ASSERT(expr, suffix) do { \155static char __itt_build_check_##suffix[(expr) ? 1 : -1]; \156__itt_build_check_##suffix[0] = 0; \157} while(0)158#define _ITT_BUILD_ASSERT(expr, suffix) __ITT_BUILD_ASSERT((expr), suffix)159#define ITT_BUILD_ASSERT(expr) _ITT_BUILD_ASSERT((expr), __LINE__)160161#define ITT_MAGIC { 0xED, 0xAB, 0xAB, 0xEC, 0x0D, 0xEE, 0xDA, 0x30 }162163/* Replace with snapshot date YYYYMMDD for promotion build. */164#define API_VERSION_BUILD 20111111165166#ifndef API_VERSION_NUM167#define API_VERSION_NUM 0.0.0168#endif /* API_VERSION_NUM */169170#define API_VERSION "ITT-API-Version " ITT_TO_STR(API_VERSION_NUM) \171" (" ITT_TO_STR(API_VERSION_BUILD) ")"172173/* OS communication functions */174#if ITT_PLATFORM==ITT_PLATFORM_WIN175#include <windows.h>176typedef HMODULE lib_t;177typedef DWORD TIDT;178typedef CRITICAL_SECTION mutex_t;179#define MUTEX_INITIALIZER { 0 }180#define strong_alias(name, aliasname) /* empty for Windows */181#else /* ITT_PLATFORM==ITT_PLATFORM_WIN */182#include <dlfcn.h>183#if defined(UNICODE) || defined(_UNICODE)184#include <wchar.h>185#endif /* UNICODE */186#ifndef _GNU_SOURCE187#define _GNU_SOURCE 1 /* need for PTHREAD_MUTEX_RECURSIVE */188#endif /* _GNU_SOURCE */189#include <pthread.h>190typedef void* lib_t;191typedef pthread_t TIDT;192typedef pthread_mutex_t mutex_t;193#define MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER194#define _strong_alias(name, aliasname) \195extern __typeof (name) aliasname __attribute__ ((alias (#name)));196#define strong_alias(name, aliasname) _strong_alias(name, aliasname)197#endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */198199#if ITT_PLATFORM==ITT_PLATFORM_WIN200#define __itt_get_proc(lib, name) GetProcAddress(lib, name)201#define __itt_mutex_init(mutex) InitializeCriticalSection(mutex)202#define __itt_mutex_lock(mutex) EnterCriticalSection(mutex)203#define __itt_mutex_unlock(mutex) LeaveCriticalSection(mutex)204#define __itt_load_lib(name) LoadLibraryA(name)205#define __itt_unload_lib(handle) FreeLibrary(handle)206#define __itt_system_error() (int)GetLastError()207#define __itt_fstrcmp(s1, s2) lstrcmpA(s1, s2)208#define __itt_fstrlen(s) lstrlenA(s)209#define __itt_fstrcpyn(s1, s2, l) lstrcpynA(s1, s2, l)210#define __itt_fstrdup(s) _strdup(s)211#define __itt_thread_id() GetCurrentThreadId()212#define __itt_thread_yield() SwitchToThread()213#ifndef ITT_SIMPLE_INIT214ITT_INLINE long215__itt_interlocked_increment(volatile long* ptr) ITT_INLINE_ATTRIBUTE;216ITT_INLINE long __itt_interlocked_increment(volatile long* ptr)217{218return InterlockedIncrement(ptr);219}220#endif /* ITT_SIMPLE_INIT */221#else /* ITT_PLATFORM!=ITT_PLATFORM_WIN */222#define __itt_get_proc(lib, name) dlsym(lib, name)223#define __itt_mutex_init(mutex) {\224pthread_mutexattr_t mutex_attr; \225int error_code = pthread_mutexattr_init(&mutex_attr); \226if (error_code) \227__itt_report_error(__itt_error_system, "pthread_mutexattr_init", \228error_code); \229error_code = pthread_mutexattr_settype(&mutex_attr, \230PTHREAD_MUTEX_RECURSIVE); \231if (error_code) \232__itt_report_error(__itt_error_system, "pthread_mutexattr_settype", \233error_code); \234error_code = pthread_mutex_init(mutex, &mutex_attr); \235if (error_code) \236__itt_report_error(__itt_error_system, "pthread_mutex_init", \237error_code); \238error_code = pthread_mutexattr_destroy(&mutex_attr); \239if (error_code) \240__itt_report_error(__itt_error_system, "pthread_mutexattr_destroy", \241error_code); \242}243#define __itt_mutex_lock(mutex) pthread_mutex_lock(mutex)244#define __itt_mutex_unlock(mutex) pthread_mutex_unlock(mutex)245#define __itt_load_lib(name) dlopen(name, RTLD_LAZY)246#define __itt_unload_lib(handle) dlclose(handle)247#define __itt_system_error() errno248#define __itt_fstrcmp(s1, s2) strcmp(s1, s2)249#define __itt_fstrlen(s) strlen(s)250#define __itt_fstrcpyn(s1, s2, l) strncpy(s1, s2, l)251#define __itt_fstrdup(s) strdup(s)252#define __itt_thread_id() pthread_self()253#define __itt_thread_yield() sched_yield()254#if ITT_ARCH==ITT_ARCH_IA64255#ifdef __INTEL_COMPILER256#define __TBB_machine_fetchadd4(addr, val) __fetchadd4_acq((void *)addr, val)257#else /* __INTEL_COMPILER */258/* TODO: Add Support for not Intel compilers for IA64 */259#endif /* __INTEL_COMPILER */260#else /* ITT_ARCH!=ITT_ARCH_IA64 */261ITT_INLINE long262__TBB_machine_fetchadd4(volatile void* ptr, long addend) ITT_INLINE_ATTRIBUTE;263ITT_INLINE long __TBB_machine_fetchadd4(volatile void* ptr, long addend)264{265long result;266__asm__ __volatile__("lock\nxadd %0,%1"267: "=r"(result),"=m"(*(long*)ptr)268: "0"(addend), "m"(*(long*)ptr)269: "memory");270return result;271}272#endif /* ITT_ARCH==ITT_ARCH_IA64 */273#ifndef ITT_SIMPLE_INIT274ITT_INLINE long275__itt_interlocked_increment(volatile long* ptr) ITT_INLINE_ATTRIBUTE;276ITT_INLINE long __itt_interlocked_increment(volatile long* ptr)277{278return __TBB_machine_fetchadd4(ptr, 1) + 1L;279}280#endif /* ITT_SIMPLE_INIT */281#endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */282283typedef enum {284__itt_collection_normal = 0,285__itt_collection_paused = 1286} __itt_collection_state;287288typedef enum {289__itt_thread_normal = 0,290__itt_thread_ignored = 1291} __itt_thread_state;292293#pragma pack(push, 8)294295typedef struct ___itt_thread_info296{297const char* nameA; /*!< Copy of original name in ASCII. */298#if defined(UNICODE) || defined(_UNICODE)299const wchar_t* nameW; /*!< Copy of original name in UNICODE. */300#else /* UNICODE || _UNICODE */301void* nameW;302#endif /* UNICODE || _UNICODE */303TIDT tid;304__itt_thread_state state; /*!< Thread state (paused or normal) */305int extra1; /*!< Reserved to the runtime */306void* extra2; /*!< Reserved to the runtime */307struct ___itt_thread_info* next;308} __itt_thread_info;309310#include "ittnotify_types.h" /* For __itt_group_id definition */311312typedef struct ___itt_api_info_20101001313{314const char* name;315void** func_ptr;316void* init_func;317__itt_group_id group;318} __itt_api_info_20101001;319320typedef struct ___itt_api_info321{322const char* name;323void** func_ptr;324void* init_func;325void* null_func;326__itt_group_id group;327} __itt_api_info;328329struct ___itt_domain;330struct ___itt_string_handle;331332typedef struct ___itt_global333{334unsigned char magic[8];335unsigned long version_major;336unsigned long version_minor;337unsigned long version_build;338volatile long api_initialized;339volatile long mutex_initialized;340volatile long atomic_counter;341mutex_t mutex;342lib_t lib;343void* error_handler;344const char** dll_path_ptr;345__itt_api_info* api_list_ptr;346struct ___itt_global* next;347/* Joinable structures below */348__itt_thread_info* thread_list;349struct ___itt_domain* domain_list;350struct ___itt_string_handle* string_list;351__itt_collection_state state;352} __itt_global;353354#pragma pack(pop)355356#define NEW_THREAD_INFO_W(gptr,h,h_tail,t,s,n) { \357h = (__itt_thread_info*)malloc(sizeof(__itt_thread_info)); \358if (h != NULL) { \359h->tid = t; \360h->nameA = NULL; \361h->nameW = n ? _wcsdup(n) : NULL; \362h->state = s; \363h->extra1 = 0; /* reserved */ \364h->extra2 = NULL; /* reserved */ \365h->next = NULL; \366if (h_tail == NULL) \367(gptr)->thread_list = h; \368else \369h_tail->next = h; \370} \371}372373#define NEW_THREAD_INFO_A(gptr,h,h_tail,t,s,n) { \374h = (__itt_thread_info*)malloc(sizeof(__itt_thread_info)); \375if (h != NULL) { \376h->tid = t; \377h->nameA = n ? __itt_fstrdup(n) : NULL; \378h->nameW = NULL; \379h->state = s; \380h->extra1 = 0; /* reserved */ \381h->extra2 = NULL; /* reserved */ \382h->next = NULL; \383if (h_tail == NULL) \384(gptr)->thread_list = h; \385else \386h_tail->next = h; \387} \388}389390#define NEW_DOMAIN_W(gptr,h,h_tail,name) { \391h = (__itt_domain*)malloc(sizeof(__itt_domain)); \392if (h != NULL) { \393h->flags = 0; /* domain is disabled by default */ \394h->nameA = NULL; \395h->nameW = name ? _wcsdup(name) : NULL; \396h->extra1 = 0; /* reserved */ \397h->extra2 = NULL; /* reserved */ \398h->next = NULL; \399if (h_tail == NULL) \400(gptr)->domain_list = h; \401else \402h_tail->next = h; \403} \404}405406#define NEW_DOMAIN_A(gptr,h,h_tail,name) { \407h = (__itt_domain*)malloc(sizeof(__itt_domain)); \408if (h != NULL) { \409h->flags = 0; /* domain is disabled by default */ \410h->nameA = name ? __itt_fstrdup(name) : NULL; \411h->nameW = NULL; \412h->extra1 = 0; /* reserved */ \413h->extra2 = NULL; /* reserved */ \414h->next = NULL; \415if (h_tail == NULL) \416(gptr)->domain_list = h; \417else \418h_tail->next = h; \419} \420}421422#define NEW_STRING_HANDLE_W(gptr,h,h_tail,name) { \423h = (__itt_string_handle*)malloc(sizeof(__itt_string_handle)); \424if (h != NULL) { \425h->strA = NULL; \426h->strW = name ? _wcsdup(name) : NULL; \427h->extra1 = 0; /* reserved */ \428h->extra2 = NULL; /* reserved */ \429h->next = NULL; \430if (h_tail == NULL) \431(gptr)->string_list = h; \432else \433h_tail->next = h; \434} \435}436437#define NEW_STRING_HANDLE_A(gptr,h,h_tail,name) { \438h = (__itt_string_handle*)malloc(sizeof(__itt_string_handle)); \439if (h != NULL) { \440h->strA = name ? __itt_fstrdup(name) : NULL; \441h->strW = NULL; \442h->extra1 = 0; /* reserved */ \443h->extra2 = NULL; /* reserved */ \444h->next = NULL; \445if (h_tail == NULL) \446(gptr)->string_list = h; \447else \448h_tail->next = h; \449} \450}451452#endif /* _ITTNOTIFY_CONFIG_H_ */453454455