@@ -30,6 +30,9 @@ class MCSection;
30
30
class MCSubtargetInfo ;
31
31
class MCSymbol ;
32
32
33
+ // Represents a contiguous segment of code or data within a section. Its size is
34
+ // determined by MCAssembler::layout. All subclasses (except
35
+ // MCRelaxableFragment, which stores a MCInst) must have trivial destructors.
33
36
class MCFragment {
34
37
friend class MCAssembler ;
35
38
friend class MCObjectStreamer ;
@@ -86,12 +89,6 @@ class MCFragment {
86
89
MCFragment (const MCFragment &) = delete ;
87
90
MCFragment &operator =(const MCFragment &) = delete ;
88
91
89
- // / Destroys the current fragment.
90
- // /
91
- // / This must be used instead of delete as MCFragment is non-virtual.
92
- // / This method will dispatch to the appropriate subclass.
93
- LLVM_ABI void destroy ();
94
-
95
92
MCFragment *getNext () const { return Next; }
96
93
97
94
FragmentType getKind () const { return Kind; }
@@ -113,10 +110,7 @@ class MCFragment {
113
110
114
111
// / Interface implemented by fragments that contain encoded instructions and/or
115
112
// / data.
116
- // /
117
113
class MCEncodedFragment : public MCFragment {
118
- uint8_t BundlePadding = 0 ;
119
-
120
114
protected:
121
115
MCEncodedFragment (MCFragment::FragmentType FType, bool HasInstructions)
122
116
: MCFragment(FType, HasInstructions) {}
@@ -125,6 +119,13 @@ class MCEncodedFragment : public MCFragment {
125
119
// / It must be non-null for instructions.
126
120
const MCSubtargetInfo *STI = nullptr ;
127
121
122
+ private:
123
+ uint32_t ContentStart = 0 ;
124
+ uint32_t ContentSize = 0 ;
125
+ uint32_t FixupStart = 0 ;
126
+ uint32_t FixupSize = 0 ;
127
+ uint8_t BundlePadding = 0 ;
128
+
128
129
public:
129
130
static bool classof (const MCFragment *F) {
130
131
MCFragment::FragmentType Kind = F->getKind ();
@@ -136,6 +137,7 @@ class MCEncodedFragment : public MCFragment {
136
137
case MCFragment::FT_Dwarf:
137
138
case MCFragment::FT_DwarfFrame:
138
139
case MCFragment::FT_PseudoProbe:
140
+ case MCFragment::FT_CVInlineLines:
139
141
return true ;
140
142
}
141
143
}
@@ -165,48 +167,33 @@ class MCEncodedFragment : public MCFragment {
165
167
HasInstructions = true ;
166
168
this ->STI = &STI;
167
169
}
168
- };
169
170
170
- // / Interface implemented by fragments that contain encoded instructions and/or
171
- // / data and also have fixups registered.
172
- // /
173
- template <unsigned ContentsSize, unsigned FixupsSize>
174
- class MCEncodedFragmentWithFixups : public MCEncodedFragment {
175
- SmallVector<char , ContentsSize> Contents;
176
-
177
- // / The list of fixups in this fragment.
178
- SmallVector<MCFixup, FixupsSize> Fixups;
179
-
180
- protected:
181
- MCEncodedFragmentWithFixups (MCFragment::FragmentType FType,
182
- bool HasInstructions)
183
- : MCEncodedFragment(FType, HasInstructions) {}
184
-
185
- public:
186
- SmallVectorImpl<char > &getContents () { return Contents; }
187
- const SmallVectorImpl<char > &getContents () const { return Contents; }
188
-
189
- void appendContents (ArrayRef<char > C) { Contents.append (C.begin (), C.end ()); }
190
- void appendContents (size_t Num, char Elt) { Contents.append (Num, Elt); }
191
- void setContents (ArrayRef<char > C) { Contents.assign (C.begin (), C.end ()); }
192
-
193
- void addFixup (MCFixup Fixup) { Fixups.push_back (Fixup); }
194
- SmallVectorImpl<MCFixup> &getFixups () { return Fixups; }
195
- const SmallVectorImpl<MCFixup> &getFixups () const { return Fixups; }
196
-
197
- static bool classof (const MCFragment *F) {
198
- MCFragment::FragmentType Kind = F->getKind ();
199
- return Kind == MCFragment::FT_Relaxable || Kind == MCFragment::FT_Data ||
200
- Kind == MCFragment::FT_CVDefRange || Kind == MCFragment::FT_Dwarf ||
201
- Kind == MCFragment::FT_DwarfFrame;
202
- }
171
+ // Content-related functions manage parent's storage using ContentStart and
172
+ // ContentSize.
173
+ void clearContents () { ContentSize = 0 ; }
174
+ SmallVectorImpl<char > &getContentsForAppending ();
175
+ void doneAppending ();
176
+ void appendContents (ArrayRef<char > Contents);
177
+ void appendContents (size_t Num, char Elt);
178
+ void setContents (ArrayRef<char > Contents);
179
+ MutableArrayRef<char > getContents ();
180
+ ArrayRef<char > getContents () const ;
181
+
182
+ // Fixup-related functions manage parent's storage using FixupStart and
183
+ // FixupSize.
184
+ void clearFixups () { FixupSize = 0 ; }
185
+ void addFixup (MCFixup Fixup);
186
+ void appendFixups (ArrayRef<MCFixup> Fixups);
187
+ void setFixups (ArrayRef<MCFixup> Fixups);
188
+ MutableArrayRef<MCFixup> getFixups ();
189
+ ArrayRef<MCFixup> getFixups () const ;
203
190
};
204
191
205
192
// / Fragment for data and encoded instructions.
206
193
// /
207
- class MCDataFragment : public MCEncodedFragmentWithFixups < 32 , 4 > {
194
+ class MCDataFragment : public MCEncodedFragment {
208
195
public:
209
- MCDataFragment () : MCEncodedFragmentWithFixups< 32 , 4 > (FT_Data, false ) {}
196
+ MCDataFragment () : MCEncodedFragment (FT_Data, false ) {}
210
197
211
198
static bool classof (const MCFragment *F) {
212
199
return F->getKind () == MCFragment::FT_Data;
@@ -219,13 +206,13 @@ class MCDataFragment : public MCEncodedFragmentWithFixups<32, 4> {
219
206
// / A relaxable fragment holds on to its MCInst, since it may need to be
220
207
// / relaxed during the assembler layout and relaxation stage.
221
208
// /
222
- class MCRelaxableFragment : public MCEncodedFragmentWithFixups < 8 , 1 > {
209
+ class MCRelaxableFragment : public MCEncodedFragment {
223
210
// / The instruction this is a fragment for.
224
211
MCInst Inst;
225
212
226
213
public:
227
214
MCRelaxableFragment (const MCInst &Inst, const MCSubtargetInfo &STI)
228
- : MCEncodedFragmentWithFixups (FT_Relaxable, true ), Inst(Inst) {
215
+ : MCEncodedFragment (FT_Relaxable, true ), Inst(Inst) {
229
216
this ->STI = &STI;
230
217
}
231
218
@@ -374,7 +361,7 @@ class MCOrgFragment : public MCFragment {
374
361
}
375
362
};
376
363
377
- class MCLEBFragment final : public MCEncodedFragmentWithFixups< 8 , 0 > {
364
+ class MCLEBFragment final : public MCEncodedFragment {
378
365
// / True if this is a sleb128, false if uleb128.
379
366
bool IsSigned;
380
367
@@ -383,24 +370,19 @@ class MCLEBFragment final : public MCEncodedFragmentWithFixups<8, 0> {
383
370
384
371
public:
385
372
MCLEBFragment (const MCExpr &Value, bool IsSigned)
386
- : MCEncodedFragmentWithFixups<8 , 0 >(FT_LEB, false ), IsSigned(IsSigned),
387
- Value (&Value) {
388
- getContents ().push_back (0 );
389
- }
373
+ : MCEncodedFragment(FT_LEB, false ), IsSigned(IsSigned), Value(&Value) {}
390
374
391
375
const MCExpr &getValue () const { return *Value; }
392
376
void setValue (const MCExpr *Expr) { Value = Expr; }
393
377
394
378
bool isSigned () const { return IsSigned; }
395
379
396
- // / @}
397
-
398
380
static bool classof (const MCFragment *F) {
399
381
return F->getKind () == MCFragment::FT_LEB;
400
382
}
401
383
};
402
384
403
- class MCDwarfLineAddrFragment : public MCEncodedFragmentWithFixups < 8 , 1 > {
385
+ class MCDwarfLineAddrFragment : public MCEncodedFragment {
404
386
// / The value of the difference between the two line numbers
405
387
// / between two .loc dwarf directives.
406
388
int64_t LineDelta;
@@ -411,8 +393,8 @@ class MCDwarfLineAddrFragment : public MCEncodedFragmentWithFixups<8, 1> {
411
393
412
394
public:
413
395
MCDwarfLineAddrFragment (int64_t LineDelta, const MCExpr &AddrDelta)
414
- : MCEncodedFragmentWithFixups< 8 , 1 > (FT_Dwarf, false ),
415
- LineDelta (LineDelta), AddrDelta(&AddrDelta) {}
396
+ : MCEncodedFragment (FT_Dwarf, false ), LineDelta(LineDelta ),
397
+ AddrDelta (&AddrDelta) {}
416
398
417
399
int64_t getLineDelta () const { return LineDelta; }
418
400
@@ -423,15 +405,14 @@ class MCDwarfLineAddrFragment : public MCEncodedFragmentWithFixups<8, 1> {
423
405
}
424
406
};
425
407
426
- class MCDwarfCallFrameFragment : public MCEncodedFragmentWithFixups < 8 , 1 > {
408
+ class MCDwarfCallFrameFragment : public MCEncodedFragment {
427
409
// / The expression for the difference of the two symbols that
428
410
// / make up the address delta between two .cfi_* dwarf directives.
429
411
const MCExpr *AddrDelta;
430
412
431
413
public:
432
414
MCDwarfCallFrameFragment (const MCExpr &AddrDelta)
433
- : MCEncodedFragmentWithFixups<8 , 1 >(FT_DwarfFrame, false ),
434
- AddrDelta (&AddrDelta) {}
415
+ : MCEncodedFragment(FT_DwarfFrame, false ), AddrDelta(&AddrDelta) {}
435
416
436
417
const MCExpr &getAddrDelta () const { return *AddrDelta; }
437
418
void setAddrDelta (const MCExpr *E) { AddrDelta = E; }
@@ -459,13 +440,12 @@ class MCSymbolIdFragment : public MCFragment {
459
440
460
441
// / Fragment representing the binary annotations produced by the
461
442
// / .cv_inline_linetable directive.
462
- class MCCVInlineLineTableFragment : public MCFragment {
443
+ class MCCVInlineLineTableFragment : public MCEncodedFragment {
463
444
unsigned SiteFuncId;
464
445
unsigned StartFileId;
465
446
unsigned StartLineNum;
466
447
const MCSymbol *FnStartSym;
467
448
const MCSymbol *FnEndSym;
468
- SmallString<8 > Contents;
469
449
470
450
// / CodeViewContext has the real knowledge about this format, so let it access
471
451
// / our members.
@@ -475,23 +455,20 @@ class MCCVInlineLineTableFragment : public MCFragment {
475
455
MCCVInlineLineTableFragment (unsigned SiteFuncId, unsigned StartFileId,
476
456
unsigned StartLineNum, const MCSymbol *FnStartSym,
477
457
const MCSymbol *FnEndSym)
478
- : MCFragment (FT_CVInlineLines, false ), SiteFuncId(SiteFuncId),
458
+ : MCEncodedFragment (FT_CVInlineLines, false ), SiteFuncId(SiteFuncId),
479
459
StartFileId (StartFileId), StartLineNum(StartLineNum),
480
460
FnStartSym(FnStartSym), FnEndSym(FnEndSym) {}
481
461
482
462
const MCSymbol *getFnStartSym () const { return FnStartSym; }
483
463
const MCSymbol *getFnEndSym () const { return FnEndSym; }
484
464
485
- SmallString<8 > &getContents () { return Contents; }
486
- const SmallString<8 > &getContents () const { return Contents; }
487
-
488
465
static bool classof (const MCFragment *F) {
489
466
return F->getKind () == MCFragment::FT_CVInlineLines;
490
467
}
491
468
};
492
469
493
470
// / Fragment representing the .cv_def_range directive.
494
- class MCCVDefRangeFragment : public MCEncodedFragmentWithFixups < 32 , 4 > {
471
+ class MCCVDefRangeFragment : public MCEncodedFragment {
495
472
ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges;
496
473
StringRef FixedSizePortion;
497
474
@@ -503,8 +480,9 @@ class MCCVDefRangeFragment : public MCEncodedFragmentWithFixups<32, 4> {
503
480
MCCVDefRangeFragment (
504
481
ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
505
482
StringRef FixedSizePortion)
506
- : MCEncodedFragmentWithFixups<32 , 4 >(FT_CVDefRange, false ),
507
- Ranges (Ranges), FixedSizePortion(FixedSizePortion) {}
483
+ : MCEncodedFragment(FT_CVDefRange, false ),
484
+ Ranges (Ranges.begin(), Ranges.end()),
485
+ FixedSizePortion(FixedSizePortion) {}
508
486
509
487
ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> getRanges () const {
510
488
return Ranges;
@@ -556,15 +534,14 @@ class MCBoundaryAlignFragment : public MCFragment {
556
534
}
557
535
};
558
536
559
- class MCPseudoProbeAddrFragment : public MCEncodedFragmentWithFixups < 8 , 1 > {
537
+ class MCPseudoProbeAddrFragment : public MCEncodedFragment {
560
538
// / The expression for the difference of the two symbols that
561
539
// / make up the address delta between two .pseudoprobe directives.
562
540
const MCExpr *AddrDelta;
563
541
564
542
public:
565
543
MCPseudoProbeAddrFragment (const MCExpr *AddrDelta)
566
- : MCEncodedFragmentWithFixups<8 , 1 >(FT_PseudoProbe, false ),
567
- AddrDelta (AddrDelta) {}
544
+ : MCEncodedFragment(FT_PseudoProbe, false ), AddrDelta(AddrDelta) {}
568
545
569
546
const MCExpr &getAddrDelta () const { return *AddrDelta; }
570
547
0 commit comments