@@ -511,12 +511,6 @@ static void CheckBundleSubtargets(const MCSubtargetInfo *OldSTI,
511
511
void MCELFStreamer::emitInstToData (const MCInst &Inst,
512
512
const MCSubtargetInfo &STI) {
513
513
MCAssembler &Assembler = getAssembler ();
514
- SmallVector<MCFixup, 4 > Fixups;
515
- SmallString<256 > Code;
516
- Assembler.getEmitter ().encodeInstruction (Inst, Code, Fixups, STI);
517
-
518
- for (auto &Fixup : Fixups)
519
- fixSymbolsInTLSFixups (Fixup.getValue ());
520
514
521
515
// There are several possibilities here:
522
516
//
@@ -526,9 +520,7 @@ void MCELFStreamer::emitInstToData(const MCInst &Inst,
526
520
//
527
521
// If bundling is enabled:
528
522
// - If we're not in a bundle-locked group, emit the instruction into a
529
- // fragment of its own. If there are no fixups registered for the
530
- // instruction, emit a MCCompactEncodedInstFragment. Otherwise, emit a
531
- // MCDataFragment.
523
+ // fragment of its own.
532
524
// - If we're in a bundle-locked group, append the instruction to the current
533
525
// data fragment because we want all the instructions in a group to get into
534
526
// the same fragment. Be careful not to do that for the first instruction in
@@ -542,16 +534,6 @@ void MCELFStreamer::emitInstToData(const MCInst &Inst,
542
534
// The bundle-locking directive ensures this is a new data fragment.
543
535
DF = cast<MCDataFragment>(getCurrentFragment ());
544
536
CheckBundleSubtargets (DF->getSubtargetInfo (), &STI);
545
- } else if (!isBundleLocked () && Fixups.size () == 0 ) {
546
- // Optimize memory usage by emitting the instruction to a
547
- // MCCompactEncodedInstFragment when not in a bundle-locked group and
548
- // there are no fixups registered.
549
- MCCompactEncodedInstFragment *CEIF =
550
- getContext ().allocFragment <MCCompactEncodedInstFragment>();
551
- insert (CEIF);
552
- CEIF->getContents ().append (Code.begin (), Code.end ());
553
- CEIF->setHasInstructions (STI);
554
- return ;
555
537
} else {
556
538
DF = getContext ().allocFragment <MCDataFragment>();
557
539
insert (DF);
@@ -571,17 +553,22 @@ void MCELFStreamer::emitInstToData(const MCInst &Inst,
571
553
DF = getOrCreateDataFragment (&STI);
572
554
}
573
555
574
- // Add the fixups and data.
556
+ // Emit instruction directly into data fragment.
557
+ size_t FixupStartIndex = DF->getFixups ().size ();
558
+ size_t CodeOffset = DF->getContents ().size ();
559
+ Assembler.getEmitter ().encodeInstruction (Inst, DF->getContents (),
560
+ DF->getFixups (), STI);
561
+
562
+ auto Fixups = MutableArrayRef (DF->getFixups ()).slice (FixupStartIndex);
575
563
for (auto &Fixup : Fixups) {
576
- Fixup.setOffset (Fixup.getOffset () + DF-> getContents (). size () );
577
- DF-> getFixups (). push_back (Fixup );
564
+ Fixup.setOffset (Fixup.getOffset () + CodeOffset );
565
+ fixSymbolsInTLSFixups (Fixup. getValue () );
578
566
}
579
567
580
568
DF->setHasInstructions (STI);
581
569
if (!Fixups.empty () && Fixups.back ().getTargetKind () ==
582
570
getAssembler ().getBackend ().RelaxFixupKind )
583
571
DF->setLinkerRelaxable ();
584
- DF->getContents ().append (Code.begin (), Code.end ());
585
572
}
586
573
587
574
void MCELFStreamer::emitBundleAlignMode (Align Alignment) {
0 commit comments