Skip to content

Commit 1911a50

Browse files
authored
Deprecate the -fbasic-block-sections=labels option. (#107494)
This feature is supported via the newer option `-fbasic-block-address-map`. Using the old option still works by delegating to the newer option, while a warning is printed to show deprecation.
1 parent 6786928 commit 1911a50

23 files changed

+48
-79
lines changed

clang/docs/UsersManual.rst

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2369,14 +2369,16 @@ are listed below.
23692369
$ cd $P/bar && clang -c -funique-internal-linkage-names name_conflict.c
23702370
$ cd $P && clang foo/name_conflict.o && bar/name_conflict.o
23712371
2372-
.. option:: -fbasic-block-sections=[labels, all, list=<arg>, none]
2372+
.. option:: -f[no]-basic-block-address-map:
2373+
Emits a ``SHT_LLVM_BB_ADDR_MAP`` section which includes address offsets for each
2374+
basic block in the program, relative to the parent function address.
2375+
2376+
2377+
.. option:: -fbasic-block-sections=[all, list=<arg>, none]
23732378

23742379
Controls how Clang emits text sections for basic blocks. With values ``all``
23752380
and ``list=<arg>``, each basic block or a subset of basic blocks can be placed
2376-
in its own unique section. With the "labels" value, normal text sections are
2377-
emitted, but a ``.bb_addr_map`` section is emitted which includes address
2378-
offsets for each basic block in the program, relative to the parent function
2379-
address.
2381+
in its own unique section.
23802382

23812383
With the ``list=<arg>`` option, a file containing the subset of basic blocks
23822384
that need to placed in unique sections can be specified. The format of the

clang/include/clang/Basic/CodeGenOptions.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,13 @@ class CodeGenOptions : public CodeGenOptionsBase {
107107

108108
// This field stores one of the allowed values for the option
109109
// -fbasic-block-sections=. The allowed values with this option are:
110-
// {"labels", "all", "list=<file>", "none"}.
110+
// {"all", "list=<file>", "none"}.
111111
//
112-
// "labels": Only generate basic block symbols (labels) for all basic
113-
// blocks, do not generate unique sections for basic blocks.
114-
// Use the machine basic block id in the symbol name to
115-
// associate profile info from virtual address to machine
116-
// basic block.
117112
// "all" : Generate basic block sections for all basic blocks.
118113
// "list=<file>": Generate basic block sections for a subset of basic blocks.
119114
// The functions and the machine basic block ids are specified
120115
// in the file.
121-
// "none": Disable sections/labels for basic blocks.
116+
// "none": Disable sections for basic blocks.
122117
std::string BBSections;
123118

124119
// If set, override the default value of MCAsmInfo::BinutilsVersion. If

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4244,8 +4244,8 @@ defm basic_block_address_map : BoolFOption<"basic-block-address-map",
42444244
def fbasic_block_sections_EQ : Joined<["-"], "fbasic-block-sections=">, Group<f_Group>,
42454245
Visibility<[ClangOption, CC1Option, CC1AsOption]>,
42464246
HelpText<"Place each function's basic blocks in unique sections (ELF Only)">,
4247-
DocBrief<[{Generate labels for each basic block or place each basic block or a subset of basic blocks in its own section.}]>,
4248-
Values<"all,labels,none,list=">,
4247+
DocBrief<[{Place each basic block or a subset of basic blocks in its own section.}]>,
4248+
Values<"all,none,list=">,
42494249
MarshallingInfoString<CodeGenOpts<"BBSections">, [{"none"}]>;
42504250
defm data_sections : BoolFOption<"data-sections",
42514251
CodeGenOpts<"DataSections">, DefaultFalse,

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,6 @@ static bool initTargetOptions(DiagnosticsEngine &Diags,
429429
Options.BBSections =
430430
llvm::StringSwitch<llvm::BasicBlockSection>(CodeGenOpts.BBSections)
431431
.Case("all", llvm::BasicBlockSection::All)
432-
.Case("labels", llvm::BasicBlockSection::Labels)
433432
.StartsWith("list=", llvm::BasicBlockSection::List)
434433
.Case("none", llvm::BasicBlockSection::None)
435434
.Default(llvm::BasicBlockSection::None);

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6228,9 +6228,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
62286228

62296229
if (Arg *A = Args.getLastArg(options::OPT_fbasic_block_sections_EQ)) {
62306230
StringRef Val = A->getValue();
6231-
if (Triple.isX86() && Triple.isOSBinFormatELF()) {
6232-
if (Val != "all" && Val != "labels" && Val != "none" &&
6233-
!Val.starts_with("list="))
6231+
if (Val == "labels") {
6232+
D.Diag(diag::warn_drv_deprecated_arg)
6233+
<< A->getAsString(Args) << /*hasReplacement=*/true
6234+
<< "-fbasic-block-address-map";
6235+
CmdArgs.push_back("-fbasic-block-address-map");
6236+
} else if (Triple.isX86() && Triple.isOSBinFormatELF()) {
6237+
if (Val != "all" && Val != "none" && !Val.starts_with("list="))
62346238
D.Diag(diag::err_drv_invalid_value)
62356239
<< A->getAsString(Args) << A->getValue();
62366240
else

clang/test/Driver/fbasic-block-sections.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
// CHECK-OPT-NONE: "-fbasic-block-sections=none"
2323
// CHECK-OPT-ALL: "-fbasic-block-sections=all"
2424
// CHECK-OPT-LIST: "-fbasic-block-sections={{[^ ]*}}fbasic-block-sections.c"
25-
// CHECK-OPT-LABELS: "-fbasic-block-sections=labels"
25+
// CHECK-OPT-LABELS: warning: argument '-fbasic-block-sections=labels' is deprecated, use '-fbasic-block-address-map' instead
26+
// CHECK-OPT-LABELS: "-fbasic-block-address-map"
2627
// CHECK-TRIPLE: error: unsupported option '-fbasic-block-sections=all' for target
2728
// CHECK-INVALID-VALUE: error: invalid value {{[^ ]*}} in '-fbasic-block-sections={{.*}}'
2829
// CHECK-OPT-NULL-LIST: "-fbasic-block-sections=list="

llvm/docs/CommandGuide/llvm-objdump.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ OPTIONS
272272
When printing a PC-relative global symbol reference, print it as an offset from the leading symbol.
273273

274274
When a bb-address-map section is present (i.e., the object file is built with
275-
``-fbasic-block-sections=labels``), labels are retrieved from that section
275+
``-fbasic-block-address-map``), labels are retrieved from that section
276276
instead. If a pgo-analysis-map is present alongside the bb-address-map, any
277277
available analyses are printed after the relevant block label. By default,
278278
any analysis with a special representation (i.e. BlockFrequency,

llvm/docs/Extensions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ the symbol that belongs to the partition. It may be constructed as follows:
401401
This section stores the binary address of basic blocks along with other related
402402
metadata. This information can be used to map binary profiles (like perf
403403
profiles) directly to machine basic blocks.
404-
This section is emitted with ``-basic-block-sections=labels`` and will contain
404+
This section is emitted with ``-basic-block-address-map`` and will contain
405405
a BB address map table for every function.
406406

407407
The ``SHT_LLVM_BB_ADDR_MAP`` type provides backward compatibility to allow

llvm/include/llvm/CodeGen/MachineFunction.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -699,11 +699,6 @@ class LLVM_ABI MachineFunction {
699699
BBSectionsType == BasicBlockSection::Preset);
700700
}
701701

702-
/// Returns true if basic block labels are to be generated for this function.
703-
bool hasBBLabels() const {
704-
return BBSectionsType == BasicBlockSection::Labels;
705-
}
706-
707702
void setBBSectionsType(BasicBlockSection V) { BBSectionsType = V; }
708703

709704
/// Assign IsBeginSection IsEndSection fields for basic blocks in this

llvm/include/llvm/Target/TargetOptions.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@ namespace llvm {
6464
List, // Get list of functions & BBs from a file. Selectively enables
6565
// basic block sections for a subset of basic blocks which can be
6666
// used to control object size bloats from creating sections.
67-
Labels, // Do not use Basic Block Sections but label basic blocks. This
68-
// is useful when associating profile counts from virtual addresses
69-
// to basic blocks.
7067
Preset, // Similar to list but the blocks are identified by passes which
7168
// seek to use Basic Block Sections, e.g. MachineFunctionSplitter.
7269
// This option cannot be set via the command line.

0 commit comments

Comments
 (0)