mirror of
https://github.com/RPCSX/llvm.git
synced 2025-03-03 18:37:56 +00:00
[LTO] Teach lib/LTO about the new pass manager.
Differential Revision: https://reviews.llvm.org/D28997 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292864 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
6fe089fa68
commit
fa5f3e4eeb
@ -42,6 +42,11 @@
|
|||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
using namespace lto;
|
using namespace lto;
|
||||||
|
|
||||||
|
static cl::opt<bool>
|
||||||
|
LTOUseNewPM("lto-use-new-pm",
|
||||||
|
cl::desc("Run LTO passes using the new pass manager"),
|
||||||
|
cl::init(false), cl::Hidden);
|
||||||
|
|
||||||
LLVM_ATTRIBUTE_NORETURN static void reportOpenError(StringRef Path, Twine Msg) {
|
LLVM_ATTRIBUTE_NORETURN static void reportOpenError(StringRef Path, Twine Msg) {
|
||||||
errs() << "failed to open " << Path << ": " << Msg << '\n';
|
errs() << "failed to open " << Path << ": " << Msg << '\n';
|
||||||
errs().flush();
|
errs().flush();
|
||||||
@ -124,6 +129,56 @@ createTargetMachine(Config &Conf, StringRef TheTriple,
|
|||||||
Conf.CodeModel, Conf.CGOptLevel));
|
Conf.CodeModel, Conf.CGOptLevel));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void runNewPMPasses(Module &Mod, TargetMachine *TM, unsigned OptLevel) {
|
||||||
|
PassBuilder PB(TM);
|
||||||
|
AAManager AA;
|
||||||
|
|
||||||
|
// Parse a custom AA pipeline if asked to.
|
||||||
|
assert(PB.parseAAPipeline(AA, "default"));
|
||||||
|
|
||||||
|
LoopAnalysisManager LAM;
|
||||||
|
FunctionAnalysisManager FAM;
|
||||||
|
CGSCCAnalysisManager CGAM;
|
||||||
|
ModuleAnalysisManager MAM;
|
||||||
|
|
||||||
|
// Register the AA manager first so that our version is the one used.
|
||||||
|
FAM.registerPass([&] { return std::move(AA); });
|
||||||
|
|
||||||
|
// Register all the basic analyses with the managers.
|
||||||
|
PB.registerModuleAnalyses(MAM);
|
||||||
|
PB.registerCGSCCAnalyses(CGAM);
|
||||||
|
PB.registerFunctionAnalyses(FAM);
|
||||||
|
PB.registerLoopAnalyses(LAM);
|
||||||
|
PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
|
||||||
|
|
||||||
|
ModulePassManager MPM;
|
||||||
|
// FIXME (davide): verify the input.
|
||||||
|
|
||||||
|
PassBuilder::OptimizationLevel OL;
|
||||||
|
|
||||||
|
switch (OptLevel) {
|
||||||
|
default:
|
||||||
|
llvm_unreachable("Invalid optimization level");
|
||||||
|
case 0:
|
||||||
|
OL = PassBuilder::O0;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
OL = PassBuilder::O1;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
OL = PassBuilder::O2;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
OL = PassBuilder::O3;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
MPM = PB.buildLTODefaultPipeline(OL, false /* DebugLogging */);
|
||||||
|
MPM.run(Mod, MAM);
|
||||||
|
|
||||||
|
// FIXME (davide): verify the output.
|
||||||
|
}
|
||||||
|
|
||||||
static void runNewPMCustomPasses(Module &Mod, TargetMachine *TM,
|
static void runNewPMCustomPasses(Module &Mod, TargetMachine *TM,
|
||||||
std::string PipelineDesc,
|
std::string PipelineDesc,
|
||||||
std::string AAPipelineDesc,
|
std::string AAPipelineDesc,
|
||||||
@ -193,12 +248,19 @@ static void runOldPMPasses(Config &Conf, Module &Mod, TargetMachine *TM,
|
|||||||
|
|
||||||
bool opt(Config &Conf, TargetMachine *TM, unsigned Task, Module &Mod,
|
bool opt(Config &Conf, TargetMachine *TM, unsigned Task, Module &Mod,
|
||||||
bool IsThinLTO, ModuleSummaryIndex &CombinedIndex) {
|
bool IsThinLTO, ModuleSummaryIndex &CombinedIndex) {
|
||||||
if (Conf.OptPipeline.empty())
|
// There's still no ThinLTO pipeline hooked up in the new pass manager,
|
||||||
runOldPMPasses(Conf, Mod, TM, IsThinLTO, CombinedIndex);
|
// once there is one, we can just remove this.
|
||||||
else
|
if (LTOUseNewPM && IsThinLTO)
|
||||||
// FIXME: Plumb the combined index into the new pass manager.
|
report_fatal_error("ThinLTO not supported with the new PM yet!");
|
||||||
|
|
||||||
|
// FIXME: Plumb the combined index into the new pass manager.
|
||||||
|
if (!Conf.OptPipeline.empty())
|
||||||
runNewPMCustomPasses(Mod, TM, Conf.OptPipeline, Conf.AAPipeline,
|
runNewPMCustomPasses(Mod, TM, Conf.OptPipeline, Conf.AAPipeline,
|
||||||
Conf.DisableVerify);
|
Conf.DisableVerify);
|
||||||
|
else if (LTOUseNewPM)
|
||||||
|
runNewPMPasses(Mod, TM, Conf.OptLevel);
|
||||||
|
else
|
||||||
|
runOldPMPasses(Conf, Mod, TM, IsThinLTO, CombinedIndex);
|
||||||
return !Conf.PostOptModuleHook || Conf.PostOptModuleHook(Task, Mod);
|
return !Conf.PostOptModuleHook || Conf.PostOptModuleHook(Task, Mod);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,10 @@
|
|||||||
; RUN: -aa-pipeline basic-aa
|
; RUN: -aa-pipeline basic-aa
|
||||||
; RUN: llvm-dis < %t.o.0.4.opt.bc | FileCheck %s --check-prefix=CUSTOM
|
; RUN: llvm-dis < %t.o.0.4.opt.bc | FileCheck %s --check-prefix=CUSTOM
|
||||||
|
|
||||||
|
; Try the new pass manager LTO default pipeline (make sure the option
|
||||||
|
; is accepted).
|
||||||
|
; RUN: llvm-lto2 %t1.bc -o %t.o -lto-use-new-pm -r %t1.bc,patatino,px
|
||||||
|
|
||||||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||||
target triple = "x86_64-unknown-linux-gnu"
|
target triple = "x86_64-unknown-linux-gnu"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user