Skip to content

Commit e54dacb

Browse files
Discover jump table by calling MachineOperand::isJTI()
1 parent 8a85d1a commit e54dacb

File tree

3 files changed

+24
-26
lines changed

3 files changed

+24
-26
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: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -92,23 +92,31 @@ bool StaticDataSplitter::splitJumpTablesWithProfiles(
9292
MachineFunction &MF, MachineJumpTableInfo &MJTI) {
9393
int NumChangedJumpTables = 0;
9494

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.
95100
for (const auto &MBB : MF) {
96-
// IMPORTANT, `getJumpTableIndex` is a thin wrapper around per-target
97-
// interface `TargetInstrInfo::getjumpTableIndex`, and only X86 implements
98-
// it so far.
99-
const int JTI = MBB.getJumpTableIndex();
100-
// This is not a source block of jump table.
101-
if (JTI == -1)
102-
continue;
103-
104-
auto Hotness = MachineFunctionDataHotness::Hot;
105-
106-
// Hotness is based on source basic block hotness.
107-
if (PSI->isColdBlock(&MBB, MBFI))
108-
Hotness = MachineFunctionDataHotness::Cold;
109-
110-
if (MF.getJumpTableInfo()->updateJumpTableEntryHotness(JTI, Hotness))
111-
++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+
}
112120
}
113121
return NumChangedJumpTables > 0;
114122
}

0 commit comments

Comments
 (0)