Convert a std::vector to a SmallVector for another 5.4% speedup on domtree.
[oota-llvm.git] / include / llvm / MC / MCSectionELF.h
1 //===- MCSectionELF.h - ELF 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 MCSectionELF class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_MC_MCSECTIONELF_H
15 #define LLVM_MC_MCSECTIONELF_H
16
17 #include "llvm/MC/MCSection.h"
18 #include "llvm/Support/ELF.h"
19
20 namespace llvm {
21
22 class MCSymbol;
23
24 /// MCSectionELF - This represents a section on linux, lots of unix variants
25 /// and some bare metal systems.
26 class MCSectionELF : public MCSection {
27   /// SectionName - This is the name of the section.  The referenced memory is
28   /// owned by TargetLoweringObjectFileELF's ELFUniqueMap.
29   StringRef SectionName;
30
31   /// Type - This is the sh_type field of a section, drawn from the enums below.
32   unsigned Type;
33
34   /// Flags - This is the sh_flags field of a section, drawn from the enums.
35   /// below.
36   unsigned Flags;
37
38   /// EntrySize - The size of each entry in this section. This size only
39   /// makes sense for sections that contain fixed-sized entries. If a
40   /// section does not contain fixed-sized entries 'EntrySize' will be 0.
41   unsigned EntrySize;
42
43   const MCSymbol *Group;
44
45 private:
46   friend class MCContext;
47   MCSectionELF(StringRef Section, unsigned type, unsigned flags,
48                SectionKind K, unsigned entrySize, const MCSymbol *group)
49     : MCSection(SV_ELF, K), SectionName(Section), Type(type), Flags(flags),
50       EntrySize(entrySize), Group(group) {}
51   ~MCSectionELF();
52 public:
53
54   /// ShouldOmitSectionDirective - Decides whether a '.section' directive
55   /// should be printed before the section name
56   bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
57
58   /// HasCommonSymbols - True if this section holds common symbols, this is
59   /// indicated on the ELF object file by a symbol with SHN_COMMON section
60   /// header index.
61   bool HasCommonSymbols() const;
62
63   StringRef getSectionName() const { return SectionName; }
64   unsigned getType() const { return Type; }
65   unsigned getFlags() const { return Flags; }
66   unsigned getEntrySize() const { return EntrySize; }
67   const MCSymbol *getGroup() const { return Group; }
68
69   void PrintSwitchToSection(const MCAsmInfo &MAI,
70                             raw_ostream &OS) const;
71   virtual bool UseCodeAlign() const;
72   virtual bool isVirtualSection() const;
73
74   /// isBaseAddressKnownZero - We know that non-allocatable sections (like
75   /// debug info) have a base of zero.
76   virtual bool isBaseAddressKnownZero() const {
77     return (getFlags() & ELF::SHF_ALLOC) == 0;
78   }
79
80   static bool classof(const MCSection *S) {
81     return S->getVariant() == SV_ELF;
82   }
83   static bool classof(const MCSectionELF *) { return true; }
84
85   // Return the entry size for sections with fixed-width data.
86   static unsigned DetermineEntrySize(SectionKind Kind);
87
88 };
89
90 } // end namespace llvm
91
92 #endif