[llvm] r285394 - [LCSSA] Perform LCSSA verification only for the current loop nest.
Igor Laevsky via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 28 05:57:20 PDT 2016
Author: igor.laevsky
Date: Fri Oct 28 07:57:20 2016
New Revision: 285394
URL: http://llvm.org/viewvc/llvm-project?rev=285394&view=rev
Log:
[LCSSA] Perform LCSSA verification only for the current loop nest.
Now LPPassManager will run LCSSA verification only for the top-level loop
which was processed on the current iteration.
Differential Revision: https://reviews.llvm.org/D25873
Modified:
llvm/trunk/include/llvm/Analysis/LoopPass.h
llvm/trunk/include/llvm/InitializePasses.h
llvm/trunk/lib/Analysis/Analysis.cpp
llvm/trunk/lib/Analysis/LoopPass.cpp
llvm/trunk/lib/Transforms/Utils/LCSSA.cpp
llvm/trunk/lib/Transforms/Utils/LoopUtils.cpp
Modified: llvm/trunk/include/llvm/Analysis/LoopPass.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/LoopPass.h?rev=285394&r1=285393&r2=285394&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/LoopPass.h (original)
+++ llvm/trunk/include/llvm/Analysis/LoopPass.h Fri Oct 28 07:57:20 2016
@@ -155,6 +155,22 @@ private:
Loop *CurrentLoop;
};
+// This pass is required by the LCSSA transformation. It is used inside
+// LPPassManager to check if current pass preserves LCSSA form, and if it does
+// pass manager calls lcssa verification for the current loop.
+struct LCSSAVerificationPass : public FunctionPass {
+ static char ID;
+ LCSSAVerificationPass() : FunctionPass(ID) {
+ initializeLCSSAVerificationPassPass(*PassRegistry::getPassRegistry());
+ }
+
+ bool runOnFunction(Function &F) override { return false; }
+
+ void getAnalysisUsage(AnalysisUsage &AU) const override {
+ AU.setPreservesAll();
+ }
+};
+
} // End llvm namespace
#endif
Modified: llvm/trunk/include/llvm/InitializePasses.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/InitializePasses.h?rev=285394&r1=285393&r2=285394&view=diff
==============================================================================
--- llvm/trunk/include/llvm/InitializePasses.h (original)
+++ llvm/trunk/include/llvm/InitializePasses.h Fri Oct 28 07:57:20 2016
@@ -166,7 +166,8 @@ void initializeInterleavedAccessPass(Pas
void initializeInternalizeLegacyPassPass(PassRegistry&);
void initializeIntervalPartitionPass(PassRegistry&);
void initializeJumpThreadingPass(PassRegistry&);
-void initializeLCSSAWrapperPassPass(PassRegistry &);
+void initializeLCSSAWrapperPassPass(PassRegistry&);
+void initializeLCSSAVerificationPassPass(PassRegistry&);
void initializeLegacyLICMPassPass(PassRegistry&);
void initializeLegacyLoopSinkPassPass(PassRegistry&);
void initializeLazyBranchProbabilityInfoPassPass(PassRegistry&);
Modified: llvm/trunk/lib/Analysis/Analysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/Analysis.cpp?rev=285394&r1=285393&r2=285394&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/Analysis.cpp (original)
+++ llvm/trunk/lib/Analysis/Analysis.cpp Fri Oct 28 07:57:20 2016
@@ -77,6 +77,7 @@ void llvm::initializeAnalysis(PassRegist
initializeTargetTransformInfoWrapperPassPass(Registry);
initializeTypeBasedAAWrapperPassPass(Registry);
initializeScopedNoAliasAAWrapperPassPass(Registry);
+ initializeLCSSAVerificationPassPass(Registry);
}
void LLVMInitializeAnalysis(LLVMPassRegistryRef R) {
Modified: llvm/trunk/lib/Analysis/LoopPass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LoopPass.cpp?rev=285394&r1=285393&r2=285394&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/LoopPass.cpp (original)
+++ llvm/trunk/lib/Analysis/LoopPass.cpp Fri Oct 28 07:57:20 2016
@@ -15,6 +15,7 @@
#include "llvm/Analysis/LoopPass.h"
#include "llvm/Analysis/LoopPassManager.h"
+#include "llvm/IR/Dominators.h"
#include "llvm/IR/IRPrintingPasses.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/OptBisect.h"
@@ -140,6 +141,7 @@ void LPPassManager::getAnalysisUsage(Ana
// LPPassManager needs LoopInfo. In the long term LoopInfo class will
// become part of LPPassManager.
Info.addRequired<LoopInfoWrapperPass>();
+ Info.addRequired<DominatorTreeWrapperPass>();
Info.setPreservesAll();
}
@@ -148,6 +150,7 @@ void LPPassManager::getAnalysisUsage(Ana
bool LPPassManager::runOnFunction(Function &F) {
auto &LIWP = getAnalysis<LoopInfoWrapperPass>();
LI = &LIWP.getLoopInfo();
+ DominatorTree *DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
bool Changed = false;
// Collect inherited analysis from Module level pass manager.
@@ -218,6 +221,12 @@ bool LPPassManager::runOnFunction(Functi
TimeRegion PassTimer(getPassTimer(&LIWP));
CurrentLoop->verifyLoop();
}
+ // Here we apply same reasoning as in the above case. Only difference
+ // is that LPPassManager might run passes which do not require LCSSA
+ // form (LoopPassPrinter for example). We should skip verification for
+ // such passes.
+ if (mustPreserveAnalysisID(LCSSAVerificationPass::ID))
+ CurrentLoop->isRecursivelyLCSSAForm(*DT, *LI);
// Then call the regular verifyAnalysis functions.
verifyPreservedAnalysis(P);
@@ -353,3 +362,8 @@ bool LoopPass::skipLoop(const Loop *L) c
}
return false;
}
+
+char LCSSAVerificationPass::ID = 0;
+INITIALIZE_PASS(LCSSAVerificationPass, "lcssa-verification", "LCSSA Verifier",
+ false, false)
+
Modified: llvm/trunk/lib/Transforms/Utils/LCSSA.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/LCSSA.cpp?rev=285394&r1=285393&r2=285394&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/LCSSA.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/LCSSA.cpp Fri Oct 28 07:57:20 2016
@@ -51,6 +51,15 @@ using namespace llvm;
STATISTIC(NumLCSSA, "Number of live out of a loop variables");
+#ifdef EXPENSIVE_CHECKS
+static bool VerifyLoopLCSSA = true;
+#else
+static bool VerifyLoopLCSSA = false;
+#endif
+static cl::opt<bool,true>
+VerifyLoopLCSSAFlag("verify-loop-lcssa", cl::location(VerifyLoopLCSSA),
+ cl::desc("Verify loop lcssa form (time consuming)"));
+
/// Return true if the specified block is in the list.
static bool isExitBlock(BasicBlock *BB,
const SmallVectorImpl<BasicBlock *> &ExitBlocks) {
@@ -322,10 +331,17 @@ struct LCSSAWrapperPass : public Functio
bool runOnFunction(Function &F) override;
void verifyAnalysis() const override {
- assert(
- all_of(*LI,
- [&](Loop *L) { return L->isRecursivelyLCSSAForm(*DT, *LI); }) &&
- "LCSSA form is broken!");
+ // This check is very expensive. On the loop intensive compiles it may cause
+ // up to 10x slowdown. Currently it's disabled by default. LPPassManager
+ // always does limited form of the LCSSA verification. Similar reasoning
+ // was used for the LoopInfo verifier.
+ if (VerifyLoopLCSSA) {
+ assert(all_of(*LI,
+ [&](Loop *L) {
+ return L->isRecursivelyLCSSAForm(*DT, *LI);
+ }) &&
+ "LCSSA form is broken!");
+ }
};
/// This transformation requires natural loop information & requires that
@@ -342,6 +358,10 @@ struct LCSSAWrapperPass : public Functio
AU.addPreserved<GlobalsAAWrapperPass>();
AU.addPreserved<ScalarEvolutionWrapperPass>();
AU.addPreserved<SCEVAAWrapperPass>();
+
+ // This is needed to perform LCSSA verification inside LPPassManager
+ AU.addRequired<LCSSAVerificationPass>();
+ AU.addPreserved<LCSSAVerificationPass>();
}
};
}
@@ -351,6 +371,7 @@ INITIALIZE_PASS_BEGIN(LCSSAWrapperPass,
false, false)
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
+INITIALIZE_PASS_DEPENDENCY(LCSSAVerificationPass)
INITIALIZE_PASS_END(LCSSAWrapperPass, "lcssa", "Loop-Closed SSA Form Pass",
false, false)
Modified: llvm/trunk/lib/Transforms/Utils/LoopUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/LoopUtils.cpp?rev=285394&r1=285393&r2=285394&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/LoopUtils.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/LoopUtils.cpp Fri Oct 28 07:57:20 2016
@@ -17,6 +17,7 @@
#include "llvm/Analysis/GlobalsModRef.h"
#include "llvm/Analysis/GlobalsModRef.h"
#include "llvm/Analysis/LoopInfo.h"
+#include "llvm/Analysis/LoopPass.h"
#include "llvm/Analysis/ScalarEvolution.h"
#include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
#include "llvm/Analysis/ScalarEvolutionExpander.h"
@@ -946,6 +947,10 @@ void llvm::getLoopAnalysisUsage(Analysis
AU.addPreservedID(LoopSimplifyID);
AU.addRequiredID(LCSSAID);
AU.addPreservedID(LCSSAID);
+ // This is used in the LPPassManager to perform LCSSA verification on passes
+ // which preserve lcssa form
+ AU.addRequired<LCSSAVerificationPass>();
+ AU.addPreserved<LCSSAVerificationPass>();
// Loop passes are designed to run inside of a loop pass manager which means
// that any function analyses they require must be required by the first loop
More information about the llvm-commits
mailing list