Skip to content

Commit

Permalink
use optimizeModule in sysimg building
Browse files Browse the repository at this point in the history
  • Loading branch information
pchintalapudi committed Mar 6, 2022
1 parent 83dd1cb commit 09b72e6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 20 deletions.
55 changes: 37 additions & 18 deletions src/aotcompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,8 @@ void jl_dump_native_impl(void *native_code,
CodeGenOpt::Aggressive // -O3 TODO: respect command -O0 flag?
));

legacy::PassManager PM;
addTargetPasses(&PM, TM.get());
// legacy::PassManager PM;
// addTargetPasses(&PM, TM.get());

// set up optimization passes
SmallVector<char, 0> bc_Buffer;
Expand All @@ -530,20 +530,39 @@ void jl_dump_native_impl(void *native_code,
std::vector<NewArchiveMember> unopt_bc_Archive;
std::vector<std::string> outputs;

if (unopt_bc_fname)
PM.add(createBitcodeWriterPass(unopt_bc_OS));
if (bc_fname || obj_fname || asm_fname) {
addOptimizationPasses(&PM, jl_options.opt_level, true, true);
addMachinePasses(&PM, TM.get(), jl_options.opt_level);
}
if (bc_fname)
PM.add(createBitcodeWriterPass(bc_OS));
if (obj_fname)
if (TM->addPassesToEmitFile(PM, obj_OS, nullptr, CGFT_ObjectFile, false))
jl_safe_printf("ERROR: target does not support generation of object files\n");
if (asm_fname)
if (TM->addPassesToEmitFile(PM, asm_OS, nullptr, CGFT_AssemblyFile, false))
jl_safe_printf("ERROR: target does not support generation of object files\n");
auto optimize = [&](Module &M) {
if (unopt_bc_fname) {
legacy::PassManager PM;
PM.add(createBitcodeWriterPass(unopt_bc_OS));
PM.run(M);
}
optimizeModule(M, TM.get(), jl_options.opt_level, true, true);
legacy::PassManager PM;
if (bc_fname)
PM.add(createBitcodeWriterPass(bc_OS));
if (obj_fname)
if (TM->addPassesToEmitFile(PM, obj_OS, nullptr, CGFT_ObjectFile, false))
jl_safe_printf("ERROR: target does not support generation of object files\n");
if (asm_fname)
if (TM->addPassesToEmitFile(PM, asm_OS, nullptr, CGFT_AssemblyFile, false))
jl_safe_printf("ERROR: target does not support generation of object files\n");
PM.run(M);
};

// if (unopt_bc_fname)
// PM.add(createBitcodeWriterPass(unopt_bc_OS));
// if (bc_fname || obj_fname || asm_fname) {
// addOptimizationPasses(&PM, jl_options.opt_level, true, true);
// addMachinePasses(&PM, TM.get(), jl_options.opt_level);
// }
// if (bc_fname)
// PM.add(createBitcodeWriterPass(bc_OS));
// if (obj_fname)
// if (TM->addPassesToEmitFile(PM, obj_OS, nullptr, CGFT_ObjectFile, false))
// jl_safe_printf("ERROR: target does not support generation of object files\n");
// if (asm_fname)
// if (TM->addPassesToEmitFile(PM, asm_OS, nullptr, CGFT_AssemblyFile, false))
// 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(TM->getTargetTriple().str());
Expand Down Expand Up @@ -573,7 +592,7 @@ void jl_dump_native_impl(void *native_code,

// do the actual work
auto add_output = [&] (Module &M, StringRef unopt_bc_Name, StringRef bc_Name, StringRef obj_Name, StringRef asm_Name) {
PM.run(M);
optimize(M);
if (unopt_bc_fname)
emit_result(unopt_bc_Archive, unopt_bc_Buffer, unopt_bc_Name, outputs);
if (bc_fname)
Expand Down Expand Up @@ -1397,7 +1416,7 @@ void *jl_get_llvmf_defn_impl(jl_method_instance_t *mi, LLVMContextRef ctxt, size
global.second->setLinkage(GlobalValue::ExternalLinkage);
if (optimize)
// PM->run(*m.get());
optimizeModule(*m, &jl_ExecutionEngine->getTargetMachine(), jl_options.opt_level, true, false);
optimizeModule(*m, &jl_ExecutionEngine->getTargetMachine(), jl_options.opt_level);
const std::string *fname;
if (decls.functionObject == "jl_fptr_args" || decls.functionObject == "jl_fptr_sparam")
getwrapper = false;
Expand Down
2 changes: 1 addition & 1 deletion src/jitlayers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ OptimizerResultT JuliaOJIT::OptimizerT::operator()(orc::ThreadSafeModule TSM, or
JL_TIMING(LLVM_OPT);

// PM.run(M);
optimizeModule(M, &TM, optlevel, true, false);
optimizeModule(M, &TM, optlevel);

uint64_t end_time = 0;
if (dump_llvm_opt_stream != NULL) {
Expand Down
2 changes: 1 addition & 1 deletion src/jitlayers.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ extern bool imaging_mode;
void addTargetPasses(legacy::PassManagerBase *PM, TargetMachine *TM);
void addOptimizationPasses(legacy::PassManagerBase *PM, int opt_level, bool lower_intrinsics=true, bool dump_native=false);
void addMachinePasses(legacy::PassManagerBase *PM, TargetMachine *TM, int optlevel);
void optimizeModule(Module &M, TargetMachine *TM, int opt_level, bool lower_intrinsics, bool dump_native);
void optimizeModule(Module &M, TargetMachine *TM, int opt_level, bool lower_intrinsics=true, bool dump_native=false);
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 &ctx, const DataLayout *DL = nullptr, const Triple *triple = nullptr);
Expand Down

0 comments on commit 09b72e6

Please sign in to comment.