Files
TheRock/compiler/amd-llvm/clang/lib/Interpreter/OrcIncrementalExecutor.cpp
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

123 lines
4.1 KiB
C++

//===--- OrcIncrementalExecutor.cpp - Orc Incremental Execution -*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file implements an Orc-based incremental code execution.
//
//===----------------------------------------------------------------------===//
#include "OrcIncrementalExecutor.h"
#include "clang/Interpreter/PartialTranslationUnit.h"
#include "llvm/ExecutionEngine/Orc/EPCDynamicLibrarySearchGenerator.h"
#include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"
#include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h"
#include "llvm/ExecutionEngine/Orc/LLJIT.h"
#include "llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h"
#include "llvm/ExecutionEngine/Orc/Shared/SimpleRemoteEPCUtils.h"
#include "llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/raw_ostream.h"
#ifdef LLVM_ON_UNIX
#include <netdb.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <unistd.h>
#endif // LLVM_ON_UNIX
// Force linking some of the runtimes that helps attaching to a debugger.
LLVM_ATTRIBUTE_USED void linkComponents() {
llvm::errs() << (void *)&llvm_orc_registerJITLoaderGDBAllocAction;
}
namespace clang {
OrcIncrementalExecutor::OrcIncrementalExecutor(
llvm::orc::ThreadSafeContext &TSC)
: TSCtx(TSC) {}
OrcIncrementalExecutor::OrcIncrementalExecutor(
llvm::orc::ThreadSafeContext &TSC, llvm::orc::LLJITBuilder &JITBuilder,
llvm::Error &Err)
: TSCtx(TSC) {
using namespace llvm::orc;
llvm::ErrorAsOutParameter EAO(&Err);
if (auto JitOrErr = JITBuilder.create())
Jit = std::move(*JitOrErr);
else {
Err = JitOrErr.takeError();
return;
}
}
OrcIncrementalExecutor::~OrcIncrementalExecutor() {}
llvm::Error OrcIncrementalExecutor::addModule(PartialTranslationUnit &PTU) {
llvm::orc::ResourceTrackerSP RT =
Jit->getMainJITDylib().createResourceTracker();
ResourceTrackers[&PTU] = RT;
return Jit->addIRModule(RT, {std::move(PTU.TheModule), TSCtx});
}
llvm::Error OrcIncrementalExecutor::removeModule(PartialTranslationUnit &PTU) {
llvm::orc::ResourceTrackerSP RT = std::move(ResourceTrackers[&PTU]);
if (!RT)
return llvm::Error::success();
ResourceTrackers.erase(&PTU);
if (llvm::Error Err = RT->remove())
return Err;
return llvm::Error::success();
}
// Clean up the JIT instance.
llvm::Error OrcIncrementalExecutor::cleanUp() {
// This calls the global dtors of registered modules.
return Jit->deinitialize(Jit->getMainJITDylib());
}
llvm::Error OrcIncrementalExecutor::runCtors() const {
return Jit->initialize(Jit->getMainJITDylib());
}
llvm::Expected<llvm::orc::ExecutorAddr>
OrcIncrementalExecutor::getSymbolAddress(llvm::StringRef Name,
SymbolNameKind NameKind) const {
using namespace llvm::orc;
auto SO = makeJITDylibSearchOrder({&Jit->getMainJITDylib(),
Jit->getPlatformJITDylib().get(),
Jit->getProcessSymbolsJITDylib().get()});
ExecutionSession &ES = Jit->getExecutionSession();
auto SymOrErr = ES.lookup(SO, (NameKind == SymbolNameKind::LinkerName)
? ES.intern(Name)
: Jit->mangleAndIntern(Name));
if (auto Err = SymOrErr.takeError())
return std::move(Err);
return SymOrErr->getAddress();
}
llvm::Error OrcIncrementalExecutor::LoadDynamicLibrary(const char *name) {
// FIXME: Eventually we should put each library in its own JITDylib and
// turn off process symbols by default.
llvm::orc::ExecutionSession &ES = Jit->getExecutionSession();
auto DLSGOrErr = llvm::orc::EPCDynamicLibrarySearchGenerator::Load(
ES, Jit->getDylibMgr(), name);
if (!DLSGOrErr)
return DLSGOrErr.takeError();
Jit->getProcessSymbolsJITDylib()->addGenerator(std::move(*DLSGOrErr));
return llvm::Error::success();
}
} // namespace clang