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