MCContext.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  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. #ifndef LLVM_MC_MCCONTEXT_H
  10. #define LLVM_MC_MCCONTEXT_H
  11. #include "llvm/ADT/DenseMap.h"
  12. #include "llvm/ADT/SetVector.h"
  13. #include "llvm/ADT/SmallString.h"
  14. #include "llvm/ADT/SmallVector.h"
  15. #include "llvm/ADT/StringMap.h"
  16. #include "llvm/ADT/Twine.h"
  17. #include "llvm/MC/MCDwarf.h"
  18. #include "llvm/MC/SectionKind.h"
  19. #include "llvm/Support/Allocator.h"
  20. #include "llvm/Support/Compiler.h"
  21. #include "llvm/Support/raw_ostream.h"
  22. #include <map>
  23. #include <tuple>
  24. #include <vector> // FIXME: Shouldn't be needed.
  25. namespace llvm {
  26. class MCAsmInfo;
  27. class MCExpr;
  28. class MCSection;
  29. class MCSymbol;
  30. class MCSymbolELF;
  31. class MCLabel;
  32. struct MCDwarfFile;
  33. class MCDwarfLoc;
  34. class MCObjectFileInfo;
  35. class MCRegisterInfo;
  36. class MCLineSection;
  37. class SMLoc;
  38. class MCSectionMachO;
  39. class MCSectionELF;
  40. class MCSectionCOFF;
  41. /// Context object for machine code objects. This class owns all of the
  42. /// sections that it creates.
  43. ///
  44. class MCContext {
  45. MCContext(const MCContext &) = delete;
  46. MCContext &operator=(const MCContext &) = delete;
  47. public:
  48. typedef StringMap<MCSymbol *, BumpPtrAllocator &> SymbolTable;
  49. private:
  50. /// The SourceMgr for this object, if any.
  51. const SourceMgr *SrcMgr;
  52. /// The MCAsmInfo for this target.
  53. const MCAsmInfo *MAI;
  54. /// The MCRegisterInfo for this target.
  55. const MCRegisterInfo *MRI;
  56. /// The MCObjectFileInfo for this target.
  57. const MCObjectFileInfo *MOFI;
  58. /// Allocator object used for creating machine code objects.
  59. ///
  60. /// We use a bump pointer allocator to avoid the need to track all allocated
  61. /// objects.
  62. BumpPtrAllocator Allocator;
  63. /// Bindings of names to symbols.
  64. SymbolTable Symbols;
  65. /// ELF sections can have a corresponding symbol. This maps one to the
  66. /// other.
  67. DenseMap<const MCSectionELF *, MCSymbolELF *> SectionSymbols;
  68. /// A mapping from a local label number and an instance count to a symbol.
  69. /// For example, in the assembly
  70. /// 1:
  71. /// 2:
  72. /// 1:
  73. /// We have three labels represented by the pairs (1, 0), (2, 0) and (1, 1)
  74. DenseMap<std::pair<unsigned, unsigned>, MCSymbol *> LocalSymbols;
  75. /// Keeps tracks of names that were used both for used declared and
  76. /// artificial symbols.
  77. StringMap<bool, BumpPtrAllocator &> UsedNames;
  78. /// The next ID to dole out to an unnamed assembler temporary symbol with
  79. /// a given prefix.
  80. StringMap<unsigned> NextID;
  81. /// Instances of directional local labels.
  82. DenseMap<unsigned, MCLabel *> Instances;
  83. /// NextInstance() creates the next instance of the directional local label
  84. /// for the LocalLabelVal and adds it to the map if needed.
  85. unsigned NextInstance(unsigned LocalLabelVal);
  86. /// GetInstance() gets the current instance of the directional local label
  87. /// for the LocalLabelVal and adds it to the map if needed.
  88. unsigned GetInstance(unsigned LocalLabelVal);
  89. /// The file name of the log file from the environment variable
  90. /// AS_SECURE_LOG_FILE. Which must be set before the .secure_log_unique
  91. /// directive is used or it is an error.
  92. char *SecureLogFile;
  93. /// The stream that gets written to for the .secure_log_unique directive.
  94. raw_ostream *SecureLog;
  95. /// Boolean toggled when .secure_log_unique / .secure_log_reset is seen to
  96. /// catch errors if .secure_log_unique appears twice without
  97. /// .secure_log_reset appearing between them.
  98. bool SecureLogUsed;
  99. /// The compilation directory to use for DW_AT_comp_dir.
  100. SmallString<128> CompilationDir;
  101. /// The main file name if passed in explicitly.
  102. std::string MainFileName;
  103. /// The dwarf file and directory tables from the dwarf .file directive.
  104. /// We now emit a line table for each compile unit. To reduce the prologue
  105. /// size of each line table, the files and directories used by each compile
  106. /// unit are separated.
  107. std::map<unsigned, MCDwarfLineTable> MCDwarfLineTablesCUMap;
  108. /// The current dwarf line information from the last dwarf .loc directive.
  109. MCDwarfLoc CurrentDwarfLoc;
  110. bool DwarfLocSeen;
  111. /// Generate dwarf debugging info for assembly source files.
  112. bool GenDwarfForAssembly;
  113. /// The current dwarf file number when generate dwarf debugging info for
  114. /// assembly source files.
  115. unsigned GenDwarfFileNumber;
  116. /// Sections for generating the .debug_ranges and .debug_aranges sections.
  117. SetVector<MCSection *> SectionsForRanges;
  118. /// The information gathered from labels that will have dwarf label
  119. /// entries when generating dwarf assembly source files.
  120. std::vector<MCGenDwarfLabelEntry> MCGenDwarfLabelEntries;
  121. /// The string to embed in the debug information for the compile unit, if
  122. /// non-empty.
  123. StringRef DwarfDebugFlags;
  124. /// The string to embed in as the dwarf AT_producer for the compile unit, if
  125. /// non-empty.
  126. StringRef DwarfDebugProducer;
  127. /// The maximum version of dwarf that we should emit.
  128. uint16_t DwarfVersion;
  129. /// Honor temporary labels, this is useful for debugging semantic
  130. /// differences between temporary and non-temporary labels (primarily on
  131. /// Darwin).
  132. bool AllowTemporaryLabels;
  133. bool UseNamesOnTempLabels = true;
  134. /// The Compile Unit ID that we are currently processing.
  135. unsigned DwarfCompileUnitID;
  136. struct ELFSectionKey {
  137. std::string SectionName;
  138. StringRef GroupName;
  139. unsigned UniqueID;
  140. ELFSectionKey(StringRef SectionName, StringRef GroupName,
  141. unsigned UniqueID)
  142. : SectionName(SectionName), GroupName(GroupName), UniqueID(UniqueID) {
  143. }
  144. bool operator<(const ELFSectionKey &Other) const {
  145. if (SectionName != Other.SectionName)
  146. return SectionName < Other.SectionName;
  147. if (GroupName != Other.GroupName)
  148. return GroupName < Other.GroupName;
  149. return UniqueID < Other.UniqueID;
  150. }
  151. };
  152. struct COFFSectionKey {
  153. std::string SectionName;
  154. StringRef GroupName;
  155. int SelectionKey;
  156. COFFSectionKey(StringRef SectionName, StringRef GroupName,
  157. int SelectionKey)
  158. : SectionName(SectionName), GroupName(GroupName),
  159. SelectionKey(SelectionKey) {}
  160. bool operator<(const COFFSectionKey &Other) const {
  161. if (SectionName != Other.SectionName)
  162. return SectionName < Other.SectionName;
  163. if (GroupName != Other.GroupName)
  164. return GroupName < Other.GroupName;
  165. return SelectionKey < Other.SelectionKey;
  166. }
  167. };
  168. StringMap<MCSectionMachO *> MachOUniquingMap;
  169. std::map<ELFSectionKey, MCSectionELF *> ELFUniquingMap;
  170. std::map<COFFSectionKey, MCSectionCOFF *> COFFUniquingMap;
  171. StringMap<bool> ELFRelSecNames;
  172. /// Do automatic reset in destructor
  173. bool AutoReset;
  174. MCSymbol *createSymbolImpl(const StringMapEntry<bool> *Name,
  175. bool CanBeUnnamed);
  176. MCSymbol *createSymbol(StringRef Name, bool AlwaysAddSuffix,
  177. bool IsTemporary);
  178. MCSymbol *getOrCreateDirectionalLocalSymbol(unsigned LocalLabelVal,
  179. unsigned Instance);
  180. public:
  181. explicit MCContext(const MCAsmInfo *MAI, const MCRegisterInfo *MRI,
  182. const MCObjectFileInfo *MOFI,
  183. const SourceMgr *Mgr = nullptr, bool DoAutoReset = true);
  184. ~MCContext();
  185. const SourceMgr *getSourceManager() const { return SrcMgr; }
  186. const MCAsmInfo *getAsmInfo() const { return MAI; }
  187. const MCRegisterInfo *getRegisterInfo() const { return MRI; }
  188. const MCObjectFileInfo *getObjectFileInfo() const { return MOFI; }
  189. void setAllowTemporaryLabels(bool Value) { AllowTemporaryLabels = Value; }
  190. void setUseNamesOnTempLabels(bool Value) { UseNamesOnTempLabels = Value; }
  191. /// \name Module Lifetime Management
  192. /// @{
  193. /// reset - return object to right after construction state to prepare
  194. /// to process a new module
  195. void reset();
  196. /// @}
  197. /// \name Symbol Management
  198. /// @{
  199. /// Create and return a new linker temporary symbol with a unique but
  200. /// unspecified name.
  201. MCSymbol *createLinkerPrivateTempSymbol();
  202. /// Create and return a new assembler temporary symbol with a unique but
  203. /// unspecified name.
  204. MCSymbol *createTempSymbol(bool CanBeUnnamed = true);
  205. MCSymbol *createTempSymbol(const Twine &Name, bool AlwaysAddSuffix,
  206. bool CanBeUnnamed = true);
  207. /// Create the definition of a directional local symbol for numbered label
  208. /// (used for "1:" definitions).
  209. MCSymbol *createDirectionalLocalSymbol(unsigned LocalLabelVal);
  210. /// Create and return a directional local symbol for numbered label (used
  211. /// for "1b" or 1f" references).
  212. MCSymbol *getDirectionalLocalSymbol(unsigned LocalLabelVal, bool Before);
  213. /// Lookup the symbol inside with the specified \p Name. If it exists,
  214. /// return it. If not, create a forward reference and return it.
  215. ///
  216. /// \param Name - The symbol name, which must be unique across all symbols.
  217. MCSymbol *getOrCreateSymbol(const Twine &Name);
  218. MCSymbolELF *getOrCreateSectionSymbol(const MCSectionELF &Section);
  219. /// Gets a symbol that will be defined to the final stack offset of a local
  220. /// variable after codegen.
  221. ///
  222. /// \param Idx - The index of a local variable passed to @llvm.localescape.
  223. MCSymbol *getOrCreateFrameAllocSymbol(StringRef FuncName, unsigned Idx);
  224. MCSymbol *getOrCreateParentFrameOffsetSymbol(StringRef FuncName);
  225. MCSymbol *getOrCreateLSDASymbol(StringRef FuncName);
  226. /// Get the symbol for \p Name, or null.
  227. MCSymbol *lookupSymbol(const Twine &Name) const;
  228. /// getSymbols - Get a reference for the symbol table for clients that
  229. /// want to, for example, iterate over all symbols. 'const' because we
  230. /// still want any modifications to the table itself to use the MCContext
  231. /// APIs.
  232. const SymbolTable &getSymbols() const { return Symbols; }
  233. /// @}
  234. /// \name Section Management
  235. /// @{
  236. /// Return the MCSection for the specified mach-o section. This requires
  237. /// the operands to be valid.
  238. MCSectionMachO *getMachOSection(StringRef Segment, StringRef Section,
  239. unsigned TypeAndAttributes,
  240. unsigned Reserved2, SectionKind K,
  241. const char *BeginSymName = nullptr);
  242. MCSectionMachO *getMachOSection(StringRef Segment, StringRef Section,
  243. unsigned TypeAndAttributes, SectionKind K,
  244. const char *BeginSymName = nullptr) {
  245. return getMachOSection(Segment, Section, TypeAndAttributes, 0, K,
  246. BeginSymName);
  247. }
  248. MCSectionELF *getELFSection(StringRef Section, unsigned Type,
  249. unsigned Flags) {
  250. return getELFSection(Section, Type, Flags, nullptr);
  251. }
  252. MCSectionELF *getELFSection(StringRef Section, unsigned Type,
  253. unsigned Flags, const char *BeginSymName) {
  254. return getELFSection(Section, Type, Flags, 0, "", BeginSymName);
  255. }
  256. MCSectionELF *getELFSection(StringRef Section, unsigned Type,
  257. unsigned Flags, unsigned EntrySize,
  258. StringRef Group) {
  259. return getELFSection(Section, Type, Flags, EntrySize, Group, nullptr);
  260. }
  261. MCSectionELF *getELFSection(StringRef Section, unsigned Type,
  262. unsigned Flags, unsigned EntrySize,
  263. StringRef Group, const char *BeginSymName) {
  264. return getELFSection(Section, Type, Flags, EntrySize, Group, ~0,
  265. BeginSymName);
  266. }
  267. MCSectionELF *getELFSection(StringRef Section, unsigned Type,
  268. unsigned Flags, unsigned EntrySize,
  269. StringRef Group, unsigned UniqueID) {
  270. return getELFSection(Section, Type, Flags, EntrySize, Group, UniqueID,
  271. nullptr);
  272. }
  273. MCSectionELF *getELFSection(StringRef Section, unsigned Type,
  274. unsigned Flags, unsigned EntrySize,
  275. StringRef Group, unsigned UniqueID,
  276. const char *BeginSymName);
  277. MCSectionELF *getELFSection(StringRef Section, unsigned Type,
  278. unsigned Flags, unsigned EntrySize,
  279. const MCSymbolELF *Group, unsigned UniqueID,
  280. const char *BeginSymName,
  281. const MCSectionELF *Associated);
  282. MCSectionELF *createELFRelSection(StringRef Name, unsigned Type,
  283. unsigned Flags, unsigned EntrySize,
  284. const MCSymbolELF *Group,
  285. const MCSectionELF *Associated);
  286. void renameELFSection(MCSectionELF *Section, StringRef Name);
  287. MCSectionELF *createELFGroupSection(const MCSymbolELF *Group);
  288. MCSectionCOFF *getCOFFSection(StringRef Section, unsigned Characteristics,
  289. SectionKind Kind, StringRef COMDATSymName,
  290. int Selection,
  291. const char *BeginSymName = nullptr);
  292. MCSectionCOFF *getCOFFSection(StringRef Section, unsigned Characteristics,
  293. SectionKind Kind,
  294. const char *BeginSymName = nullptr);
  295. MCSectionCOFF *getCOFFSection(StringRef Section);
  296. /// Gets or creates a section equivalent to Sec that is associated with the
  297. /// section containing KeySym. For example, to create a debug info section
  298. /// associated with an inline function, pass the normal debug info section
  299. /// as Sec and the function symbol as KeySym.
  300. MCSectionCOFF *getAssociativeCOFFSection(MCSectionCOFF *Sec,
  301. const MCSymbol *KeySym);
  302. /// @}
  303. /// \name Dwarf Management
  304. /// @{
  305. /// \brief Get the compilation directory for DW_AT_comp_dir
  306. /// This can be overridden by clients which want to control the reported
  307. /// compilation directory and have it be something other than the current
  308. /// working directory.
  309. /// Returns an empty string if the current directory cannot be determined.
  310. StringRef getCompilationDir() const { return CompilationDir; }
  311. /// \brief Set the compilation directory for DW_AT_comp_dir
  312. /// Override the default (CWD) compilation directory.
  313. void setCompilationDir(StringRef S) { CompilationDir = S.str(); }
  314. /// \brief Get the main file name for use in error messages and debug
  315. /// info. This can be set to ensure we've got the correct file name
  316. /// after preprocessing or for -save-temps.
  317. const std::string &getMainFileName() const { return MainFileName; }
  318. /// \brief Set the main file name and override the default.
  319. void setMainFileName(StringRef S) { MainFileName = S; }
  320. /// Creates an entry in the dwarf file and directory tables.
  321. unsigned getDwarfFile(StringRef Directory, StringRef FileName,
  322. unsigned FileNumber, unsigned CUID);
  323. bool isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID = 0);
  324. const std::map<unsigned, MCDwarfLineTable> &getMCDwarfLineTables() const {
  325. return MCDwarfLineTablesCUMap;
  326. }
  327. MCDwarfLineTable &getMCDwarfLineTable(unsigned CUID) {
  328. return MCDwarfLineTablesCUMap[CUID];
  329. }
  330. const MCDwarfLineTable &getMCDwarfLineTable(unsigned CUID) const {
  331. auto I = MCDwarfLineTablesCUMap.find(CUID);
  332. assert(I != MCDwarfLineTablesCUMap.end());
  333. return I->second;
  334. }
  335. const SmallVectorImpl<MCDwarfFile> &getMCDwarfFiles(unsigned CUID = 0) {
  336. return getMCDwarfLineTable(CUID).getMCDwarfFiles();
  337. }
  338. const SmallVectorImpl<std::string> &getMCDwarfDirs(unsigned CUID = 0) {
  339. return getMCDwarfLineTable(CUID).getMCDwarfDirs();
  340. }
  341. bool hasMCLineSections() const {
  342. for (const auto &Table : MCDwarfLineTablesCUMap)
  343. if (!Table.second.getMCDwarfFiles().empty() || Table.second.getLabel())
  344. return true;
  345. return false;
  346. }
  347. unsigned getDwarfCompileUnitID() { return DwarfCompileUnitID; }
  348. void setDwarfCompileUnitID(unsigned CUIndex) {
  349. DwarfCompileUnitID = CUIndex;
  350. }
  351. void setMCLineTableCompilationDir(unsigned CUID, StringRef CompilationDir) {
  352. getMCDwarfLineTable(CUID).setCompilationDir(CompilationDir);
  353. }
  354. /// Saves the information from the currently parsed dwarf .loc directive
  355. /// and sets DwarfLocSeen. When the next instruction is assembled an entry
  356. /// in the line number table with this information and the address of the
  357. /// instruction will be created.
  358. void setCurrentDwarfLoc(unsigned FileNum, unsigned Line, unsigned Column,
  359. unsigned Flags, unsigned Isa,
  360. unsigned Discriminator) {
  361. CurrentDwarfLoc.setFileNum(FileNum);
  362. CurrentDwarfLoc.setLine(Line);
  363. CurrentDwarfLoc.setColumn(Column);
  364. CurrentDwarfLoc.setFlags(Flags);
  365. CurrentDwarfLoc.setIsa(Isa);
  366. CurrentDwarfLoc.setDiscriminator(Discriminator);
  367. DwarfLocSeen = true;
  368. }
  369. void clearDwarfLocSeen() { DwarfLocSeen = false; }
  370. bool getDwarfLocSeen() { return DwarfLocSeen; }
  371. const MCDwarfLoc &getCurrentDwarfLoc() { return CurrentDwarfLoc; }
  372. bool getGenDwarfForAssembly() { return GenDwarfForAssembly; }
  373. void setGenDwarfForAssembly(bool Value) { GenDwarfForAssembly = Value; }
  374. unsigned getGenDwarfFileNumber() { return GenDwarfFileNumber; }
  375. void setGenDwarfFileNumber(unsigned FileNumber) {
  376. GenDwarfFileNumber = FileNumber;
  377. }
  378. const SetVector<MCSection *> &getGenDwarfSectionSyms() {
  379. return SectionsForRanges;
  380. }
  381. bool addGenDwarfSection(MCSection *Sec) {
  382. return SectionsForRanges.insert(Sec);
  383. }
  384. void finalizeDwarfSections(MCStreamer &MCOS);
  385. const std::vector<MCGenDwarfLabelEntry> &getMCGenDwarfLabelEntries() const {
  386. return MCGenDwarfLabelEntries;
  387. }
  388. void addMCGenDwarfLabelEntry(const MCGenDwarfLabelEntry &E) {
  389. MCGenDwarfLabelEntries.push_back(E);
  390. }
  391. void setDwarfDebugFlags(StringRef S) { DwarfDebugFlags = S; }
  392. StringRef getDwarfDebugFlags() { return DwarfDebugFlags; }
  393. void setDwarfDebugProducer(StringRef S) { DwarfDebugProducer = S; }
  394. StringRef getDwarfDebugProducer() { return DwarfDebugProducer; }
  395. void setDwarfVersion(uint16_t v) { DwarfVersion = v; }
  396. uint16_t getDwarfVersion() const { return DwarfVersion; }
  397. /// @}
  398. char *getSecureLogFile() { return SecureLogFile; }
  399. raw_ostream *getSecureLog() { return SecureLog; }
  400. bool getSecureLogUsed() { return SecureLogUsed; }
  401. void setSecureLog(raw_ostream *Value) { SecureLog = Value; }
  402. void setSecureLogUsed(bool Value) { SecureLogUsed = Value; }
  403. void *allocate(unsigned Size, unsigned Align = 8) {
  404. return Allocator.Allocate(Size, Align);
  405. }
  406. void deallocate(void *Ptr) {}
  407. // Unrecoverable error has occurred. Display the best diagnostic we can
  408. // and bail via exit(1). For now, most MC backend errors are unrecoverable.
  409. // FIXME: We should really do something about that.
  410. LLVM_ATTRIBUTE_NORETURN void reportFatalError(SMLoc L,
  411. const Twine &Msg) const;
  412. };
  413. } // end namespace llvm
  414. // operator new and delete aren't allowed inside namespaces.
  415. // The throw specifications are mandated by the standard.
  416. /// \brief Placement new for using the MCContext's allocator.
  417. ///
  418. /// This placement form of operator new uses the MCContext's allocator for
  419. /// obtaining memory. It is a non-throwing new, which means that it returns
  420. /// null on error. (If that is what the allocator does. The current does, so if
  421. /// this ever changes, this operator will have to be changed, too.)
  422. /// Usage looks like this (assuming there's an MCContext 'Context' in scope):
  423. /// \code
  424. /// // Default alignment (8)
  425. /// IntegerLiteral *Ex = new (Context) IntegerLiteral(arguments);
  426. /// // Specific alignment
  427. /// IntegerLiteral *Ex2 = new (Context, 4) IntegerLiteral(arguments);
  428. /// \endcode
  429. /// Please note that you cannot use delete on the pointer; it must be
  430. /// deallocated using an explicit destructor call followed by
  431. /// \c Context.Deallocate(Ptr).
  432. ///
  433. /// \param Bytes The number of bytes to allocate. Calculated by the compiler.
  434. /// \param C The MCContext that provides the allocator.
  435. /// \param Alignment The alignment of the allocated memory (if the underlying
  436. /// allocator supports it).
  437. /// \return The allocated memory. Could be NULL.
  438. inline void *operator new(size_t Bytes, llvm::MCContext &C,
  439. size_t Alignment = 8) throw() {
  440. return C.allocate(Bytes, Alignment);
  441. }
  442. /// \brief Placement delete companion to the new above.
  443. ///
  444. /// This operator is just a companion to the new above. There is no way of
  445. /// invoking it directly; see the new operator for more details. This operator
  446. /// is called implicitly by the compiler if a placement new expression using
  447. /// the MCContext throws in the object constructor.
  448. inline void operator delete(void *Ptr, llvm::MCContext &C, size_t)
  449. throw () {
  450. C.deallocate(Ptr);
  451. }
  452. /// This placement form of operator new[] uses the MCContext's allocator for
  453. /// obtaining memory. It is a non-throwing new[], which means that it returns
  454. /// null on error.
  455. /// Usage looks like this (assuming there's an MCContext 'Context' in scope):
  456. /// \code
  457. /// // Default alignment (8)
  458. /// char *data = new (Context) char[10];
  459. /// // Specific alignment
  460. /// char *data = new (Context, 4) char[10];
  461. /// \endcode
  462. /// Please note that you cannot use delete on the pointer; it must be
  463. /// deallocated using an explicit destructor call followed by
  464. /// \c Context.Deallocate(Ptr).
  465. ///
  466. /// \param Bytes The number of bytes to allocate. Calculated by the compiler.
  467. /// \param C The MCContext that provides the allocator.
  468. /// \param Alignment The alignment of the allocated memory (if the underlying
  469. /// allocator supports it).
  470. /// \return The allocated memory. Could be NULL.
  471. inline void *operator new[](size_t Bytes, llvm::MCContext& C,
  472. size_t Alignment = 8) throw() {
  473. return C.allocate(Bytes, Alignment);
  474. }
  475. /// \brief Placement delete[] companion to the new[] above.
  476. ///
  477. /// This operator is just a companion to the new[] above. There is no way of
  478. /// invoking it directly; see the new[] operator for more details. This operator
  479. /// is called implicitly by the compiler if a placement new[] expression using
  480. /// the MCContext throws in the object constructor.
  481. inline void operator delete[](void *Ptr, llvm::MCContext &C) throw () {
  482. C.deallocate(Ptr);
  483. }
  484. #endif