1//===- JITEventListener.h - Exposes events from JIT compilation -*- C++ -*-===// 2// 3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4// See https://llvm.org/LICENSE.txt for license information. 5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6// 7//===----------------------------------------------------------------------===// 8// 9// This file defines the JITEventListener interface, which lets users get 10// callbacks when significant events happen during the JIT compilation process. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef LLVM_EXECUTIONENGINE_JITEVENTLISTENER_H 15#define LLVM_EXECUTIONENGINE_JITEVENTLISTENER_H 16 17#include "llvm-c/ExecutionEngine.h" 18#include "llvm/Config/llvm-config.h" 19#include "llvm/ExecutionEngine/RuntimeDyld.h" 20#include "llvm/IR/DebugLoc.h" 21#include "llvm/Support/CBindingWrapping.h" 22#include <cstdint> 23#include <vector> 24 25namespace llvm { 26 27class IntelJITEventsWrapper; 28class MachineFunction; 29class OProfileWrapper; 30 31namespace object { 32 33class ObjectFile; 34 35} // end namespace object 36 37/// JITEventListener - Abstract interface for use by the JIT to notify clients 38/// about significant events during compilation. For example, to notify 39/// profilers and debuggers that need to know where functions have been emitted. 40/// 41/// The default implementation of each method does nothing. 42class JITEventListener { 43public: 44 using ObjectKey = uint64_t; 45 46 JITEventListener() = default; 47 virtual ~JITEventListener() = default; 48 49 /// notifyObjectLoaded - Called after an object has had its sections allocated 50 /// and addresses assigned to all symbols. Note: Section memory will not have 51 /// been relocated yet. notifyFunctionLoaded will not be called for 52 /// individual functions in the object. 53 /// 54 /// ELF-specific information 55 /// The ObjectImage contains the generated object image 56 /// with section headers updated to reflect the address at which sections 57 /// were loaded and with relocations performed in-place on debug sections. 58 virtual void notifyObjectLoaded(ObjectKey K, const object::ObjectFile &Obj, 59 const RuntimeDyld::LoadedObjectInfo &L) {} 60 61 /// notifyFreeingObject - Called just before the memory associated with 62 /// a previously emitted object is released. 63 virtual void notifyFreeingObject(ObjectKey K) {} 64 65 // Get a pointe to the GDB debugger registration listener. 66 static JITEventListener *createGDBRegistrationListener(); 67 68#if LLVM_USE_INTEL_JITEVENTS 69 // Construct an IntelJITEventListener 70 static JITEventListener *createIntelJITEventListener(); 71 72 // Construct an IntelJITEventListener with a test Intel JIT API implementation 73 static JITEventListener *createIntelJITEventListener( 74 IntelJITEventsWrapper* AlternativeImpl); 75#else 76 static JITEventListener *createIntelJITEventListener() { return nullptr; } 77 78 static JITEventListener *createIntelJITEventListener( 79 IntelJITEventsWrapper* AlternativeImpl) { 80 return nullptr; 81 } 82#endif // USE_INTEL_JITEVENTS 83 84#if LLVM_USE_OPROFILE 85 // Construct an OProfileJITEventListener 86 static JITEventListener *createOProfileJITEventListener(); 87 88 // Construct an OProfileJITEventListener with a test opagent implementation 89 static JITEventListener *createOProfileJITEventListener( 90 OProfileWrapper* AlternativeImpl); 91#else 92 static JITEventListener *createOProfileJITEventListener() { return nullptr; } 93 94 static JITEventListener *createOProfileJITEventListener( 95 OProfileWrapper* AlternativeImpl) { 96 return nullptr; 97 } 98#endif // USE_OPROFILE 99 100#if LLVM_USE_PERF 101 static JITEventListener *createPerfJITEventListener(); 102#else 103 static JITEventListener *createPerfJITEventListener() 104 { 105 return nullptr; 106 } 107#endif // USE_PERF 108 109private: 110 virtual void anchor(); 111}; 112 113DEFINE_SIMPLE_CONVERSION_FUNCTIONS(JITEventListener, LLVMJITEventListenerRef) 114 115} // end namespace llvm 116 117#endif // LLVM_EXECUTIONENGINE_JITEVENTLISTENER_H 118