Skip to content

Commit 28defd8

Browse files
merge base patch
2 parents e816def + e54dacb commit 28defd8

File tree

3 files changed

+30
-32
lines changed

3 files changed

+30
-32
lines changed

llvm/include/llvm/CodeGen/MachineBasicBlock.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -997,12 +997,6 @@ class MachineBasicBlock
997997
/// no changes occurred in the meantime.
998998
bool canSplitCriticalEdge(const MachineBasicBlock *Succ) const;
999999

1000-
/// Return an index for MachineJumpTableInfo if \p this basic block ends with
1001-
/// an indirect jump using a jump table, otherwise -1.
1002-
/// This function is a thin wrapper and forward calls to the per-target method
1003-
/// `TargetInstrInfo::getjumpTableIndex`.
1004-
int getJumpTableIndex() const;
1005-
10061000
void pop_front() { Insts.pop_front(); }
10071001
void pop_back() { Insts.pop_back(); }
10081002
void push_back(MachineInstr *MI) { Insts.push_back(MI); }

llvm/lib/CodeGen/MachineBasicBlock.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,10 +1426,6 @@ bool MachineBasicBlock::canSplitCriticalEdge(
14261426
return true;
14271427
}
14281428

1429-
int MachineBasicBlock::getJumpTableIndex() const {
1430-
return findJumpTableIndex(*this);
1431-
}
1432-
14331429
/// Prepare MI to be removed from its bundle. This fixes bundle flags on MI's
14341430
/// neighboring instructions so the bundle won't be broken by removing MI.
14351431
static void unbundleSingleMI(MachineInstr *MI) {

llvm/lib/CodeGen/StaticDataSplitter.cpp

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ STATISTIC(NumUnknownJumpTables,
4343

4444
static cl::opt<MachineFunctionDataHotness> StaticDataDefaultHotness(
4545
"static-data-default-hotness", cl::Hidden,
46-
cl::desc("The hotness for static data with unknown hotness"),
46+
cl::desc("This option specifies the hotness of static data when profile "
47+
"information is unavailable"),
4748
cl::init(MachineFunctionDataHotness::Hot),
4849
cl::values(clEnumValN(MachineFunctionDataHotness::Hot, "hot", "Hot"),
4950
clEnumValN(MachineFunctionDataHotness::Cold, "cold", "Cold")));
@@ -84,32 +85,38 @@ bool StaticDataSplitter::runOnMachineFunction(MachineFunction &MF) {
8485
MBFI = &getAnalysis<MachineBlockFrequencyInfoWrapperPass>().getMBFI();
8586
PSI = &getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI();
8687

87-
// Split jump tables based on profile information. Subsequent patches will
88-
// handle other data types like constant pools, module-internal data, etc.
8988
return splitJumpTables(MF);
9089
}
9190

9291
bool StaticDataSplitter::splitJumpTablesWithProfiles(
9392
MachineFunction &MF, MachineJumpTableInfo &MJTI) {
9493
int NumChangedJumpTables = 0;
9594

95+
// Jump table could be used by either terminating instructions or
96+
// non-terminating ones, so we walk all instructions and use
97+
// `MachineOperand::isJTI()` to identify jump table operands.
98+
// Similarly, `MachineOperand::isCPI()` can identify constant pool usages
99+
// in the same loop.
96100
for (const auto &MBB : MF) {
97-
// IMPORTANT, `getJumpTableIndex` is a thin wrapper around per-target
98-
// interface `TargetInstrInfo::getjumpTableIndex`, and only X86 implements
99-
// it so far.
100-
const int JTI = MBB.getJumpTableIndex();
101-
// This is not a source block of jump table.
102-
if (JTI == -1)
103-
continue;
104-
105-
auto Hotness = MachineFunctionDataHotness::Hot;
106-
107-
// Hotness is based on source basic block hotness.
108-
if (PSI->isColdBlock(&MBB, MBFI))
109-
Hotness = MachineFunctionDataHotness::Cold;
110-
111-
if (MF.getJumpTableInfo()->updateJumpTableEntryHotness(JTI, Hotness))
112-
++NumChangedJumpTables;
101+
for (const MachineInstr &I : MBB) {
102+
for (const MachineOperand &Op : I.operands()) {
103+
if (!Op.isJTI())
104+
continue;
105+
const int JTI = Op.getIndex();
106+
// This is not a source block of jump table.
107+
if (JTI == -1)
108+
continue;
109+
110+
auto Hotness = MachineFunctionDataHotness::Hot;
111+
112+
// Hotness is based on source basic block hotness.
113+
if (PSI->isColdBlock(&MBB, MBFI))
114+
Hotness = MachineFunctionDataHotness::Cold;
115+
116+
if (MF.getJumpTableInfo()->updateJumpTableEntryHotness(JTI, Hotness))
117+
++NumChangedJumpTables;
118+
}
119+
}
113120
}
114121
return NumChangedJumpTables > 0;
115122
}
@@ -136,7 +143,7 @@ bool StaticDataSplitter::splitJumpTables(MachineFunction &MF) {
136143
NumHotJumpTables++;
137144
else {
138145
assert(Hotness == MachineFunctionDataHotness::Cold &&
139-
"A jump table is hot or cold when profile information is "
146+
"A jump table is either hot or cold when profile information is "
140147
"available.");
141148
NumColdJumpTables++;
142149
}
@@ -147,8 +154,9 @@ bool StaticDataSplitter::splitJumpTables(MachineFunction &MF) {
147154
if (ProfileAvailable)
148155
return splitJumpTablesWithProfiles(MF, *MJTI);
149156

150-
// If function profile is unavailable, -static-data-default-hotness specifies
151-
// the hotness.
157+
// If function profile is unavailable (e.g., module not instrumented, or new
158+
// code paths lacking samples), -static-data-default-hotness specifies the
159+
// hotness.
152160
for (size_t JTI = 0; JTI < MJTI->getJumpTables().size(); JTI++)
153161
MF.getJumpTableInfo()->updateJumpTableEntryHotness(
154162
JTI, StaticDataDefaultHotness);

0 commit comments

Comments
 (0)