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 15249423Sdim#ifndef LLVM_EXECUTIONENGINE_JITEVENTLISTENER_H 16249423Sdim#define LLVM_EXECUTIONENGINE_JITEVENTLISTENER_H 17195098Sed 18249423Sdim#include "llvm/Config/llvm-config.h" 19218893Sdim#include "llvm/Support/DataTypes.h" 20198090Srdivacky#include "llvm/Support/DebugLoc.h" 21198090Srdivacky#include <vector> 22198090Srdivacky 23195098Sednamespace llvm { 24195098Sedclass Function; 25198090Srdivackyclass MachineFunction; 26234353Sdimclass OProfileWrapper; 27234353Sdimclass IntelJITEventsWrapper; 28243830Sdimclass ObjectImage; 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 79243830Sdim /// NotifyObjectEmitted - Called after an object has been successfully 80243830Sdim /// emitted to memory. NotifyFunctionEmitted will not be called for 81243830Sdim /// individual functions in the object. 82243830Sdim /// 83243830Sdim /// ELF-specific information 84243830Sdim /// The ObjectImage contains the generated object image 85243830Sdim /// with section headers updated to reflect the address at which sections 86243830Sdim /// were loaded and with relocations performed in-place on debug sections. 87243830Sdim virtual void NotifyObjectEmitted(const ObjectImage &Obj) {} 88243830Sdim 89243830Sdim /// NotifyFreeingObject - Called just before the memory associated with 90243830Sdim /// a previously emitted object is released. 91243830Sdim virtual void NotifyFreeingObject(const ObjectImage &Obj) {} 92243830Sdim 93234353Sdim#if LLVM_USE_INTEL_JITEVENTS 94234353Sdim // Construct an IntelJITEventListener 95234353Sdim static JITEventListener *createIntelJITEventListener(); 96234353Sdim 97234353Sdim // Construct an IntelJITEventListener with a test Intel JIT API implementation 98234353Sdim static JITEventListener *createIntelJITEventListener( 99234353Sdim IntelJITEventsWrapper* AlternativeImpl); 100234353Sdim#else 101234353Sdim static JITEventListener *createIntelJITEventListener() { return 0; } 102234353Sdim 103234353Sdim static JITEventListener *createIntelJITEventListener( 104234353Sdim IntelJITEventsWrapper* AlternativeImpl) { 105234353Sdim return 0; 106234353Sdim } 107234353Sdim#endif // USE_INTEL_JITEVENTS 108234353Sdim 109234353Sdim#if LLVM_USE_OPROFILE 110234353Sdim // Construct an OProfileJITEventListener 111234353Sdim static JITEventListener *createOProfileJITEventListener(); 112234353Sdim 113234353Sdim // Construct an OProfileJITEventListener with a test opagent implementation 114234353Sdim static JITEventListener *createOProfileJITEventListener( 115234353Sdim OProfileWrapper* AlternativeImpl); 116234353Sdim#else 117234353Sdim 118234353Sdim static JITEventListener *createOProfileJITEventListener() { return 0; } 119234353Sdim 120234353Sdim static JITEventListener *createOProfileJITEventListener( 121234353Sdim OProfileWrapper* AlternativeImpl) { 122234353Sdim return 0; 123234353Sdim } 124234353Sdim#endif // USE_OPROFILE 125234353Sdim 126195098Sed}; 127195098Sed 128195098Sed} // end namespace llvm. 129195098Sed 130249423Sdim#endif // defined LLVM_EXECUTIONENGINE_JITEVENTLISTENER_H 131