@@ -58,6 +58,12 @@ class StaticDataSplitter : public MachineFunctionPass {
5858 // .data.rel.ro} sections.
5959 bool inStaticDataSection (const GlobalVariable *GV, const TargetMachine &TM);
6060
61+ // Returns the constant if the operand refers to a global variable or constant
62+ // that gets lowered to static data sections. Otherwise, return nullptr.
63+ const Constant *getConstant (const MachineOperand &Op,
64+ const TargetMachine &TM,
65+ const MachineConstantPool *MCP);
66+
6167 // Use profiles to partition static data.
6268 bool partitionStaticDataWithProfiles (MachineFunction &MF);
6369
@@ -69,11 +75,6 @@ class StaticDataSplitter : public MachineFunctionPass {
6975
7076 void annotateStaticDataWithoutProfiles (const MachineFunction &MF);
7177
72- // Returns the constant if the operand refers to a global variable or constant
73- // that gets lowered to static data sections. Otherwise, return nullptr.
74- const Constant *getConstant (const MachineOperand &Op, const TargetMachine &TM,
75- const MachineConstantPool *MCP);
76-
7778public:
7879 static char ID;
7980
@@ -89,6 +90,11 @@ class StaticDataSplitter : public MachineFunctionPass {
8990 AU.addRequired <MachineBlockFrequencyInfoWrapperPass>();
9091 AU.addRequired <ProfileSummaryInfoWrapperPass>();
9192 AU.addRequired <StaticDataProfileInfoWrapperPass>();
93+ // This pass does not modify any required analysis results except
94+ // StaticDataProfileInfoWrapperPass, but StaticDataProfileInfoWrapperPass
95+ // is made an immutable pass that it won't be re-scheduled by pass manager
96+ // anyway. So mark setPreservesAll() here for faster compile time.
97+ AU.setPreservesAll ();
9298 }
9399
94100 bool runOnMachineFunction (MachineFunction &MF) override ;
@@ -127,7 +133,7 @@ StaticDataSplitter::getConstant(const MachineOperand &Op,
127133 if (Op.isGlobal ()) {
128134 // Find global variables with local linkage.
129135 const GlobalVariable *GV = getLocalLinkageGlobalVariable (Op.getGlobal ());
130- // Skip 'special' global variables conservatively because they are
136+ // Skip 'llvm.'-prefixed global variables conservatively because they are
131137 // often handled specially, and skip those not in static data
132138 // sections.
133139 if (!GV || GV->getName ().starts_with (" llvm." ) ||
@@ -150,7 +156,15 @@ StaticDataSplitter::getConstant(const MachineOperand &Op,
150156}
151157
152158bool StaticDataSplitter::partitionStaticDataWithProfiles (MachineFunction &MF) {
153- int NumChangedJumpTables = 0 ;
159+ // If any of the static data (jump tables, global variables, constant pools)
160+ // are captured by the analysis, set `Changed` to true. Note this pass won't
161+ // invalidate any analysis pass (see `getAnalysisUsage` above), so the main
162+ // purpose of tracking and conveying the change (to pass manager) is
163+ // informative as opposed to invalidating any analysis results. As an example
164+ // of where this information is useful, `PMDataManager::dumpPassInfo` will
165+ // only dump pass info if a local change happens, otherwise a pass appears as
166+ // "skipped".
167+ bool Changed = false ;
154168
155169 MachineJumpTableInfo *MJTI = MF.getJumpTableInfo ();
156170
@@ -161,12 +175,11 @@ bool StaticDataSplitter::partitionStaticDataWithProfiles(MachineFunction &MF) {
161175 // usages in the same loop.
162176 for (const auto &MBB : MF) {
163177 for (const MachineInstr &I : MBB) {
178+ std::optional<uint64_t > Count = MBFI->getBlockProfileCount (&MBB);
164179 for (const MachineOperand &Op : I.operands ()) {
165180 if (!Op.isJTI () && !Op.isGlobal () && !Op.isCPI ())
166181 continue ;
167182
168- std::optional<uint64_t > Count = MBFI->getBlockProfileCount (&MBB);
169-
170183 if (Op.isJTI ()) {
171184 assert (MJTI != nullptr && " Jump table info is not available." );
172185 const int JTI = Op.getIndex ();
@@ -182,16 +195,16 @@ bool StaticDataSplitter::partitionStaticDataWithProfiles(MachineFunction &MF) {
182195 if (Count && PSI->isColdCount (*Count))
183196 Hotness = MachineFunctionDataHotness::Cold;
184197
185- if (MJTI->updateJumpTableEntryHotness (JTI, Hotness))
186- ++NumChangedJumpTables;
198+ Changed |= MJTI->updateJumpTableEntryHotness (JTI, Hotness);
187199 } else if (const Constant *C =
188200 getConstant (Op, MF.getTarget (), MF.getConstantPool ())) {
189201 SDPI->addConstantProfileCount (C, Count);
202+ Changed = true ;
190203 }
191204 }
192205 }
193206 }
194- return NumChangedJumpTables > 0 ;
207+ return Changed ;
195208}
196209
197210const GlobalVariable *
@@ -231,16 +244,11 @@ void StaticDataSplitter::updateStatsWithProfiles(const MachineFunction &MF) {
231244
232245void StaticDataSplitter::annotateStaticDataWithoutProfiles (
233246 const MachineFunction &MF) {
234- for (const auto &MBB : MF) {
235- for (const MachineInstr &I : MBB) {
236- for (const MachineOperand &Op : I.operands ()) {
237- const Constant *C =
238- getConstant (Op, MF.getTarget (), MF.getConstantPool ());
239- if (C)
247+ for (const auto &MBB : MF)
248+ for (const MachineInstr &I : MBB)
249+ for (const MachineOperand &Op : I.operands ())
250+ if (const Constant *C = getConstant (Op, MF.getTarget (), MF.getConstantPool ()))
240251 SDPI->addConstantProfileCount (C, std::nullopt );
241- }
242- }
243- }
244252}
245253
246254void StaticDataSplitter::updateStatsWithoutProfiles (const MachineFunction &MF) {
0 commit comments