Skip to content

Commit 23fd549

Browse files
merge the base branch and resolve comments
2 parents 9fae47c + 9302b2b commit 23fd549

File tree

5 files changed

+46
-48
lines changed

5 files changed

+46
-48
lines changed

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2770,20 +2770,16 @@ namespace {
27702770
} // end anonymous namespace
27712771

27722772
StringRef AsmPrinter::getConstantSectionSuffix(const Constant *C) const {
2773-
SmallString<8> SectionNameSuffix;
2774-
if (TM.Options.EnableStaticDataPartitioning) {
2775-
if (C && SDPI && PSI) {
2776-
auto Count = SDPI->getConstantProfileCount(C);
2777-
if (Count) {
2778-
if (PSI->isHotCount(*Count)) {
2779-
SectionNameSuffix.append("hot");
2780-
} else if (PSI->isColdCount(*Count) && !SDPI->hasUnknownCount(C)) {
2781-
SectionNameSuffix.append("unlikely");
2782-
}
2783-
}
2773+
if (TM.Options.EnableStaticDataPartitioning && C && SDPI && PSI) {
2774+
if (auto Count = SDPI->getConstantProfileCount(C)) {
2775+
if (PSI->isHotCount(*Count))
2776+
return "hot";
2777+
2778+
if (PSI->isColdCount(*Count) && !SDPI->hasUnknownCount(C))
2779+
return "unlikely";
27842780
}
27852781
}
2786-
return SectionNameSuffix.str();
2782+
return "";
27872783
}
27882784

27892785
/// EmitConstantPool - Print to the current output stream assembly

llvm/lib/CodeGen/StaticDataSplitter.cpp

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
7778
public:
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

152158
bool 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

197210
const GlobalVariable *
@@ -231,16 +244,11 @@ void StaticDataSplitter::updateStatsWithProfiles(const MachineFunction &MF) {
231244

232245
void 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

246254
void StaticDataSplitter::updateStatsWithoutProfiles(const MachineFunction &MF) {

llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -226,15 +226,11 @@ class AArch64AsmPrinter : public AsmPrinter {
226226
}
227227

228228
bool runOnMachineFunction(MachineFunction &MF) override {
229-
auto *PSIW = getAnalysisIfAvailable<ProfileSummaryInfoWrapperPass>();
230-
if (PSIW) {
229+
if (auto *PSIW = getAnalysisIfAvailable<ProfileSummaryInfoWrapperPass>())
231230
PSI = &PSIW->getPSI();
232-
}
233-
234-
auto *SDPIW = getAnalysisIfAvailable<StaticDataProfileInfoWrapperPass>();
235-
if (SDPIW) {
231+
if (auto *SDPIW =
232+
getAnalysisIfAvailable<StaticDataProfileInfoWrapperPass>())
236233
SDPI = &SDPIW->getStaticDataProfileInfo();
237-
}
238234

239235
AArch64FI = MF.getInfo<AArch64FunctionInfo>();
240236
STI = &MF.getSubtarget<AArch64Subtarget>();

llvm/lib/Target/TargetLoweringObjectFile.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,9 @@ MCSection *TargetLoweringObjectFile::getSectionForConstant(
393393
// is empty.
394394
if (SectionPrefix.empty())
395395
return getSectionForConstant(DL, Kind, C, Alignment);
396-
report_fatal_error("Unimplemented");
396+
report_fatal_error(
397+
"TargetLoweringObjectFile::getSectionForConstant that "
398+
"accepts SectionPrefix is not implemented for the object file format");
397399
}
398400

399401
MCSection *TargetLoweringObjectFile::getSectionForMachineBasicBlock(

llvm/lib/Target/X86/X86AsmPrinter.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,11 @@ X86AsmPrinter::X86AsmPrinter(TargetMachine &TM,
6262
/// runOnMachineFunction - Emit the function body.
6363
///
6464
bool X86AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
65-
auto *PSIW = getAnalysisIfAvailable<ProfileSummaryInfoWrapperPass>();
66-
if (PSIW) {
65+
if (auto *PSIW = getAnalysisIfAvailable<ProfileSummaryInfoWrapperPass>())
6766
PSI = &PSIW->getPSI();
68-
}
69-
70-
auto *SDPIW = getAnalysisIfAvailable<StaticDataProfileInfoWrapperPass>();
71-
if (SDPIW) {
67+
if (auto *SDPIW = getAnalysisIfAvailable<StaticDataProfileInfoWrapperPass>())
7268
SDPI = &SDPIW->getStaticDataProfileInfo();
73-
}
69+
7470
Subtarget = &MF.getSubtarget<X86Subtarget>();
7571

7672
SMShadowTracker.startFunction(MF);

0 commit comments

Comments
 (0)