Skip to content

Commit 8f36a13

Browse files
[Driver]Add cland and lld driver option, as well as llc CLI option
1 parent 8d3a985 commit 8f36a13

File tree

10 files changed

+48
-1
lines changed

10 files changed

+48
-1
lines changed

clang/include/clang/Basic/CodeGenOptions.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ CODEGENOPT(ForbidGuardVariables , 1, 0) ///< Issue errors if C++ guard variables
101101
///< are required.
102102
CODEGENOPT(FunctionSections , 1, 0) ///< Set when -ffunction-sections is enabled.
103103
CODEGENOPT(BBAddrMap , 1, 0) ///< Set when -fbasic-block-address-map is enabled.
104+
CODEGENOPT(SplitDataSections, 1,
105+
0) ///< Set when -fsplit-data-sections is enabled.
104106
CODEGENOPT(InstrumentFunctions , 1, 0) ///< Set when -finstrument-functions is
105107
///< enabled.
106108
CODEGENOPT(InstrumentFunctionsAfterInlining , 1, 0) ///< Set when

clang/include/clang/Driver/Options.td

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

4355+
defm split_data_sections: BoolFOption<"split-data-sections",
4356+
CodeGenOpts<"SplitDataSections">, DefaultFalse,
4357+
PosFlag<SetTrue, [], [ClangOption, CC1Option], "Enable">,
4358+
NegFlag<SetFalse, [], [ClangOption], "Disable">,
4359+
BothFlags<[], [ClangOption], "Split static data sections using profile information (x86 ELF)">>;
4360+
43554361
defm strict_return : BoolFOption<"strict-return",
43564362
CodeGenOpts<"StrictReturn">, DefaultTrue,
43574363
NegFlag<SetFalse, [], [ClangOption, CC1Option],

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ static bool initTargetOptions(DiagnosticsEngine &Diags,
441441
}
442442

443443
Options.EnableMachineFunctionSplitter = CodeGenOpts.SplitMachineFunctions;
444+
Options.EnableDataSectionSplitting = CodeGenOpts.SplitDataSections;
444445
Options.FunctionSections = CodeGenOpts.FunctionSections;
445446
Options.DataSections = CodeGenOpts.DataSections;
446447
Options.IgnoreXCOFFVisibility = LangOpts.IgnoreXCOFFVisibility;

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6355,6 +6355,17 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
63556355
}
63566356
}
63576357

6358+
if (Arg *A = Args.getLastArg(options::OPT_fsplit_data_sections,
6359+
options::OPT_fno_split_data_sections)) {
6360+
if (!A->getOption().matches(options::OPT_fno_split_data_sections)) {
6361+
if (Triple.isX86() && Triple.isOSBinFormatELF())
6362+
A->render(Args, CmdArgs);
6363+
else
6364+
D.Diag(diag::err_drv_unsupported_opt_for_target)
6365+
<< A->getAsString(Args) << TripleStr;
6366+
}
6367+
}
6368+
63586369
Args.AddLastArg(CmdArgs, options::OPT_finstrument_functions,
63596370
options::OPT_finstrument_functions_after_inlining,
63606371
options::OPT_finstrument_function_entry_bare);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// RUN: %clang -### --target=x86_64 -fprofile-use=default.profdata -fsplit-data-sections %s 2>&1 | FileCheck %s --check-prefixes=CHECK
2+
// RUN: not %clang -### --target=aarch64 -fprofile-use=default.profdata -fsplit-data-sections %s 2>&1 | FileCheck %s --check-prefixes=ERR
3+
4+
// CHECK: "-cc1" {{.*}} "-fsplit-data-sections"
5+
6+
// ERR: error: unsupported option '-fsplit-data-sections' for target 'aarch64'

lld/ELF/Config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,10 @@ struct Config {
491491
// If an input file matches a wildcard pattern, remap it to the value.
492492
llvm::SmallVector<std::pair<llvm::GlobPattern, llvm::StringRef>, 0>
493493
remapInputsWildcards;
494+
495+
// Propagated to TargetOptions in lto::Config.
496+
// If true, emit suffix for a static data section to indicate its hotness.
497+
bool ltoEmitStaticDataSectionSuffix = false;
494498
};
495499

