Skip to content

Commit

Permalink
Parameterize jl_create_llvm_module with DataLayout and Triple
Browse files Browse the repository at this point in the history
  • Loading branch information
pchintalapudi committed Mar 3, 2022
1 parent 44943c2 commit cfa83a7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 21 deletions.
6 changes: 2 additions & 4 deletions src/aotcompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,10 +508,8 @@ void jl_dump_native_impl(void *native_code,
jl_safe_printf("ERROR: target does not support generation of object files\n");

// Reset the target triple to make sure it matches the new target machine
data->M->setTargetTriple(jl_ExecutionEngine->getTargetTriple().str());
DataLayout DL = TM->createDataLayout();
DL.reset(DL.getStringRepresentation() + "-ni:10:11:12:13");
data->M->setDataLayout(DL);
data->M->setTargetTriple(TM->getTargetTriple().str());
data->M->setDataLayout(create_jl_data_layout(*TM));
Type *T_size;
if (sizeof(size_t) == 8)
T_size = Type::getInt64Ty(Context);
Expand Down
14 changes: 7 additions & 7 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1894,7 +1894,7 @@ static jl_cgval_t convert_julia_type(jl_codectx_t &ctx, const jl_cgval_t &v, jl_
return jl_cgval_t(v, typ, new_tindex);
}

Module *_jl_create_llvm_module(StringRef name, LLVMContext &context, const jl_cgparams_t *params)
Module *_jl_create_llvm_module(StringRef name, LLVMContext &context, const jl_cgparams_t *params, const DataLayout &DL, const Triple &triple)
{
Module *m = new Module(name, context);
// Some linkers (*cough* OS X) don't understand DWARF v4, so we use v2 in
Expand All @@ -1911,8 +1911,8 @@ Module *_jl_create_llvm_module(StringRef name, LLVMContext &context, const jl_cg
if (!m->getModuleFlag("Debug Info Version"))
m->addModuleFlag(llvm::Module::Warning, "Debug Info Version",
llvm::DEBUG_METADATA_VERSION);
m->setDataLayout(jl_ExecutionEngine->getDataLayout());
m->setTargetTriple(jl_ExecutionEngine->getTargetTriple().str());
m->setDataLayout(DL);
m->setTargetTriple(triple.str());

#if defined(_OS_WINDOWS_) && !defined(_CPU_X86_64_) && JL_LLVM_VERSION >= 130000
// tell Win32 to assume the stack is always 16-byte aligned,
Expand All @@ -1926,9 +1926,9 @@ Module *_jl_create_llvm_module(StringRef name, LLVMContext &context, const jl_cg
return m;
}

Module *jl_create_llvm_module(StringRef name, LLVMContext &context)
Module *jl_create_llvm_module(StringRef name, LLVMContext &ctx, const DataLayout *DL, const Triple *triple)
{
return _jl_create_llvm_module(name, context, &jl_default_cgparams);
return _jl_create_llvm_module(name, ctx, &jl_default_cgparams, DL ? *DL : jl_ExecutionEngine->getDataLayout(), triple ? *triple : jl_ExecutionEngine->getTargetTriple());
}

static void jl_init_function(Function *F)
Expand Down Expand Up @@ -6438,7 +6438,7 @@ static std::pair<std::unique_ptr<Module>, jl_llvm_functions_t>
declarations.specFunctionObject = funcName.str();

// allocate Function declarations and wrapper objects
Module *M = _jl_create_llvm_module(ctx.name, ctx.builder.getContext(), ctx.params);
Module *M = _jl_create_llvm_module(ctx.name, ctx.builder.getContext(), ctx.params, jl_ExecutionEngine->getDataLayout(), jl_ExecutionEngine->getTargetTriple());
jl_returninfo_t returninfo = {};
Function *f = NULL;
bool has_sret = false;
Expand Down Expand Up @@ -8294,7 +8294,7 @@ extern "C" JL_DLLEXPORT void jl_init_codegen_impl(void)
jl_init_jit();
init_jit_functions();

Module *m = _jl_create_llvm_module("julia", *jl_ExecutionEngine->getContext().getContext(), &jl_default_cgparams);
Module *m = _jl_create_llvm_module("julia", *jl_ExecutionEngine->getContext().getContext(), &jl_default_cgparams, jl_ExecutionEngine->getDataLayout(), jl_ExecutionEngine->getTargetTriple());
init_julia_llvm_env(m);

jl_init_intrinsic_functions_codegen();
Expand Down
17 changes: 8 additions & 9 deletions src/jitlayers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -876,14 +876,6 @@ namespace {
#endif
return std::unique_ptr<TargetMachine>(TM);
}

llvm::DataLayout createDataLayout(TargetMachine &TM) {
// Mark our address spaces as non-integral
auto jl_data_layout = TM.createDataLayout();
std::string DL = jl_data_layout.getStringRepresentation() + "-ni:10:11:12:13";
jl_data_layout.reset(DL);
return jl_data_layout;
}
} // namespace

namespace {
Expand All @@ -898,9 +890,16 @@ namespace {
}
}

llvm::DataLayout create_jl_data_layout(TargetMachine &TM) {
// Mark our address spaces as non-integral
auto jl_data_layout = TM.createDataLayout();
jl_data_layout.reset(jl_data_layout.getStringRepresentation() + "-ni:10:11:12:13");
return jl_data_layout;
}

JuliaOJIT::JuliaOJIT(LLVMContext *LLVMCtx)
: TM(createTargetMachine()),
DL(createDataLayout(*TM)),
DL(create_jl_data_layout(*TM)),
TMs{
cantFail(createJTMBFromTM(*TM, 0).createTargetMachine()),
cantFail(createJTMBFromTM(*TM, 1).createTargetMachine()),
Expand Down
3 changes: 2 additions & 1 deletion src/jitlayers.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ void addOptimizationPasses(legacy::PassManagerBase *PM, int opt_level, bool lowe
void addMachinePasses(legacy::PassManagerBase *PM, TargetMachine *TM, int optlevel);
void jl_finalize_module(std::unique_ptr<Module> m);
void jl_merge_module(Module *dest, std::unique_ptr<Module> src);
Module *jl_create_llvm_module(StringRef name, LLVMContext &ctxt);
Module *jl_create_llvm_module(StringRef name, LLVMContext &ctx, const DataLayout *DL = nullptr, const Triple *triple = nullptr);
GlobalVariable *jl_emit_RTLD_DEFAULT_var(Module *M);
DataLayout create_jl_data_layout(TargetMachine &TM);

typedef struct _jl_llvm_functions_t {
std::string functionObject; // jlcall llvm Function name
Expand Down

0 comments on commit cfa83a7

Please sign in to comment.