LLVM 20.0.0git
|
#include "llvm/CodeGen/SelectOptimize.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/BlockFrequencyInfo.h"
#include "llvm/Analysis/BranchProbabilityInfo.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
#include "llvm/Analysis/ProfileSummaryInfo.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/CodeGen/Passes.h"
#include "llvm/CodeGen/TargetLowering.h"
#include "llvm/CodeGen/TargetPassConfig.h"
#include "llvm/CodeGen/TargetSchedule.h"
#include "llvm/CodeGen/TargetSubtargetInfo.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/PatternMatch.h"
#include "llvm/IR/ProfDataUtils.h"
#include "llvm/InitializePasses.h"
#include "llvm/Pass.h"
#include "llvm/Support/ScaledNumber.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Transforms/Utils/SizeOpts.h"
#include <algorithm>
#include <queue>
#include <stack>
Go to the source code of this file.
Macros | |
#define | DEBUG_TYPE "select-optimize" |
Functions | |
STATISTIC (NumSelectOptAnalyzed, "Number of select groups considered for conversion to branch") | |
STATISTIC (NumSelectConvertedExpColdOperand, "Number of select groups converted due to expensive cold operand") | |
STATISTIC (NumSelectConvertedHighPred, "Number of select groups converted due to high-predictability") | |
STATISTIC (NumSelectUnPred, "Number of select groups not converted due to unpredictability") | |
STATISTIC (NumSelectColdBB, "Number of select groups not converted due to cold basic block") | |
STATISTIC (NumSelectConvertedLoop, "Number of select groups converted due to loop-level analysis") | |
STATISTIC (NumSelectsConverted, "Number of selects converted") | |
INITIALIZE_PASS_BEGIN (SelectOptimize, DEBUG_TYPE, "Optimize selects", false, false) INITIALIZE_PASS_END(SelectOptimize | |
static Value * | getTrueOrFalseValue (SelectOptimizeImpl::SelectLike &SI, bool isTrue, SmallDenseMap< Instruction *, std::pair< Value *, Value * >, 2 > &OptSelects, BasicBlock *B) |
Returns optimised value on IsTrue branch. | |
static void | EmitAndPrintRemark (OptimizationRemarkEmitter *ORE, DiagnosticInfoOptimizationBase &Rem) |
static InstructionCost | divideNearest (InstructionCost Numerator, uint64_t Denominator) |
static bool | extractBranchWeights (const SelectOptimizeImpl::SelectLike SI, uint64_t &TrueVal, uint64_t &FalseVal) |
static bool | isSafeToSinkLoad (Instruction *LoadI, Instruction *SI) |
Variables | |
static cl::opt< unsigned > | ColdOperandThreshold ("cold-operand-threshold", cl::desc("Maximum frequency of path for an operand to be considered cold."), cl::init(20), cl::Hidden) |
static cl::opt< unsigned > | ColdOperandMaxCostMultiplier ("cold-operand-max-cost-multiplier", cl::desc("Maximum cost multiplier of TCC_expensive for the dependence " "slice of a cold operand to be considered inexpensive."), cl::init(1), cl::Hidden) |
static cl::opt< unsigned > | GainGradientThreshold ("select-opti-loop-gradient-gain-threshold", cl::desc("Gradient gain threshold (%)."), cl::init(25), cl::Hidden) |
static cl::opt< unsigned > | GainCycleThreshold ("select-opti-loop-cycle-gain-threshold", cl::desc("Minimum gain per loop (in cycles) threshold."), cl::init(4), cl::Hidden) |
static cl::opt< unsigned > | GainRelativeThreshold ("select-opti-loop-relative-gain-threshold", cl::desc("Minimum relative gain per loop threshold (1/X). Defaults to 12.5%"), cl::init(8), cl::Hidden) |
static cl::opt< unsigned > | MispredictDefaultRate ("mispredict-default-rate", cl::Hidden, cl::init(25), cl::desc("Default mispredict rate (initialized to 25%).")) |
static cl::opt< bool > | DisableLoopLevelHeuristics ("disable-loop-level-heuristics", cl::Hidden, cl::init(false), cl::desc("Disable loop-level heuristics.")) |
DEBUG_TYPE | |
Optimize | selects |
Optimize | false |
#define DEBUG_TYPE "select-optimize" |
Definition at line 47 of file SelectOptimize.cpp.
|
static |
Definition at line 1052 of file SelectOptimize.cpp.
|
static |
Definition at line 950 of file SelectOptimize.cpp.
References llvm::dbgs(), llvm::OptimizationRemarkEmitter::emit(), llvm::DiagnosticInfoOptimizationBase::getMsg(), and LLVM_DEBUG.
|
static |
Definition at line 1057 of file SelectOptimize.cpp.
References llvm::extractBranchWeights().
|
static |
Returns optimised value on IsTrue
branch.
For SelectInst that would be either True or False value. For (BinaryOperator) instructions, where the condition may be skipped, the operation will use a non-conditional operand. For example, for or(V,zext(cond))
this function would return V. However, if the conditional operand on IsTrue
branch matters, we create a clone of instruction at the end of that branch B
and replace the condition operand with a constant.
Also /p OptSelects contains previously optimised select-like instructions. If the current value uses one of the optimised values, we can optimise it further by replacing it with the corresponding value on the given branch
Definition at line 480 of file SelectOptimize.cpp.
INITIALIZE_PASS_BEGIN | ( | SelectOptimize | , |
DEBUG_TYPE | , | ||
"Optimize selects" | , | ||
false | , | ||
false | |||
) |
|
static |
Definition at line 1119 of file SelectOptimize.cpp.
References llvm::ilist_node_impl< OptionsT >::getIterator(), and llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent().
STATISTIC | ( | NumSelectColdBB | , |
"Number of select groups not converted due to cold basic block" | |||
) |
STATISTIC | ( | NumSelectConvertedExpColdOperand | , |
"Number of select groups converted due to expensive cold operand" | |||
) |
STATISTIC | ( | NumSelectConvertedHighPred | , |
"Number of select groups converted due to high-predictability" | |||
) |
STATISTIC | ( | NumSelectConvertedLoop | , |
"Number of select groups converted due to loop-level analysis" | |||
) |
STATISTIC | ( | NumSelectOptAnalyzed | , |
"Number of select groups considered for conversion to branch" | |||
) |
STATISTIC | ( | NumSelectsConverted | , |
"Number of selects converted" | |||
) |
STATISTIC | ( | NumSelectUnPred | , |
"Number of select groups not converted due to unpredictability" | |||
) |
|
static |
|
static |
DEBUG_TYPE |
Definition at line 347 of file SelectOptimize.cpp.
|
static |
Optimize false |
Definition at line 347 of file SelectOptimize.cpp.
|
static |
|
static |
|
static |
|
static |
Optimize selects |
Definition at line 347 of file SelectOptimize.cpp.