LLVM  3.7.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/StringRef.h"
19 #include "llvm/ADT/ilist.h"
20 #include "llvm/ADT/ilist_node.h"
21 #include "llvm/MC/SectionKind.h"
22 #include "llvm/Support/Compiler.h"
23 
24 namespace llvm {
25 class MCAssembler;
26 class MCAsmInfo;
27 class MCContext;
28 class MCExpr;
29 class MCFragment;
30 class MCSection;
31 class MCSymbol;
32 class raw_ostream;
33 
34 template<>
36  MCFragment *createNode(const MCFragment &V);
37  static void deleteNode(MCFragment *V);
38 
43  ilist_iterator<MCFragment> /*last*/) {}
44 };
45 
46 /// Instances of this class represent a uniqued identifier for a section in the
47 /// current translation unit. The MCContext class uniques and creates these.
48 class MCSection {
49 public:
51 
52  /// \brief Express the state of bundle locked groups while emitting code.
57  };
58 
60 
63 
66 
67 private:
68  MCSection(const MCSection &) = delete;
69  void operator=(const MCSection &) = delete;
70 
71  MCSymbol *Begin;
72  MCSymbol *End = nullptr;
73  /// The alignment requirement of this section.
74  unsigned Alignment = 1;
75  /// The section index in the assemblers section list.
76  unsigned Ordinal = 0;
77  /// The index of this section in the layout order.
78  unsigned LayoutOrder;
79 
80  /// \brief Keeping track of bundle-locked state.
81  BundleLockStateType BundleLockState = NotBundleLocked;
82 
83  /// \brief Current nesting depth of bundle_lock directives.
84  unsigned BundleLockNestingDepth = 0;
85 
86  /// \brief We've seen a bundle_lock directive but not its first instruction
87  /// yet.
88  unsigned BundleGroupBeforeFirstInst : 1;
89 
90  /// Whether this section has had instructions emitted into it.
91  unsigned HasInstructions : 1;
92 
93  unsigned IsRegistered : 1;
94 
95  FragmentListType Fragments;
96 
97  /// Mapping from subsection number to insertion point for subsection numbers
98  /// below that number.
99  SmallVector<std::pair<unsigned, MCFragment *>, 1> SubsectionFragmentMap;
100 
101 protected:
105 
106 public:
107  virtual ~MCSection();
108 
109  SectionKind getKind() const { return Kind; }
110 
111  SectionVariant getVariant() const { return Variant; }
112 
113  MCSymbol *getBeginSymbol() { return Begin; }
114  const MCSymbol *getBeginSymbol() const {
115  return const_cast<MCSection *>(this)->getBeginSymbol();
116  }
118  assert(!Begin);
119  Begin = Sym;
120  }
122  bool hasEnded() const;
123 
124  unsigned getAlignment() const { return Alignment; }
125  void setAlignment(unsigned Value) { Alignment = Value; }
126 
127  unsigned getOrdinal() const { return Ordinal; }
128  void setOrdinal(unsigned Value) { Ordinal = Value; }
129 
130  unsigned getLayoutOrder() const { return LayoutOrder; }
131  void setLayoutOrder(unsigned Value) { LayoutOrder = Value; }
132 
133  BundleLockStateType getBundleLockState() const { return BundleLockState; }
135  bool isBundleLocked() const { return BundleLockState != NotBundleLocked; }
136 
138  return BundleGroupBeforeFirstInst;
139  }
140  void setBundleGroupBeforeFirstInst(bool IsFirst) {
141  BundleGroupBeforeFirstInst = IsFirst;
142  }
143 
144  bool hasInstructions() const { return HasInstructions; }
145  void setHasInstructions(bool Value) { HasInstructions = Value; }
146 
147  bool isRegistered() const { return IsRegistered; }
148  void setIsRegistered(bool Value) { IsRegistered = Value; }
149 
152  return const_cast<MCSection *>(this)->getFragmentList();
153  }
154 
157  return const_cast<MCSection *>(this)->begin();
158  }
159 
162  return const_cast<MCSection *>(this)->end();
163  }
164 
167  return const_cast<MCSection *>(this)->rbegin();
168  }
169 
172  return const_cast<MCSection *>(this)->rend();
173  }
174 
176 
177  void dump();
178 
179  virtual void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS,
180  const MCExpr *Subsection) const = 0;
181 
182  /// Return true if a .align directive should use "optimized nops" to fill
183  /// instead of 0s.
184  virtual bool UseCodeAlign() const = 0;
185 
186  /// Check whether this section is "virtual", that is has no actual object
187  /// file contents.
188  virtual bool isVirtualSection() const = 0;
189 };
190 
191 } // end namespace llvm
192 
193 #endif
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:48
bool hasInstructions() const
Definition: MCSection.h:144
void removeNodeFromList(MCFragment *)
Definition: MCSection.h:40
static NodeTy * createNode(const NodeTy &V)
Definition: ilist.h:112
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:111
void setLayoutOrder(unsigned Value)
Definition: MCSection.h:131
void setAlignment(unsigned Value)
Definition: MCSection.h:125
void setBundleLockState(BundleLockStateType NewState)
Definition: MCSection.cpp:37
MCSection::reverse_iterator rbegin()
Definition: MCSection.cpp:107
FragmentListType::const_iterator const_iterator
Definition: MCSection.h:61
MCSection::const_iterator end() const
Definition: MCSection.h:161
unsigned getAlignment() const
Definition: MCSection.h:124
BundleLockStateType
Express the state of bundle locked groups while emitting code.
Definition: MCSection.h:53
void setHasInstructions(bool Value)
Definition: MCSection.h:145
FragmentListType::const_reverse_iterator const_reverse_iterator
Definition: MCSection.h:64
const MCSection::FragmentListType & getFragmentList() const
Definition: MCSection.h:151
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:33
const MCSymbol * getBeginSymbol() const
Definition: MCSection.h:114
MCSection::reverse_iterator rend()
Definition: MCSection.cpp:109
MCSymbol * getEndSymbol(MCContext &Ctx)
Definition: MCSection.cpp:26
Context object for machine code objects.
Definition: MCContext.h:48
MCSection::iterator end()
Definition: MCSection.cpp:105
static void deleteNode(NodeTy *V)
Definition: ilist.h:113
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:58
FragmentListType::iterator iterator
Definition: MCSection.h:62
MCSection::const_reverse_iterator rbegin() const
Definition: MCSection.h:166
MCSection::const_reverse_iterator rend() const
Definition: MCSection.h:171
FragmentListType::reverse_iterator reverse_iterator
Definition: MCSection.h:65
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:28
unsigned getOrdinal() const
Definition: MCSection.h:127
void setIsRegistered(bool Value)
Definition: MCSection.h:148
virtual void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS, const MCExpr *Subsection) const =0
bool isRegistered() const
Definition: MCSection.h:147
virtual bool UseCodeAlign() const =0
Return true if a .align directive should use "optimized nops" to fill instead of 0s.
ilist_node_traits - A fragment for template traits for intrusive list that provides default node rela...
Definition: ilist.h:111
MCSection::iterator begin()
Definition: MCSection.cpp:103
SectionVariant Variant
Definition: MCSection.h:103
void setOrdinal(unsigned Value)
Definition: MCSection.h:128
SectionKind getKind() const
Definition: MCSection.h:109
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:861
MCSymbol * getBeginSymbol()
Definition: MCSection.h:113
std::reverse_iterator< iterator > reverse_iterator
Definition: ilist.h:349
unsigned getLayoutOrder() const
Definition: MCSection.h:130
bool isBundleGroupBeforeFirstInst() const
Definition: MCSection.h:137
BundleLockStateType getBundleLockState() const
Definition: MCSection.h:133
void setBundleGroupBeforeFirstInst(bool IsFirst)
Definition: MCSection.h:140
iplist< MCFragment > FragmentListType
Definition: MCSection.h:59
MCSection::iterator getSubsectionInsertionPoint(unsigned Subsection)
Definition: MCSection.cpp:57
LLVM Value Representation.
Definition: Value.h:69
bool isBundleLocked() const
Definition: MCSection.h:135
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: ilist.h:348
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:38
virtual ~MCSection()
Definition: MCSection.cpp:34
void transferNodesFromList(ilist_node_traits &, ilist_iterator< MCFragment >, ilist_iterator< MCFragment >)
Definition: MCSection.h:41
MCSection::FragmentListType & getFragmentList()
Definition: MCSection.h:150
SectionKind Kind
Definition: MCSection.h:104
MCSection::const_iterator begin() const
Definition: MCSection.h:156
void addNodeToList(MCFragment *)
Definition: MCSection.h:39
void setBeginSymbol(MCSymbol *Sym)
Definition: MCSection.h:117