[llvm] [ORC] Call Perf/VTune support wrappers through Proxies (PR #226677)
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 27 03:57:56 PDT 2026
https://github.com/lhames updated https://github.com/llvm/llvm-project/pull/226677
>From 51793cfbe0a4e102bec41730a6cc554dc4c99d1c Mon Sep 17 00:00:00 2001
From: Lang Hames <lhames at gmail.com>
Date: Sat, 26 Sep 2026 20:51:03 +1000
Subject: [PATCH 1/2] [ORC] Call Perf/VTune support wrappers through Proxies
Hold PerfSupportPlugin's start/end registration wrappers and
VTuneSupportPlugin's unregister wrapper as Proxy members, replacing
their callSPSWrapper calls. Each proxy is built in the constructor from
the address it already takes, so the constructor signatures are
unchanged. The Perf impl and VTune register wrappers are only used as
alloc-action tags and stay ExecutorAddrs.
---
.../Orc/Debugging/PerfSupportPlugin.h | 5 ++-
.../Orc/Debugging/VTuneSupportPlugin.h | 8 ++--
.../Orc/Debugging/PerfSupportPlugin.cpp | 37 ++++++++++++++-----
.../Orc/Debugging/VTuneSupportPlugin.cpp | 27 ++++++++++++--
4 files changed, 57 insertions(+), 20 deletions(-)
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/Debugging/PerfSupportPlugin.h b/llvm/include/llvm/ExecutionEngine/Orc/Debugging/PerfSupportPlugin.h
index f9b1d2c273bb6..ca5bc2725a527 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/Debugging/PerfSupportPlugin.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/Debugging/PerfSupportPlugin.h
@@ -18,6 +18,7 @@
#include "llvm/ExecutionEngine/Orc/Core.h"
#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
+#include "llvm/ExecutionEngine/Orc/Proxy.h"
namespace llvm {
namespace orc {
@@ -55,8 +56,8 @@ class LLVM_ABI PerfSupportPlugin : public ObjectLinkingLayer::Plugin {
private:
ExecutorProcessControl &EPC;
- ExecutorAddr RegisterPerfStartAddr;
- ExecutorAddr RegisterPerfEndAddr;
+ Proxy<void()> RegisterPerfStart;
+ Proxy<void()> RegisterPerfEnd;
ExecutorAddr RegisterPerfImplAddr;
std::atomic<uint64_t> CodeIndex;
bool EmitDebugInfo;
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/Debugging/VTuneSupportPlugin.h b/llvm/include/llvm/ExecutionEngine/Orc/Debugging/VTuneSupportPlugin.h
index 5bdb6a1faed89..dddfeaf28b981 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/Debugging/VTuneSupportPlugin.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/Debugging/VTuneSupportPlugin.h
@@ -17,6 +17,7 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/ExecutionEngine/Orc/Core.h"
#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
+#include "llvm/ExecutionEngine/Orc/Proxy.h"
#include "llvm/ExecutionEngine/Orc/Shared/SimplePackedSerialization.h"
#include "llvm/ExecutionEngine/Orc/Shared/VTuneSharedStructs.h"
#include "llvm/Support/Compiler.h"
@@ -28,10 +29,7 @@ namespace orc {
class LLVM_ABI VTuneSupportPlugin : public ObjectLinkingLayer::Plugin {
public:
VTuneSupportPlugin(ExecutorProcessControl &EPC, ExecutorAddr RegisterImplAddr,
- ExecutorAddr UnregisterImplAddr, bool EmitDebugInfo)
- : EPC(EPC), RegisterVTuneImplAddr(RegisterImplAddr),
- UnregisterVTuneImplAddr(UnregisterImplAddr),
- EmitDebugInfo(EmitDebugInfo) {}
+ ExecutorAddr UnregisterImplAddr, bool EmitDebugInfo);
void modifyPassConfig(MaterializationResponsibility &MR,
jitlink::LinkGraph &G,
@@ -50,7 +48,7 @@ class LLVM_ABI VTuneSupportPlugin : public ObjectLinkingLayer::Plugin {
private:
ExecutorProcessControl &EPC;
ExecutorAddr RegisterVTuneImplAddr;
- ExecutorAddr UnregisterVTuneImplAddr;
+ Proxy<void(VTuneUnloadedMethodIDs)> UnregisterVTuneImpl;
std::mutex PluginMutex;
uint64_t NextMethodID = 0;
DenseMap<MaterializationResponsibility *, std::pair<uint64_t, uint64_t>>
diff --git a/llvm/lib/ExecutionEngine/Orc/Debugging/PerfSupportPlugin.cpp b/llvm/lib/ExecutionEngine/Orc/Debugging/PerfSupportPlugin.cpp
index 4e07800a416bd..1c282e4a4341d 100644
--- a/llvm/lib/ExecutionEngine/Orc/Debugging/PerfSupportPlugin.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/Debugging/PerfSupportPlugin.cpp
@@ -14,6 +14,7 @@
#include "llvm/ExecutionEngine/Orc/Debugging/DebugInfoSupport.h"
#include "llvm/ExecutionEngine/Orc/LookupAndApply.h"
+#include "llvm/ExecutionEngine/Orc/SPSProxySpec.h"
#include "llvm/ExecutionEngine/Orc/Shared/WrapperFunctionUtils.h"
#define DEBUG_TYPE "orc"
@@ -22,6 +23,21 @@ using namespace llvm;
using namespace llvm::orc;
using namespace llvm::jitlink;
+// Controller-interface descriptors for the executor's perf-support wrapper
+// calls.
+namespace llvm::orc::perf_sps_ci {
+struct RegisterPerfStart {
+ static constexpr SymbolNameSpec Name =
+ SymbolNameSpec::c("llvm_orc_registerJITLoaderPerfStart");
+ using SPSSig = void();
+};
+struct RegisterPerfEnd {
+ static constexpr SymbolNameSpec Name =
+ SymbolNameSpec::c("llvm_orc_registerJITLoaderPerfEnd");
+ using SPSSig = void();
+};
+} // namespace llvm::orc::perf_sps_ci
+
namespace {
// Creates an EH frame header prepared for a 32-bit relative relocation
@@ -76,10 +92,6 @@ Expected<std::string> createX64EHFrameHeader(Section &EHFrame,
return HeaderContent;
}
-constexpr SymbolNameSpec RegisterPerfStartSymbolName =
- SymbolNameSpec::c("llvm_orc_registerJITLoaderPerfStart");
-constexpr SymbolNameSpec RegisterPerfEndSymbolName =
- SymbolNameSpec::c("llvm_orc_registerJITLoaderPerfEnd");
constexpr SymbolNameSpec RegisterPerfImplSymbolName =
SymbolNameSpec::c("llvm_orc_registerJITLoaderPerfImpl");
@@ -256,14 +268,19 @@ PerfSupportPlugin::PerfSupportPlugin(ExecutorProcessControl &EPC,
ExecutorAddr RegisterPerfEndAddr,
ExecutorAddr RegisterPerfImplAddr,
bool EmitDebugInfo, bool EmitUnwindInfo)
- : EPC(EPC), RegisterPerfStartAddr(RegisterPerfStartAddr),
- RegisterPerfEndAddr(RegisterPerfEndAddr),
+ : EPC(EPC), RegisterPerfStart(
+ sps::ProxySpec<Proxy<void()>,
+ perf_sps_ci::RegisterPerfStart>::dispatch,
+ RegisterPerfStartAddr),
+ RegisterPerfEnd(
+ sps::ProxySpec<Proxy<void()>, perf_sps_ci::RegisterPerfEnd>::dispatch,
+ RegisterPerfEndAddr),
RegisterPerfImplAddr(RegisterPerfImplAddr), CodeIndex(0),
EmitDebugInfo(EmitDebugInfo), EmitUnwindInfo(EmitUnwindInfo) {
- cantFail(EPC.callSPSWrapper<void()>(RegisterPerfStartAddr));
+ cantFail(RegisterPerfStart(EPC.getExecutionSession()));
}
PerfSupportPlugin::~PerfSupportPlugin() {
- cantFail(EPC.callSPSWrapper<void()>(RegisterPerfEndAddr));
+ cantFail(RegisterPerfEnd(EPC.getExecutionSession()));
}
void PerfSupportPlugin::modifyPassConfig(MaterializationResponsibility &MR,
@@ -291,8 +308,8 @@ PerfSupportPlugin::Create(ExecutorProcessControl &EPC, JITDylib &JD,
}
ExecutorAddr StartAddr, EndAddr, ImplAddr;
if (auto Err = lookupAndApply(
- JD, {recordAddr(RegisterPerfStartSymbolName, &StartAddr),
- recordAddr(RegisterPerfEndSymbolName, &EndAddr),
+ JD, {recordAddr(perf_sps_ci::RegisterPerfStart::Name, &StartAddr),
+ recordAddr(perf_sps_ci::RegisterPerfEnd::Name, &EndAddr),
recordAddr(RegisterPerfImplSymbolName, &ImplAddr)}))
return std::move(Err);
return std::make_unique<PerfSupportPlugin>(EPC, StartAddr, EndAddr, ImplAddr,
diff --git a/llvm/lib/ExecutionEngine/Orc/Debugging/VTuneSupportPlugin.cpp b/llvm/lib/ExecutionEngine/Orc/Debugging/VTuneSupportPlugin.cpp
index 8793d6f8ab90b..bfbab618a1bec 100644
--- a/llvm/lib/ExecutionEngine/Orc/Debugging/VTuneSupportPlugin.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/Debugging/VTuneSupportPlugin.cpp
@@ -12,6 +12,7 @@
#include "llvm/ExecutionEngine/Orc/Debugging/VTuneSupportPlugin.h"
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
#include "llvm/ExecutionEngine/Orc/Debugging/DebugInfoSupport.h"
+#include "llvm/ExecutionEngine/Orc/SPSProxySpec.h"
using namespace llvm;
using namespace llvm::orc;
@@ -23,6 +24,27 @@ static constexpr StringRef UnregisterVTuneImplName =
static constexpr StringRef RegisterTestVTuneImplName =
"llvm_orc_test_registerVTuneImpl";
+// Controller-interface descriptors for the executor's VTune-support wrapper
+// calls.
+namespace llvm::orc::vtune_sps_ci {
+struct UnregisterVTuneImpl {
+ static constexpr SymbolNameSpec Name =
+ SymbolNameSpec::c(UnregisterVTuneImplName);
+ using SPSSig = void(shared::SPSVTuneUnloadedMethodIDs);
+};
+} // namespace llvm::orc::vtune_sps_ci
+
+VTuneSupportPlugin::VTuneSupportPlugin(ExecutorProcessControl &EPC,
+ ExecutorAddr RegisterImplAddr,
+ ExecutorAddr UnregisterImplAddr,
+ bool EmitDebugInfo)
+ : EPC(EPC), RegisterVTuneImplAddr(RegisterImplAddr),
+ UnregisterVTuneImpl(
+ sps::ProxySpec<Proxy<void(VTuneUnloadedMethodIDs)>,
+ vtune_sps_ci::UnregisterVTuneImpl>::dispatch,
+ UnregisterImplAddr),
+ EmitDebugInfo(EmitDebugInfo) {}
+
static VTuneMethodBatch getMethodBatch(LinkGraph &G, bool EmitDebugInfo) {
VTuneMethodBatch Batch;
std::unique_ptr<DWARFContext> DC;
@@ -133,7 +155,7 @@ Error VTuneSupportPlugin::notifyFailed(MaterializationResponsibility &MR) {
Error VTuneSupportPlugin::notifyRemovingResources(JITDylib &JD, ResourceKey K) {
// Unregistration not required if not provided
- if (!UnregisterVTuneImplAddr) {
+ if (!UnregisterVTuneImpl) {
return Error::success();
}
VTuneUnloadedMethodIDs UnloadedIDs;
@@ -146,8 +168,7 @@ Error VTuneSupportPlugin::notifyRemovingResources(JITDylib &JD, ResourceKey K) {
UnloadedIDs = std::move(I->second);
LoadedMethodIDs.erase(I);
}
- if (auto Err = EPC.callSPSWrapper<void(shared::SPSVTuneUnloadedMethodIDs)>(
- UnregisterVTuneImplAddr, UnloadedIDs))
+ if (auto Err = UnregisterVTuneImpl(EPC.getExecutionSession(), UnloadedIDs))
return Err;
return Error::success();
>From f6723e484cbe1c8679636dbc1bc8a2ae1d70bf48 Mon Sep 17 00:00:00 2001
From: Lang Hames <lhames at gmail.com>
Date: Sun, 27 Sep 2026 20:56:03 +1000
Subject: [PATCH 2/2] Work around PerfSupporcPlugin's shutdown sequence issue.
---
.../Orc/Debugging/PerfSupportPlugin.cpp | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/ExecutionEngine/Orc/Debugging/PerfSupportPlugin.cpp b/llvm/lib/ExecutionEngine/Orc/Debugging/PerfSupportPlugin.cpp
index 1c282e4a4341d..4311deb7a04fb 100644
--- a/llvm/lib/ExecutionEngine/Orc/Debugging/PerfSupportPlugin.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/Debugging/PerfSupportPlugin.cpp
@@ -280,7 +280,16 @@ PerfSupportPlugin::PerfSupportPlugin(ExecutorProcessControl &EPC,
cantFail(RegisterPerfStart(EPC.getExecutionSession()));
}
PerfSupportPlugin::~PerfSupportPlugin() {
- cantFail(RegisterPerfEnd(EPC.getExecutionSession()));
+ // FIXME: End message from destructor is unreliable. Executor-side perf
+ // support (currently JITLoaderPerf.cpp in OrcTargetProcess) should be
+ // reimplemented as a service in the new ORC runtime, where cleanup
+ // can be run as an on-shutdown event.
+ //
+ // For now, switch to async dispatch here so that a message failure doesn't
+ // load to a crash when we try to read from a std::future whose std::promise
+ // has been destoryed.
+ RegisterPerfEnd([](Error Err) { consumeError(std::move(Err)); },
+ EPC.getExecutionSession());
}
void PerfSupportPlugin::modifyPassConfig(MaterializationResponsibility &MR,
More information about the llvm-commits
mailing list