496500
// Some index properties of a symbol are stored separately in this auxiliary

lld/ELF/Options.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,9 @@ defm lto_basic_block_address_map: BB<"lto-basic-block-address-map",
670670
defm lto_unique_basic_block_section_names: BB<"lto-unique-basic-block-section-names",
671671
"Give unique names to every basic block section for LTO",
672672
"Do not give unique names to every basic block section for LTO (default)">;
673+
defm lto_split_data_sections: BB<"lto-split-data-sections",
674+
"Split a static data section into a hot section and a non-hot one",
675+
"Do not split static data sections (default)">;
673676
defm shuffle_sections: EEq<"shuffle-sections",
674677
"Shuffle matched sections using the given seed before mapping them to the output sections. "
675678
"If -1, reverse the section order. If 0, use a random seed">,

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 getEnableDataSectionSplitting();
140+
139141
bool getEnableDebugEntryValues();
140142

141143
bool getValueTrackingVariableLocations();

llvm/include/llvm/Target/TargetOptions.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ namespace llvm {
146146
EmulatedTLS(false), EnableTLSDESC(false), EnableIPRA(false),
147147
EmitStackSizeSection(false), EnableMachineOutliner(false),
148148
EnableMachineFunctionSplitter(false), SupportsDefaultOutlining(false),
149-
EmitAddrsig(false), BBAddrMap(false), EmitCallSiteInfo(false),
149+
EmitAddrsig(false), BBAddrMap(false), EnableDataSectionSplitting(false), EmitCallSiteInfo(false),
150150
SupportsDebugEntryValues(false), EnableDebugEntryValues(false),
151151
ValueTrackingVariableLocations(false), ForceDwarfFrameSection(false),
152152
XRayFunctionIndex(true), DebugStrictDwarf(false), Hotpatch(false),
@@ -322,6 +322,9 @@ namespace llvm {
322322
// which can be used to map virtual addresses to machine basic blocks.
323323
unsigned BBAddrMap : 1;
324324

325+
// For a static data section, emit a section suffix to indicate its hotness.
326+
unsigned EnableDataSectionSplitting : 1;
327+
325328
/// Emit basic blocks into separate sections.
326329
BasicBlockSection BBSections = BasicBlockSection::None;
327330

llvm/lib/CodeGen/CommandFlags.cpp

Lines changed: 9 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, EnableDataSectionSplitting)
106107
CGOPT(bool, EnableDebugEntryValues)
107108
CGOPT(bool, ForceDwarfFrameSection)
108109
CGOPT(bool, XRayFunctionIndex)
@@ -480,6 +481,13 @@ codegen::RegisterCodeGenFlags::RegisterCodeGenFlags() {
480481
cl::init(false));
481482
CGBINDOPT(EnableMachineFunctionSplitter);
482483

484+
static cl::opt<bool> EnableDataSectionSplitting(
485+
"split-data-sections",
486+
cl::desc("Partition static data sections into hot and cold sections "
487+
"using profile information"),
488+
cl::init(false));
489+
CGBINDOPT(EnableDataSectionSplitting);
490+
483491
static cl::opt<bool> ForceDwarfFrameSection(
484492
"force-dwarf-frame-section",
485493
cl::desc("Always emit a debug frame section."), cl::init(false));
@@ -586,6 +594,7 @@ codegen::InitTargetOptionsFromCodeGenFlags(const Triple &TheTriple) {
586594
Options.ExceptionModel = getExceptionModel();
587595
Options.EmitStackSizeSection = getEnableStackSizeSection();
588596
Options.EnableMachineFunctionSplitter = getEnableMachineFunctionSplitter();
597+
Options.EnableDataSectionSplitting = getEnableDataSectionSplitting();
589598
Options.EmitAddrsig = getEnableAddrsig();
590599
Options.EmitCallSiteInfo = getEmitCallSiteInfo();
591600
Options.EnableDebugEntryValues = getEnableDebugEntryValues();

0 commit comments

Comments
 (0)