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