LLVM API Documentation

IntelJITEventsWrapper.h
Go to the documentation of this file.
00001 //===-- IntelJITEventsWrapper.h - Intel JIT Events API Wrapper --*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines a wrapper for the Intel JIT Events API. It allows for the
00011 // implementation of the jitprofiling library to be swapped with an alternative
00012 // implementation (for testing). To include this file, you must have the
00013 // jitprofiling.h header available; it is available in Intel(R) VTune(TM)
00014 // Amplifier XE 2011.
00015 //
00016 //===----------------------------------------------------------------------===//
00017 
00018 #ifndef INTEL_JIT_EVENTS_WRAPPER_H
00019 #define INTEL_JIT_EVENTS_WRAPPER_H
00020 
00021 #include "jitprofiling.h"
00022 
00023 namespace llvm {
00024 
00025 class IntelJITEventsWrapper {
00026   // Function pointer types for testing implementation of Intel jitprofiling
00027   // library
00028   typedef int (*NotifyEventPtr)(iJIT_JVM_EVENT, void*);
00029   typedef void (*RegisterCallbackExPtr)(void *, iJIT_ModeChangedEx );
00030   typedef iJIT_IsProfilingActiveFlags (*IsProfilingActivePtr)(void);
00031   typedef void (*FinalizeThreadPtr)(void);
00032   typedef void (*FinalizeProcessPtr)(void);
00033   typedef unsigned int (*GetNewMethodIDPtr)(void);
00034 
00035   NotifyEventPtr NotifyEventFunc;
00036   RegisterCallbackExPtr RegisterCallbackExFunc;
00037   IsProfilingActivePtr IsProfilingActiveFunc;
00038   GetNewMethodIDPtr GetNewMethodIDFunc;
00039 
00040 public:
00041   bool isAmplifierRunning() {
00042     return iJIT_IsProfilingActive() == iJIT_SAMPLING_ON;
00043   }
00044 
00045   IntelJITEventsWrapper()
00046   : NotifyEventFunc(::iJIT_NotifyEvent),
00047     RegisterCallbackExFunc(::iJIT_RegisterCallbackEx),
00048     IsProfilingActiveFunc(::iJIT_IsProfilingActive),
00049     GetNewMethodIDFunc(::iJIT_GetNewMethodID) {
00050   }
00051 
00052   IntelJITEventsWrapper(NotifyEventPtr NotifyEventImpl,
00053                    RegisterCallbackExPtr RegisterCallbackExImpl,
00054                    IsProfilingActivePtr IsProfilingActiveImpl,
00055                    FinalizeThreadPtr FinalizeThreadImpl,
00056                    FinalizeProcessPtr FinalizeProcessImpl,
00057                    GetNewMethodIDPtr GetNewMethodIDImpl)
00058   : NotifyEventFunc(NotifyEventImpl),
00059     RegisterCallbackExFunc(RegisterCallbackExImpl),
00060     IsProfilingActiveFunc(IsProfilingActiveImpl),
00061     GetNewMethodIDFunc(GetNewMethodIDImpl) {
00062   }
00063 
00064   // Sends an event announcing that a function has been emitted
00065   //   return values are event-specific.  See Intel documentation for details.
00066   int  iJIT_NotifyEvent(iJIT_JVM_EVENT EventType, void *EventSpecificData) {
00067     if (!NotifyEventFunc)
00068       return -1;
00069     return NotifyEventFunc(EventType, EventSpecificData);
00070   }
00071 
00072   // Registers a callback function to receive notice of profiling state changes
00073   void iJIT_RegisterCallbackEx(void *UserData,
00074                                iJIT_ModeChangedEx NewModeCallBackFuncEx) {
00075     if (RegisterCallbackExFunc)
00076       RegisterCallbackExFunc(UserData, NewModeCallBackFuncEx);
00077   }
00078 
00079   // Returns the current profiler mode
00080   iJIT_IsProfilingActiveFlags iJIT_IsProfilingActive(void) {
00081     if (!IsProfilingActiveFunc)
00082       return iJIT_NOTHING_RUNNING;
00083     return IsProfilingActiveFunc();
00084   }
00085 
00086   // Generates a locally unique method ID for use in code registration
00087   unsigned int iJIT_GetNewMethodID(void) {
00088     if (!GetNewMethodIDFunc)
00089       return -1;
00090     return GetNewMethodIDFunc();
00091   }
00092 };
00093 
00094 } //namespace llvm
00095 
00096 #endif //INTEL_JIT_EVENTS_WRAPPER_H