Skip to content

Commit 27ef86d

Browse files
Introduce a TargetMachine option , and the command line flag option to set it
1 parent 8d3a985 commit 27ef86d

File tree

8 files changed

+46
-56
lines changed

8 files changed

+46
-56
lines changed

llvm/include/llvm/CodeGen/CommandFlags.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ bool getEmitCallSiteInfo();
136136

137137
bool getEnableMachineFunctionSplitter();
138138

139+
bool getEnableStaticDataPartitioning();
140+
139141
bool getEnableDebugEntryValues();
140142

141143
bool getValueTrackingVariableLocations();

llvm/include/llvm/Target/TargetMachine.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,10 @@ class TargetMachine {
305305
return Options.FunctionSections;
306306
}
307307

308+
bool getEnableStaticDataPartitioning() const {
309+
return Options.EnableStaticDataPartitioning;
310+
}
311+
308312
/// Return true if visibility attribute should not be emitted in XCOFF,
309313
/// corresponding to -mignore-xcoff-visibility.
310314
bool getIgnoreXCOFFVisibility() const {

llvm/include/llvm/Target/TargetOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,9 @@ namespace llvm {
312312
/// Enables the MachineFunctionSplitter pass.
313313
unsigned EnableMachineFunctionSplitter : 1;
314314

315+
/// Enables the StaticDataSplitter pass.
316+
unsigned EnableStaticDataPartitioning : 1;
317+
315318
/// Set if the target supports default outlining behaviour.
316319
unsigned SupportsDefaultOutlining : 1;
317320

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,6 @@ static cl::opt<bool> BBAddrMapSkipEmitBBEntries(
168168
"unnecessary for some PGOAnalysisMap features."),
169169
cl::Hidden, cl::init(false));
170170

171-
static cl::opt<bool>
172-
EmitStaticDataHotnessSuffix("emit-static-data-hotness-suffix", cl::Hidden,
173-
cl::init(false), cl::ZeroOrMore,
174-
cl::desc("Emit static data hotness suffix"));
175-
176171
static cl::opt<bool> EmitJumpTableSizesSection(
177172
"emit-jump-table-sizes-section",
178173
cl::desc("Emit a section containing jump table addresses and sizes"),
@@ -2882,7 +2877,7 @@ void AsmPrinter::emitJumpTableInfo() {
28822877
F);
28832878

28842879
std::vector<unsigned> JumpTableIndices;
2885-
if (!EmitStaticDataHotnessSuffix) {
2880+
if (!TM.Options.EnableStaticDataPartitioning) {
28862881
for (unsigned JTI = 0, JTSize = JT.size(); JTI < JTSize; ++JTI)
28872882
JumpTableIndices.push_back(JTI);
28882883
emitJumpTables(JumpTableIndices, TLOF.getSectionForJumpTable(F, TM),

llvm/lib/CodeGen/CommandFlags.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ CGOPT(bool, EnableStackSizeSection)
103103
CGOPT(bool, EnableAddrsig)
104104
CGOPT(bool, EmitCallSiteInfo)
105105
CGOPT(bool, EnableMachineFunctionSplitter)
106+
CGOPT(bool, EnableStaticDataPartitioning)
106107
CGOPT(bool, EnableDebugEntryValues)
107108
CGOPT(bool, ForceDwarfFrameSection)
108109
CGOPT(bool, XRayFunctionIndex)
@@ -480,6 +481,12 @@ codegen::RegisterCodeGenFlags::RegisterCodeGenFlags() {
480481
cl::init(false));
481482
CGBINDOPT(EnableMachineFunctionSplitter);
482483

484+
static cl::opt<bool> EnableStaticDataPartitioning(
485+
"partition-static-data-sections",
486+
cl::desc("Partition data sections using profile information."),
487+
cl::init(false));
488+
CGBINDOPT(EnableStaticDataPartitioning);
489+
483490
static cl::opt<bool> ForceDwarfFrameSection(
484491
"force-dwarf-frame-section",
485492
cl::desc("Always emit a debug frame section."), cl::init(false));
@@ -586,6 +593,7 @@ codegen::InitTargetOptionsFromCodeGenFlags(const Triple &TheTriple) {
586593
Options.ExceptionModel = getExceptionModel();
587594
Options.EmitStackSizeSection = getEnableStackSizeSection();
588595
Options.EnableMachineFunctionSplitter = getEnableMachineFunctionSplitter();
596+
Options.EnableStaticDataPartitioning = getEnableStaticDataPartitioning();
589597
Options.EmitAddrsig = getEnableAddrsig();
590598
Options.EmitCallSiteInfo = getEmitCallSiteInfo();
591599
Options.EnableDebugEntryValues = getEnableDebugEntryValues();

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@ MCSection *TargetLoweringObjectFileELF::getSectionForJumpTable(
974974
// the table doesn't prevent the removal.
975975
const Comdat *C = F.getComdat();
976976
bool EmitUniqueSection = TM.getFunctionSections() || C;
977-
if (!EmitUniqueSection)
977+
if (!EmitUniqueSection && !TM.getEnableStaticDataPartitioning())
978978
return ReadOnlySection;
979979

980980
return selectELFSectionForGlobal(getContext(), &F, SectionKind::getReadOnly(),

llvm/lib/CodeGen/TargetPassConfig.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1261,7 +1261,7 @@ void TargetPassConfig::addMachinePasses() {
12611261
"performance.\n";
12621262
}
12631263
}
1264-
if (SplitStaticData)
1264+
if (SplitStaticData || TM->Options.EnableStaticDataPartitioning)
12651265
addPass(createStaticDataSplitterPass());
12661266
addPass(createMachineFunctionSplitterPass());
12671267
}

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

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

9-
; RUN: llc -enable-split-machine-functions -split-static-data -emit-static-data-hotness-suffix=true -function-sections -min-jump-table-entries=2 -disable-block-placement %s -o - 2>&1 | FileCheck %s --check-prefix=SECTION
10-
11-
; Tests stat messages are expected.
12-
; TODO: Update test to verify section suffixes when target-lowering and assembler changes are implemented.
13-
; TODO: Also run static-data-splitter pass with -static-data-default-hotness=cold and check data section suffix.
9+
; When 'partition-static-data-sections' is enabled, static data splitter pass will
10+
; categorize jump tables and assembly printer will place hot jump tables in the
11+
; `.hot`-suffixed read only section, and cold ones in the `.rodata` sections.
12+
; Section names will optionally have `.<func>` if -function-sections is enabled.
13+
; RUN: llc -enable-split-machine-functions -partition-static-data-sections=true -function-sections=true -min-jump-table-entries=2 %s -o - 2>&1 | FileCheck %s --check-prefixes=FUNC,JT,HOT
14+
; RUN: llc -enable-split-machine-functions -partition-static-data-sections=true -function-sections=false -min-jump-table-entries=2 %s -o - 2>&1 | FileCheck %s --check-prefixes=FUNCLESS,JT
15+
16+
; Tests that jump tables with unknown hotness are categorized as cold if `-static-data-default-hotness` specifies so.
17+
; RUN: llc -enable-split-machine-functions -partition-static-data-sections=true -min-jump-table-entries=2 -static-data-default-hotness=cold -function-sections=true %s -o - 2>&1 | FileCheck %s --check-prefixes=FUNC,JT,DEFAULT
1418

19+
; Tests stat messages are expected.
1520
; STAT-DAG: 2 static-data-splitter - Number of cold jump tables seen
16-
; STAT-DAG: 3 static-data-splitter - Number of hot jump tables seen
21+
; STAT-DAG: 2 static-data-splitter - Number of hot jump tables seen
1722
; STAT-DAG: 1 static-data-splitter - Number of jump tables with unknown hotness
1823

19-
; SECTION: .section .rodata.hot.foo,"a",@progbits
20-
; SECTION: .LJTI0_0:
21-
; SECTION: .LJTI0_2:
22-
; SECTION: .section .rodata.foo,"a",@progbits
23-
; SECTION: .LJTI0_1:
24-
; SECTION: .LJTI0_3:
24+
; Tests that the first and third jump table are placed in a hot-suffixed section,
25+
; and the second and fourth are placed in the original section.
26+
; FUNC: .section .rodata.hot.foo,"a",@progbits
27+
; FUNCLESS: .section .rodata.hot,"a",@progbits
28+
; JT: .LJTI0_0:
29+
; JT: .LJTI0_2:
30+
; FUNC: .section .rodata.foo,"a",@progbits
31+
; FUNCLESS: .section .rodata,"a",@progbits
32+
; JT: .LJTI0_1:
33+
; JT: .LJTI0_3:
34+
; HOT: .section .rodata.hot.func_without_entry_count,"a",@progbits
35+
; HOT: .LJTI1_0:
36+
37+
; DEFAULT: .section .rodata.func_without_entry_count,"a",@progbits
38+
; DEFAULT: .LJTI1_0:
2539

2640
; @foo has four jump tables, jt0, jt1, jt2 and jt3 in the input basic block
2741
; order; jt0 and jt2 are hot, and jt1 and jt3 are cold.
@@ -142,42 +156,6 @@ return:
142156
ret i32 %mod3
143157
}
144158

145-
define i32 @func_with_hot_jt() !prof !15 {
146-
entry:
147-
br label %for.body
148-
149-
for.cond.cleanup:
150-
ret i32 0
151-
152-
for.body:
153-
%lsr.iv = phi i32 [ 100000, %entry ], [ %lsr.iv.next, %loop.exit ]
154-
%i.04 = phi i32 [ 0, %entry ], [ %inc, %loop.exit ]
155-
%0 = urem i32 %i.04, 100
156-
switch i32 %0, label %sw.default [
157-
i32 1, label %loop.exit
158-
i32 2, label %sw.bb1.i
159-
i32 3, label %sw.bb3.i
160-
], !prof !19
161-
162-
sw.bb1.i:
163-
br label %loop.exit
164-
165-
sw.bb3.i:
166-
call i32 (ptr, ...) @printf(ptr @case1)
167-
br label %sw.default
168-
169-
sw.default:
170-
br label %loop.exit
171-
172-
loop.exit:
173-
%str.5.sink.i = phi ptr [ @str.10, %sw.default ], [ @str.9, %sw.bb1.i ], [ @case2, %for.body ]
174-
call i32 @puts(ptr %str.5.sink.i)
175-
%inc = add i32 %i.04, 1
176-
%lsr.iv.next = add i32 %lsr.iv, -1
177-
%exitcond.not = icmp eq i32 %lsr.iv.next, 0
178-
br i1 %exitcond.not, label %for.body, label %for.cond.cleanup, !prof !17
179-
}
180-
181159
define void @func_without_entry_count(i32 %num) {
182160
entry:
183161
switch i32 %num, label %sw.default [

0 commit comments

Comments
 (0)