LLVM  10.0.0svn
Macros | Functions | Variables
LoopSimplifyCFG.cpp File Reference
#include "llvm/Transforms/Scalar/LoopSimplifyCFG.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/AssumptionCache.h"
#include "llvm/Analysis/BasicAliasAnalysis.h"
#include "llvm/Analysis/DependenceAnalysis.h"
#include "llvm/Analysis/DomTreeUpdater.h"
#include "llvm/Analysis/GlobalsModRef.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/LoopPass.h"
#include "llvm/Analysis/MemorySSA.h"
#include "llvm/Analysis/MemorySSAUpdater.h"
#include "llvm/Analysis/ScalarEvolution.h"
#include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/IR/Dominators.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Scalar/LoopPassManager.h"
#include "llvm/Transforms/Utils.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Transforms/Utils/LoopUtils.h"
Include dependency graph for LoopSimplifyCFG.cpp:

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "loop-simplifycfg"
 

Functions

 STATISTIC (NumTerminatorsFolded, "Number of terminators folded to unconditional branches")
 
 STATISTIC (NumLoopBlocksDeleted, "Number of loop blocks deleted")
 
 STATISTIC (NumLoopExitsDeleted, "Number of loop exiting edges deleted")
 
static BasicBlockgetOnlyLiveSuccessor (BasicBlock *BB)
 If BB is a switch or a conditional branch, but only one of its successors can be reached from this block in runtime, return this successor. More...
 
static void removeBlockFromLoops (BasicBlock *BB, Loop *FirstLoop, Loop *LastLoop=nullptr)
 Removes BB from all loops from [FirstLoop, LastLoop) in parent chain. More...
 
static LoopgetInnermostLoopFor (SmallPtrSetImpl< BasicBlock *> &BBs, Loop &L, LoopInfo &LI)
 Find innermost loop that contains at least one block from BBs and contains the header of loop L. More...
 
static bool constantFoldTerminators (Loop &L, DominatorTree &DT, LoopInfo &LI, ScalarEvolution &SE, MemorySSAUpdater *MSSAU, bool &IsLoopDeleted)
 Turn branches and switches with known constant conditions into unconditional branches. More...
 
static bool mergeBlocksIntoPredecessors (Loop &L, DominatorTree &DT, LoopInfo &LI, MemorySSAUpdater *MSSAU)
 
