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;
65 MCSection(SectionVariant V, SectionKind K, MCSymbol *Begin)
66 : Begin(Begin), Variant(V), Kind(K) {}
67 SectionVariant Variant;
73 SectionKind getKind() const { return Kind; }
75 SectionVariant getVariant() const { return Variant; }
77 MCSymbol *getBeginSymbol() { return Begin; }
78 const MCSymbol *getBeginSymbol() const {
79 return const_cast<MCSection *>(this)->getBeginSymbol();
81 void setBeginSymbol(MCSymbol *Sym) {
85 MCSymbol *getEndSymbol(MCContext &Ctx);
86 bool hasEnded() const;
88 unsigned getAlignment() const { return Alignment; }
89 void setAlignment(unsigned Value) { Alignment = Value; }
91 unsigned getOrdinal() const { return Ordinal; }
92 void setOrdinal(unsigned Value) { Ordinal = Value; }
94 unsigned getLayoutOrder() const { return LayoutOrder; }
95 void setLayoutOrder(unsigned Value) { LayoutOrder = Value; }
97 BundleLockStateType getBundleLockState() const { return BundleLockState; }
98 void setBundleLockState(BundleLockStateType NewState);
99 bool isBundleLocked() const { return BundleLockState != NotBundleLocked; }
101 bool isBundleGroupBeforeFirstInst() const {
102 return BundleGroupBeforeFirstInst;
104 void setBundleGroupBeforeFirstInst(bool IsFirst) {
105 BundleGroupBeforeFirstInst = IsFirst;
108 virtual void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS,
109 const MCExpr *Subsection) const = 0;
111 /// Return true if a .align directive should use "optimized nops" to fill
113 virtual bool UseCodeAlign() const = 0;
115 /// Check whether this section is "virtual", that is has no actual object
117 virtual bool isVirtualSection() const = 0;
120 } // end namespace llvm