Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AsmPrinter][ELF] Support profile-guided section prefix for jump tables' (read-only) data sections #122215

Merged
merged 23 commits into from
Jan 29, 2025
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
5d207e9
[SDP]Introduce StaticDataSplitter pass and implemenet jump table spli…
mingmingl-llvm Jan 8, 2025
34b6b9b
Flag-gate the new pass and resolve review feedback
mingmingl-llvm Jan 9, 2025
dd74827
rely to upstream
mingmingl-llvm Jan 10, 2025
8d3a985
Emit jump table with section suffix
mingmingl-llvm Jan 11, 2025
1bacc51
Apply suggestions from code review
mingmingl-llvm Jan 11, 2025
8a85d1a
resolve review feedback
mingmingl-llvm Jan 11, 2025
e54dacb
Discover jump table by calling MachineOperand::isJTI()
mingmingl-llvm Jan 13, 2025
27ef86d
Introduce a TargetMachine option , and the command line flag option t…
mingmingl-llvm Jan 14, 2025
e816def
Emit jump tables into .hot and .unlikely sections respectively
mingmingl-llvm Jan 15, 2025
28defd8
merge base patch
mingmingl-llvm Jan 15, 2025
7f3e473
Add -mtriple=x86_64-unknown-linux-gnu for test
mingmingl-llvm Jan 16, 2025
1bef9b1
run clang format
mingmingl-llvm Jan 16, 2025
59a958a
Apply suggestions from code review
mingmingl-llvm Jan 17, 2025
2d06092
fix windows build bot failure
mingmingl-llvm Jan 17, 2025
9134ffa
resolve comments
mingmingl-llvm Jan 17, 2025
ea2d838
merge with main branch
mingmingl-llvm Jan 24, 2025
027ae56
resolve review feedback
mingmingl-llvm Jan 27, 2025
fd0034a
[NFCI]Refactor AsmPrinter around jump table emission
mingmingl-llvm Jan 27, 2025
a79a789
Merge branch 'main' into users/mingmingl-llvm/spr/nfcprecommit
mingmingl-llvm Jan 27, 2025
d569eff
display diff after refactor
mingmingl-llvm Jan 27, 2025
be96277
git merge main
mingmingl-llvm Jan 27, 2025
b919de9
resolve comments
mingmingl-llvm Jan 28, 2025
6bb4b32
Resolve comments. Also append a dot when -fno-unique-section-names is…
mingmingl-llvm Jan 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Discover jump table by calling MachineOperand::isJTI()
mingmingl-llvm committed Jan 13, 2025
commit e54dacbbbf94538674868b7a8ae1a86dccac44fb
6 changes: 0 additions & 6 deletions llvm/include/llvm/CodeGen/MachineBasicBlock.h
Original file line number Diff line number Diff line change
@@ -997,12 +997,6 @@ class MachineBasicBlock
/// no changes occurred in the meantime.
bool canSplitCriticalEdge(const MachineBasicBlock *Succ) const;

/// Return an index for MachineJumpTableInfo if \p this basic block ends with
/// an indirect jump using a jump table, otherwise -1.
/// This function is a thin wrapper and forward calls to the per-target method
/// `TargetInstrInfo::getjumpTableIndex`.
int getJumpTableIndex() const;

void pop_front() { Insts.pop_front(); }
void pop_back() { Insts.pop_back(); }
void push_back(MachineInstr *MI) { Insts.push_back(MI); }
4 changes: 0 additions & 4 deletions llvm/lib/CodeGen/MachineBasicBlock.cpp
Original file line number Diff line number Diff line change
@@ -1426,10 +1426,6 @@ bool MachineBasicBlock::canSplitCriticalEdge(
return true;
}

int MachineBasicBlock::getJumpTableIndex() const {
return findJumpTableIndex(*this);
}

/// Prepare MI to be removed from its bundle. This fixes bundle flags on MI's
/// neighboring instructions so the bundle won't be broken by removing MI.
static void unbundleSingleMI(MachineInstr *MI) {
40 changes: 24 additions & 16 deletions llvm/lib/CodeGen/StaticDataSplitter.cpp
Original file line number Diff line number Diff line change
@@ -92,23 +92,31 @@ bool StaticDataSplitter::splitJumpTablesWithProfiles(
MachineFunction &MF, MachineJumpTableInfo &MJTI) {
int NumChangedJumpTables = 0;

// Jump table could be used by either terminating instructions or
// non-terminating ones, so we walk all instructions and use
// `MachineOperand::isJTI()` to identify jump table operands.
// Similarly, `MachineOperand::isCPI()` can identify constant pool usages
// in the same loop.
for (const auto &MBB : MF) {
// IMPORTANT, `getJumpTableIndex` is a thin wrapper around per-target
// interface `TargetInstrInfo::getjumpTableIndex`, and only X86 implements
// it so far.
const int JTI = MBB.getJumpTableIndex();
// This is not a source block of jump table.
if (JTI == -1)
continue;

auto Hotness = MachineFunctionDataHotness::Hot;

// Hotness is based on source basic block hotness.
if (PSI->isColdBlock(&MBB, MBFI))
Hotness = MachineFunctionDataHotness::Cold;

if (MF.getJumpTableInfo()->updateJumpTableEntryHotness(JTI, Hotness))
++NumChangedJumpTables;
for (const MachineInstr &I : MBB) {
for (const MachineOperand &Op : I.operands()) {
if (!Op.isJTI())
continue;
const int JTI = Op.getIndex();
// This is not a source block of jump table.
if (JTI == -1)
continue;

auto Hotness = MachineFunctionDataHotness::Hot;

// Hotness is based on source basic block hotness.
if (PSI->isColdBlock(&MBB, MBFI))
Hotness = MachineFunctionDataHotness::Cold;

if (MF.getJumpTableInfo()->updateJumpTableEntryHotness(JTI, Hotness))
++NumChangedJumpTables;
}
}
}
return NumChangedJumpTables > 0;
}