Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions interpreter/cling/lib/Interpreter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ set(LLVM_LINK_COMPONENTS
object
option
orcjit
orcdebugging
runtimedyld
scalaropts
support
Expand Down
68 changes: 68 additions & 0 deletions interpreter/cling/lib/Interpreter/IncrementalJIT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@
#include <clang/Basic/TargetOptions.h>
#include <clang/Frontend/CompilerInstance.h>

#include <llvm/ExecutionEngine/Orc/Debugging/DebugInfoSupport.h>
#include <llvm/ExecutionEngine/Orc/Debugging/DebuggerSupport.h>
#include <llvm/ExecutionEngine/Orc/Debugging/PerfSupportPlugin.h>
#include <llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h>
#include <llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h>
#include <llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h>
#include <llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderPerf.h>
#include <llvm/ExecutionEngine/SectionMemoryManager.h>
#include <llvm/IR/LLVMContext.h>
#include <llvm/MC/TargetRegistry.h>
Expand All @@ -40,7 +44,57 @@
using namespace llvm::jitlink;
using namespace llvm::orc;

static LLVM_ATTRIBUTE_USED void linkComponents() {
errs() << "Linking in runtime functions\n"
<< (void*)&llvm_orc_registerJITLoaderPerfStart << '\n'
<< (void*)&llvm_orc_registerJITLoaderPerfEnd << '\n'
<< (void*)&llvm_orc_registerJITLoaderPerfImpl << '\n';
}

namespace {
// This could potentially be upstreamed, similar to enableDebuggerSupport()
Error enablePerfSupport(LLJIT& J) {

Check warning on line 56 in interpreter/cling/lib/Interpreter/IncrementalJIT.cpp

View workflow job for this annotation

GitHub Actions / mac14 X64 CMAKE_CXX_STANDARD=20

unused function 'enablePerfSupport' [-Wunused-function]

Check warning on line 56 in interpreter/cling/lib/Interpreter/IncrementalJIT.cpp

View workflow job for this annotation

GitHub Actions / mac26 ARM64

unused function 'enablePerfSupport' [-Wunused-function]

Check warning on line 56 in interpreter/cling/lib/Interpreter/IncrementalJIT.cpp

View workflow job for this annotation

GitHub Actions / mac15 ARM64 CMAKE_CXX_STANDARD=23

unused function 'enablePerfSupport' [-Wunused-function]

Check warning on line 56 in interpreter/cling/lib/Interpreter/IncrementalJIT.cpp

View workflow job for this annotation

GitHub Actions / mac-beta ARM64

unused function 'enablePerfSupport' [-Wunused-function]
auto* ObjLinkingLayer =
dyn_cast<ObjectLinkingLayer>(&J.getObjLinkingLayer());
if (!ObjLinkingLayer)
return make_error<StringError>("Cannot enable LLJIT perf support: "
"perf support requires JITLink",
inconvertibleErrorCode());
auto ProcessSymsJD = J.getProcessSymbolsJITDylib();
if (!ProcessSymsJD)
return make_error<StringError>("Cannot enable LLJIT perf support: "
"Process symbols are not available",
inconvertibleErrorCode());

auto& ES = J.getExecutionSession();
const auto& TT = J.getTargetTriple();

switch (TT.getObjectFormat()) {
case Triple::ELF: {
auto debugInfoPreservationPlugin =
DebugInfoPreservationPlugin::Create();
if (!debugInfoPreservationPlugin)
return debugInfoPreservationPlugin.takeError();

auto perfSupportPlugin =
PerfSupportPlugin::Create(ES.getExecutorProcessControl(),
*ProcessSymsJD, true, true);
if (!perfSupportPlugin)
return perfSupportPlugin.takeError();

ObjLinkingLayer->addPlugin(std::move(*debugInfoPreservationPlugin));
ObjLinkingLayer->addPlugin(std::move(*perfSupportPlugin));

return Error::success();
}
default:
return make_error<StringError>("Cannot enable LLJIT perf support: " +
Triple::getObjectFormatTypeName(
TT.getObjectFormat()) +
" is not supported",
inconvertibleErrorCode());
}
}

class ClingMMapper final : public SectionMemoryManager::MemoryMapper {
public:
Expand Down Expand Up @@ -491,6 +545,20 @@
Builder.setDataLayout(m_TM->createDataLayout());
Builder.setExecutorProcessControl(std::move(EPC));

if (m_JITLink) {
Builder.setPrePlatformSetup([](llvm::orc::LLJIT& J) {
// Try to enable debugging of JIT'd code (only works with JITLink for
// ELF and MachO).
if (cling::utils::ConvertEnvValueToBool(std::getenv("CLING_DEBUG")))
consumeError(enableDebuggerSupport(J));
#ifdef __linux__
if (cling::utils::ConvertEnvValueToBool(std::getenv("CLING_PROFILE")))
consumeError(enablePerfSupport(J));
#endif
return llvm::Error::success();
});
}

// Create ObjectLinkingLayer with our own MemoryManager.
Builder.setObjectLinkingLayerCreator([&](ExecutionSession& ES,
const Triple& TT)
Expand Down
Loading