25
25
#include " llvm/IR/Verifier.h"
26
26
#include " llvm/Passes/PassBuilder.h"
27
27
#include " llvm/Support/DynamicLibrary.h"
28
+ #include " llvm/Transforms/Utils/Cloning.h"
28
29
29
30
#include " tc/core/flags.h"
30
31
#include " tc/core/polyhedral/codegen_llvm.h"
@@ -68,6 +69,7 @@ std::string find_library_path(std::string library) {
68
69
69
70
namespace tc {
70
71
72
+ #if LLVM_VERSION_MAJOR <= 6
71
73
Jit::Jit ()
72
74
: TM_(EngineBuilder().selectTarget()),
73
75
DL_(TM_->createDataLayout ()),
@@ -82,20 +84,7 @@ Jit::Jit()
82
84
}
83
85
}
84
86
85
- std::shared_ptr<Module> Jit::codegenScop (
86
- const std::string& specializedName,
87
- const polyhedral::Scop& scop) {
88
- std::shared_ptr<Module> mod = emitLLVMKernel (
89
- specializedName, scop, getTargetMachine ().createDataLayout ());
90
- addModule (mod);
91
- return mod;
92
- }
93
-
94
- TargetMachine& Jit::getTargetMachine () {
95
- return *TM_;
96
- }
97
-
98
- Jit::ModuleHandle Jit::addModule (std::shared_ptr<Module> M) {
87
+ void Jit::addModule (std::shared_ptr<Module> M) {
99
88
M->setTargetTriple (TM_->getTargetTriple ().str ());
100
89
auto Resolver = orc::createLambdaResolver (
101
90
[&](const std::string& Name) {
@@ -111,7 +100,63 @@ Jit::ModuleHandle Jit::addModule(std::shared_ptr<Module> M) {
111
100
112
101
auto res = compileLayer_.addModule (M, std::move (Resolver));
113
102
CHECK (res) << " Failed to jit compile." ;
114
- return *res;
103
+ }
104
+ #else
105
+ Jit::Jit ()
106
+ : SSP(),
107
+ ES(SSP),
108
+ Resolver(llvm::orc::createLegacyLookupResolver(
109
+ [this ](const std::string& Name) -> JITSymbol {
110
+ if (auto Sym = compileLayer_.findSymbol (Name, false ))
111
+ return Sym;
112
+ else if (auto Err = Sym.takeError ())
113
+ return std::move (Err);
114
+ if (auto SymAddr =
115
+ RTDyldMemoryManager::getSymbolAddressInProcess (Name))
116
+ return JITSymbol (SymAddr, JITSymbolFlags::Exported);
117
+ return nullptr ;
118
+ },
119
+ [](Error err) { throw std::runtime_error (" Lookup failed!" ); })),
120
+ TM_ (EngineBuilder().selectTarget()),
121
+ DL_(TM_->createDataLayout ()),
122
+ objectLayer_(
123
+ ES,
124
+ [this ](llvm::orc::VModuleKey) {
125
+ return llvm::orc::RTDyldObjectLinkingLayer::Resources{
126
+ std::make_shared<SectionMemoryManager>(), Resolver};
127
+ }),
128
+ compileLayer_(objectLayer_, orc::SimpleCompiler(*TM_)) {
129
+ std::string err;
130
+
131
+ sys::DynamicLibrary::LoadLibraryPermanently (nullptr , &err);
132
+ if (err != " " ) {
133
+ throw std::runtime_error (" Failed to find cilkrts: " + err);
134
+ }
135
+ }
136
+
137
+ // Note that this copy may cause tapir tests to fail
138
+ // However, this code will never use tapir code
139
+ // and once the LLVM API churn stops, will be modified
140
+ // to be properly compatable.
141
+ void Jit::addModule (std::shared_ptr<Module> M) {
142
+ M->setTargetTriple (TM_->getTargetTriple ().str ());
143
+ auto K = ES.allocateVModule ();
144
+ llvm::Error res = compileLayer_.addModule (K, CloneModule (*M));
145
+ CHECK (!res) << " Failed to jit compile." ;
146
+ }
147
+ #endif
148
+
149
+ std::shared_ptr<Module> Jit::codegenScop (
150
+ const std::string& specializedName,
151
+ const polyhedral::Scop& scop) {
152
+ std::shared_ptr<Module> mod = emitLLVMKernel (
153
+ specializedName, scop, getTargetMachine ().createDataLayout ());
154
+ addModule (mod);
155
+ return mod;
156
+ }
157
+
158
+ TargetMachine& Jit::getTargetMachine () {
159
+ return *TM_;
115
160
}
116
161
117
162
JITSymbol Jit::findSymbol (const std::string Name) {
0 commit comments