LLVM  9.0.0svn
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/None.h"
#include "llvm/ADT/Optional.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/Transforms/Utils/Local.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Constants.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/Value.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/SizeOpts.h"
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <iterator>
#include <tuple>
#include <utility>
Include dependency graph for ConstantHoisting.cpp:

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, SmallPtrSet< BasicBlock *, 8 > &BBs)
 Given BBs as input, find another set of BBs which collectively dominates BBs and have the minimal sum of frequencies. More...
 
static 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. More...
 

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 75 of file ConstantHoisting.cpp.

Function Documentation

◆ calculateOffsetDiff()

static Optional<APInt> calculateOffsetDiff ( const APInt V1,
const APInt V2 
)
static

◆ findBestInsertionSet()

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

Given BBs as input, find another set of BBs which collectively dominates BBs and have the minimal sum of frequencies.

Return the BB set found in BBs.

Definition at line 205 of file ConstantHoisting.cpp.

References assert(), llvm::SmallPtrSetImplBase::clear(), llvm::SmallPtrSetImpl< PtrType >::count(), and llvm::DominatorTree::isReachableFromEntry().

◆ 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 form 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 706 of file ConstantHoisting.cpp.

References llvm::MCID::Add, assert(), llvm::consthoist::ConstantInfo::BaseExpr, llvm::consthoist::ConstantInfo::BaseInt, llvm::Instruction::clone(), llvm::BinaryOperator::Create(), llvm::GetElementPtrInst::Create(), llvm::dbgs(), llvm::SmallPtrSetImplBase::empty(), llvm::Instruction::eraseFromParent(), llvm::ConstantInt::get(), llvm::ConstantExpr::getAsInstruction(), llvm::Instruction::getDebugLoc(), llvm::PointerType::getElementType(), llvm::Type::getInt32Ty(), llvm::Type::getInt8PtrTy(), llvm::DILocation::getMergedLocation(), llvm::Value::getName(), llvm::User::getOperand(), llvm::Instruction::getParent(), llvm::BasicBlock::getParent(), llvm::ConstantInt::getType(), llvm::Value::getType(), I, llvm::consthoist::ConstantUser::Inst, llvm::Instruction::isCast(), llvm::ConstantExpr::isCast(), llvm::ConstantExpr::isGEPWithNoNotionalOverIndexing(), LLVM_DEBUG, MinNumOfDependentToRebase, llvm::consthoist::ConstantUser::OpndIdx, llvm::SmallVectorTemplateBase< T >::push_back(), llvm::consthoist::ConstantInfo::RebasedConstants, llvm::Instruction::setDebugLoc(), llvm::User::setOperand(), llvm::SmallVectorBase::size(), llvm::Value::use_empty(), and llvm::Instruction::user_back().

Variable Documentation

◆ consthoist

consthoist

Definition at line 134 of file ConstantHoisting.cpp.

◆ ConstHoistGEP

cl::opt<bool> ConstHoistGEP("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."))
static

◆ false

Constant false

Definition at line 134 of file ConstantHoisting.cpp.

◆ Hoisting

Constant Hoisting

Definition at line 134 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)
static

Referenced by updateOperand().