Simplify control flow a bit, note that unswitch preserves canonical loop form

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26098 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2006-02-09 22:15:42 +00:00
parent 7d82d607c5
commit f4f5f4e56f

View File

@@ -59,12 +59,13 @@ namespace {
/// ///
virtual void getAnalysisUsage(AnalysisUsage &AU) const { virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequiredID(LoopSimplifyID); AU.addRequiredID(LoopSimplifyID);
AU.addPreservedID(LoopSimplifyID);
AU.addRequired<LoopInfo>(); AU.addRequired<LoopInfo>();
AU.addPreserved<LoopInfo>(); AU.addPreserved<LoopInfo>();
} }
private: private:
void VersionLoop(Value *LIC, Loop *L); void VersionLoop(Value *LIC, Loop *L, Loop *&Out1, Loop *&Out2);
BasicBlock *SplitBlock(BasicBlock *BB, bool SplitAtTop); BasicBlock *SplitBlock(BasicBlock *BB, bool SplitAtTop);
void RewriteLoopBodyWithConditionConstant(Loop *L, Value *LIC, bool Val); void RewriteLoopBodyWithConditionConstant(Loop *L, Value *LIC, bool Val);
}; };
@@ -172,11 +173,13 @@ bool LoopUnswitch::visitLoop(Loop *L) {
} }
//std::cerr << "BEFORE:\n"; LI->dump(); //std::cerr << "BEFORE:\n"; LI->dump();
VersionLoop(BI->getCondition(), L); Loop *First = 0, *Second = 0;
VersionLoop(BI->getCondition(), L, First, Second);
//std::cerr << "AFTER:\n"; LI->dump(); //std::cerr << "AFTER:\n"; LI->dump();
// FIXME: Why return here? What if we have: // Try to unswitch each of our new loops now!
// "for () { if (iv1) { if (iv2) { } } }" ? if (First) visitLoop(First);
if (Second) visitLoop(Second);
return true; return true;
} }
@@ -247,8 +250,9 @@ static Loop *CloneLoop(Loop *L, Loop *PL, std::map<const Value*, Value*> &VM,
/// VersionLoop - We determined that the loop is profitable to unswitch and /// VersionLoop - We determined that the loop is profitable to unswitch and
/// contains a branch on a loop invariant condition. Split it into loop /// contains a branch on a loop invariant condition. Split it into loop
/// versions and test the condition outside of either loop. /// versions and test the condition outside of either loop. Return the loops
void LoopUnswitch::VersionLoop(Value *LIC, Loop *L) { /// created as Out1/Out2.
void LoopUnswitch::VersionLoop(Value *LIC, Loop *L, Loop *&Out1, Loop *&Out2) {
Function *F = L->getHeader()->getParent(); Function *F = L->getHeader()->getParent();
DEBUG(std::cerr << "loop-unswitch: Unswitching loop %" DEBUG(std::cerr << "loop-unswitch: Unswitching loop %"
@@ -324,10 +328,8 @@ void LoopUnswitch::VersionLoop(Value *LIC, Loop *L) {
RewriteLoopBodyWithConditionConstant(L, LIC, true); RewriteLoopBodyWithConditionConstant(L, LIC, true);
RewriteLoopBodyWithConditionConstant(NewLoop, LIC, false); RewriteLoopBodyWithConditionConstant(NewLoop, LIC, false);
++NumUnswitched; ++NumUnswitched;
Out1 = L;
// Try to unswitch each of our new loops now! Out2 = NewLoop;
visitLoop(L);
visitLoop(NewLoop);
} }
// RewriteLoopBodyWithConditionConstant - We know that the boolean value LIC has // RewriteLoopBodyWithConditionConstant - We know that the boolean value LIC has