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/BinaryFormat/Dwarf.h"
21 #include "llvm/MC/MCAsmMacro.h"
22 #include "llvm/MC/MCDwarf.h"
23 #include "llvm/MC/MCSubtargetInfo.h"
24 #include "llvm/MC/SectionKind.h"
25 #include "llvm/Support/Allocator.h"
26 #include "llvm/Support/Compiler.h"
27 #include "llvm/Support/raw_ostream.h"
40 class CodeViewContext;
43 class MCObjectFileInfo;
57 /// Context object for machine code objects. This class owns all of the
58 /// sections that it creates.
62 using SymbolTable = StringMap<MCSymbol *, BumpPtrAllocator &>;
65 /// The SourceMgr for this object, if any.
66 const SourceMgr *SrcMgr;
68 /// The SourceMgr for inline assembly, if any.
69 SourceMgr *InlineSrcMgr;
71 /// The MCAsmInfo for this target.
74 /// The MCRegisterInfo for this target.
75 const MCRegisterInfo *MRI;
77 /// The MCObjectFileInfo for this target.
78 const MCObjectFileInfo *MOFI;
80 std::unique_ptr<CodeViewContext> CVContext;
82 /// Allocator object used for creating machine code objects.
84 /// We use a bump pointer allocator to avoid the need to track all allocated
86 BumpPtrAllocator Allocator;
88 SpecificBumpPtrAllocator<MCSectionCOFF> COFFAllocator;
89 SpecificBumpPtrAllocator<MCSectionELF> ELFAllocator;
90 SpecificBumpPtrAllocator<MCSectionMachO> MachOAllocator;
91 SpecificBumpPtrAllocator<MCSectionWasm> WasmAllocator;
93 /// Bindings of names to symbols.
96 /// A mapping from a local label number and an instance count to a symbol.
97 /// For example, in the assembly
101 /// We have three labels represented by the pairs (1, 0), (2, 0) and (1, 1)
102 DenseMap<std::pair<unsigned, unsigned>, MCSymbol *> LocalSymbols;
104 /// Keeps tracks of names that were used both for used declared and
105 /// artificial symbols. The value is "true" if the name has been used for a
106 /// non-section symbol (there can be at most one of those, plus an unlimited
107 /// number of section symbols with the same name).
108 StringMap<bool, BumpPtrAllocator &> UsedNames;
110 /// The next ID to dole out to an unnamed assembler temporary symbol with
112 StringMap<unsigned> NextID;
114 /// Instances of directional local labels.
115 DenseMap<unsigned, MCLabel *> Instances;
116 /// NextInstance() creates the next instance of the directional local label
117 /// for the LocalLabelVal and adds it to the map if needed.
118 unsigned NextInstance(unsigned LocalLabelVal);
119 /// GetInstance() gets the current instance of the directional local label
120 /// for the LocalLabelVal and adds it to the map if needed.
121 unsigned GetInstance(unsigned LocalLabelVal);
123 /// The file name of the log file from the environment variable
124 /// AS_SECURE_LOG_FILE. Which must be set before the .secure_log_unique
125 /// directive is used or it is an error.
127 /// The stream that gets written to for the .secure_log_unique directive.
128 std::unique_ptr<raw_fd_ostream> SecureLog;
129 /// Boolean toggled when .secure_log_unique / .secure_log_reset is seen to
130 /// catch errors if .secure_log_unique appears twice without
131 /// .secure_log_reset appearing between them.
132 bool SecureLogUsed = false;
134 /// The compilation directory to use for DW_AT_comp_dir.
135 SmallString<128> CompilationDir;
137 /// The main file name if passed in explicitly.
138 std::string MainFileName;
140 /// The dwarf file and directory tables from the dwarf .file directive.
141 /// We now emit a line table for each compile unit. To reduce the prologue
142 /// size of each line table, the files and directories used by each compile
143 /// unit are separated.
144 std::map<unsigned, MCDwarfLineTable> MCDwarfLineTablesCUMap;
146 /// The current dwarf line information from the last dwarf .loc directive.
147 MCDwarfLoc CurrentDwarfLoc;
148 bool DwarfLocSeen = false;
150 /// Generate dwarf debugging info for assembly source files.
151 bool GenDwarfForAssembly = false;
153 /// The current dwarf file number when generate dwarf debugging info for
154 /// assembly source files.
155 unsigned GenDwarfFileNumber = 0;
157 /// Sections for generating the .debug_ranges and .debug_aranges sections.
158 SetVector<MCSection *> SectionsForRanges;
160 /// The information gathered from labels that will have dwarf label
161 /// entries when generating dwarf assembly source files.
162 std::vector<MCGenDwarfLabelEntry> MCGenDwarfLabelEntries;
164 /// The string to embed in the debug information for the compile unit, if
166 StringRef DwarfDebugFlags;
168 /// The string to embed in as the dwarf AT_producer for the compile unit, if
170 StringRef DwarfDebugProducer;
172 /// The maximum version of dwarf that we should emit.
173 uint16_t DwarfVersion = 4;
175 /// Honor temporary labels, this is useful for debugging semantic
176 /// differences between temporary and non-temporary labels (primarily on
178 bool AllowTemporaryLabels = true;
179 bool UseNamesOnTempLabels = true;
181 /// The Compile Unit ID that we are currently processing.
182 unsigned DwarfCompileUnitID = 0;
184 struct ELFSectionKey {
185 std::string SectionName;
189 ELFSectionKey(StringRef SectionName, StringRef GroupName,
191 : SectionName(SectionName), GroupName(GroupName), UniqueID(UniqueID) {
194 bool operator<(const ELFSectionKey &Other) const {
195 if (SectionName != Other.SectionName)
196 return SectionName < Other.SectionName;
197 if (GroupName != Other.GroupName)
198 return GroupName < Other.GroupName;
199 return UniqueID < Other.UniqueID;
203 struct COFFSectionKey {
204 std::string SectionName;
209 COFFSectionKey(StringRef SectionName, StringRef GroupName,
210 int SelectionKey, unsigned UniqueID)
211 : SectionName(SectionName), GroupName(GroupName),
212 SelectionKey(SelectionKey), UniqueID(UniqueID) {}
214 bool operator<(const COFFSectionKey &Other) const {
215 if (SectionName != Other.SectionName)
216 return SectionName < Other.SectionName;
217 if (GroupName != Other.GroupName)
218 return GroupName < Other.GroupName;
219 if (SelectionKey != Other.SelectionKey)
220 return SelectionKey < Other.SelectionKey;
221 return UniqueID < Other.UniqueID;
225 struct WasmSectionKey {
226 std::string SectionName;
230 WasmSectionKey(StringRef SectionName, StringRef GroupName,
232 : SectionName(SectionName), GroupName(GroupName), UniqueID(UniqueID) {
235 bool operator<(const WasmSectionKey &Other) const {
236 if (SectionName != Other.SectionName)
237 return SectionName < Other.SectionName;
238 if (GroupName != Other.GroupName)
239 return GroupName < Other.GroupName;
240 return UniqueID < Other.UniqueID;
244 StringMap<MCSectionMachO *> MachOUniquingMap;
245 std::map<ELFSectionKey, MCSectionELF *> ELFUniquingMap;
246 std::map<COFFSectionKey, MCSectionCOFF *> COFFUniquingMap;
247 std::map<WasmSectionKey, MCSectionWasm *> WasmUniquingMap;
248 StringMap<bool> RelSecNames;
250 SpecificBumpPtrAllocator<MCSubtargetInfo> MCSubtargetAllocator;
252 /// Do automatic reset in destructor
255 bool HadError = false;
257 MCSymbol *createSymbolImpl(const StringMapEntry<bool> *Name,
259 MCSymbol *createSymbol(StringRef Name, bool AlwaysAddSuffix,
262 MCSymbol *getOrCreateDirectionalLocalSymbol(unsigned LocalLabelVal,
265 MCSectionELF *createELFSectionImpl(StringRef Section, unsigned Type,
266 unsigned Flags, SectionKind K,
268 const MCSymbolELF *Group,
270 const MCSymbolELF *Associated);
272 /// \brief Map of currently defined macros.
273 StringMap<MCAsmMacro> MacroMap;
276 explicit MCContext(const MCAsmInfo *MAI, const MCRegisterInfo *MRI,
277 const MCObjectFileInfo *MOFI,
278 const SourceMgr *Mgr = nullptr, bool DoAutoReset = true);
279 MCContext(const MCContext &) = delete;
280 MCContext &operator=(const MCContext &) = delete;
283 const SourceMgr *getSourceManager() const { return SrcMgr; }
285 void setInlineSourceManager(SourceMgr *SM) { InlineSrcMgr = SM; }
287 const MCAsmInfo *getAsmInfo() const { return MAI; }
289 const MCRegisterInfo *getRegisterInfo() const { return MRI; }
291 const MCObjectFileInfo *getObjectFileInfo() const { return MOFI; }
293 CodeViewContext &getCVContext();
295 void setAllowTemporaryLabels(bool Value) { AllowTemporaryLabels = Value; }
296 void setUseNamesOnTempLabels(bool Value) { UseNamesOnTempLabels = Value; }
298 /// \name Module Lifetime Management
301 /// reset - return object to right after construction state to prepare
302 /// to process a new module
307 /// \name Symbol Management
310 /// Create and return a new linker temporary symbol with a unique but
311 /// unspecified name.
312 MCSymbol *createLinkerPrivateTempSymbol();
314 /// Create and return a new assembler temporary symbol with a unique but
315 /// unspecified name.
316 MCSymbol *createTempSymbol(bool CanBeUnnamed = true);
318 MCSymbol *createTempSymbol(const Twine &Name, bool AlwaysAddSuffix,
319 bool CanBeUnnamed = true);
321 /// Create the definition of a directional local symbol for numbered label
322 /// (used for "1:" definitions).
323 MCSymbol *createDirectionalLocalSymbol(unsigned LocalLabelVal);
325 /// Create and return a directional local symbol for numbered label (used
326 /// for "1b" or 1f" references).
327 MCSymbol *getDirectionalLocalSymbol(unsigned LocalLabelVal, bool Before);
329 /// Lookup the symbol inside with the specified \p Name. If it exists,
330 /// return it. If not, create a forward reference and return it.
332 /// \param Name - The symbol name, which must be unique across all symbols.
333 MCSymbol *getOrCreateSymbol(const Twine &Name);
335 /// Gets a symbol that will be defined to the final stack offset of a local
336 /// variable after codegen.
338 /// \param Idx - The index of a local variable passed to @llvm.localescape.
339 MCSymbol *getOrCreateFrameAllocSymbol(StringRef FuncName, unsigned Idx);
341 MCSymbol *getOrCreateParentFrameOffsetSymbol(StringRef FuncName);
343 MCSymbol *getOrCreateLSDASymbol(StringRef FuncName);
345 /// Get the symbol for \p Name, or null.
346 MCSymbol *lookupSymbol(const Twine &Name) const;
348 /// Set value for a symbol.
349 void setSymbolValue(MCStreamer &Streamer, StringRef Sym, uint64_t Val);
351 /// getSymbols - Get a reference for the symbol table for clients that
352 /// want to, for example, iterate over all symbols. 'const' because we
353 /// still want any modifications to the table itself to use the MCContext
355 const SymbolTable &getSymbols() const { return Symbols; }
359 /// \name Section Management
363 /// Pass this value as the UniqueID during section creation to get the
364 /// generic section with the given name and characteristics. The usual
365 /// sections such as .text use this ID.
366 GenericSectionID = ~0U
369 /// Return the MCSection for the specified mach-o section. This requires
370 /// the operands to be valid.
371 MCSectionMachO *getMachOSection(StringRef Segment, StringRef Section,
372 unsigned TypeAndAttributes,
373 unsigned Reserved2, SectionKind K,
374 const char *BeginSymName = nullptr);
376 MCSectionMachO *getMachOSection(StringRef Segment, StringRef Section,
377 unsigned TypeAndAttributes, SectionKind K,
378 const char *BeginSymName = nullptr) {
379 return getMachOSection(Segment, Section, TypeAndAttributes, 0, K,
383 MCSectionELF *getELFSection(const Twine &Section, unsigned Type,
385 return getELFSection(Section, Type, Flags, 0, "");
388 MCSectionELF *getELFSection(const Twine &Section, unsigned Type,
389 unsigned Flags, unsigned EntrySize,
390 const Twine &Group) {
391 return getELFSection(Section, Type, Flags, EntrySize, Group, ~0);
394 MCSectionELF *getELFSection(const Twine &Section, unsigned Type,
395 unsigned Flags, unsigned EntrySize,
396 const Twine &Group, unsigned UniqueID) {
397 return getELFSection(Section, Type, Flags, EntrySize, Group, UniqueID,
401 MCSectionELF *getELFSection(const Twine &Section, unsigned Type,
402 unsigned Flags, unsigned EntrySize,
403 const Twine &Group, unsigned UniqueID,
404 const MCSymbolELF *Associated);
406 MCSectionELF *getELFSection(const Twine &Section, unsigned Type,
407 unsigned Flags, unsigned EntrySize,
408 const MCSymbolELF *Group, unsigned UniqueID,
409 const MCSymbolELF *Associated);
411 /// Get a section with the provided group identifier. This section is
412 /// named by concatenating \p Prefix with '.' then \p Suffix. The \p Type
413 /// describes the type of the section and \p Flags are used to further
414 /// configure this named section.
415 MCSectionELF *getELFNamedSection(const Twine &Prefix, const Twine &Suffix,
416 unsigned Type, unsigned Flags,
417 unsigned EntrySize = 0);
419 MCSectionELF *createELFRelSection(const Twine &Name, unsigned Type,
420 unsigned Flags, unsigned EntrySize,
421 const MCSymbolELF *Group,
422 const MCSectionELF *RelInfoSection);
424 void renameELFSection(MCSectionELF *Section, StringRef Name);
426 MCSectionELF *createELFGroupSection(const MCSymbolELF *Group);
428 MCSectionCOFF *getCOFFSection(StringRef Section, unsigned Characteristics,
429 SectionKind Kind, StringRef COMDATSymName,
431 unsigned UniqueID = GenericSectionID,
432 const char *BeginSymName = nullptr);
434 MCSectionCOFF *getCOFFSection(StringRef Section, unsigned Characteristics,
436 const char *BeginSymName = nullptr);
438 MCSectionCOFF *getCOFFSection(StringRef Section);
440 /// Gets or creates a section equivalent to Sec that is associated with the
441 /// section containing KeySym. For example, to create a debug info section
442 /// associated with an inline function, pass the normal debug info section
443 /// as Sec and the function symbol as KeySym.
445 getAssociativeCOFFSection(MCSectionCOFF *Sec, const MCSymbol *KeySym,
446 unsigned UniqueID = GenericSectionID);
448 MCSectionWasm *getWasmSection(const Twine &Section, SectionKind K) {
449 return getWasmSection(Section, K, nullptr);
452 MCSectionWasm *getWasmSection(const Twine &Section, SectionKind K,
453 const char *BeginSymName) {
454 return getWasmSection(Section, K, "", ~0, BeginSymName);
457 MCSectionWasm *getWasmSection(const Twine &Section, SectionKind K,
458 const Twine &Group, unsigned UniqueID) {
459 return getWasmSection(Section, K, Group, UniqueID, nullptr);
462 MCSectionWasm *getWasmSection(const Twine &Section, SectionKind K,
463 const Twine &Group, unsigned UniqueID,
464 const char *BeginSymName);
466 MCSectionWasm *getWasmSection(const Twine &Section, SectionKind K,
467 const MCSymbolWasm *Group, unsigned UniqueID,
468 const char *BeginSymName);
470 // Create and save a copy of STI and return a reference to the copy.
471 MCSubtargetInfo &getSubtargetCopy(const MCSubtargetInfo &STI);
475 /// \name Dwarf Management
478 /// \brief Get the compilation directory for DW_AT_comp_dir
479 /// The compilation directory should be set with \c setCompilationDir before
480 /// calling this function. If it is unset, an empty string will be returned.
481 StringRef getCompilationDir() const { return CompilationDir; }
483 /// \brief Set the compilation directory for DW_AT_comp_dir
484 void setCompilationDir(StringRef S) { CompilationDir = S.str(); }
486 /// \brief Get the main file name for use in error messages and debug
487 /// info. This can be set to ensure we've got the correct file name
488 /// after preprocessing or for -save-temps.
489 const std::string &getMainFileName() const { return MainFileName; }
491 /// \brief Set the main file name and override the default.
492 void setMainFileName(StringRef S) { MainFileName = S; }
494 /// Creates an entry in the dwarf file and directory tables.
495 unsigned getDwarfFile(StringRef Directory, StringRef FileName,
496 unsigned FileNumber, unsigned CUID);
498 bool isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID = 0);
500 const std::map<unsigned, MCDwarfLineTable> &getMCDwarfLineTables() const {
501 return MCDwarfLineTablesCUMap;
504 MCDwarfLineTable &getMCDwarfLineTable(unsigned CUID) {
505 return MCDwarfLineTablesCUMap[CUID];
508 const MCDwarfLineTable &getMCDwarfLineTable(unsigned CUID) const {
509 auto I = MCDwarfLineTablesCUMap.find(CUID);
510 assert(I != MCDwarfLineTablesCUMap.end());
514 const SmallVectorImpl<MCDwarfFile> &getMCDwarfFiles(unsigned CUID = 0) {
515 return getMCDwarfLineTable(CUID).getMCDwarfFiles();
518 const SmallVectorImpl<std::string> &getMCDwarfDirs(unsigned CUID = 0) {
519 return getMCDwarfLineTable(CUID).getMCDwarfDirs();
522 bool hasMCLineSections() const {
523 for (const auto &Table : MCDwarfLineTablesCUMap)
524 if (!Table.second.getMCDwarfFiles().empty() || Table.second.getLabel())
529 unsigned getDwarfCompileUnitID() { return DwarfCompileUnitID; }
531 void setDwarfCompileUnitID(unsigned CUIndex) {
532 DwarfCompileUnitID = CUIndex;
535 void setMCLineTableCompilationDir(unsigned CUID, StringRef CompilationDir) {
536 getMCDwarfLineTable(CUID).setCompilationDir(CompilationDir);
539 /// Saves the information from the currently parsed dwarf .loc directive
540 /// and sets DwarfLocSeen. When the next instruction is assembled an entry
541 /// in the line number table with this information and the address of the
542 /// instruction will be created.
543 void setCurrentDwarfLoc(unsigned FileNum, unsigned Line, unsigned Column,
544 unsigned Flags, unsigned Isa,
545 unsigned Discriminator) {
546 CurrentDwarfLoc.setFileNum(FileNum);
547 CurrentDwarfLoc.setLine(Line);
548 CurrentDwarfLoc.setColumn(Column);
549 CurrentDwarfLoc.setFlags(Flags);
550 CurrentDwarfLoc.setIsa(Isa);
551 CurrentDwarfLoc.setDiscriminator(Discriminator);
555 void clearDwarfLocSeen() { DwarfLocSeen = false; }
557 bool getDwarfLocSeen() { return DwarfLocSeen; }
558 const MCDwarfLoc &getCurrentDwarfLoc() { return CurrentDwarfLoc; }
560 bool getGenDwarfForAssembly() { return GenDwarfForAssembly; }
561 void setGenDwarfForAssembly(bool Value) { GenDwarfForAssembly = Value; }
562 unsigned getGenDwarfFileNumber() { return GenDwarfFileNumber; }
564 void setGenDwarfFileNumber(unsigned FileNumber) {
565 GenDwarfFileNumber = FileNumber;
568 const SetVector<MCSection *> &getGenDwarfSectionSyms() {
569 return SectionsForRanges;
572 bool addGenDwarfSection(MCSection *Sec) {
573 return SectionsForRanges.insert(Sec);
576 void finalizeDwarfSections(MCStreamer &MCOS);
578 const std::vector<MCGenDwarfLabelEntry> &getMCGenDwarfLabelEntries() const {
579 return MCGenDwarfLabelEntries;
582 void addMCGenDwarfLabelEntry(const MCGenDwarfLabelEntry &E) {
583 MCGenDwarfLabelEntries.push_back(E);
586 void setDwarfDebugFlags(StringRef S) { DwarfDebugFlags = S; }
587 StringRef getDwarfDebugFlags() { return DwarfDebugFlags; }
589 void setDwarfDebugProducer(StringRef S) { DwarfDebugProducer = S; }
590 StringRef getDwarfDebugProducer() { return DwarfDebugProducer; }
592 dwarf::DwarfFormat getDwarfFormat() const {
593 // TODO: Support DWARF64
594 return dwarf::DWARF32;
597 void setDwarfVersion(uint16_t v) { DwarfVersion = v; }
598 uint16_t getDwarfVersion() const { return DwarfVersion; }
602 char *getSecureLogFile() { return SecureLogFile; }
603 raw_fd_ostream *getSecureLog() { return SecureLog.get(); }
605 void setSecureLog(std::unique_ptr<raw_fd_ostream> Value) {
606 SecureLog = std::move(Value);
609 bool getSecureLogUsed() { return SecureLogUsed; }
610 void setSecureLogUsed(bool Value) { SecureLogUsed = Value; }
612 void *allocate(unsigned Size, unsigned Align = 8) {
613 return Allocator.Allocate(Size, Align);
616 void deallocate(void *Ptr) {}
618 bool hadError() { return HadError; }
619 void reportError(SMLoc L, const Twine &Msg);
620 // Unrecoverable error has occurred. Display the best diagnostic we can
621 // and bail via exit(1). For now, most MC backend errors are unrecoverable.
622 // FIXME: We should really do something about that.
623 LLVM_ATTRIBUTE_NORETURN void reportFatalError(SMLoc L,
626 const MCAsmMacro *lookupMacro(StringRef Name) {
627 StringMap<MCAsmMacro>::iterator I = MacroMap.find(Name);
628 return (I == MacroMap.end()) ? nullptr : &I->getValue();
631 void defineMacro(StringRef Name, MCAsmMacro Macro) {
632 MacroMap.insert(std::make_pair(Name, std::move(Macro)));
635 void undefineMacro(StringRef Name) { MacroMap.erase(Name); }
638 } // end namespace llvm
640 // operator new and delete aren't allowed inside namespaces.
641 // The throw specifications are mandated by the standard.
642 /// \brief Placement new for using the MCContext's allocator.
644 /// This placement form of operator new uses the MCContext's allocator for
645 /// obtaining memory. It is a non-throwing new, which means that it returns
646 /// null on error. (If that is what the allocator does. The current does, so if
647 /// this ever changes, this operator will have to be changed, too.)
648 /// Usage looks like this (assuming there's an MCContext 'Context' in scope):
650 /// // Default alignment (8)
651 /// IntegerLiteral *Ex = new (Context) IntegerLiteral(arguments);
652 /// // Specific alignment
653 /// IntegerLiteral *Ex2 = new (Context, 4) IntegerLiteral(arguments);
655 /// Please note that you cannot use delete on the pointer; it must be
656 /// deallocated using an explicit destructor call followed by
657 /// \c Context.Deallocate(Ptr).
659 /// \param Bytes The number of bytes to allocate. Calculated by the compiler.
660 /// \param C The MCContext that provides the allocator.
661 /// \param Alignment The alignment of the allocated memory (if the underlying
662 /// allocator supports it).
663 /// \return The allocated memory. Could be NULL.
664 inline void *operator new(size_t Bytes, llvm::MCContext &C,
665 size_t Alignment = 8) noexcept {
666 return C.allocate(Bytes, Alignment);
668 /// \brief Placement delete companion to the new above.
670 /// This operator is just a companion to the new above. There is no way of
671 /// invoking it directly; see the new operator for more details. This operator
672 /// is called implicitly by the compiler if a placement new expression using
673 /// the MCContext throws in the object constructor.
674 inline void operator delete(void *Ptr, llvm::MCContext &C, size_t) noexcept {
678 /// This placement form of operator new[] uses the MCContext's allocator for
679 /// obtaining memory. It is a non-throwing new[], which means that it returns
681 /// Usage looks like this (assuming there's an MCContext 'Context' in scope):
683 /// // Default alignment (8)
684 /// char *data = new (Context) char[10];
685 /// // Specific alignment
686 /// char *data = new (Context, 4) char[10];
688 /// Please note that you cannot use delete on the pointer; it must be
689 /// deallocated using an explicit destructor call followed by
690 /// \c Context.Deallocate(Ptr).
692 /// \param Bytes The number of bytes to allocate. Calculated by the compiler.
693 /// \param C The MCContext that provides the allocator.
694 /// \param Alignment The alignment of the allocated memory (if the underlying
695 /// allocator supports it).
696 /// \return The allocated memory. Could be NULL.
697 inline void *operator new[](size_t Bytes, llvm::MCContext &C,
698 size_t Alignment = 8) noexcept {
699 return C.allocate(Bytes, Alignment);
702 /// \brief Placement delete[] companion to the new[] above.
704 /// This operator is just a companion to the new[] above. There is no way of
705 /// invoking it directly; see the new[] operator for more details. This operator
706 /// is called implicitly by the compiler if a placement new[] expression using
707 /// the MCContext throws in the object constructor.
708 inline void operator delete[](void *Ptr, llvm::MCContext &C) noexcept {
712 #endif // LLVM_MC_MCCONTEXT_H