[PATCH] D28997: [LTO] Teach lib/LTO about the new pass manager
Davide Italiano via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Jan 22 17:04:52 PST 2017
davide created this revision.
Herald added a subscriber: mehdi_amini.
Depends on https://reviews.llvm.org/D28996.
With this in, we can teach the gold plugin and lld about the new PM and start to experiment with that.
Repository:
rL LLVM
https://reviews.llvm.org/D28997
Files:
include/llvm/LTO/Config.h
lib/LTO/LTOBackend.cpp
Index: lib/LTO/LTOBackend.cpp
===================================================================
--- lib/LTO/LTOBackend.cpp
+++ lib/LTO/LTOBackend.cpp
@@ -124,6 +124,57 @@
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,
std::string PipelineDesc,
std::string AAPipelineDesc,
@@ -193,12 +244,16 @@
bool opt(Config &Conf, TargetMachine *TM, unsigned Task, Module &Mod,
bool IsThinLTO, ModuleSummaryIndex &CombinedIndex) {
- if (Conf.OptPipeline.empty())
- runOldPMPasses(Conf, Mod, TM, IsThinLTO, CombinedIndex);
- else
+ if (Conf.OptUseNewPM || !Conf.OptPipeline.empty()) {
// FIXME: Plumb the combined index into the new pass manager.
- runNewPMCustomPasses(Mod, TM, Conf.OptPipeline, Conf.AAPipeline,
- Conf.DisableVerify);
+ if (Conf.OptPipeline.empty())
+ runNewPMPasses(Mod, TM, Conf.OptLevel);
+ else
+ runNewPMCustomPasses(Mod, TM, Conf.OptPipeline, Conf.AAPipeline,
+ Conf.DisableVerify);
+ }
+ else
+ runOldPMPasses(Conf, Mod, TM, IsThinLTO, CombinedIndex);
return !Conf.PostOptModuleHook || Conf.PostOptModuleHook(Task, Mod);
}
Index: include/llvm/LTO/Config.h
===================================================================
--- include/llvm/LTO/Config.h
+++ include/llvm/LTO/Config.h
@@ -47,6 +47,11 @@
/// Disable entirely the optimizer, including importing for ThinLTO
bool CodeGenOnly = false;
+ /// If this field is set, the new pass manager is used to run passes.
+ /// This will go away once the new pass manager will be the default and
+ /// the old pass manager will be removed.
+ bool OptUseNewPM = false;
+
/// If this field is set, the set of passes run in the middle-end optimizer
/// will be the one specified by the string. Only works with the new pass
/// manager as the old one doesn't have this ability.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28997.85308.patch
Type: text/x-patch
Size: 3303 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170123/0578dd7b/attachment.bin>
More information about the llvm-commits
mailing list