1 //===- MCSection.h - Machine Code Sections ----------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the MCSection class.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_MC_MCSECTION_H
15 #define LLVM_MC_MCSECTION_H
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/MC/SectionKind.h"
19 #include "llvm/Support/Compiler.h"
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.
32 enum SectionVariant { SV_COFF = 0, SV_ELF, SV_MachO };
34 /// \brief Express the state of bundle locked groups while emitting code.
35 enum BundleLockStateType {
38 BundleLockedAlignToEnd
42 MCSection(const MCSection &) = delete;
43 void operator=(const MCSection &) = delete;
46 MCSymbol *End = nullptr;
47 /// The alignment requirement of this section.
48 unsigned Alignment = 1;
49 /// The section index in the assemblers section list.
51 /// The index of this section in the layout order.
54 /// \brief Keeping track of bundle-locked state.
55 BundleLockStateType BundleLockState = NotBundleLocked;
57 /// \brief Current nesting depth of bundle_lock directives.
58 unsigned BundleLockNestingDepth = 0;
60 /// \brief We've seen a bundle_lock directive but not its first instruction
62 bool BundleGroupBeforeFirstInst = false;
64 /// Whether this section has had instructions emitted into it.
65 unsigned HasInstructions : 1;
68 MCSection(SectionVariant V, SectionKind K, MCSymbol *Begin)
69 : Begin(Begin), HasInstructions(false), Variant(V), Kind(K) {}
70 SectionVariant Variant;
76 SectionKind getKind() const { return Kind; }
78 SectionVariant getVariant() const { return Variant; }
80 MCSymbol *getBeginSymbol() { return Begin; }
81 const MCSymbol *getBeginSymbol() const {
82 return const_cast<MCSection *>(this)->getBeginSymbol();
84 void setBeginSymbol(MCSymbol *Sym) {
88 MCSymbol *getEndSymbol(MCContext &Ctx);
89 bool hasEnded() const;
91 unsigned getAlignment() const { return Alignment; }
92 void setAlignment(unsigned Value) { Alignment = Value; }
94 unsigned getOrdinal() const { return Ordinal; }
95 void setOrdinal(unsigned Value) { Ordinal = Value; }
97 unsigned getLayoutOrder() const { return LayoutOrder; }
98 void setLayoutOrder(unsigned Value) { LayoutOrder = Value; }
100 BundleLockStateType getBundleLockState() const { return BundleLockState; }
101 void setBundleLockState(BundleLockStateType NewState);
102 bool isBundleLocked() const { return BundleLockState != NotBundleLocked; }
104 bool isBundleGroupBeforeFirstInst() const {
105 return BundleGroupBeforeFirstInst;
107 void setBundleGroupBeforeFirstInst(bool IsFirst) {
108 BundleGroupBeforeFirstInst = IsFirst;
111 bool hasInstructions() const { return HasInstructions; }
112 void setHasInstructions(bool Value) { HasInstructions = Value; }
114 virtual void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS,
115 const MCExpr *Subsection) const = 0;
117 /// Return true if a .align directive should use "optimized nops" to fill
119 virtual bool UseCodeAlign() const = 0;
121 /// Check whether this section is "virtual", that is has no actual object
123 virtual bool isVirtualSection() const = 0;
126 } // end namespace llvm