Path: blob/main/contrib/llvm-project/llvm/lib/ExecutionEngine/IntelJITProfiling/IntelJITEventsWrapper.h
35271 views
//===-- IntelJITEventsWrapper.h - Intel JIT Events API Wrapper --*- 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 defines a wrapper for the Intel JIT Events API. It allows for the9// implementation of the jitprofiling library to be swapped with an alternative10// implementation (for testing). To include this file, you must have the11// jitprofiling.h header available; it is available in Intel(R) VTune(TM)12// Amplifier XE 2011.13//14//===----------------------------------------------------------------------===//1516#ifndef INTEL_JIT_EVENTS_WRAPPER_H17#define INTEL_JIT_EVENTS_WRAPPER_H1819#include "jitprofiling.h"2021namespace llvm {2223typedef enum {24LoadBinaryModule,25LoadBinarySection,26UnloadBinaryModule,27UnloadBinarySection28} IttEventType;2930class IntelJITEventsWrapper {31// Function pointer types for testing implementation of Intel jitprofiling32// library33typedef int (*NotifyEventPtr)(iJIT_JVM_EVENT, void*);34typedef int (*IttnotifyInfoPtr)(IttEventType, const char *, unsigned int);35typedef void (*RegisterCallbackExPtr)(void *, iJIT_ModeChangedEx );36typedef iJIT_IsProfilingActiveFlags (*IsProfilingActivePtr)(void);37typedef void (*FinalizeThreadPtr)(void);38typedef void (*FinalizeProcessPtr)(void);39typedef unsigned int (*GetNewMethodIDPtr)(void);4041NotifyEventPtr NotifyEventFunc;42IttnotifyInfoPtr IttnotifyInfoFunc;43RegisterCallbackExPtr RegisterCallbackExFunc;44IsProfilingActivePtr IsProfilingActiveFunc;45GetNewMethodIDPtr GetNewMethodIDFunc;4647public:48bool isAmplifierRunning() {49return iJIT_IsProfilingActive() == iJIT_SAMPLING_ON;50}5152IntelJITEventsWrapper()53: NotifyEventFunc(::iJIT_NotifyEvent), IttnotifyInfoFunc(0),54RegisterCallbackExFunc(::iJIT_RegisterCallbackEx),55IsProfilingActiveFunc(::iJIT_IsProfilingActive),56GetNewMethodIDFunc(::iJIT_GetNewMethodID) {}5758IntelJITEventsWrapper(NotifyEventPtr NotifyEventImpl,59IttnotifyInfoPtr IttnotifyInfoImpl,60RegisterCallbackExPtr RegisterCallbackExImpl,61IsProfilingActivePtr IsProfilingActiveImpl,62FinalizeThreadPtr FinalizeThreadImpl,63FinalizeProcessPtr FinalizeProcessImpl,64GetNewMethodIDPtr GetNewMethodIDImpl)65: NotifyEventFunc(NotifyEventImpl), IttnotifyInfoFunc(IttnotifyInfoImpl),66RegisterCallbackExFunc(RegisterCallbackExImpl),67IsProfilingActiveFunc(IsProfilingActiveImpl),68GetNewMethodIDFunc(GetNewMethodIDImpl) {}6970// Sends an event announcing that a function has been emitted71// return values are event-specific. See Intel documentation for details.72int iJIT_NotifyEvent(iJIT_JVM_EVENT EventType, void *EventSpecificData) {73if (!NotifyEventFunc)74return -1;75return NotifyEventFunc(EventType, EventSpecificData);76}7778int iJitIttNotifyInfo(IttEventType EventType, const char *Name,79unsigned int Size) {80if (!IttnotifyInfoFunc)81return -1;82return IttnotifyInfoFunc(EventType, Name, Size);83}8485// Registers a callback function to receive notice of profiling state changes86void iJIT_RegisterCallbackEx(void *UserData,87iJIT_ModeChangedEx NewModeCallBackFuncEx) {88if (RegisterCallbackExFunc)89RegisterCallbackExFunc(UserData, NewModeCallBackFuncEx);90}9192// Returns the current profiler mode93iJIT_IsProfilingActiveFlags iJIT_IsProfilingActive(void) {94if (!IsProfilingActiveFunc)95return iJIT_NOTHING_RUNNING;96return IsProfilingActiveFunc();97}9899// Generates a locally unique method ID for use in code registration100unsigned int iJIT_GetNewMethodID(void) {101if (!GetNewMethodIDFunc)102return -1;103return GetNewMethodIDFunc();104}105};106107} // namespace llvm108109#endif //INTEL_JIT_EVENTS_WRAPPER_H110111112