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_EXECUTION_ENGINE_JIT_EVENTLISTENER_H
     16 #define LLVM_EXECUTION_ENGINE_JIT_EVENTLISTENER_H
     17 
     18 #include "llvm/Support/DataTypes.h"
     19 #include "llvm/Support/DebugLoc.h"
     20 
     21 #include <vector>
     22 
     23 namespace llvm {
     24 class Function;
     25 class MachineFunction;
     26 
     27 /// JITEvent_EmittedFunctionDetails - Helper struct for containing information
     28 /// about a generated machine code function.
     29 struct JITEvent_EmittedFunctionDetails {
     30   struct LineStart {
     31     /// The address at which the current line changes.
     32     uintptr_t Address;
     33 
     34     /// The new location information.  These can be translated to DebugLocTuples
     35     /// using MF->getDebugLocTuple().
     36     DebugLoc Loc;
     37   };
     38 
     39   /// The machine function the struct contains information for.
     40   const MachineFunction *MF;
     41 
     42   /// The list of line boundary information, sorted by address.
     43   std::vector<LineStart> LineStarts;
     44 };
     45 
     46 /// JITEventListener - Abstract interface for use by the JIT to notify clients
     47 /// about significant events during compilation. For example, to notify
     48 /// profilers and debuggers that need to know where functions have been emitted.
     49 ///
     50 /// The default implementation of each method does nothing.
     51 class JITEventListener {
     52 public:
     53   typedef JITEvent_EmittedFunctionDetails EmittedFunctionDetails;
     54 
     55 public:
     56   JITEventListener() {}
     57   virtual ~JITEventListener();
     58 
     59   /// NotifyFunctionEmitted - Called after a function has been successfully
     60   /// emitted to memory.  The function still has its MachineFunction attached,
     61   /// if you should happen to need that.
     62   virtual void NotifyFunctionEmitted(const Function &F,
     63                                      void *Code, size_t Size,
     64                                      const EmittedFunctionDetails &Details) {}
     65 
     66   /// NotifyFreeingMachineCode - Called from freeMachineCodeForFunction(), after
     67   /// the global mapping is removed, but before the machine code is returned to
     68   /// the allocator.
     69   ///
     70   /// OldPtr is the address of the machine code and will be the same as the Code
     71   /// parameter to a previous NotifyFunctionEmitted call.  The Function passed
     72   /// to NotifyFunctionEmitted may have been destroyed by the time of the
     73   /// matching NotifyFreeingMachineCode call.
     74   virtual void NotifyFreeingMachineCode(void *OldPtr) {}
     75 };
     76 
     77 // This returns NULL if support isn't available.
     78 JITEventListener *createOProfileJITEventListener();
     79 
     80 } // end namespace llvm.
     81 
     82 #endif
     83