summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorAlina Sbirlea <asbirlea@google.com>2019-08-21 17:00:57 +0000
committerAlina Sbirlea <asbirlea@google.com>2019-08-21 17:00:57 +0000
commit7425179fee9b4ed1ff6d366ee06487f05a1c0ab3 (patch)
tree42f533a45605d2614eaef25446aec5cd03471ad1 /llvm/lib
parent954a012b4c75db77b99b259d9cc4edd8ab551c68 (diff)
downloadbcm5719-llvm-7425179fee9b4ed1ff6d366ee06487f05a1c0ab3.tar.gz
bcm5719-llvm-7425179fee9b4ed1ff6d366ee06487f05a1c0ab3.zip
[LoopPassManager + MemorySSA] Only enable use of MemorySSA for LPMs known to preserve it.
Summary: Add a flag to the FunctionToLoopAdaptor that allows enabling MemorySSA only for the loop pass managers that are known to preserve it. If an LPM is known to have only loop transforms that *all* preserve MemorySSA, then use MemorySSA if `EnableMSSALoopDependency` is set. If an LPM has loop passes that do not preserve MemorySSA, then the flag passed is `false`, regardless of the value of `EnableMSSALoopDependency`. When using a custom loop pass pipeline via `passes=...`, use keyword `loop` vs `loop-mssa` to use MemorySSA in that LPM. If a loop that does not preserve MemorySSA is added while using the `loop-mssa` keyword, that's an error. Add the new `loop-mssa` keyword to a few tests where a difference occurs when enabling MemorySSA. Reviewers: chandlerc Subscribers: mehdi_amini, Prazek, george.burgess.iv, sanjoy.google, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D66376 llvm-svn: 369548
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Analysis/LoopAnalysisManager.cpp2
-rw-r--r--llvm/lib/Passes/PassBuilder.cpp31
2 files changed, 20 insertions, 13 deletions
diff --git a/llvm/lib/Analysis/LoopAnalysisManager.cpp b/llvm/lib/Analysis/LoopAnalysisManager.cpp
index a10a87ce113..02d40fb8d72 100644
--- a/llvm/lib/Analysis/LoopAnalysisManager.cpp
+++ b/llvm/lib/Analysis/LoopAnalysisManager.cpp
@@ -46,7 +46,7 @@ bool LoopAnalysisManagerFunctionProxy::Result::invalidate(
// invalidation logic below to act on that.
auto PAC = PA.getChecker<LoopAnalysisManagerFunctionProxy>();
bool invalidateMemorySSAAnalysis = false;
- if (EnableMSSALoopDependency)
+ if (MSSAUsed)
invalidateMemorySSAAnalysis = Inv.invalidate<MemorySSAAnalysis>(F, PA);
if (!(PAC.preserved() || PAC.preservedSet<AllAnalysesOn<Function>>()) ||
Inv.invalidate<AAManager>(F, PA) ||
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index 74bb7f6f307..cbb1b5c946b 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -477,10 +477,15 @@ PassBuilder::buildFunctionSimplificationPipeline(OptimizationLevel Level,
// We provide the opt remark emitter pass for LICM to use. We only need to do
// this once as it is immutable.
FPM.addPass(RequireAnalysisPass<OptimizationRemarkEmitterAnalysis, Function>());
- FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM1), DebugLogging));
+ FPM.addPass(createFunctionToLoopPassAdaptor(
+ std::move(LPM1), EnableMSSALoopDependency, DebugLogging));
FPM.addPass(SimplifyCFGPass());
FPM.addPass(InstCombinePass());
- FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM2), DebugLogging));
+ // The loop passes in LPM2 (IndVarSimplifyPass, LoopIdiomRecognizePass,
+ // LoopDeletionPass and LoopFullUnrollPass) do not preserve MemorySSA.
+ // *All* loop passes must preserve it, in order to be able to use it.
+ FPM.addPass(createFunctionToLoopPassAdaptor(
+ std::move(LPM2), /*UseMemorySSA=*/false, DebugLogging));
// Eliminate redundancies.
if (Level != O1) {
@@ -517,7 +522,7 @@ PassBuilder::buildFunctionSimplificationPipeline(OptimizationLevel Level,
FPM.addPass(DSEPass());
FPM.addPass(createFunctionToLoopPassAdaptor(
LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap),
- DebugLogging));
+ EnableMSSALoopDependency, DebugLogging));
for (auto &C : ScalarOptimizerLateEPCallbacks)
C(FPM, Level);
@@ -593,7 +598,8 @@ void PassBuilder::addPGOInstrPasses(ModulePassManager &MPM, bool DebugLogging,
MPM.addPass(PGOInstrumentationGen(IsCS));
FunctionPassManager FPM;
- FPM.addPass(createFunctionToLoopPassAdaptor(LoopRotatePass(), DebugLogging));
+ FPM.addPass(createFunctionToLoopPassAdaptor(
+ LoopRotatePass(), EnableMSSALoopDependency, DebugLogging));
MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
// Add the profile lowering pass.
@@ -894,8 +900,8 @@ ModulePassManager PassBuilder::buildModuleOptimizationPipeline(
C(OptimizePM, Level);
// First rotate loops that may have been un-rotated by prior passes.
- OptimizePM.addPass(
- createFunctionToLoopPassAdaptor(LoopRotatePass(), DebugLogging));
+ OptimizePM.addPass(createFunctionToLoopPassAdaptor(
+ LoopRotatePass(), EnableMSSALoopDependency, DebugLogging));
// Distribute loops to allow partial vectorization. I.e. isolate dependences
// into separate loop that would otherwise inhibit vectorization. This is
@@ -954,7 +960,7 @@ ModulePassManager PassBuilder::buildModuleOptimizationPipeline(
OptimizePM.addPass(RequireAnalysisPass<OptimizationRemarkEmitterAnalysis, Function>());
OptimizePM.addPass(createFunctionToLoopPassAdaptor(
LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap),
- DebugLogging));
+ EnableMSSALoopDependency, DebugLogging));
// Now that we've vectorized and unrolled loops, we may have more refined
// alignment information, try to re-derive it here.
@@ -1662,7 +1668,7 @@ static bool isFunctionPassName(StringRef Name, CallbacksT &Callbacks) {
// Explicitly handle pass manager names.
if (Name == "function")
return true;
- if (Name == "loop")
+ if (Name == "loop" || Name == "loop-mssa")
return true;
// Explicitly handle custom-parsed pass names.
@@ -1686,7 +1692,7 @@ static bool isFunctionPassName(StringRef Name, CallbacksT &Callbacks) {
template <typename CallbacksT>
static bool isLoopPassName(StringRef Name, CallbacksT &Callbacks) {
// Explicitly handle pass manager names.
- if (Name == "loop")
+ if (Name == "loop" || Name == "loop-mssa")
return true;
// Explicitly handle custom-parsed pass names.
@@ -1990,14 +1996,15 @@ Error PassBuilder::parseFunctionPass(FunctionPassManager &FPM,
FPM.addPass(std::move(NestedFPM));
return Error::success();
}
- if (Name == "loop") {
+ if (Name == "loop" || Name == "loop-mssa") {
LoopPassManager LPM(DebugLogging);
if (auto Err = parseLoopPassPipeline(LPM, InnerPipeline, VerifyEachPass,
DebugLogging))
return Err;
// Add the nested pass manager with the appropriate adaptor.
- FPM.addPass(
- createFunctionToLoopPassAdaptor(std::move(LPM), DebugLogging));
+ bool UseMemorySSA = (Name == "loop-mssa");
+ FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM), UseMemorySSA,
+ DebugLogging));
return Error::success();
}
if (auto Count = parseRepeatPassName(Name)) {
OpenPOWER on IntegriCloud