1//===--- VTuneSupportPlugin.h -- Support for VTune profiler ---*- 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 VIntel Tune's Amplifier JIT API.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_EXECUTIONENGINE_ORC_DEBUGGING_VTUNESUPPORT_H
14#define LLVM_EXECUTIONENGINE_ORC_DEBUGGING_VTUNESUPPORT_H
15
16#include "llvm/ADT/DenseMap.h"
17#include "llvm/ADT/SmallVector.h"
18#include "llvm/ExecutionEngine/Orc/Core.h"
19#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
20#include "llvm/ExecutionEngine/Orc/Proxy.h"
21#include "llvm/ExecutionEngine/Orc/Shared/SimplePackedSerialization.h"
22#include "llvm/ExecutionEngine/Orc/Shared/VTuneSharedStructs.h"
23#include "llvm/Support/Compiler.h"
24
25namespace llvm {
26
27namespace orc {
28
29class LLVM_ABI VTuneSupportPlugin : public ObjectLinkingLayer::Plugin {
30public:
31 VTuneSupportPlugin(ExecutorProcessControl &EPC, ExecutorAddr RegisterImplAddr,
32 ExecutorAddr UnregisterImplAddr, bool EmitDebugInfo);
33
34 void modifyPassConfig(MaterializationResponsibility &MR,
35 jitlink::LinkGraph &G,
36 jitlink::PassConfiguration &Config) override;
37
38 Error notifyEmitted(MaterializationResponsibility &MR) override;
39 Error notifyFailed(MaterializationResponsibility &MR) override;
40 Error notifyRemovingResources(JITDylib &JD, ResourceKey K) override;
41 void notifyTransferringResources(JITDylib &JD, ResourceKey DstKey,
42 ResourceKey SrcKey) override;
43
44 static Expected<std::unique_ptr<VTuneSupportPlugin>>
45 Create(ExecutorProcessControl &EPC, JITDylib &JD, bool EmitDebugInfo,
46 bool TestMode = false);
47
48private:
49 ExecutorProcessControl &EPC;
50 ExecutorAddr RegisterVTuneImplAddr;
51 Proxy<void(VTuneUnloadedMethodIDs)> UnregisterVTuneImpl;
52 std::mutex PluginMutex;
53 uint64_t NextMethodID = 0;
54 DenseMap<MaterializationResponsibility *, std::pair<uint64_t, uint64_t>>
55 PendingMethodIDs;
56 DenseMap<ResourceKey, SmallVector<std::pair<uint64_t, uint64_t>>>
57 LoadedMethodIDs;
58 bool EmitDebugInfo;
59};
60
61} // end namespace orc
62
63} // end namespace llvm
64
65#endif
66