diff options
author | Devang Patel <dpatel@apple.com> | 2007-08-22 18:27:01 +0000 |
---|---|---|
committer | Devang Patel <dpatel@apple.com> | 2007-08-22 18:27:01 +0000 |
commit | dc5239535356847e8659fbb5065a8acdf3b9873a (patch) | |
tree | fbdd4ff3b85f40b9e84c624e1698839b58ee9f07 /lib/Transforms | |
parent | ea0fa973340a8e98818f7a97b5d225267641bfc5 (diff) | |
download | external_llvm-dc5239535356847e8659fbb5065a8acdf3b9873a.zip external_llvm-dc5239535356847e8659fbb5065a8acdf3b9873a.tar.gz external_llvm-dc5239535356847e8659fbb5065a8acdf3b9873a.tar.bz2 |
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
Diffstat (limited to 'lib/Transforms')
-rw-r--r-- | lib/Transforms/Scalar/LoopIndexSplit.cpp | 51 |
1 files changed, 34 insertions, 17 deletions
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<BranchInst>(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<BranchInst>(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) |