Skip to content
This repository was archived by the owner on Jul 3, 2021. It is now read-only.

Commit 73a565a

Browse files
Create empty module and pass it to the JIT
1 parent 731f482 commit 73a565a

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

JitFromScratch.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
#include "JitFromScratch.h"
22

3+
#include <llvm/ExecutionEngine/Orc/ThreadSafeModule.h>
4+
35
using namespace llvm;
46
using namespace llvm::orc;
57

68
JitFromScratch::JitFromScratch(ExitOnError ExitOnErr)
79
: LLJIT(ExitOnErr(LLJITBuilder().create())) {}
10+
11+
Error JitFromScratch::submitModule(std::unique_ptr<Module> M,
12+
std::unique_ptr<LLVMContext> C) {
13+
return LLJIT->addIRModule(ThreadSafeModule(std::move(M), std::move(C)));
14+
}

JitFromScratch.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#pragma once
22

33
#include <llvm/ExecutionEngine/Orc/LLJIT.h>
4+
#include <llvm/IR/DataLayout.h>
5+
#include <llvm/IR/LLVMContext.h>
6+
#include <llvm/IR/Module.h>
7+
#include <llvm/Support/Error.h>
48

59
#include <memory>
610

@@ -14,6 +18,12 @@ class JitFromScratch {
1418
JitFromScratch(JitFromScratch &&) = delete;
1519
JitFromScratch &operator=(JitFromScratch &&) = delete;
1620

21+
llvm::DataLayout getDataLayout() const {
22+
return LLJIT->getDataLayout();
23+
}
24+
25+
llvm::Error submitModule(std::unique_ptr<llvm::Module> M,
26+
std::unique_ptr<llvm::LLVMContext> C);
1727
private:
1828
std::unique_ptr<llvm::orc::LLJIT> LLJIT;
1929
};

main.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include <llvm/ExecutionEngine/ExecutionEngine.h>
22
#include <llvm/IR/DataLayout.h>
3+
#include <llvm/IR/LLVMContext.h>
4+
#include <llvm/IR/Module.h>
35
#include <llvm/Support/Error.h>
46
#include <llvm/Support/Format.h>
57
#include <llvm/Support/InitLLVM.h>
@@ -12,6 +14,10 @@
1214

1315
using namespace llvm;
1416

17+
Expected<std::string> codegenIR(Module &module, unsigned items) {
18+
return "todo";
19+
}
20+
1521
// Determine the size of a C array at compile-time.
1622
template <typename T, size_t sizeOfArray>
1723
constexpr unsigned arrayElements(T (&)[sizeOfArray]) {
@@ -60,6 +66,13 @@ int main(int argc, char **argv) {
6066

6167
JitFromScratch Jit(ExitOnErr);
6268

69+
auto C = std::make_unique<LLVMContext>();
70+
auto M = std::make_unique<Module>("JitFromScratch", *C);
71+
M->setDataLayout(Jit.getDataLayout());
72+
73+
ExitOnErr(codegenIR(*M, arrayElements(x)));
74+
ExitOnErr(Jit.submitModule(std::move(M), std::move(C)));
75+
6376
int *z = integerDistances(x, y);
6477

6578
outs() << format("Integer Distances: %d, %d, %d\n\n", z[0], z[1], z[2]);

0 commit comments

Comments
 (0)