Home | History | Annotate | Download | only in ExecutionEngine
      1 //===- JITEventListener.h - Exposes events from JIT compilation -*- 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 the JITEventListener interface, which lets users get
     11 // callbacks when significant events happen during the JIT compilation process.
     12 //
     13 //===----------------------------------------------------------------------===//
     14 
     15 #ifndef LLVM_EXECUTIONENGINE_JITEVENTLISTENER_H
     16 #define LLVM_EXECUTIONENGINE_JITEVENTLISTENER_H
     17 
     18 #include "llvm/Config/llvm-config.h"
     19 #include "llvm/ExecutionEngine/RuntimeDyld.h"
     20 #include "llvm/IR/DebugLoc.h"
     21 #include <cstdint>
     22 #include <vector>
     23 
     24 namespace llvm {
     25 
     26 class IntelJITEventsWrapper;
     27 class MachineFunction;
     28 class OProfileWrapper;
     29 
     30 namespace object {
     31 
     32 class ObjectFile;
     33 
     34 } // end namespace object
     35 
     36 /// JITEvent_EmittedFunctionDetails - Helper struct for containing information
     37 /// about a generated machine code function.
     38 struct JITEvent_EmittedFunctionDetails {
     39   struct LineStart {
     40     /// The address at which the current line changes.
     41     uintptr_t Address;
     42 
     43     /// The new location information.  These can be translated to DebugLocTuples
     44     /// using MF->getDebugLocTuple().
     45     DebugLoc Loc;
     46   };
     47 
     48   /// The machine function the struct contains information for.
     49   const MachineFunction *MF;
     50 
     51   /// The list of line boundary information, sorted by address.
     52   std::vector<LineStart> LineStarts;
     53 };
     54 
     55 /// JITEventListener - Abstract interface for use by the JIT to notify clients
     56 /// about significant events during compilation. For example, to notify
     57 /// profilers and debuggers that need to know where functions have been emitted.
     58 ///
     59 /// The default implementation of each method does nothing.
     60 class JITEventListener {
     61 public:
     62   using EmittedFunctionDetails = JITEvent_EmittedFunctionDetails;
     63 
     64 public:
     65   JITEventListener() = default;
     66   virtual ~JITEventListener() = default;
     67 
     68   /// NotifyObjectEmitted - Called after an object has been successfully
     69   /// emitted to memory.  NotifyFunctionEmitted will not be called for
     70   /// individual functions in the object.
     71   ///
     72   /// ELF-specific information
     73   /// The ObjectImage contains the generated object image
     74   /// with section headers updated to reflect the address at which sections
     75   /// were loaded and with relocations performed in-place on debug sections.
     76   virtual void NotifyObjectEmitted(const object::ObjectFile &Obj,
     77                                    const RuntimeDyld::LoadedObjectInfo &L) {}
     78 
     79   /// NotifyFreeingObject - Called just before the memory associated with
     80   /// a previously emitted object is released.
     81   virtual void NotifyFreeingObject(const object::ObjectFile &Obj) {}
     82 
     83   // Get a pointe to the GDB debugger registration listener.
     84   static JITEventListener *createGDBRegistrationListener();
     85 
     86 #if LLVM_USE_INTEL_JITEVENTS
     87   // Construct an IntelJITEventListener
     88   static JITEventListener *createIntelJITEventListener();
     89 
     90   // Construct an IntelJITEventListener with a test Intel JIT API implementation
     91   static JITEventListener *createIntelJITEventListener(
     92                                       IntelJITEventsWrapper* AlternativeImpl);
     93 #else
     94   static JITEventListener *createIntelJITEventListener() { return nullptr; }
     95 
     96   static JITEventListener *createIntelJITEventListener(
     97                                       IntelJITEventsWrapper* AlternativeImpl) {
     98     return nullptr;
     99   }
    100 #endif // USE_INTEL_JITEVENTS
    101 
    102 #if LLVM_USE_OPROFILE
    103   // Construct an OProfileJITEventListener
    104   static JITEventListener *createOProfileJITEventListener();
    105 
    106   // Construct an OProfileJITEventListener with a test opagent implementation
    107   static JITEventListener *createOProfileJITEventListener(
    108                                       OProfileWrapper* AlternativeImpl);
    109 #else
    110   static JITEventListener *createOProfileJITEventListener() { return nullptr; }
    111 
    112   static JITEventListener *createOProfileJITEventListener(
    113                                       OProfileWrapper* AlternativeImpl) {
    114     return nullptr;
    115   }
    116 #endif // USE_OPROFILE
    117 
    118 private:
    119   virtual void anchor();
    120 };
    121 
    122 } // end namespace llvm
    123 
    124 #endif // LLVM_EXECUTIONENGINE_JITEVENTLISTENER_H
    125