LLVM 20.0.0git
Macros | Typedefs | Functions | Variables
HotColdSplitting.cpp File Reference

The goal of hot/cold splitting is to improve the memory locality of code. More...

#include "llvm/Transforms/IPO/HotColdSplitting.h"
#include "llvm/ADT/PostOrderIterator.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/AssumptionCache.h"
#include "llvm/Analysis/BlockFrequencyInfo.h"
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
#include "llvm/Analysis/PostDominators.h"
#include "llvm/Analysis/ProfileSummaryInfo.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CFG.h"
#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/EHPersonalities.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/PassManager.h"
#include "llvm/IR/ProfDataUtils.h"
#include "llvm/IR/User.h"
#include "llvm/IR/Value.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/IPO.h"
#include "llvm/Transforms/Utils/CodeExtractor.h"
#include <cassert>
#include <limits>
#include <string>

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "hotcoldsplit"
 

Typedefs

using BlockTy = std::pair< BasicBlock *, unsigned >
 A pair of (basic block, score).
 

Functions

 STATISTIC (NumColdRegionsFound, "Number of cold regions found.")
 
 STATISTIC (NumColdRegionsOutlined, "Number of cold regions outlined.")
 
static InstructionCost getOutliningBenefit (ArrayRef< BasicBlock * > Region, TargetTransformInfo &TTI)
 Get the benefit score of outlining Region.
 
static int getOutliningPenalty (ArrayRef< BasicBlock * > Region, unsigned NumInputs, unsigned NumOutputs)
 Get the penalty score for outlining Region.
 

Variables

static cl::opt< boolEnableStaticAnalysis ("hot-cold-static-analysis", cl::init(true), cl::Hidden)
 
static cl::opt< int > SplittingThreshold ("hotcoldsplit-threshold", cl::init(2), cl::Hidden, cl::desc("Base penalty for splitting cold code (as a " "multiple of TCC_Basic)"))
 
static cl::opt< boolEnableColdSection ("enable-cold-section", cl::init(false), cl::Hidden, cl::desc("Enable placement of extracted cold functions" " into a separate section after hot-cold splitting."))
 
static cl::opt< std::string > ColdSectionName ("hotcoldsplit-cold-section-name", cl::init("__llvm_cold"), cl::Hidden, cl::desc("Name for the section containing cold functions " "extracted by hot-cold splitting."))
 
static cl::opt< int > MaxParametersForSplit ("hotcoldsplit-max-params", cl::init(4), cl::Hidden, cl::desc("Maximum number of parameters for a split function"))
 
static cl::opt< int > ColdBranchProbDenom ("hotcoldsplit-cold-probability-denom", cl::init(100), cl::Hidden, cl::desc("Divisor of cold branch probability." "BranchProbability = 1/ColdBranchProbDenom"))
 

Detailed Description

The goal of hot/cold splitting is to improve the memory locality of code.

The splitting pass does this by identifying cold blocks and moving them into separate functions.

When the splitting pass finds a cold block (referred to as "the sink"), it grows a maximal cold region around that block. The maximal region contains all blocks (post-)dominated by the sink [*]. In theory, these blocks are as cold as the sink. Once a region is found, it's split out of the original function provided it's profitable to do so.

[*] In practice, there is some added complexity because some blocks are not safe to extract.

TODO: Use the PM to get domtrees, and preserve BFI/BPI. TODO: Reorder outlined functions.

Definition in file HotColdSplitting.cpp.

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "hotcoldsplit"

Definition at line 60 of file HotColdSplitting.cpp.

Typedef Documentation

◆ BlockTy

using BlockTy = std::pair<BasicBlock *, unsigned>

A pair of (basic block, score).

Definition at line 456 of file HotColdSplitting.cpp.

Function Documentation

◆ getOutliningBenefit()

static InstructionCost getOutliningBenefit ( ArrayRef< BasicBlock * >  Region,
TargetTransformInfo TTI 
)
static

◆ getOutliningPenalty()

static int getOutliningPenalty ( ArrayRef< BasicBlock * >  Region,
unsigned  NumInputs,
unsigned  NumOutputs 
)
static

◆ STATISTIC() [1/2]

STATISTIC ( NumColdRegionsFound  ,
"Number of cold regions found."   
)

◆ STATISTIC() [2/2]

STATISTIC ( NumColdRegionsOutlined  ,
"Number of cold regions outlined."   
)

Variable Documentation

◆ ColdBranchProbDenom

cl::opt< int > ColdBranchProbDenom("hotcoldsplit-cold-probability-denom", cl::init(100), cl::Hidden, cl::desc("Divisor of cold branch probability." "BranchProbability = 1/ColdBranchProbDenom")) ( "hotcoldsplit-cold-probability-denom"  ,
cl::init(100)  ,
cl::Hidden  ,
cl::desc("Divisor of cold branch probability." "BranchProbability = 1/ColdBranchProbDenom")   
)
static

◆ ColdSectionName

cl::opt< std::string > ColdSectionName("hotcoldsplit-cold-section-name", cl::init("__llvm_cold"), cl::Hidden, cl::desc("Name for the section containing cold functions " "extracted by hot-cold splitting.")) ( "hotcoldsplit-cold-section-name"  ,
cl::init("__llvm_cold")  ,
cl::Hidden  ,
cl::desc("Name for the section containing cold functions " "extracted by hot-cold splitting.")   
)
static

◆ EnableColdSection

cl::opt< bool > EnableColdSection("enable-cold-section", cl::init(false), cl::Hidden, cl::desc("Enable placement of extracted cold functions" " into a separate section after hot-cold splitting.")) ( "enable-cold-section"  ,
cl::init(false)  ,
cl::Hidden  ,
cl::desc("Enable placement of extracted cold functions" " into a separate section after hot-cold splitting.")   
)
static

◆ EnableStaticAnalysis

cl::opt< bool > EnableStaticAnalysis("hot-cold-static-analysis", cl::init(true), cl::Hidden) ( "hot-cold-static-analysis"  ,
cl::init(true ,
cl::Hidden   
)
static

◆ MaxParametersForSplit

cl::opt< int > MaxParametersForSplit("hotcoldsplit-max-params", cl::init(4), cl::Hidden, cl::desc("Maximum number of parameters for a split function")) ( "hotcoldsplit-max-params"  ,
cl::init(4)  ,
cl::Hidden  ,
cl::desc("Maximum number of parameters for a split function")   
)
static

Referenced by getOutliningPenalty().

◆ SplittingThreshold

cl::opt< int > SplittingThreshold("hotcoldsplit-threshold", cl::init(2), cl::Hidden, cl::desc("Base penalty for splitting cold code (as a " "multiple of TCC_Basic)")) ( "hotcoldsplit-threshold"  ,
cl::init(2)  ,
cl::Hidden  ,
cl::desc("Base penalty for splitting cold code (as a " "multiple of TCC_Basic)")   
)
static

Referenced by getOutliningPenalty().