Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

605 lines
24 KiB

  1. //===-- llvm/Module.h - C++ class to represent a VM module ------*- 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. /// @file
  11. /// Module.h This file contains the declarations for the Module class.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_MODULE_H
  15. #define LLVM_MODULE_H
  16. #include "llvm/Function.h"
  17. #include "llvm/GlobalVariable.h"
  18. #include "llvm/GlobalAlias.h"
  19. #include "llvm/Metadata.h"
  20. #include "llvm/ADT/OwningPtr.h"
  21. #include "llvm/Support/DataTypes.h"
  22. #include <vector>
  23. namespace llvm {
  24. class FunctionType;
  25. class GVMaterializer;
  26. class LLVMContext;
  27. class StructType;
  28. template<typename T> struct DenseMapInfo;
  29. template<typename KeyT, typename ValueT, typename KeyInfoT> class DenseMap;
  30. template<> struct ilist_traits<Function>
  31. : public SymbolTableListTraits<Function, Module> {
  32. // createSentinel is used to get hold of the node that marks the end of the
  33. // list... (same trick used here as in ilist_traits<Instruction>)
  34. Function *createSentinel() const {
  35. return static_cast<Function*>(&Sentinel);
  36. }
  37. static void destroySentinel(Function*) {}
  38. Function *provideInitialHead() const { return createSentinel(); }
  39. Function *ensureHead(Function*) const { return createSentinel(); }
  40. static void noteHead(Function*, Function*) {}
  41. private:
  42. mutable ilist_node<Function> Sentinel;
  43. };
  44. template<> struct ilist_traits<GlobalVariable>
  45. : public SymbolTableListTraits<GlobalVariable, Module> {
  46. // createSentinel is used to create a node that marks the end of the list.
  47. GlobalVariable *createSentinel() const {
  48. return static_cast<GlobalVariable*>(&Sentinel);
  49. }
  50. static void destroySentinel(GlobalVariable*) {}
  51. GlobalVariable *provideInitialHead() const { return createSentinel(); }
  52. GlobalVariable *ensureHead(GlobalVariable*) const { return createSentinel(); }
  53. static void noteHead(GlobalVariable*, GlobalVariable*) {}
  54. private:
  55. mutable ilist_node<GlobalVariable> Sentinel;
  56. };
  57. template<> struct ilist_traits<GlobalAlias>
  58. : public SymbolTableListTraits<GlobalAlias, Module> {
  59. // createSentinel is used to create a node that marks the end of the list.
  60. GlobalAlias *createSentinel() const {
  61. return static_cast<GlobalAlias*>(&Sentinel);
  62. }
  63. static void destroySentinel(GlobalAlias*) {}
  64. GlobalAlias *provideInitialHead() const { return createSentinel(); }
  65. GlobalAlias *ensureHead(GlobalAlias*) const { return createSentinel(); }
  66. static void noteHead(GlobalAlias*, GlobalAlias*) {}
  67. private:
  68. mutable ilist_node<GlobalAlias> Sentinel;
  69. };
  70. template<> struct ilist_traits<NamedMDNode>
  71. : public ilist_default_traits<NamedMDNode> {
  72. // createSentinel is used to get hold of a node that marks the end of
  73. // the list...
  74. NamedMDNode *createSentinel() const {
  75. return static_cast<NamedMDNode*>(&Sentinel);
  76. }
  77. static void destroySentinel(NamedMDNode*) {}
  78. NamedMDNode *provideInitialHead() const { return createSentinel(); }
  79. NamedMDNode *ensureHead(NamedMDNode*) const { return createSentinel(); }
  80. static void noteHead(NamedMDNode*, NamedMDNode*) {}
  81. void addNodeToList(NamedMDNode *) {}
  82. void removeNodeFromList(NamedMDNode *) {}
  83. private:
  84. mutable ilist_node<NamedMDNode> Sentinel;
  85. };
  86. /// A Module instance is used to store all the information related to an
  87. /// LLVM module. Modules are the top level container of all other LLVM
  88. /// Intermediate Representation (IR) objects. Each module directly contains a
  89. /// list of globals variables, a list of functions, a list of libraries (or
  90. /// other modules) this module depends on, a symbol table, and various data
  91. /// about the target's characteristics.
  92. ///
  93. /// A module maintains a GlobalValRefMap object that is used to hold all
  94. /// constant references to global variables in the module. When a global
  95. /// variable is destroyed, it should have no entries in the GlobalValueRefMap.
  96. /// @brief The main container class for the LLVM Intermediate Representation.
  97. class Module {
  98. /// @name Types And Enumerations
  99. /// @{
  100. public:
  101. /// The type for the list of global variables.
  102. typedef iplist<GlobalVariable> GlobalListType;
  103. /// The type for the list of functions.
  104. typedef iplist<Function> FunctionListType;
  105. /// The type for the list of aliases.
  106. typedef iplist<GlobalAlias> AliasListType;
  107. /// The type for the list of named metadata.
  108. typedef ilist<NamedMDNode> NamedMDListType;
  109. /// The type for the list of dependent libraries.
  110. typedef std::vector<std::string> LibraryListType;
  111. /// The Global Variable iterator.
  112. typedef GlobalListType::iterator global_iterator;
  113. /// The Global Variable constant iterator.
  114. typedef GlobalListType::const_iterator const_global_iterator;
  115. /// The Function iterators.
  116. typedef FunctionListType::iterator iterator;
  117. /// The Function constant iterator
  118. typedef FunctionListType::const_iterator const_iterator;
  119. /// The Global Alias iterators.
  120. typedef AliasListType::iterator alias_iterator;
  121. /// The Global Alias constant iterator
  122. typedef AliasListType::const_iterator const_alias_iterator;
  123. /// The named metadata iterators.
  124. typedef NamedMDListType::iterator named_metadata_iterator;
  125. /// The named metadata constant interators.
  126. typedef NamedMDListType::const_iterator const_named_metadata_iterator;
  127. /// The Library list iterator.
  128. typedef LibraryListType::const_iterator lib_iterator;
  129. /// An enumeration for describing the endianess of the target machine.
  130. enum Endianness { AnyEndianness, LittleEndian, BigEndian };
  131. /// An enumeration for describing the size of a pointer on the target machine.
  132. enum PointerSize { AnyPointerSize, Pointer32, Pointer64 };
  133. /// An enumeration for the supported behaviors of module flags. The following
  134. /// module flags behavior values are supported:
  135. ///
  136. /// Value Behavior
  137. /// ----- --------
  138. /// 1 Error
  139. /// Emits an error if two values disagree.
  140. ///
  141. /// 2 Warning
  142. /// Emits a warning if two values disagree.
  143. ///
  144. /// 3 Require
  145. /// Emits an error when the specified value is not present
  146. /// or doesn't have the specified value. It is an error for
  147. /// two (or more) llvm.module.flags with the same ID to have
  148. /// the Require behavior but different values. There may be
  149. /// multiple Require flags per ID.
  150. ///
  151. /// 4 Override
  152. /// Uses the specified value if the two values disagree. It
  153. /// is an error for two (or more) llvm.module.flags with the
  154. /// same ID to have the Override behavior but different
  155. /// values.
  156. enum ModFlagBehavior { Error = 1, Warning = 2, Require = 3, Override = 4 };
  157. struct ModuleFlagEntry {
  158. ModFlagBehavior Behavior;
  159. MDString *Key;
  160. Value *Val;
  161. ModuleFlagEntry(ModFlagBehavior B, MDString *K, Value *V)
  162. : Behavior(B), Key(K), Val(V) {}
  163. };
  164. /// @}
  165. /// @name Member Variables
  166. /// @{
  167. private:
  168. LLVMContext &Context; ///< The LLVMContext from which types and
  169. ///< constants are allocated.
  170. GlobalListType GlobalList; ///< The Global Variables in the module
  171. FunctionListType FunctionList; ///< The Functions in the module
  172. AliasListType AliasList; ///< The Aliases in the module
  173. LibraryListType LibraryList; ///< The Libraries needed by the module
  174. NamedMDListType NamedMDList; ///< The named metadata in the module
  175. std::string GlobalScopeAsm; ///< Inline Asm at global scope.
  176. ValueSymbolTable *ValSymTab; ///< Symbol table for values
  177. OwningPtr<GVMaterializer> Materializer; ///< Used to materialize GlobalValues
  178. std::string ModuleID; ///< Human readable identifier for the module
  179. std::string TargetTriple; ///< Platform target triple Module compiled on
  180. std::string DataLayout; ///< Target data description
  181. void *NamedMDSymTab; ///< NamedMDNode names.
  182. friend class Constant;
  183. /// @}
  184. /// @name Constructors
  185. /// @{
  186. public:
  187. /// The Module constructor. Note that there is no default constructor. You
  188. /// must provide a name for the module upon construction.
  189. explicit Module(StringRef ModuleID, LLVMContext& C);
  190. /// The module destructor. This will dropAllReferences.
  191. ~Module();
  192. /// @}
  193. /// @name Module Level Accessors
  194. /// @{
  195. /// Get the module identifier which is, essentially, the name of the module.
  196. /// @returns the module identifier as a string
  197. const std::string &getModuleIdentifier() const { return ModuleID; }
  198. /// Get the data layout string for the module's target platform. This encodes
  199. /// the type sizes and alignments expected by this module.
  200. /// @returns the data layout as a string
  201. const std::string &getDataLayout() const { return DataLayout; }
  202. /// Get the target triple which is a string describing the target host.
  203. /// @returns a string containing the target triple.
  204. const std::string &getTargetTriple() const { return TargetTriple; }
  205. /// Get the target endian information.
  206. /// @returns Endianess - an enumeration for the endianess of the target
  207. Endianness getEndianness() const;
  208. /// Get the target pointer size.
  209. /// @returns PointerSize - an enumeration for the size of the target's pointer
  210. PointerSize getPointerSize() const;
  211. /// Get the global data context.
  212. /// @returns LLVMContext - a container for LLVM's global information
  213. LLVMContext &getContext() const { return Context; }
  214. /// Get any module-scope inline assembly blocks.
  215. /// @returns a string containing the module-scope inline assembly blocks.
  216. const std::string &getModuleInlineAsm() const { return GlobalScopeAsm; }
  217. /// @}
  218. /// @name Module Level Mutators
  219. /// @{
  220. /// Set the module identifier.
  221. void setModuleIdentifier(StringRef ID) { ModuleID = ID; }
  222. /// Set the data layout
  223. void setDataLayout(StringRef DL) { DataLayout = DL; }
  224. /// Set the target triple.
  225. void setTargetTriple(StringRef T) { TargetTriple = T; }
  226. /// Set the module-scope inline assembly blocks.
  227. void setModuleInlineAsm(StringRef Asm) {
  228. GlobalScopeAsm = Asm;
  229. if (!GlobalScopeAsm.empty() &&
  230. GlobalScopeAsm[GlobalScopeAsm.size()-1] != '\n')
  231. GlobalScopeAsm += '\n';
  232. }
  233. /// Append to the module-scope inline assembly blocks, automatically inserting
  234. /// a separating newline if necessary.
  235. void appendModuleInlineAsm(StringRef Asm) {
  236. GlobalScopeAsm += Asm;
  237. if (!GlobalScopeAsm.empty() &&
  238. GlobalScopeAsm[GlobalScopeAsm.size()-1] != '\n')
  239. GlobalScopeAsm += '\n';
  240. }
  241. /// @}
  242. /// @name Generic Value Accessors
  243. /// @{
  244. /// getNamedValue - Return the global value in the module with
  245. /// the specified name, of arbitrary type. This method returns null
  246. /// if a global with the specified name is not found.
  247. GlobalValue *getNamedValue(StringRef Name) const;
  248. /// getMDKindID - Return a unique non-zero ID for the specified metadata kind.
  249. /// This ID is uniqued across modules in the current LLVMContext.
  250. unsigned getMDKindID(StringRef Name) const;
  251. /// getMDKindNames - Populate client supplied SmallVector with the name for
  252. /// custom metadata IDs registered in this LLVMContext.
  253. void getMDKindNames(SmallVectorImpl<StringRef> &Result) const;
  254. typedef DenseMap<StructType*, unsigned, DenseMapInfo<StructType*> >
  255. NumeredTypesMapTy;
  256. /// getTypeByName - Return the type with the specified name, or null if there
  257. /// is none by that name.
  258. StructType *getTypeByName(StringRef Name) const;
  259. /// @}
  260. /// @name Function Accessors
  261. /// @{
  262. /// getOrInsertFunction - Look up the specified function in the module symbol
  263. /// table. Four possibilities:
  264. /// 1. If it does not exist, add a prototype for the function and return it.
  265. /// 2. If it exists, and has a local linkage, the existing function is
  266. /// renamed and a new one is inserted.
  267. /// 3. Otherwise, if the existing function has the correct prototype, return
  268. /// the existing function.
  269. /// 4. Finally, the function exists but has the wrong prototype: return the
  270. /// function with a constantexpr cast to the right prototype.
  271. Constant *getOrInsertFunction(StringRef Name, FunctionType *T,
  272. AttrListPtr AttributeList);
  273. Constant *getOrInsertFunction(StringRef Name, FunctionType *T);
  274. /// getOrInsertFunction - Look up the specified function in the module symbol
  275. /// table. If it does not exist, add a prototype for the function and return
  276. /// it. This function guarantees to return a constant of pointer to the
  277. /// specified function type or a ConstantExpr BitCast of that type if the
  278. /// named function has a different type. This version of the method takes a
  279. /// null terminated list of function arguments, which makes it easier for
  280. /// clients to use.
  281. Constant *getOrInsertFunction(StringRef Name,
  282. AttrListPtr AttributeList,
  283. Type *RetTy, ...) END_WITH_NULL;
  284. /// getOrInsertFunction - Same as above, but without the attributes.
  285. Constant *getOrInsertFunction(StringRef Name, Type *RetTy, ...)
  286. END_WITH_NULL;
  287. Constant *getOrInsertTargetIntrinsic(StringRef Name,
  288. FunctionType *Ty,
  289. AttrListPtr AttributeList);
  290. /// getFunction - Look up the specified function in the module symbol table.
  291. /// If it does not exist, return null.
  292. Function *getFunction(StringRef Name) const;
  293. /// @}
  294. /// @name Global Variable Accessors
  295. /// @{
  296. /// getGlobalVariable - Look up the specified global variable in the module
  297. /// symbol table. If it does not exist, return null. If AllowInternal is set
  298. /// to true, this function will return types that have InternalLinkage. By
  299. /// default, these types are not returned.
  300. GlobalVariable *getGlobalVariable(StringRef Name,
  301. bool AllowInternal = false) const;
  302. /// getNamedGlobal - Return the global variable in the module with the
  303. /// specified name, of arbitrary type. This method returns null if a global
  304. /// with the specified name is not found.
  305. GlobalVariable *getNamedGlobal(StringRef Name) const {
  306. return getGlobalVariable(Name, true);
  307. }
  308. /// getOrInsertGlobal - Look up the specified global in the module symbol
  309. /// table.
  310. /// 1. If it does not exist, add a declaration of the global and return it.
  311. /// 2. Else, the global exists but has the wrong type: return the function
  312. /// with a constantexpr cast to the right type.
  313. /// 3. Finally, if the existing global is the correct declaration, return
  314. /// the existing global.
  315. Constant *getOrInsertGlobal(StringRef Name, Type *Ty);
  316. /// @}
  317. /// @name Global Alias Accessors
  318. /// @{
  319. /// getNamedAlias - Return the global alias in the module with the
  320. /// specified name, of arbitrary type. This method returns null if a global
  321. /// with the specified name is not found.
  322. GlobalAlias *getNamedAlias(StringRef Name) const;
  323. /// @}
  324. /// @name Named Metadata Accessors
  325. /// @{
  326. /// getNamedMetadata - Return the NamedMDNode in the module with the
  327. /// specified name. This method returns null if a NamedMDNode with the
  328. /// specified name is not found.
  329. NamedMDNode *getNamedMetadata(const Twine &Name) const;
  330. /// getOrInsertNamedMetadata - Return the named MDNode in the module
  331. /// with the specified name. This method returns a new NamedMDNode if a
  332. /// NamedMDNode with the specified name is not found.
  333. NamedMDNode *getOrInsertNamedMetadata(StringRef Name);
  334. /// eraseNamedMetadata - Remove the given NamedMDNode from this module
  335. /// and delete it.
  336. void eraseNamedMetadata(NamedMDNode *NMD);
  337. /// @}
  338. /// @name Module Flags Accessors
  339. /// @{
  340. /// getModuleFlagsMetadata - Returns the module flags in the provided vector.
  341. void getModuleFlagsMetadata(SmallVectorImpl<ModuleFlagEntry> &Flags) const;
  342. /// getModuleFlagsMetadata - Returns the NamedMDNode in the module that
  343. /// represents module-level flags. This method returns null if there are no
  344. /// module-level flags.
  345. NamedMDNode *getModuleFlagsMetadata() const;
  346. /// getOrInsertModuleFlagsMetadata - Returns the NamedMDNode in the module
  347. /// that represents module-level flags. If module-level flags aren't found,
  348. /// it creates the named metadata that contains them.
  349. NamedMDNode *getOrInsertModuleFlagsMetadata();
  350. /// addModuleFlag - Add a module-level flag to the module-level flags
  351. /// metadata. It will create the module-level flags named metadata if it
  352. /// doesn't already exist.
  353. void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, Value *Val);
  354. void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, uint32_t Val);
  355. void addModuleFlag(MDNode *Node);
  356. /// @}
  357. /// @name Materialization
  358. /// @{
  359. /// setMaterializer - Sets the GVMaterializer to GVM. This module must not
  360. /// yet have a Materializer. To reset the materializer for a module that
  361. /// already has one, call MaterializeAllPermanently first. Destroying this
  362. /// module will destroy its materializer without materializing any more
  363. /// GlobalValues. Without destroying the Module, there is no way to detach or
  364. /// destroy a materializer without materializing all the GVs it controls, to
  365. /// avoid leaving orphan unmaterialized GVs.
  366. void setMaterializer(GVMaterializer *GVM);
  367. /// getMaterializer - Retrieves the GVMaterializer, if any, for this Module.
  368. GVMaterializer *getMaterializer() const { return Materializer.get(); }
  369. /// isMaterializable - True if the definition of GV has yet to be materialized
  370. /// from the GVMaterializer.
  371. bool isMaterializable(const GlobalValue *GV) const;
  372. /// isDematerializable - Returns true if this GV was loaded from this Module's
  373. /// GVMaterializer and the GVMaterializer knows how to dematerialize the GV.
  374. bool isDematerializable(const GlobalValue *GV) const;
  375. /// Materialize - Make sure the GlobalValue is fully read. If the module is
  376. /// corrupt, this returns true and fills in the optional string with
  377. /// information about the problem. If successful, this returns false.
  378. bool Materialize(GlobalValue *GV, std::string *ErrInfo = 0);
  379. /// Dematerialize - If the GlobalValue is read in, and if the GVMaterializer
  380. /// supports it, release the memory for the function, and set it up to be
  381. /// materialized lazily. If !isDematerializable(), this method is a noop.
  382. void Dematerialize(GlobalValue *GV);
  383. /// MaterializeAll - Make sure all GlobalValues in this Module are fully read.
  384. /// If the module is corrupt, this returns true and fills in the optional
  385. /// string with information about the problem. If successful, this returns
  386. /// false.
  387. bool MaterializeAll(std::string *ErrInfo = 0);
  388. /// MaterializeAllPermanently - Make sure all GlobalValues in this Module are
  389. /// fully read and clear the Materializer. If the module is corrupt, this
  390. /// returns true, fills in the optional string with information about the
  391. /// problem, and DOES NOT clear the old Materializer. If successful, this
  392. /// returns false.
  393. bool MaterializeAllPermanently(std::string *ErrInfo = 0);
  394. /// @}
  395. /// @name Direct access to the globals list, functions list, and symbol table
  396. /// @{
  397. /// Get the Module's list of global variables (constant).
  398. const GlobalListType &getGlobalList() const { return GlobalList; }
  399. /// Get the Module's list of global variables.
  400. GlobalListType &getGlobalList() { return GlobalList; }
  401. static iplist<GlobalVariable> Module::*getSublistAccess(GlobalVariable*) {
  402. return &Module::GlobalList;
  403. }
  404. /// Get the Module's list of functions (constant).
  405. const FunctionListType &getFunctionList() const { return FunctionList; }
  406. /// Get the Module's list of functions.
  407. FunctionListType &getFunctionList() { return FunctionList; }
  408. static iplist<Function> Module::*getSublistAccess(Function*) {
  409. return &Module::FunctionList;
  410. }
  411. /// Get the Module's list of aliases (constant).
  412. const AliasListType &getAliasList() const { return AliasList; }
  413. /// Get the Module's list of aliases.
  414. AliasListType &getAliasList() { return AliasList; }
  415. static iplist<GlobalAlias> Module::*getSublistAccess(GlobalAlias*) {
  416. return &Module::AliasList;
  417. }
  418. /// Get the Module's list of named metadata (constant).
  419. const NamedMDListType &getNamedMDList() const { return NamedMDList; }
  420. /// Get the Module's list of named metadata.
  421. NamedMDListType &getNamedMDList() { return NamedMDList; }
  422. static ilist<NamedMDNode> Module::*getSublistAccess(NamedMDNode*) {
  423. return &Module::NamedMDList;
  424. }
  425. /// Get the symbol table of global variable and function identifiers
  426. const ValueSymbolTable &getValueSymbolTable() const { return *ValSymTab; }
  427. /// Get the Module's symbol table of global variable and function identifiers.
  428. ValueSymbolTable &getValueSymbolTable() { return *ValSymTab; }
  429. /// @}
  430. /// @name Global Variable Iteration
  431. /// @{
  432. global_iterator global_begin() { return GlobalList.begin(); }
  433. const_global_iterator global_begin() const { return GlobalList.begin(); }
  434. global_iterator global_end () { return GlobalList.end(); }
  435. const_global_iterator global_end () const { return GlobalList.end(); }
  436. bool global_empty() const { return GlobalList.empty(); }
  437. /// @}
  438. /// @name Function Iteration
  439. /// @{
  440. iterator begin() { return FunctionList.begin(); }
  441. const_iterator begin() const { return FunctionList.begin(); }
  442. iterator end () { return FunctionList.end(); }
  443. const_iterator end () const { return FunctionList.end(); }
  444. size_t size() const { return FunctionList.size(); }
  445. bool empty() const { return FunctionList.empty(); }
  446. /// @}
  447. /// @name Dependent Library Iteration
  448. /// @{
  449. /// @brief Get a constant iterator to beginning of dependent library list.
  450. inline lib_iterator lib_begin() const { return LibraryList.begin(); }
  451. /// @brief Get a constant iterator to end of dependent library list.
  452. inline lib_iterator lib_end() const { return LibraryList.end(); }
  453. /// @brief Returns the number of items in the list of libraries.
  454. inline size_t lib_size() const { return LibraryList.size(); }
  455. /// @brief Add a library to the list of dependent libraries
  456. void addLibrary(StringRef Lib);
  457. /// @brief Remove a library from the list of dependent libraries
  458. void removeLibrary(StringRef Lib);
  459. /// @brief Get all the libraries
  460. inline const LibraryListType& getLibraries() const { return LibraryList; }
  461. /// @}
  462. /// @name Alias Iteration
  463. /// @{
  464. alias_iterator alias_begin() { return AliasList.begin(); }
  465. const_alias_iterator alias_begin() const { return AliasList.begin(); }
  466. alias_iterator alias_end () { return AliasList.end(); }
  467. const_alias_iterator alias_end () const { return AliasList.end(); }
  468. size_t alias_size () const { return AliasList.size(); }
  469. bool alias_empty() const { return AliasList.empty(); }
  470. /// @}
  471. /// @name Named Metadata Iteration
  472. /// @{
  473. named_metadata_iterator named_metadata_begin() { return NamedMDList.begin(); }
  474. const_named_metadata_iterator named_metadata_begin() const {
  475. return NamedMDList.begin();
  476. }
  477. named_metadata_iterator named_metadata_end() { return NamedMDList.end(); }
  478. const_named_metadata_iterator named_metadata_end() const {
  479. return NamedMDList.end();
  480. }
  481. size_t named_metadata_size() const { return NamedMDList.size(); }
  482. bool named_metadata_empty() const { return NamedMDList.empty(); }
  483. /// @}
  484. /// @name Utility functions for printing and dumping Module objects
  485. /// @{
  486. /// Print the module to an output stream with an optional
  487. /// AssemblyAnnotationWriter.
  488. void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW) const;
  489. /// Dump the module to stderr (for debugging).
  490. void dump() const;
  491. /// This function causes all the subinstructions to "let go" of all references
  492. /// that they are maintaining. This allows one to 'delete' a whole class at
  493. /// a time, even though there may be circular references... first all
  494. /// references are dropped, and all use counts go to zero. Then everything
  495. /// is delete'd for real. Note that no operations are valid on an object
  496. /// that has "dropped all references", except operator delete.
  497. void dropAllReferences();
  498. /// @}
  499. };
  500. /// An raw_ostream inserter for modules.
  501. inline raw_ostream &operator<<(raw_ostream &O, const Module &M) {
  502. M.print(O, 0);
  503. return O;
  504. }
  505. } // End llvm namespace
  506. #endif