[llvm] [NFC]In codegen pipeline, turn static-data-splitter pass on/off with its own option (PR #134752)
Mingming Liu via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 7 18:48:38 PDT 2025
https://github.com/mingmingl-llvm updated https://github.com/llvm/llvm-project/pull/134752
>From 45ca93cae28f24ca2f7d1dd6454c52c0ba4970d0 Mon Sep 17 00:00:00 2001
From: mingmingl <mingmingl at google.com>
Date: Mon, 7 Apr 2025 23:15:41 +0000
Subject: [PATCH 1/2] [NFC]In codegen pipeline, turn static-data-splitter pass
on/off with its own option
---
llvm/lib/CodeGen/TargetPassConfig.cpp | 37 ++++++++++++-------
.../AArch64/constant-pool-partition.ll | 10 ++---
.../CodeGen/X86/constant-pool-partition.ll | 14 +++----
.../CodeGen/X86/global-variable-partition.ll | 36 +++++++++---------
llvm/test/CodeGen/X86/jump-table-partition.ll | 18 ++++-----
5 files changed, 60 insertions(+), 55 deletions(-)
diff --git a/llvm/lib/CodeGen/TargetPassConfig.cpp b/llvm/lib/CodeGen/TargetPassConfig.cpp
index fa1bb84ec5319..45fae653e4181 100644
--- a/llvm/lib/CodeGen/TargetPassConfig.cpp
+++ b/llvm/lib/CodeGen/TargetPassConfig.cpp
@@ -1235,13 +1235,11 @@ void TargetPassConfig::addMachinePasses() {
addPass(createMIRAddFSDiscriminatorsPass(
sampleprof::FSDiscriminatorPass::PassLast));
- // Machine function splitter uses the basic block sections feature.
- // When used along with `-basic-block-sections=`, the basic-block-sections
- // feature takes precedence. This means functions eligible for
- // basic-block-sections optimizations (`=all`, or `=list=` with function
- // included in the list profile) will get that optimization instead.
- if (TM->Options.EnableMachineFunctionSplitter ||
- EnableMachineFunctionSplitter) {
+ bool MIRProfileLoaderPassEnabled = false;
+ auto EnableMIRProfileLoaderPass = [&]() {
+ if (MIRProfileLoaderPassEnabled)
+ return;
+
const std::string ProfileFile = getFSProfileFile(TM);
if (!ProfileFile.empty()) {
if (EnableFSDiscriminator) {
@@ -1256,14 +1254,25 @@ void TargetPassConfig::addMachinePasses() {
"performance.\n";
}
}
+ MIRProfileLoaderPassEnabled = true;
+ };
+ // Machine function splitter uses the basic block sections feature.
+ // When used along with `-basic-block-sections=`, the basic-block-sections
+ // feature takes precedence. This means functions eligible for
+ // basic-block-sections optimizations (`=all`, or `=list=` with function
+ // included in the list profile) will get that optimization instead.
+ if (TM->Options.EnableMachineFunctionSplitter ||
+ EnableMachineFunctionSplitter) {
+ EnableMIRProfileLoaderPass();
addPass(createMachineFunctionSplitterPass());
- if (SplitStaticData || TM->Options.EnableStaticDataPartitioning) {
- // The static data splitter pass is a machine function pass. and
- // static data annotator pass is a module-wide pass. See the file comment
- // in StaticDataAnnotator.cpp for the motivation.
- addPass(createStaticDataSplitterPass());
- addPass(createStaticDataAnnotatorPass());
- }
+ }
+ if (SplitStaticData || TM->Options.EnableStaticDataPartitioning) {
+ EnableMIRProfileLoaderPass();
+ // The static data splitter pass is a machine function pass. and
+ // static data annotator pass is a module-wide pass. See the file comment
+ // in StaticDataAnnotator.cpp for the motivation.
+ addPass(createStaticDataSplitterPass());
+ addPass(createStaticDataAnnotatorPass());
}
// We run the BasicBlockSections pass if either we need BB sections or BB
// address map (or both).
diff --git a/llvm/test/CodeGen/AArch64/constant-pool-partition.ll b/llvm/test/CodeGen/AArch64/constant-pool-partition.ll
index ab627b02a1bc7..d4447131e9de1 100644
--- a/llvm/test/CodeGen/AArch64/constant-pool-partition.ll
+++ b/llvm/test/CodeGen/AArch64/constant-pool-partition.ll
@@ -1,12 +1,10 @@
-; RUN: llc -mtriple=aarch64 -enable-split-machine-functions \
-; RUN: -partition-static-data-sections=true -function-sections=true \
-; RUN: -unique-section-names=false \
+; RUN: llc -mtriple=aarch64 -partition-static-data-sections \
+; RUN: -function-sections -unique-section-names=false \
; RUN: %s -o - 2>&1 | FileCheck %s --dump-input=always
; Repeat the RUN command above for big-endian systems.
-; RUN: llc -mtriple=aarch64_be -enable-split-machine-functions \
-; RUN: -partition-static-data-sections=true -function-sections=true \
-; RUN: -unique-section-names=false \
+; RUN: llc -mtriple=aarch64_be -partition-static-data-sections \
+; RUN: -function-sections -unique-section-names=false \
; RUN: %s -o - 2>&1 | FileCheck %s --dump-input=always
; Tests that constant pool hotness is aggregated across the module. The
diff --git a/llvm/test/CodeGen/X86/constant-pool-partition.ll b/llvm/test/CodeGen/X86/constant-pool-partition.ll
index d2c87b7b3fc14..515284fb2cf1a 100644
--- a/llvm/test/CodeGen/X86/constant-pool-partition.ll
+++ b/llvm/test/CodeGen/X86/constant-pool-partition.ll
@@ -10,18 +10,16 @@ target triple = "x86_64-grtev4-linux-gnu"
; 2. Similarly if a constant is accessed by both cold function and un-profiled
; function, constant pools for this constant should not have .unlikely suffix.
-; RUN: llc -mtriple=x86_64-unknown-linux-gnu -enable-split-machine-functions \
-; RUN: -partition-static-data-sections=true -function-sections=true -data-sections=true \
-; RUN: -unique-section-names=false \
+; RUN: llc -mtriple=x86_64-unknown-linux-gnu -partition-static-data-sections \
+; RUN: -function-sections -data-sections -unique-section-names=false \
; RUN: %s -o - 2>&1 | FileCheck %s --dump-input=always
-; RUN: llc -mtriple=x86_64-unknown-linux-gnu -enable-split-machine-functions \
-; RUN: -partition-static-data-sections=true -function-sections=true -data-sections=true \
-; RUN: -unique-section-names=true \
+; RUN: llc -mtriple=x86_64-unknown-linux-gnu -partition-static-data-sections \
+; RUN: -function-sections -data-sections -unique-section-names \
; RUN: %s -o - 2>&1 | FileCheck %s --dump-input=always
-; RUN: llc -mtriple=x86_64-unknown-linux-gnu -enable-split-machine-functions \
-; RUN: -partition-static-data-sections=true -function-sections=false -data-sections=false \
+; RUN: llc -mtriple=x86_64-unknown-linux-gnu -partition-static-data-sections \
+; RUN: -function-sections=false -data-sections=false \
; RUN: -unique-section-names=false \
; RUN: %s -o - 2>&1 | FileCheck %s --dump-input=always
diff --git a/llvm/test/CodeGen/X86/global-variable-partition.ll b/llvm/test/CodeGen/X86/global-variable-partition.ll
index 91084d038cfe0..ce06d1712f840 100644
--- a/llvm/test/CodeGen/X86/global-variable-partition.ll
+++ b/llvm/test/CodeGen/X86/global-variable-partition.ll
@@ -11,22 +11,22 @@ target triple = "x86_64-unknown-linux-gnu"
; This RUN command sets `-data-sections=true -unique-section-names=true` so data
; sections are uniqufied by numbers.
-; RUN: llc -mtriple=x86_64-unknown-linux-gnu -enable-split-machine-functions \
-; RUN: -partition-static-data-sections=true -data-sections=true \
-; RUN: -unique-section-names=true -relocation-model=pic \
+; RUN: llc -mtriple=x86_64-unknown-linux-gnu -relocation-model=pic \
+; RUN: -partition-static-data-sections=true \
+; RUN: -data-sections=true -unique-section-names=true \
; RUN: %s -o - 2>&1 | FileCheck %s --check-prefixes=SYM,COMMON --dump-input=always
; This RUN command sets `-data-sections=true -unique-section-names=false` so
; data sections are uniqufied by variable names.
-; RUN: llc -mtriple=x86_64-unknown-linux-gnu -enable-split-machine-functions \
-; RUN: -partition-static-data-sections=true -data-sections=true \
-; RUN: -unique-section-names=false -relocation-model=pic \
+; RUN: llc -mtriple=x86_64-unknown-linux-gnu -relocation-model=pic \
+; RUN: -partition-static-data-sections=true \
+; RUN: -data-sections=true -unique-section-names=false \
; RUN: %s -o - 2>&1 | FileCheck %s --check-prefixes=UNIQ,COMMON --dump-input=always
; This RUN command sets `-data-sections=false -unique-section-names=false`.
-; RUN: llc -mtriple=x86_64-unknown-linux-gnu -enable-split-machine-functions \
-; RUN: -partition-static-data-sections=true -data-sections=false \
-; RUN: -unique-section-names=false -relocation-model=pic \
+; RUN: llc -mtriple=x86_64-unknown-linux-gnu -relocation-model=pic \
+; RUN: -partition-static-data-sections=true \
+; RUN: -data-sections=false -unique-section-names=false \
; RUN: %s -o - 2>&1 | FileCheck %s --check-prefixes=AGG,COMMON --dump-input=always
; For @.str and @.str.1
@@ -42,19 +42,19 @@ target triple = "x86_64-unknown-linux-gnu"
; For @hot_relro_array
; COMMON: .type hot_relro_array, at object
; SYM-NEXT: .section .data.rel.ro.hot.hot_relro_array
-; UNIQ-NEXT: .section .data.rel.ro.hot.,"aw", at progbits,unique,3
+; UNIQ-NEXT: .section .data.rel.ro.hot.,"aw", at progbits,unique,1
; AGG-NEXT: .section .data.rel.ro.hot.,"aw", at progbits
; For @hot_data, which is accessed by {cold_func, unprofiled_func, hot_func}.
; COMMON: .type hot_data, at object
; SYM-NEXT: .section .data.hot.hot_data,"aw", at progbits
-; UNIQ-NEXT: .section .data.hot.,"aw", at progbits,unique,4
+; UNIQ-NEXT: .section .data.hot.,"aw", at progbits,unique,2
; AGG-NEXT: .section .data.hot.,"aw", at progbits
; For @hot_bss, which is accessed by {unprofiled_func, hot_func}.
; COMMON: .type hot_bss, at object
; SYM-NEXT: .section .bss.hot.hot_bss,"aw", at nobits
-; UNIQ-NEXT: .section .bss.hot.,"aw", at nobits,unique,5
+; UNIQ-NEXT: .section .bss.hot.,"aw", at nobits,unique,3
; AGG-NEXT: .section .bss.hot.,"aw", at nobits
; For @.str.2
@@ -68,13 +68,13 @@ target triple = "x86_64-unknown-linux-gnu"
; For @cold_bss
; COMMON: .type cold_bss, at object
; SYM-NEXT: .section .bss.unlikely.cold_bss,"aw", at nobits
-; UNIQ-NEXT: .section .bss.unlikely.,"aw", at nobits,unique,6
+; UNIQ-NEXT: .section .bss.unlikely.,"aw", at nobits,unique,4
; AGG-NEXT: .section .bss.unlikely.,"aw", at nobits
; For @cold_data
; COMMON: .type cold_data, at object
; SYM-NEXT: .section .data.unlikely.cold_data,"aw", at progbits
-; UNIQ-NEXT: .section .data.unlikely.,"aw", at progbits,unique,7
+; UNIQ-NEXT: .section .data.unlikely.,"aw", at progbits,unique,5
; AGG-NEXT: .section .data.unlikely.,"aw", at progbits
; For @cold_data_custom_foo_section
@@ -87,7 +87,7 @@ target triple = "x86_64-unknown-linux-gnu"
; For @cold_relro_array
; COMMON: .type cold_relro_array, at object
; SYM-NEXT: .section .data.rel.ro.unlikely.cold_relro_array,"aw", at progbits
-; UNIQ-NEXT: .section .data.rel.ro.unlikely.,"aw", at progbits,unique,8
+; UNIQ-NEXT: .section .data.rel.ro.unlikely.,"aw", at progbits,unique,6
; AGG-NEXT: .section .data.rel.ro.unlikely.,"aw", at progbits
; Currently static-data-splitter only analyzes access from code.
@@ -97,19 +97,19 @@ target triple = "x86_64-unknown-linux-gnu"
; For @bss2
; COMMON: .type bss2, at object
; SYM-NEXT: .section .bss.unlikely.bss2,"aw", at nobits
-; UNIQ-NEXT: .section .bss.unlikely.,"aw", at nobits,unique,9
+; UNIQ-NEXT: .section .bss.unlikely.,"aw", at nobits,unique,7
; AGG-NEXT: .section .bss.unlikely.,"aw", at nobits
; For @data3
; COMMON: .type data3, at object
; SYM-NEXT: .section .data.unlikely.data3,"aw", at progbits
-; UNIQ-NEXT: .section .data.unlikely.,"aw", at progbits,unique,10
+; UNIQ-NEXT: .section .data.unlikely.,"aw", at progbits,unique,8
; AGG-NEXT: .section .data.unlikely.,"aw", at progbits
; For @data_with_unknown_hotness
; SYM: .type .Ldata_with_unknown_hotness, at object # @data_with_unknown_hotness
; SYM: .section .data..Ldata_with_unknown_hotness,"aw", at progbits
-; UNIQ: .section .data,"aw", at progbits,unique,11
+; UNIQ: .section .data,"aw", at progbits,unique,9
; The `.section` directive is omitted for .data with -unique-section-names=false.
; See MCSectionELF::shouldOmitSectionDirective for the implementation details.
; AGG: .data
diff --git a/llvm/test/CodeGen/X86/jump-table-partition.ll b/llvm/test/CodeGen/X86/jump-table-partition.ll
index 0d76f8a5a91ed..40dbc8131e22b 100644
--- a/llvm/test/CodeGen/X86/jump-table-partition.ll
+++ b/llvm/test/CodeGen/X86/jump-table-partition.ll
@@ -13,19 +13,19 @@
; STAT: 2 static-data-splitter - Number of hot jump tables seen
; STAT: 2 static-data-splitter - Number of jump tables with unknown hotness
-; RUN: llc -mtriple=x86_64-unknown-linux-gnu -enable-split-machine-functions \
-; RUN: -partition-static-data-sections=true -function-sections=true \
-; RUN: -min-jump-table-entries=2 -unique-section-names=false \
+; RUN: llc -mtriple=x86_64-unknown-linux-gnu -partition-static-data-sections \
+; RUN: -function-sections -unique-section-names=false \
+; RUN: -min-jump-table-entries=2 \
; RUN: %s -o - 2>&1 | FileCheck %s --check-prefixes=NUM,JT
; Section names will optionally have `.<func>` if -function-sections is enabled.
-; RUN: llc -mtriple=x86_64-unknown-linux-gnu -enable-split-machine-functions \
-; RUN: -partition-static-data-sections=true -function-sections=true \
-; RUN: -min-jump-table-entries=2 %s -o - 2>&1 | FileCheck %s --check-prefixes=FUNC,JT
+; RUN: llc -mtriple=x86_64-unknown-linux-gnu -partition-static-data-sections \
+; RUN: -function-sections -min-jump-table-entries=2 \
+; RUN: %s -o - 2>&1 | FileCheck %s --check-prefixes=FUNC,JT
-; RUN: llc -mtriple=x86_64-unknown-linux-gnu -enable-split-machine-functions \
-; RUN: -partition-static-data-sections=true -function-sections=false \
-; RUN: -min-jump-table-entries=2 %s -o - 2>&1 | FileCheck %s --check-prefixes=FUNCLESS,JT
+; RUN: llc -mtriple=x86_64-unknown-linux-gnu -partition-static-data-sections \
+; RUN: -function-sections=false -min-jump-table-entries=2 \
+; RUN: %s -o - 2>&1 | FileCheck %s --check-prefixes=FUNCLESS,JT
; In function @foo, the 2 switch instructions to jt0.* and jt1.* are placed in
; hot-prefixed sections, and the 2 switch instructions to jt2.* and jt3.* are
>From 9a7012e388ac611fa805dbf1e2282bae0a7495f1 Mon Sep 17 00:00:00 2001
From: mingmingl <mingmingl at google.com>
Date: Tue, 8 Apr 2025 01:44:37 +0000
Subject: [PATCH 2/2] simplify code as suggested
---
llvm/lib/CodeGen/TargetPassConfig.cpp | 18 +++++++-----------
1 file changed, 7 insertions(+), 11 deletions(-)
diff --git a/llvm/lib/CodeGen/TargetPassConfig.cpp b/llvm/lib/CodeGen/TargetPassConfig.cpp
index 45fae653e4181..1bf6621cdf791 100644
--- a/llvm/lib/CodeGen/TargetPassConfig.cpp
+++ b/llvm/lib/CodeGen/TargetPassConfig.cpp
@@ -1235,11 +1235,9 @@ void TargetPassConfig::addMachinePasses() {
addPass(createMIRAddFSDiscriminatorsPass(
sampleprof::FSDiscriminatorPass::PassLast));
- bool MIRProfileLoaderPassEnabled = false;
- auto EnableMIRProfileLoaderPass = [&]() {
- if (MIRProfileLoaderPassEnabled)
- return;
-
+ if (TM->Options.EnableMachineFunctionSplitter ||
+ EnableMachineFunctionSplitter || SplitStaticData ||
+ TM->Options.EnableStaticDataPartitioning) {
const std::string ProfileFile = getFSProfileFile(TM);
if (!ProfileFile.empty()) {
if (EnableFSDiscriminator) {
@@ -1254,20 +1252,18 @@ void TargetPassConfig::addMachinePasses() {
"performance.\n";
}
}
- MIRProfileLoaderPassEnabled = true;
- };
+ }
+
// Machine function splitter uses the basic block sections feature.
// When used along with `-basic-block-sections=`, the basic-block-sections
// feature takes precedence. This means functions eligible for
// basic-block-sections optimizations (`=all`, or `=list=` with function
// included in the list profile) will get that optimization instead.
if (TM->Options.EnableMachineFunctionSplitter ||
- EnableMachineFunctionSplitter) {
- EnableMIRProfileLoaderPass();
+ EnableMachineFunctionSplitter)
addPass(createMachineFunctionSplitterPass());
- }
+
if (SplitStaticData || TM->Options.EnableStaticDataPartitioning) {
- EnableMIRProfileLoaderPass();
// The static data splitter pass is a machine function pass. and
// static data annotator pass is a module-wide pass. See the file comment
// in StaticDataAnnotator.cpp for the motivation.
More information about the llvm-commits
mailing list