LCOV - code coverage report
Current view: top level - include/llvm/MC - MCContext.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 43 53 81.1 %
Date: 2018-02-22 16:16:46 Functions: 5 6 83.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- MCContext.h - Machine Code Context -----------------------*- 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             : #ifndef LLVM_MC_MCCONTEXT_H
      11             : #define LLVM_MC_MCCONTEXT_H
      12             : 
      13             : #include "llvm/ADT/DenseMap.h"
      14             : #include "llvm/ADT/SetVector.h"
      15             : #include "llvm/ADT/SmallString.h"
      16             : #include "llvm/ADT/SmallVector.h"
      17             : #include "llvm/ADT/StringMap.h"
      18             : #include "llvm/ADT/StringRef.h"
      19             : #include "llvm/ADT/Twine.h"
      20             : #include "llvm/BinaryFormat/Dwarf.h"
      21             : #include "llvm/MC/MCAsmMacro.h"
      22             : #include "llvm/MC/MCDwarf.h"
      23             : #include "llvm/MC/MCSubtargetInfo.h"
      24             : #include "llvm/MC/SectionKind.h"
      25             : #include "llvm/Support/Allocator.h"
      26             : #include "llvm/Support/Compiler.h"
      27             : #include "llvm/Support/MD5.h"
      28             : #include "llvm/Support/raw_ostream.h"
      29             : #include <algorithm>
      30             : #include <cassert>
      31             : #include <cstddef>
      32             : #include <cstdint>
      33             : #include <map>
      34             : #include <memory>
      35             : #include <string>
      36             : #include <utility>
      37             : #include <vector>
      38             : 
      39             : namespace llvm {
      40             : 
      41             :   class CodeViewContext;
      42             :   class MCAsmInfo;
      43             :   class MCLabel;
      44             :   class MCObjectFileInfo;
      45             :   class MCRegisterInfo;
      46             :   class MCSection;
      47             :   class MCSectionCOFF;
      48             :   class MCSectionELF;
      49             :   class MCSectionMachO;
      50             :   class MCSectionWasm;
      51             :   class MCStreamer;
      52             :   class MCSymbol;
      53             :   class MCSymbolELF;
      54             :   class MCSymbolWasm;
      55             :   class SMLoc;
      56             :   class SourceMgr;
      57             : 
      58             :   /// Context object for machine code objects.  This class owns all of the
      59             :   /// sections that it creates.
      60             :   ///
      61             :   class MCContext {
      62             :   public:
      63             :     using SymbolTable = StringMap<MCSymbol *, BumpPtrAllocator &>;
      64             : 
      65             :   private:
      66             :     /// The SourceMgr for this object, if any.
      67             :     const SourceMgr *SrcMgr;
      68             : 
      69             :     /// The SourceMgr for inline assembly, if any.
      70             :     SourceMgr *InlineSrcMgr;
      71             : 
      72             :     /// The MCAsmInfo for this target.
      73             :     const MCAsmInfo *MAI;
      74             : 
      75             :     /// The MCRegisterInfo for this target.
      76             :     const MCRegisterInfo *MRI;
      77             : 
      78             :     /// The MCObjectFileInfo for this target.
      79             :     const MCObjectFileInfo *MOFI;
      80             : 
      81             :     std::unique_ptr<CodeViewContext> CVContext;
      82             : 
      83             :     /// Allocator object used for creating machine code objects.
      84             :     ///
      85             :     /// We use a bump pointer allocator to avoid the need to track all allocated
      86             :     /// objects.
      87             :     BumpPtrAllocator Allocator;
      88             : 
      89             :     SpecificBumpPtrAllocator<MCSectionCOFF> COFFAllocator;
      90             :     SpecificBumpPtrAllocator<MCSectionELF> ELFAllocator;
      91             :     SpecificBumpPtrAllocator<MCSectionMachO> MachOAllocator;
      92             :     SpecificBumpPtrAllocator<MCSectionWasm> WasmAllocator;
      93             : 
      94             :     /// Bindings of names to symbols.
      95             :     SymbolTable Symbols;
      96             : 
      97             :     /// A mapping from a local label number and an instance count to a symbol.
      98             :     /// For example, in the assembly
      99             :     ///     1:
     100             :     ///     2:
     101             :     ///     1:
     102             :     /// We have three labels represented by the pairs (1, 0), (2, 0) and (1, 1)
     103             :     DenseMap<std::pair<unsigned, unsigned>, MCSymbol *> LocalSymbols;
     104             : 
     105             :     /// Keeps tracks of names that were used both for used declared and
     106             :     /// artificial symbols. The value is "true" if the name has been used for a
     107             :     /// non-section symbol (there can be at most one of those, plus an unlimited
     108             :     /// number of section symbols with the same name).
     109             :     StringMap<bool, BumpPtrAllocator &> UsedNames;
     110             : 
     111             :     /// The next ID to dole out to an unnamed assembler temporary symbol with
     112             :     /// a given prefix.
     113             :     StringMap<unsigned> NextID;
     114             : 
     115             :     /// Instances of directional local labels.
     116             :     DenseMap<unsigned, MCLabel *> Instances;
     117             :     /// NextInstance() creates the next instance of the directional local label
     118             :     /// for the LocalLabelVal and adds it to the map if needed.
     119             :     unsigned NextInstance(unsigned LocalLabelVal);
     120             :     /// GetInstance() gets the current instance of the directional local label
     121             :     /// for the LocalLabelVal and adds it to the map if needed.
     122             :     unsigned GetInstance(unsigned LocalLabelVal);
     123             : 
     124             :     /// The file name of the log file from the environment variable
     125             :     /// AS_SECURE_LOG_FILE.  Which must be set before the .secure_log_unique
     126             :     /// directive is used or it is an error.
     127             :     char *SecureLogFile;
     128             :     /// The stream that gets written to for the .secure_log_unique directive.
     129             :     std::unique_ptr<raw_fd_ostream> SecureLog;
     130             :     /// Boolean toggled when .secure_log_unique / .secure_log_reset is seen to
     131             :     /// catch errors if .secure_log_unique appears twice without
     132             :     /// .secure_log_reset appearing between them.
     133             :     bool SecureLogUsed = false;
     134             : 
     135             :     /// The compilation directory to use for DW_AT_comp_dir.
     136             :     SmallString<128> CompilationDir;
     137             : 
     138             :     /// The main file name if passed in explicitly.
     139             :     std::string MainFileName;
     140             : 
     141             :     /// The dwarf file and directory tables from the dwarf .file directive.
     142             :     /// We now emit a line table for each compile unit. To reduce the prologue
     143             :     /// size of each line table, the files and directories used by each compile
     144             :     /// unit are separated.
     145             :     std::map<unsigned, MCDwarfLineTable> MCDwarfLineTablesCUMap;
     146             : 
     147             :     /// The current dwarf line information from the last dwarf .loc directive.
     148             :     MCDwarfLoc CurrentDwarfLoc;
     149             :     bool DwarfLocSeen = false;
     150             : 
     151             :     /// Generate dwarf debugging info for assembly source files.
     152             :     bool GenDwarfForAssembly = false;
     153             : 
     154             :     /// The current dwarf file number when generate dwarf debugging info for
     155             :     /// assembly source files.
     156             :     unsigned GenDwarfFileNumber = 0;
     157             : 
     158             :     /// Sections for generating the .debug_ranges and .debug_aranges sections.
     159             :     SetVector<MCSection *> SectionsForRanges;
     160             : 
     161             :     /// The information gathered from labels that will have dwarf label
     162             :     /// entries when generating dwarf assembly source files.
     163             :     std::vector<MCGenDwarfLabelEntry> MCGenDwarfLabelEntries;
     164             : 
     165             :     /// The string to embed in the debug information for the compile unit, if
     166             :     /// non-empty.
     167             :     StringRef DwarfDebugFlags;
     168             : 
     169             :     /// The string to embed in as the dwarf AT_producer for the compile unit, if
     170             :     /// non-empty.
     171             :     StringRef DwarfDebugProducer;
     172             : 
     173             :     /// The maximum version of dwarf that we should emit.
     174             :     uint16_t DwarfVersion = 4;
     175             : 
     176             :     /// Honor temporary labels, this is useful for debugging semantic
     177             :     /// differences between temporary and non-temporary labels (primarily on
     178             :     /// Darwin).
     179             :     bool AllowTemporaryLabels = true;
     180             :     bool UseNamesOnTempLabels = true;
     181             : 
     182             :     /// The Compile Unit ID that we are currently processing.
     183             :     unsigned DwarfCompileUnitID = 0;
     184             : 
     185     4335059 :     struct ELFSectionKey {
     186             :       std::string SectionName;
     187             :       StringRef GroupName;
     188             :       unsigned UniqueID;
     189             : 
     190             :       ELFSectionKey(StringRef SectionName, StringRef GroupName,
     191             :                     unsigned UniqueID)
     192     3186255 :           : SectionName(SectionName), GroupName(GroupName), UniqueID(UniqueID) {
     193             :       }
     194             : 
     195    13930409 :       bool operator<(const ELFSectionKey &Other) const {
     196    27860818 :         if (SectionName != Other.SectionName)
     197    13485681 :           return SectionName < Other.SectionName;
     198             :         if (GroupName != Other.GroupName)
     199         148 :           return GroupName < Other.GroupName;
     200      444580 :         return UniqueID < Other.UniqueID;
     201             :       }
     202             :     };
     203             : 
     204      126263 :     struct COFFSectionKey {
     205             :       std::string SectionName;
     206             :       StringRef GroupName;
     207             :       int SelectionKey;
     208             :       unsigned UniqueID;
     209             : 
     210             :       COFFSectionKey(StringRef SectionName, StringRef GroupName,
     211             :                      int SelectionKey, unsigned UniqueID)
     212       42385 :           : SectionName(SectionName), GroupName(GroupName),
     213       42385 :             SelectionKey(SelectionKey), UniqueID(UniqueID) {}
     214             : 
     215      282049 :       bool operator<(const COFFSectionKey &Other) const {
     216      564098 :         if (SectionName != Other.SectionName)
     217      279399 :           return SectionName < Other.SectionName;
     218             :         if (GroupName != Other.GroupName)
     219        1680 :           return GroupName < Other.GroupName;
     220         970 :         if (SelectionKey != Other.SelectionKey)
     221          19 :           return SelectionKey < Other.SelectionKey;
     222         951 :         return UniqueID < Other.UniqueID;
     223             :       }
     224             :     };
     225             : 
     226           0 :     struct WasmSectionKey {
     227             :       std::string SectionName;
     228             :       StringRef GroupName;
     229             :       unsigned UniqueID;
     230             : 
     231             :       WasmSectionKey(StringRef SectionName, StringRef GroupName,
     232             :                      unsigned UniqueID)
     233           0 :           : SectionName(SectionName), GroupName(GroupName), UniqueID(UniqueID) {
     234             :       }
     235             : 
     236           0 :       bool operator<(const WasmSectionKey &Other) const {
     237           0 :         if (SectionName != Other.SectionName)
     238           0 :           return SectionName < Other.SectionName;
     239             :         if (GroupName != Other.GroupName)
     240           0 :           return GroupName < Other.GroupName;
     241           0 :         return UniqueID < Other.UniqueID;
     242             :       }
     243             :     };
     244             : 
     245             :     StringMap<MCSectionMachO *> MachOUniquingMap;
     246             :     std::map<ELFSectionKey, MCSectionELF *> ELFUniquingMap;
     247             :     std::map<COFFSectionKey, MCSectionCOFF *> COFFUniquingMap;
     248             :     std::map<WasmSectionKey, MCSectionWasm *> WasmUniquingMap;
     249             :     StringMap<bool> RelSecNames;
     250             : 
     251             :     SpecificBumpPtrAllocator<MCSubtargetInfo> MCSubtargetAllocator;
     252             : 
     253             :     /// Do automatic reset in destructor
     254             :     bool AutoReset;
     255             : 
     256             :     bool HadError = false;
     257             : 
     258             :     MCSymbol *createSymbolImpl(const StringMapEntry<bool> *Name,
     259             :                                bool CanBeUnnamed);
     260             :     MCSymbol *createSymbol(StringRef Name, bool AlwaysAddSuffix,
     261             :                            bool IsTemporary);
     262             : 
     263             :     MCSymbol *getOrCreateDirectionalLocalSymbol(unsigned LocalLabelVal,
     264             :                                                 unsigned Instance);
     265             : 
     266             :     MCSectionELF *createELFSectionImpl(StringRef Section, unsigned Type,
     267             :                                        unsigned Flags, SectionKind K,
     268             :                                        unsigned EntrySize,
     269             :                                        const MCSymbolELF *Group,
     270             :                                        unsigned UniqueID,
     271             :                                        const MCSymbolELF *Associated);
     272             : 
     273             :     /// \brief Map of currently defined macros.
     274             :     StringMap<MCAsmMacro> MacroMap;
     275             : 
     276             :   public:
     277             :     explicit MCContext(const MCAsmInfo *MAI, const MCRegisterInfo *MRI,
     278             :                        const MCObjectFileInfo *MOFI,
     279             :                        const SourceMgr *Mgr = nullptr, bool DoAutoReset = true);
     280             :     MCContext(const MCContext &) = delete;
     281             :     MCContext &operator=(const MCContext &) = delete;
     282             :     ~MCContext();
     283             : 
     284             :     const SourceMgr *getSourceManager() const { return SrcMgr; }
     285             : 
     286         575 :     void setInlineSourceManager(SourceMgr *SM) { InlineSrcMgr = SM; }
     287             : 
     288             :     const MCAsmInfo *getAsmInfo() const { return MAI; }
     289             : 
     290             :     const MCRegisterInfo *getRegisterInfo() const { return MRI; }
     291             : 
     292             :     const MCObjectFileInfo *getObjectFileInfo() const { return MOFI; }
     293             : 
     294             :     CodeViewContext &getCVContext();
     295             : 
     296           4 :     void setAllowTemporaryLabels(bool Value) { AllowTemporaryLabels = Value; }
     297        4530 :     void setUseNamesOnTempLabels(bool Value) { UseNamesOnTempLabels = Value; }
     298             : 
     299             :     /// \name Module Lifetime Management
     300             :     /// @{
     301             : 
     302             :     /// reset - return object to right after construction state to prepare
     303             :     /// to process a new module
     304             :     void reset();
     305             : 
     306             :     /// @}
     307             : 
     308             :     /// \name Symbol Management
     309             :     /// @{
     310             : 
     311             :     /// Create and return a new linker temporary symbol with a unique but
     312             :     /// unspecified name.
     313             :     MCSymbol *createLinkerPrivateTempSymbol();
     314             : 
     315             :     /// Create and return a new assembler temporary symbol with a unique but
     316             :     /// unspecified name.
     317             :     MCSymbol *createTempSymbol(bool CanBeUnnamed = true);
     318             : 
     319             :     MCSymbol *createTempSymbol(const Twine &Name, bool AlwaysAddSuffix,
     320             :                                bool CanBeUnnamed = true);
     321             : 
     322             :     /// Create the definition of a directional local symbol for numbered label
     323             :     /// (used for "1:" definitions).
     324             :     MCSymbol *createDirectionalLocalSymbol(unsigned LocalLabelVal);
     325             : 
     326             :     /// Create and return a directional local symbol for numbered label (used
     327             :     /// for "1b" or 1f" references).
     328             :     MCSymbol *getDirectionalLocalSymbol(unsigned LocalLabelVal, bool Before);
     329             : 
     330             :     /// Lookup the symbol inside with the specified \p Name.  If it exists,
     331             :     /// return it.  If not, create a forward reference and return it.
     332             :     ///
     333             :     /// \param Name - The symbol name, which must be unique across all symbols.
     334             :     MCSymbol *getOrCreateSymbol(const Twine &Name);
     335             : 
     336             :     /// Gets a symbol that will be defined to the final stack offset of a local
     337             :     /// variable after codegen.
     338             :     ///
     339             :     /// \param Idx - The index of a local variable passed to @llvm.localescape.
     340             :     MCSymbol *getOrCreateFrameAllocSymbol(StringRef FuncName, unsigned Idx);
     341             : 
     342             :     MCSymbol *getOrCreateParentFrameOffsetSymbol(StringRef FuncName);
     343             : 
     344             :     MCSymbol *getOrCreateLSDASymbol(StringRef FuncName);
     345             : 
     346             :     /// Get the symbol for \p Name, or null.
     347             :     MCSymbol *lookupSymbol(const Twine &Name) const;
     348             : 
     349             :     /// Set value for a symbol.
     350             :     void setSymbolValue(MCStreamer &Streamer, StringRef Sym, uint64_t Val);
     351             : 
     352             :     /// getSymbols - Get a reference for the symbol table for clients that
     353             :     /// want to, for example, iterate over all symbols. 'const' because we
     354             :     /// still want any modifications to the table itself to use the MCContext
     355             :     /// APIs.
     356             :     const SymbolTable &getSymbols() const { return Symbols; }
     357             : 
     358             :     /// @}
     359             : 
     360             :     /// \name Section Management
     361             :     /// @{
     362             : 
     363             :     enum : unsigned {
     364             :       /// Pass this value as the UniqueID during section creation to get the
     365             :       /// generic section with the given name and characteristics. The usual
     366             :       /// sections such as .text use this ID.
     367             :       GenericSectionID = ~0U
     368             :     };
     369             : 
     370             :     /// Return the MCSection for the specified mach-o section.  This requires
     371             :     /// the operands to be valid.
     372             :     MCSectionMachO *getMachOSection(StringRef Segment, StringRef Section,
     373             :                                     unsigned TypeAndAttributes,
     374             :                                     unsigned Reserved2, SectionKind K,
     375             :                                     const char *BeginSymName = nullptr);
     376             : 
     377             :     MCSectionMachO *getMachOSection(StringRef Segment, StringRef Section,
     378             :                                     unsigned TypeAndAttributes, SectionKind K,
     379             :                                     const char *BeginSymName = nullptr) {
     380             :       return getMachOSection(Segment, Section, TypeAndAttributes, 0, K,
     381      156585 :                              BeginSymName);
     382             :     }
     383             : 
     384             :     MCSectionELF *getELFSection(const Twine &Section, unsigned Type,
     385             :                                 unsigned Flags) {
     386      899411 :       return getELFSection(Section, Type, Flags, 0, "");
     387             :     }
     388             : 
     389             :     MCSectionELF *getELFSection(const Twine &Section, unsigned Type,
     390             :                                 unsigned Flags, unsigned EntrySize,
     391             :                                 const Twine &Group) {
     392             :       return getELFSection(Section, Type, Flags, EntrySize, Group, ~0);
     393             :     }
     394             : 
     395             :     MCSectionELF *getELFSection(const Twine &Section, unsigned Type,
     396             :                                 unsigned Flags, unsigned EntrySize,
     397             :                                 const Twine &Group, unsigned UniqueID) {
     398             :       return getELFSection(Section, Type, Flags, EntrySize, Group, UniqueID,
     399     1053167 :                            nullptr);
     400             :     }
     401             : 
     402             :     MCSectionELF *getELFSection(const Twine &Section, unsigned Type,
     403             :                                 unsigned Flags, unsigned EntrySize,
     404             :                                 const Twine &Group, unsigned UniqueID,
     405             :                                 const MCSymbolELF *Associated);
     406             : 
     407             :     MCSectionELF *getELFSection(const Twine &Section, unsigned Type,
     408             :                                 unsigned Flags, unsigned EntrySize,
     409             :                                 const MCSymbolELF *Group, unsigned UniqueID,
     410             :                                 const MCSymbolELF *Associated);
     411             : 
     412             :     /// Get a section with the provided group identifier. This section is
     413             :     /// named by concatenating \p Prefix with '.' then \p Suffix. The \p Type
     414             :     /// describes the type of the section and \p Flags are used to further
     415             :     /// configure this named section.
     416             :     MCSectionELF *getELFNamedSection(const Twine &Prefix, const Twine &Suffix,
     417             :                                      unsigned Type, unsigned Flags,
     418             :                                      unsigned EntrySize = 0);
     419             : 
     420             :     MCSectionELF *createELFRelSection(const Twine &Name, unsigned Type,
     421             :                                       unsigned Flags, unsigned EntrySize,
     422             :                                       const MCSymbolELF *Group,
     423             :                                       const MCSectionELF *RelInfoSection);
     424             : 
     425             :     void renameELFSection(MCSectionELF *Section, StringRef Name);
     426             : 
     427             :     MCSectionELF *createELFGroupSection(const MCSymbolELF *Group);
     428             : 
     429             :     MCSectionCOFF *getCOFFSection(StringRef Section, unsigned Characteristics,
     430             :                                   SectionKind Kind, StringRef COMDATSymName,
     431             :                                   int Selection,
     432             :                                   unsigned UniqueID = GenericSectionID,
     433             :                                   const char *BeginSymName = nullptr);
     434             : 
     435             :     MCSectionCOFF *getCOFFSection(StringRef Section, unsigned Characteristics,
     436             :                                   SectionKind Kind,
     437             :                                   const char *BeginSymName = nullptr);
     438             : 
     439             :     MCSectionCOFF *getCOFFSection(StringRef Section);
     440             : 
     441             :     /// Gets or creates a section equivalent to Sec that is associated with the
     442             :     /// section containing KeySym. For example, to create a debug info section
     443             :     /// associated with an inline function, pass the normal debug info section
     444             :     /// as Sec and the function symbol as KeySym.
     445             :     MCSectionCOFF *
     446             :     getAssociativeCOFFSection(MCSectionCOFF *Sec, const MCSymbol *KeySym,
     447             :                               unsigned UniqueID = GenericSectionID);
     448             : 
     449             :     MCSectionWasm *getWasmSection(const Twine &Section, SectionKind K) {
     450             :       return getWasmSection(Section, K, nullptr);
     451             :     }
     452             : 
     453             :     MCSectionWasm *getWasmSection(const Twine &Section, SectionKind K,
     454             :                                   const char *BeginSymName) {
     455           0 :       return getWasmSection(Section, K, "", ~0, BeginSymName);
     456             :     }
     457             : 
     458             :     MCSectionWasm *getWasmSection(const Twine &Section, SectionKind K,
     459             :                                   const Twine &Group, unsigned UniqueID) {
     460           0 :       return getWasmSection(Section, K, Group, UniqueID, nullptr);
     461             :     }
     462             : 
     463             :     MCSectionWasm *getWasmSection(const Twine &Section, SectionKind K,
     464             :                                   const Twine &Group, unsigned UniqueID,
     465             :                                   const char *BeginSymName);
     466             : 
     467             :     MCSectionWasm *getWasmSection(const Twine &Section, SectionKind K,
     468             :                                   const MCSymbolWasm *Group, unsigned UniqueID,
     469             :                                   const char *BeginSymName);
     470             : 
     471             :     // Create and save a copy of STI and return a reference to the copy.
     472             :     MCSubtargetInfo &getSubtargetCopy(const MCSubtargetInfo &STI);
     473             : 
     474             :     /// @}
     475             : 
     476             :     /// \name Dwarf Management
     477             :     /// @{
     478             : 
     479             :     /// \brief Get the compilation directory for DW_AT_comp_dir
     480             :     /// The compilation directory should be set with \c setCompilationDir before
     481             :     /// calling this function. If it is unset, an empty string will be returned.
     482             :     StringRef getCompilationDir() const { return CompilationDir; }
     483             : 
     484             :     /// \brief Set the compilation directory for DW_AT_comp_dir
     485       11004 :     void setCompilationDir(StringRef S) { CompilationDir = S.str(); }
     486             : 
     487             :     /// \brief Get the main file name for use in error messages and debug
     488             :     /// info. This can be set to ensure we've got the correct file name
     489             :     /// after preprocessing or for -save-temps.
     490             :     const std::string &getMainFileName() const { return MainFileName; }
     491             : 
     492             :     /// \brief Set the main file name and override the default.
     493           6 :     void setMainFileName(StringRef S) { MainFileName = S; }
     494             : 
     495             :     /// Creates an entry in the dwarf file and directory tables.
     496             :     unsigned getDwarfFile(StringRef Directory, StringRef FileName,
     497             :                           unsigned FileNumber, MD5::MD5Result *Checksum,
     498             :                           unsigned CUID);
     499             : 
     500             :     bool isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID = 0);
     501             : 
     502             :     const std::map<unsigned, MCDwarfLineTable> &getMCDwarfLineTables() const {
     503             :       return MCDwarfLineTablesCUMap;
     504             :     }
     505             : 
     506             :     MCDwarfLineTable &getMCDwarfLineTable(unsigned CUID) {
     507      440397 :       return MCDwarfLineTablesCUMap[CUID];
     508             :     }
     509             : 
     510             :     const MCDwarfLineTable &getMCDwarfLineTable(unsigned CUID) const {
     511             :       auto I = MCDwarfLineTablesCUMap.find(CUID);
     512             :       assert(I != MCDwarfLineTablesCUMap.end());
     513             :       return I->second;
     514             :     }
     515             : 
     516             :     const SmallVectorImpl<MCDwarfFile> &getMCDwarfFiles(unsigned CUID = 0) {
     517             :       return getMCDwarfLineTable(CUID).getMCDwarfFiles();
     518             :     }
     519             : 
     520             :     const SmallVectorImpl<std::string> &getMCDwarfDirs(unsigned CUID = 0) {
     521             :       return getMCDwarfLineTable(CUID).getMCDwarfDirs();
     522             :     }
     523             : 
     524             :     bool hasMCLineSections() const {
     525             :       for (const auto &Table : MCDwarfLineTablesCUMap)
     526             :         if (!Table.second.getMCDwarfFiles().empty() || Table.second.getLabel())
     527             :           return true;
     528             :       return false;
     529             :     }
     530             : 
     531             :     unsigned getDwarfCompileUnitID() { return DwarfCompileUnitID; }
     532             : 
     533             :     void setDwarfCompileUnitID(unsigned CUIndex) {
     534       12826 :       DwarfCompileUnitID = CUIndex;
     535             :     }
     536             : 
     537             :     void setMCLineTableCompilationDir(unsigned CUID, StringRef CompilationDir) {
     538             :       getMCDwarfLineTable(CUID).setCompilationDir(CompilationDir);
     539             :     }
     540             : 
     541             :     /// Saves the information from the currently parsed dwarf .loc directive
     542             :     /// and sets DwarfLocSeen.  When the next instruction is assembled an entry
     543             :     /// in the line number table with this information and the address of the
     544             :     /// instruction will be created.
     545             :     void setCurrentDwarfLoc(unsigned FileNum, unsigned Line, unsigned Column,
     546             :                             unsigned Flags, unsigned Isa,
     547             :                             unsigned Discriminator) {
     548             :       CurrentDwarfLoc.setFileNum(FileNum);
     549             :       CurrentDwarfLoc.setLine(Line);
     550             :       CurrentDwarfLoc.setColumn(Column);
     551             :       CurrentDwarfLoc.setFlags(Flags);
     552             :       CurrentDwarfLoc.setIsa(Isa);
     553             :       CurrentDwarfLoc.setDiscriminator(Discriminator);
     554      437136 :       DwarfLocSeen = true;
     555             :     }
     556             : 
     557      839591 :     void clearDwarfLocSeen() { DwarfLocSeen = false; }
     558             : 
     559             :     bool getDwarfLocSeen() { return DwarfLocSeen; }
     560             :     const MCDwarfLoc &getCurrentDwarfLoc() { return CurrentDwarfLoc; }
     561             : 
     562             :     bool getGenDwarfForAssembly() { return GenDwarfForAssembly; }
     563        5505 :     void setGenDwarfForAssembly(bool Value) { GenDwarfForAssembly = Value; }
     564             :     unsigned getGenDwarfFileNumber() { return GenDwarfFileNumber; }
     565             : 
     566             :     void setGenDwarfFileNumber(unsigned FileNumber) {
     567          40 :       GenDwarfFileNumber = FileNumber;
     568             :     }
     569             : 
     570             :     const SetVector<MCSection *> &getGenDwarfSectionSyms() {
     571             :       return SectionsForRanges;
     572             :     }
     573             : 
     574             :     bool addGenDwarfSection(MCSection *Sec) {
     575          41 :       return SectionsForRanges.insert(Sec);
     576             :     }
     577             : 
     578             :     void finalizeDwarfSections(MCStreamer &MCOS);
     579             : 
     580             :     const std::vector<MCGenDwarfLabelEntry> &getMCGenDwarfLabelEntries() const {
     581             :       return MCGenDwarfLabelEntries;
     582             :     }
     583             : 
     584             :     void addMCGenDwarfLabelEntry(const MCGenDwarfLabelEntry &E) {
     585          39 :       MCGenDwarfLabelEntries.push_back(E);
     586             :     }
     587             : 
     588           0 :     void setDwarfDebugFlags(StringRef S) { DwarfDebugFlags = S; }
     589             :     StringRef getDwarfDebugFlags() { return DwarfDebugFlags; }
     590             : 
     591           2 :     void setDwarfDebugProducer(StringRef S) { DwarfDebugProducer = S; }
     592             :     StringRef getDwarfDebugProducer() { return DwarfDebugProducer; }
     593             : 
     594             :     dwarf::DwarfFormat getDwarfFormat() const {
     595             :       // TODO: Support DWARF64
     596             :       return dwarf::DWARF32;
     597             :     }
     598             : 
     599       24144 :     void setDwarfVersion(uint16_t v) { DwarfVersion = v; }
     600             :     uint16_t getDwarfVersion() const { return DwarfVersion; }
     601             : 
     602             :     /// @}
     603             : 
     604             :     char *getSecureLogFile() { return SecureLogFile; }
     605             :     raw_fd_ostream *getSecureLog() { return SecureLog.get(); }
     606             : 
     607             :     void setSecureLog(std::unique_ptr<raw_fd_ostream> Value) {
     608             :       SecureLog = std::move(Value);
     609             :     }
     610             : 
     611             :     bool getSecureLogUsed() { return SecureLogUsed; }
     612           2 :     void setSecureLogUsed(bool Value) { SecureLogUsed = Value; }
     613             : 
     614             :     void *allocate(unsigned Size, unsigned Align = 8) {
     615    10557475 :       return Allocator.Allocate(Size, Align);
     616             :     }
     617             : 
     618             :     void deallocate(void *Ptr) {}
     619             : 
     620             :     bool hadError() { return HadError; }
     621             :     void reportError(SMLoc L, const Twine &Msg);
     622             :     // Unrecoverable error has occurred. Display the best diagnostic we can
     623             :     // and bail via exit(1). For now, most MC backend errors are unrecoverable.
     624             :     // FIXME: We should really do something about that.
     625             :     LLVM_ATTRIBUTE_NORETURN void reportFatalError(SMLoc L,
     626             :                                                   const Twine &Msg);
     627             : 
     628             :     const MCAsmMacro *lookupMacro(StringRef Name) {
     629     1067413 :       StringMap<MCAsmMacro>::iterator I = MacroMap.find(Name);
     630     2134826 :       return (I == MacroMap.end()) ? nullptr : &I->getValue();
     631             :     }
     632             : 
     633         207 :     void defineMacro(StringRef Name, MCAsmMacro Macro) {
     634         414 :       MacroMap.insert(std::make_pair(Name, std::move(Macro)));
     635         207 :     }
     636             : 
     637           4 :     void undefineMacro(StringRef Name) { MacroMap.erase(Name); }
     638             :   };
     639             : 
     640             : } // end namespace llvm
     641             : 
     642             : // operator new and delete aren't allowed inside namespaces.
     643             : // The throw specifications are mandated by the standard.
     644             : /// \brief Placement new for using the MCContext's allocator.
     645             : ///
     646             : /// This placement form of operator new uses the MCContext's allocator for
     647             : /// obtaining memory. It is a non-throwing new, which means that it returns
     648             : /// null on error. (If that is what the allocator does. The current does, so if
     649             : /// this ever changes, this operator will have to be changed, too.)
     650             : /// Usage looks like this (assuming there's an MCContext 'Context' in scope):
     651             : /// \code
     652             : /// // Default alignment (8)
     653             : /// IntegerLiteral *Ex = new (Context) IntegerLiteral(arguments);
     654             : /// // Specific alignment
     655             : /// IntegerLiteral *Ex2 = new (Context, 4) IntegerLiteral(arguments);
     656             : /// \endcode
     657             : /// Please note that you cannot use delete on the pointer; it must be
     658             : /// deallocated using an explicit destructor call followed by
     659             : /// \c Context.Deallocate(Ptr).
     660             : ///
     661             : /// \param Bytes The number of bytes to allocate. Calculated by the compiler.
     662             : /// \param C The MCContext that provides the allocator.
     663             : /// \param Alignment The alignment of the allocated memory (if the underlying
     664             : ///                  allocator supports it).
     665             : /// \return The allocated memory. Could be NULL.
     666             : inline void *operator new(size_t Bytes, llvm::MCContext &C,
     667             :                           size_t Alignment = 8) noexcept {
     668             :   return C.allocate(Bytes, Alignment);
     669             : }
     670             : /// \brief Placement delete companion to the new above.
     671             : ///
     672             : /// This operator is just a companion to the new above. There is no way of
     673             : /// invoking it directly; see the new operator for more details. This operator
     674             : /// is called implicitly by the compiler if a placement new expression using
     675             : /// the MCContext throws in the object constructor.
     676             : inline void operator delete(void *Ptr, llvm::MCContext &C, size_t) noexcept {
     677             :   C.deallocate(Ptr);
     678             : }
     679             : 
     680             : /// This placement form of operator new[] uses the MCContext's allocator for
     681             : /// obtaining memory. It is a non-throwing new[], which means that it returns
     682             : /// null on error.
     683             : /// Usage looks like this (assuming there's an MCContext 'Context' in scope):
     684             : /// \code
     685             : /// // Default alignment (8)
     686             : /// char *data = new (Context) char[10];
     687             : /// // Specific alignment
     688             : /// char *data = new (Context, 4) char[10];
     689             : /// \endcode
     690             : /// Please note that you cannot use delete on the pointer; it must be
     691             : /// deallocated using an explicit destructor call followed by
     692             : /// \c Context.Deallocate(Ptr).
     693             : ///
     694             : /// \param Bytes The number of bytes to allocate. Calculated by the compiler.
     695             : /// \param C The MCContext that provides the allocator.
     696             : /// \param Alignment The alignment of the allocated memory (if the underlying
     697             : ///                  allocator supports it).
     698             : /// \return The allocated memory. Could be NULL.
     699             : inline void *operator new[](size_t Bytes, llvm::MCContext &C,
     700             :                             size_t Alignment = 8) noexcept {
     701             :   return C.allocate(Bytes, Alignment);
     702             : }
     703             : 
     704             : /// \brief Placement delete[] companion to the new[] above.
     705             : ///
     706             : /// This operator is just a companion to the new[] above. There is no way of
     707             : /// invoking it directly; see the new[] operator for more details. This operator
     708             : /// is called implicitly by the compiler if a placement new[] expression using
     709             : /// the MCContext throws in the object constructor.
     710             : inline void operator delete[](void *Ptr, llvm::MCContext &C) noexcept {
     711             :   C.deallocate(Ptr);
     712             : }
     713             : 
     714             : #endif // LLVM_MC_MCCONTEXT_H

Generated by: LCOV version 1.13