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

Commit

Permalink
Create empty module and pass it to the JIT
Browse files Browse the repository at this point in the history
  • Loading branch information
weliveindetail committed Dec 8, 2019
1 parent 731f482 commit 73a565a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
7 changes: 7 additions & 0 deletions JitFromScratch.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
#include "JitFromScratch.h"

#include <llvm/ExecutionEngine/Orc/ThreadSafeModule.h>

using namespace llvm;
using namespace llvm::orc;

JitFromScratch::JitFromScratch(ExitOnError ExitOnErr)
: LLJIT(ExitOnErr(LLJITBuilder().create())) {}

Error JitFromScratch::submitModule(std::unique_ptr<Module> M,
std::unique_ptr<LLVMContext> C) {
return LLJIT->addIRModule(ThreadSafeModule(std::move(M), std::move(C)));
}
10 changes: 10 additions & 0 deletions JitFromScratch.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#pragma once

#include <llvm/ExecutionEngine/Orc/LLJIT.h>
#include <llvm/IR/DataLayout.h>
#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/Module.h>
#include <llvm/Support/Error.h>

#include <memory>

Expand All @@ -14,6 +18,12 @@ class JitFromScratch {
JitFromScratch(JitFromScratch &&) = delete;
JitFromScratch &operator=(JitFromScratch &&) = delete;

llvm::DataLayout getDataLayout() const {
return LLJIT->getDataLayout();
}

llvm::Error submitModule(std::unique_ptr<llvm::Module> M,
std::unique_ptr<llvm::LLVMContext> C);
private:
std::unique_ptr<llvm::orc::LLJIT> LLJIT;
};
13 changes: 13 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <llvm/ExecutionEngine/ExecutionEngine.h>
#include <llvm/IR/DataLayout.h>
#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/Module.h>
#include <llvm/Support/Error.h>
#include <llvm/Support/Format.h>
#include <llvm/Support/InitLLVM.h>
Expand All @@ -12,6 +14,10 @@

using namespace llvm;

Expected<std::string> codegenIR(Module &module, unsigned items) {
return "todo";
}

// Determine the size of a C array at compile-time.
template <typename T, size_t sizeOfArray>
constexpr unsigned arrayElements(T (&)[sizeOfArray]) {
Expand Down Expand Up @@ -60,6 +66,13 @@ int main(int argc, char **argv) {

JitFromScratch Jit(ExitOnErr);

auto C = std::make_unique<LLVMContext>();
auto M = std::make_unique<Module>("JitFromScratch", *C);
M->setDataLayout(Jit.getDataLayout());

ExitOnErr(codegenIR(*M, arrayElements(x)));
ExitOnErr(Jit.submitModule(std::move(M), std::move(C)));

int *z = integerDistances(x, y);

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

0 comments on commit 73a565a

Please sign in to comment.