Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:54

0001 //===- JITEventListener.h - Exposes events from JIT compilation -*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file defines the JITEventListener interface, which lets users get
0010 // callbacks when significant events happen during the JIT compilation process.
0011 //
0012 //===----------------------------------------------------------------------===//
0013 
0014 #ifndef LLVM_EXECUTIONENGINE_JITEVENTLISTENER_H
0015 #define LLVM_EXECUTIONENGINE_JITEVENTLISTENER_H
0016 
0017 #include "llvm-c/ExecutionEngine.h"
0018 #include "llvm/Config/llvm-config.h"
0019 #include "llvm/ExecutionEngine/RuntimeDyld.h"
0020 #include "llvm/IR/DebugLoc.h"
0021 #include "llvm/Support/CBindingWrapping.h"
0022 #include <cstdint>
0023 
0024 namespace llvm {
0025 
0026 class IntelJITEventsWrapper;
0027 class OProfileWrapper;
0028 
0029 namespace object {
0030 
0031 class ObjectFile;
0032 
0033 } // end namespace object
0034 
0035 /// JITEventListener - Abstract interface for use by the JIT to notify clients
0036 /// about significant events during compilation. For example, to notify
0037 /// profilers and debuggers that need to know where functions have been emitted.
0038 ///
0039 /// The default implementation of each method does nothing.
0040 class JITEventListener {
0041 public:
0042   using ObjectKey = uint64_t;
0043 
0044   JITEventListener() = default;
0045   virtual ~JITEventListener() = default;
0046 
0047   /// notifyObjectLoaded - Called after an object has had its sections allocated
0048   /// and addresses assigned to all symbols. Note: Section memory will not have
0049   /// been relocated yet. notifyFunctionLoaded will not be called for
0050   /// individual functions in the object.
0051   ///
0052   /// ELF-specific information
0053   /// The ObjectImage contains the generated object image
0054   /// with section headers updated to reflect the address at which sections
0055   /// were loaded and with relocations performed in-place on debug sections.
0056   virtual void notifyObjectLoaded(ObjectKey K, const object::ObjectFile &Obj,
0057                                   const RuntimeDyld::LoadedObjectInfo &L) {}
0058 
0059   /// notifyFreeingObject - Called just before the memory associated with
0060   /// a previously emitted object is released.
0061   virtual void notifyFreeingObject(ObjectKey K) {}
0062 
0063   // Get a pointer to the GDB debugger registration listener.
0064   static JITEventListener *createGDBRegistrationListener();
0065 
0066 #if LLVM_USE_INTEL_JITEVENTS
0067   // Construct an IntelJITEventListener
0068   static JITEventListener *createIntelJITEventListener();
0069 
0070   // Construct an IntelJITEventListener with a test Intel JIT API implementation
0071   static JITEventListener *createIntelJITEventListener(
0072                                       IntelJITEventsWrapper* AlternativeImpl);
0073 #else
0074   static JITEventListener *createIntelJITEventListener() { return nullptr; }
0075 
0076   static JITEventListener *createIntelJITEventListener(
0077                                       IntelJITEventsWrapper* AlternativeImpl) {
0078     return nullptr;
0079   }
0080 #endif // USE_INTEL_JITEVENTS
0081 
0082 #if LLVM_USE_OPROFILE
0083   // Construct an OProfileJITEventListener
0084   static JITEventListener *createOProfileJITEventListener();
0085 
0086   // Construct an OProfileJITEventListener with a test opagent implementation
0087   static JITEventListener *createOProfileJITEventListener(
0088                                       OProfileWrapper* AlternativeImpl);
0089 #else
0090   static JITEventListener *createOProfileJITEventListener() { return nullptr; }
0091 
0092   static JITEventListener *createOProfileJITEventListener(
0093                                       OProfileWrapper* AlternativeImpl) {
0094     return nullptr;
0095   }
0096 #endif // USE_OPROFILE
0097 
0098 #if LLVM_USE_PERF
0099   static JITEventListener *createPerfJITEventListener();
0100 #else
0101   static JITEventListener *createPerfJITEventListener()
0102   {
0103     return nullptr;
0104   }
0105 #endif // USE_PERF
0106 
0107 private:
0108   virtual void anchor();
0109 };
0110 
0111 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(JITEventListener, LLVMJITEventListenerRef)
0112 
0113 } // end namespace llvm
0114 
0115 #endif // LLVM_EXECUTIONENGINE_JITEVENTLISTENER_H