@@ -58,6 +58,11 @@ class StaticDataSplitter : public MachineFunctionPass {
58
58
// .data.rel.ro} sections.
59
59
bool inStaticDataSection (const GlobalVariable *GV, const TargetMachine &TM);
60
60
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
+
61
66
// Use profiles to partition static data.
62
67
bool partitionStaticDataWithProfiles (MachineFunction &MF);
63
68
@@ -84,6 +89,8 @@ class StaticDataSplitter : public MachineFunctionPass {
84
89
AU.addRequired <MachineBlockFrequencyInfoWrapperPass>();
85
90
AU.addRequired <ProfileSummaryInfoWrapperPass>();
86
91
AU.addRequired <StaticDataProfileInfoWrapperPass>();
92
+ // This pass does not modify the CFG.
93
+ AU.setPreservesCFG ();
87
94
}
88
95
89
96
bool runOnMachineFunction (MachineFunction &MF) override ;
@@ -112,6 +119,20 @@ bool StaticDataSplitter::runOnMachineFunction(MachineFunction &MF) {
112
119
return Changed;
113
120
}
114
121
122
+ const Constant *StaticDataSplitter::getConstant (const MachineOperand &Op,
123
+ const TargetMachine &TM) {
124
+ if (!Op.isGlobal ())
125
+ return nullptr ;
126
+
127
+ // Find global variables with local linkage.
128
+ const GlobalVariable *GV = getLocalLinkageGlobalVariable (Op.getGlobal ());
129
+ // Skip 'llvm.'-prefixed global variables conservatively because they are
130
+ // often handled specially, and skip those not in static data sections.
131
+ if (!GV || GV->getName ().starts_with (" llvm." ) || !inStaticDataSection (GV, TM))
132
+ return nullptr ;
133
+ return GV;
134
+ }
135
+
115
136
bool StaticDataSplitter::partitionStaticDataWithProfiles (MachineFunction &MF) {
116
137
int NumChangedJumpTables = 0 ;
117
138
@@ -148,17 +169,8 @@ bool StaticDataSplitter::partitionStaticDataWithProfiles(MachineFunction &MF) {
148
169
149
170
if (MJTI->updateJumpTableEntryHotness (JTI, Hotness))
150
171
++NumChangedJumpTables;
151
- } else {
152
- // Find global variables with local linkage.
153
- const GlobalVariable *GV =
154
- getLocalLinkageGlobalVariable (Op.getGlobal ());
155
- // Skip 'special' global variables conservatively because they are
156
- // often handled specially, and skip those not in static data
157
- // sections.
158
- if (!GV || GV->getName ().starts_with (" llvm." ) ||
159
- !inStaticDataSection (GV, TM))
160
- continue ;
161
- SDPI->addConstantProfileCount (GV, Count);
172
+ } else if (const Constant *C = getConstant (Op, TM)) {
173
+ SDPI->addConstantProfileCount (C, Count);
162
174
}
163
175
}
164
176
}
@@ -203,20 +215,11 @@ void StaticDataSplitter::updateStatsWithProfiles(const MachineFunction &MF) {
203
215
204
216
void StaticDataSplitter::annotateStaticDataWithoutProfiles (
205
217
const MachineFunction &MF) {
206
- for (const auto &MBB : MF) {
207
- for (const MachineInstr &I : MBB) {
208
- for (const MachineOperand &Op : I.operands ()) {
209
- if (!Op.isGlobal ())
210
- continue ;
211
- const GlobalVariable *GV =
212
- getLocalLinkageGlobalVariable (Op.getGlobal ());
213
- if (!GV || GV->getName ().starts_with (" llvm." ) ||
214
- !inStaticDataSection (GV, MF.getTarget ()))
215
- continue ;
216
- SDPI->addConstantProfileCount (GV, std::nullopt);
217
- }
218
- }
219
- }
218
+ for (const auto &MBB : MF)
219
+ for (const MachineInstr &I : MBB)
220
+ for (const MachineOperand &Op : I.operands ())
221
+ if (const Constant *C = getConstant (Op, MF.getTarget ()))
222
+ SDPI->addConstantProfileCount (C, std::nullopt);
220
223
}
221
224
222
225
void StaticDataSplitter::updateStatsWithoutProfiles (const MachineFunction &MF) {
0 commit comments