1 //===----- PerfSupportPlugin.h ----- Utils for perf support -----*- 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 // Handles support for registering code with perf 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef LLVM_EXECUTIONENGINE_ORC_PERFSUPPORTPLUGIN_H 14 #define LLVM_EXECUTIONENGINE_ORC_PERFSUPPORTPLUGIN_H 15 16 #include "llvm/ExecutionEngine/Orc/Shared/PerfSharedStructs.h" 17 #include "llvm/Support/Compiler.h" 18 19 #include "llvm/ExecutionEngine/Orc/Core.h" 20 #include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h" 21 22 namespace llvm { 23 namespace orc { 24 25 /// Log perf jitdump events for each object (see 26 /// https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/perf/Documentation/jitdump-specification.txt). 27 /// Currently has support for dumping code load records and unwind info records. 28 class LLVM_ABI PerfSupportPlugin : public ObjectLinkingLayer::Plugin { 29 public: 30 PerfSupportPlugin(ExecutorProcessControl &EPC, 31 ExecutorAddr RegisterPerfStartAddr, 32 ExecutorAddr RegisterPerfEndAddr, 33 ExecutorAddr RegisterPerfImplAddr, bool EmitDebugInfo, 34 bool EmitUnwindInfo); 35 ~PerfSupportPlugin(); 36 37 void modifyPassConfig(MaterializationResponsibility &MR, 38 jitlink::LinkGraph &G, 39 jitlink::PassConfiguration &Config) override; 40 notifyFailed(MaterializationResponsibility & MR)41 Error notifyFailed(MaterializationResponsibility &MR) override { 42 return Error::success(); 43 } 44 notifyRemovingResources(JITDylib & JD,ResourceKey K)45 Error notifyRemovingResources(JITDylib &JD, ResourceKey K) override { 46 return Error::success(); 47 } 48 notifyTransferringResources(JITDylib & JD,ResourceKey DstKey,ResourceKey SrcKey)49 void notifyTransferringResources(JITDylib &JD, ResourceKey DstKey, 50 ResourceKey SrcKey) override {} 51 52 static Expected<std::unique_ptr<PerfSupportPlugin>> 53 Create(ExecutorProcessControl &EPC, JITDylib &JD, bool EmitDebugInfo, 54 bool EmitUnwindInfo); 55 56 private: 57 ExecutorProcessControl &EPC; 58 ExecutorAddr RegisterPerfStartAddr; 59 ExecutorAddr RegisterPerfEndAddr; 60 ExecutorAddr RegisterPerfImplAddr; 61 std::atomic<uint64_t> CodeIndex; 62 bool EmitDebugInfo; 63 bool EmitUnwindInfo; 64 }; 65 66 } // namespace orc 67 } // namespace llvm 68 69 #endif // LLVM_EXECUTIONENGINE_ORC_PERFSUPPORTPLUGIN_H 70