@@ -1097,14 +1097,6 @@ void AsmPrinter::emitFunctionBody() {
1097
1097
// Print out code for the function.
1098
1098
bool HasAnyRealCode = false ;
1099
1099
int NumInstsInFunction = 0 ;
1100
- bool emitBBSections = MF->hasBBSections ();
1101
- MachineBasicBlock *EndOfRegularSectionMBB = nullptr ;
1102
- if (emitBBSections) {
1103
- EndOfRegularSectionMBB =
1104
- const_cast <MachineBasicBlock *>(MF->front ().getSectionEndMBB ());
1105
- assert (EndOfRegularSectionMBB->isEndSection () &&
1106
- " The MBB at the end of the regular section must end a section" );
1107
- }
1108
1100
1109
1101
for (auto &MBB : *MF) {
1110
1102
// Print a label for the basic block.
@@ -1185,17 +1177,41 @@ void AsmPrinter::emitFunctionBody() {
1185
1177
}
1186
1178
}
1187
1179
}
1188
- if (&MBB != EndOfRegularSectionMBB &&
1189
- (MF->hasBBLabels () || MBB.isEndSection ())) {
1190
- // Emit size directive for the size of this basic block. Create a symbol
1191
- // for the end of the basic block.
1192
- MCSymbol *CurrentBBEnd = OutContext.createTempSymbol ();
1180
+
1181
+ // We need a temporary symbol for the end of this basic block, if either we
1182
+ // have BBLabels enabled and we want to emit size directive for the BBs, or
1183
+ // if this basic blocks marks the end of a section (except the section
1184
+ // containing the entry basic block as the end symbol for that section is
1185
+ // CurrentFnEnd).
1186
+ MCSymbol *CurrentBBEnd = nullptr ;
1187
+ if ((MAI->hasDotTypeDotSizeDirective () && MF->hasBBLabels ()) ||
1188
+ (MBB.isEndSection () && !MBB.sameSection (&MF->front ()))) {
1189
+ CurrentBBEnd = OutContext.createTempSymbol ();
1190
+ OutStreamer->emitLabel (CurrentBBEnd);
1191
+ }
1192
+
1193
+ // Helper for emitting the size directive associated with a basic block
1194
+ // symbol.
1195
+ auto emitELFSizeDirective = [&](MCSymbol *SymForSize) {
1196
+ assert (CurrentBBEnd && " Basicblock end symbol not set!" );
1193
1197
const MCExpr *SizeExp = MCBinaryExpr::createSub (
1194
1198
MCSymbolRefExpr::create (CurrentBBEnd, OutContext),
1195
- MCSymbolRefExpr::create (MBB.getSymbol (), OutContext), OutContext);
1196
- OutStreamer->emitLabel (CurrentBBEnd);
1197
- MBB.setEndMCSymbol (CurrentBBEnd);
1198
- OutStreamer->emitELFSize (MBB.getSymbol (), SizeExp);
1199
+ MCSymbolRefExpr::create (SymForSize, OutContext), OutContext);
1200
+ OutStreamer->emitELFSize (SymForSize, SizeExp);
1201
+ };
1202
+
1203
+ // Emit size directive for the size of each basic block, if BBLabels is
1204
+ // enabled.
1205
+ if (MAI->hasDotTypeDotSizeDirective () && MF->hasBBLabels ())
1206
+ emitELFSizeDirective (MBB.getSymbol ());
1207
+
1208
+ // Emit size directive for the size of each basic block section once we
1209
+ // get to the end of that section.
1210
+ if (MBB.isEndSection ()) {
1211
+ if (!MBB.sameSection (&MF->front ())) {
1212
+ if (MAI->hasDotTypeDotSizeDirective ())
1213
+ emitELFSizeDirective (CurrentSectionBeginSym);
1214
+ }
1199
1215
}
1200
1216
emitBasicBlockEnd (MBB);
1201
1217
}
@@ -1230,9 +1246,8 @@ void AsmPrinter::emitFunctionBody() {
1230
1246
}
1231
1247
}
1232
1248
1233
- // Switch to the original section if basic block sections was used.
1234
- if (emitBBSections)
1235
- OutStreamer->SwitchSection (MF->getSection ());
1249
+ // Switch to the original section in case basic block sections was used.
1250
+ OutStreamer->SwitchSection (MF->getSection ());
1236
1251
1237
1252
const Function &F = MF->getFunction ();
1238
1253
for (const auto &BB : F) {
@@ -1249,7 +1264,7 @@ void AsmPrinter::emitFunctionBody() {
1249
1264
emitFunctionBodyEnd ();
1250
1265
1251
1266
if (needFuncLabelsForEHOrDebugInfo (*MF, MMI) ||
1252
- MAI->hasDotTypeDotSizeDirective () || emitBBSections ) {
1267
+ MAI->hasDotTypeDotSizeDirective ()) {
1253
1268
// Create a symbol for the end of function.
1254
1269
CurrentFnEnd = createTempSymbol (" func_end" );
1255
1270
OutStreamer->emitLabel (CurrentFnEnd);
@@ -1272,8 +1287,6 @@ void AsmPrinter::emitFunctionBody() {
1272
1287
HI.Handler ->markFunctionEnd ();
1273
1288
}
1274
1289
1275
- if (emitBBSections)
1276
- EndOfRegularSectionMBB->setEndMCSymbol (CurrentFnEnd);
1277
1290
1278
1291
// Print out jump tables referenced by the function.
1279
1292
emitJumpTableInfo ();
@@ -1753,6 +1766,7 @@ void AsmPrinter::SetupMachineFunction(MachineFunction &MF) {
1753
1766
1754
1767
CurrentFnSymForSize = CurrentFnSym;
1755
1768
CurrentFnBegin = nullptr ;
1769
+ CurrentSectionBeginSym = nullptr ;
1756
1770
CurExceptionSym = nullptr ;
1757
1771
bool NeedsLocalForSize = MAI->needsLocalForSize ();
1758
1772
if (F.hasFnAttribute (" patchable-function-entry" ) ||
@@ -2981,7 +2995,6 @@ static void emitBasicBlockLoopComments(const MachineBasicBlock &MBB,
2981
2995
// / MachineBasicBlock, an alignment (if present) and a comment describing
2982
2996
// / it if appropriate.
2983
2997
void AsmPrinter::emitBasicBlockStart (const MachineBasicBlock &MBB) {
2984
- bool BBSections = MF->hasBBSections ();
2985
2998
// End the previous funclet and start a new one.
2986
2999
if (MBB.isEHFuncletEntry ()) {
2987
3000
for (const HandlerInfo &HI : Handlers) {
@@ -2991,11 +3004,9 @@ void AsmPrinter::emitBasicBlockStart(const MachineBasicBlock &MBB) {
2991
3004
}
2992
3005
2993
3006
// Emit an alignment directive for this block, if needed.
2994
- if (MBB.pred_empty () || !BBSections) {
2995
- const Align Alignment = MBB.getAlignment ();
2996
- if (Alignment != Align (1 ))
2997
- emitAlignment (Alignment);
2998
- }
3007
+ const Align Alignment = MBB.getAlignment ();
3008
+ if (Alignment != Align (1 ))
3009
+ emitAlignment (Alignment);
2999
3010
3000
3011
// If the block has its address taken, emit any labels that were used to
3001
3012
// reference the block. It is possible that there is more than one label
@@ -3027,9 +3038,8 @@ void AsmPrinter::emitBasicBlockStart(const MachineBasicBlock &MBB) {
3027
3038
emitBasicBlockLoopComments (MBB, MLI, *this );
3028
3039
}
3029
3040
3030
- bool emitBBLabels = BBSections || MF->hasBBLabels ();
3031
3041
if (MBB.pred_empty () ||
3032
- (!emitBBLabels && isBlockOnlyReachableByFallthrough (&MBB) &&
3042
+ (!MF-> hasBBLabels () && isBlockOnlyReachableByFallthrough (&MBB) &&
3033
3043
!MBB.isEHFuncletEntry () && !MBB.hasLabelMustBeEmitted ())) {
3034
3044
if (isVerbose ()) {
3035
3045
// NOTE: Want this comment at start of line, don't emit with AddComment.
@@ -3040,23 +3050,12 @@ void AsmPrinter::emitBasicBlockStart(const MachineBasicBlock &MBB) {
3040
3050
if (isVerbose () && MBB.hasLabelMustBeEmitted ()) {
3041
3051
OutStreamer->AddComment (" Label of block must be emitted" );
3042
3052
}
3043
- // With -fbasicblock-sections, a basic block can start a new section.
3044
- if (MBB.getSectionType () == MachineBasicBlockSection::MBBS_Exception) {
3045
- // Create the exception section for this function.
3046
- OutStreamer->SwitchSection (
3047
- getObjFileLowering ().getNamedSectionForMachineBasicBlock (
3048
- MF->getFunction (), MBB, TM, " .eh" ));
3049
- } else if (MBB.getSectionType () == MachineBasicBlockSection::MBBS_Cold) {
3050
- // Create the cold section here.
3051
- OutStreamer->SwitchSection (
3052
- getObjFileLowering ().getNamedSectionForMachineBasicBlock (
3053
- MF->getFunction (), MBB, TM, " .unlikely" ));
3054
- } else if (MBB.isBeginSection () && MBB.isEndSection ()) {
3053
+ // Switch to a new section if this basic block must begin a section.
3054
+ if (MBB.isBeginSection ()) {
3055
3055
OutStreamer->SwitchSection (
3056
3056
getObjFileLowering ().getSectionForMachineBasicBlock (MF->getFunction (),
3057
3057
MBB, TM));
3058
- } else if (BBSections) {
3059
- OutStreamer->SwitchSection (MF->getSection ());
3058
+ CurrentSectionBeginSym = MBB.getSymbol ();
3060
3059
}
3061
3060
OutStreamer->emitLabel (MBB.getSymbol ());
3062
3061
}
@@ -3090,7 +3089,7 @@ void AsmPrinter::emitVisibility(MCSymbol *Sym, unsigned Visibility,
3090
3089
// / the predecessor and this block is a fall-through.
3091
3090
bool AsmPrinter::
3092
3091
isBlockOnlyReachableByFallthrough (const MachineBasicBlock *MBB) const {
3093
- // With BasicBlock Sections, no block is a fall through .
3092
+ // With BasicBlock Sections, beginning of the section is not a fallthrough .
3094
3093
if (MBB->isBeginSection ())
3095
3094
return false ;
3096
3095
0 commit comments