@@ -1053,7 +1053,7 @@ void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {
1053
1053
// Emit BB Information for each basic block in the funciton.
1054
1054
for (const MachineBasicBlock &MBB : MF) {
1055
1055
const MCSymbol *MBBSymbol =
1056
- MBB.pred_empty () ? FunctionSymbol : MBB.getSymbol ();
1056
+ MBB.isEntryBlock () ? FunctionSymbol : MBB.getSymbol ();
1057
1057
// Emit the basic block offset.
1058
1058
emitLabelDifferenceAsULEB128 (MBBSymbol, FunctionSymbol);
1059
1059
// Emit the basic block size. When BBs have alignments, their size cannot
@@ -3088,7 +3088,7 @@ void AsmPrinter::emitBasicBlockStart(const MachineBasicBlock &MBB) {
3088
3088
// Switch to a new section if this basic block must begin a section. The
3089
3089
// entry block is always placed in the function section and is handled
3090
3090
// separately.
3091
- if (MBB.isBeginSection () && !MBB.pred_empty ()) {
3091
+ if (MBB.isBeginSection () && !MBB.isEntryBlock ()) {
3092
3092
OutStreamer->SwitchSection (
3093
3093
getObjFileLowering ().getSectionForMachineBasicBlock (MF->getFunction (),
3094
3094
MBB, TM));
@@ -3126,24 +3126,22 @@ void AsmPrinter::emitBasicBlockStart(const MachineBasicBlock &MBB) {
3126
3126
}
3127
3127
3128
3128
// Print the main label for the block.
3129
- if (MBB.pred_empty () ||
3130
- (!MF->hasBBLabels () && isBlockOnlyReachableByFallthrough (&MBB) &&
3131
- !MBB.isEHFuncletEntry () && !MBB.hasLabelMustBeEmitted ())) {
3129
+ if (shouldEmitLabelForBasicBlock (MBB)) {
3130
+ if (isVerbose () && MBB.hasLabelMustBeEmitted ())
3131
+ OutStreamer->AddComment (" Label of block must be emitted" );
3132
+ OutStreamer->emitLabel (MBB.getSymbol ());
3133
+ } else {
3132
3134
if (isVerbose ()) {
3133
3135
// NOTE: Want this comment at start of line, don't emit with AddComment.
3134
3136
OutStreamer->emitRawComment (" %bb." + Twine (MBB.getNumber ()) + " :" ,
3135
3137
false );
3136
3138
}
3137
- } else {
3138
- if (isVerbose () && MBB.hasLabelMustBeEmitted ())
3139
- OutStreamer->AddComment (" Label of block must be emitted" );
3140
- OutStreamer->emitLabel (MBB.getSymbol ());
3141
3139
}
3142
3140
3143
3141
// With BB sections, each basic block must handle CFI information on its own
3144
3142
// if it begins a section (Entry block is handled separately by
3145
3143
// AsmPrinterHandler::beginFunction).
3146
- if (MBB.isBeginSection () && !MBB.pred_empty ())
3144
+ if (MBB.isBeginSection () && !MBB.isEntryBlock ())
3147
3145
for (const HandlerInfo &HI : Handlers)
3148
3146
HI.Handler ->beginBasicBlock (MBB);
3149
3147
}
@@ -3177,15 +3175,26 @@ void AsmPrinter::emitVisibility(MCSymbol *Sym, unsigned Visibility,
3177
3175
OutStreamer->emitSymbolAttribute (Sym, Attr);
3178
3176
}
3179
3177
3178
+ bool AsmPrinter::shouldEmitLabelForBasicBlock (
3179
+ const MachineBasicBlock &MBB) const {
3180
+ // With `-fbasic-block-sections=`, a label is needed for every non-entry block
3181
+ // in the labels mode (option `=labels`) and every section beginning in the
3182
+ // sections mode (`=all` and `=list=`).
3183
+ if ((MF->hasBBLabels () || MBB.isBeginSection ()) && !MBB.isEntryBlock ())
3184
+ return true ;
3185
+ // A label is needed for any block with at least one predecessor (when that
3186
+ // predecessor is not the fallthrough predecessor, or if it is an EH funclet
3187
+ // entry, or if a label is forced).
3188
+ return !MBB.pred_empty () &&
3189
+ (!isBlockOnlyReachableByFallthrough (&MBB) || MBB.isEHFuncletEntry () ||
3190
+ MBB.hasLabelMustBeEmitted ());
3191
+ }
3192
+
3180
3193
// / isBlockOnlyReachableByFallthough - Return true if the basic block has
3181
3194
// / exactly one predecessor and the control transfer mechanism between
3182
3195
// / the predecessor and this block is a fall-through.
3183
3196
bool AsmPrinter::
3184
3197
isBlockOnlyReachableByFallthrough (const MachineBasicBlock *MBB) const {
3185
- // With BasicBlock Sections, beginning of the section is not a fallthrough.
3186
- if (MBB->isBeginSection ())
3187
- return false ;
3188
-
3189
3198
// If this is a landing pad, it isn't a fall through. If it has no preds,
3190
3199
// then nothing falls through to it.
3191
3200
if (MBB->isEHPad () || MBB->pred_empty ())
0 commit comments