@@ -31,101 +31,21 @@ class MCAsmInfo;
3131class MCAssembler ;
3232class MCContext ;
3333class MCExpr ;
34+ class MCFragment ;
3435class MCObjectStreamer ;
3536class MCSymbol ;
3637class MCSection ;
3738class MCSubtargetInfo ;
3839class raw_ostream ;
3940class Triple ;
4041
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-
12342// / Instances of this class represent a uniqued identifier for a section in the
12443// / current translation unit. The MCContext class uniques and creates these.
12544class LLVM_ABI MCSection {
12645public:
12746 friend MCAssembler;
12847 friend MCObjectStreamer;
48+ friend class MCFragment ;
12949 friend class MCEncodedFragment ;
13050 friend class MCRelaxableFragment ;
13151 static constexpr unsigned NonUniqueID = ~0U ;
@@ -155,10 +75,7 @@ class LLVM_ABI MCSection {
15575 MCFragment &operator *() const { return *F; }
15676 bool operator ==(const iterator &O) const { return F == O.F ; }
15777 bool operator !=(const iterator &O) const { return F != O.F ; }
158- iterator &operator ++() {
159- F = F->Next ;
160- return *this ;
161- }
78+ iterator &operator ++();
16279 };
16380
16481 struct FragList {
@@ -296,6 +213,87 @@ class LLVM_ABI MCSection {
296213 virtual StringRef getVirtualSectionKind () const ;
297214};
298215
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+
299297// / Interface implemented by fragments that contain encoded instructions and/or
300298// / data.
301299class MCEncodedFragment : public MCFragment {
@@ -357,6 +355,9 @@ class MCEncodedFragment : public MCFragment {
357355 this ->STI = &STI;
358356 }
359357
358+ bool getAllowAutoPadding () const { return AllowAutoPadding; }
359+ void setAllowAutoPadding (bool V) { AllowAutoPadding = V; }
360+
360361 // Content-related functions manage parent's storage using ContentStart and
361362 // ContentSize.
362363 void clearContents () { ContentEnd = ContentStart; }
@@ -407,6 +408,8 @@ class MCEncodedFragment : public MCFragment {
407408 return ArrayRef (getParent ()->FixupStorage )
408409 .slice (FixupStart, FixupEnd - FixupStart);
409410 }
411+
412+ size_t getSize () const { return ContentEnd - ContentStart; }
410413};
411414
412415// / Fragment for data and encoded instructions.
@@ -418,9 +421,6 @@ class MCDataFragment : public MCEncodedFragment {
418421 static bool classof (const MCFragment *F) {
419422 return F->getKind () == MCFragment::FT_Data;
420423 }
421-
422- bool isLinkerRelaxable () const { return LinkerRelaxable; }
423- void setLinkerRelaxable () { LinkerRelaxable = true ; }
424424};
425425
426426// / A relaxable fragment holds on to its MCInst, since it may need to be
@@ -463,9 +463,6 @@ class MCRelaxableFragment : public MCEncodedFragment {
463463 llvm::copy (Inst, S.begin () + OperandStart);
464464 }
465465
466- bool getAllowAutoPadding () const { return AllowAutoPadding; }
467- void setAllowAutoPadding (bool V) { AllowAutoPadding = V; }
468-
469466 static bool classof (const MCFragment *F) {
470467 return F->getKind () == MCFragment::FT_Relaxable;
471468 }
@@ -794,6 +791,11 @@ class MCPseudoProbeAddrFragment : public MCEncodedFragment {
794791 }
795792};
796793
794+ inline MCSection::iterator &MCSection::iterator::operator ++() {
795+ F = F->Next ;
796+ return *this ;
797+ }
798+
797799} // end namespace llvm
798800
799801#endif // LLVM_MC_MCSECTION_H
0 commit comments