LLVM 20.0.0git
Macros | Functions | Variables
ConstantHoisting.cpp File Reference
#include "llvm/Transforms/Scalar/ConstantHoisting.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/BlockFrequencyInfo.h"
#include "llvm/Analysis/ProfileSummaryInfo.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/InstrTypes.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Operator.h"
#include "llvm/IR/Value.h"
#include "llvm/InitializePasses.h"
#include "llvm/Pass.h"
#include "llvm/Support/BlockFrequency.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Transforms/Utils/SizeOpts.h"
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <iterator>
#include <tuple>
#include <utility>

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "consthoist"
 

Functions

 STATISTIC (NumConstantsHoisted, "Number of constants hoisted")
 
 STATISTIC (NumConstantsRebased, "Number of constants rebased")
 
 INITIALIZE_PASS_BEGIN (ConstantHoistingLegacyPass, "consthoist", "Constant Hoisting", false, false) INITIALIZE_PASS_END(ConstantHoistingLegacyPass
 
static void findBestInsertionSet (DominatorTree &DT, BlockFrequencyInfo &BFI, BasicBlock *Entry, SetVector< BasicBlock * > &BBs)
 Given BBs as input, find another set of BBs which collectively dominates BBs and have the minimal sum of frequencies.
 
static std::optional< APIntcalculateOffsetDiff (const APInt &V1, const APInt &V2)
 
static bool updateOperand (Instruction *Inst, unsigned Idx, Instruction *Mat)
 Updates the operand at Idx in instruction Inst with the result of instruction Mat.
 

Variables

static cl::opt< boolConstHoistWithBlockFrequency ("consthoist-with-block-frequency", cl::init(true), cl::Hidden, cl::desc("Enable the use of the block frequency analysis to reduce the " "chance to execute const materialization more frequently than " "without hoisting."))
 
static cl::opt< boolConstHoistGEP ("consthoist-gep", cl::init(false), cl::Hidden, cl::desc("Try hoisting constant gep expressions"))
 
static cl::opt< unsignedMinNumOfDependentToRebase ("consthoist-min-num-to-rebase", cl::desc("Do not rebase if number of dependent constants of a Base is less " "than this number."), cl::init(0), cl::Hidden)
 
 consthoist
 
Constant Hoisting
 
Constant false
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "consthoist"

Definition at line 76 of file ConstantHoisting.cpp.

Function Documentation

◆ calculateOffsetDiff()

static std::optional< APInt > calculateOffsetDiff ( const APInt V1,
const APInt V2 
)
static

◆ findBestInsertionSet()

static void findBestInsertionSet ( DominatorTree DT,
BlockFrequencyInfo BFI,
BasicBlock Entry,
SetVector< BasicBlock * > &  BBs 
)
static

◆ INITIALIZE_PASS_BEGIN()

INITIALIZE_PASS_BEGIN ( ConstantHoistingLegacyPass  ,
"consthoist"  ,
"Constant Hoisting"  ,
false  ,
false   
)

◆ STATISTIC() [1/2]

STATISTIC ( NumConstantsHoisted  ,
"Number of constants hoisted"   
)

◆ STATISTIC() [2/2]

STATISTIC ( NumConstantsRebased  ,
"Number of constants rebased"   
)

◆ updateOperand()

static bool updateOperand ( Instruction Inst,
unsigned  Idx,
Instruction Mat 
)
static

Updates the operand at Idx in instruction Inst with the result of instruction Mat.

If the instruction is a PHI node then special handling for duplicate values from the same incoming basic block is required.

Returns
The update will always succeed, but the return value indicated if Mat was used for the update or not.

Definition at line 731 of file ConstantHoisting.cpp.

References Idx, PHI, and llvm::User::setOperand().

Variable Documentation

◆ consthoist

consthoist

Definition at line 135 of file ConstantHoisting.cpp.

◆ ConstHoistGEP

cl::opt< bool > ConstHoistGEP("consthoist-gep", cl::init(false), cl::Hidden, cl::desc("Try hoisting constant gep expressions")) ( "consthoist-gep"  ,
cl::init(false)  ,
cl::Hidden  ,
cl::desc("Try hoisting constant gep expressions")   
)
static

◆ ConstHoistWithBlockFrequency

cl::opt< bool > ConstHoistWithBlockFrequency("consthoist-with-block-frequency", cl::init(true), cl::Hidden, cl::desc("Enable the use of the block frequency analysis to reduce the " "chance to execute const materialization more frequently than " "without hoisting.")) ( "consthoist-with-block-frequency"  ,
cl::init(true ,
cl::Hidden  ,
cl::desc("Enable the use of the block frequency analysis to reduce the " "chance to execute const materialization more frequently than " "without hoisting.")   
)
static

◆ false

Constant false

Definition at line 136 of file ConstantHoisting.cpp.

◆ Hoisting

Constant Hoisting

Definition at line 136 of file ConstantHoisting.cpp.

◆ MinNumOfDependentToRebase

cl::opt< unsigned > MinNumOfDependentToRebase("consthoist-min-num-to-rebase", cl::desc("Do not rebase if number of dependent constants of a Base is less " "than this number."), cl::init(0), cl::Hidden) ( "consthoist-min-num-to-rebase"  ,
cl::desc("Do not rebase if number of dependent constants of a Base is less " "than this number.")  ,
cl::init(0)  ,
cl::Hidden   
)
static