From dc5239535356847e8659fbb5065a8acdf3b9873a Mon Sep 17 00:00:00 2001 From: Devang Patel Date: Wed, 22 Aug 2007 18:27:01 +0000 Subject: Refactor loop condition check in a separate function. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41282 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/LoopIndexSplit.cpp | 51 +++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 17 deletions(-) (limited to 'lib/Transforms/Scalar/LoopIndexSplit.cpp') diff --git a/lib/Transforms/Scalar/LoopIndexSplit.cpp b/lib/Transforms/Scalar/LoopIndexSplit.cpp index a01798b..145741f 100644 --- a/lib/Transforms/Scalar/LoopIndexSplit.cpp +++ b/lib/Transforms/Scalar/LoopIndexSplit.cpp @@ -105,6 +105,13 @@ namespace { /// Find cost of spliting loop L. unsigned findSplitCost(Loop *L, SplitInfo &SD); + + /// safeSplitCondition - Return true if it is possible to + /// split loop using given split condition. + bool safeSplitCondition(SplitInfo &SD); + + /// splitLoop - Split current loop L in two loops using split information + /// SD. Update dominator information. Maintain LCSSA form. bool splitLoop(SplitInfo &SD); void initialize() { @@ -705,32 +712,28 @@ void LoopIndexSplit::removeBlocks(BasicBlock *DeadBB, Loop *LP, } -/// splitLoop - Split current loop L in two loops using split information -/// SD. Update dominator information. Maintain LCSSA form. -bool LoopIndexSplit::splitLoop(SplitInfo &SD) { - - // True loop is original loop. False loop is cloned loop. +/// safeSplitCondition - Return true if it is possible to +/// split loop using given split condition. +bool LoopIndexSplit::safeSplitCondition(SplitInfo &SD) { - BasicBlock *TL_Preheader = L->getLoopPreheader(); - BasicBlock *TL_SplitCondBlock = SD.SplitCondition->getParent(); - BasicBlock *TL_Latch = L->getLoopLatch(); - BasicBlock *TL_Header = L->getHeader(); - BranchInst *TL_SplitTerminator = - cast(TL_SplitCondBlock->getTerminator()); + BasicBlock *SplitCondBlock = SD.SplitCondition->getParent(); - // FIXME - Unable to handle triange loops at the moment. + // Unable to handle triange loops at the moment. // In triangle loop, split condition is in header and one of the // the split destination is loop latch. If split condition is EQ // then such loops are already handle in processOneIterationLoop(). - BasicBlock *Succ0 = TL_SplitTerminator->getSuccessor(0); - BasicBlock *Succ1 = TL_SplitTerminator->getSuccessor(1); - if (TL_Header == TL_SplitCondBlock - && (TL_Latch == Succ0 || TL_Latch == Succ1)) + BasicBlock *Latch = L->getLoopLatch(); + BranchInst *SplitTerminator = + cast(SplitCondBlock->getTerminator()); + BasicBlock *Succ0 = SplitTerminator->getSuccessor(0); + BasicBlock *Succ1 = SplitTerminator->getSuccessor(1); + if (L->getHeader() == SplitCondBlock + && (Latch == Succ0 || Latch == Succ1)) return false; // If one of the split condition branch is post dominating other then loop // index split is not appropriate. - if (DT->dominates(Succ0, TL_Latch) || DT->dominates(Succ1, TL_Latch)) + if (DT->dominates(Succ0, Latch) || DT->dominates(Succ1, Latch)) return false; // If one of the split condition branch is a predecessor of the other @@ -744,6 +747,20 @@ bool LoopIndexSplit::splitLoop(SplitInfo &SD) { if (Succ0 == *PI) return false; + return true; +} + +/// splitLoop - Split current loop L in two loops using split information +/// SD. Update dominator information. Maintain LCSSA form. +bool LoopIndexSplit::splitLoop(SplitInfo &SD) { + + if (!safeSplitCondition(SD)) + return false; + + // True loop is original loop. False loop is cloned loop. + BasicBlock *TL_SplitCondBlock = SD.SplitCondition->getParent(); + BasicBlock *TL_Preheader = L->getLoopPreheader(); + bool SignedPredicate = ExitCondition->isSignedPredicate(); //[*] Calculate True loop's new Exit Value in loop preheader. // TL_ExitValue = min(SplitValue, ExitValue) -- cgit v1.1