IntelJITEventsWrapper.h 3.4 KB

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