Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/include/clang/Basic/CodeGenOptions.def
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ CODEGENOPT(DisableBlockSignatureString, 1, 0) ///< Set when -fdisable-block-sign
CODEGENOPT(HIPSaveKernelArgName, 1, 0) ///< Set when -fhip-kernel-arg-name is enabled.
CODEGENOPT(UniqueInternalLinkageNames, 1, 0) ///< Internal Linkage symbols get unique names.
CODEGENOPT(SplitMachineFunctions, 1, 0) ///< Split machine functions using profile information.
CODEGENOPT(PartitionStaticDataSections, 1,
0) /// < Partition static data sections using profile information.
CODEGENOPT(PPCUseFullRegisterNames, 1, 0) ///< Print full register names in assembly
CODEGENOPT(X86RelaxRelocations, 1, 1) ///< -Wa,-mrelax-relocations={yes,no}
CODEGENOPT(X86Sse2Avx , 1, 0) ///< -Wa,-msse2avx
Expand Down
6 changes: 6 additions & 0 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -4385,6 +4385,12 @@ defm split_machine_functions: BoolFOption<"split-machine-functions",
NegFlag<SetFalse, [], [ClangOption], "Disable">,
BothFlags<[], [ClangOption], " late function splitting using profile information (x86 and aarch64 ELF)">>;

defm partition_static_data_sections: BoolFOption<"partition-static-data-sections",
CodeGenOpts<"PartitionStaticDataSections">, DefaultFalse,
PosFlag<SetTrue, [], [ClangOption, CC1Option], "Enable">,
NegFlag<SetFalse, [], [ClangOption], "Disable">,
BothFlags<[], [ClangOption], " partition static data sections using profile information (x86 and aarch64 ELF)">>;

defm strict_return : BoolFOption<"strict-return",
CodeGenOpts<"StrictReturn">, DefaultTrue,
NegFlag<SetFalse, [], [ClangOption, CC1Option],
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/CodeGen/BackendUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,8 @@ static bool initTargetOptions(const CompilerInstance &CI,
}

Options.EnableMachineFunctionSplitter = CodeGenOpts.SplitMachineFunctions;
Options.EnableStaticDataPartitioning =
CodeGenOpts.PartitionStaticDataSections;
Options.FunctionSections = CodeGenOpts.FunctionSections;
Options.DataSections = CodeGenOpts.DataSections;
Options.IgnoreXCOFFVisibility = LangOpts.IgnoreXCOFFVisibility;
Expand Down
14 changes: 14 additions & 0 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6401,6 +6401,20 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
}
}

if (Arg *A =
Args.getLastArg(options::OPT_fpartition_static_data_sections,
options::OPT_fno_partition_static_data_sections)) {
if (!A->getOption().matches(
options::OPT_fno_partition_static_data_sections)) {
// This codegen pass is only available on x86 and AArch64 ELF targets.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If someone interested in using this on other backends comes across this comment, where should they look to understand what needs to be done?

if ((Triple.isX86() || Triple.isAArch64()) && Triple.isOSBinFormatELF())
A->render(Args, CmdArgs);
else
D.Diag(diag::err_drv_unsupported_opt_for_target)
<< A->getAsString(Args) << TripleStr;
}
}

Args.AddLastArg(CmdArgs, options::OPT_finstrument_functions,
options::OPT_finstrument_functions_after_inlining,
options::OPT_finstrument_function_entry_bare);
Expand Down
8 changes: 8 additions & 0 deletions clang/lib/Driver/ToolChains/CommonArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,14 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args,
"-split-machine-functions"));
}

if (auto *A =
Args.getLastArg(options::OPT_fpartition_static_data_sections,
options::OPT_fno_partition_static_data_sections)) {
if (A->getOption().matches(options::OPT_fpartition_static_data_sections))
CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) +
"-partition-static-data-sections"));
}

if (Arg *A = getLastProfileSampleUseArg(Args)) {
StringRef FName = A->getValue();
if (!llvm::sys::fs::exists(FName))
Expand Down
15 changes: 15 additions & 0 deletions clang/test/Driver/fpartition-static-data-sections.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// RUN: %clang -### --target=x86_64 -fpartition-static-data-sections %s 2>&1 | FileCheck %s --check-prefixes=OPT
// RUN: %clang -### --target=aarch64 -fpartition-static-data-sections %s 2>&1 | FileCheck %s --check-prefixes=OPT

// RUN: not %clang -### --target=arm -fpartition-static-data-sections %s 2>&1 | FileCheck %s --check-prefixes=ERR

// 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"

// RUN: %clang -### --target=x86_64-linux -flto -fpartition-static-data-sections %s 2>&1 | FileCheck %s --check-prefix=LTO
// 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"

// OPT: "-fpartition-static-data-sections"

// ERR: error: unsupported option '-fpartition-static-data-sections' for target

// LTO: "-plugin-opt=-partition-static-data-sections"
15 changes: 15 additions & 0 deletions clang/test/Driver/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// RUN: %clang -### --target=x86_64 -fpartition-static-data-sections %s 2>&1 | FileCheck %s --check-prefixes=OPT
// RUN: %clang -### --target=aarch64 -fpartition-static-data-sections %s 2>&1 | FileCheck %s --check-prefixes=OPT

// RUN: not %clang -### --target=arm -fpartition-static-data-sections %s 2>&1 | FileCheck %s --check-prefixes=ERR

// 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"

// RUN: %clang -### --target=x86_64-linux -flto -fpartition-static-data-sections %s 2>&1 | FileCheck %s --check-prefix=LTO
// 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"

// OPT: "-fpartition-static-data-sections"

// ERR: error: unsupported option '-fpartition-static-data-sections' for target

// LTO: "-plugin-opt=-partition-static-data-sections"