LLVM  8.0.1
Namespaces | Macros | Functions | Variables
ControlHeightReduction.cpp File Reference
#include "llvm/Transforms/Instrumentation/ControlHeightReduction.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/Analysis/BlockFrequencyInfo.h"
#include "llvm/Analysis/GlobalsModRef.h"
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
#include "llvm/Analysis/ProfileSummaryInfo.h"
#include "llvm/Analysis/RegionInfo.h"
#include "llvm/Analysis/RegionIterator.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/CFG.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/MDBuilder.h"
#include "llvm/Support/BranchProbability.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Transforms/Utils.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/Cloning.h"
#include "llvm/Transforms/Utils/ValueMapper.h"
#include <set>
#include <sstream>
Include dependency graph for ControlHeightReduction.cpp:

Go to the source code of this file.

Namespaces

 llvm
 This class represents lattice values for constants.
 

Macros

#define DEBUG_TYPE   "chr"
 
#define CHR_DEBUG(X)   LLVM_DEBUG(X)
 

Functions

static void parseCHRFilterFiles ()
 
 INITIALIZE_PASS_BEGIN (ControlHeightReductionLegacyPass, "chr", "Reduce control height in the hot paths", false, false) INITIALIZE_PASS_END(ControlHeightReductionLegacyPass
 
static raw_ostream LLVM_ATTRIBUTE_UNUSEDoperator<< (raw_ostream &OS, const CHRStats &Stats)
 
static raw_ostreamoperator<< (raw_ostream &OS, const CHRScope &Scope)
 
static bool shouldApply (Function &F, ProfileSummaryInfo &PSI)
 
static void LLVM_ATTRIBUTE_UNUSED dumpIR (Function &F, const char *Label, CHRStats *Stats)
 
static bool isHoistableInstructionType (Instruction *I)
 
static bool isHoistable (Instruction *I, DominatorTree &DT)
 
static std::set< Value * > getBaseValues (Value *V, DominatorTree &DT)
 
static bool checkHoistValue (Value *V, Instruction *InsertPoint, DominatorTree &DT, DenseSet< Instruction *> &Unhoistables, DenseSet< Instruction *> *HoistStops)
 
static bool checkMDProf (MDNode *MD, BranchProbability &TrueProb, BranchProbability &FalseProb)
 
static BranchProbability getCHRBiasThreshold ()
 
template<typename K , typename S , typename M >
static bool checkBias (K *Key, BranchProbability TrueProb, BranchProbability FalseProb, S &TrueSet, S &FalseSet, M &BiasMap)
 
static bool checkBiasedBranch (BranchInst *BI, Region *R, DenseSet< Region *> &TrueBiasedRegionsGlobal, DenseSet< Region *> &FalseBiasedRegionsGlobal, DenseMap< Region *, BranchProbability > &BranchBiasMap)
 
static bool checkBiasedSelect (SelectInst *SI, Region *R, DenseSet< SelectInst *> &TrueBiasedSelectsGlobal, DenseSet< SelectInst *> &FalseBiasedSelectsGlobal, DenseMap< SelectInst *, BranchProbability > &SelectBiasMap)
 
static InstructiongetBranchInsertPoint (RegInfo &RI)
 
static DenseSet< Value * > getCHRConditionValuesForRegion (RegInfo &RI)
 
static bool shouldSplit (Instruction *InsertPoint, DenseSet< Value *> &PrevConditionValues, DenseSet< Value *> &ConditionValues, DominatorTree &DT, DenseSet< Instruction *> &Unhoistables)
 
static void getSelectsInScope (CHRScope *Scope, DenseSet< Instruction *> &Output)
 
static bool hasAtLeastTwoBiasedBranches (CHRScope *Scope)
 
bool CHRScopeSorter (CHRScope *Scope1, CHRScope *Scope2)
 
static void hoistValue (Value *V, Instruction *HoistPoint, Region *R, HoistStopMapTy &HoistStopMap, DenseSet< Instruction *> &HoistedSet, DenseSet< PHINode *> &TrivialPHIs)
 
static void hoistScopeConditions (CHRScope *Scope, Instruction *HoistPoint, DenseSet< PHINode *> &TrivialPHIs)
 
static bool negateICmpIfUsedByBranchOrSelectOnly (ICmpInst *ICmp, Instruction *ExcludedUser, CHRScope *Scope)
 
static void insertTrivialPHIs (CHRScope *Scope, BasicBlock *EntryBlock, BasicBlock *ExitBlock, DenseSet< PHINode *> &TrivialPHIs)
 
static void LLVM_ATTRIBUTE_UNUSED assertCHRRegionsHaveBiasedBranchOrSelect (CHRScope *Scope)
 
static void LLVM_ATTRIBUTE_UNUSED assertBranchOrSelectConditionHoisted (CHRScope *Scope, BasicBlock *PreEntryBlock)
 
static void LLVM_ATTRIBUTE_UNUSED dumpScopes (SmallVectorImpl< CHRScope *> &Scopes, const char *Label)
 

Variables

static cl::opt< boolForceCHR ("force-chr", cl::init(false), cl::Hidden, cl::desc("Apply CHR for all functions"))
 
static cl::opt< double > CHRBiasThreshold ("chr-bias-threshold", cl::init(0.99), cl::Hidden, cl::desc("CHR considers a branch bias greater than this ratio as biased"))
 
static cl::opt< unsignedCHRMergeThreshold ("chr-merge-threshold", cl::init(2), cl::Hidden, cl::desc("CHR merges a group of N branches/selects where N >= this value"))
 
static cl::opt< std::string > CHRModuleList ("chr-module-list", cl::init(""), cl::Hidden, cl::desc("Specify file to retrieve the list of modules to apply CHR to"))
 
static cl::opt< std::string > CHRFunctionList ("chr-function-list", cl::init(""), cl::Hidden, cl::desc("Specify file to retrieve the list of functions to apply CHR to"))
 
static StringSet CHRModules
 
static StringSet CHRFunctions
 
 chr
 
Reduce control height in the hot paths
 
Reduce control height in the hot false
 

Macro Definition Documentation

◆ CHR_DEBUG

#define CHR_DEBUG (   X)    LLVM_DEBUG(X)

◆ DEBUG_TYPE

#define DEBUG_TYPE   "chr"

Function Documentation

◆ assertBranchOrSelectConditionHoisted()

static void LLVM_ATTRIBUTE_UNUSED assertBranchOrSelectConditionHoisted ( CHRScope *  Scope,
BasicBlock PreEntryBlock 
)
static

Definition at line 1624 of file ControlHeightReduction.cpp.

References assert(), assertCHRRegionsHaveBiasedBranchOrSelect(), llvm::AMDGPUISD::BFI, CHR_DEBUG, llvm::CloneBasicBlock(), llvm::RegionBase< Tr >::contains(), llvm::BranchInst::Create(), llvm::IRBuilder< T, Inserter >::CreateAnd(), llvm::IRBuilder< T, Inserter >::CreateXor(), llvm::dbgs(), DEBUG_TYPE, llvm::User::dropAllReferences(), dumpIR(), llvm::ValueMap< KeyT, ValueT, Config >::end(), llvm::Instruction::eraseFromParent(), F(), llvm::ValueMap< KeyT, ValueT, Config >::find(), getCHRBiasThreshold(), llvm::SelectInst::getCondition(), llvm::RegionBase< Tr >::getEntry(), llvm::RegionBase< Tr >::getExit(), llvm::ConstantInt::getFalse(), llvm::BasicBlock::getInstList(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::Value::getName(), llvm::BasicBlock::getSinglePredecessor(), llvm::BranchInst::getSuccessor(), llvm::BasicBlock::getTerminator(), llvm::ConstantInt::getTrue(), llvm::Optional< T >::getValue(), hoistScopeConditions(), I, insertTrivialPHIs(), llvm::BranchInst::isUnconditional(), LLVM_ATTRIBUTE_UNUSED, llvm::LLVMContext::MD_prof, negateICmpIfUsedByBranchOrSelectOnly(), llvm::BasicBlock::phis(), llvm::SmallVectorTemplateBase< T >::push_back(), llvm::iplist_impl< IntrusiveListT, TraitsT >::push_back(), llvm::RemapInstruction(), llvm::RF_IgnoreMissingLocals, llvm::RF_NoModuleLevelChanges, llvm::SelectInst::setCondition(), llvm::BranchInst::setCondition(), llvm::Instruction::setMetadata(), SI, llvm::SmallVectorBase::size(), llvm::SplitBlock(), Stats, and std::swap().

◆ assertCHRRegionsHaveBiasedBranchOrSelect()

static void LLVM_ATTRIBUTE_UNUSED assertCHRRegionsHaveBiasedBranchOrSelect ( CHRScope *  Scope)
static

Definition at line 1603 of file ControlHeightReduction.cpp.

References assert(), and SI.

Referenced by assertBranchOrSelectConditionHoisted().

◆ checkBias()

template<typename K , typename S , typename M >
static bool checkBias ( K *  Key,
BranchProbability  TrueProb,
BranchProbability  FalseProb,
S &  TrueSet,
S &  FalseSet,
M &  BiasMap 
)
static

Definition at line 625 of file ControlHeightReduction.cpp.

References getCHRBiasThreshold(), and Threshold.

Referenced by checkBiasedBranch(), and checkBiasedSelect().

◆ checkBiasedBranch()

static bool checkBiasedBranch ( BranchInst BI,
Region R,
DenseSet< Region *> &  TrueBiasedRegionsGlobal,
DenseSet< Region *> &  FalseBiasedRegionsGlobal,
DenseMap< Region *, BranchProbability > &  BranchBiasMap 
)
static

◆ checkBiasedSelect()

static bool checkBiasedSelect ( SelectInst SI,
Region R,
DenseSet< SelectInst *> &  TrueBiasedSelectsGlobal,
DenseSet< SelectInst *> &  FalseBiasedSelectsGlobal,
DenseMap< SelectInst *, BranchProbability > &  SelectBiasMap 
)
static

◆ checkHoistValue()

static bool checkHoistValue ( Value V,
Instruction InsertPoint,
DominatorTree DT,
DenseSet< Instruction *> &  Unhoistables,
DenseSet< Instruction *> *  HoistStops 
)
static

◆ checkMDProf()

static bool checkMDProf ( MDNode MD,
BranchProbability TrueProb,
BranchProbability FalseProb 
)
static

◆ CHRScopeSorter()

bool CHRScopeSorter ( CHRScope *  Scope1,
CHRScope *  Scope2 
)

◆ dumpIR()

static void LLVM_ATTRIBUTE_UNUSED dumpIR ( Function F,
const char Label,
CHRStats *  Stats 
)
static

◆ dumpScopes()

static void LLVM_ATTRIBUTE_UNUSED dumpScopes ( SmallVectorImpl< CHRScope *> &  Scopes,
const char Label 
)
static

◆ getBaseValues()

static std::set<Value *> getBaseValues ( Value V,
DominatorTree DT 
)
static

Definition at line 516 of file ControlHeightReduction.cpp.

References I, and isHoistable().

Referenced by shouldSplit().

◆ getBranchInsertPoint()

static Instruction* getBranchInsertPoint ( RegInfo &  RI)
static

◆ getCHRBiasThreshold()

static BranchProbability getCHRBiasThreshold ( )
static

◆ getCHRConditionValuesForRegion()

static DenseSet<Value *> getCHRConditionValuesForRegion ( RegInfo &  RI)
static

◆ getSelectsInScope()

static void getSelectsInScope ( CHRScope *  Scope,
DenseSet< Instruction *> &  Output 
)
static

◆ hasAtLeastTwoBiasedBranches()

static bool hasAtLeastTwoBiasedBranches ( CHRScope *  Scope)
static

◆ hoistScopeConditions()

static void hoistScopeConditions ( CHRScope *  Scope,
Instruction HoistPoint,
DenseSet< PHINode *> &  TrivialPHIs 
)
static

◆ hoistValue()

static void hoistValue ( Value V,
Instruction HoistPoint,
Region R,
HoistStopMapTy &  HoistStopMap,
DenseSet< Instruction *> &  HoistedSet,
DenseSet< PHINode *> &  TrivialPHIs 
)
static

◆ INITIALIZE_PASS_BEGIN()

INITIALIZE_PASS_BEGIN ( ControlHeightReductionLegacyPass  ,
"chr"  ,
"Reduce control height in the hot paths ,
false  ,
false   
)

Referenced by parseCHRFilterFiles().

◆ insertTrivialPHIs()

static void insertTrivialPHIs ( CHRScope *  Scope,
BasicBlock EntryBlock,
BasicBlock ExitBlock,
DenseSet< PHINode *> &  TrivialPHIs 
)
static

◆ isHoistable()

static bool isHoistable ( Instruction I,
DominatorTree DT 
)
static

◆ isHoistableInstructionType()

static bool isHoistableInstructionType ( Instruction I)
static

Definition at line 496 of file ControlHeightReduction.cpp.

References I.

Referenced by hoistValue(), and isHoistable().

◆ negateICmpIfUsedByBranchOrSelectOnly()

static bool negateICmpIfUsedByBranchOrSelectOnly ( ICmpInst ICmp,
Instruction ExcludedUser,
CHRScope *  Scope 
)
static

◆ operator<<() [1/2]

static raw_ostream LLVM_ATTRIBUTE_UNUSED& operator<< ( raw_ostream OS,
const CHRStats &  Stats 
)
inlinestatic

Definition at line 430 of file ControlHeightReduction.cpp.

◆ operator<<() [2/2]

static raw_ostream& operator<< ( raw_ostream OS,
const CHRScope &  Scope 
)
inlinestatic

Definition at line 437 of file ControlHeightReduction.cpp.

◆ parseCHRFilterFiles()

static void parseCHRFilterFiles ( )
static

◆ shouldApply()

static bool shouldApply ( Function F,
ProfileSummaryInfo PSI 
)
static

◆ shouldSplit()

static bool shouldSplit ( Instruction InsertPoint,
DenseSet< Value *> &  PrevConditionValues,
DenseSet< Value *> &  ConditionValues,
DominatorTree DT,
DenseSet< Instruction *> &  Unhoistables 
)
static

Variable Documentation

◆ chr

chr

Definition at line 135 of file ControlHeightReduction.cpp.

◆ CHRBiasThreshold

cl::opt<double> CHRBiasThreshold("chr-bias-threshold", cl::init(0.99), cl::Hidden, cl::desc("CHR considers a branch bias greater than this ratio as biased"))
static

Referenced by getCHRBiasThreshold().

◆ CHRFunctionList

cl::opt<std::string> CHRFunctionList("chr-function-list", cl::init(""), cl::Hidden, cl::desc("Specify file to retrieve the list of functions to apply CHR to"))
static

Referenced by parseCHRFilterFiles(), and shouldApply().

◆ CHRFunctions

StringSet CHRFunctions
static

Definition at line 67 of file ControlHeightReduction.cpp.

Referenced by shouldApply().

◆ CHRMergeThreshold

cl::opt<unsigned> CHRMergeThreshold("chr-merge-threshold", cl::init(2), cl::Hidden, cl::desc("CHR merges a group of N branches/selects where N >= this value"))
static

◆ CHRModuleList

cl::opt<std::string> CHRModuleList("chr-module-list", cl::init(""), cl::Hidden, cl::desc("Specify file to retrieve the list of modules to apply CHR to"))
static

Referenced by parseCHRFilterFiles(), and shouldApply().

◆ CHRModules

StringSet CHRModules
static

Definition at line 66 of file ControlHeightReduction.cpp.

Referenced by shouldApply().

◆ false

Reduce control height in the hot false

Definition at line 135 of file ControlHeightReduction.cpp.

◆ ForceCHR

cl::opt<bool> ForceCHR("force-chr", cl::init(false), cl::Hidden, cl::desc("Apply CHR for all functions"))
static

Referenced by shouldApply().

◆ paths

Reduce control height in the hot paths

Definition at line 135 of file ControlHeightReduction.cpp.