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.
This commit is contained in:
Rahman Lavaee
2024-09-25 12:03:38 -07:00
committed by GitHub
parent 6786928c4f
commit 1911a50fae
23 changed files with 48 additions and 79 deletions

View File

@@ -2369,14 +2369,16 @@ are listed below.
$ cd $P/bar && clang -c -funique-internal-linkage-names name_conflict.c
$ cd $P && clang foo/name_conflict.o && bar/name_conflict.o
.. option:: -fbasic-block-sections=[labels, all, list=<arg>, none]
.. option:: -f[no]-basic-block-address-map:
Emits a ``SHT_LLVM_BB_ADDR_MAP`` section which includes address offsets for each
basic block in the program, relative to the parent function address.
.. option:: -fbasic-block-sections=[all, list=<arg>, none]
Controls how Clang emits text sections for basic blocks. With values ``all``
and ``list=<arg>``, each basic block or a subset of basic blocks can be placed
in its own unique section. With the "labels" value, normal text sections are
emitted, but a ``.bb_addr_map`` section is emitted which includes address
offsets for each basic block in the program, relative to the parent function
address.
in its own unique section.
With the ``list=<arg>`` option, a file containing the subset of basic blocks
that need to placed in unique sections can be specified. The format of the

View File

@@ -107,18 +107,13 @@ public:
// This field stores one of the allowed values for the option
// -fbasic-block-sections=. The allowed values with this option are:
// {"labels", "all", "list=<file>", "none"}.
// {"all", "list=<file>", "none"}.
//
// "labels": Only generate basic block symbols (labels) for all basic
// blocks, do not generate unique sections for basic blocks.
// Use the machine basic block id in the symbol name to
// associate profile info from virtual address to machine
// basic block.
// "all" : Generate basic block sections for all basic blocks.
// "list=<file>": Generate basic block sections for a subset of basic blocks.
// The functions and the machine basic block ids are specified
// in the file.
// "none": Disable sections/labels for basic blocks.
// "none": Disable sections for basic blocks.
std::string BBSections;
// If set, override the default value of MCAsmInfo::BinutilsVersion. If

View File

@@ -4244,8 +4244,8 @@ defm basic_block_address_map : BoolFOption<"basic-block-address-map",
def fbasic_block_sections_EQ : Joined<["-"], "fbasic-block-sections=">, Group<f_Group>,
Visibility<[ClangOption, CC1Option, CC1AsOption]>,
HelpText<"Place each function's basic blocks in unique sections (ELF Only)">,
DocBrief<[{Generate labels for each basic block or place each basic block or a subset of basic blocks in its own section.}]>,
Values<"all,labels,none,list=">,
DocBrief<[{Place each basic block or a subset of basic blocks in its own section.}]>,
Values<"all,none,list=">,
MarshallingInfoString<CodeGenOpts<"BBSections">, [{"none"}]>;
defm data_sections : BoolFOption<"data-sections",
CodeGenOpts<"DataSections">, DefaultFalse,

View File

