LLVM  4.0.0
MCSection.h
Go to the documentation of this file.
1 //===- MCSection.h - Machine Code Sections ----------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares the MCSection class.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_MC_MCSECTION_H
15 #define LLVM_MC_MCSECTION_H
16 
17 #include "llvm/ADT/SmallVector.h"
18 #include "llvm/ADT/ilist.h"
19 #include "llvm/ADT/ilist_node.h"
20 #include "llvm/MC/MCFragment.h"
21 #include "llvm/MC/SectionKind.h"
22 #include "llvm/Support/Compiler.h"
23 
24 namespace llvm {
25 class MCAsmInfo;
26 class MCAssembler;
27 class MCContext;
28 class MCExpr;
29 class MCFragment;
30 class MCSection;
31 class MCSymbol;
32 class raw_ostream;
33 
34 template <> struct ilist_alloc_traits<MCFragment> {
35  static void deleteNode(MCFragment *V);
36 };
37 
38 /// Instances of this class represent a uniqued identifier for a section in the
39 /// current translation unit. The MCContext class uniques and creates these.
40 class MCSection {
41 public:
43 
44  /// \brief Express the state of bundle locked groups while emitting code.
49  };
50 
52 
55 
58 
59 private:
60  MCSection(const MCSection &) = delete;
61  void operator=(const MCSection &) = delete;
62 
63  MCSymbol *Begin;
64  MCSymbol *End = nullptr;
65  /// The alignment requirement of this section.
66  unsigned Alignment = 1;
67  /// The section index in the assemblers section list.
68  unsigned Ordinal = 0;
69  /// The index of this section in the layout order.
70  unsigned LayoutOrder;
71 
72  /// \brief Keeping track of bundle-locked state.
73  BundleLockStateType BundleLockState = NotBundleLocked;
74 
75  /// \brief Current nesting depth of bundle_lock directives.
76  unsigned BundleLockNestingDepth = 0;
77 
78  /// \brief We've seen a bundle_lock directive but not its first instruction
79  /// yet.
80  unsigned BundleGroupBeforeFirstInst : 1;
81 
82  /// Whether this section has had instructions emitted into it.
83  unsigned HasInstructions : 1;
84 
85  unsigned IsRegistered : 1;
86 
87  MCDummyFragment DummyFragment;
88 
89  FragmentListType Fragments;
90 
91  /// Mapping from subsection number to insertion point for subsection numbers
92  /// below that number.
93  SmallVector<std::pair<unsigned, MCFragment *>, 1> SubsectionFragmentMap;
94 
95 protected:
99  ~MCSection();
100 
101 public:
102  SectionKind getKind() const { return Kind; }
103 
104  SectionVariant getVariant() const { return Variant; }
105 
106  MCSymbol *getBeginSymbol() { return Begin; }
107  const MCSymbol *getBeginSymbol() const {
108  return const_cast<MCSection *>(this)->getBeginSymbol();
109  }
111  assert(!Begin);
112  Begin = Sym;
113  }
115  bool hasEnded() const;
116 
117  unsigned getAlignment() const { return Alignment; }
118  void setAlignment(unsigned Value) { Alignment = Value; }
119 
120  unsigned getOrdinal() const { return Ordinal; }
121  void setOrdinal(unsigned Value) { Ordinal = Value; }
122 
123  unsigned getLayoutOrder() const { return LayoutOrder; }
124  void setLayoutOrder(unsigned Value) { LayoutOrder = Value; }
125 
126  BundleLockStateType getBundleLockState() const { return BundleLockState; }
128  bool isBundleLocked() const { return BundleLockState != NotBundleLocked; }
129 
131  return BundleGroupBeforeFirstInst;
132  }
133  void setBundleGroupBeforeFirstInst(bool IsFirst) {
134  BundleGroupBeforeFirstInst = IsFirst;
135  }
136 
137  bool hasInstructions() const { return HasInstructions; }
138  void setHasInstructions(bool Value) { HasInstructions = Value; }
139 
140  bool isRegistered() const { return IsRegistered; }
141  void setIsRegistered(bool Value) { IsRegistered = Value; }
142 
145  return const_cast<MCSection *>(this)->getFragmentList();
146  }
147 
148  /// Support for MCFragment::getNextNode().
150  return &MCSection::Fragments;
151  }
152 
153  const MCDummyFragment &getDummyFragment() const { return DummyFragment; }
154  MCDummyFragment &getDummyFragment() { return DummyFragment; }
155 
156  iterator begin() { return Fragments.begin(); }
157  const_iterator begin() const { return Fragments.begin(); }
158 
159  iterator end() { return Fragments.end(); }
160  const_iterator end() const { return Fragments.end(); }
161 
162  reverse_iterator rbegin() { return Fragments.rbegin(); }
163  const_reverse_iterator rbegin() const { return Fragments.rbegin(); }
164 
165  reverse_iterator rend() { return Fragments.rend(); }
166  const_reverse_iterator rend() const { return Fragments.rend(); }
167 
169 
170  void dump();
171 
172  virtual void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS,
173  const MCExpr *Subsection) const = 0;
174 
175  /// Return true if a .align directive should use "optimized nops" to fill
176  /// instead of 0s.
177  virtual bool UseCodeAlign() const = 0;
178 
179  /// Check whether this section is "virtual", that is has no actual object
180  /// file contents.
181  virtual bool isVirtualSection() const = 0;
182 };
183 
184 } // end namespace llvm
185 
186 #endif
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:40
bool hasInstructions() const
Definition: MCSection.h:137
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:39
bool hasEnded() const
Definition: MCSection.cpp:32
SectionVariant getVariant() const
Definition: MCSection.h:104
void setLayoutOrder(unsigned Value)
Definition: MCSection.h:124
const MCDummyFragment & getDummyFragment() const
Definition: MCSection.h:153
reverse_iterator rend()
Definition: MCSection.h:165
void setAlignment(unsigned Value)
Definition: MCSection.h:118
void setBundleLockState(BundleLockStateType NewState)
Definition: MCSection.cpp:37
FragmentListType::const_iterator const_iterator
Definition: MCSection.h:53
unsigned getAlignment() const
Definition: MCSection.h:117
BundleLockStateType
Express the state of bundle locked groups while emitting code.
Definition: MCSection.h:45
void setHasInstructions(bool Value)
Definition: MCSection.h:138
FragmentListType::const_reverse_iterator const_reverse_iterator
Definition: MCSection.h:56
const MCSection::FragmentListType & getFragmentList() const
Definition: MCSection.h:144
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:34
const MCSymbol * getBeginSymbol() const
Definition: MCSection.h:107
MCSymbol * getEndSymbol(MCContext &Ctx)
Definition: MCSection.cpp:26
Context object for machine code objects.
Definition: MCContext.h:51
reverse_iterator rbegin()
Definition: MCSection.h:162
const_reverse_iterator rend() const
Definition: MCSection.h:166
const_iterator begin() const
Definition: MCSection.h:157
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:57
Use delete by default for iplist and ilist.
Definition: ilist.h:41
FragmentListType::iterator iterator
Definition: MCSection.h:54
FragmentListType::reverse_iterator reverse_iterator
Definition: MCSection.h:57
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:23
unsigned getOrdinal() const
Definition: MCSection.h:120
void setIsRegistered(bool Value)
Definition: MCSection.h:141
virtual void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS, const MCExpr *Subsection) const =0
bool isRegistered() const
Definition: MCSection.h:140
virtual bool UseCodeAlign() const =0
Return true if a .align directive should use "optimized nops" to fill instead of 0s.
SectionVariant Variant
Definition: MCSection.h:97
void setOrdinal(unsigned Value)
Definition: MCSection.h:121
Iterator for intrusive lists based on ilist_node.
SectionKind getKind() const
Definition: MCSection.h:102
virtual bool isVirtualSection() const =0
Check whether this section is "virtual", that is has no actual object file contents.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:843
MCSymbol * getBeginSymbol()
Definition: MCSection.h:106
static void deleteNode(NodeTy *V)
Definition: ilist.h:42
static FragmentListType MCSection::* getSublistAccess(MCFragment *)
Support for MCFragment::getNextNode().
Definition: MCSection.h:149
unsigned getLayoutOrder() const
Definition: MCSection.h:123
bool isBundleGroupBeforeFirstInst() const
Definition: MCSection.h:130
const_reverse_iterator rbegin() const
Definition: MCSection.h:163
BundleLockStateType getBundleLockState() const
Definition: MCSection.h:126
void setBundleGroupBeforeFirstInst(bool IsFirst)
Definition: MCSection.h:133
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const_iterator end() const
Definition: MCSection.h:160
iplist< MCFragment > FragmentListType
Definition: MCSection.h:51
MCSection::iterator getSubsectionInsertionPoint(unsigned Subsection)
Definition: MCSection.cpp:57
LLVM Value Representation.
Definition: Value.h:71
bool isBundleLocked() const
Definition: MCSection.h:128
MCDummyFragment & getDummyFragment()
Definition: MCSection.h:154
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
iterator end()
Definition: MCSection.h:159
MCSection::FragmentListType & getFragmentList()
Definition: MCSection.h:143
SectionKind Kind
Definition: MCSection.h:98
iterator begin()
Definition: MCSection.h:156
void setBeginSymbol(MCSymbol *Sym)
Definition: MCSection.h:110