Skip to content

Commit

Permalink
Fix a few pre-NewPM nits
Browse files Browse the repository at this point in the history
  • Loading branch information
pchintalapudi committed May 18, 2022
1 parent 18bfd7e commit 87e0ef8
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 49 deletions.
47 changes: 26 additions & 21 deletions src/aotcompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,6 @@ void jl_dump_native_impl(void *native_code,
CodeGenOpt::Aggressive // -O3 TODO: respect command -O0 flag?
));

legacy::PassManager PM;
addTargetPasses(&PM, TM->getTargetTriple(), TM->getTargetIRAnalysis());

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

legacy::PassManager preopt, postopt;

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, jl_options.opt_level);
}
preopt.add(createBitcodeWriterPass(unopt_bc_OS));

//Is this necessary for TM?
// addTargetPasses(&postopt, TM->getTargetTriple(), TM->getTargetIRAnalysis());
if (bc_fname)
PM.add(createBitcodeWriterPass(bc_OS));
postopt.add(createBitcodeWriterPass(bc_OS));
if (obj_fname)
if (TM->addPassesToEmitFile(PM, obj_OS, nullptr, CGFT_ObjectFile, false))
if (TM->addPassesToEmitFile(postopt, 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))
if (TM->addPassesToEmitFile(postopt, asm_OS, nullptr, CGFT_AssemblyFile, false))
jl_safe_printf("ERROR: target does not support generation of object files\n");

legacy::PassManager optimizer;
if (bc_fname || obj_fname || asm_fname) {
addTargetPasses(&optimizer, TM->getTargetTriple(), TM->getTargetIRAnalysis());
addOptimizationPasses(&optimizer, jl_options.opt_level, true, true);
addMachinePasses(&optimizer, jl_options.opt_level);
}

// Reset the target triple to make sure it matches the new target machine
auto dataM = data->M.getModuleUnlocked();
dataM->setTargetTriple(TM->getTargetTriple().str());
Expand Down Expand Up @@ -542,7 +548,9 @@ 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);
preopt.run(M);
optimizer.run(M);
postopt.run(M);
if (unopt_bc_fname)
emit_result(unopt_bc_Archive, unopt_bc_Buffer, unopt_bc_Name, outputs);
if (bc_fname)
Expand Down Expand Up @@ -990,14 +998,6 @@ void *jl_get_llvmf_defn_impl(jl_method_instance_t *mi, size_t world, char getwra
return NULL;
}

static legacy::PassManager *PM;
if (!PM) {
PM = new legacy::PassManager();
addTargetPasses(PM, jl_ExecutionEngine->getTargetTriple(), jl_ExecutionEngine->getTargetIRAnalysis());
addOptimizationPasses(PM, jl_options.opt_level);
addMachinePasses(PM, jl_options.opt_level);
}

