Fix typo in comment. NFC.
[oota-llvm.git] / include / llvm / MC / MCContext.h
index fd0181e66ab0521768b3373ead92b5c15dec9c2a..db2afa50b6628c2ccdeadcb9765d74fd3094f383 100644 (file)
@@ -17,6 +17,7 @@
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/Twine.h"
 #include "llvm/MC/MCDwarf.h"
+#include "llvm/MC/MCSubtargetInfo.h"
 #include "llvm/MC/SectionKind.h"
 #include "llvm/Support/Allocator.h"
 #include "llvm/Support/Compiler.h"
@@ -30,6 +31,7 @@ namespace llvm {
   class MCExpr;
   class MCSection;
   class MCSymbol;
+  class MCSymbolELF;
   class MCLabel;
   struct MCDwarfFile;
   class MCDwarfLoc;
@@ -70,12 +72,16 @@ namespace llvm {
     /// objects.
     BumpPtrAllocator Allocator;
 
+    SpecificBumpPtrAllocator<MCSectionCOFF> COFFAllocator;
+    SpecificBumpPtrAllocator<MCSectionELF> ELFAllocator;
+    SpecificBumpPtrAllocator<MCSectionMachO> MachOAllocator;
+
     /// Bindings of names to symbols.
     SymbolTable Symbols;
 
     /// ELF sections can have a corresponding symbol. This maps one to the
     /// other.
-    DenseMap<const MCSectionELF *, MCSymbol *> SectionSymbols;
+    DenseMap<const MCSectionELF *, MCSymbolELF *> SectionSymbols;
 
     /// A mapping from a local label number and an instance count to a symbol.
     /// For example, in the assembly
@@ -136,10 +142,8 @@ namespace llvm {
     /// assembly source files.
     unsigned GenDwarfFileNumber;
 
-    /// Symbols created for the start and end of each section, used for
-    /// generating the .debug_ranges and .debug_aranges sections.
-    MapVector<const MCSection *, std::pair<MCSymbol *, MCSymbol *>>
-        SectionStartEndSyms;
+    /// Sections for generating the .debug_ranges and .debug_aranges sections.
+    SetVector<MCSection *> SectionsForRanges;
 
     /// The information gathered from labels that will have dwarf label
     /// entries when generating dwarf assembly source files.
@@ -199,15 +203,22 @@ namespace llvm {
       }
     };
 
-    StringMap<const MCSectionMachO *> MachOUniquingMap;
-    std::map<ELFSectionKey, const MCSectionELF *> ELFUniquingMap;
-    std::map<COFFSectionKey, const MCSectionCOFF *> COFFUniquingMap;
+    StringMap<MCSectionMachO *> MachOUniquingMap;
+    std::map<ELFSectionKey, MCSectionELF *> ELFUniquingMap;
+    std::map<COFFSectionKey, MCSectionCOFF *> COFFUniquingMap;
     StringMap<bool> ELFRelSecNames;
 
+    SpecificBumpPtrAllocator<MCSubtargetInfo> MCSubtargetAllocator;
+
     /// Do automatic reset in destructor
     bool AutoReset;
 
-    MCSymbol *CreateSymbol(StringRef Name, bool AlwaysAddSuffix);
+    bool HadError;
+
+    MCSymbol *createSymbolImpl(const StringMapEntry<bool> *Name,
+                               bool CanBeUnnamed);
+    MCSymbol *createSymbol(StringRef Name, bool AlwaysAddSuffix,
+                           bool IsTemporary);
 
     MCSymbol *getOrCreateDirectionalLocalSymbol(unsigned LocalLabelVal,
                                                 unsigned Instance);
@@ -247,9 +258,10 @@ namespace llvm {
 
     /// Create and return a new assembler temporary symbol with a unique but
     /// unspecified name.
-    MCSymbol *createTempSymbol();
+    MCSymbol *createTempSymbol(bool CanBeUnnamed = true);
 
-    MCSymbol *createTempSymbol(const Twine &Name, bool AlwaysAddSuffix);
+    MCSymbol *createTempSymbol(const Twine &Name, bool AlwaysAddSuffix,
+                               bool CanBeUnnamed = true);
 
     /// Create the definition of a directional local symbol for numbered label
     /// (used for "1:" definitions).
@@ -265,12 +277,12 @@ namespace llvm {
     /// \param Name - The symbol name, which must be unique across all symbols.
     MCSymbol *getOrCreateSymbol(const Twine &Name);
 
-    MCSymbol *getOrCreateSectionSymbol(const MCSectionELF &Section);
+    MCSymbolELF *getOrCreateSectionSymbol(const MCSectionELF &Section);
 
     /// Gets a symbol that will be defined to the final stack offset of a local
     /// variable after codegen.
     ///
-    /// \param Idx - The index of a local variable passed to @llvm.frameescape.
+    /// \param Idx - The index of a local variable passed to @llvm.localescape.
     MCSymbol *getOrCreateFrameAllocSymbol(StringRef FuncName, unsigned Idx);
 
     MCSymbol *getOrCreateParentFrameOffsetSymbol(StringRef FuncName);
@@ -293,90 +305,88 @@ namespace llvm {
 
     /// Return the MCSection for the specified mach-o section.  This requires
     /// the operands to be valid.
-    const MCSectionMachO *getMachOSection(StringRef Segment, StringRef Section,
-                                          unsigned TypeAndAttributes,
-                                          unsigned Reserved2, SectionKind K,
-                                          const char *BeginSymName = nullptr);
-
-    const MCSectionMachO *getMachOSection(StringRef Segment, StringRef Section,
-                                          unsigned TypeAndAttributes,
-                                          SectionKind K,
-                                          const char *BeginSymName = nullptr) {
+    MCSectionMachO *getMachOSection(StringRef Segment, StringRef Section,
+                                    unsigned TypeAndAttributes,
+                                    unsigned Reserved2, SectionKind K,
+                                    const char *BeginSymName = nullptr);
+
+    MCSectionMachO *getMachOSection(StringRef Segment, StringRef Section,
+                                    unsigned TypeAndAttributes, SectionKind K,
+                                    const char *BeginSymName = nullptr) {
       return getMachOSection(Segment, Section, TypeAndAttributes, 0, K,
                              BeginSymName);
     }
 
-    const MCSectionELF *getELFSection(StringRef Section, unsigned Type,
-                                      unsigned Flags) {
+    MCSectionELF *getELFSection(StringRef Section, unsigned Type,
+                                unsigned Flags) {
       return getELFSection(Section, Type, Flags, nullptr);
     }
 
-    const MCSectionELF *getELFSection(StringRef Section, unsigned Type,
-                                      unsigned Flags,
-                                      const char *BeginSymName) {
+    MCSectionELF *getELFSection(StringRef Section, unsigned Type,
+                                unsigned Flags, const char *BeginSymName) {
       return getELFSection(Section, Type, Flags, 0, "", BeginSymName);
     }
 
-    const MCSectionELF *getELFSection(StringRef Section, unsigned Type,
-                                      unsigned Flags, unsigned EntrySize,
-                                      StringRef Group) {
+    MCSectionELF *getELFSection(StringRef Section, unsigned Type,
+                                unsigned Flags, unsigned EntrySize,
+                                StringRef Group) {
       return getELFSection(Section, Type, Flags, EntrySize, Group, nullptr);
     }
 
-    const MCSectionELF *getELFSection(StringRef Section, unsigned Type,
-                                      unsigned Flags, unsigned EntrySize,
-                                      StringRef Group,
-                                      const char *BeginSymName) {
+    MCSectionELF *getELFSection(StringRef Section, unsigned Type,
+                                unsigned Flags, unsigned EntrySize,
+                                StringRef Group, const char *BeginSymName) {
       return getELFSection(Section, Type, Flags, EntrySize, Group, ~0,
                            BeginSymName);
     }
 
-    const MCSectionELF *getELFSection(StringRef Section, unsigned Type,
-                                      unsigned Flags, unsigned EntrySize,
-                                      StringRef Group, unsigned UniqueID) {
+    MCSectionELF *getELFSection(StringRef Section, unsigned Type,
+                                unsigned Flags, unsigned EntrySize,
+                                StringRef Group, unsigned UniqueID) {
       return getELFSection(Section, Type, Flags, EntrySize, Group, UniqueID,
                            nullptr);
     }
 
-    const MCSectionELF *getELFSection(StringRef Section, unsigned Type,
-                                      unsigned Flags, unsigned EntrySize,
-                                      StringRef Group, unsigned UniqueID,
-                                      const char *BeginSymName);
+    MCSectionELF *getELFSection(StringRef Section, unsigned Type,
+                                unsigned Flags, unsigned EntrySize,
+                                StringRef Group, unsigned UniqueID,
+                                const char *BeginSymName);
+
+    MCSectionELF *getELFSection(StringRef Section, unsigned Type,
+                                unsigned Flags, unsigned EntrySize,
+                                const MCSymbolELF *Group, unsigned UniqueID,
+                                const char *BeginSymName,
+                                const MCSectionELF *Associated);
 
-    const MCSectionELF *getELFSection(StringRef Section, unsigned Type,
+    MCSectionELF *createELFRelSection(StringRef Name, unsigned Type,
                                       unsigned Flags, unsigned EntrySize,
-                                      const MCSymbol *Group, unsigned UniqueID,
-                                      const char *BeginSymName,
+                                      const MCSymbolELF *Group,
                                       const MCSectionELF *Associated);
 
-    const MCSectionELF *createELFRelSection(StringRef Name, unsigned Type,
-                                            unsigned Flags, unsigned EntrySize,
-                                            const MCSymbol *Group,
-                                            const MCSectionELF *Associated);
-
-    void renameELFSection(const MCSectionELF *Section, StringRef Name);
+    void renameELFSection(MCSectionELF *Section, StringRef Name);
 
-    const MCSectionELF *createELFGroupSection(const MCSymbol *Group);
+    MCSectionELF *createELFGroupSection(const MCSymbolELF *Group);
 
-    const MCSectionCOFF *getCOFFSection(StringRef Section,
-                                        unsigned Characteristics,
-                                        SectionKind Kind,
-                                        StringRef COMDATSymName, int Selection,
-                                        const char *BeginSymName = nullptr);
+    MCSectionCOFF *getCOFFSection(StringRef Section, unsigned Characteristics,
+                                  SectionKind Kind, StringRef COMDATSymName,
+                                  int Selection,
+                                  const char *BeginSymName = nullptr);
 
-    const MCSectionCOFF *getCOFFSection(StringRef Section,
-                                        unsigned Characteristics,
-                                        SectionKind Kind,
-                                        const char *BeginSymName = nullptr);
+    MCSectionCOFF *getCOFFSection(StringRef Section, unsigned Characteristics,
+                                  SectionKind Kind,
+                                  const char *BeginSymName = nullptr);
 
-    const MCSectionCOFF *getCOFFSection(StringRef Section);
+    MCSectionCOFF *getCOFFSection(StringRef Section);
 
     /// Gets or creates a section equivalent to Sec that is associated with the
     /// section containing KeySym. For example, to create a debug info section
     /// associated with an inline function, pass the normal debug info section
     /// as Sec and the function symbol as KeySym.
-    const MCSectionCOFF *getAssociativeCOFFSection(const MCSectionCOFF *Sec,
-                                                   const MCSymbol *KeySym);
+    MCSectionCOFF *getAssociativeCOFFSection(MCSectionCOFF *Sec,
+                                             const MCSymbol *KeySym);
+
+    // Create and save a copy of STI and return a reference to the copy.
+    MCSubtargetInfo &getSubtargetCopy(const MCSubtargetInfo &STI);
 
     /// @}
 
@@ -469,17 +479,13 @@ namespace llvm {
     void setGenDwarfFileNumber(unsigned FileNumber) {
       GenDwarfFileNumber = FileNumber;
     }
-    MapVector<const MCSection *, std::pair<MCSymbol *, MCSymbol *>> &
-    getGenDwarfSectionSyms() {
-      return SectionStartEndSyms;
+    const SetVector<MCSection *> &getGenDwarfSectionSyms() {
+      return SectionsForRanges;
     }
-    std::pair<MapVector<const MCSection *,
-                        std::pair<MCSymbol *, MCSymbol *>>::iterator,
-              bool>
-    addGenDwarfSection(const MCSection *Sec) {
-      return SectionStartEndSyms.insert(
-          std::make_pair(Sec, std::make_pair(nullptr, nullptr)));
+    bool addGenDwarfSection(MCSection *Sec) {
+      return SectionsForRanges.insert(Sec);
     }
+
     void finalizeDwarfSections(MCStreamer &MCOS);
     const std::vector<MCGenDwarfLabelEntry> &getMCGenDwarfLabelEntries() const {
       return MCGenDwarfLabelEntries;
@@ -510,11 +516,13 @@ namespace llvm {
     }
     void deallocate(void *Ptr) {}
 
+    bool hadError() { return HadError; }
+    void reportError(SMLoc L, const Twine &Msg);
     // Unrecoverable error has occurred. Display the best diagnostic we can
     // and bail via exit(1). For now, most MC backend errors are unrecoverable.
     // FIXME: We should really do something about that.
     LLVM_ATTRIBUTE_NORETURN void reportFatalError(SMLoc L,
-                                                  const Twine &Msg) const;
+                                                  const Twine &Msg);
   };
 
 } // end namespace llvm
@@ -544,7 +552,7 @@ namespace llvm {
 ///                  allocator supports it).
 /// \return The allocated memory. Could be NULL.
 inline void *operator new(size_t Bytes, llvm::MCContext &C,
-                          size_t Alignment = 8) throw() {
+                          size_t Alignment = 8) LLVM_NOEXCEPT {
   return C.allocate(Bytes, Alignment);
 }
 /// \brief Placement delete companion to the new above.
@@ -553,8 +561,8 @@ inline void *operator new(size_t Bytes, llvm::MCContext &C,
 /// invoking it directly; see the new operator for more details. This operator
 /// is called implicitly by the compiler if a placement new expression using
 /// the MCContext throws in the object constructor.
-inline void operator delete(void *Ptr, llvm::MCContext &C, size_t)
-              throw () {
+inline void operator delete(void *Ptr, llvm::MCContext &C,
+                            size_t) LLVM_NOEXCEPT {
   C.deallocate(Ptr);
 }
 
@@ -577,8 +585,8 @@ inline void operator delete(void *Ptr, llvm::MCContext &C, size_t)
 /// \param Alignment The alignment of the allocated memory (if the underlying
 ///                  allocator supports it).
 /// \return The allocated memory. Could be NULL.
-inline void *operator new[](size_t Bytes, llvm::MCContextC,
-                            size_t Alignment = 8) throw() {
+inline void *operator new[](size_t Bytes, llvm::MCContext &C,
+                            size_t Alignment = 8) LLVM_NOEXCEPT {
   return C.allocate(Bytes, Alignment);
 }
 
@@ -588,7 +596,7 @@ inline void *operator new[](size_t Bytes, llvm::MCContext& C,
 /// invoking it directly; see the new[] operator for more details. This operator
 /// is called implicitly by the compiler if a placement new[] expression using
 /// the MCContext throws in the object constructor.
-inline void operator delete[](void *Ptr, llvm::MCContext &C) throw () {
+inline void operator delete[](void *Ptr, llvm::MCContext &C) LLVM_NOEXCEPT {
   C.deallocate(Ptr);
 }