Skip to content

Commit cf1b613

Browse files
simplify code
1 parent a2a6f9f commit cf1b613

File tree

3 files changed

+23
-24
lines changed

3 files changed

+23
-24
lines changed

llvm/include/llvm/CodeGen/AsmPrinter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ class AsmPrinter : public MachineFunctionPass {
453453
/// function to the current output stream.
454454
virtual void emitJumpTableInfo();
455455

456-
virtual void emitJumpTables(const std::vector<unsigned> &JumpTableIndices,
456+
virtual void emitJumpTables(ArrayRef<unsigned> JumpTableIndices,
457457
MCSection *JumpTableSection, bool JTInDiffSection,
458458
const MachineJumpTableInfo &MJTI);
459459

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2881,42 +2881,41 @@ void AsmPrinter::emitJumpTableInfo() {
28812881
MJTI->getEntryKind() == MachineJumpTableInfo::EK_LabelDifference64,
28822882
F);
28832883

2884+
std::vector<unsigned> JumpTableIndices;
2885+
for (unsigned JTI = 0, JTSize = JT.size(); JTI != JTSize; ++JTI)
2886+
JumpTableIndices.push_back(JTI);
28842887
if (!EmitStaticDataHotnessSuffix) {
2885-
std::vector<unsigned> JumpTableIndices;
2886-
for (unsigned JTI = 0, e = JT.size(); JTI != e; ++JTI)
2887-
JumpTableIndices.push_back(JTI);
2888-
// Prior code in this function verifies JT is not empty. Use JT[0] directly.
28892888
emitJumpTables(JumpTableIndices, TLOF.getSectionForJumpTable(F, TM),
28902889
JTInDiffSection, *MJTI);
28912890
return;
28922891
}
28932892

2894-
// Iterate all jump tables, put them into two vectors, hot and lukewarm
2895-
std::vector<unsigned> HotOrWarmJumpTableIndices, ColdJumpTableIndices;
2896-
2897-
for (unsigned JTI = 0, e = JT.size(); JTI != e; ++JTI) {
2898-
if (JT[JTI].Hotness == llvm::DataHotness::Cold)
2899-
ColdJumpTableIndices.push_back(JTI);
2900-
else
2901-
HotOrWarmJumpTableIndices.push_back(JTI);
2893+
// Iterate all jump tables, put hot jump table indices towards the beginning
2894+
// of the vector, and cold jump table indices towards the end.
2895+
unsigned ColdJumpTableStart = JT.size();
2896+
for (unsigned JTI = 0; JTI != ColdJumpTableStart;) {
2897+
if (JT[JTI].Hotness == llvm::DataHotness::Cold) {
2898+
ColdJumpTableStart -= 1;
2899+
std::swap(JumpTableIndices[JTI], JumpTableIndices[ColdJumpTableStart]);
2900+
} else
2901+
JTI += 1;
29022902
}
29032903

2904-
if (!HotOrWarmJumpTableIndices.empty())
2905-
emitJumpTables(HotOrWarmJumpTableIndices,
2906-
TLOF.getSectionForJumpTable(
2907-
F, TM, &JT[*HotOrWarmJumpTableIndices.begin()]),
2908-
JTInDiffSection, *MJTI);
2904+
if (ColdJumpTableStart != 0)
2905+
emitJumpTables(
2906+
ArrayRef<unsigned>(JumpTableIndices).slice(0, ColdJumpTableStart),
2907+
TLOF.getSectionForJumpTable(F, TM, &JT[0]), JTInDiffSection, *MJTI);
29092908

2910-
if (!ColdJumpTableIndices.empty())
2909+
if (ColdJumpTableStart != JT.size())
29112910
emitJumpTables(
2912-
ColdJumpTableIndices,
2913-
TLOF.getSectionForJumpTable(F, TM, &JT[*ColdJumpTableIndices.begin()]),
2911+
ArrayRef<unsigned>(JumpTableIndices).slice(ColdJumpTableStart),
2912+
TLOF.getSectionForJumpTable(F, TM, &JT[ColdJumpTableStart]),
29142913
JTInDiffSection, *MJTI);
29152914

29162915
return;
29172916
}
29182917

2919-
void AsmPrinter::emitJumpTables(const std::vector<unsigned> &JumpTableIndices,
2918+
void AsmPrinter::emitJumpTables(ArrayRef<unsigned> JumpTableIndices,
29202919
MCSection *JumpTableSection,
29212920
bool JTInDiffSection,
29222921
const MachineJumpTableInfo &MJTI) {

llvm/test/CodeGen/X86/jump-table-partition.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
; requires: asserts
33

44
; RUN: llc -stop-after=block-placement %s -o - | llc --run-pass=static-data-splitter -stats -x mir -o - 2>&1 | FileCheck %s --check-prefix=STAT
5-
; RUN: llc -enable-split-machine-functions -split-static-data --function-sections -data-sections %s -o - 2>&1 | FileCheck %s --check-prefix=SECTION
5+
; RUN: llc -enable-split-machine-functions -split-static-data -emit-static-data-hotness-suffix=true -function-sections -data-sections %s -o - 2>&1 | FileCheck %s --check-prefix=SECTION
66

77
; `func_with_hot_jumptable` contains a hot jump table and `func_with_cold_jumptable` contains a cold one.
88
; `func_without_entry_count` simulates the functions without profile information (e.g., not instrumented or not profiled),
@@ -13,7 +13,6 @@
1313
; STAT-DAG: 1 static-data-splitter - Number of hot jump tables seen
1414
; STAT-DAG: 1 static-data-splitter - Number of jump tables with unknown hotness
1515

16-
; TODO: Construct a test case where a hot function has a cold jump table.
1716
; SECTION: .section .rodata.hot.func_with_hot_jumptable
1817
; SECTION: .section .rodata.unlikely.func_with_cold_jumptable
1918
; SECTION: .section .rodata.hot.func_without_entry_count
@@ -28,6 +27,7 @@ target triple = "x86_64-unknown-linux-gnu"
2827
@str.10 = private constant [7 x i8] c"case 1\00"
2928
@str.11 = private constant [8 x i8] c"default\00"
3029

30+
; TODO: Add a cold jump table in this function.
3131
define i32 @func_with_hot_jumptable(i32 %num) !prof !13 {
3232
entry:
3333
switch i32 %num, label %sw.default [

0 commit comments

Comments
 (0)