// get the source code for this function
jl_value_t *jlrettype = (jl_value_t*)jl_any_type;
jl_code_info_t *src = NULL;
Expand Down Expand Up @@ -1050,9 +1050,14 @@ void *jl_get_llvmf_defn_impl(jl_method_instance_t *mi, size_t world, char getwra
// and will better match what's actually in sysimg.
for (auto &global : output.globals)
global.second->setLinkage(GlobalValue::ExternalLinkage);
if (optimize)
if (optimize) {
legacy::PassManager PM;
addTargetPasses(&PM, jl_ExecutionEngine->getTargetTriple(), jl_ExecutionEngine->getTargetIRAnalysis());
addOptimizationPasses(&PM, jl_options.opt_level);
addMachinePasses(&PM, jl_options.opt_level);
//Safe b/c context lock is held by output
PM->run(*m.getModuleUnlocked());
PM.run(*m.getModuleUnlocked());
}
const std::string *fname;
if (decls.functionObject == "jl_fptr_args" || decls.functionObject == "jl_fptr_sparam")
getwrapper = false;
Expand Down
49 changes: 25 additions & 24 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,32 +86,8 @@
#include <llvm/Bitcode/BitcodeReader.h>
#include <llvm/Linker/Linker.h>

#define DEBUG_TYPE "julia_irgen_codegen"

using namespace llvm;

STATISTIC(EmittedAllocas, "Number of allocas emitted");
STATISTIC(EmittedIntToPtrs, "Number of inttoptrs emitted");
STATISTIC(ModulesCreated, "Number of LLVM Modules created");
STATISTIC(EmittedBoxCompares, "Number of box compares emitted");
STATISTIC(EmittedBitsUnionCompares, "Number of bitsunion compares emitted");
STATISTIC(EmittedBitsCompares, "Number of bits compares emitted");
STATISTIC(EmittedEgals, "Number of egals emitted");
STATISTIC(EmittedOpfields, "Number of opfields emitted");
STATISTIC(EmittedBuiltinCalls, "Number of builtin calls emitted");
STATISTIC(EmittedJLCalls, "Number of jlcalls emitted");
STATISTIC(EmittedSpecfunCalls, "Number of specialized calls emitted");
STATISTIC(EmittedInvokes, "Number of invokes emitted");
STATISTIC(EmittedCalls, "Number of calls emitted");
STATISTIC(EmittedUndefVarErrors, "Number of undef var errors emitted");
STATISTIC(EmittedOpaqueClosureFunctions, "Number of opaque closures emitted");
STATISTIC(EmittedToJLInvokes, "Number of tojlinvoke calls emitted");
STATISTIC(EmittedCFuncInvalidates, "Number of C function invalidates emitted");
STATISTIC(GeneratedCFuncWrappers, "Number of C function wrappers generated");
STATISTIC(GeneratedCCallables, "Number of C-callable functions generated");
STATISTIC(GeneratedInvokeWrappers, "Number of invoke wrappers generated");
STATISTIC(EmittedFunctions, "Number of functions emitted");

//Drag some useful type functions into our namespace
//to reduce verbosity of our code
auto getInt1Ty(LLVMContext &ctxt) {
Expand Down Expand Up @@ -186,6 +162,31 @@ typedef Instruction TerminatorInst;
#include "processor.h"
#include "julia_assert.h"

#undef DEBUG_TYPE //LLVM occasionally likes to set DEBUG_TYPE in a header...
#define DEBUG_TYPE "julia_irgen_codegen"

STATISTIC(EmittedAllocas, "Number of allocas emitted");
STATISTIC(EmittedIntToPtrs, "Number of inttoptrs emitted");
STATISTIC(ModulesCreated, "Number of LLVM Modules created");
STATISTIC(EmittedBoxCompares, "Number of box compares emitted");
STATISTIC(EmittedBitsUnionCompares, "Number of bitsunion compares emitted");
STATISTIC(EmittedBitsCompares, "Number of bits compares emitted");
STATISTIC(EmittedEgals, "Number of egals emitted");
STATISTIC(EmittedOpfields, "Number of opfields emitted");
STATISTIC(EmittedBuiltinCalls, "Number of builtin calls emitted");
STATISTIC(EmittedJLCalls, "Number of jlcalls emitted");
STATISTIC(EmittedSpecfunCalls, "Number of specialized calls emitted");
STATISTIC(EmittedInvokes, "Number of invokes emitted");
STATISTIC(EmittedCalls, "Number of calls emitted");
STATISTIC(EmittedUndefVarErrors, "Number of undef var errors emitted");
STATISTIC(EmittedOpaqueClosureFunctions, "Number of opaque closures emitted");
STATISTIC(EmittedToJLInvokes, "Number of tojlinvoke calls emitted");
STATISTIC(EmittedCFuncInvalidates, "Number of C function invalidates emitted");
STATISTIC(GeneratedCFuncWrappers, "Number of C function wrappers generated");
STATISTIC(GeneratedCCallables, "Number of C-callable functions generated");
STATISTIC(GeneratedInvokeWrappers, "Number of invoke wrappers generated");
STATISTIC(EmittedFunctions, "Number of functions emitted");

extern "C" JL_DLLEXPORT
void jl_dump_emitted_mi_name_impl(void *s)
{
Expand Down
7 changes: 5 additions & 2 deletions src/jitlayers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,9 @@ namespace {
} // namespace

namespace {

typedef legacy::PassManager PassManager;

orc::JITTargetMachineBuilder createJTMBFromTM(TargetMachine &TM, int optlevel) {
return orc::JITTargetMachineBuilder(TM.getTargetTriple())
.setCPU(TM.getTargetCPU().str())
Expand Down Expand Up @@ -899,7 +902,7 @@ namespace {
swap(*this, other);
return *this;
}
std::unique_ptr<legacy::PassManager> operator()() {
std::unique_ptr<PassManager> operator()() {
auto PM = std::make_unique<legacy::PassManager>();
addTargetPasses(PM.get(), TM->getTargetTriple(), TM->getTargetIRAnalysis());
addOptimizationPasses(PM.get(), optlevel);
Expand Down Expand Up @@ -967,7 +970,7 @@ namespace {
}
private:
int optlevel;
JuliaOJIT::ResourcePool<std::unique_ptr<legacy::PassManager>> PMs;
JuliaOJIT::ResourcePool<std::unique_ptr<PassManager>> PMs;
};

struct CompilerT : orc::IRCompileLayer::IRCompiler {
Expand Down
2 changes: 1 addition & 1 deletion src/llvm-multiversioning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ PreservedAnalyses MultiVersioning::run(Module &M, ModuleAnalysisManager &AM)
auto GetCG = [&]() -> CallGraph & {
return AM.getResult<CallGraphAnalysis>(M);
};
if (runMultiVersioning(M, GetLI, GetCG, false)) {
if (runMultiVersioning(M, GetLI, GetCG, external_use)) {
auto preserved = PreservedAnalyses::allInSet<CFGAnalyses>();
preserved.preserve<LoopAnalysis>();
return preserved;
Expand Down
4 changes: 3 additions & 1 deletion src/passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@ struct LowerSIMDLoop : PassInfoMixin<LowerSIMDLoop> {
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
};

struct FinalLowerGCPass : PassInfoMixin<LateLowerGC> {
struct FinalLowerGCPass : PassInfoMixin<FinalLowerGCPass> {
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
static bool isRequired() { return true; }
};

struct MultiVersioning : PassInfoMixin<MultiVersioning> {
bool external_use;
MultiVersioning(bool external_use = false) : external_use(external_use) {}
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
static bool isRequired() { return true; }
};
Expand Down

0 comments on commit 87e0ef8

Please sign in to comment.