LLVM  8.0.1
MCContext.h
Go to the documentation of this file.
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"
22 #include "llvm/MC/MCAsmMacro.h"
23 #include "llvm/MC/MCDwarf.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"
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:
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 
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)
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).
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.
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  struct ELFSectionKey {
191  std::string SectionName;
192  StringRef GroupName;
193  unsigned UniqueID;
194 
195  ELFSectionKey(StringRef SectionName, StringRef GroupName,
196  unsigned UniqueID)
197  : SectionName(SectionName), GroupName(GroupName), UniqueID(UniqueID) {
198  }
199 
200  bool operator<(const ELFSectionKey &Other) const {
201  if (SectionName != Other.SectionName)
202  return SectionName < Other.SectionName;
203  if (GroupName != Other.GroupName)
204  return GroupName < Other.GroupName;
205  return UniqueID < Other.UniqueID;
206  }
207  };
208 
209  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  : SectionName(SectionName), GroupName(GroupName),
218  SelectionKey(SelectionKey), UniqueID(UniqueID) {}
219 
220  bool operator<(const COFFSectionKey &Other) const {
221  if (SectionName != Other.SectionName)
222  return SectionName < Other.SectionName;
223  if (GroupName != Other.GroupName)
224  return GroupName < Other.GroupName;
225  if (SelectionKey != Other.SelectionKey)
226  return SelectionKey < Other.SelectionKey;
227  return UniqueID < Other.UniqueID;
228  }
229  };
230 
231  struct WasmSectionKey {
232  std::string SectionName;
233  StringRef GroupName;
234  unsigned UniqueID;
235 
236  WasmSectionKey(StringRef SectionName, StringRef GroupName,
237  unsigned UniqueID)
238  : SectionName(SectionName), GroupName(GroupName), UniqueID(UniqueID) {
239  }
240 
241  bool operator<(const WasmSectionKey &Other) const {
242  if (SectionName != Other.SectionName)
243  return SectionName < Other.SectionName;
244  if (GroupName != Other.GroupName)
245  return GroupName < Other.GroupName;
246  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  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 
300 
301  void setAllowTemporaryLabels(bool Value) { AllowTemporaryLabels = Value; }
302  void setUseNamesOnTempLabels(bool Value) { UseNamesOnTempLabels = Value; }
303 
304  /// \name Module Lifetime Management
305  /// @{
306 
307  /// reset - return object to right after construction state to prepare
308  /// to process a new module
309  void reset();
310 
311  /// @}
312 
313  /// \name Symbol Management
314  /// @{
315 
316  /// Create and return a new linker temporary symbol with a unique but
317  /// unspecified name.
319 
320  /// Create and return a new assembler temporary symbol with a unique but
321  /// unspecified name.
322  MCSymbol *createTempSymbol(bool CanBeUnnamed = true);
323 
324  MCSymbol *createTempSymbol(const Twine &Name, bool AlwaysAddSuffix,
325  bool CanBeUnnamed = true);
326 
327  /// Create the definition of a directional local symbol for numbered label
328  /// (used for "1:" definitions).
329  MCSymbol *createDirectionalLocalSymbol(unsigned LocalLabelVal);
330 
331  /// Create and return a directional local symbol for numbered label (used
332  /// for "1b" or 1f" references).
333  MCSymbol *getDirectionalLocalSymbol(unsigned LocalLabelVal, bool Before);
334 
335  /// Lookup the symbol inside with the specified \p Name. If it exists,
336  /// return it. If not, create a forward reference and return it.
337  ///
338  /// \param Name - The symbol name, which must be unique across all symbols.
339  MCSymbol *getOrCreateSymbol(const Twine &Name);
340 
341  /// Gets a symbol that will be defined to the final stack offset of a local
342  /// variable after codegen.
343  ///
344  /// \param Idx - The index of a local variable passed to \@llvm.localescape.
345  MCSymbol *getOrCreateFrameAllocSymbol(StringRef FuncName, unsigned Idx);
346 
348 
350 
351  /// Get the symbol for \p Name, or null.
352  MCSymbol *lookupSymbol(const Twine &Name) const;
353 
354  /// Set value for a symbol.
355  void setSymbolValue(MCStreamer &Streamer, StringRef Sym, uint64_t Val);
356 
357  /// getSymbols - Get a reference for the symbol table for clients that
358  /// want to, for example, iterate over all symbols. 'const' because we
359  /// still want any modifications to the table itself to use the MCContext
360  /// APIs.
361  const SymbolTable &getSymbols() const { return Symbols; }
362 
363  /// @}
364 
365  /// \name Section Management
366  /// @{
367 
368  enum : unsigned {
369  /// Pass this value as the UniqueID during section creation to get the
370  /// generic section with the given name and characteristics. The usual
371  /// sections such as .text use this ID.
373  };
374 
375  /// Return the MCSection for the specified mach-o section. This requires
376  /// the operands to be valid.
378  unsigned TypeAndAttributes,
379  unsigned Reserved2, SectionKind K,
380  const char *BeginSymName = nullptr);
381 
383  unsigned TypeAndAttributes, SectionKind K,
384  const char *BeginSymName = nullptr) {
385  return getMachOSection(Segment, Section, TypeAndAttributes, 0, K,
386  BeginSymName);
387  }
388 
390  unsigned Flags) {
391  return getELFSection(Section, Type, Flags, 0, "");
392  }
393 
395  unsigned Flags, unsigned EntrySize,
396  const Twine &Group) {
397  return getELFSection(Section, Type, Flags, EntrySize, Group, ~0);
398  }
399 
401  unsigned Flags, unsigned EntrySize,
402  const Twine &Group, unsigned UniqueID) {
403  return getELFSection(Section, Type, Flags, EntrySize, Group, UniqueID,
404  nullptr);
405  }
406 
407  MCSectionELF *getELFSection(const Twine &Section, unsigned Type,
408  unsigned Flags, unsigned EntrySize,
409  const Twine &Group, unsigned UniqueID,
410  const MCSymbolELF *Associated);
411 
412  MCSectionELF *getELFSection(const Twine &Section, unsigned Type,
413  unsigned Flags, unsigned EntrySize,
414  const MCSymbolELF *Group, unsigned UniqueID,
415  const MCSymbolELF *Associated);
416 
417  /// Get a section with the provided group identifier. This section is
418  /// named by concatenating \p Prefix with '.' then \p Suffix. The \p Type
419  /// describes the type of the section and \p Flags are used to further
420  /// configure this named section.
421  MCSectionELF *getELFNamedSection(const Twine &Prefix, const Twine &Suffix,
422  unsigned Type, unsigned Flags,
423  unsigned EntrySize = 0);
424 
425  MCSectionELF *createELFRelSection(const Twine &Name, unsigned Type,
426  unsigned Flags, unsigned EntrySize,
427  const MCSymbolELF *Group,
428  const MCSectionELF *RelInfoSection);
429 
430  void renameELFSection(MCSectionELF *Section, StringRef Name);
431 
433 
435  SectionKind Kind, StringRef COMDATSymName,
436  int Selection,
437  unsigned UniqueID = GenericSectionID,
438  const char *BeginSymName = nullptr);
439 
440  MCSectionCOFF *getCOFFSection(StringRef Section, unsigned Characteristics,
441  SectionKind Kind,
442  const char *BeginSymName = nullptr);
443 
445 
446  /// Gets or creates a section equivalent to Sec that is associated with the
447  /// section containing KeySym. For example, to create a debug info section
448  /// associated with an inline function, pass the normal debug info section
449  /// as Sec and the function symbol as KeySym.
450  MCSectionCOFF *
452  unsigned UniqueID = GenericSectionID);
453 
455  return getWasmSection(Section, K, nullptr);
456  }
457 
459  const char *BeginSymName) {
460  return getWasmSection(Section, K, "", ~0, BeginSymName);
461  }
462 
464  const Twine &Group, unsigned UniqueID) {
465  return getWasmSection(Section, K, Group, UniqueID, nullptr);
466  }
467 
468  MCSectionWasm *getWasmSection(const Twine &Section, SectionKind K,
469  const Twine &Group, unsigned UniqueID,
470  const char *BeginSymName);
471 
472  MCSectionWasm *getWasmSection(const Twine &Section, SectionKind K,
473  const MCSymbolWasm *Group, unsigned UniqueID,
474  const char *BeginSymName);
475 
476  // Create and save a copy of STI and return a reference to the copy.
478 
479  /// @}
480 
481  /// \name Dwarf Management
482  /// @{
483 
484  /// Get the compilation directory for DW_AT_comp_dir
485  /// The compilation directory should be set with \c setCompilationDir before
486  /// calling this function. If it is unset, an empty string will be returned.
487  StringRef getCompilationDir() const { return CompilationDir; }
488 
489  /// Set the compilation directory for DW_AT_comp_dir
490  void setCompilationDir(StringRef S) { CompilationDir = S.str(); }
491 
492  /// Get the debug prefix map.
493  const std::map<const std::string, const std::string> &
495  return DebugPrefixMap;
496  }
497 
498  /// Add an entry to the debug prefix map.
499  void addDebugPrefixMapEntry(const std::string &From, const std::string &To);
500 
501  // Remaps all debug directory paths in-place as per the debug prefix map.
502  void RemapDebugPaths();
503 
504  /// Get the main file name for use in error messages and debug
505  /// info. This can be set to ensure we've got the correct file name
506  /// after preprocessing or for -save-temps.
507  const std::string &getMainFileName() const { return MainFileName; }
508 
509  /// Set the main file name and override the default.
510  void setMainFileName(StringRef S) { MainFileName = S; }
511 
512  /// Creates an entry in the dwarf file and directory tables.
514  unsigned FileNumber,
515  MD5::MD5Result *Checksum,
516  Optional<StringRef> Source, unsigned CUID);
517 
518  bool isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID = 0);
519 
520  const std::map<unsigned, MCDwarfLineTable> &getMCDwarfLineTables() const {
521  return MCDwarfLineTablesCUMap;
522  }
523 
525  return MCDwarfLineTablesCUMap[CUID];
526  }
527 
528  const MCDwarfLineTable &getMCDwarfLineTable(unsigned CUID) const {
529  auto I = MCDwarfLineTablesCUMap.find(CUID);
530  assert(I != MCDwarfLineTablesCUMap.end());
531  return I->second;
532  }
533 
534  const SmallVectorImpl<MCDwarfFile> &getMCDwarfFiles(unsigned CUID = 0) {
535  return getMCDwarfLineTable(CUID).getMCDwarfFiles();
536  }
537 
538  const SmallVectorImpl<std::string> &getMCDwarfDirs(unsigned CUID = 0) {
539  return getMCDwarfLineTable(CUID).getMCDwarfDirs();
540  }
541 
542  bool hasMCLineSections() const {
543  for (const auto &Table : MCDwarfLineTablesCUMap)
544  if (!Table.second.getMCDwarfFiles().empty() || Table.second.getLabel())
545  return true;
546  return false;
547  }
548 
549  unsigned getDwarfCompileUnitID() { return DwarfCompileUnitID; }
550 
551  void setDwarfCompileUnitID(unsigned CUIndex) {
552  DwarfCompileUnitID = CUIndex;
553  }
554 
555  /// Specifies the "root" file and directory of the compilation unit.
556  /// These are "file 0" and "directory 0" in DWARF v5.
557  void setMCLineTableRootFile(unsigned CUID, StringRef CompilationDir,
558  StringRef Filename, MD5::MD5Result *Checksum,
559  Optional<StringRef> Source) {
560  getMCDwarfLineTable(CUID).setRootFile(CompilationDir, Filename, Checksum,
561  Source);
562  }
563 
564  /// Reports whether MD5 checksum usage is consistent (all-or-none).
565  bool isDwarfMD5UsageConsistent(unsigned CUID) const {
567  }
568 
569  /// Saves the information from the currently parsed dwarf .loc directive
570  /// and sets DwarfLocSeen. When the next instruction is assembled an entry
571  /// in the line number table with this information and the address of the
572  /// instruction will be created.
573  void setCurrentDwarfLoc(unsigned FileNum, unsigned Line, unsigned Column,
574  unsigned Flags, unsigned Isa,
575  unsigned Discriminator) {
576  CurrentDwarfLoc.setFileNum(FileNum);
577  CurrentDwarfLoc.setLine(Line);
578  CurrentDwarfLoc.setColumn(Column);
579  CurrentDwarfLoc.setFlags(Flags);
580  CurrentDwarfLoc.setIsa(Isa);
581  CurrentDwarfLoc.setDiscriminator(Discriminator);
582  DwarfLocSeen = true;
583  }
584 
585  void clearDwarfLocSeen() { DwarfLocSeen = false; }
586 
587  bool getDwarfLocSeen() { return DwarfLocSeen; }
588  const MCDwarfLoc &getCurrentDwarfLoc() { return CurrentDwarfLoc; }
589 
590  bool getGenDwarfForAssembly() { return GenDwarfForAssembly; }
591  void setGenDwarfForAssembly(bool Value) { GenDwarfForAssembly = Value; }
592  unsigned getGenDwarfFileNumber() { return GenDwarfFileNumber; }
593 
594  void setGenDwarfFileNumber(unsigned FileNumber) {
595  GenDwarfFileNumber = FileNumber;
596  }
597 
599  return SectionsForRanges;
600  }
601 
603  return SectionsForRanges.insert(Sec);
604  }
605 
606  void finalizeDwarfSections(MCStreamer &MCOS);
607 
608  const std::vector<MCGenDwarfLabelEntry> &getMCGenDwarfLabelEntries() const {
609  return MCGenDwarfLabelEntries;
610  }
611 
613  MCGenDwarfLabelEntries.push_back(E);
614  }
615 
616  void setDwarfDebugFlags(StringRef S) { DwarfDebugFlags = S; }
617  StringRef getDwarfDebugFlags() { return DwarfDebugFlags; }
618 
619  void setDwarfDebugProducer(StringRef S) { DwarfDebugProducer = S; }
620  StringRef getDwarfDebugProducer() { return DwarfDebugProducer; }
621 
623  // TODO: Support DWARF64
624  return dwarf::DWARF32;
625  }
626 
627  void setDwarfVersion(uint16_t v) { DwarfVersion = v; }
628  uint16_t getDwarfVersion() const { return DwarfVersion; }
629 
630  /// @}
631 
632  char *getSecureLogFile() { return SecureLogFile; }
633  raw_fd_ostream *getSecureLog() { return SecureLog.get(); }
634 
635  void setSecureLog(std::unique_ptr<raw_fd_ostream> Value) {
636  SecureLog = std::move(Value);
637  }
638 
639  bool getSecureLogUsed() { return SecureLogUsed; }
640  void setSecureLogUsed(bool Value) { SecureLogUsed = Value; }
641 
642  void *allocate(unsigned Size, unsigned Align = 8) {
643  return Allocator.Allocate(Size, Align);
644  }
645 
646  void deallocate(void *Ptr) {}
647 
648  bool hadError() { return HadError; }
649  void reportError(SMLoc L, const Twine &Msg);
650  // Unrecoverable error has occurred. Display the best diagnostic we can
651  // and bail via exit(1). For now, most MC backend errors are unrecoverable.
652  // FIXME: We should really do something about that.
654  const Twine &Msg);
655 
657  StringMap<MCAsmMacro>::iterator I = MacroMap.find(Name);
658  return (I == MacroMap.end()) ? nullptr : &I->getValue();
659  }
660 
662  MacroMap.insert(std::make_pair(Name, std::move(Macro)));
663  }
664 
665  void undefineMacro(StringRef Name) { MacroMap.erase(Name); }
666  };
667 
668 } // end namespace llvm
669 
670 // operator new and delete aren't allowed inside namespaces.
671 // The throw specifications are mandated by the standard.
672 /// Placement new for using the MCContext's allocator.
673 ///
674 /// This placement form of operator new uses the MCContext's allocator for
675 /// obtaining memory. It is a non-throwing new, which means that it returns
676 /// null on error. (If that is what the allocator does. The current does, so if
677 /// this ever changes, this operator will have to be changed, too.)
678 /// Usage looks like this (assuming there's an MCContext 'Context' in scope):
679 /// \code
680 /// // Default alignment (8)
681 /// IntegerLiteral *Ex = new (Context) IntegerLiteral(arguments);
682 /// // Specific alignment
683 /// IntegerLiteral *Ex2 = new (Context, 4) IntegerLiteral(arguments);
684 /// \endcode
685 /// Please note that you cannot use delete on the pointer; it must be
686 /// deallocated using an explicit destructor call followed by
687 /// \c Context.Deallocate(Ptr).
688 ///
689 /// \param Bytes The number of bytes to allocate. Calculated by the compiler.
690 /// \param C The MCContext that provides the allocator.
691 /// \param Alignment The alignment of the allocated memory (if the underlying
692 /// allocator supports it).
693 /// \return The allocated memory. Could be NULL.
694 inline void *operator new(size_t Bytes, llvm::MCContext &C,
695  size_t Alignment = 8) noexcept {
696  return C.allocate(Bytes, Alignment);
697 }
698 /// Placement delete companion to the new above.
699 ///
700 /// This operator is just a companion to the new above. There is no way of
701 /// invoking it directly; see the new operator for more details. This operator
702 /// is called implicitly by the compiler if a placement new expression using
703 /// the MCContext throws in the object constructor.
704 inline void operator delete(void *Ptr, llvm::MCContext &C, size_t) noexcept {
705  C.deallocate(Ptr);
706 }
707 
708 /// This placement form of operator new[] uses the MCContext's allocator for
709 /// obtaining memory. It is a non-throwing new[], which means that it returns
710 /// null on error.
711 /// Usage looks like this (assuming there's an MCContext 'Context' in scope):
712 /// \code
713 /// // Default alignment (8)
714 /// char *data = new (Context) char[10];
715 /// // Specific alignment
716 /// char *data = new (Context, 4) char[10];
717 /// \endcode
718 /// Please note that you cannot use delete on the pointer; it must be
719 /// deallocated using an explicit destructor call followed by
720 /// \c Context.Deallocate(Ptr).
721 ///
722 /// \param Bytes The number of bytes to allocate. Calculated by the compiler.
723 /// \param C The MCContext that provides the allocator.
724 /// \param Alignment The alignment of the allocated memory (if the underlying
725 /// allocator supports it).
726 /// \return The allocated memory. Could be NULL.
727 inline void *operator new[](size_t Bytes, llvm::MCContext &C,
728  size_t Alignment = 8) noexcept {
729  return C.allocate(Bytes, Alignment);
730 }
731 
732 /// Placement delete[] companion to the new[] above.
733 ///
734 /// This operator is just a companion to the new[] above. There is no way of
735 /// invoking it directly; see the new[] operator for more details. This operator
736 /// is called implicitly by the compiler if a placement new[] expression using
737 /// the MCContext throws in the object constructor.
738 inline void operator delete[](void *Ptr, llvm::MCContext &C) noexcept {
739  C.deallocate(Ptr);
740 }
741 
742 #endif // LLVM_MC_MCCONTEXT_H
const MCAsmInfo * getAsmInfo() const
Definition: MCContext.h:293
uint64_t CallInst * C
void addMCGenDwarfLabelEntry(const MCGenDwarfLabelEntry &E)
Definition: MCContext.h:612
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:39
MCSymbol * getDirectionalLocalSymbol(unsigned LocalLabelVal, bool Before)
Create and return a directional local symbol for numbered label (used for "1b" or 1f" references)...
Definition: MCContext.cpp:248
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
void setGenDwarfForAssembly(bool Value)
Definition: MCContext.h:591
This represents a section on a Mach-O system (used by Mac OS X).
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:228
MCSymbol * lookupSymbol(const Twine &Name) const
Get the symbol for Name, or null.
Definition: MCContext.cpp:256
This class represents lattice values for constants.
Definition: AllocatorList.h:24
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
Definition: StringMap.h:126
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
const SmallVectorImpl< MCDwarfFile > & getMCDwarfFiles(unsigned CUID=0)
Definition: MCContext.h:534
MCSymbol * getOrCreateFrameAllocSymbol(StringRef FuncName, unsigned Idx)
Gets a symbol that will be defined to the final stack offset of a local variable after codegen...
Definition: MCContext.cpp:136
void reset()
reset - return object to right after construction state to prepare to process a new module ...
Definition: MCContext.cpp:83
MCSectionWasm * getWasmSection(const Twine &Section, SectionKind K, const char *BeginSymName)
Definition: MCContext.h:458
const SmallVectorImpl< std::string > & getMCDwarfDirs() const
Definition: MCDwarf.h:335
MCSectionWasm * getWasmSection(const Twine &Section, SectionKind K, const Twine &Group, unsigned UniqueID)
Definition: MCContext.h:463
MCSectionWasm * getWasmSection(const Twine &Section, SectionKind K)
Definition: MCContext.h:454
MCSymbol * createDirectionalLocalSymbol(unsigned LocalLabelVal)
Create the definition of a directional local symbol for numbered label (used for "1:" definitions)...
Definition: MCContext.cpp:243
iterator find(StringRef Key)
Definition: StringMap.h:333
MCSymbol * getOrCreateParentFrameOffsetSymbol(StringRef FuncName)
Definition: MCContext.cpp:142
uint16_t getDwarfVersion() const
Definition: MCContext.h:628
void setDwarfVersion(uint16_t v)
Definition: MCContext.h:627
void setIsa(unsigned isa)
Set the Isa of this MCDwarfLoc.
Definition: MCDwarf.h:135
MCContext(const MCAsmInfo *MAI, const MCRegisterInfo *MRI, const MCObjectFileInfo *MOFI, const SourceMgr *Mgr=nullptr, bool DoAutoReset=true)
Definition: MCContext.cpp:57
StringRef getDwarfDebugFlags()
Definition: MCContext.h:617
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
MCSectionCOFF * getCOFFSection(StringRef Section, unsigned Characteristics, SectionKind Kind, StringRef COMDATSymName, int Selection, unsigned UniqueID=GenericSectionID, const char *BeginSymName=nullptr)
Definition: MCContext.cpp:422
MCSectionCOFF * getAssociativeCOFFSection(MCSectionCOFF *Sec, const MCSymbol *KeySym, unsigned UniqueID=GenericSectionID)
Gets or creates a section equivalent to Sec that is associated with the section containing KeySym...
Definition: MCContext.cpp:470
This represents a section on Windows.
Definition: MCSectionCOFF.h:27
const std::vector< MCGenDwarfLabelEntry > & getMCGenDwarfLabelEntries() const
Definition: MCContext.h:608
amdgpu Simplify well known AMD library false Value Value const Twine & Name
StringRef getDwarfDebugProducer()
Definition: MCContext.h:620
MCSymbol * createLinkerPrivateTempSymbol()
Create and return a new linker temporary symbol with a unique but unspecified name.
Definition: MCContext.cpp:211
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
DwarfFormat
Constants that define the DWARF format as 32 or 64 bit.
Definition: Dwarf.h:66
void renameELFSection(MCSectionELF *Section, StringRef Name)
Definition: MCContext.cpp:301
bool isMD5UsageConsistent() const
Definition: MCDwarf.h:325
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
void finalizeDwarfSections(MCStreamer &MCOS)
Remove empty sections from SectionsForRanges, to avoid generating useless debug info for them...
Definition: MCContext.cpp:597
void setUseNamesOnTempLabels(bool Value)
Definition: MCContext.h:302
Tagged union holding either a T or a Error.
Definition: CachePruning.h:23
void * allocate(unsigned Size, unsigned Align=8)
Definition: MCContext.h:642
MCDwarfLineTable & getMCDwarfLineTable(unsigned CUID)
Definition: MCContext.h:524
const SmallVectorImpl< std::string > & getMCDwarfDirs(unsigned CUID=0)
Definition: MCContext.h:538
Context object for machine code objects.
Definition: MCContext.h:63
void setCompilationDir(StringRef S)
Set the compilation directory for DW_AT_comp_dir.
Definition: MCContext.h:490
void setLine(unsigned line)
Set the Line of this MCDwarfLoc.
Definition: MCDwarf.h:120
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition: SetVector.h:142
void setDwarfCompileUnitID(unsigned CUIndex)
Definition: MCContext.h:551
MCSectionMachO * getMachOSection(StringRef Segment, StringRef Section, unsigned TypeAndAttributes, unsigned Reserved2, SectionKind K, const char *BeginSymName=nullptr)
Return the MCSection for the specified mach-o section.
Definition: MCContext.cpp:273
unsigned getDwarfCompileUnitID()
Definition: MCContext.h:549
const std::map< unsigned, MCDwarfLineTable > & getMCDwarfLineTables() const
Definition: MCContext.h:520
void RemapDebugPaths()
Definition: MCContext.cpp:543
Instances of this class represent the information from a dwarf .loc directive.
Definition: MCDwarf.h:68
unsigned getGenDwarfFileNumber()
Definition: MCContext.h:592
const SymbolTable & getSymbols() const
getSymbols - Get a reference for the symbol table for clients that want to, for example, iterate over all symbols.
Definition: MCContext.h:361
bool hadError()
Definition: MCContext.h:648
bool isDwarfMD5UsageConsistent(unsigned CUID) const
Reports whether MD5 checksum usage is consistent (all-or-none).
Definition: MCContext.h:565
LLVM_ATTRIBUTE_NORETURN void reportFatalError(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:626
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
bool hasMCLineSections() const
Definition: MCContext.h:542
const SmallVectorImpl< MCDwarfFile > & getMCDwarfFiles() const
Definition: MCDwarf.h:343
void setInlineSourceManager(SourceMgr *SM)
Definition: MCContext.h:291
Streaming machine code generation interface.
Definition: MCStreamer.h:189
MCSymbol * createTempSymbol(bool CanBeUnnamed=true)
Create and return a new assembler temporary symbol with a unique but unspecified name.
Definition: MCContext.cpp:217
void setAllowTemporaryLabels(bool Value)
Definition: MCContext.h:301
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:141
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This represents a section on wasm.
Definition: MCSectionWasm.h:28
void setDwarfDebugFlags(StringRef S)
Definition: MCContext.h:616
void undefineMacro(StringRef Name)
Definition: MCContext.h:665
LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ATTRIBUTE_RETURNS_NOALIAS void * Allocate(size_t Size, size_t Alignment)
Allocate space at the specified alignment.
Definition: Allocator.h:215
void erase(iterator I)
Definition: StringMap.h:436
const MCObjectFileInfo * getObjectFileInfo() const
Definition: MCContext.h:297
void reportError(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:612
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:23
MCSectionELF * getELFNamedSection(const Twine &Prefix, const Twine &Suffix, unsigned Type, unsigned Flags, unsigned EntrySize=0)
Get a section with the provided group identifier.
Definition: MCContext.cpp:366
const MCDwarfLoc & getCurrentDwarfLoc()
Definition: MCContext.h:588
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling...
Definition: SourceMgr.h:42
const SourceMgr * getSourceManager() const
Definition: MCContext.h:289
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags, unsigned EntrySize, const Twine &Group, unsigned UniqueID)
Definition: MCContext.h:400
bool getSecureLogUsed()
Definition: MCContext.h:639
MCSectionMachO * getMachOSection(StringRef Segment, StringRef Section, unsigned TypeAndAttributes, SectionKind K, const char *BeginSymName=nullptr)
Definition: MCContext.h:382
const MCAsmMacro * lookupMacro(StringRef Name)
Definition: MCContext.h:656
bool isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID=0)
isValidDwarfFileNumber - takes a dwarf file number and returns true if it currently is assigned and f...
Definition: MCContext.cpp:585
bool getGenDwarfForAssembly()
Definition: MCContext.h:590
void clearDwarfLocSeen()
Definition: MCContext.h:585
void setMainFileName(StringRef S)
Set the main file name and override the default.
Definition: MCContext.h:510
StringRef getCompilationDir() const
Get the compilation directory for DW_AT_comp_dir The compilation directory should be set with setComp...
Definition: MCContext.h:487
const SetVector< MCSection * > & getGenDwarfSectionSyms()
Definition: MCContext.h:598
MCSectionELF * createELFRelSection(const Twine &Name, unsigned Type, unsigned Flags, unsigned EntrySize, const MCSymbolELF *Group, const MCSectionELF *RelInfoSection)
Definition: MCContext.cpp:352
BlockVerifier::State From
MCSymbol * getOrCreateLSDASymbol(StringRef FuncName)
Definition: MCContext.cpp:147
void setDwarfDebugProducer(StringRef S)
Definition: MCContext.h:619
const MCDwarfLineTable & getMCDwarfLineTable(unsigned CUID) const
Definition: MCContext.h:528
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags, unsigned EntrySize, const Twine &Group)
Definition: MCContext.h:394
A BumpPtrAllocator that allows only elements of a specific type to be allocated.
Definition: Allocator.h:442
bool getDwarfLocSeen()
Definition: MCContext.h:587
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
Definition: StringMap.h:366
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
Definition: StringMap.h:220
This file contains constants used for implementing Dwarf debug support.
bool addGenDwarfSection(MCSection *Sec)
Definition: MCContext.h:602
amdgpu AMDGPU DAG DAG Pattern Instruction Selection
void setSymbolValue(MCStreamer &Streamer, StringRef Sym, uint64_t Val)
Set value for a symbol.
Definition: MCContext.cpp:262
#define LLVM_ATTRIBUTE_NORETURN
Definition: Compiler.h:222
const std::map< const std::string, const std::string > & getDebugPrefixMap() const
Get the debug prefix map.
Definition: MCContext.h:494
char * getSecureLogFile()
Definition: MCContext.h:632
A raw_ostream that writes to a file descriptor.
Definition: raw_ostream.h:366
void setGenDwarfFileNumber(unsigned FileNumber)
Definition: MCContext.h:594
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
Definition: MCContext.cpp:123
void deallocate(void *Ptr)
Definition: MCContext.h:646
void setRootFile(StringRef Directory, StringRef FileName, MD5::MD5Result *Checksum, Optional< StringRef > Source)
Definition: MCDwarf.h:304
void addDebugPrefixMapEntry(const std::string &From, const std::string &To)
Add an entry to the debug prefix map.
Definition: MCContext.cpp:538
#define I(x, y, z)
Definition: MD5.cpp:58
COFFYAML::WeakExternalCharacteristics Characteristics
Definition: COFFYAML.cpp:323
Generic base class for all target subtargets.
This represents a section on linux, lots of unix variants and some bare metal systems.
Definition: MCSectionELF.h:28
uint32_t Size
Definition: Profile.cpp:47
void setFileNum(unsigned fileNum)
Set the FileNum of this MCDwarfLoc.
Definition: MCDwarf.h:117
void setMCLineTableRootFile(unsigned CUID, StringRef CompilationDir, StringRef Filename, MD5::MD5Result *Checksum, Optional< StringRef > Source)
Specifies the "root" file and directory of the compilation unit.
Definition: MCContext.h:557
const std::string & getMainFileName() const
Get the main file name for use in error messages and debug info.
Definition: MCContext.h:507
void setFlags(unsigned flags)
Set the Flags of this MCDwarfLoc.
Definition: MCDwarf.h:129
MCSectionELF * createELFGroupSection(const MCSymbolELF *Group)
Definition: MCContext.cpp:416
void setCurrentDwarfLoc(unsigned FileNum, unsigned Line, unsigned Column, unsigned Flags, unsigned Isa, unsigned Discriminator)
Saves the information from the currently parsed dwarf .loc directive and sets DwarfLocSeen.
Definition: MCContext.h:573
CodeViewContext & getCVContext()
Definition: MCContext.cpp:602
const unsigned Kind
Expected< unsigned > getDwarfFile(StringRef Directory, StringRef FileName, unsigned FileNumber, MD5::MD5Result *Checksum, Optional< StringRef > Source, unsigned CUID)
Creates an entry in the dwarf file and directory tables.
Definition: MCContext.cpp:573
dwarf::DwarfFormat getDwarfFormat() const
Definition: MCContext.h:622
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool operator<(int64_t V1, const APSInt &V2)
Definition: APSInt.h:326
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Definition: MCContext.h:389
raw_fd_ostream * getSecureLog()
Definition: MCContext.h:633
const MCRegisterInfo * getRegisterInfo() const
Definition: MCContext.h:295
LLVM Value Representation.
Definition: Value.h:73
A vector that has set insertion semantics.
Definition: SetVector.h:41
const char SectionName[]
Definition: AMDGPUPTNote.h:24
void setColumn(unsigned column)
Set the Column of this MCDwarfLoc.
Definition: MCDwarf.h:123
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
MCContext & operator=(const MCContext &)=delete
Represents a location in source code.
Definition: SMLoc.h:24
void setSecureLog(std::unique_ptr< raw_fd_ostream > Value)
Definition: MCContext.h:635
void setDiscriminator(unsigned discriminator)
Set the Discriminator of this MCDwarfLoc.
Definition: MCDwarf.h:141
void setSecureLogUsed(bool Value)
Definition: MCContext.h:640
iterator end()
Definition: StringMap.h:318
void defineMacro(StringRef Name, MCAsmMacro Macro)
Definition: MCContext.h:661
Pass this value as the UniqueID during section creation to get the generic section with the given nam...
Definition: MCContext.h:372
MCSubtargetInfo & getSubtargetCopy(const MCSubtargetInfo &STI)
Definition: MCContext.cpp:534
Holds state from .cv_file and .cv_loc directives for later emission.
Definition: MCCodeView.h:138