Move bundle info from MCSectionData 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 protected:
65   MCSection(SectionVariant V, SectionKind K, MCSymbol *Begin)
66       : Begin(Begin), Variant(V), Kind(K) {}
67   SectionVariant Variant;
68   SectionKind Kind;
69
70 public:
71   virtual ~MCSection();
72
73   SectionKind getKind() const { return Kind; }
74
75   SectionVariant getVariant() const { return Variant; }
76
77   MCSymbol *getBeginSymbol() { return Begin; }
78   const MCSymbol *getBeginSymbol() const {
79     return const_cast<MCSection *>(this)->getBeginSymbol();
80   }
81   void setBeginSymbol(MCSymbol *Sym) {
82     assert(!Begin);
83     Begin = Sym;
84   }
85   MCSymbol *getEndSymbol(MCContext &Ctx);
86   bool hasEnded() const;
87
88   unsigned getAlignment() const { return Alignment; }
89   void setAlignment(unsigned Value) { Alignment = Value; }
90
91   unsigned getOrdinal() const { return Ordinal; }
92   void setOrdinal(unsigned Value) { Ordinal = Value; }
93
94   unsigned getLayoutOrder() const { return LayoutOrder; }
95   void setLayoutOrder(unsigned Value) { LayoutOrder = Value; }
96
97   BundleLockStateType getBundleLockState() const { return BundleLockState; }
98   void setBundleLockState(BundleLockStateType NewState);
99   bool isBundleLocked() const { return BundleLockState != NotBundleLocked; }
100
101   bool isBundleGroupBeforeFirstInst() const {
102     return BundleGroupBeforeFirstInst;
103   }
104   void setBundleGroupBeforeFirstInst(bool IsFirst) {
105     BundleGroupBeforeFirstInst = IsFirst;
106   }
107
108   virtual void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS,
109                                     const MCExpr *Subsection) const = 0;
110
111   /// Return true if a .align directive should use "optimized nops" to fill
112   /// instead of 0s.
113   virtual bool UseCodeAlign() const = 0;
114
115   /// Check whether this section is "virtual", that is has no actual object
116   /// file contents.
117   virtual bool isVirtualSection() const = 0;
118 };
119
120 } // end namespace llvm
121
122 #endif