diff --git a/polly/lib/Transform/CodePreparation.cpp b/polly/lib/Transform/CodePreparation.cpp index 7c8579eb93218..d045fb6b62c90 100644 --- a/polly/lib/Transform/CodePreparation.cpp +++ b/polly/lib/Transform/CodePreparation.cpp @@ -27,6 +27,26 @@ using namespace llvm; using namespace polly; +static bool runCodePreprationImpl(Function &F, DominatorTree *DT, LoopInfo *LI, + RegionInfo *RI) { + // Find first non-alloca instruction. Every basic block has a non-alloca + // instruction, as every well formed basic block has a terminator. + auto &EntryBlock = F.getEntryBlock(); + BasicBlock::iterator I = EntryBlock.begin(); + while (isa(I)) + ++I; + + // Abort if not necessary to split + if (I->isTerminator() && isa(I) && + cast(I)->isUnconditional()) + return false; + + // splitBlock updates DT, LI and RI. + splitEntryBlockForAlloca(&EntryBlock, DT, LI, RI); + + return true; +} + namespace { /// Prepare the IR for the scop detection. @@ -35,9 +55,6 @@ class CodePreparation final : public FunctionPass { CodePreparation(const CodePreparation &) = delete; const CodePreparation &operator=(const CodePreparation &) = delete; - LoopInfo *LI; - ScalarEvolution *SE; - void clear(); public: @@ -58,19 +75,11 @@ class CodePreparation final : public FunctionPass { PreservedAnalyses CodePreparationPass::run(Function &F, FunctionAnalysisManager &FAM) { - - // Find first non-alloca instruction. Every basic block has a non-alloca - // instruction, as every well formed basic block has a terminator. - auto &EntryBlock = F.getEntryBlock(); - BasicBlock::iterator I = EntryBlock.begin(); - while (isa(I)) - ++I; - auto &DT = FAM.getResult(F); auto &LI = FAM.getResult(F); - - // splitBlock updates DT, LI and RI. - splitEntryBlockForAlloca(&EntryBlock, &DT, &LI, nullptr); + bool Changed = runCodePreprationImpl(F, &DT, &LI, nullptr); + if (!Changed) + return PreservedAnalyses::all(); PreservedAnalyses PA; PA.preserve(); @@ -84,7 +93,6 @@ CodePreparation::~CodePreparation() { clear(); } void CodePreparation::getAnalysisUsage(AnalysisUsage &AU) const { AU.addRequired(); - AU.addRequired(); AU.addPreserved(); AU.addPreserved(); @@ -96,10 +104,11 @@ bool CodePreparation::runOnFunction(Function &F) { if (skipFunction(F)) return false; - LI = &getAnalysis().getLoopInfo(); - SE = &getAnalysis().getSE(); + DominatorTree *DT = &getAnalysis().getDomTree(); + LoopInfo *LI = &getAnalysis().getLoopInfo(); + RegionInfo *RI = &getAnalysis().getRegionInfo(); - splitEntryBlockForAlloca(&F.getEntryBlock(), this); + runCodePreprationImpl(F, DT, LI, RI); return true; }