Move HasInstructions to MCSection.
[oota-llvm.git] / include / llvm / MC / MCSection.h
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/StringRef.h"
18 #include "llvm/MC/SectionKind.h"
19 #include "llvm/Support/Compiler.h"
20
21 namespace llvm {
22 class MCAsmInfo;
23 class MCContext;
24 class MCExpr;
25 class MCSymbol;
26 class raw_ostream;
27
28 /// Instances of this class represent a uniqued identifier for a section in the
29 /// current translation unit.  The MCContext class uniques and creates these.
30 class MCSection {
31 public:
32   enum SectionVariant { SV_COFF = 0, SV_ELF, SV_MachO };
33
34   /// \brief Express the state of bundle locked groups while emitting code.
35   enum BundleLockStateType {
36     NotBundleLocked,
37     BundleLocked,
38     BundleLockedAlignToEnd
39   };
40
41 private:
42   MCSection(const MCSection &) = delete;
43   void operator=(const MCSection &) = delete;
44
45   MCSymbol *Begin;
46   MCSymbol *End = nullptr;
47   /// The alignment requirement of this section.
48   unsigned Alignment = 1;
49   /// The section index in the assemblers section list.
50   unsigned Ordinal = 0;
51   /// The index of this section in the layout order.
52   unsigned LayoutOrder;
53
54   /// \brief Keeping track of bundle-locked state.
55   BundleLockStateType BundleLockState = NotBundleLocked;
56
57   /// \brief Current nesting depth of bundle_lock directives.
58   unsigned BundleLockNestingDepth = 0;
59
60   /// \brief We've seen a bundle_lock directive but not its first instruction
61   /// yet.
62   bool BundleGroupBeforeFirstInst = false;
63
64   /// Whether this section has had instructions emitted into it.
65   unsigned HasInstructions : 1;
66
67 protected:
68   MCSection(SectionVariant V, SectionKind K, MCSymbol *Begin)
69       : Begin(Begin), HasInstructions(false), Variant(V), Kind(K) {}
70   SectionVariant Variant;
71   SectionKind Kind;
72
73 public:
74   virtual ~MCSection();
75
76   SectionKind getKind() const { return Kind; }
77
78   SectionVariant getVariant() const { return Variant; }
79
80   MCSymbol *getBeginSymbol() { return Begin; }
81   const MCSymbol *getBeginSymbol() const {
82     return const_cast<MCSection *>(this)->getBeginSymbol();
83   }
84   void setBeginSymbol(MCSymbol *Sym) {
85     assert(!Begin);
86     Begin = Sym;
87   }
88   MCSymbol *getEndSymbol(MCContext &Ctx);
89   bool hasEnded() const;
90
91   unsigned getAlignment() const { return Alignment; }
92   void setAlignment(unsigned Value) { Alignment = Value; }
93
94   unsigned getOrdinal() const { return Ordinal; }
95   void setOrdinal(unsigned Value) { Ordinal = Value; }
96
97   unsigned getLayoutOrder() const { return LayoutOrder; }
98   void setLayoutOrder(unsigned Value) { LayoutOrder = Value; }
99
100   BundleLockStateType getBundleLockState() const { return BundleLockState; }
101   void setBundleLockState(BundleLockStateType NewState);
102   bool isBundleLocked() const { return BundleLockState != NotBundleLocked; }
103
104   bool isBundleGroupBeforeFirstInst() const {
105     return BundleGroupBeforeFirstInst;
106   }
107   void setBundleGroupBeforeFirstInst(bool IsFirst) {
108     BundleGroupBeforeFirstInst = IsFirst;
109   }
110
111   bool hasInstructions() const { return HasInstructions; }
112   void setHasInstructions(bool Value) { HasInstructions = Value; }
113
114   virtual void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS,
115                                     const MCExpr *Subsection) const = 0;
116
117   /// Return true if a .align directive should use "optimized nops" to fill
118   /// instead of 0s.
119   virtual bool UseCodeAlign() const = 0;
120
121   /// Check whether this section is "virtual", that is has no actual object
122   /// file contents.
123   virtual bool isVirtualSection() const = 0;
124 };
125
126 } // end namespace llvm
127
128 #endif