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

Generated by: LCOV version 1.13