JITEventListener.h revision 276479
16059Samurai//===- JITEventListener.h - Exposes events from JIT compilation -*- C++ -*-===//
26059Samurai//
36059Samurai//                     The LLVM Compiler Infrastructure
46059Samurai//
56059Samurai// This file is distributed under the University of Illinois Open Source
66059Samurai// License. See LICENSE.TXT for details.
76059Samurai//
86059Samurai//===----------------------------------------------------------------------===//
96059Samurai//
106059Samurai// This file defines the JITEventListener interface, which lets users get
116059Samurai// callbacks when significant events happen during the JIT compilation process.
126059Samurai//
136059Samurai//===----------------------------------------------------------------------===//
146059Samurai
156059Samurai#ifndef LLVM_EXECUTIONENGINE_JITEVENTLISTENER_H
166059Samurai#define LLVM_EXECUTIONENGINE_JITEVENTLISTENER_H
176059Samurai
186059Samurai#include "llvm/Config/llvm-config.h"
198857Srgrimes#include "llvm/IR/DebugLoc.h"
2031080Sbrian#include "llvm/Support/DataTypes.h"
218857Srgrimes#include <vector>
226059Samurai
2330715Sbriannamespace llvm {
2430715Sbrianclass Function;
2526031Sbrianclass MachineFunction;
2630715Sbrianclass OProfileWrapper;
2726031Sbrianclass IntelJITEventsWrapper;
2830715Sbrianclass ObjectImage;
2926031Sbrian
3030715Sbrian/// JITEvent_EmittedFunctionDetails - Helper struct for containing information
3130715Sbrian/// about a generated machine code function.
3226031Sbrianstruct JITEvent_EmittedFunctionDetails {
3330715Sbrian  struct LineStart {
3430715Sbrian    /// The address at which the current line changes.
3526516Sbrian    uintptr_t Address;
3630715Sbrian
3730715Sbrian    /// The new location information.  These can be translated to DebugLocTuples
3830715Sbrian    /// using MF->getDebugLocTuple().
3930715Sbrian    DebugLoc Loc;
4030715Sbrian  };
4130715Sbrian
4230715Sbrian  /// The machine function the struct contains information for.
4330715Sbrian  const MachineFunction *MF;
4430715Sbrian
4530715Sbrian  /// The list of line boundary information, sorted by address.
4630715Sbrian  std::vector<LineStart> LineStarts;
4730715Sbrian};
4830715Sbrian
4930715Sbrian/// JITEventListener - Abstract interface for use by the JIT to notify clients
506059Samurai/// about significant events during compilation. For example, to notify
516059Samurai/// profilers and debuggers that need to know where functions have been emitted.
526059Samurai///
536059Samurai/// The default implementation of each method does nothing.
546059Samuraiclass JITEventListener {
5530715Sbrianpublic:
5613389Sphk  typedef JITEvent_EmittedFunctionDetails EmittedFunctionDetails;
5726031Sbrian
586059Samuraipublic:
5926142Sbrian  JITEventListener() {}
606059Samurai  virtual ~JITEventListener();
6125630Sbrian
6225630Sbrian  /// NotifyFunctionEmitted - Called after a function has been successfully
636059Samurai  /// emitted to memory.  The function still has its MachineFunction attached,
6426940Sbrian  /// if you should happen to need that.
6530715Sbrian  virtual void NotifyFunctionEmitted(const Function &,
6630715Sbrian                                     void *, size_t,
6730715Sbrian                                     const EmittedFunctionDetails &) {}
6830733Sbrian
6930715Sbrian  /// NotifyFreeingMachineCode - Called from freeMachineCodeForFunction(), after
7031080Sbrian  /// the global mapping is removed, but before the machine code is returned to
716059Samurai  /// the allocator.
726059Samurai  ///
736059Samurai  /// OldPtr is the address of the machine code and will be the same as the Code
7428679Sbrian  /// parameter to a previous NotifyFunctionEmitted call.  The Function passed
7528679Sbrian  /// to NotifyFunctionEmitted may have been destroyed by the time of the
7628679Sbrian  /// matching NotifyFreeingMachineCode call.
7728679Sbrian  virtual void NotifyFreeingMachineCode(void *) {}
7828679Sbrian
7928679Sbrian  /// NotifyObjectEmitted - Called after an object has been successfully
8028679Sbrian  /// emitted to memory.  NotifyFunctionEmitted will not be called for
8128679Sbrian  /// individual functions in the object.
8228679Sbrian  ///
8328679Sbrian  /// ELF-specific information
8428679Sbrian  /// The ObjectImage contains the generated object image
8528679Sbrian  /// with section headers updated to reflect the address at which sections
8630715Sbrian  /// were loaded and with relocations performed in-place on debug sections.
8730715Sbrian  virtual void NotifyObjectEmitted(const ObjectImage &Obj) {}
8830715Sbrian
896059Samurai  /// NotifyFreeingObject - Called just before the memory associated with
906059Samurai  /// a previously emitted object is released.
9128679Sbrian  virtual void NotifyFreeingObject(const ObjectImage &Obj) {}
9228679Sbrian
9328679Sbrian#if LLVM_USE_INTEL_JITEVENTS
9428679Sbrian  // Construct an IntelJITEventListener
956059Samurai  static JITEventListener *createIntelJITEventListener();
9628679Sbrian
976059Samurai  // Construct an IntelJITEventListener with a test Intel JIT API implementation
986059Samurai  static JITEventListener *createIntelJITEventListener(
9926516Sbrian                                      IntelJITEventsWrapper* AlternativeImpl);
10026516Sbrian#else
10126516Sbrian  static JITEventListener *createIntelJITEventListener() { return nullptr; }
1026059Samurai
10326516Sbrian  static JITEventListener *createIntelJITEventListener(
10425566Sbrian                                      IntelJITEventsWrapper* AlternativeImpl) {
10528679Sbrian    return nullptr;
10628679Sbrian  }
1076059Samurai#endif // USE_INTEL_JITEVENTS
10826516Sbrian
1096059Samurai#if LLVM_USE_OPROFILE
1106059Samurai  // Construct an OProfileJITEventListener
11126516Sbrian  static JITEventListener *createOProfileJITEventListener();
1126764Samurai
11326587Sbrian  // Construct an OProfileJITEventListener with a test opagent implementation
1146059Samurai  static JITEventListener *createOProfileJITEventListener(
1156059Samurai                                      OProfileWrapper* AlternativeImpl);
1166059Samurai#else
11726516Sbrian
11826516Sbrian  static JITEventListener *createOProfileJITEventListener() { return nullptr; }
11926516Sbrian
1206059Samurai  static JITEventListener *createOProfileJITEventListener(
1216059Samurai                                      OProfileWrapper* AlternativeImpl) {
1226059Samurai    return nullptr;
12330913Sbrian  }
1246059Samurai#endif // USE_OPROFILE
1256059Samurai
1266059Samurai};
12720120Snate
12820120Snate} // end namespace llvm.
12925908Sbrian
13025908Sbrian#endif // defined LLVM_EXECUTIONENGINE_JITEVENTLISTENER_H
13120120Snate