@@ -511,12 +511,6 @@ static void CheckBundleSubtargets(const MCSubtargetInfo *OldSTI,
511511void MCELFStreamer::emitInstToData (const MCInst &Inst,
512512 const MCSubtargetInfo &STI) {
513513 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 ());
520514
521515 // There are several possibilities here:
522516 //
@@ -526,9 +520,7 @@ void MCELFStreamer::emitInstToData(const MCInst &Inst,
526520 //
527521 // If bundling is enabled:
528522 // - 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.
532524 // - If we're in a bundle-locked group, append the instruction to the current
533525 // data fragment because we want all the instructions in a group to get into
534526 // the same fragment. Be careful not to do that for the first instruction in
@@ -542,16 +534,6 @@ void MCELFStreamer::emitInstToData(const MCInst &Inst,
542534 // The bundle-locking directive ensures this is a new data fragment.
543535 DF = cast<MCDataFragment>(getCurrentFragment ());
544536 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 ;
555537 } else {
556538 DF = getContext ().allocFragment <MCDataFragment>();
557539 insert (DF);
@@ -571,17 +553,22 @@ void MCELFStreamer::emitInstToData(const MCInst &Inst,
571553 DF = getOrCreateDataFragment (&STI);
572554 }
573555
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);
575563 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 () );
578566 }
579567
580568 DF->setHasInstructions (STI);
581569 if (!Fixups.empty () && Fixups.back ().getTargetKind () ==
582570 getAssembler ().getBackend ().RelaxFixupKind )
583571 DF->setLinkerRelaxable ();
584- DF->getContents ().append (Code.begin (), Code.end ());
585572}
586573
587574void MCELFStreamer::emitBundleAlignMode (Align Alignment) {
0 commit comments