LLVM  7.0.0
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/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 <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< APInt > calculateOffsetDiff (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< 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
 
Constant Hoisting
 
Constant false
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "consthoist"

Definition at line 74 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 193 of file ConstantHoisting.cpp.

References assert(), llvm::BasicBlock::begin(), llvm::SmallPtrSetImpl< PtrType >::begin(), llvm::AMDGPUISD::BFI, llvm::canReplaceOperandWithVariable(), llvm::SmallPtrSetImplBase::clear(), llvm::DenseMapBase< DenseMap< KeyT, ValueT, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::clear(), llvm::SmallPtrSetImpl< PtrType >::count(), llvm::dbgs(), E, llvm::SmallVectorBase::empty(), llvm::SmallPtrSetImpl< PtrType >::end(), llvm::SmallPtrSetImpl< PtrType >::erase(), llvm::DomTreeNodeBase< NodeT >::getBlock(), llvm::BlockFrequencyInfo::getBlockFreq(), llvm::DomTreeNodeBase< NodeT >::getChildren(), llvm::DomTreeNodeBase< NodeT >::getIDom(), llvm::DominatorTreeBase< NodeT, IsPostDom >::getNode(), llvm::User::getNumOperands(), llvm::Instruction::getOpcode(), llvm::User::getOperand(), llvm::ConstantInt::getType(), llvm::ConstantInt::getValue(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::Instruction::isCast(), llvm::BasicBlock::isEHPad(), LLVM_DEBUG, llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), llvm::SmallVectorTemplateCommon< T >::rbegin(), llvm::consthoist::ConstantInfo::RebasedConstants, llvm::SmallVectorTemplateCommon< T >::rend(), llvm::DenseMapBase< DenseMap< KeyT, ValueT, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::reserve(), llvm::SmallVectorBase::size(), llvm::SmallPtrSetImplBase::size(), and llvm::TargetTransformInfo::TCC_Basic.

◆ 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

Variable Documentation

◆ consthoist

consthoist

Definition at line 123 of file ConstantHoisting.cpp.

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

◆ Hoisting

Constant Hoisting

Definition at line 123 of file ConstantHoisting.cpp.