Changes in directory llvm/lib/Transforms/Scalar:
LoopUnswitch.cpp updated: 1.19 -> 1.20 --- Log message: more refactoring, no functionality change. --- Diffs of the changes: (+11 -12) LoopUnswitch.cpp | 23 +++++++++++------------ 1 files changed, 11 insertions(+), 12 deletions(-) Index: llvm/lib/Transforms/Scalar/LoopUnswitch.cpp diff -u llvm/lib/Transforms/Scalar/LoopUnswitch.cpp:1.19 llvm/lib/Transforms/Scalar/LoopUnswitch.cpp:1.20 --- llvm/lib/Transforms/Scalar/LoopUnswitch.cpp:1.19 Tue Feb 14 18:07:43 2006 +++ llvm/lib/Transforms/Scalar/LoopUnswitch.cpp Tue Feb 14 19:44:42 2006 @@ -77,7 +77,7 @@ BasicBlock *SplitEdge(BasicBlock *From, BasicBlock *To); void RewriteLoopBodyWithConditionConstant(Loop *L, Value *LIC,Constant *Val, bool isEqual); - void UnswitchTrivialCondition(Loop *L, Value *Cond, bool EntersLoopOnCond, + void UnswitchTrivialCondition(Loop *L, Value *Cond, Constant *Val, BasicBlock *ExitBlock); }; RegisterOpt<LoopUnswitch> X("loop-unswitch", "Unswitch loops"); @@ -154,7 +154,7 @@ /// runs when the condition is true, False if the loop body executes when the /// condition is false. Otherwise, return null to indicate a complex condition. static bool IsTrivialUnswitchCondition(Loop *L, Value *Cond, - bool *CondEntersLoop = 0, + Constant **Val = 0, BasicBlock **LoopExit = 0) { BasicBlock *Header = L->getHeader(); BranchInst *HeaderTerm = dyn_cast<BranchInst>(Header->getTerminator()); @@ -170,9 +170,9 @@ // the loop. BasicBlock *Latch = L->getLoopLatch(); if (HeaderTerm->getSuccessor(1) == Latch) { - if (CondEntersLoop) *CondEntersLoop = true; + if (Val) *Val = ConstantBool::True; } else if (HeaderTerm->getSuccessor(0) == Latch) - if (CondEntersLoop) *CondEntersLoop = false; + if (Val) *Val = ConstantBool::False; else return false; // Doesn't branch to latch block. @@ -333,10 +333,10 @@ // If this is a trivial condition to unswitch (which results in no code // duplication), do it now. - bool EntersLoopOnCond; + Constant *CondVal; BasicBlock *ExitBlock; - if (IsTrivialUnswitchCondition(L, LoopCond, &EntersLoopOnCond, &ExitBlock)){ - UnswitchTrivialCondition(L, LoopCond, EntersLoopOnCond, ExitBlock); + if (IsTrivialUnswitchCondition(L, LoopCond, &CondVal, &ExitBlock)){ + UnswitchTrivialCondition(L, LoopCond, CondVal, ExitBlock); NewLoop1 = L; } else { VersionLoop(LoopCond, Val, L, NewLoop1, NewLoop2); @@ -460,7 +460,7 @@ /// side-effects), unswitch it. This doesn't involve any code duplication, just /// moving the conditional branch outside of the loop and updating loop info. void LoopUnswitch::UnswitchTrivialCondition(Loop *L, Value *Cond, - bool EnterOnCond, + Constant *Val, BasicBlock *ExitBlock) { DEBUG(std::cerr << "loop-unswitch: Trivial-Unswitch loop %" << L->getHeader()->getName() << " [" << L->getBlocks().size() @@ -484,15 +484,14 @@ // Okay, now we have a position to branch from and a position to branch to, // insert the new conditional branch. - new BranchInst(EnterOnCond ? NewPH : NewExit, EnterOnCond ? NewExit : NewPH, - Cond, OrigPH->getTerminator()); + EmitPreheaderBranchOnCondition(Cond, Val, NewPH, NewExit, + OrigPH->getTerminator()); OrigPH->getTerminator()->eraseFromParent(); // Now that we know that the loop is never entered when this condition is a // particular value, rewrite the loop with this info. We know that this will // at least eliminate the old branch. - RewriteLoopBodyWithConditionConstant(L, Cond, ConstantBool::get(EnterOnCond), - true); + RewriteLoopBodyWithConditionConstant(L, Cond, Val, true); ++NumTrivial; } _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits