Coverage Report

Created: 2019-07-24 05:18

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