Skip to content

Commit

Permalink
Use actual analysis managers with non-optimization pass manager
Browse files Browse the repository at this point in the history
  • Loading branch information
pchintalapudi committed May 24, 2022
1 parent a7d6a7b commit 8bb1b96
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
27 changes: 18 additions & 9 deletions src/aotcompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,6 @@ void jl_dump_native_impl(void *native_code,
std::vector<NewArchiveMember> unopt_bc_Archive;
std::vector<std::string> outputs;

ModuleAnalysisManager none;
ModulePassManager preopt, postopt;
legacy::PassManager emitter;

Expand Down Expand Up @@ -603,13 +602,18 @@ 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) {
preopt.run(M, none);
AnalysisManagers AM;
PassBuilder PB;
AM.crossRegister(PB);
preopt.run(M, AM.MAM);
if (unopt_bc_fname)
emit_result(unopt_bc_Archive, unopt_bc_Buffer, unopt_bc_Name, outputs);
if (!bc_fname && !obj_fname && !asm_fname)
return;
optimizer.run(M);
postopt.run(M, none);
AM = AnalysisManagers();
AM.crossRegister(PB);
postopt.run(M, AM.MAM);
emitter.run(M);
if (bc_fname)
emit_result(bc_Archive, bc_Buffer, bc_Name, outputs);
Expand Down Expand Up @@ -1395,17 +1399,22 @@ NewPM::NewPM(std::unique_ptr<TargetMachine> TM, int opt_level, OptimizationOptio
PB(this->TM.get(), PipelineTuningOptions(), None, PIC.get()),
MPM(createMPM(opt_level, options)), opt_level(opt_level) {}

PreservedAnalyses NewPM::run(Module &M) {
LoopAnalysisManager LAM;
FunctionAnalysisManager FAM(createFAM(opt_level, TM->getTargetIRAnalysis(), TM->getTargetTriple()));
CGSCCAnalysisManager CGAM;
ModuleAnalysisManager MAM;
AnalysisManagers::AnalysisManagers(PassBuilder &PB, TargetMachine &TM, int opt_level) :
LAM(), FAM(createFAM(opt_level, TM.getTargetIRAnalysis(), TM.getTargetTriple())), CGAM(), MAM() {
crossRegister(PB);
}

void AnalysisManagers::crossRegister(PassBuilder &PB) {
PB.registerLoopAnalyses(LAM);
PB.registerFunctionAnalyses(FAM);
PB.registerCGSCCAnalyses(CGAM);
PB.registerModuleAnalyses(MAM);
PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
return MPM.run(M, MAM);
}

PreservedAnalyses NewPM::run(Module &M) {
AnalysisManagers analyses(PB, *TM, opt_level);
return MPM.run(M, analyses.MAM);
}

// TODO(vchuravy/maleadt):
Expand Down
6 changes: 4 additions & 2 deletions src/disasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,11 @@ void jl_strip_llvm_debug(Module *m)
void jl_strip_llvm_addrspaces(Module *m)
{
ModulePassManager PM;
ModuleAnalysisManager MAM;
AnalysisManagers AM;
PassBuilder PB;
AM.crossRegister(PB);
PM.addPass(RemoveJuliaAddrspacesPass());
PM.run(*m, MAM);
PM.run(*m, AM.MAM);
}

// print an llvm IR acquired from jl_get_llvmf
Expand Down
12 changes: 12 additions & 0 deletions src/jitlayers.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ static inline bool imaging_default() {
return jl_options.image_codegen || (jl_generating_output() && !jl_options.incremental);
}

struct AnalysisManagers {
LoopAnalysisManager LAM;
FunctionAnalysisManager FAM;
CGSCCAnalysisManager CGAM;
ModuleAnalysisManager MAM;

AnalysisManagers() = default;
AnalysisManagers(PassBuilder &PB, TargetMachine &TM, int opt_level);

void crossRegister(PassBuilder &PB);
};

struct NewPM {
std::unique_ptr<TargetMachine> TM;
StandardInstrumentations SI;
Expand Down

0 comments on commit 8bb1b96

Please sign in to comment.