summaryrefslogtreecommitdiff
path: root/lib/LTO/LTOBackend.cpp
diff options
context:
space:
mode:
authorDavide Italiano <davide@freebsd.org>2016-09-07 17:46:16 +0000
committerDavide Italiano <davide@freebsd.org>2016-09-07 17:46:16 +0000
commitfab897dd11a017c0191db2423dcd7fe8e9b7eca2 (patch)
tree7b0f00bca84a13912b2124593073a467240cf9c1 /lib/LTO/LTOBackend.cpp
parent6874fa846baa070414567f689fa11c389b6cad8f (diff)
[lib/LTO] Add a way to run a custom pipeline
Differential Revision: https://reviews.llvm.org/D24095 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@280830 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/LTO/LTOBackend.cpp')
-rw-r--r--lib/LTO/LTOBackend.cpp46
1 files changed, 45 insertions, 1 deletions
diff --git a/lib/LTO/LTOBackend.cpp b/lib/LTO/LTOBackend.cpp
index 3ed52ba575d..75f3182ee1d 100644
--- a/lib/LTO/LTOBackend.cpp
+++ b/lib/LTO/LTOBackend.cpp
@@ -15,12 +15,18 @@
//===----------------------------------------------------------------------===//
#include "llvm/LTO/LTOBackend.h"
+#include "llvm/Analysis/AliasAnalysis.h"
+#include "llvm/Analysis/CGSCCPassManager.h"
+#include "llvm/Analysis/LoopPassManager.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/IR/LegacyPassManager.h"
+#include "llvm/IR/PassManager.h"
+#include "llvm/IR/Verifier.h"
#include "llvm/LTO/LTO.h"
#include "llvm/MC/SubtargetFeature.h"
+#include "llvm/Passes/PassBuilder.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/TargetRegistry.h"
@@ -115,6 +121,41 @@ createTargetMachine(Config &Conf, StringRef TheTriple,
Conf.CodeModel, Conf.CGOptLevel));
}
+static void runNewPMCustomPasses(Module &Mod, TargetMachine *TM,
+ std::string PipelineDesc,
+ bool DisableVerify) {
+ PassBuilder PB(TM);
+ AAManager AA;
+ 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;
+
+ // Always verify the input.
+ MPM.addPass(VerifierPass());
+
+ // Now, add all the passes we've been requested to.
+ if (!PB.parsePassPipeline(MPM, PipelineDesc))
+ report_fatal_error("unable to parse pass pipeline description: " +
+ PipelineDesc);
+
+ if (!DisableVerify)
+ MPM.addPass(VerifierPass());
+ MPM.run(Mod, MAM);
+}
+
static void runOldPMPasses(Config &Conf, Module &Mod, TargetMachine *TM,
bool IsThinLto) {
legacy::PassManager passes;
@@ -140,7 +181,10 @@ static void runOldPMPasses(Config &Conf, Module &Mod, TargetMachine *TM,
bool opt(Config &Conf, TargetMachine *TM, unsigned Task, Module &Mod,
bool IsThinLto) {
Mod.setDataLayout(TM->createDataLayout());
- runOldPMPasses(Conf, Mod, TM, IsThinLto);
+ if (Conf.OptPipeline.empty())
+ runOldPMPasses(Conf, Mod, TM, IsThinLto);
+ else
+ runNewPMCustomPasses(Mod, TM, Conf.OptPipeline, Conf.DisableVerify);
return !Conf.PostOptModuleHook || Conf.PostOptModuleHook(Task, Mod);
}