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
23namespace llvm::orc {
24class LLJITBuilder;
25}
26
27namespace clang {
28namespace driver {
29class Compilation;
30}
31
32/// Configuration for in-process and out-of-process ORC execution.
33class OrcIncrementalExecutorBuilder : public IncrementalExecutorBuilder {
34public:
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
69private:
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