LLVM  13.0.0git
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/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/LoopIterator.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/IR/IRBuilder.h"
#include "llvm/InitializePasses.h"
#include "llvm/Support/CommandLine.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< bool > EnableTermFolding ("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 44 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 631 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

◆ 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 59 of file LoopSimplifyCFG.cpp.

References BB, Cond, and SI.

◆ 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 86 of file LoopSimplifyCFG.cpp.

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

◆ simplifyLoopCFG()

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

◆ STATISTIC() [1/3]

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

◆ STATISTIC() [2/3]

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

◆ STATISTIC() [3/3]

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

Variable Documentation

◆ CFG

Definition at line 769 of file LoopSimplifyCFG.cpp.

◆ EnableTermFolding

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

Referenced by constantFoldTerminators().

◆ false

Definition at line 769 of file LoopSimplifyCFG.cpp.

◆ simplifycfg

loop simplifycfg

Definition at line 768 of file LoopSimplifyCFG.cpp.