@@ -31,101 +31,21 @@ class MCAsmInfo;
31
31
class MCAssembler ;
32
32
class MCContext ;
33
33
class MCExpr ;
34
+ class MCFragment ;
34
35
class MCObjectStreamer ;
35
36
class MCSymbol ;
36
37
class MCSection ;
37
38
class MCSubtargetInfo ;
38
39
class raw_ostream ;
39
40
class Triple ;
40
41
41
- // Represents a contiguous piece of code or data within a section. Its size is
42
- // determined by MCAssembler::layout. All subclasses must have trivial
43
- // destructors.
44
- //
45
- // Declaration order: MCFragment, MCSection, then MCFragment's derived classes.
46
- // This allows MCSection's inline functions to access MCFragment members and
47
- // allows MCFragment's derived classes to access MCSection.
48
- class MCFragment {
49
- friend class MCAssembler ;
50
- friend class MCObjectStreamer ;
51
- friend class MCSection ;
52
-
53
- public:
54
- enum FragmentType : uint8_t {
55
- FT_Data,
56
- FT_Relaxable,
57
- FT_Align,
58
- FT_Fill,
59
- FT_LEB,
60
- FT_Nops,
61
- FT_Org,
62
- FT_Dwarf,
63
- FT_DwarfFrame,
64
- FT_BoundaryAlign,
65
- FT_SymbolId,
66
- FT_CVInlineLines,
67
- FT_CVDefRange,
68
- FT_PseudoProbe,
69
- };
70
-
71
- private:
72
- // The next fragment within the section.
73
- MCFragment *Next = nullptr ;
74
-
75
- // / The data for the section this fragment is in.
76
- MCSection *Parent = nullptr ;
77
-
78
- // / The offset of this fragment in its section.
79
- uint64_t Offset = 0 ;
80
-
81
- // / The layout order of this fragment.
82
- unsigned LayoutOrder = 0 ;
83
-
84
- FragmentType Kind;
85
-
86
- protected:
87
- // / Used by subclasses for better packing.
88
- // /
89
- // / MCEncodedFragment
90
- bool HasInstructions : 1 ;
91
- bool AlignToBundleEnd : 1 ;
92
- // / MCDataFragment
93
- bool LinkerRelaxable : 1 ;
94
- // / MCRelaxableFragment: x86-specific
95
- bool AllowAutoPadding : 1 ;
96
-
97
- LLVM_ABI MCFragment (FragmentType Kind, bool HasInstructions);
98
-
99
- public:
100
- MCFragment () = delete ;
101
- MCFragment (const MCFragment &) = delete ;
102
- MCFragment &operator =(const MCFragment &) = delete ;
103
-
104
- MCFragment *getNext () const { return Next; }
105
-
106
- FragmentType getKind () const { return Kind; }
107
-
108
- MCSection *getParent () const { return Parent; }
109
- void setParent (MCSection *Value) { Parent = Value; }
110
-
111
- LLVM_ABI const MCSymbol *getAtom () const ;
112
-
113
- unsigned getLayoutOrder () const { return LayoutOrder; }
114
- void setLayoutOrder (unsigned Value) { LayoutOrder = Value; }
115
-
116
- // / Does this fragment have instructions emitted into it? By default
117
- // / this is false, but specific fragment types may set it to true.
118
- bool hasInstructions () const { return HasInstructions; }
119
-
120
- LLVM_ABI void dump () const ;
121
- };
122
-
123
42
// / Instances of this class represent a uniqued identifier for a section in the
124
43
// / current translation unit. The MCContext class uniques and creates these.
125
44
class LLVM_ABI MCSection {
126
45
public:
127
46
friend MCAssembler;
128
47
friend MCObjectStreamer;
48
+ friend class MCFragment ;
129
49
friend class MCEncodedFragment ;
130
50
friend class MCRelaxableFragment ;
131
51
static constexpr unsigned NonUniqueID = ~0U ;
@@ -155,10 +75,7 @@ class LLVM_ABI MCSection {
155
75
MCFragment &operator *() const { return *F; }
156
76
bool operator ==(const iterator &O) const { return F == O.F ; }
157
77
bool operator !=(const iterator &O) const { return F != O.F ; }
158
- iterator &operator ++() {
159
- F = F->Next ;
160
- return *this ;
161
- }
78
+ iterator &operator ++();
162
79
};
163
80
164
81
struct FragList {
@@ -296,6 +213,87 @@ class LLVM_ABI MCSection {
296
213
virtual StringRef getVirtualSectionKind () const ;
297
214
};
298
215
216
+ // Represents a contiguous piece of code or data within a section. Its size is
217
+ // determined by MCAssembler::layout. All subclasses must have trivial
218
+ // destructors.
219
+ class MCFragment {
220
+ friend class MCAssembler ;
221
+ friend class MCObjectStreamer ;
222
+ friend class MCSection ;
223
+
224
+ public:
225
+ enum FragmentType : uint8_t {
226
+ FT_Data,
227
+ FT_Relaxable,
228
+ FT_Align,
229
+ FT_Fill,
230
+ FT_LEB,
231
+ FT_Nops,
232
+ FT_Org,
233
+ FT_Dwarf,
234
+ FT_DwarfFrame,
235
+ FT_BoundaryAlign,
236
+ FT_SymbolId,
237
+ FT_CVInlineLines,
238
+ FT_CVDefRange,
239
+ FT_PseudoProbe,
240
+ };
241
+
242
+ private:
243
+ // The next fragment within the section.
244
+ MCFragment *Next = nullptr ;
245
+
246
+ // / The data for the section this fragment is in.
247
+ MCSection *Parent = nullptr ;
248
+
249
+ // / The offset of this fragment in its section.
250
+ uint64_t Offset = 0 ;
251
+
252
+ // / The layout order of this fragment.
253
+ unsigned LayoutOrder = 0 ;
254
+
255
+ FragmentType Kind;
256
+
257
+ protected:
258
+ // / Used by subclasses for better packing.
259
+ // /
260
+ // / MCEncodedFragment
261
+ bool HasInstructions : 1 ;
262
+ bool AlignToBundleEnd : 1 ;
263
+ // / MCDataFragment
264
+ bool LinkerRelaxable : 1 ;
265
+ // / MCRelaxableFragment: x86-specific
266
+ bool AllowAutoPadding : 1 ;
267
+
268
+ LLVM_ABI MCFragment (FragmentType Kind, bool HasInstructions);
269
+
270
+ public:
271
+ MCFragment () = delete ;
272
+ MCFragment (const MCFragment &) = delete ;
273
+ MCFragment &operator =(const MCFragment &) = delete ;
274
+
275
+ MCFragment *getNext () const { return Next; }
276
+
277
+ FragmentType getKind () const { return Kind; }
278
+
279
+ MCSection *getParent () const { return Parent; }
280
+ void setParent (MCSection *Value) { Parent = Value; }
281
+
282
+ LLVM_ABI const MCSymbol *getAtom () const ;
283
+
284
+ unsigned getLayoutOrder () const { return LayoutOrder; }
285
+ void setLayoutOrder (unsigned Value) { LayoutOrder = Value; }
286
+
287
+ // / Does this fragment have instructions emitted into it? By default
288
+ // / this is false, but specific fragment types may set it to true.
289
+ bool hasInstructions () const { return HasInstructions; }
290
+
291
+ bool isLinkerRelaxable () const { return LinkerRelaxable; }
292
+ void setLinkerRelaxable () { LinkerRelaxable = true ; }
293
+
294
+ LLVM_ABI void dump () const ;
295
+ };
296
+
299
297
// / Interface implemented by fragments that contain encoded instructions and/or
300
298
// / data.
301
299
class MCEncodedFragment : public MCFragment {
@@ -357,6 +355,9 @@ class MCEncodedFragment : public MCFragment {
357
355
this ->STI = &STI;
358
356
}
359
357
358
+ bool getAllowAutoPadding () const { return AllowAutoPadding; }
359
+ void setAllowAutoPadding (bool V) { AllowAutoPadding = V; }
360
+
360
361
// Content-related functions manage parent's storage using ContentStart and
361
362
// ContentSize.
362
363
void clearContents () { ContentEnd = ContentStart; }
@@ -407,6 +408,8 @@ class MCEncodedFragment : public MCFragment {
407
408
return ArrayRef (getParent ()->FixupStorage )
408
409
.slice (FixupStart, FixupEnd - FixupStart);
409
410
}
411
+
412
+ size_t getSize () const { return ContentEnd - ContentStart; }
410
413
};
411
414
412
415
// / Fragment for data and encoded instructions.
@@ -418,9 +421,6 @@ class MCDataFragment : public MCEncodedFragment {
418
421
static bool classof (const MCFragment *F) {
419
422
return F->getKind () == MCFragment::FT_Data;
420
423
}
421
-
422
- bool isLinkerRelaxable () const { return LinkerRelaxable; }
423
- void setLinkerRelaxable () { LinkerRelaxable = true ; }
424
424
};
425
425
426
426
// / A relaxable fragment holds on to its MCInst, since it may need to be
@@ -463,9 +463,6 @@ class MCRelaxableFragment : public MCEncodedFragment {
463
463
llvm::copy (Inst, S.begin () + OperandStart);
464
464
}
465
465
466
- bool getAllowAutoPadding () const { return AllowAutoPadding; }
467
- void setAllowAutoPadding (bool V) { AllowAutoPadding = V; }
468
-
469
466
static bool classof (const MCFragment *F) {
470
467
return F->getKind () == MCFragment::FT_Relaxable;
471
468
}
@@ -794,6 +791,11 @@ class MCPseudoProbeAddrFragment : public MCEncodedFragment {
794
791
}
795
792
};
796
793
794
+ inline MCSection::iterator &MCSection::iterator::operator ++() {
795
+ F = F->Next ;
796
+ return *this ;
797
+ }
798
+
797
799
} // end namespace llvm
798
800
799
801
#endif // LLVM_MC_MCSECTION_H
0 commit comments