static bool simplifyLoopCFG (Loop &L, DominatorTree &DT, LoopInfo &LI, ScalarEvolution &SE, MemorySSAUpdater *MSSAU, bool &isLoopDeleted)
 
 INITIALIZE_PASS_BEGIN (LoopSimplifyCFGLegacyPass, "loop-simplifycfg", "Simplify loop CFG", false, false) INITIALIZE_PASS_END(LoopSimplifyCFGLegacyPass
 

Variables

static cl::opt< boolEnableTermFolding ("enable-loop-simplifycfg-term-folding", cl::init(true))
 
loop simplifycfg
 
loop Simplify loop CFG
 
loop Simplify loop false
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "loop-simplifycfg"

Definition at line 41 of file LoopSimplifyCFG.cpp.

Function Documentation

◆ constantFoldTerminators()

static bool constantFoldTerminators ( Loop L,
DominatorTree DT,
LoopInfo LI,
ScalarEvolution SE,
MemorySSAUpdater MSSAU,
bool IsLoopDeleted 
)
static

Turn branches and switches with known constant conditions into unconditional branches.

Definition at line 623 of file LoopSimplifyCFG.cpp.

References EnableTermFolding, and llvm::LoopBase< BlockT, LoopT >::getLoopLatch().

Referenced by simplifyLoopCFG().

◆ getInnermostLoopFor()

static Loop* getInnermostLoopFor ( SmallPtrSetImpl< BasicBlock *> &  BBs,
Loop L,
LoopInfo LI 
)
static

Find innermost loop that contains at least one block from BBs and contains the header of loop L.

Definition at line 95 of file LoopSimplifyCFG.cpp.

References llvm::LoopBase< BlockT, LoopT >::addChildLoop(), llvm::LoopInfoBase< BlockT, LoopT >::addTopLevelLoop(), llvm::any_of(), llvm::DomTreeUpdater::applyUpdates(), llvm::MemorySSAUpdater::applyUpdates(), assert(), llvm::SmallVectorTemplateCommon< T >::begin(), llvm::LoopBlocksDFS::beginPostorder(), llvm::LoopBlocksDFS::beginRPO(), llvm::LoopBase< BlockT, LoopT >::blocks(), llvm::SmallVectorImpl< T >::clear(), llvm::LoopBase< BlockT, LoopT >::contains(), llvm::SmallPtrSetImpl< PtrType >::count(), llvm::dbgs(), llvm::DominatorTreeBase< BasicBlock, false >::Delete, llvm::DomTreeUpdater::deleteBB(), llvm::DetatchDeadBlocks(), DFS(), llvm::dump(), E, llvm::DomTreeUpdater::Eager, llvm::SmallVectorBase::empty(), llvm::SmallVectorTemplateCommon< T >::end(), llvm::LoopBlocksDFS::endPostorder(), llvm::LoopBlocksDFS::endRPO(), llvm::LoopInfo::erase(), llvm::Instruction::eraseFromParent(), llvm::CallingConv::Fast, llvm::ScalarEvolution::forgetTopmostLoop(), llvm::formLCSSARecursively(), From, llvm::JumpTable::Full, llvm::UndefValue::get(), llvm::LoopBase< BlockT, LoopT >::getExitBlocks(), llvm::LoopBase< BlockT, LoopT >::getHeader(), llvm::LoopBase< BlockT, LoopT >::getLoopDepth(), llvm::LoopInfoBase< BlockT, LoopT >::getLoopFor(), llvm::LoopBase< BlockT, LoopT >::getLoopLatch(), llvm::LoopBase< BlockT, LoopT >::getLoopPreheader(), llvm::MemorySSAUpdater::getMemorySSA(), llvm::Value::getName(), llvm::LoopBase< BlockT, LoopT >::getNumBlocks(), getOnlyLiveSuccessor(), llvm::BasicBlock::getParent(), llvm::LoopBase< BlockT, LoopT >::getParentLoop(), llvm::BasicBlock::getTerminator(), I, llvm::DominatorTreeBase< BasicBlock, false >::Insert, llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::LoopBlocksDFS::isComplete(), llvm::LoopInfoBase< BlockT, LoopT >::isLoopHeader(), llvm::DominatorTree::isReachableFromEntry(), LLVM_DEBUG, llvm::LoopBlocksDFS::perform(), llvm::AArch64CC::PL, llvm::SmallVectorTemplateBase< T >::push_back(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::LoopInfoBase< BlockT, LoopT >::removeBlock(), removeBlockFromLoops(), llvm::MemorySSAUpdater::removeBlocks(), llvm::MemorySSAUpdater::removeDuplicatePhiEdgesBetween(), llvm::MemorySSAUpdater::removeEdge(), RPO, llvm::SmallVectorBase::size(), llvm::SmallPtrSetImplBase::size(), llvm::SplitBlock(), llvm::successors(), llvm::DominatorTreeBase< NodeT, IsPostDom >::verify(), llvm::LoopInfoBase< BlockT, LoopT >::verify(), llvm::VerifyMemorySSA, and llvm::MemorySSA::verifyMemorySSA().

◆ getOnlyLiveSuccessor()

static BasicBlock* getOnlyLiveSuccessor ( BasicBlock BB)
static

If BB is a switch or a conditional branch, but only one of its successors can be reached from this block in runtime, return this successor.

Otherwise, return nullptr.

Definition at line 56 of file LoopSimplifyCFG.cpp.

References llvm::Instruction::getSuccessor(), and llvm::BasicBlock::getTerminator().

Referenced by getInnermostLoopFor().

◆ INITIALIZE_PASS_BEGIN()

INITIALIZE_PASS_BEGIN ( LoopSimplifyCFGLegacyPass  ,
"loop-simplifycfg ,
"Simplify loop CFG ,
false  ,
false   
)

◆ mergeBlocksIntoPredecessors()

static bool mergeBlocksIntoPredecessors ( Loop L,
DominatorTree DT,
LoopInfo LI,
MemorySSAUpdater MSSAU 
)
static

◆ removeBlockFromLoops()

static void removeBlockFromLoops ( BasicBlock BB,
Loop FirstLoop,
Loop LastLoop = nullptr 
)
static

Removes BB from all loops from [FirstLoop, LastLoop) in parent chain.

Definition at line 83 of file LoopSimplifyCFG.cpp.

References assert(), llvm::LoopBase< BlockT, LoopT >::contains(), llvm::LoopBase< BlockT, LoopT >::getHeader(), and llvm::LoopBase< BlockT, LoopT >::getParentLoop().

Referenced by getInnermostLoopFor().

◆ simplifyLoopCFG()

static bool simplifyLoopCFG ( Loop L,
DominatorTree DT,
LoopInfo LI,
ScalarEvolution SE,
MemorySSAUpdater MSSAU,
bool isLoopDeleted 
)
static

◆ STATISTIC() [1/3]

STATISTIC ( NumTerminatorsFolded  ,
"Number of terminators folded to unconditional branches  
)

◆ STATISTIC() [2/3]

STATISTIC ( NumLoopBlocksDeleted  ,
"Number of loop blocks deleted"   
)

◆ STATISTIC() [3/3]

STATISTIC ( NumLoopExitsDeleted  ,
"Number of loop exiting edges deleted"   
)

Variable Documentation

◆ CFG

loop Simplify loop CFG

Definition at line 757 of file LoopSimplifyCFG.cpp.

◆ EnableTermFolding

cl::opt<bool> EnableTermFolding("enable-loop-simplifycfg-term-folding", cl::init(true))
static

Referenced by constantFoldTerminators().

◆ false

loop Simplify loop false

Definition at line 757 of file LoopSimplifyCFG.cpp.

◆ simplifycfg

loop simplifycfg

Definition at line 757 of file LoopSimplifyCFG.cpp.