LLVM API Documentation

JITEventListener.h
Go to the documentation of this file.
00001 //===- JITEventListener.h - Exposes events from JIT compilation -*- 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 the JITEventListener interface, which lets users get
00011 // callbacks when significant events happen during the JIT compilation process.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef LLVM_EXECUTIONENGINE_JITEVENTLISTENER_H
00016 #define LLVM_EXECUTIONENGINE_JITEVENTLISTENER_H
00017 
00018 #include "llvm/Config/llvm-config.h"
00019 #include "llvm/IR/DebugLoc.h"
00020 #include "llvm/Support/DataTypes.h"
00021 #include <vector>
00022 
00023 namespace llvm {
00024 class Function;
00025 class MachineFunction;
00026 class OProfileWrapper;
00027 class IntelJITEventsWrapper;
00028 class ObjectImage;
00029 
00030 /// JITEvent_EmittedFunctionDetails - Helper struct for containing information
00031 /// about a generated machine code function.
00032 struct JITEvent_EmittedFunctionDetails {
00033   struct LineStart {
00034     /// The address at which the current line changes.
00035     uintptr_t Address;
00036 
00037     /// The new location information.  These can be translated to DebugLocTuples
00038     /// using MF->getDebugLocTuple().
00039     DebugLoc Loc;
00040   };
00041 
00042   /// The machine function the struct contains information for.
00043   const MachineFunction *MF;
00044 
00045   /// The list of line boundary information, sorted by address.
00046   std::vector<LineStart> LineStarts;
00047 };
00048 
00049 /// JITEventListener - Abstract interface for use by the JIT to notify clients
00050 /// about significant events during compilation. For example, to notify
00051 /// profilers and debuggers that need to know where functions have been emitted.
00052 ///
00053 /// The default implementation of each method does nothing.
00054 class JITEventListener {
00055 public:
00056   typedef JITEvent_EmittedFunctionDetails EmittedFunctionDetails;
00057 
00058 public:
00059   JITEventListener() {}
00060   virtual ~JITEventListener();
00061 
00062   /// NotifyFunctionEmitted - Called after a function has been successfully
00063   /// emitted to memory.  The function still has its MachineFunction attached,
00064   /// if you should happen to need that.
00065   virtual void NotifyFunctionEmitted(const Function &,
00066                                      void *, size_t,
00067                                      const EmittedFunctionDetails &) {}
00068 
00069   /// NotifyFreeingMachineCode - Called from freeMachineCodeForFunction(), after
00070   /// the global mapping is removed, but before the machine code is returned to
00071   /// the allocator.
00072   ///
00073   /// OldPtr is the address of the machine code and will be the same as the Code
00074   /// parameter to a previous NotifyFunctionEmitted call.  The Function passed
00075   /// to NotifyFunctionEmitted may have been destroyed by the time of the
00076   /// matching NotifyFreeingMachineCode call.
00077   virtual void NotifyFreeingMachineCode(void *) {}
00078 
00079   /// NotifyObjectEmitted - Called after an object has been successfully
00080   /// emitted to memory.  NotifyFunctionEmitted will not be called for
00081   /// individual functions in the object.
00082   ///
00083   /// ELF-specific information
00084   /// The ObjectImage contains the generated object image
00085   /// with section headers updated to reflect the address at which sections
00086   /// were loaded and with relocations performed in-place on debug sections.
00087   virtual void NotifyObjectEmitted(const ObjectImage &Obj) {}
00088 
00089   /// NotifyFreeingObject - Called just before the memory associated with
00090   /// a previously emitted object is released.
00091   virtual void NotifyFreeingObject(const ObjectImage &Obj) {}
00092 
00093 #if LLVM_USE_INTEL_JITEVENTS
00094   // Construct an IntelJITEventListener
00095   static JITEventListener *createIntelJITEventListener();
00096 
00097   // Construct an IntelJITEventListener with a test Intel JIT API implementation
00098   static JITEventListener *createIntelJITEventListener(
00099                                       IntelJITEventsWrapper* AlternativeImpl);
00100 #else
00101   static JITEventListener *createIntelJITEventListener() { return nullptr; }
00102 
00103   static JITEventListener *createIntelJITEventListener(
00104                                       IntelJITEventsWrapper* AlternativeImpl) {
00105     return nullptr;
00106   }
00107 #endif // USE_INTEL_JITEVENTS
00108 
00109 #if LLVM_USE_OPROFILE
00110   // Construct an OProfileJITEventListener
00111   static JITEventListener *createOProfileJITEventListener();
00112 
00113   // Construct an OProfileJITEventListener with a test opagent implementation
00114   static JITEventListener *createOProfileJITEventListener(
00115                                       OProfileWrapper* AlternativeImpl);
00116 #else
00117 
00118   static JITEventListener *createOProfileJITEventListener() { return nullptr; }
00119 
00120   static JITEventListener *createOProfileJITEventListener(
00121                                       OProfileWrapper* AlternativeImpl) {
00122     return nullptr;
00123   }
00124 #endif // USE_OPROFILE
00125 
00126 };
00127 
00128 } // end namespace llvm.
00129 
00130 #endif // defined LLVM_EXECUTIONENGINE_JITEVENTLISTENER_H