JITEventListener.h revision 234353
1195098Sed//===- JITEventListener.h - Exposes events from JIT compilation -*- C++ -*-===// 2195098Sed// 3195098Sed// The LLVM Compiler Infrastructure 4195098Sed// 5195098Sed// This file is distributed under the University of Illinois Open Source 6195098Sed// License. See LICENSE.TXT for details. 7195098Sed// 8195098Sed//===----------------------------------------------------------------------===// 9195098Sed// 10195098Sed// This file defines the JITEventListener interface, which lets users get 11195098Sed// callbacks when significant events happen during the JIT compilation process. 12195098Sed// 13195098Sed//===----------------------------------------------------------------------===// 14195098Sed 15195098Sed#ifndef LLVM_EXECUTION_ENGINE_JIT_EVENTLISTENER_H 16195098Sed#define LLVM_EXECUTION_ENGINE_JIT_EVENTLISTENER_H 17195098Sed 18234353Sdim#include "llvm/Config/config.h" 19218893Sdim#include "llvm/Support/DataTypes.h" 20198090Srdivacky#include "llvm/Support/DebugLoc.h" 21195098Sed 22198090Srdivacky#include <vector> 23198090Srdivacky 24195098Sednamespace llvm { 25195098Sedclass Function; 26198090Srdivackyclass MachineFunction; 27234353Sdimclass OProfileWrapper; 28234353Sdimclass IntelJITEventsWrapper; 29195098Sed 30218893Sdim/// JITEvent_EmittedFunctionDetails - Helper struct for containing information 31218893Sdim/// about a generated machine code function. 32195098Sedstruct JITEvent_EmittedFunctionDetails { 33198090Srdivacky struct LineStart { 34218893Sdim /// The address at which the current line changes. 35198090Srdivacky uintptr_t Address; 36218893Sdim 37218893Sdim /// The new location information. These can be translated to DebugLocTuples 38218893Sdim /// using MF->getDebugLocTuple(). 39198090Srdivacky DebugLoc Loc; 40198090Srdivacky }; 41218893Sdim 42218893Sdim /// The machine function the struct contains information for. 43218893Sdim const MachineFunction *MF; 44218893Sdim 45218893Sdim /// The list of line boundary information, sorted by address. 46198090Srdivacky std::vector<LineStart> LineStarts; 47195098Sed}; 48195098Sed 49218893Sdim/// JITEventListener - Abstract interface for use by the JIT to notify clients 50218893Sdim/// about significant events during compilation. For example, to notify 51218893Sdim/// profilers and debuggers that need to know where functions have been emitted. 52195098Sed/// 53218893Sdim/// The default implementation of each method does nothing. 54195098Sedclass JITEventListener { 55195098Sedpublic: 56218893Sdim typedef JITEvent_EmittedFunctionDetails EmittedFunctionDetails; 57218893Sdim 58218893Sdimpublic: 59195098Sed JITEventListener() {} 60218893Sdim virtual ~JITEventListener(); 61195098Sed 62195098Sed /// NotifyFunctionEmitted - Called after a function has been successfully 63195098Sed /// emitted to memory. The function still has its MachineFunction attached, 64195098Sed /// if you should happen to need that. 65234353Sdim virtual void NotifyFunctionEmitted(const Function &, 66234353Sdim void *, size_t, 67234353Sdim const EmittedFunctionDetails &) {} 68195098Sed 69218893Sdim /// NotifyFreeingMachineCode - Called from freeMachineCodeForFunction(), after 70218893Sdim /// the global mapping is removed, but before the machine code is returned to 71218893Sdim /// the allocator. 72218893Sdim /// 73218893Sdim /// OldPtr is the address of the machine code and will be the same as the Code 74218893Sdim /// parameter to a previous NotifyFunctionEmitted call. The Function passed 75218893Sdim /// to NotifyFunctionEmitted may have been destroyed by the time of the 76218893Sdim /// matching NotifyFreeingMachineCode call. 77234353Sdim virtual void NotifyFreeingMachineCode(void *) {} 78234353Sdim 79234353Sdim#if LLVM_USE_INTEL_JITEVENTS 80234353Sdim // Construct an IntelJITEventListener 81234353Sdim static JITEventListener *createIntelJITEventListener(); 82234353Sdim 83234353Sdim // Construct an IntelJITEventListener with a test Intel JIT API implementation 84234353Sdim static JITEventListener *createIntelJITEventListener( 85234353Sdim IntelJITEventsWrapper* AlternativeImpl); 86234353Sdim#else 87234353Sdim static JITEventListener *createIntelJITEventListener() { return 0; } 88234353Sdim 89234353Sdim static JITEventListener *createIntelJITEventListener( 90234353Sdim IntelJITEventsWrapper* AlternativeImpl) { 91234353Sdim return 0; 92234353Sdim } 93234353Sdim#endif // USE_INTEL_JITEVENTS 94234353Sdim 95234353Sdim#if LLVM_USE_OPROFILE 96234353Sdim // Construct an OProfileJITEventListener 97234353Sdim static JITEventListener *createOProfileJITEventListener(); 98234353Sdim 99234353Sdim // Construct an OProfileJITEventListener with a test opagent implementation 100234353Sdim static JITEventListener *createOProfileJITEventListener( 101234353Sdim OProfileWrapper* AlternativeImpl); 102234353Sdim#else 103234353Sdim 104234353Sdim static JITEventListener *createOProfileJITEventListener() { return 0; } 105234353Sdim 106234353Sdim static JITEventListener *createOProfileJITEventListener( 107234353Sdim OProfileWrapper* AlternativeImpl) { 108234353Sdim return 0; 109234353Sdim } 110234353Sdim#endif // USE_OPROFILE 111234353Sdim 112195098Sed}; 113195098Sed 114195098Sed} // end namespace llvm. 115195098Sed 116234353Sdim#endif // defined LLVM_EXECUTION_ENGINE_JIT_EVENTLISTENER_H 117