1 //===- JITEventListener.h - Exposes events from JIT compilation -*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This file defines the JITEventListener interface, which lets users get
10 // callbacks when significant events happen during the JIT compilation process.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_EXECUTIONENGINE_JITEVENTLISTENER_H
15 #define LLVM_EXECUTIONENGINE_JITEVENTLISTENER_H
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"
27 class IntelJITEventsWrapper
;
28 class MachineFunction
;
29 class OProfileWrapper
;
35 } // end namespace object
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.
41 /// The default implementation of each method does nothing.
42 class JITEventListener
{
44 using ObjectKey
= uint64_t;
46 JITEventListener() = default;
47 virtual ~JITEventListener() = default;
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.
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
) {}
61 /// notifyFreeingObject - Called just before the memory associated with
62 /// a previously emitted object is released.
63 virtual void notifyFreeingObject(ObjectKey K
) {}
65 // Get a pointe to the GDB debugger registration listener.
66 static JITEventListener
*createGDBRegistrationListener();
68 #if LLVM_USE_INTEL_JITEVENTS
69 // Construct an IntelJITEventListener
70 static JITEventListener
*createIntelJITEventListener();
72 // Construct an IntelJITEventListener with a test Intel JIT API implementation
73 static JITEventListener
*createIntelJITEventListener(
74 IntelJITEventsWrapper
* AlternativeImpl
);
76 static JITEventListener
*createIntelJITEventListener() { return nullptr; }
78 static JITEventListener
*createIntelJITEventListener(
79 IntelJITEventsWrapper
* AlternativeImpl
) {
82 #endif // USE_INTEL_JITEVENTS
85 // Construct an OProfileJITEventListener
86 static JITEventListener
*createOProfileJITEventListener();
88 // Construct an OProfileJITEventListener with a test opagent implementation
89 static JITEventListener
*createOProfileJITEventListener(
90 OProfileWrapper
* AlternativeImpl
);
92 static JITEventListener
*createOProfileJITEventListener() { return nullptr; }
94 static JITEventListener
*createOProfileJITEventListener(
95 OProfileWrapper
* AlternativeImpl
) {
98 #endif // USE_OPROFILE
101 static JITEventListener
*createPerfJITEventListener();
103 static JITEventListener
*createPerfJITEventListener()
110 virtual void anchor();
113 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(JITEventListener
, LLVMJITEventListenerRef
)
115 } // end namespace llvm
117 #endif // LLVM_EXECUTIONENGINE_JITEVENTLISTENER_H