37#define DEBUG_TYPE "static-data-splitter"
39STATISTIC(NumHotJumpTables,
"Number of hot jump tables seen.");
40STATISTIC(NumColdJumpTables,
"Number of cold jump tables seen.");
42 "Number of jump tables with unknown hotness. They are from functions "
43 "without profile information.");
106 .getStaticDataProfileInfo();
108 const bool ProfileAvailable = PSI && PSI->hasProfileSummary() && MBFI &&
111 if (!ProfileAvailable) {
112 annotateStaticDataWithoutProfiles(MF);
113 updateStatsWithoutProfiles(MF);
117 bool Changed = partitionStaticDataWithProfiles(MF);
119 updateStatsWithProfiles(MF);
127 if (!
Op.isGlobal() && !
Op.isCPI())
137 !inStaticDataSection(*GV, TM))
141 assert(
Op.isCPI() &&
"Op must be constant pool index in this branch");
142 int CPI =
Op.getIndex();
146 assert(MCP !=
nullptr &&
"Constant pool info is not available.");
147 const MachineConstantPoolEntry &CPE = MCP->
getConstants()[CPI];
155bool StaticDataSplitter::partitionStaticDataWithProfiles(
MachineFunction &MF) {
173 for (
const auto &
MBB : MF) {
174 std::optional<uint64_t>
Count = MBFI->getBlockProfileCount(&
MBB);
175 for (
const MachineInstr &
I :
MBB) {
176 for (
const MachineOperand &
Op :
I.operands()) {
177 if (!
Op.isJTI() && !
Op.isGlobal() && !
Op.isCPI())
181 assert(MJTI !=
nullptr &&
"Jump table info is not available.");
182 const int JTI =
Op.getIndex();
187 auto Hotness = MachineFunctionDataHotness::Hot;
193 Hotness = MachineFunctionDataHotness::Cold;
196 }
else if (
const Constant *
C =
197 getConstant(
Op, MF.getTarget(), MF.getConstantPool())) {
198 SDPI->addConstantProfileCount(
C,
Count);
208StaticDataSplitter::getLocalLinkageGlobalVariable(
const GlobalValue *GV) {
215bool StaticDataSplitter::inStaticDataSection(
const GlobalVariable &GV,
219 return Kind.isData() || Kind.isReadOnly() || Kind.isReadOnlyWithRel() ||
223void StaticDataSplitter::updateStatsWithProfiles(
const MachineFunction &MF) {
229 if (
JumpTable.Hotness == MachineFunctionDataHotness::Hot) {
233 "A jump table is either hot or cold when profile information is "
241void StaticDataSplitter::annotateStaticDataWithoutProfiles(
243 for (
const auto &
MBB : MF)
244 for (
const MachineInstr &
I :
MBB)
245 for (
const MachineOperand &
Op :
I.operands())
246 if (
const Constant *
C =
247 getConstant(
Op, MF.getTarget(), MF.getConstantPool()))
248 SDPI->addConstantProfileCount(
C, std::nullopt);
251void StaticDataSplitter::updateStatsWithoutProfiles(
const MachineFunction &MF) {
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
void setPreservesAll()
Set by analyses that do not transform their input at all.
This is an important base class in LLVM.
bool hasProfileData(bool IncludeSynthetic=false) const
Return true if the function is annotated with profile data.
bool hasLocalLinkage() const
MachineBlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate machine basic b...
union llvm::MachineConstantPoolEntry::@004270020304201266316354007027341142157160323045 Val
The constant itself.
bool isMachineConstantPoolEntry() const
isMachineConstantPoolEntry - Return true if the MachineConstantPoolEntry is indeed a target specific ...
const Constant * ConstVal
The MachineConstantPool class keeps track of constants referenced by a function which must be spilled...
const std::vector< MachineConstantPoolEntry > & getConstants() const
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
MachineFunctionPass(char &ID)
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Function & getFunction()
Return the LLVM function that this machine code represents.
const MachineJumpTableInfo * getJumpTableInfo() const
getJumpTableInfo - Return the jump table info object for the current function.
LLVM_ABI bool updateJumpTableEntryHotness(size_t JTI, MachineFunctionDataHotness Hotness)
const std::vector< MachineJumpTableEntry > & getJumpTables() const
MachineOperand class - Representation of each machine instruction operand.
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
AnalysisType & getAnalysis() const
getAnalysis<AnalysisType>() - This function is used by subclasses to get to the analysis information ...
An analysis pass based on legacy pass manager to deliver ProfileSummaryInfo.
Analysis providing profile information.
This wraps the StaticDataProfileInfo object as an immutable pass, for a backend pass to operate on.
A class that holds the constants that represent static data and their profile information and provide...
StringRef - Represent a constant reference to a string, i.e.
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
static SectionKind getKindForGlobal(const GlobalObject *GO, const TargetMachine &TM)
Classify the specified global variable into a set of target independent categories embodied in Sectio...
Primary interface to the complete machine description for the target machine.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI void initializeStaticDataSplitterPass(PassRegistry &)
LLVM_ABI MachineFunctionPass * createStaticDataSplitterPass()
createStaticDataSplitterPass - This is a machine-function pass that categorizes static data hotness u...
FunctionAddr VTableAddr Count
LLVM_ABI bool AreStatisticsEnabled()
Check if statistics are enabled.
DWARFExpression::Operation Op