|
LLVM
4.0.0
|
#include "llvm/Transforms/Utils/LoopSimplify.h"#include "llvm/Transforms/Scalar.h"#include "llvm/ADT/DepthFirstIterator.h"#include "llvm/ADT/SetOperations.h"#include "llvm/ADT/SetVector.h"#include "llvm/ADT/SmallVector.h"#include "llvm/ADT/Statistic.h"#include "llvm/Analysis/AliasAnalysis.h"#include "llvm/Analysis/BasicAliasAnalysis.h"#include "llvm/Analysis/AssumptionCache.h"#include "llvm/Analysis/DependenceAnalysis.h"#include "llvm/Analysis/GlobalsModRef.h"#include "llvm/Analysis/InstructionSimplify.h"#include "llvm/Analysis/LoopInfo.h"#include "llvm/Analysis/ScalarEvolution.h"#include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"#include "llvm/IR/CFG.h"#include "llvm/IR/Constants.h"#include "llvm/IR/DataLayout.h"#include "llvm/IR/Dominators.h"#include "llvm/IR/Function.h"#include "llvm/IR/Instructions.h"#include "llvm/IR/IntrinsicInst.h"#include "llvm/IR/LLVMContext.h"#include "llvm/IR/Module.h"#include "llvm/IR/Type.h"#include "llvm/Support/Debug.h"#include "llvm/Support/raw_ostream.h"#include "llvm/Transforms/Utils/BasicBlockUtils.h"#include "llvm/Transforms/Utils/Local.h"#include "llvm/Transforms/Utils/LoopUtils.h"Go to the source code of this file.
Macros | |
| #define | DEBUG_TYPE "loop-simplify" |
Functions | |
| STATISTIC (NumInserted,"Number of pre-header or exit blocks inserted") | |
| STATISTIC (NumNested,"Number of nested loops split out") | |
| static void | placeSplitBlockCarefully (BasicBlock *NewBB, SmallVectorImpl< BasicBlock * > &SplitPreds, Loop *L) |
| static BasicBlock * | rewriteLoopExitBlock (Loop *L, BasicBlock *Exit, DominatorTree *DT, LoopInfo *LI, bool PreserveLCSSA) |
| Ensure that the loop preheader dominates all exit blocks. More... | |
| static void | addBlockAndPredsToSet (BasicBlock *InputBB, BasicBlock *StopBlock, std::set< BasicBlock * > &Blocks) |
| Add the specified block, and all of its predecessors, to the specified set, if it's not already in there. More... | |
| 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. More... | |
| static Loop * | separateNestedLoop (Loop *L, BasicBlock *Preheader, DominatorTree *DT, LoopInfo *LI, ScalarEvolution *SE, bool PreserveLCSSA, AssumptionCache *AC) |
| If this loop has multiple backedges, try to pull one of them out into a nested loop. More... | |
| static BasicBlock * | insertUniqueBackedgeBlock (Loop *L, BasicBlock *Preheader, DominatorTree *DT, LoopInfo *LI) |
| This method is called when the specified loop has more than one backedge in it. More... | |
| static bool | simplifyOneLoop (Loop *L, SmallVectorImpl< Loop * > &Worklist, DominatorTree *DT, LoopInfo *LI, ScalarEvolution *SE, AssumptionCache *AC, bool PreserveLCSSA) |
| Simplify one loop and queue further loops for simplification. More... | |
| 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 |
| #define DEBUG_TYPE "loop-simplify" |
Definition at line 73 of file LoopSimplify.cpp.
|
static |
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 189 of file LoopSimplify.cpp.
References E, llvm::SmallVectorBase::empty(), I, llvm::SmallVectorImpl< T >::pop_back_val(), llvm::pred_begin(), llvm::pred_end(), and llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back().
Referenced by separateNestedLoop().
|
static |
The first part of loop-nestification is to find a PHI node that tells us how to partition the loops.
Definition at line 207 of file LoopSimplify.cpp.
References llvm::LoopBase< N, M >::contains(), llvm::Instruction::eraseFromParent(), llvm::LoopBase< N, M >::getHeader(), llvm::PHINode::getIncomingBlock(), llvm::PHINode::getIncomingValue(), llvm::PHINode::getNumIncomingValues(), I, i, llvm::Value::replaceAllUsesWith(), and llvm::SimplifyInstruction().
Referenced by separateNestedLoop().
| INITIALIZE_PASS_BEGIN | ( | LoopSimplify | , |
| "loop-simplify" | , | ||
| "Canonicalize natural loops" | , | ||
| false | , | ||
| false | |||
| ) |
|
static |
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 382 of file LoopSimplify.cpp.
References llvm::LoopBase< N, M >::addBasicBlockToLoop(), llvm::PHINode::addIncoming(), assert(), llvm::BasicBlock::Create(), llvm::PHINode::Create(), llvm::BranchInst::Create(), llvm::dbgs(), DEBUG, E, llvm::iplist_impl< IntrusiveListT, TraitsT >::erase(), F, llvm::Function::getBasicBlockList(), llvm::BasicBlock::getContext(), llvm::LoopBase< N, M >::getHeader(), llvm::PHINode::getIncomingBlock(), llvm::PHINode::getIncomingValue(), llvm::BasicBlock::getInstList(), llvm::LLVMContext::getMDKindID(), llvm::Instruction::getMetadata(), llvm::Value::getName(), llvm::LoopBase< N, M >::getNumBackEdges(), llvm::PHINode::getNumIncomingValues(), llvm::TerminatorInst::getNumSuccessors(), llvm::TerminatorInst::getSuccessor(), llvm::BasicBlock::getTerminator(), llvm::Value::getType(), I, i, P, llvm::pred_begin(), llvm::pred_end(), llvm::PHINode::removeIncomingValue(), llvm::PHINode::setIncomingBlock(), llvm::PHINode::setIncomingValue(), llvm::Instruction::setMetadata(), llvm::TerminatorInst::setSuccessor(), llvm::iplist_impl< IntrusiveListT, TraitsT >::splice(), and llvm::DominatorTreeBase< N >::splitBlock().
Referenced by simplifyOneLoop().
|
static |
Definition at line 81 of file LoopSimplify.cpp.
References llvm::LoopBase< N, M >::contains(), llvm::Function::end(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::BasicBlock::getParent(), i, llvm::BasicBlock::moveAfter(), and llvm::SmallVectorTemplateCommon< T >::size().
Referenced by llvm::InsertPreheaderForLoop(), and separateNestedLoop().
|
static |
Ensure that the loop preheader dominates all exit blocks.
This method is used to split exit blocks that have predecessors outside of the loop.
Definition at line 159 of file LoopSimplify.cpp.
References assert(), llvm::LoopBase< N, M >::contains(), llvm::dbgs(), DEBUG, E, llvm::SmallVectorBase::empty(), llvm::BasicBlock::getTerminator(), I, P, llvm::pred_begin(), llvm::pred_end(), llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), and llvm::SplitBlockPredecessors().
Referenced by separateNestedLoop(), and simplifyOneLoop().
|
static |
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 249 of file LoopSimplify.cpp.
References addBlockAndPredsToSet(), llvm::LoopBase< N, M >::addBlockEntry(), llvm::LoopBase< N, M >::addChildLoop(), llvm::any_of(), assert(), llvm::SmallVectorTemplateCommon< T >::begin(), llvm::LoopBase< N, M >::block_begin(), llvm::LoopBase< N, M >::block_end(), llvm::LoopInfoBase< N, M >::changeLoopFor(), llvm::LoopInfoBase< N, M >::changeTopLevelLoop(), llvm::LoopBase< N, M >::contains(), llvm::dbgs(), DEBUG, llvm::DominatorTree::dominates(), E, llvm::SmallVectorTemplateCommon< T >::end(), findPHIToPartitionLoops(), llvm::ScalarEvolution::forgetLoop(), llvm::formLCSSA(), llvm::LoopBase< N, M >::getBlocks(), llvm::LoopBase< N, M >::getExitBlocks(), llvm::LoopBase< N, M >::getHeader(), llvm::LoopBase< N, M >::getParentLoop(), llvm::LoopBase< N, M >::getSubLoops(), I, i, llvm::BasicBlock::isEHPad(), llvm::Loop::isRecursivelyLCSSAForm(), llvm::LoopBase< N, M >::moveToHeader(), P, placeSplitBlockCarefully(), llvm::pred_begin(), llvm::pred_end(), llvm::predecessors(), llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), llvm::LoopBase< N, M >::removeBlockFromLoop(), llvm::LoopBase< N, M >::removeChildLoop(), rewriteLoopExitBlock(), and llvm::SplitBlockPredecessors().
Referenced by simplifyOneLoop().
|
static |
Simplify one loop and queue further loops for simplification.
Definition at line 502 of file LoopSimplify.cpp.
References llvm::any_of(), assert(), llvm::SmallVectorTemplateCommon< T >::begin(), llvm::BasicBlock::begin(), llvm::LoopBase< N, M >::block_begin(), llvm::LoopBase< N, M >::block_end(), llvm::DominatorTreeBase< N >::changeImmediateDominator(), llvm::changeToUnreachable(), llvm::LoopBase< N, M >::contains(), llvm::dbgs(), DEBUG, llvm::dyn_cast(), E, llvm::SmallVectorBase::empty(), llvm::SmallVectorTemplateCommon< T >::end(), llvm::Instruction::eraseFromParent(), llvm::BasicBlock::eraseFromParent(), llvm::DominatorTreeBase< N >::eraseNode(), llvm::FoldBranchToCommonDest(), llvm::ScalarEvolution::forgetLoop(), llvm::ScalarEvolution::forgetLoopDispositions(), llvm::ScalarEvolution::forgetValue(), llvm::ConstantInt::get(), llvm::DomTreeNodeBase< NodeT >::getChildren(), llvm::BranchInst::getCondition(), llvm::LoopBase< N, M >::getExitBlocks(), llvm::LoopBase< N, M >::getExitingBlocks(), llvm::LoopBase< N, M >::getHeader(), llvm::DomTreeNodeBase< NodeT >::getIDom(), llvm::LoopBase< N, M >::getLoopLatch(), llvm::LoopBase< N, M >::getLoopPreheader(), llvm::Value::getName(), llvm::DominatorTreeBase< N >::getNode(), llvm::LoopBase< N, M >::getNumBackEdges(), llvm::Instruction::getParent(), llvm::BasicBlock::getSinglePredecessor(), llvm::BranchInst::getSuccessor(), llvm::BasicBlock::getTerminator(), I, i, llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::InsertPreheaderForLoop(), insertUniqueBackedgeBlock(), llvm::BranchInst::isConditional(), llvm::Loop::makeLoopInvariant(), P, llvm::pred_begin(), llvm::pred_end(), llvm::predecessors(), llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), llvm::LoopInfoBase< N, M >::removeBlock(), llvm::BasicBlock::removePredecessor(), llvm::Value::replaceAllUsesWith(), llvm::LoopInfo::replacementPreservesLCSSAForm(), rewriteLoopExitBlock(), separateNestedLoop(), llvm::SimplifyInstruction(), and llvm::SmallVectorTemplateCommon< T >::size().
Referenced by llvm::simplifyLoop().
| STATISTIC | ( | NumInserted | , |
| "Number of pre-header or exit blocks inserted" | |||
| ) |
| loop Canonicalize natural false |
Definition at line 797 of file LoopSimplify.cpp.
| loop Canonicalize natural loops |
Definition at line 797 of file LoopSimplify.cpp.
| loop simplify |
Definition at line 797 of file LoopSimplify.cpp.
1.8.6