Skip to content

Commit 639a0af

Browse files
1 parent 1911a50 commit 639a0af

23 files changed

+79
-48
lines changed

clang/docs/UsersManual.rst

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2369,16 +2369,14 @@ 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:: -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]
2372+
.. option:: -fbasic-block-sections=[labels, all, list=<arg>, none]
23782373

23792374
Controls how Clang emits text sections for basic blocks. With values ``all``
23802375
and ``list=<arg>``, each basic block or a subset of basic blocks can be placed
2381-
in its own unique section.
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.
23822380

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

clang/include/clang/Basic/CodeGenOptions.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,18 @@ 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-
// {"all", "list=<file>", "none"}.
110+
// {"labels", "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.
112117
// "all" : Generate basic block sections for all basic blocks.
113118
// "list=<file>": Generate basic block sections for a subset of basic blocks.
114119
// The functions and the machine basic block ids are specified
115120
// in the file.
116-
// "none": Disable sections for basic blocks.
121+
// "none": Disable sections/labels for basic blocks.
117122
std::string BBSections;
118123

119124
// 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<[{Place each basic block or a subset of basic blocks in its own section.}]>,
4248-
Values<"all,none,list=">,
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=">,
42494249
MarshallingInfoString<CodeGenOpts<"BBSections">, [{"none"}]>;
42504250
defm data_sections : BoolFOption<"data-sections",
42514251
CodeGenOpts<"DataSections">, DefaultFalse,

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ 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)
432433
.StartsWith("list=", llvm::BasicBlockSection::List)
433434
.Case("none", llvm::BasicBlockSection::None)
434435
.Default(llvm::BasicBlockSection::None);

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6228,13 +6228,9 @@ 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 (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="))
6231+
if (Triple.isX86() && Triple.isOSBinFormatELF()) {
6232+
if (Val != "all" && Val != "labels" && Val != "none" &&
6233+
!Val.starts_with("list="))
62386234
D.Diag(diag::err_drv_invalid_value)
62396235
<< A->getAsString(Args) << A->getValue();
62406236
else

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
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: warning: argument '-fbasic-block-sections=labels' is deprecated, use '-fbasic-block-address-map' instead
26-
// CHECK-OPT-LABELS: "-fbasic-block-address-map"
25+
// CHECK-OPT-LABELS: "-fbasic-block-sections=labels"
2726
// CHECK-TRIPLE: error: unsupported option '-fbasic-block-sections=all' for target
2827
// CHECK-INVALID-VALUE: error: invalid value {{[^ ]*}} in '-fbasic-block-sections={{.*}}'
2928
// 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-address-map``), labels are retrieved from that section
275+
``-fbasic-block-sections=labels``), 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-address-map`` and will contain
404+
This section is emitted with ``-basic-block-sections=labels`` 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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,11 @@ 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+
702707
void setBBSectionsType(BasicBlockSection V) { BBSectionsType = V; }
703708

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

llvm/include/llvm/Target/TargetOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ 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.
6770
Preset, // Similar to list but the blocks are identified by passes which
6871
// seek to use Basic Block Sections, e.g. MachineFunctionSplitter.
6972
// This option cannot be set via the command line.

0 commit comments

Comments
 (0)