LLVM 20.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/DomTreeUpdater.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/LoopIterator.h"
#include "llvm/Analysis/MemorySSA.h"
#include "llvm/Analysis/MemorySSAUpdater.h"
#include "llvm/Analysis/ScalarEvolution.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Scalar/LoopPassManager.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/LoopUtils.h"
#include <optional>

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.
 
static void removeBlockFromLoops (BasicBlock *BB, Loop *FirstLoop, Loop *LastLoop=nullptr)
 Removes BB from all loops from [FirstLoop, LastLoop) in parent chain.
 
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.
 
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.
 
static bool mergeBlocksIntoPredecessors (Loop &L, DominatorTree &DT, LoopInfo &LI, MemorySSAUpdater *MSSAU, ScalarEvolution &SE)
 
static bool simplifyLoopCFG (Loop &L, DominatorTree &DT, LoopInfo &LI, ScalarEvolution &SE, MemorySSAUpdater *MSSAU, bool &IsLoopDeleted)
 

Variables

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

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "loop-simplifycfg"

Definition at line 35 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 642 of file LoopSimplifyCFG.cpp.

References EnableTermFolding.

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

References llvm::LoopBase< BlockT, LoopT >::contains(), llvm::LoopBase< BlockT, LoopT >::getLoopDepth(), llvm::LoopInfoBase< BlockT, LoopT >::getLoopFor(), and llvm::LoopBase< BlockT, LoopT >::getParentLoop().

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

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

◆ mergeBlocksIntoPredecessors()

static bool mergeBlocksIntoPredecessors ( Loop L,
DominatorTree DT,
LoopInfo LI,
MemorySSAUpdater MSSAU,
ScalarEvolution SE 
)
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 77 of file LoopSimplifyCFG.cpp.

References assert(), 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

◆ EnableTermFolding

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

Referenced by constantFoldTerminators().