LLVM: lib/Transforms/Utils/LoopSimplify.cpp File Reference (original) (raw)
Go to the source code of this file.
| Macros | |
|---|---|
| #define | DEBUG_TYPE "loop-simplify" |
| Functions | |
|---|---|
| STATISTIC (NumNested, "Number of nested loops split out") | |
| static void | placeSplitBlockCarefully (BasicBlock *NewBB, SmallVectorImpl< BasicBlock * > &SplitPreds, Loop *L) |
| static void | addBlockAndPredsToSet (BasicBlock *InputBB, BasicBlock *StopBlock, SmallPtrSetImpl< BasicBlock * > &Blocks) |
| Add the specified block, and all of its predecessors, to the specified set, if it's not already in there. | |
| static PHINode * | findPHIToPartitionLoops (Loop *L, DominatorTree *DT, AssumptionCache *AC) |
| The first part of loop-nestification is to find a PHI node that tells us how to partition the loops. | |
| static Loop * | separateNestedLoop (Loop *L, BasicBlock *Preheader, DominatorTree *DT, LoopInfo *LI, ScalarEvolution *SE, bool PreserveLCSSA, AssumptionCache *AC, MemorySSAUpdater *MSSAU) |
| If this loop has multiple backedges, try to pull one of them out into a nested loop. | |
| static BasicBlock * | insertUniqueBackedgeBlock (Loop *L, BasicBlock *Preheader, DominatorTree *DT, LoopInfo *LI, MemorySSAUpdater *MSSAU) |
| This method is called when the specified loop has more than one backedge in it. | |
| static bool | simplifyOneLoop (Loop *L, SmallVectorImpl< Loop * > &Worklist, DominatorTree *DT, LoopInfo *LI, ScalarEvolution *SE, AssumptionCache *AC, MemorySSAUpdater *MSSAU, bool PreserveLCSSA) |
| Simplify one loop and queue further loops for simplification. | |
| INITIALIZE_PASS_BEGIN (LoopSimplify, "loop-simplify", "Canonicalize natural loops", false, false) INITIALIZE_PASS_END(LoopSimplify |
| Variables | |
|---|---|
| loop | simplify |
| loop Canonicalize natural | loops |
| loop Canonicalize natural | false |
◆ DEBUG_TYPE
#define DEBUG_TYPE "loop-simplify"
◆ addBlockAndPredsToSet()
Add the specified block, and all of its predecessors, to the specified set, if it's not already in there.
Stop predecessor traversal when we reach StopBlock.
Definition at line 155 of file LoopSimplify.cpp.
References llvm::append_range(), llvm::SmallVectorTemplateCommon< T, typename >::empty(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::SmallVectorImpl< T >::pop_back_val(), llvm::predecessors(), and llvm::SmallVectorTemplateBase< T, bool >::push_back().
Referenced by separateNestedLoop().
◆ findPHIToPartitionLoops()
◆ INITIALIZE_PASS_BEGIN()
| INITIALIZE_PASS_BEGIN | ( | LoopSimplify | , |
|---|---|---|---|
| "loop-simplify" | , | ||
| "Canonicalize natural loops" | , | ||
| false | , | ||
| false | ) |
◆ insertUniqueBackedgeBlock()
This method is called when the specified loop has more than one backedge in it.
If this occurs, revector all of these backedges to target a new basic block and have that block branch to the loop header. This ensures that loops have exactly one backedge.
Definition at line 355 of file LoopSimplify.cpp.
References llvm::PHINode::addIncoming(), assert(), llvm::cast(), llvm::BasicBlock::Create(), llvm::BranchInst::Create(), llvm::PHINode::Create(), llvm::dbgs(), llvm::Instruction::eraseFromParent(), F, llvm::PHINode::getIncomingBlock(), llvm::PHINode::getIncomingValue(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::Instruction::getMetadata(), llvm::Value::getName(), llvm::PHINode::getNumIncomingValues(), llvm::BasicBlock::getTerminator(), llvm::Value::getType(), I, llvm::isa(), IV, LLVM_DEBUG, P, llvm::predecessors(), llvm::PHINode::removeIncomingValueIf(), llvm::Value::replaceAllUsesWith(), llvm::Instruction::replaceSuccessorWith(), llvm::Instruction::setDebugLoc(), llvm::PHINode::setIncomingBlock(), llvm::PHINode::setIncomingValue(), llvm::Instruction::setMetadata(), llvm::DominatorTreeBase< NodeT, IsPostDom >::splitBlock(), and llvm::MemorySSAUpdater::updatePhisWhenInsertingUniqueBackedgeBlock().
Referenced by simplifyOneLoop().
◆ placeSplitBlockCarefully()
◆ separateNestedLoop()
If this loop has multiple backedges, try to pull one of them out into a nested loop.
This is important for code that looks like this:
Loop: ... br cond, Loop, Next ... br cond2, Loop, Out
To identify this common case, we look at the PHI nodes in the header of the loop. PHI nodes with unchanging values on one backedge correspond to values that change in the "outer" loop, but not in the "inner" loop.
If we are able to separate out a loop, return the new outer loop that was created.
Definition at line 212 of file LoopSimplify.cpp.
References addBlockAndPredsToSet(), llvm::LoopBase< BlockT, LoopT >::addBlockEntry(), llvm::LoopBase< BlockT, LoopT >::addChildLoop(), llvm::LoopInfoBase< BlockT, LoopT >::AllocateLoop(), assert(), llvm::LoopInfoBase< BlockT, LoopT >::changeLoopFor(), llvm::LoopInfoBase< BlockT, LoopT >::changeTopLevelLoop(), llvm::SmallPtrSetImpl< PtrType >::count(), llvm::dbgs(), llvm::DominatorTree::dominates(), llvm::dyn_cast(), findPHIToPartitionLoops(), llvm::ScalarEvolution::forgetLoop(), llvm::formDedicatedExitBlocks(), llvm::formLCSSA(), llvm::PHINode::getIncomingBlock(), llvm::PHINode::getIncomingValue(), llvm::PHINode::getNumIncomingValues(), llvm::BasicBlock::getTerminator(), I, II, llvm::isa(), llvm::Loop::isRecursivelyLCSSAForm(), LLVM_DEBUG, P, placeSplitBlockCarefully(), llvm::predecessors(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::LoopBase< BlockT, LoopT >::replaceChildLoopWith(), llvm::size(), and llvm::SplitBlockPredecessors().
Referenced by simplifyOneLoop().
◆ simplifyOneLoop()
Simplify one loop and queue further loops for simplification.
Definition at line 475 of file LoopSimplify.cpp.
References assert(), Changed, llvm::DominatorTreeBase< NodeT, IsPostDom >::changeImmediateDominator(), llvm::changeToUnreachable(), Cond, llvm::dbgs(), DL, llvm::dyn_cast(), llvm::Instruction::eraseFromParent(), llvm::DominatorTreeBase< NodeT, IsPostDom >::eraseNode(), llvm::foldBranchToCommonDest(), llvm::ScalarEvolution::forgetValue(), llvm::formDedicatedExitBlocks(), llvm::BranchInst::getCondition(), llvm::MemorySSAUpdater::getMemorySSA(), llvm::DominatorTreeBase< NodeT, IsPostDom >::getNode(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), llvm::BranchInst::getSuccessor(), llvm::BasicBlock::getTerminator(), I, llvm::SetVector< T, Vector, Set, N >::insert(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::InsertPreheaderForLoop(), insertUniqueBackedgeBlock(), llvm::BranchInst::isConditional(), LLVM_DEBUG, P, llvm::pred_empty(), llvm::predecessors(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::LoopInfoBase< BlockT, LoopT >::removeBlock(), llvm::MemorySSAUpdater::removeBlocks(), llvm::BasicBlock::removePredecessor(), llvm::Value::replaceAllUsesWith(), llvm::LoopInfo::replacementPreservesLCSSAForm(), separateNestedLoop(), llvm::simplifyInstruction(), llvm::successors(), llvm::VerifyMemorySSA, and llvm::MemorySSA::verifyMemorySSA().
Referenced by llvm::simplifyLoop().
◆ STATISTIC()
| STATISTIC | ( | NumNested | , |
|---|---|---|---|
| "Number of nested loops split out" | ) |
◆ false
loop Canonicalize natural false
◆ loops
loop Canonicalize natural loops