| 1 | //===-- OrcIncrementalExecutorBuilder.h - ORC Builder -----------*- 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 | // This file declares the builder for ORC incremental execution. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #ifndef LLVM_CLANG_INTERPRETER_ORCINCREMENTALEXECUTORBUILDER_H |
| 14 | #define LLVM_CLANG_INTERPRETER_ORCINCREMENTALEXECUTORBUILDER_H |
| 15 | |
| 16 | #include "clang/Interpreter/IncrementalExecutor.h" |
| 17 | #include "llvm/Support/CodeGen.h" |
| 18 | |
| 19 | #include <cstdint> |
| 20 | #include <functional> |
| 21 | #include <optional> |
| 22 | |
| 23 | namespace llvm::orc { |
| 24 | class LLJITBuilder; |
| 25 | } |
| 26 | |
| 27 | namespace clang { |
| 28 | namespace driver { |
| 29 | class Compilation; |
| 30 | } |
| 31 | |
| 32 | /// Configuration for in-process and out-of-process ORC execution. |
| 33 | class OrcIncrementalExecutorBuilder : public IncrementalExecutorBuilder { |
| 34 | public: |
| 35 | /// Indicates whether out-of-process JIT execution is enabled. |
| 36 | bool IsOutOfProcess = false; |
| 37 | /// Path to the out-of-process JIT executor. |
| 38 | std::string OOPExecutor = "" ; |
| 39 | std::string OOPExecutorConnect = "" ; |
| 40 | /// Indicates whether to use shared memory for communication. |
| 41 | bool UseSharedMemory = false; |
| 42 | /// Representing the slab allocation size for memory management in kb. |
| 43 | unsigned SlabAllocateSize = 0; |
| 44 | /// Path to the ORC runtime library. |
| 45 | std::string OrcRuntimePath = "" ; |
| 46 | /// PID of the out-of-process JIT executor. |
| 47 | uint32_t ExecutorPID = 0; |
| 48 | /// Custom lambda to be executed inside child process/executor |
| 49 | std::function<void()> CustomizeFork = nullptr; |
| 50 | /// An optional code model to provide to the JITTargetMachineBuilder |
| 51 | std::optional<llvm::CodeModel::Model> CM = std::nullopt; |
| 52 | /// An optional external ORC JIT builder. |
| 53 | std::unique_ptr<llvm::orc::LLJITBuilder> JITBuilder; |
| 54 | /// A default callback that can be used in the IncrementalCompilerBuilder to |
| 55 | /// retrieve the path to the orc runtime. |
| 56 | std::function<llvm::Error(const driver::Compilation &)> |
| 57 | UpdateOrcRuntimePathCB = [this](const driver::Compilation &C) { |
| 58 | return UpdateOrcRuntimePath(C); |
| 59 | }; |
| 60 | |
| 61 | OrcIncrementalExecutorBuilder(); |
| 62 | ~OrcIncrementalExecutorBuilder() override; |
| 63 | |
| 64 | llvm::Error configure(IncrementalCompilerBuilder &CB, |
| 65 | const Options &Opts) override; |
| 66 | bool supportsJIT() const override; |
| 67 | llvm::Expected<llvm::Triple> getHostJITTriple() const override; |
| 68 | |
| 69 | private: |
| 70 | llvm::Expected<std::unique_ptr<IncrementalExecutor>> |
| 71 | createExecutor(llvm::orc::ThreadSafeContext &TSC, |
| 72 | const clang::TargetInfo &TI) override; |
| 73 | llvm::Error UpdateOrcRuntimePath(const driver::Compilation &C); |
| 74 | }; |
| 75 | |
| 76 | } // namespace clang |
| 77 | |
| 78 | #endif // LLVM_CLANG_INTERPRETER_ORCINCREMENTALEXECUTORBUILDER_H |
| 79 | |