Skip to content

Commit 755b5d0

Browse files
[Clang]Add -fpartition-static-data-section
1 parent a368402 commit 755b5d0

File tree

7 files changed

+58
-0
lines changed

7 files changed

+58
-0
lines changed

clang/include/clang/Basic/CodeGenOptions.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ CODEGENOPT(DisableBlockSignatureString, 1, 0) ///< Set when -fdisable-block-sign
199199
CODEGENOPT(HIPSaveKernelArgName, 1, 0) ///< Set when -fhip-kernel-arg-name is enabled.
200200
CODEGENOPT(UniqueInternalLinkageNames, 1, 0) ///< Internal Linkage symbols get unique names.
201201
CODEGENOPT(SplitMachineFunctions, 1, 0) ///< Split machine functions using profile information.
202+
CODEGENOPT(PartitionStaticDataSections, 1,
203+
0) /// < Partition static data sections using profile information.
202204
CODEGENOPT(PPCUseFullRegisterNames, 1, 0) ///< Print full register names in assembly
203205
CODEGENOPT(X86RelaxRelocations, 1, 1) ///< -Wa,-mrelax-relocations={yes,no}
204206
CODEGENOPT(X86Sse2Avx , 1, 0) ///< -Wa,-msse2avx

clang/include/clang/Driver/Options.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4385,6 +4385,12 @@ defm split_machine_functions: BoolFOption<"split-machine-functions",
43854385
NegFlag<SetFalse, [], [ClangOption], "Disable">,
43864386
BothFlags<[], [ClangOption], " late function splitting using profile information (x86 and aarch64 ELF)">>;
43874387

4388+
defm partition_static_data_sections: BoolFOption<"partition-static-data-sections",
4389+
CodeGenOpts<"PartitionStaticDataSections">, DefaultFalse,
4390+
PosFlag<SetTrue, [], [ClangOption, CC1Option], "Enable">,
4391+
NegFlag<SetFalse, [], [ClangOption], "Disable">,
4392+
BothFlags<[], [ClangOption], " partition static data sections using profile information (x86 ELF)">>;
4393+
43884394
defm strict_return : BoolFOption<"strict-return",
43894395
CodeGenOpts<"StrictReturn">, DefaultTrue,
43904396
NegFlag<SetFalse, [], [ClangOption, CC1Option],

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,8 @@ static bool initTargetOptions(const CompilerInstance &CI,
442442
}
443443

444444
Options.EnableMachineFunctionSplitter = CodeGenOpts.SplitMachineFunctions;
445+
Options.EnableStaticDataPartitioning =
446+
CodeGenOpts.PartitionStaticDataSections;
445447
Options.FunctionSections = CodeGenOpts.FunctionSections;
446448
Options.DataSections = CodeGenOpts.DataSections;
447449
Options.IgnoreXCOFFVisibility = LangOpts.IgnoreXCOFFVisibility;

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6401,6 +6401,20 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
64016401
}
64026402
}
64036403

6404+
if (Arg *A =
6405+
Args.getLastArg(options::OPT_fpartition_static_data_sections,
6406+
options::OPT_fno_partition_static_data_sections)) {
6407+
if (!A->getOption().matches(
6408+
options::OPT_fno_partition_static_data_sections)) {
6409+
// This codegen pass is only available on x86 and AArch64 ELF targets.
6410+
if (Triple.isX86() && Triple.isOSBinFormatELF())
6411+
A->render(Args, CmdArgs);
6412+
else
6413+
D.Diag(diag::err_drv_unsupported_opt_for_target)
6414+
<< A->getAsString(Args) << TripleStr;
6415+
}
6416+
}
6417+
64046418
Args.AddLastArg(CmdArgs, options::OPT_finstrument_functions,
64056419
options::OPT_finstrument_functions_after_inlining,
64066420
options::OPT_finstrument_function_entry_bare);

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,14 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args,
10871087
"-split-machine-functions"));
10881088
}
10891089

1090+
if (auto *A =
1091+
Args.getLastArg(options::OPT_fpartition_static_data_sections,
1092+
options::OPT_fno_partition_static_data_sections)) {
1093+
if (A->getOption().matches(options::OPT_fpartition_static_data_sections))
1094+
CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) +
1095+
"-partition-static-data-sections"));
1096+
}
1097+
10901098
if (Arg *A = getLastProfileSampleUseArg(Args)) {
10911099
StringRef FName = A->getValue();
10921100
if (!llvm::sys::fs::exists(FName))
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %clang -### --target=x86_64 -fpartition-static-data-sections %s 2>&1 | FileCheck %s --check-prefixes=OPT
2+
// RUN: not %clang -### --target=aarch64 -fpartition-static-data-sections %s 2>&1 | FileCheck %s --check-prefixes=ERR
3+
4+
// RUN: %clang -### --target=x86_64 -fpartition-static-data-sections -fno-partition-static-data-sections %s 2>&1 | FileCheck %s --implicit-check-not="-fpartition-static-data-sections"
5+
6+
// RUN: %clang -### --target=x86_64-linux -flto -fpartition-static-data-sections %s 2>&1 | FileCheck %s --check-prefix=LTO
7+
// RUN: %clang -### --target=x86_64-linux -flto -fpartition-static-data-sections -fno-partition-static-data-sections %s 2>&1 | FileCheck %s --implicit-check-not="-plugin-opt=-fpartition-static-data-sections"
8+
9+
// OPT: "-fpartition-static-data-sections"
10+
11+
// ERR: error: unsupported option '-fpartition-static-data-sections' for target
12+
13+
// LTO: "-plugin-opt=-partition-static-data-sections"

clang/test/Driver/test.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %clang -### --target=x86_64 -fpartition-static-data-sections %s 2>&1 | FileCheck %s --check-prefixes=OPT
2+
// RUN: not %clang -### --target=aarch64 -fpartition-static-data-sections %s 2>&1 | FileCheck %s --check-prefixes=ERR
3+
4+
// RUN: %clang -### --target=x86_64 -fpartition-static-data-sections -fno-partition-static-data-sections %s 2>&1 | FileCheck %s --implicit-check-not="-fpartition-static-data-sections"
5+
6+
// RUN: %clang -### --target=x86_64-linux -flto -fpartition-static-data-sections %s 2>&1 | FileCheck %s --check-prefix=LTO
7+
// RUN: %clang -### --target=x86_64-linux -flto -fpartition-static-data-sections -fno-partition-static-data-sections %s 2>&1 | FileCheck %s --implicit-check-not="-plugin-opt=-fpartition-static-data-sections"
8+
9+
// OPT: "-fpartition-static-data-sections"
10+
11+
// ERR: error: unsupported option '-fpartition-static-data-sections' for target
12+
13+
// LTO: "-plugin-opt=-partition-static-data-sections"

0 commit comments

Comments
 (0)