xref: /aosp_15_r20/external/llvm/lib/ExecutionEngine/IntelJITEvents/IntelJITEventsWrapper.h (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker //===-- IntelJITEventsWrapper.h - Intel JIT Events API Wrapper --*- C++ -*-===//
2*9880d681SAndroid Build Coastguard Worker //
3*9880d681SAndroid Build Coastguard Worker //                     The LLVM Compiler Infrastructure
4*9880d681SAndroid Build Coastguard Worker //
5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source
6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details.
7*9880d681SAndroid Build Coastguard Worker //
8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*9880d681SAndroid Build Coastguard Worker //
10*9880d681SAndroid Build Coastguard Worker // This file defines a wrapper for the Intel JIT Events API. It allows for the
11*9880d681SAndroid Build Coastguard Worker // implementation of the jitprofiling library to be swapped with an alternative
12*9880d681SAndroid Build Coastguard Worker // implementation (for testing). To include this file, you must have the
13*9880d681SAndroid Build Coastguard Worker // jitprofiling.h header available; it is available in Intel(R) VTune(TM)
14*9880d681SAndroid Build Coastguard Worker // Amplifier XE 2011.
15*9880d681SAndroid Build Coastguard Worker //
16*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
17*9880d681SAndroid Build Coastguard Worker 
18*9880d681SAndroid Build Coastguard Worker #ifndef INTEL_JIT_EVENTS_WRAPPER_H
19*9880d681SAndroid Build Coastguard Worker #define INTEL_JIT_EVENTS_WRAPPER_H
20*9880d681SAndroid Build Coastguard Worker 
21*9880d681SAndroid Build Coastguard Worker #include "jitprofiling.h"
22*9880d681SAndroid Build Coastguard Worker 
23*9880d681SAndroid Build Coastguard Worker namespace llvm {
24*9880d681SAndroid Build Coastguard Worker 
25*9880d681SAndroid Build Coastguard Worker class IntelJITEventsWrapper {
26*9880d681SAndroid Build Coastguard Worker   // Function pointer types for testing implementation of Intel jitprofiling
27*9880d681SAndroid Build Coastguard Worker   // library
28*9880d681SAndroid Build Coastguard Worker   typedef int (*NotifyEventPtr)(iJIT_JVM_EVENT, void*);
29*9880d681SAndroid Build Coastguard Worker   typedef void (*RegisterCallbackExPtr)(void *, iJIT_ModeChangedEx );
30*9880d681SAndroid Build Coastguard Worker   typedef iJIT_IsProfilingActiveFlags (*IsProfilingActivePtr)(void);
31*9880d681SAndroid Build Coastguard Worker   typedef void (*FinalizeThreadPtr)(void);
32*9880d681SAndroid Build Coastguard Worker   typedef void (*FinalizeProcessPtr)(void);
33*9880d681SAndroid Build Coastguard Worker   typedef unsigned int (*GetNewMethodIDPtr)(void);
34*9880d681SAndroid Build Coastguard Worker 
35*9880d681SAndroid Build Coastguard Worker   NotifyEventPtr NotifyEventFunc;
36*9880d681SAndroid Build Coastguard Worker   RegisterCallbackExPtr RegisterCallbackExFunc;
37*9880d681SAndroid Build Coastguard Worker   IsProfilingActivePtr IsProfilingActiveFunc;
38*9880d681SAndroid Build Coastguard Worker   GetNewMethodIDPtr GetNewMethodIDFunc;
39*9880d681SAndroid Build Coastguard Worker 
40*9880d681SAndroid Build Coastguard Worker public:
isAmplifierRunning()41*9880d681SAndroid Build Coastguard Worker   bool isAmplifierRunning() {
42*9880d681SAndroid Build Coastguard Worker     return iJIT_IsProfilingActive() == iJIT_SAMPLING_ON;
43*9880d681SAndroid Build Coastguard Worker   }
44*9880d681SAndroid Build Coastguard Worker 
IntelJITEventsWrapper()45*9880d681SAndroid Build Coastguard Worker   IntelJITEventsWrapper()
46*9880d681SAndroid Build Coastguard Worker   : NotifyEventFunc(::iJIT_NotifyEvent),
47*9880d681SAndroid Build Coastguard Worker     RegisterCallbackExFunc(::iJIT_RegisterCallbackEx),
48*9880d681SAndroid Build Coastguard Worker     IsProfilingActiveFunc(::iJIT_IsProfilingActive),
49*9880d681SAndroid Build Coastguard Worker     GetNewMethodIDFunc(::iJIT_GetNewMethodID) {
50*9880d681SAndroid Build Coastguard Worker   }
51*9880d681SAndroid Build Coastguard Worker 
IntelJITEventsWrapper(NotifyEventPtr NotifyEventImpl,RegisterCallbackExPtr RegisterCallbackExImpl,IsProfilingActivePtr IsProfilingActiveImpl,FinalizeThreadPtr FinalizeThreadImpl,FinalizeProcessPtr FinalizeProcessImpl,GetNewMethodIDPtr GetNewMethodIDImpl)52*9880d681SAndroid Build Coastguard Worker   IntelJITEventsWrapper(NotifyEventPtr NotifyEventImpl,
53*9880d681SAndroid Build Coastguard Worker                    RegisterCallbackExPtr RegisterCallbackExImpl,
54*9880d681SAndroid Build Coastguard Worker                    IsProfilingActivePtr IsProfilingActiveImpl,
55*9880d681SAndroid Build Coastguard Worker                    FinalizeThreadPtr FinalizeThreadImpl,
56*9880d681SAndroid Build Coastguard Worker                    FinalizeProcessPtr FinalizeProcessImpl,
57*9880d681SAndroid Build Coastguard Worker                    GetNewMethodIDPtr GetNewMethodIDImpl)
58*9880d681SAndroid Build Coastguard Worker   : NotifyEventFunc(NotifyEventImpl),
59*9880d681SAndroid Build Coastguard Worker     RegisterCallbackExFunc(RegisterCallbackExImpl),
60*9880d681SAndroid Build Coastguard Worker     IsProfilingActiveFunc(IsProfilingActiveImpl),
61*9880d681SAndroid Build Coastguard Worker     GetNewMethodIDFunc(GetNewMethodIDImpl) {
62*9880d681SAndroid Build Coastguard Worker   }
63*9880d681SAndroid Build Coastguard Worker 
64*9880d681SAndroid Build Coastguard Worker   // Sends an event announcing that a function has been emitted
65*9880d681SAndroid Build Coastguard Worker   //   return values are event-specific.  See Intel documentation for details.
iJIT_NotifyEvent(iJIT_JVM_EVENT EventType,void * EventSpecificData)66*9880d681SAndroid Build Coastguard Worker   int  iJIT_NotifyEvent(iJIT_JVM_EVENT EventType, void *EventSpecificData) {
67*9880d681SAndroid Build Coastguard Worker     if (!NotifyEventFunc)
68*9880d681SAndroid Build Coastguard Worker       return -1;
69*9880d681SAndroid Build Coastguard Worker     return NotifyEventFunc(EventType, EventSpecificData);
70*9880d681SAndroid Build Coastguard Worker   }
71*9880d681SAndroid Build Coastguard Worker 
72*9880d681SAndroid Build Coastguard Worker   // Registers a callback function to receive notice of profiling state changes
iJIT_RegisterCallbackEx(void * UserData,iJIT_ModeChangedEx NewModeCallBackFuncEx)73*9880d681SAndroid Build Coastguard Worker   void iJIT_RegisterCallbackEx(void *UserData,
74*9880d681SAndroid Build Coastguard Worker                                iJIT_ModeChangedEx NewModeCallBackFuncEx) {
75*9880d681SAndroid Build Coastguard Worker     if (RegisterCallbackExFunc)
76*9880d681SAndroid Build Coastguard Worker       RegisterCallbackExFunc(UserData, NewModeCallBackFuncEx);
77*9880d681SAndroid Build Coastguard Worker   }
78*9880d681SAndroid Build Coastguard Worker 
79*9880d681SAndroid Build Coastguard Worker   // Returns the current profiler mode
iJIT_IsProfilingActive(void)80*9880d681SAndroid Build Coastguard Worker   iJIT_IsProfilingActiveFlags iJIT_IsProfilingActive(void) {
81*9880d681SAndroid Build Coastguard Worker     if (!IsProfilingActiveFunc)
82*9880d681SAndroid Build Coastguard Worker       return iJIT_NOTHING_RUNNING;
83*9880d681SAndroid Build Coastguard Worker     return IsProfilingActiveFunc();
84*9880d681SAndroid Build Coastguard Worker   }
85*9880d681SAndroid Build Coastguard Worker 
86*9880d681SAndroid Build Coastguard Worker   // Generates a locally unique method ID for use in code registration
iJIT_GetNewMethodID(void)87*9880d681SAndroid Build Coastguard Worker   unsigned int iJIT_GetNewMethodID(void) {
88*9880d681SAndroid Build Coastguard Worker     if (!GetNewMethodIDFunc)
89*9880d681SAndroid Build Coastguard Worker       return -1;
90*9880d681SAndroid Build Coastguard Worker     return GetNewMethodIDFunc();
91*9880d681SAndroid Build Coastguard Worker   }
92*9880d681SAndroid Build Coastguard Worker };
93*9880d681SAndroid Build Coastguard Worker 
94*9880d681SAndroid Build Coastguard Worker } //namespace llvm
95*9880d681SAndroid Build Coastguard Worker 
96*9880d681SAndroid Build Coastguard Worker #endif //INTEL_JIT_EVENTS_WRAPPER_H
97