LLVM  12.0.0git
IntelJITEventsWrapper.h
Go to the documentation of this file.
1 //===-- IntelJITEventsWrapper.h - Intel JIT Events API Wrapper --*- 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-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines a wrapper for the Intel JIT Events API. It allows for the
10 // implementation of the jitprofiling library to be swapped with an alternative
11 // implementation (for testing). To include this file, you must have the
12 // jitprofiling.h header available; it is available in Intel(R) VTune(TM)
13 // Amplifier XE 2011.
14 //
15 //===----------------------------------------------------------------------===//
16 
17 #ifndef INTEL_JIT_EVENTS_WRAPPER_H
18 #define INTEL_JIT_EVENTS_WRAPPER_H
19 
20 #include "jitprofiling.h"
21 
22 namespace llvm {
23 
25  // Function pointer types for testing implementation of Intel jitprofiling
26  // library
27  typedef int (*NotifyEventPtr)(iJIT_JVM_EVENT, void*);
28  typedef void (*RegisterCallbackExPtr)(void *, iJIT_ModeChangedEx );
29  typedef iJIT_IsProfilingActiveFlags (*IsProfilingActivePtr)(void);
30  typedef void (*FinalizeThreadPtr)(void);
31  typedef void (*FinalizeProcessPtr)(void);
32  typedef unsigned int (*GetNewMethodIDPtr)(void);
33 
34  NotifyEventPtr NotifyEventFunc;
35  RegisterCallbackExPtr RegisterCallbackExFunc;
36  IsProfilingActivePtr IsProfilingActiveFunc;
37  GetNewMethodIDPtr GetNewMethodIDFunc;
38 
39 public:
42  }
43 
45  : NotifyEventFunc(::iJIT_NotifyEvent),
46  RegisterCallbackExFunc(::iJIT_RegisterCallbackEx),
47  IsProfilingActiveFunc(::iJIT_IsProfilingActive),
48  GetNewMethodIDFunc(::iJIT_GetNewMethodID) {
49  }
50 
51  IntelJITEventsWrapper(NotifyEventPtr NotifyEventImpl,
52  RegisterCallbackExPtr RegisterCallbackExImpl,
53  IsProfilingActivePtr IsProfilingActiveImpl,
54  FinalizeThreadPtr FinalizeThreadImpl,
55  FinalizeProcessPtr FinalizeProcessImpl,
56  GetNewMethodIDPtr GetNewMethodIDImpl)
57  : NotifyEventFunc(NotifyEventImpl),
58  RegisterCallbackExFunc(RegisterCallbackExImpl),
59  IsProfilingActiveFunc(IsProfilingActiveImpl),
60  GetNewMethodIDFunc(GetNewMethodIDImpl) {
61  }
62 
63  // Sends an event announcing that a function has been emitted
64  // return values are event-specific. See Intel documentation for details.
65  int iJIT_NotifyEvent(iJIT_JVM_EVENT EventType, void *EventSpecificData) {
66  if (!NotifyEventFunc)
67  return -1;
68  return NotifyEventFunc(EventType, EventSpecificData);
69  }
70 
71  // Registers a callback function to receive notice of profiling state changes
72  void iJIT_RegisterCallbackEx(void *UserData,
73  iJIT_ModeChangedEx NewModeCallBackFuncEx) {
74  if (RegisterCallbackExFunc)
75  RegisterCallbackExFunc(UserData, NewModeCallBackFuncEx);
76  }
77 
78  // Returns the current profiler mode
80  if (!IsProfilingActiveFunc)
81  return iJIT_NOTHING_RUNNING;
82  return IsProfilingActiveFunc();
83  }
84 
85  // Generates a locally unique method ID for use in code registration
86  unsigned int iJIT_GetNewMethodID(void) {
87  if (!GetNewMethodIDFunc)
88  return -1;
89  return GetNewMethodIDFunc();
90  }
91 };
92 
93 } //namespace llvm
94 
95 #endif //INTEL_JIT_EVENTS_WRAPPER_H
This class represents lattice values for constants.
Definition: AllocatorList.h:23
iJIT_IsProfilingActiveFlags iJIT_IsProfilingActive(void)
enum iJIT_jvm_event iJIT_JVM_EVENT
void(* iJIT_ModeChangedEx)(void *UserData, iJIT_ModeFlags Flags)
Definition: jitprofiling.h:238
void iJIT_RegisterCallbackEx(void *UserData, iJIT_ModeChangedEx NewModeCallBackFuncEx)
IntelJITEventsWrapper(NotifyEventPtr NotifyEventImpl, RegisterCallbackExPtr RegisterCallbackExImpl, IsProfilingActivePtr IsProfilingActiveImpl, FinalizeThreadPtr FinalizeThreadImpl, FinalizeProcessPtr FinalizeProcessImpl, GetNewMethodIDPtr GetNewMethodIDImpl)
int iJIT_NotifyEvent(iJIT_JVM_EVENT EventType, void *EventSpecificData)
unsigned int iJIT_GetNewMethodID(void)
enum _iJIT_IsProfilingActiveFlags iJIT_IsProfilingActiveFlags