From 23d0e83aa3745c51e1c32afa952e5bcec53cd251 Mon Sep 17 00:00:00 2001 From: Michael Kruse Date: Tue, 11 Aug 2015 14:04:06 +0000 Subject: [PATCH] Introduce splitBlock and use it in splitEntryBlockForAlloca RegionInfo::splitBlock did not update RegionInfo correctly. Specifically, it tried to make the new block the entry block if possible. This breaks for nested regions that have edges to the old block. We simply do not change the entry block. Updating RegionInfo becomes trivial as both block will always be in the same region. splitEntryBlockForAlloca makes use of the new splitBlock. Reviewers: grosser Part of Differential Revision: http://reviews.llvm.org/D11867 llvm-svn: 244600 --- polly/lib/Support/ScopHelper.cpp | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/polly/lib/Support/ScopHelper.cpp b/polly/lib/Support/ScopHelper.cpp index 176b30d..633f74b 100644 --- a/polly/lib/Support/ScopHelper.cpp +++ b/polly/lib/Support/ScopHelper.cpp @@ -169,6 +169,38 @@ BasicBlock *polly::simplifyRegion(Scop *S, Pass *P) { return EnteringBB; } +// Split the block into two successive blocks. +// +// Like llvm::SplitBlock, but also preserves RegionInfo +static BasicBlock *splitBlock(BasicBlock *Old, Instruction *SplitPt, + DominatorTree *DT, llvm::LoopInfo *LI, + RegionInfo *RI) { + assert(Old && SplitPt); + + // Before: + // + // \ / // + // Old // + // / \ // + + BasicBlock *NewBlock = llvm::SplitBlock(Old, SplitPt, DT, LI); + + if (RI) { + Region *R = RI->getRegionFor(Old); + RI->setRegionFor(NewBlock, R); + } + + // After: + // + // \ / // + // Old // + // | // + // NewBlock // + // / \ // + + return NewBlock; +} + void polly::splitEntryBlockForAlloca(BasicBlock *EntryBlock, Pass *P) { // Find first non-alloca instruction. Every basic block has a non-alloc // instruction, as every well formed basic block has a terminator. @@ -180,9 +212,9 @@ void polly::splitEntryBlockForAlloca(BasicBlock *EntryBlock, Pass *P) { auto *DT = DTWP ? &DTWP->getDomTree() : nullptr; auto *LIWP = P->getAnalysisIfAvailable(); auto *LI = LIWP ? &LIWP->getLoopInfo() : nullptr; + RegionInfoPass *RIP = P->getAnalysisIfAvailable(); + RegionInfo *RI = RIP ? &RIP->getRegionInfo() : nullptr; - // SplitBlock updates DT, DF and LI. - BasicBlock *NewEntry = SplitBlock(EntryBlock, I, DT, LI); - if (RegionInfoPass *RIP = P->getAnalysisIfAvailable()) - RIP->getRegionInfo().splitBlock(NewEntry, EntryBlock); + // splitBlock updates DT, LI and RI. + splitBlock(EntryBlock, I, DT, LI, RI); } -- 2.7.4