@@ -133,6 +133,7 @@ class LLVM_ABI MCSection {
133133 friend MCAssembler;
134134 friend MCObjectStreamer;
135135 friend class MCEncodedFragment ;
136+ friend class MCRelaxableFragment ;
136137 static constexpr unsigned NonUniqueID = ~0U ;
137138
138139 enum SectionVariant {
@@ -213,6 +214,7 @@ class LLVM_ABI MCSection {
213214 // Content and fixup storage for fragments
214215 SmallVector<char , 0 > ContentStorage;
215216 SmallVector<MCFixup, 0 > FixupStorage;
217+ SmallVector<MCOperand, 0 > MCOperandStorage;
216218
217219protected:
218220 // TODO Make Name private when possible.
@@ -221,7 +223,8 @@ class LLVM_ABI MCSection {
221223
222224 MCSection (SectionVariant V, StringRef Name, bool IsText, bool IsVirtual,
223225 MCSymbol *Begin);
224- ~MCSection ();
226+ // Protected non-virtual dtor prevents destroy through a base class pointer.
227+ ~MCSection () {}
225228
226229public:
227230 MCSection (const MCSection &) = delete ;
@@ -431,16 +434,38 @@ class MCDataFragment : public MCEncodedFragment {
431434// /
432435class MCRelaxableFragment : public MCEncodedFragment {
433436 // / The instruction this is a fragment for.
434- MCInst Inst;
437+ unsigned Opcode = 0 ;
438+ uint32_t OperandStart = 0 ;
439+ uint32_t OperandSize = 0 ;
435440
436441public:
437- MCRelaxableFragment (const MCInst &Inst, const MCSubtargetInfo &STI)
438- : MCEncodedFragment(FT_Relaxable, true ), Inst(Inst) {
442+ MCRelaxableFragment (const MCSubtargetInfo &STI)
443+ : MCEncodedFragment(FT_Relaxable, true ) {
439444 this ->STI = &STI;
440445 }
441446
442- const MCInst &getInst () const { return Inst; }
443- void setInst (const MCInst &Value) { Inst = Value; }
447+ unsigned getOpcode () const { return Opcode; }
448+ ArrayRef<MCOperand> getOperands () const {
449+ return MutableArrayRef (getParent ()->MCOperandStorage )
450+ .slice (OperandStart, OperandSize);
451+ }
452+ MCInst getInst () const {
453+ MCInst Inst;
454+ Inst.setOpcode (Opcode);
455+ Inst.setOperands (ArrayRef (getParent ()->MCOperandStorage )
456+ .slice (OperandStart, OperandSize));
457+ return Inst;
458+ }
459+ void setInst (const MCInst &Inst) {
460+ Opcode = Inst.getOpcode ();
461+ auto &S = getParent ()->MCOperandStorage ;
462+ if (Inst.getNumOperands () > OperandSize) {
463+ OperandStart = S.size ();
464+ S.resize_for_overwrite (S.size () + Inst.getNumOperands ());
465+ }
466+ OperandSize = Inst.getNumOperands ();
467+ llvm::copy (Inst, S.begin () + OperandStart);
468+ }
444469
445470 bool getAllowAutoPadding () const { return AllowAutoPadding; }
446471 void setAllowAutoPadding (bool V) { AllowAutoPadding = V; }
0 commit comments