1 //===- MCContext.h - Machine Code Context -----------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_MC_MCCONTEXT_H
11 #define LLVM_MC_MCCONTEXT_H
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"
20 #include "llvm/MC/MCDwarf.h"
21 #include "llvm/MC/MCSubtargetInfo.h"
22 #include "llvm/MC/SectionKind.h"
23 #include "llvm/Support/Allocator.h"
24 #include "llvm/Support/Compiler.h"
25 #include "llvm/Support/Dwarf.h"
26 #include "llvm/Support/raw_ostream.h"
39 class CodeViewContext;
42 class MCObjectFileInfo;
54 /// Context object for machine code objects. This class owns all of the
55 /// sections that it creates.
59 typedef StringMap<MCSymbol *, BumpPtrAllocator &> SymbolTable;
62 /// The SourceMgr for this object, if any.
63 const SourceMgr *SrcMgr;
65 /// The SourceMgr for inline assembly, if any.
66 SourceMgr *InlineSrcMgr;
68 /// The MCAsmInfo for this target.
71 /// The MCRegisterInfo for this target.
72 const MCRegisterInfo *MRI;
74 /// The MCObjectFileInfo for this target.
75 const MCObjectFileInfo *MOFI;
77 std::unique_ptr<CodeViewContext> CVContext;
79 /// Allocator object used for creating machine code objects.
81 /// We use a bump pointer allocator to avoid the need to track all allocated
83 BumpPtrAllocator Allocator;
85 SpecificBumpPtrAllocator<MCSectionCOFF> COFFAllocator;
86 SpecificBumpPtrAllocator<MCSectionELF> ELFAllocator;
87 SpecificBumpPtrAllocator<MCSectionMachO> MachOAllocator;
88 SpecificBumpPtrAllocator<MCSectionWasm> WasmAllocator;
90 /// Bindings of names to symbols.
93 /// A mapping from a local label number and an instance count to a symbol.
94 /// For example, in the assembly
98 /// We have three labels represented by the pairs (1, 0), (2, 0) and (1, 1)
99 DenseMap<std::pair<unsigned, unsigned>, MCSymbol *> LocalSymbols;
101 /// Keeps tracks of names that were used both for used declared and
102 /// artificial symbols. The value is "true" if the name has been used for a
103 /// non-section symbol (there can be at most one of those, plus an unlimited
104 /// number of section symbols with the same name).
105 StringMap<bool, BumpPtrAllocator &> UsedNames;
107 /// The next ID to dole out to an unnamed assembler temporary symbol with
109 StringMap<unsigned> NextID;
111 /// Instances of directional local labels.
112 DenseMap<unsigned, MCLabel *> Instances;
113 /// NextInstance() creates the next instance of the directional local label
114 /// for the LocalLabelVal and adds it to the map if needed.
115 unsigned NextInstance(unsigned LocalLabelVal);
116 /// GetInstance() gets the current instance of the directional local label
117 /// for the LocalLabelVal and adds it to the map if needed.
118 unsigned GetInstance(unsigned LocalLabelVal);
120 /// The file name of the log file from the environment variable
121 /// AS_SECURE_LOG_FILE. Which must be set before the .secure_log_unique
122 /// directive is used or it is an error.
124 /// The stream that gets written to for the .secure_log_unique directive.
125 std::unique_ptr<raw_fd_ostream> SecureLog;
126 /// Boolean toggled when .secure_log_unique / .secure_log_reset is seen to
127 /// catch errors if .secure_log_unique appears twice without
128 /// .secure_log_reset appearing between them.
129 bool SecureLogUsed = false;
131 /// The compilation directory to use for DW_AT_comp_dir.
132 SmallString<128> CompilationDir;
134 /// The main file name if passed in explicitly.
135 std::string MainFileName;
137 /// The dwarf file and directory tables from the dwarf .file directive.
138 /// We now emit a line table for each compile unit. To reduce the prologue
139 /// size of each line table, the files and directories used by each compile
140 /// unit are separated.
141 std::map<unsigned, MCDwarfLineTable> MCDwarfLineTablesCUMap;
143 /// The current dwarf line information from the last dwarf .loc directive.
144 MCDwarfLoc CurrentDwarfLoc;
145 bool DwarfLocSeen = false;
147 /// Generate dwarf debugging info for assembly source files.
148 bool GenDwarfForAssembly = false;
150 /// The current dwarf file number when generate dwarf debugging info for
151 /// assembly source files.
152 unsigned GenDwarfFileNumber = 0;
154 /// Sections for generating the .debug_ranges and .debug_aranges sections.
155 SetVector<MCSection *> SectionsForRanges;
157 /// The information gathered from labels that will have dwarf label
158 /// entries when generating dwarf assembly source files.
159 std::vector<MCGenDwarfLabelEntry> MCGenDwarfLabelEntries;
161 /// The string to embed in the debug information for the compile unit, if
163 StringRef DwarfDebugFlags;
165 /// The string to embed in as the dwarf AT_producer for the compile unit, if
167 StringRef DwarfDebugProducer;
169 /// The maximum version of dwarf that we should emit.
170 uint16_t DwarfVersion = 4;
172 /// Honor temporary labels, this is useful for debugging semantic
173 /// differences between temporary and non-temporary labels (primarily on
175 bool AllowTemporaryLabels = true;
176 bool UseNamesOnTempLabels = true;
178 /// The Compile Unit ID that we are currently processing.
179 unsigned DwarfCompileUnitID = 0;
181 struct ELFSectionKey {
182 std::string SectionName;
186 ELFSectionKey(StringRef SectionName, StringRef GroupName,
188 : SectionName(SectionName), GroupName(GroupName), UniqueID(UniqueID) {
191 bool operator<(const ELFSectionKey &Other) const {
192 if (SectionName != Other.SectionName)
193 return SectionName < Other.SectionName;
194 if (GroupName != Other.GroupName)
195 return GroupName < Other.GroupName;
196 return UniqueID < Other.UniqueID;
200 struct COFFSectionKey {
201 std::string SectionName;
206 COFFSectionKey(StringRef SectionName, StringRef GroupName,
207 int SelectionKey, unsigned UniqueID)
208 : SectionName(SectionName), GroupName(GroupName),
209 SelectionKey(SelectionKey), UniqueID(UniqueID) {}
211 bool operator<(const COFFSectionKey &Other) const {
212 if (SectionName != Other.SectionName)
213 return SectionName < Other.SectionName;
214 if (GroupName != Other.GroupName)
215 return GroupName < Other.GroupName;
216 if (SelectionKey != Other.SelectionKey)
217 return SelectionKey < Other.SelectionKey;
218 return UniqueID < Other.UniqueID;
222 struct WasmSectionKey {
223 std::string SectionName;
226 WasmSectionKey(StringRef SectionName, StringRef GroupName,
228 : SectionName(SectionName), GroupName(GroupName), UniqueID(UniqueID) {
230 bool operator<(const WasmSectionKey &Other) const {
231 if (SectionName != Other.SectionName)
232 return SectionName < Other.SectionName;
233 if (GroupName != Other.GroupName)
234 return GroupName < Other.GroupName;
235 return UniqueID < Other.UniqueID;
239 StringMap<MCSectionMachO *> MachOUniquingMap;
240 std::map<ELFSectionKey, MCSectionELF *> ELFUniquingMap;
241 std::map<COFFSectionKey, MCSectionCOFF *> COFFUniquingMap;
242 std::map<WasmSectionKey, MCSectionWasm *> WasmUniquingMap;
243 StringMap<bool> RelSecNames;
245 SpecificBumpPtrAllocator<MCSubtargetInfo> MCSubtargetAllocator;
247 /// Do automatic reset in destructor
250 bool HadError = false;
252 MCSymbol *createSymbolImpl(const StringMapEntry<bool> *Name,
254 MCSymbol *createSymbol(StringRef Name, bool AlwaysAddSuffix,
257 MCSymbol *getOrCreateDirectionalLocalSymbol(unsigned LocalLabelVal,
260 MCSectionELF *createELFSectionImpl(StringRef Section, unsigned Type,
261 unsigned Flags, SectionKind K,
263 const MCSymbolELF *Group,
265 const MCSymbolELF *Associated);
268 explicit MCContext(const MCAsmInfo *MAI, const MCRegisterInfo *MRI,
269 const MCObjectFileInfo *MOFI,
270 const SourceMgr *Mgr = nullptr, bool DoAutoReset = true);
271 MCContext(const MCContext &) = delete;
272 MCContext &operator=(const MCContext &) = delete;
275 const SourceMgr *getSourceManager() const { return SrcMgr; }
277 void setInlineSourceManager(SourceMgr *SM) { InlineSrcMgr = SM; }
279 const MCAsmInfo *getAsmInfo() const { return MAI; }
281 const MCRegisterInfo *getRegisterInfo() const { return MRI; }
283 const MCObjectFileInfo *getObjectFileInfo() const { return MOFI; }
285 CodeViewContext &getCVContext();
287 void setAllowTemporaryLabels(bool Value) { AllowTemporaryLabels = Value; }
288 void setUseNamesOnTempLabels(bool Value) { UseNamesOnTempLabels = Value; }
290 /// \name Module Lifetime Management
293 /// reset - return object to right after construction state to prepare
294 /// to process a new module
299 /// \name Symbol Management
302 /// Create and return a new linker temporary symbol with a unique but
303 /// unspecified name.
304 MCSymbol *createLinkerPrivateTempSymbol();
306 /// Create and return a new assembler temporary symbol with a unique but
307 /// unspecified name.
308 MCSymbol *createTempSymbol(bool CanBeUnnamed = true);
310 MCSymbol *createTempSymbol(const Twine &Name, bool AlwaysAddSuffix,
311 bool CanBeUnnamed = true);
313 /// Create the definition of a directional local symbol for numbered label
314 /// (used for "1:" definitions).
315 MCSymbol *createDirectionalLocalSymbol(unsigned LocalLabelVal);
317 /// Create and return a directional local symbol for numbered label (used
318 /// for "1b" or 1f" references).
319 MCSymbol *getDirectionalLocalSymbol(unsigned LocalLabelVal, bool Before);
321 /// Lookup the symbol inside with the specified \p Name. If it exists,
322 /// return it. If not, create a forward reference and return it.
324 /// \param Name - The symbol name, which must be unique across all symbols.
325 MCSymbol *getOrCreateSymbol(const Twine &Name);
327 /// Gets a symbol that will be defined to the final stack offset of a local
328 /// variable after codegen.
330 /// \param Idx - The index of a local variable passed to @llvm.localescape.
331 MCSymbol *getOrCreateFrameAllocSymbol(StringRef FuncName, unsigned Idx);
333 MCSymbol *getOrCreateParentFrameOffsetSymbol(StringRef FuncName);
335 MCSymbol *getOrCreateLSDASymbol(StringRef FuncName);
337 /// Get the symbol for \p Name, or null.
338 MCSymbol *lookupSymbol(const Twine &Name) const;
340 /// Set value for a symbol.
341 void setSymbolValue(MCStreamer &Streamer, StringRef Sym, uint64_t Val);
343 /// getSymbols - Get a reference for the symbol table for clients that
344 /// want to, for example, iterate over all symbols. 'const' because we
345 /// still want any modifications to the table itself to use the MCContext
347 const SymbolTable &getSymbols() const { return Symbols; }
351 /// \name Section Management
355 /// Pass this value as the UniqueID during section creation to get the
356 /// generic section with the given name and characteristics. The usual
357 /// sections such as .text use this ID.
358 GenericSectionID = ~0U
361 /// Return the MCSection for the specified mach-o section. This requires
362 /// the operands to be valid.
363 MCSectionMachO *getMachOSection(StringRef Segment, StringRef Section,
364 unsigned TypeAndAttributes,
365 unsigned Reserved2, SectionKind K,
366 const char *BeginSymName = nullptr);
368 MCSectionMachO *getMachOSection(StringRef Segment, StringRef Section,
369 unsigned TypeAndAttributes, SectionKind K,
370 const char *BeginSymName = nullptr) {
371 return getMachOSection(Segment, Section, TypeAndAttributes, 0, K,
375 MCSectionELF *getELFSection(const Twine &Section, unsigned Type,
377 return getELFSection(Section, Type, Flags, 0, "");
380 MCSectionELF *getELFSection(const Twine &Section, unsigned Type,
381 unsigned Flags, unsigned EntrySize,
382 const Twine &Group) {
383 return getELFSection(Section, Type, Flags, EntrySize, Group, ~0);
386 MCSectionELF *getELFSection(const Twine &Section, unsigned Type,
387 unsigned Flags, unsigned EntrySize,
388 const Twine &Group, unsigned UniqueID) {
389 return getELFSection(Section, Type, Flags, EntrySize, Group, UniqueID,
393 MCSectionELF *getELFSection(const Twine &Section, unsigned Type,
394 unsigned Flags, unsigned EntrySize,
395 const Twine &Group, unsigned UniqueID,
396 const MCSymbolELF *Associated);
398 MCSectionELF *getELFSection(const Twine &Section, unsigned Type,
399 unsigned Flags, unsigned EntrySize,
400 const MCSymbolELF *Group, unsigned UniqueID,
401 const MCSymbolELF *Associated);
403 /// Get a section with the provided group identifier. This section is
404 /// named by concatenating \p Prefix with '.' then \p Suffix. The \p Type
405 /// describes the type of the section and \p Flags are used to further
406 /// configure this named section.
407 MCSectionELF *getELFNamedSection(const Twine &Prefix, const Twine &Suffix,
408 unsigned Type, unsigned Flags,
409 unsigned EntrySize = 0);
411 MCSectionELF *createELFRelSection(const Twine &Name, unsigned Type,
412 unsigned Flags, unsigned EntrySize,
413 const MCSymbolELF *Group,
414 const MCSectionELF *RelInfoSection);
416 void renameELFSection(MCSectionELF *Section, StringRef Name);
418 MCSectionELF *createELFGroupSection(const MCSymbolELF *Group);
420 MCSectionCOFF *getCOFFSection(StringRef Section, unsigned Characteristics,
421 SectionKind Kind, StringRef COMDATSymName,
423 unsigned UniqueID = GenericSectionID,
424 const char *BeginSymName = nullptr);
426 MCSectionCOFF *getCOFFSection(StringRef Section, unsigned Characteristics,
428 const char *BeginSymName = nullptr);
430 MCSectionCOFF *getCOFFSection(StringRef Section);
432 /// Gets or creates a section equivalent to Sec that is associated with the
433 /// section containing KeySym. For example, to create a debug info section
434 /// associated with an inline function, pass the normal debug info section
435 /// as Sec and the function symbol as KeySym.
437 getAssociativeCOFFSection(MCSectionCOFF *Sec, const MCSymbol *KeySym,
438 unsigned UniqueID = GenericSectionID);
440 MCSectionWasm *getWasmSection(const Twine &Section, unsigned Type,
442 return getWasmSection(Section, Type, Flags, nullptr);
445 MCSectionWasm *getWasmSection(const Twine &Section, unsigned Type,
446 unsigned Flags, const char *BeginSymName) {
447 return getWasmSection(Section, Type, Flags, "", BeginSymName);
450 MCSectionWasm *getWasmSection(const Twine &Section, unsigned Type,
451 unsigned Flags, const Twine &Group) {
452 return getWasmSection(Section, Type, Flags, Group, nullptr);
455 MCSectionWasm *getWasmSection(const Twine &Section, unsigned Type,
456 unsigned Flags, const Twine &Group,
457 const char *BeginSymName) {
458 return getWasmSection(Section, Type, Flags, Group, ~0, BeginSymName);
461 MCSectionWasm *getWasmSection(const Twine &Section, unsigned Type,
462 unsigned Flags, const Twine &Group,
464 return getWasmSection(Section, Type, Flags, Group, UniqueID, nullptr);
467 MCSectionWasm *getWasmSection(const Twine &Section, unsigned Type,
468 unsigned Flags, const Twine &Group,
469 unsigned UniqueID, const char *BeginSymName);
471 MCSectionWasm *getWasmSection(const Twine &Section, unsigned Type,
472 unsigned Flags, const MCSymbolWasm *Group,
473 unsigned UniqueID, const char *BeginSymName);
475 /// Get a section with the provided group identifier. This section is
476 /// named by concatenating \p Prefix with '.' then \p Suffix. The \p Type
477 /// describes the type of the section and \p Flags are used to further
478 /// configure this named section.
479 MCSectionWasm *getWasmNamedSection(const Twine &Prefix, const Twine &Suffix,
480 unsigned Type, unsigned Flags);
482 MCSectionWasm *createWasmRelSection(const Twine &Name, unsigned Type,
484 const MCSymbolWasm *Group);
486 void renameWasmSection(MCSectionWasm *Section, StringRef Name);
488 // Create and save a copy of STI and return a reference to the copy.
489 MCSubtargetInfo &getSubtargetCopy(const MCSubtargetInfo &STI);
493 /// \name Dwarf Management
496 /// \brief Get the compilation directory for DW_AT_comp_dir
497 /// The compilation directory should be set with \c setCompilationDir before
498 /// calling this function. If it is unset, an empty string will be returned.
499 StringRef getCompilationDir() const { return CompilationDir; }
501 /// \brief Set the compilation directory for DW_AT_comp_dir
502 void setCompilationDir(StringRef S) { CompilationDir = S.str(); }
504 /// \brief 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; }
509 /// \brief Set the main file name and override the default.
510 void setMainFileName(StringRef S) { MainFileName = S; }
512 /// Creates an entry in the dwarf file and directory tables.
513 unsigned getDwarfFile(StringRef Directory, StringRef FileName,
514 unsigned FileNumber, unsigned CUID);
516 bool isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID = 0);
518 const std::map<unsigned, MCDwarfLineTable> &getMCDwarfLineTables() const {
519 return MCDwarfLineTablesCUMap;
522 MCDwarfLineTable &getMCDwarfLineTable(unsigned CUID) {
523 return MCDwarfLineTablesCUMap[CUID];
526 const MCDwarfLineTable &getMCDwarfLineTable(unsigned CUID) const {
527 auto I = MCDwarfLineTablesCUMap.find(CUID);
528 assert(I != MCDwarfLineTablesCUMap.end());
532 const SmallVectorImpl<MCDwarfFile> &getMCDwarfFiles(unsigned CUID = 0) {
533 return getMCDwarfLineTable(CUID).getMCDwarfFiles();
536 const SmallVectorImpl<std::string> &getMCDwarfDirs(unsigned CUID = 0) {
537 return getMCDwarfLineTable(CUID).getMCDwarfDirs();
540 bool hasMCLineSections() const {
541 for (const auto &Table : MCDwarfLineTablesCUMap)
542 if (!Table.second.getMCDwarfFiles().empty() || Table.second.getLabel())
547 unsigned getDwarfCompileUnitID() { return DwarfCompileUnitID; }
549 void setDwarfCompileUnitID(unsigned CUIndex) {
550 DwarfCompileUnitID = CUIndex;
553 void setMCLineTableCompilationDir(unsigned CUID, StringRef CompilationDir) {
554 getMCDwarfLineTable(CUID).setCompilationDir(CompilationDir);
557 /// Saves the information from the currently parsed dwarf .loc directive
558 /// and sets DwarfLocSeen. When the next instruction is assembled an entry
559 /// in the line number table with this information and the address of the
560 /// instruction will be created.
561 void setCurrentDwarfLoc(unsigned FileNum, unsigned Line, unsigned Column,
562 unsigned Flags, unsigned Isa,
563 unsigned Discriminator) {
564 CurrentDwarfLoc.setFileNum(FileNum);
565 CurrentDwarfLoc.setLine(Line);
566 CurrentDwarfLoc.setColumn(Column);
567 CurrentDwarfLoc.setFlags(Flags);
568 CurrentDwarfLoc.setIsa(Isa);
569 CurrentDwarfLoc.setDiscriminator(Discriminator);
573 void clearDwarfLocSeen() { DwarfLocSeen = false; }
575 bool getDwarfLocSeen() { return DwarfLocSeen; }
576 const MCDwarfLoc &getCurrentDwarfLoc() { return CurrentDwarfLoc; }
578 bool getGenDwarfForAssembly() { return GenDwarfForAssembly; }
579 void setGenDwarfForAssembly(bool Value) { GenDwarfForAssembly = Value; }
580 unsigned getGenDwarfFileNumber() { return GenDwarfFileNumber; }
582 void setGenDwarfFileNumber(unsigned FileNumber) {
583 GenDwarfFileNumber = FileNumber;
586 const SetVector<MCSection *> &getGenDwarfSectionSyms() {
587 return SectionsForRanges;
590 bool addGenDwarfSection(MCSection *Sec) {
591 return SectionsForRanges.insert(Sec);
594 void finalizeDwarfSections(MCStreamer &MCOS);
596 const std::vector<MCGenDwarfLabelEntry> &getMCGenDwarfLabelEntries() const {
597 return MCGenDwarfLabelEntries;
600 void addMCGenDwarfLabelEntry(const MCGenDwarfLabelEntry &E) {
601 MCGenDwarfLabelEntries.push_back(E);
604 void setDwarfDebugFlags(StringRef S) { DwarfDebugFlags = S; }
605 StringRef getDwarfDebugFlags() { return DwarfDebugFlags; }
607 void setDwarfDebugProducer(StringRef S) { DwarfDebugProducer = S; }
608 StringRef getDwarfDebugProducer() { return DwarfDebugProducer; }
610 dwarf::DwarfFormat getDwarfFormat() const {
611 // TODO: Support DWARF64
612 return dwarf::DWARF32;
615 void setDwarfVersion(uint16_t v) { DwarfVersion = v; }
616 uint16_t getDwarfVersion() const { return DwarfVersion; }
620 char *getSecureLogFile() { return SecureLogFile; }
621 raw_fd_ostream *getSecureLog() { return SecureLog.get(); }
623 void setSecureLog(std::unique_ptr<raw_fd_ostream> Value) {
624 SecureLog = std::move(Value);
627 bool getSecureLogUsed() { return SecureLogUsed; }
628 void setSecureLogUsed(bool Value) { SecureLogUsed = Value; }
630 void *allocate(unsigned Size, unsigned Align = 8) {
631 return Allocator.Allocate(Size, Align);
634 void deallocate(void *Ptr) {}
636 bool hadError() { return HadError; }
637 void reportError(SMLoc L, const Twine &Msg);
638 // Unrecoverable error has occurred. Display the best diagnostic we can
639 // and bail via exit(1). For now, most MC backend errors are unrecoverable.
640 // FIXME: We should really do something about that.
641 LLVM_ATTRIBUTE_NORETURN void reportFatalError(SMLoc L,
645 } // end namespace llvm
647 // operator new and delete aren't allowed inside namespaces.
648 // The throw specifications are mandated by the standard.
649 /// \brief Placement new for using the MCContext's allocator.
651 /// This placement form of operator new uses the MCContext's allocator for
652 /// obtaining memory. It is a non-throwing new, which means that it returns
653 /// null on error. (If that is what the allocator does. The current does, so if
654 /// this ever changes, this operator will have to be changed, too.)
655 /// Usage looks like this (assuming there's an MCContext 'Context' in scope):
657 /// // Default alignment (8)
658 /// IntegerLiteral *Ex = new (Context) IntegerLiteral(arguments);
659 /// // Specific alignment
660 /// IntegerLiteral *Ex2 = new (Context, 4) IntegerLiteral(arguments);
662 /// Please note that you cannot use delete on the pointer; it must be
663 /// deallocated using an explicit destructor call followed by
664 /// \c Context.Deallocate(Ptr).
666 /// \param Bytes The number of bytes to allocate. Calculated by the compiler.
667 /// \param C The MCContext that provides the allocator.
668 /// \param Alignment The alignment of the allocated memory (if the underlying
669 /// allocator supports it).
670 /// \return The allocated memory. Could be NULL.
671 inline void *operator new(size_t Bytes, llvm::MCContext &C,
672 size_t Alignment = 8) noexcept {
673 return C.allocate(Bytes, Alignment);
675 /// \brief Placement delete companion to the new above.
677 /// This operator is just a companion to the new above. There is no way of
678 /// invoking it directly; see the new operator for more details. This operator
679 /// is called implicitly by the compiler if a placement new expression using
680 /// the MCContext throws in the object constructor.
681 inline void operator delete(void *Ptr, llvm::MCContext &C, size_t) noexcept {
685 /// This placement form of operator new[] uses the MCContext's allocator for
686 /// obtaining memory. It is a non-throwing new[], which means that it returns
688 /// Usage looks like this (assuming there's an MCContext 'Context' in scope):
690 /// // Default alignment (8)
691 /// char *data = new (Context) char[10];
692 /// // Specific alignment
693 /// char *data = new (Context, 4) char[10];
695 /// Please note that you cannot use delete on the pointer; it must be
696 /// deallocated using an explicit destructor call followed by
697 /// \c Context.Deallocate(Ptr).
699 /// \param Bytes The number of bytes to allocate. Calculated by the compiler.
700 /// \param C The MCContext that provides the allocator.
701 /// \param Alignment The alignment of the allocated memory (if the underlying
702 /// allocator supports it).
703 /// \return The allocated memory. Could be NULL.
704 inline void *operator new[](size_t Bytes, llvm::MCContext &C,
705 size_t Alignment = 8) noexcept {
706 return C.allocate(Bytes, Alignment);
709 /// \brief Placement delete[] companion to the new[] above.
711 /// This operator is just a companion to the new[] above. There is no way of
712 /// invoking it directly; see the new[] operator for more details. This operator
713 /// is called implicitly by the compiler if a placement new[] expression using
714 /// the MCContext throws in the object constructor.
715 inline void operator delete[](void *Ptr, llvm::MCContext &C) noexcept {
719 #endif // LLVM_MC_MCCONTEXT_H