This repository has been archived by the owner on Jul 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
JitFromScratch.h
80 lines (62 loc) · 2.45 KB
/
JitFromScratch.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#pragma once
#include <llvm/ADT/StringRef.h>
#include <llvm/ExecutionEngine/JITEventListener.h>
#include <llvm/ExecutionEngine/JITSymbol.h>
#include <llvm/ExecutionEngine/Orc/Core.h>
#include <llvm/ExecutionEngine/Orc/IRCompileLayer.h>
#include <llvm/ExecutionEngine/Orc/IRTransformLayer.h>
#include <llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h>
#include <llvm/IR/DataLayout.h>
#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/Module.h>
#include <llvm/Support/Error.h>
#include <llvm/Target/TargetMachine.h>
#include <functional>
#include <memory>
#include <string>
#include "SimpleObjectCache.h"
class JitFromScratch {
public:
JitFromScratch(llvm::ExitOnError ExitOnErr,
const std::string &CacheDir = "");
// Not a value type.
JitFromScratch(const JitFromScratch &) = delete;
JitFromScratch &operator=(const JitFromScratch &) = delete;
JitFromScratch(JitFromScratch &&) = delete;
JitFromScratch &operator=(JitFromScratch &&) = delete;
llvm::DataLayout getDataLayout() const {
return TM->createDataLayout();
}
const llvm::Triple &getTargetTriple() const {
return TM->getTargetTriple();
}
llvm::Error submitModule(std::unique_ptr<llvm::Module> M,
std::unique_ptr<llvm::LLVMContext> C,
unsigned OptLevel, bool AddToCache);
template <class Signature_t>
llvm::Expected<std::function<Signature_t>> getFunction(llvm::StringRef Name) {
if (auto A = getFunctionAddr(Name))
return std::function<Signature_t>(
llvm::jitTargetAddressToPointer<Signature_t *>(*A));
else
return A.takeError();
}
private:
std::unique_ptr<llvm::orc::ExecutionSession> ES;
std::unique_ptr<llvm::TargetMachine> TM;
std::unique_ptr<SimpleObjectCache> ObjCache;
llvm::JITEventListener *GDBListener;
llvm::orc::RTDyldObjectLinkingLayer ObjLinkingLayer;
llvm::orc::IRCompileLayer CompileLayer;
llvm::orc::IRTransformLayer OptimizeLayer;
llvm::orc::JITDylib::GeneratorFunction createHostProcessResolver();
std::unique_ptr<llvm::TargetMachine>
createTargetMachine(llvm::ExitOnError ExitOnErr);
llvm::orc::RTDyldObjectLinkingLayer::GetMemoryManagerFunction
createMemoryManagerFtor();
llvm::orc::RTDyldObjectLinkingLayer::NotifyLoadedFunction
createNotifyLoadedFtor();
std::string mangle(llvm::StringRef UnmangledName);
llvm::Error applyDataLayout(llvm::Module &M);
llvm::Expected<llvm::JITTargetAddress> getFunctionAddr(llvm::StringRef Name);
};