@@ -106,18 +106,6 @@ void MCObjectStreamer::emitFrames(MCAsmBackend *MAB) {
106
106
MCDwarfFrameEmitter::Emit (*this , MAB, false );
107
107
}
108
108
109
- MCFragment *MCObjectStreamer::getOrCreateDataFragment () {
110
- // TODO: Start a new fragment whenever finalizing the variable-size tail of a
111
- // previous one, so that all getOrCreateDataFragment calls can be replaced
112
- // with getCurrentFragment
113
- auto *F = getCurrentFragment ();
114
- if (F->getKind () != MCFragment::FT_Data) {
115
- F = getContext ().allocFragment <MCFragment>();
116
- insert (F);
117
- }
118
- return F;
119
- }
120
-
121
109
void MCObjectStreamer::visitUsedSymbol (const MCSymbol &Sym) {
122
110
Assembler->registerSymbol (Sym);
123
111
}
@@ -379,6 +367,7 @@ void MCObjectStreamer::emitInstToFragment(const MCInst &Inst,
379
367
F->setVarContents (Data);
380
368
F->setVarFixups (Fixups);
381
369
F->setInst (Inst);
370
+ newFragment ();
382
371
}
383
372
384
373
void MCObjectStreamer::emitDwarfLocDirective (unsigned FileNo, unsigned Line,
@@ -444,6 +433,7 @@ void MCObjectStreamer::emitDwarfAdvanceLineAddr(int64_t LineDelta,
444
433
F->Kind = MCFragment::FT_Dwarf;
445
434
F->setDwarfAddrDelta (buildSymbolDiff (*this , Label, LastLabel, SMLoc ()));
446
435
F->setDwarfLineDelta (LineDelta);
436
+ newFragment ();
447
437
}
448
438
449
439
void MCObjectStreamer::emitDwarfLineEndEntry (MCSection *Section,
@@ -474,6 +464,7 @@ void MCObjectStreamer::emitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel,
474
464
auto *F = getOrCreateDataFragment ();
475
465
F->Kind = MCFragment::FT_DwarfFrame;
476
466
F->setDwarfAddrDelta (buildSymbolDiff (*this , Label, LastLabel, Loc));
467
+ newFragment ();
477
468
}
478
469
479
470
void MCObjectStreamer::emitCVLocDirective (unsigned FunctionId, unsigned FileNo,
@@ -536,32 +527,38 @@ void MCObjectStreamer::emitBytes(StringRef Data) {
536
527
DF->appendContents (ArrayRef (Data.data (), Data.size ()));
537
528
}
538
529
539
- void MCObjectStreamer::emitValueToAlignment (Align Alignment, int64_t Fill,
540
- uint8_t FillLen,
541
- unsigned MaxBytesToEmit) {
530
+ MCAlignFragment *MCObjectStreamer::createAlignFragment (
531
+ Align Alignment, int64_t Fill, uint8_t FillLen, unsigned MaxBytesToEmit) {
542
532
if (MaxBytesToEmit == 0 )
543
533
MaxBytesToEmit = Alignment.value ();
544
- insert (getContext ().allocFragment <MCAlignFragment>(Alignment, Fill, FillLen,
545
- MaxBytesToEmit));
534
+ return getContext ().allocFragment <MCAlignFragment>(Alignment, Fill, FillLen,
535
+ MaxBytesToEmit);
536
+ }
546
537
538
+ void MCObjectStreamer::emitValueToAlignment (Align Alignment, int64_t Fill,
539
+ uint8_t FillLen,
540
+ unsigned MaxBytesToEmit) {
541
+ auto *F = createAlignFragment (Alignment, Fill, FillLen, MaxBytesToEmit);
542
+ insert (F);
547
543
// Update the maximum alignment on the current section if necessary.
548
- MCSection *CurSec = getCurrentSectionOnly ();
549
- CurSec->ensureMinAlignment (Alignment);
544
+ F->getParent ()->ensureMinAlignment (Alignment);
550
545
}
551
546
552
547
void MCObjectStreamer::emitCodeAlignment (Align Alignment,
553
548
const MCSubtargetInfo *STI,
554
549
unsigned MaxBytesToEmit) {
555
- emitValueToAlignment (Alignment, 0 , 1 , MaxBytesToEmit);
556
- auto *F = cast<MCAlignFragment>(getCurrentFragment ());
550
+ auto *F = createAlignFragment (Alignment, 0 , 1 , MaxBytesToEmit);
557
551
F->setEmitNops (true , STI);
552
+ insert (F);
553
+ // Update the maximum alignment on the current section if necessary.
554
+ F->getParent ()->ensureMinAlignment (Alignment);
555
+
558
556
// With RISC-V style linker relaxation, mark the section as linker-relaxable
559
557
// if the alignment is larger than the minimum NOP size.
560
558
unsigned Size;
561
559
if (getAssembler ().getBackend ().shouldInsertExtraNopBytesForCodeAlign (*F,
562
560
Size)) {
563
- getCurrentSectionOnly ()->setLinkerRelaxable ();
564
- newFragment ();
561
+ F->getParent ()->setLinkerRelaxable ();
565
562
}
566
563
}
567
564
0 commit comments