@@ -429,7 +429,6 @@ static bool initTargetOptions(DiagnosticsEngine &Diags,
Options.BBSections =
llvm::StringSwitch<llvm::BasicBlockSection>(CodeGenOpts.BBSections)
.Case("all", llvm::BasicBlockSection::All)
.Case("labels", llvm::BasicBlockSection::Labels)
.StartsWith("list=", llvm::BasicBlockSection::List)
.Case("none", llvm::BasicBlockSection::None)
.Default(llvm::BasicBlockSection::None);

View File

@@ -6228,9 +6228,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
if (Arg *A = Args.getLastArg(options::OPT_fbasic_block_sections_EQ)) {
StringRef Val = A->getValue();
if (Triple.isX86() && Triple.isOSBinFormatELF()) {
if (Val != "all" && Val != "labels" && Val != "none" &&
!Val.starts_with("list="))
if (Val == "labels") {
D.Diag(diag::warn_drv_deprecated_arg)
<< A->getAsString(Args) << /*hasReplacement=*/true
<< "-fbasic-block-address-map";
CmdArgs.push_back("-fbasic-block-address-map");
} else if (Triple.isX86() && Triple.isOSBinFormatELF()) {
if (Val != "all" && Val != "none" && !Val.starts_with("list="))
D.Diag(diag::err_drv_invalid_value)
<< A->getAsString(Args) << A->getValue();
else

View File

@@ -22,7 +22,8 @@
// CHECK-OPT-NONE: "-fbasic-block-sections=none"
// CHECK-OPT-ALL: "-fbasic-block-sections=all"
// CHECK-OPT-LIST: "-fbasic-block-sections={{[^ ]*}}fbasic-block-sections.c"
// CHECK-OPT-LABELS: "-fbasic-block-sections=labels"
// CHECK-OPT-LABELS: warning: argument '-fbasic-block-sections=labels' is deprecated, use '-fbasic-block-address-map' instead
// CHECK-OPT-LABELS: "-fbasic-block-address-map"
// CHECK-TRIPLE: error: unsupported option '-fbasic-block-sections=all' for target
// CHECK-INVALID-VALUE: error: invalid value {{[^ ]*}} in '-fbasic-block-sections={{.*}}'
// CHECK-OPT-NULL-LIST: "-fbasic-block-sections=list="

View File

@@ -272,7 +272,7 @@ OPTIONS
When printing a PC-relative global symbol reference, print it as an offset from the leading symbol.
When a bb-address-map section is present (i.e., the object file is built with
``-fbasic-block-sections=labels``), labels are retrieved from that section
``-fbasic-block-address-map``), labels are retrieved from that section
instead. If a pgo-analysis-map is present alongside the bb-address-map, any
available analyses are printed after the relevant block label. By default,
any analysis with a special representation (i.e. BlockFrequency,

View File

@@ -401,7 +401,7 @@ the symbol that belongs to the partition. It may be constructed as follows:
This section stores the binary address of basic blocks along with other related
metadata. This information can be used to map binary profiles (like perf
profiles) directly to machine basic blocks.
This section is emitted with ``-basic-block-sections=labels`` and will contain
This section is emitted with ``-basic-block-address-map`` and will contain
a BB address map table for every function.
The ``SHT_LLVM_BB_ADDR_MAP`` type provides backward compatibility to allow

View File

@@ -699,11 +699,6 @@ public:
BBSectionsType == BasicBlockSection::Preset);
}
/// Returns true if basic block labels are to be generated for this function.
bool hasBBLabels() const {
return BBSectionsType == BasicBlockSection::Labels;
}
void setBBSectionsType(BasicBlockSection V) { BBSectionsType = V; }
/// Assign IsBeginSection IsEndSection fields for basic blocks in this

View File

@@ -64,9 +64,6 @@ namespace llvm {
List, // Get list of functions & BBs from a file. Selectively enables
// basic block sections for a subset of basic blocks which can be
// used to control object size bloats from creating sections.
Labels, // Do not use Basic Block Sections but label basic blocks. This
// is useful when associating profile counts from virtual addresses
// to basic blocks.
Preset, // Similar to list but the blocks are identified by passes which
// seek to use Basic Block Sections, e.g. MachineFunctionSplitter.
// This option cannot be set via the command line.

View File

@@ -1432,7 +1432,7 @@ void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {
OutStreamer->AddComment("BB id");
// Emit the BB ID for this basic block.
// We only emit BaseID since CloneID is unset for
// basic-block-sections=labels.
// -basic-block-adress-map.
// TODO: Emit the full BBID when labels and sections can be mixed
// together.
OutStreamer->emitULEB128IntValue(MBB.getBBID()->BaseID);
@@ -1866,7 +1866,7 @@ void AsmPrinter::emitFunctionBody() {
// We must emit temporary symbol for the end of this basic block, if either
// we have BBLabels enabled or if this basic blocks marks the end of a
// section.
if (MF->hasBBLabels() || MF->getTarget().Options.BBAddrMap ||
if (MF->getTarget().Options.BBAddrMap ||
(MAI->hasDotTypeDotSizeDirective() && MBB.isEndSection()))
OutStreamer->emitLabel(MBB.getEndSymbol());
@@ -2021,7 +2021,7 @@ void AsmPrinter::emitFunctionBody() {
// Emit section containing BB address offsets and their metadata, when
// BB labels are requested for this function. Skip empty functions.
if (HasAnyRealCode) {
if (MF->hasBBLabels() || MF->getTarget().Options.BBAddrMap)
if (MF->getTarget().Options.BBAddrMap)
emitBBAddrMapSection(*MF);
else if (PgoAnalysisMapFeatures.getBits() != 0)
MF->getContext().reportWarning(
@@ -2620,7 +2620,7 @@ void AsmPrinter::SetupMachineFunction(MachineFunction &MF) {
F.hasFnAttribute("xray-instruction-threshold") ||
needFuncLabels(MF, *this) || NeedsLocalForSize ||
MF.getTarget().Options.EmitStackSizeSection ||
MF.getTarget().Options.BBAddrMap || MF.hasBBLabels()) {
MF.getTarget().Options.BBAddrMap) {
CurrentFnBegin = createTempSymbol("func_begin");
if (NeedsLocalForSize)
CurrentFnSymForSize = CurrentFnBegin;
@@ -4155,8 +4155,7 @@ bool AsmPrinter::shouldEmitLabelForBasicBlock(
// With `-fbasic-block-sections=`, a label is needed for every non-entry block
// in the labels mode (option `=labels`) and every section beginning in the
// sections mode (`=all` and `=list=`).
if ((MF->hasBBLabels() || MF->getTarget().Options.BBAddrMap ||
MBB.isBeginSection()) &&
if ((MF->getTarget().Options.BBAddrMap || MBB.isBeginSection()) &&
!MBB.isEntryBlock())
return true;
// A label is needed for any block with at least one predecessor (when that

View File

@@ -311,11 +311,6 @@ bool BasicBlockSections::handleBBSections(MachineFunction &MF) {
// original layout positions and finding the original fallthroughs.
MF.RenumberBlocks();
if (BBSectionsType == BasicBlockSection::Labels) {
MF.setBBSectionsType(BBSectionsType);
return true;
}
DenseMap<UniqueBBID, BBClusterInfo> FuncClusterInfo;
if (BBSectionsType == BasicBlockSection::List) {
auto [HasProfile, ClusterInfo] =
@@ -382,8 +377,6 @@ bool BasicBlockSections::handleBBSections(MachineFunction &MF) {
// avoids the need to store basic block IDs in the BB address map section, since
// they can be determined implicitly.
bool BasicBlockSections::handleBBAddrMap(MachineFunction &MF) {
if (MF.getTarget().getBBSectionsType() == BasicBlockSection::Labels)
return false;
if (!MF.getTarget().Options.BBAddrMap)
return false;
MF.RenumberBlocks();

View File

@@ -525,8 +525,6 @@ llvm::BasicBlockSection
codegen::getBBSectionsMode(llvm::TargetOptions &Options) {
if (getBBSections() == "all")
return BasicBlockSection::All;
else if (getBBSections() == "labels")
return BasicBlockSection::Labels;
else if (getBBSections() == "none")
return BasicBlockSection::None;
else {

View File

@@ -780,7 +780,7 @@ bool MIParser::parseBasicBlockDefinition(
"' is not defined in the function '" +
MF.getName() + "'");
}
auto *MBB = MF.CreateMachineBasicBlock(BB);
auto *MBB = MF.CreateMachineBasicBlock(BB, BBID);
MF.insert(MF.end(), MBB);
bool WasInserted = MBBSlots.insert(std::make_pair(ID, MBB)).second;
if (!WasInserted)
@@ -799,13 +799,6 @@ bool MIParser::parseBasicBlockDefinition(
MBB->setSectionID(*SectionID);
MF.setBBSectionsType(BasicBlockSection::List);
}
if (BBID.has_value()) {
// BBSectionsType is set to `List` if any basic blocks has `SectionID`.
// Here, we set it to `Labels` if it hasn't been set above.
if (!MF.hasBBSections())
MF.setBBSectionsType(BasicBlockSection::Labels);
MBB->setBBID(BBID.value());
}
MBB->setCallFrameSize(CallFrameSize);
return false;
}

View File

@@ -569,9 +569,7 @@ MIRParserImpl::initializeMachineFunction(const yaml::MachineFunction &YamlMF,
return true;
}
// Check Basic Block Section Flags.
if (MF.getTarget().getBBSectionsType() == BasicBlockSection::Labels) {
MF.setBBSectionsType(BasicBlockSection::Labels);
} else if (MF.hasBBSections()) {
if (MF.hasBBSections()) {
MF.assignBeginEndSections();
}
PFS.SM = &SM;

View File

@@ -465,11 +465,9 @@ MachineFunction::CreateMachineBasicBlock(const BasicBlock *BB,
MachineBasicBlock *MBB =
new (BasicBlockRecycler.Allocate<MachineBasicBlock>(Allocator))
MachineBasicBlock(*this, BB);
// Set BBID for `-basic-block=sections=labels` and
// `-basic-block-sections=list` to allow robust mapping of profiles to basic
// blocks.
if (Target.getBBSectionsType() == BasicBlockSection::Labels ||
Target.Options.BBAddrMap ||
// Set BBID for `-basic-block-sections=list` and `-basic-block-address-map` to
// allow robust mapping of profiles to basic blocks.
if (Target.Options.BBAddrMap ||
Target.getBBSectionsType() == BasicBlockSection::List)
MBB->setBBID(BBID.has_value() ? *BBID : UniqueBBID{NextBBID++, 0});
return MBB;

View File

@@ -1,5 +1,5 @@
;; This test verifies that with -gc-empty-basic-blocks SHT_LLVM_BB_ADDR_MAP will not include entries for empty blocks.
; RUN: llc < %s -mtriple=x86_64 -O0 -basic-block-sections=labels -gc-empty-basic-blocks | FileCheck --check-prefix=CHECK %s
; RUN: llc < %s -mtriple=x86_64 -O0 -basic-block-address-map -gc-empty-basic-blocks | FileCheck --check-prefix=CHECK %s
define void @foo(i1 zeroext %0) nounwind {
br i1 %0, label %2, label %empty_block

View File

@@ -1,6 +1,6 @@
;; Verify that the BB address map is not emitted for empty functions.
; RUN: llc < %s -mtriple=x86_64 -basic-block-sections=labels | FileCheck %s --check-prefixes=CHECK,BASIC
; RUN: llc < %s -mtriple=x86_64 -basic-block-sections=labels -pgo-analysis-map=func-entry-count,bb-freq | FileCheck %s --check-prefixes=CHECK,PGO
; RUN: llc < %s -mtriple=x86_64 -basic-block-address-map | FileCheck %s --check-prefixes=CHECK,BASIC
; RUN: llc < %s -mtriple=x86_64 -basic-block-address-map -pgo-analysis-map=func-entry-count,bb-freq | FileCheck %s --check-prefixes=CHECK,PGO
define void @empty_func() {
entry:

View File

@@ -1,4 +1,3 @@
; RUN: llc < %s -mtriple=x86_64 -function-sections -basic-block-sections=labels | FileCheck %s
; RUN: llc < %s -mtriple=x86_64 -function-sections -basic-block-address-map | FileCheck %s
$_Z4fooTIiET_v = comdat any

View File

@@ -1,5 +1,5 @@
# Start after bbsections0-prepare and check that the BB address map is generated.
# RUN: llc -mtriple x86_64-unknown-linux-gnu -start-after=bbsections-prepare %s -o - | FileCheck %s -check-prefix=CHECK
# RUN: llc -mtriple x86_64-unknown-linux-gnu -start-after=bbsections-prepare -basic-block-address-map %s -o - | FileCheck %s -check-prefix=CHECK
# How to generate the input:
# foo.cc
@@ -9,7 +9,7 @@
# }
#
# clang -O0 -S -emit-llvm foo.cc
# llc < foo.ll -stop-after=bbsections-prepare -basic-block-sections=labels
# llc < foo.ll -stop-after=bbsections-prepare -basic-block-address-map
# CHECK: .section .llvm_bb_addr_map,"o",@llvm_bb_addr_map,.text
--- |

View File

@@ -1,13 +1,13 @@
; Check the basic block sections labels option
; RUN: llc < %s -mtriple=x86_64 -function-sections -unique-section-names=true -basic-block-sections=labels | FileCheck %s --check-prefixes=CHECK,BASIC
; RUN: llc < %s -mtriple=x86_64 -function-sections -unique-section-names=true -basic-block-address-map | FileCheck %s --check-prefixes=CHECK,BASIC
;; Also verify this holds for all PGO features enabled
; RUN: llc < %s -mtriple=x86_64 -function-sections -unique-section-names=true -basic-block-sections=labels -pgo-analysis-map=func-entry-count,bb-freq,br-prob | FileCheck %s --check-prefixes=CHECK,PGO-ALL,PGO-FEC,PGO-BBF,PGO-BRP
; RUN: llc < %s -mtriple=x86_64 -function-sections -unique-section-names=true -basic-block-address-map -pgo-analysis-map=func-entry-count,bb-freq,br-prob | FileCheck %s --check-prefixes=CHECK,PGO-ALL,PGO-FEC,PGO-BBF,PGO-BRP
;; Also verify that pgo extension only includes the enabled feature
; RUN: llc < %s -mtriple=x86_64 -function-sections -unique-section-names=true -basic-block-sections=labels -pgo-analysis-map=func-entry-count | FileCheck %s --check-prefixes=CHECK,PGO-FEC,FEC-ONLY
; RUN: llc < %s -mtriple=x86_64 -function-sections -unique-section-names=true -basic-block-sections=labels -pgo-analysis-map=bb-freq | FileCheck %s --check-prefixes=CHECK,PGO-BBF,BBF-ONLY
; RUN: llc < %s -mtriple=x86_64 -function-sections -unique-section-names=true -basic-block-sections=labels -pgo-analysis-map=br-prob | FileCheck %s --check-prefixes=CHECK,PGO-BRP,BRP-ONLY
; RUN: llc < %s -mtriple=x86_64 -function-sections -unique-section-names=true -basic-block-address-map -pgo-analysis-map=func-entry-count | FileCheck %s --check-prefixes=CHECK,PGO-FEC,FEC-ONLY
; RUN: llc < %s -mtriple=x86_64 -function-sections -unique-section-names=true -basic-block-address-map -pgo-analysis-map=bb-freq | FileCheck %s --check-prefixes=CHECK,PGO-BBF,BBF-ONLY
; RUN: llc < %s -mtriple=x86_64 -function-sections -unique-section-names=true -basic-block-address-map -pgo-analysis-map=br-prob | FileCheck %s --check-prefixes=CHECK,PGO-BRP,BRP-ONLY
define void @_Z3bazb(i1 zeroext, i1 zeroext) personality ptr @__gxx_personality_v0 !prof !0 {

View File

@@ -1,9 +1,7 @@
; Check the basic block sections labels option
; RUN: llc < %s -mtriple=x86_64 -function-sections -unique-section-names=true -basic-block-address-map | FileCheck %s --check-prefixes=CHECK,UNIQ
; RUN: llc < %s -mtriple=x86_64 -function-sections -unique-section-names=true -basic-block-sections=labels | FileCheck %s --check-prefixes=CHECK,UNIQ
; RUN: llc < %s -mtriple=x86_64 -function-sections -unique-section-names=false -basic-block-address-map | FileCheck %s --check-prefixes=CHECK,NOUNIQ
; RUN: llc < %s -mtriple=x86_64 -function-sections -unique-section-names=false -basic-block-sections=labels | FileCheck %s --check-prefixes=CHECK,NOUNIQ
; RUN: llc < %s -mtriple=x86_64 -function-sections -unique-section-names=true -basic-block-sections=labels -split-machine-functions | FileCheck %s --check-prefixes=CHECK,UNIQ
; RUN: llc < %s -mtriple=x86_64 -function-sections -unique-section-names=true -basic-block-address-map -split-machine-functions | FileCheck %s --check-prefixes=CHECK,UNIQ
define void @_Z3bazb(i1 zeroext, i1 zeroext) personality ptr @__gxx_personality_v0 {
br i1 %0, label %3, label %8

View File

@@ -1,5 +1,5 @@
; Stop after bbsections-prepare and check MIR output for section type.
; RUN: llc < %s -O0 -mtriple=x86_64-pc-linux -function-sections -basic-block-sections=labels -stop-after=bbsections-prepare | FileCheck %s -check-prefix=BBLABELS
; RUN: llc < %s -O0 -mtriple=x86_64-pc-linux -function-sections -basic-block-address-map -stop-after=bbsections-prepare | FileCheck %s -check-prefix=BBADDRMAP
; RUN: echo '!_Z3foob' > %t
; RUN: echo '!!1' >> %t
; RUN: echo '!!2' >> %t
@@ -33,7 +33,7 @@ define dso_local i32 @_Z3foob(i1 zeroext %0) {
; BBSECTIONS: bb.1 (%ir-block.7, bb_id 1)
; BBSECTIONS: bb.2 (%ir-block.8, bbsections 1, bb_id 2):
; BBLABELS: bb.0 (%ir-block.1, bb_id 0):
; BBLABELS: bb.1 (%ir-block.7, bb_id 1):
; BBLABELS: bb.2 (%ir-block.8, bb_id 2):
; BBLABELS: bb.3 (%ir-block.9, bb_id 3):
; BBADDRMAP: bb.0 (%ir-block.1, bb_id 0):
; BBADDRMAP: bb.1 (%ir-block.7, bb_id 1):
; BBADDRMAP: bb.2 (%ir-block.8, bb_id 2):
; BBADDRMAP: bb.3 (%ir-block.9, bb_id 3):