41#define DEBUG_TYPE "static-data-splitter"
43STATISTIC(NumHotJumpTables,
"Number of hot jump tables seen.");
44STATISTIC(NumColdJumpTables,
"Number of cold jump tables seen.");
46 "Number of jump tables with unknown hotness. They are from functions "
47 "without profile information.");
82 : MBFI(MBFI), PSI(PSI), SDPI(SDPI) {}
110 const bool ProfileAvailable = PSI && PSI->hasProfileSummary() && MBFI &&
113 if (!ProfileAvailable) {
114 annotateStaticDataWithoutProfiles(MF);
115 updateStatsWithoutProfiles(MF);
119 bool Changed = partitionStaticDataWithProfiles(MF);
121 updateStatsWithProfiles(MF);
129 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 StaticDataSplitterImpl::partitionStaticDataWithProfiles(
174 for (
const auto &
MBB : MF) {
175 std::optional<uint64_t>
Count = MBFI->getBlockProfileCount(&
MBB);
176 for (
const MachineInstr &
I :
MBB) {
177 for (
const MachineOperand &
Op :
I.operands()) {
178 if (!
Op.isJTI() && !
Op.isGlobal() && !
Op.isCPI())
182 assert(MJTI !=
nullptr &&
"Jump table info is not available.");
183 const int JTI =
Op.getIndex();
188 auto Hotness = MachineFunctionDataHotness::Hot;
194 Hotness = MachineFunctionDataHotness::Cold;
197 }
else if (
const Constant *
C =
198 getConstant(
Op, MF.getTarget(), MF.getConstantPool())) {
199 SDPI->addConstantProfileCount(
C,
Count);
209StaticDataSplitterImpl::getLocalLinkageGlobalVariable(
const GlobalValue *GV) {
216bool StaticDataSplitterImpl::inStaticDataSection(
const GlobalVariable &GV,
220 return Kind.isData() ||
Kind.isReadOnly() ||
Kind.isReadOnlyWithRel() ||
224void StaticDataSplitterImpl::updateStatsWithProfiles(
231 if (
JumpTable.Hotness == MachineFunctionDataHotness::Hot) {
235 "A jump table is either hot or cold when profile information is "
243void StaticDataSplitterImpl::annotateStaticDataWithoutProfiles(
245 for (
const auto &
MBB : MF)
246 for (
const MachineInstr &
I :
MBB)
247 for (
const MachineOperand &
Op :
I.operands())
248 if (
const Constant *
C =
249 getConstant(
Op, MF.getTarget(), MF.getConstantPool()))
250 SDPI->addConstantProfileCount(
C, std::nullopt);
253void StaticDataSplitterImpl::updateStatsWithoutProfiles(
284 .getStaticDataProfileInfo();
286 return Impl.runOnMachineFunction(MF);
294 auto &ModuleAnalysisManagerProxy =
300 &ModuleAnalysisManagerProxy
303 ->getStaticDataProfileInfo();
305 return Impl.runOnMachineFunction(MF)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static const Function * getParent(const Value *V)
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
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)
bool runOnMachineFunction(MachineFunction &MF)
StaticDataSplitterImpl(MachineBlockFrequencyInfo *MBFI, ProfileSummaryInfo *PSI, StaticDataProfileInfo *SDPI)
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
StaticDataSplitterLegacy()
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
void setPreservesAll()
Set by analyses that do not transform their input at all.
Represents analyses that only rely on functions' control flow.
This is an important base class in LLVM.
bool hasProfileData() 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.
AnalysisType & getAnalysis() const
getAnalysis<AnalysisType>() - This function is used by subclasses to get to the analysis information ...
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
An analysis pass based on the new PM to deliver ProfileSummaryInfo.
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...
LLVM_ABI PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
Represent a constant reference to a string, i.e.
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.
Pass manager infrastructure for declaring and invalidating analyses.
LLVM_ABI bool IsAnnotationOK(const GlobalVariable &GV)
Returns true if the annotation kind of the global variable GV is AnnotationOK.
This is an optimization pass for GlobalISel generic memory operations.
OuterAnalysisManagerProxy< ModuleAnalysisManager, MachineFunction > ModuleAnalysisManagerMachineFunctionProxy
Provide the ModuleAnalysisManager to Function proxy.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
LLVM_ABI bool AreStatisticsEnabled()
Check if statistics are enabled.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
DWARFExpression::Operation Op
LLVM_ABI MachineFunctionPass * createStaticDataSplitterLegacyPass()
createStaticDataSplitterPass - This is a machine-function pass that categorizes static data hotness u...