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