Skip to content

Commit

Permalink
TaichiLLVMJIT -> TaichiLLVMJITCPU
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanming-hu committed Feb 24, 2020
1 parent 6902078 commit a538eb3
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion taichi/backends/codegen_llvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ using namespace llvm;

class CodeGenLLVM : public IRVisitor, public ModuleBuilder {
public:
TaichiLLVMJIT *jit;
TaichiLLVMJITCPU *jit;

CodeGenBase *codegen;
Kernel *kernel;
Expand Down
2 changes: 1 addition & 1 deletion taichi/backends/codegen_llvm_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ FunctionType CPUCodeGen::codegen_llvm() {
return CodeGenLLVMCPU(this, kernel).gen();
}

void global_optimize_module_x86_64(std::unique_ptr<llvm::Module> &module) {
void global_optimize_module_cpu(std::unique_ptr<llvm::Module> &module) {
TI_AUTO_PROF
auto JTMB = JITTargetMachineBuilder::detectHost();
if (!JTMB) {
Expand Down
36 changes: 18 additions & 18 deletions taichi/backends/llvm_jit.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ std::string compile_module_to_ptx(std::unique_ptr<llvm::Module> &module);
int compile_ptx_and_launch(const std::string &ptx,
const std::string &kernel_name,
void *);
void global_optimize_module_x86_64(std::unique_ptr<llvm::Module> &module);
void global_optimize_module_cpu(std::unique_ptr<llvm::Module> &module);

class TaichiLLVMJIT {
class TaichiLLVMJITCPU {
private:
ExecutionSession ES;
std::map<VModuleKey, std::shared_ptr<SymbolResolver>> Resolvers;
Expand All @@ -64,7 +64,7 @@ class TaichiLLVMJIT {
LegacyCompileOnDemandLayer<decltype(OptimizeLayer)> CODLayer;

public:
TaichiLLVMJIT(JITTargetMachineBuilder JTMB, DataLayout DL)
TaichiLLVMJITCPU(JITTargetMachineBuilder JTMB, DataLayout DL)
: TM(EngineBuilder().selectTarget()),
DL(TM->createDataLayout()),
ObjectLayer(ES,
Expand All @@ -82,25 +82,24 @@ class TaichiLLVMJIT {
orc::createLocalCompileCallbackManager(TM->getTargetTriple(),
ES,
0))),
CODLayer(
ES,
OptimizeLayer,
[&](orc::VModuleKey K) { return Resolvers[K]; },
[&](orc::VModuleKey K, std::shared_ptr<SymbolResolver> R) {
Resolvers[K] = std::move(R);
},
[](Function &F) { return std::set<Function *>({&F}); },
*CompileCallbackManager,
orc::createLocalIndirectStubsManagerBuilder(
TM->getTargetTriple())) {
CODLayer(ES,
OptimizeLayer,
[&](orc::VModuleKey K) { return Resolvers[K]; },
[&](orc::VModuleKey K, std::shared_ptr<SymbolResolver> R) {
Resolvers[K] = std::move(R);
},
[](Function &F) { return std::set<Function *>({&F}); },
*CompileCallbackManager,
orc::createLocalIndirectStubsManagerBuilder(
TM->getTargetTriple())) {
llvm::sys::DynamicLibrary::LoadLibraryPermanently(nullptr);
}

const DataLayout &getDataLayout() const {
return DL;
}

static Expected<std::unique_ptr<TaichiLLVMJIT>> create(Arch arch) {
static Expected<std::unique_ptr<TaichiLLVMJITCPU>> create(Arch arch) {
std::unique_ptr<JITTargetMachineBuilder> jtmb;
if (arch == Arch::x64) {
auto JTMB = JITTargetMachineBuilder::detectHost();
Expand All @@ -117,11 +116,12 @@ class TaichiLLVMJIT {
if (!DL)
return DL.takeError();

return llvm::make_unique<TaichiLLVMJIT>(std::move(*jtmb), std::move(*DL));
return llvm::make_unique<TaichiLLVMJITCPU>(std::move(*jtmb),
std::move(*DL));
}

VModuleKey addModule(std::unique_ptr<llvm::Module> M) {
global_optimize_module_x86_64(M);
global_optimize_module_cpu(M);
// Create a new VModuleKey.
VModuleKey K = ES.allocateVModule();

Expand Down Expand Up @@ -183,7 +183,7 @@ class TaichiLLVMJIT {
}
};

inline void *jit_lookup_name(TaichiLLVMJIT *jit, const std::string &name) {
inline void *jit_lookup_name(TaichiLLVMJITCPU *jit, const std::string &name) {
auto ExprSymbol = jit->lookup(name);
if (!ExprSymbol)
TI_ERROR("Function \"{}\" not found", name);
Expand Down
2 changes: 1 addition & 1 deletion taichi/taichi_llvm_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ TaichiLLVMContext::TaichiLLVMContext(Arch arch) : arch(arch) {
ctx = std::make_unique<llvm::LLVMContext>();
TI_TRACE("Creating llvm context for arch: {}", arch_name(arch));
llvm::ExitOnError exit_on_err;
jit = exit_on_err(TaichiLLVMJIT::create(arch));
jit = exit_on_err(TaichiLLVMJITCPU::create(arch));
}

TaichiLLVMContext::~TaichiLLVMContext() {
Expand Down
6 changes: 3 additions & 3 deletions taichi/taichi_llvm_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
#include "snode.h"

TLANG_NAMESPACE_BEGIN
class TaichiLLVMJIT;
class TaichiLLVMJITCPU;

void *jit_lookup_name(TaichiLLVMJIT *jit, const std::string &name);
void *jit_lookup_name(TaichiLLVMJITCPU *jit, const std::string &name);

class TaichiLLVMContext {
public:
std::unique_ptr<llvm::LLVMContext> ctx;
std::unique_ptr<TaichiLLVMJIT> jit;
std::unique_ptr<TaichiLLVMJITCPU> jit;
std::unique_ptr<llvm::Module> runtime_module, struct_module;
Arch arch;

Expand Down

0 comments on commit a538eb3

Please sign in to comment.