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

Generated by: LCOV version 1.13