clang  14.0.0git
IncrementalExecutor.cpp
Go to the documentation of this file.
1 //===--- IncrementalExecutor.cpp - Incremental Execution --------*- 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 implements the class which performs incremental code execution.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "IncrementalExecutor.h"
14 
15 #include "llvm/ExecutionEngine/ExecutionEngine.h"
16 #include "llvm/ExecutionEngine/Orc/CompileUtils.h"
17 #include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"
18 #include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
19 #include "llvm/ExecutionEngine/Orc/LLJIT.h"
20 #include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
21 #include "llvm/ExecutionEngine/SectionMemoryManager.h"
22 #include "llvm/IR/Module.h"
23 #include "llvm/Support/ManagedStatic.h"
24 #include "llvm/Support/TargetSelect.h"
25 
26 namespace clang {
27 
28 IncrementalExecutor::IncrementalExecutor(llvm::orc::ThreadSafeContext &TSC,
29  llvm::Error &Err,
30  const llvm::Triple &Triple)
31  : TSCtx(TSC) {
32  using namespace llvm::orc;
33  llvm::ErrorAsOutParameter EAO(&Err);
34 
35  auto JTMB = JITTargetMachineBuilder(Triple);
36  if (auto JitOrErr = LLJITBuilder().setJITTargetMachineBuilder(JTMB).create())
37  Jit = std::move(*JitOrErr);
38  else {
39  Err = JitOrErr.takeError();
40  return;
41  }
42 
43  const char Pref = Jit->getDataLayout().getGlobalPrefix();
44  // Discover symbols from the process as a fallback.
45  if (auto PSGOrErr = DynamicLibrarySearchGenerator::GetForCurrentProcess(Pref))
46  Jit->getMainJITDylib().addGenerator(std::move(*PSGOrErr));
47  else {
48  Err = PSGOrErr.takeError();
49  return;
50  }
51 }
52 
54 
55 llvm::Error IncrementalExecutor::addModule(std::unique_ptr<llvm::Module> M) {
56  return Jit->addIRModule(llvm::orc::ThreadSafeModule(std::move(M), TSCtx));
57 }
58 
59 llvm::Error IncrementalExecutor::runCtors() const {
60  return Jit->initialize(Jit->getMainJITDylib());
61 }
62 
63 } // end namespace clang
llvm::orc
Definition: Interpreter.h:25
clang::IncrementalExecutor::~IncrementalExecutor
~IncrementalExecutor()
Definition: IncrementalExecutor.cpp:53
clang::serialized_diags::create
std::unique_ptr< DiagnosticConsumer > create(StringRef OutputFile, DiagnosticOptions *Diags, bool MergeChildRecords=false)
Returns a DiagnosticConsumer that serializes diagnostics to a bitcode file.
Definition: SerializedDiagnosticPrinter.cpp:302
clang::IncrementalExecutor::addModule
llvm::Error addModule(std::unique_ptr< llvm::Module > M)
Definition: IncrementalExecutor.cpp:55
IncrementalExecutor.h
clang::IncrementalExecutor::runCtors
llvm::Error runCtors() const
Definition: IncrementalExecutor.cpp:59
clang::IncrementalExecutor::IncrementalExecutor
IncrementalExecutor(llvm::orc::ThreadSafeContext &TSC, llvm::Error &Err, const llvm::Triple &Triple)
Definition: IncrementalExecutor.cpp:28
clang
Definition: CalledOnceCheck.h:17