Coverage Report

Created: 2022-01-18 06:27

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Interpreter/IncrementalExecutor.cpp
Line
Count
Source (jump to first uncovered line)
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
5
    : TSCtx(TSC) {
32
5
  using namespace llvm::orc;
33
5
  llvm::ErrorAsOutParameter EAO(&Err);
34
35
5
  auto JTMB = JITTargetMachineBuilder(Triple);
36
5
  if (auto JitOrErr = LLJITBuilder().setJITTargetMachineBuilder(JTMB).create())
37
5
    Jit = std::move(*JitOrErr);
38
0
  else {
39
0
    Err = JitOrErr.takeError();
40
0
    return;
41
0
  }
42
43
5
  const char Pref = Jit->getDataLayout().getGlobalPrefix();
44
  // Discover symbols from the process as a fallback.
45
5
  if (auto PSGOrErr = DynamicLibrarySearchGenerator::GetForCurrentProcess(Pref))
46
5
    Jit->getMainJITDylib().addGenerator(std::move(*PSGOrErr));
47
0
  else {
48
0
    Err = PSGOrErr.takeError();
49
0
    return;
50
0
  }
51
5
}
52
53
5
IncrementalExecutor::~IncrementalExecutor() {}
54
55
23
llvm::Error IncrementalExecutor::addModule(std::unique_ptr<llvm::Module> M) {
56
23
  return Jit->addIRModule(llvm::orc::ThreadSafeModule(std::move(M), TSCtx));
57
23
}
58
59
23
llvm::Error IncrementalExecutor::runCtors() const {
60
23
  return Jit->initialize(Jit->getMainJITDylib());
61
23
}
62
63
llvm::Expected<llvm::JITTargetAddress>
64
IncrementalExecutor::getSymbolAddress(llvm::StringRef Name,
65
5
                                      SymbolNameKind NameKind) const {
66
5
  auto Sym = (NameKind == LinkerName) ? 
Jit->lookupLinkerMangled(Name)0
67
5
                                      : Jit->lookup(Name);
68
69
5
  if (!Sym)
70
0
    return Sym.takeError();
71
5
  return Sym->getAddress();
72
5
}
73
74
} // end namespace clang