Skip to content

Commit 6bb4b32

Browse files
Resolve comments. Also append a dot when -fno-unique-section-names is used for linker's disambiguation
1 parent b919de9 commit 6bb4b32

File tree

3 files changed

+58
-24
lines changed

3 files changed

+58
-24
lines changed

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -672,13 +672,17 @@ getELFSectionNameForGlobal(const GlobalObject *GO, SectionKind Kind,
672672
bool HasPrefix = false;
673673
if (const auto *F = dyn_cast<Function>(GO)) {
674674
// Jump table hotness takes precedence over its enclosing function's hotness
675-
// if both are available.
676-
if (JTE) {
675+
// if it's known. The function's section prefix is used if jump table entry
676+
// hotness is unknown.
677+
if (JTE && JTE->Hotness != MachineFunctionDataHotness::Unknown) {
677678
if (JTE->Hotness == MachineFunctionDataHotness::Hot) {
678679
raw_svector_ostream(Name) << ".hot";
679-
} else if (JTE->Hotness == MachineFunctionDataHotness::Cold) {
680+
} else {
681+
assert(JTE->Hotness == MachineFunctionDataHotness::Cold &&
682+
"Hotness must be cold");
680683
raw_svector_ostream(Name) << ".unlikely";
681684
}
685+
HasPrefix = true;
682686
} else if (std::optional<StringRef> Prefix = F->getSectionPrefix()) {
683687
raw_svector_ostream(Name) << '.' << *Prefix;
684688
HasPrefix = true;
@@ -978,7 +982,7 @@ MCSection *TargetLoweringObjectFileELF::getUniqueSectionForFunction(
978982

979983
MCSection *TargetLoweringObjectFileELF::getSectionForJumpTable(
980984
const Function &F, const TargetMachine &TM) const {
981-
return getSectionForJumpTable(F, TM, nullptr);
985+
return getSectionForJumpTable(F, TM, /*JTE=*/nullptr);
982986
}
983987

984988
MCSection *TargetLoweringObjectFileELF::getSectionForJumpTable(

llvm/lib/Target/TargetLoweringObjectFile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ TargetLoweringObjectFile::SectionForGlobal(const GlobalObject *GO,
348348

349349
MCSection *TargetLoweringObjectFile::getSectionForJumpTable(
350350
const Function &F, const TargetMachine &TM) const {
351-
return getSectionForJumpTable(F, TM, nullptr);
351+
return getSectionForJumpTable(F, TM, /*JTE=*/nullptr);
352352
}
353353

354354
MCSection *TargetLoweringObjectFile::getSectionForJumpTable(

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

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,12 @@
66
; RUN: llc -mtriple=x86_64-unknown-linux-gnu -stop-after=finalize-isel -min-jump-table-entries=2 %s -o %t.mir
77
; RUN: llc -mtriple=x86_64-unknown-linux-gnu --run-pass=static-data-splitter -stats -x mir %t.mir -o - 2>&1 | FileCheck %s --check-prefix=STAT
88

9-
; In function @foo, the 2 switch instructions to jt0.* and jt1.* get lowered to
10-
; hot jump tables, and the 2 switch instructions to jt2.* and jt3.* get lowered
11-
; to cold jump tables.
12-
13-
; @func_without_entry_count simulates the functions without profile information
14-
; (e.g., not instrumented or not profiled), it's jump table hotness is unknown.
15-
16-
; Tests stat messages are expected.
9+
; @foo has 2 hot and 2 cold jump tables.
10+
; The two jump tables with unknown hotness come from @func_without_profile and
11+
; @bar respectively.
1712
; STAT: 2 static-data-splitter - Number of cold jump tables seen
1813
; STAT: 2 static-data-splitter - Number of hot jump tables seen
19-
; STAT: 1 static-data-splitter - Number of jump tables with unknown hotness
20-
21-
; Hot jump tables are in the `.rodata.hot`-prefixed section, and cold ones in
22-
; the `.rodata.unlikely`-prefixed section. In the function without profile
23-
; information, jump table section is `rodata` without hot or unlikely prefix.
14+
; STAT: 2 static-data-splitter - Number of jump tables with unknown hotness
2415

2516
; RUN: llc -mtriple=x86_64-unknown-linux-gnu -enable-split-machine-functions \
2617
; RUN: -partition-static-data-sections=true -function-sections=true \
@@ -36,20 +27,35 @@
3627
; RUN: -partition-static-data-sections=true -function-sections=false \
3728
; RUN: -min-jump-table-entries=2 %s -o - 2>&1 | FileCheck %s --check-prefixes=FUNCLESS,JT
3829

39-
; NUM: .section .rodata.hot,"a",@progbits,unique,2
30+
; In function @foo, the 2 switch instructions to jt0.* and jt1.* are placed in
31+
; hot-prefixed sections, and the 2 switch instructions to jt2.* and jt3.* are
32+
; placed in cold-prefixed sections.
33+
; NUM: .section .rodata.hot.,"a",@progbits,unique,2
4034
; FUNC: .section .rodata.hot.foo,"a",@progbits
41-
; FUNCLESS: .section .rodata.hot,"a",@progbits
35+
; FUNCLESS: .section .rodata.hot.,"a",@progbits
4236
; JT: .LJTI0_0:
4337
; JT: .LJTI0_2:
44-
; NUM: .section .rodata.unlikely,"a",@progbits,unique,3
38+
; NUM: .section .rodata.unlikely.,"a",@progbits,unique,3
4539
; FUNC: .section .rodata.unlikely.foo,"a",@progbits
46-
; FUNCLESS: .section .rodata.unlikely,"a",@progbits
40+
; FUNCLESS: .section .rodata.unlikely.,"a",@progbits
4741
; JT: .LJTI0_1:
4842
; JT: .LJTI0_3:
49-
; FUNC: .section .rodata.func_without_entry_count,"a",@progbits
43+
44+
; @func_without_profile simulates the functions without profile information
45+
; (e.g., not instrumented or not profiled), its jump tables are placed in
46+
; sections without hot or unlikely prefixes.
47+
; NUM: .section .rodata,"a",@progbits,unique,5
48+
; FUNC: .section .rodata.func_without_profile,"a",@progbits
5049
; FUNCLESS: .section .rodata,"a",@progbits
5150
; JT: .LJTI1_0:
5251

52+
; @bar doesn't have profile information and it has a section prefix.
53+
; Tests that its jump tables are placed in sections with function prefixes.
54+
; NUM: .section .rodata.bar_prefix.,"a",@progbits,unique,7
55+
; FUNC: .section .rodata.bar_prefix.bar
56+
; FUNCLESS: .section .rodata.bar_prefix.,"a"
57+
; JT: .LJTI2_0
58+
5359
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
5460
target triple = "x86_64-unknown-linux-gnu"
5561

@@ -159,7 +165,7 @@ return:
159165
ret i32 %mod3
160166
}
161167

162-
define void @func_without_entry_count(i32 %num) {
168+
define void @func_without_profile(i32 %num) {
163169
entry:
164170
switch i32 %num, label %sw.default [
165171
i32 1, label %sw.bb
@@ -182,6 +188,29 @@ sw.epilog:
182188
ret void
183189
}
184190

191+
define void @bar(i32 %num) !section_prefix !20 {
192+
entry:
193+
switch i32 %num, label %sw.default [
194+
i32 1, label %sw.bb
195+
i32 2, label %sw.bb1
196+
]
197+
198+
sw.bb:
199+
call i32 @puts(ptr @str.10)
200+
br label %sw.epilog
201+
202+
sw.bb1:
203+
call i32 @puts(ptr @str.9)
204+
br label %sw.epilog
205+
206+
sw.default:
207+
call i32 @puts(ptr @str.11)
208+
br label %sw.epilog
209+
210+
sw.epilog:
211+
ret void
212+
}
213+
185214
declare i32 @puts(ptr)
186215
declare i32 @printf(ptr, ...)
187216
declare i32 @compute(i32)
@@ -210,3 +239,4 @@ declare i32 @cleanup(i32)
210239
!17 = !{!"branch_weights", i32 99999, i32 1}
211240
!18 = !{!"branch_weights", i32 99998, i32 1}
212241
!19 = !{!"branch_weights", i32 97000, i32 1000, i32 1000, i32 1000}
242+
!20 = !{!"function_section_prefix", !"bar_prefix"}

0 commit comments

Comments
 (0)