LLVM API Documentation

Module.h
Go to the documentation of this file.
00001 //===-- llvm/Module.h - C++ class to represent a VM module ------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 /// @file
00011 /// Module.h This file contains the declarations for the Module class.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef LLVM_IR_MODULE_H
00016 #define LLVM_IR_MODULE_H
00017 
00018 #include "llvm/ADT/OwningPtr.h"
00019 #include "llvm/IR/Function.h"
00020 #include "llvm/IR/GlobalAlias.h"
00021 #include "llvm/IR/GlobalVariable.h"
00022 #include "llvm/IR/Metadata.h"
00023 #include "llvm/Support/CBindingWrapping.h"
00024 #include "llvm/Support/DataTypes.h"
00025 
00026 namespace llvm {
00027 
00028 class FunctionType;
00029 class GVMaterializer;
00030 class LLVMContext;
00031 class StructType;
00032 template<typename T> struct DenseMapInfo;
00033 template<typename KeyT, typename ValueT, typename KeyInfoT> class DenseMap;
00034 
00035 template<> struct ilist_traits<Function>
00036   : public SymbolTableListTraits<Function, Module> {
00037 
00038   // createSentinel is used to get hold of the node that marks the end of the
00039   // list... (same trick used here as in ilist_traits<Instruction>)
00040   Function *createSentinel() const {
00041     return static_cast<Function*>(&Sentinel);
00042   }
00043   static void destroySentinel(Function*) {}
00044 
00045   Function *provideInitialHead() const { return createSentinel(); }
00046   Function *ensureHead(Function*) const { return createSentinel(); }
00047   static void noteHead(Function*, Function*) {}
00048 
00049 private:
00050   mutable ilist_node<Function> Sentinel;
00051 };
00052 
00053 template<> struct ilist_traits<GlobalVariable>
00054   : public SymbolTableListTraits<GlobalVariable, Module> {
00055   // createSentinel is used to create a node that marks the end of the list.
00056   GlobalVariable *createSentinel() const {
00057     return static_cast<GlobalVariable*>(&Sentinel);
00058   }
00059   static void destroySentinel(GlobalVariable*) {}
00060 
00061   GlobalVariable *provideInitialHead() const { return createSentinel(); }
00062   GlobalVariable *ensureHead(GlobalVariable*) const { return createSentinel(); }
00063   static void noteHead(GlobalVariable*, GlobalVariable*) {}
00064 private:
00065   mutable ilist_node<GlobalVariable> Sentinel;
00066 };
00067 
00068 template<> struct ilist_traits<GlobalAlias>
00069   : public SymbolTableListTraits<GlobalAlias, Module> {
00070   // createSentinel is used to create a node that marks the end of the list.
00071   GlobalAlias *createSentinel() const {
00072     return static_cast<GlobalAlias*>(&Sentinel);
00073   }
00074   static void destroySentinel(GlobalAlias*) {}
00075 
00076   GlobalAlias *provideInitialHead() const { return createSentinel(); }
00077   GlobalAlias *ensureHead(GlobalAlias*) const { return createSentinel(); }
00078   static void noteHead(GlobalAlias*, GlobalAlias*) {}
00079 private:
00080   mutable ilist_node<GlobalAlias> Sentinel;
00081 };
00082 
00083 template<> struct ilist_traits<NamedMDNode>
00084   : public ilist_default_traits<NamedMDNode> {
00085   // createSentinel is used to get hold of a node that marks the end of
00086   // the list...
00087   NamedMDNode *createSentinel() const {
00088     return static_cast<NamedMDNode*>(&Sentinel);
00089   }
00090   static void destroySentinel(NamedMDNode*) {}
00091 
00092   NamedMDNode *provideInitialHead() const { return createSentinel(); }
00093   NamedMDNode *ensureHead(NamedMDNode*) const { return createSentinel(); }
00094   static void noteHead(NamedMDNode*, NamedMDNode*) {}
00095   void addNodeToList(NamedMDNode *) {}
00096   void removeNodeFromList(NamedMDNode *) {}
00097 private:
00098   mutable ilist_node<NamedMDNode> Sentinel;
00099 };
00100 
00101 /// A Module instance is used to store all the information related to an
00102 /// LLVM module. Modules are the top level container of all other LLVM
00103 /// Intermediate Representation (IR) objects. Each module directly contains a
00104 /// list of globals variables, a list of functions, a list of libraries (or
00105 /// other modules) this module depends on, a symbol table, and various data
00106 /// about the target's characteristics.
00107 ///
00108 /// A module maintains a GlobalValRefMap object that is used to hold all
00109 /// constant references to global variables in the module.  When a global
00110 /// variable is destroyed, it should have no entries in the GlobalValueRefMap.
00111 /// @brief The main container class for the LLVM Intermediate Representation.
00112 class Module {
00113 /// @name Types And Enumerations
00114 /// @{
00115 public:
00116   /// The type for the list of global variables.
00117   typedef iplist<GlobalVariable> GlobalListType;
00118   /// The type for the list of functions.
00119   typedef iplist<Function> FunctionListType;
00120   /// The type for the list of aliases.
00121   typedef iplist<GlobalAlias> AliasListType;
00122   /// The type for the list of named metadata.
00123   typedef ilist<NamedMDNode> NamedMDListType;
00124 
00125   /// The Global Variable iterator.
00126   typedef GlobalListType::iterator                      global_iterator;
00127   /// The Global Variable constant iterator.
00128   typedef GlobalListType::const_iterator          const_global_iterator;
00129 
00130   /// The Function iterators.
00131   typedef FunctionListType::iterator                           iterator;
00132   /// The Function constant iterator
00133   typedef FunctionListType::const_iterator               const_iterator;
00134 
00135   /// The Global Alias iterators.
00136   typedef AliasListType::iterator                        alias_iterator;
00137   /// The Global Alias constant iterator
00138   typedef AliasListType::const_iterator            const_alias_iterator;
00139 
00140   /// The named metadata iterators.
00141   typedef NamedMDListType::iterator             named_metadata_iterator;
00142   /// The named metadata constant interators.
00143   typedef NamedMDListType::const_iterator const_named_metadata_iterator;
00144 
00145   /// An enumeration for describing the endianess of the target machine.
00146   enum Endianness  { AnyEndianness, LittleEndian, BigEndian };
00147 
00148   /// An enumeration for describing the size of a pointer on the target machine.
00149   enum PointerSize { AnyPointerSize, Pointer32, Pointer64 };
00150 
00151   /// This enumeration defines the supported behaviors of module flags.
00152   enum ModFlagBehavior {
00153     /// Emits an error if two values disagree, otherwise the resulting value is
00154     /// that of the operands.
00155     Error = 1,
00156 
00157     /// Emits a warning if two values disagree. The result value will be the
00158     /// operand for the flag from the first module being linked.
00159     Warning  = 2,
00160 
00161     /// Adds a requirement that another module flag be present and have a
00162     /// specified value after linking is performed. The value must be a metadata
00163     /// pair, where the first element of the pair is the ID of the module flag
00164     /// to be restricted, and the second element of the pair is the value the
00165     /// module flag should be restricted to. This behavior can be used to
00166     /// restrict the allowable results (via triggering of an error) of linking
00167     /// IDs with the **Override** behavior.
00168     Require = 3,
00169 
00170     /// Uses the specified value, regardless of the behavior or value of the
00171     /// other module. If both modules specify **Override**, but the values
00172     /// differ, an error will be emitted.
00173     Override = 4,
00174 
00175     /// Appends the two values, which are required to be metadata nodes.
00176     Append = 5,
00177 
00178     /// Appends the two values, which are required to be metadata
00179     /// nodes. However, duplicate entries in the second list are dropped
00180     /// during the append operation.
00181     AppendUnique = 6
00182   };
00183 
00184   struct ModuleFlagEntry {
00185     ModFlagBehavior Behavior;
00186     MDString *Key;
00187     Value *Val;
00188     ModuleFlagEntry(ModFlagBehavior B, MDString *K, Value *V)
00189       : Behavior(B), Key(K), Val(V) {}
00190   };
00191 
00192 /// @}
00193 /// @name Member Variables
00194 /// @{
00195 private:
00196   LLVMContext &Context;           ///< The LLVMContext from which types and
00197                                   ///< constants are allocated.
00198   GlobalListType GlobalList;      ///< The Global Variables in the module
00199   FunctionListType FunctionList;  ///< The Functions in the module
00200   AliasListType AliasList;        ///< The Aliases in the module
00201   NamedMDListType NamedMDList;    ///< The named metadata in the module
00202   std::string GlobalScopeAsm;     ///< Inline Asm at global scope.
00203   ValueSymbolTable *ValSymTab;    ///< Symbol table for values
00204   OwningPtr<GVMaterializer> Materializer;  ///< Used to materialize GlobalValues
00205   std::string ModuleID;           ///< Human readable identifier for the module
00206   std::string TargetTriple;       ///< Platform target triple Module compiled on
00207   std::string DataLayout;         ///< Target data description
00208   void *NamedMDSymTab;            ///< NamedMDNode names.
00209 
00210   friend class Constant;
00211 
00212 /// @}
00213 /// @name Constructors
00214 /// @{
00215 public:
00216   /// The Module constructor. Note that there is no default constructor. You
00217   /// must provide a name for the module upon construction.
00218   explicit Module(StringRef ModuleID, LLVMContext& C);
00219   /// The module destructor. This will dropAllReferences.
00220   ~Module();
00221 
00222 /// @}
00223 /// @name Module Level Accessors
00224 /// @{
00225 
00226   /// Get the module identifier which is, essentially, the name of the module.
00227   /// @returns the module identifier as a string
00228   const std::string &getModuleIdentifier() const { return ModuleID; }
00229 
00230   /// Get the data layout string for the module's target platform.  This encodes
00231   /// the type sizes and alignments expected by this module.
00232   /// @returns the data layout as a string
00233   const std::string &getDataLayout() const { return DataLayout; }
00234 
00235   /// Get the target triple which is a string describing the target host.
00236   /// @returns a string containing the target triple.
00237   const std::string &getTargetTriple() const { return TargetTriple; }
00238 
00239   /// Get the target endian information.
00240   /// @returns Endianess - an enumeration for the endianess of the target
00241   Endianness getEndianness() const;
00242 
00243   /// Get the target pointer size.
00244   /// @returns PointerSize - an enumeration for the size of the target's pointer
00245   PointerSize getPointerSize() const;
00246 
00247   /// Get the global data context.
00248   /// @returns LLVMContext - a container for LLVM's global information
00249   LLVMContext &getContext() const { return Context; }
00250 
00251   /// Get any module-scope inline assembly blocks.
00252   /// @returns a string containing the module-scope inline assembly blocks.
00253   const std::string &getModuleInlineAsm() const { return GlobalScopeAsm; }
00254 
00255 /// @}
00256 /// @name Module Level Mutators
00257 /// @{
00258 
00259   /// Set the module identifier.
00260   void setModuleIdentifier(StringRef ID) { ModuleID = ID; }
00261 
00262   /// Set the data layout
00263   void setDataLayout(StringRef DL) { DataLayout = DL; }
00264 
00265   /// Set the target triple.
00266   void setTargetTriple(StringRef T) { TargetTriple = T; }
00267 
00268   /// Set the module-scope inline assembly blocks.
00269   void setModuleInlineAsm(StringRef Asm) {
00270     GlobalScopeAsm = Asm;
00271     if (!GlobalScopeAsm.empty() &&
00272         GlobalScopeAsm[GlobalScopeAsm.size()-1] != '\n')
00273       GlobalScopeAsm += '\n';
00274   }
00275 
00276   /// Append to the module-scope inline assembly blocks, automatically inserting
00277   /// a separating newline if necessary.
00278   void appendModuleInlineAsm(StringRef Asm) {
00279     GlobalScopeAsm += Asm;
00280     if (!GlobalScopeAsm.empty() &&
00281         GlobalScopeAsm[GlobalScopeAsm.size()-1] != '\n')
00282       GlobalScopeAsm += '\n';
00283   }
00284 
00285 /// @}
00286 /// @name Generic Value Accessors
00287 /// @{
00288 
00289   /// getNamedValue - Return the global value in the module with
00290   /// the specified name, of arbitrary type.  This method returns null
00291   /// if a global with the specified name is not found.
00292   GlobalValue *getNamedValue(StringRef Name) const;
00293 
00294   /// getMDKindID - Return a unique non-zero ID for the specified metadata kind.
00295   /// This ID is uniqued across modules in the current LLVMContext.
00296   unsigned getMDKindID(StringRef Name) const;
00297 
00298   /// getMDKindNames - Populate client supplied SmallVector with the name for
00299   /// custom metadata IDs registered in this LLVMContext.
00300   void getMDKindNames(SmallVectorImpl<StringRef> &Result) const;
00301 
00302   
00303   typedef DenseMap<StructType*, unsigned, DenseMapInfo<StructType*> >
00304                    NumeredTypesMapTy;
00305 
00306   /// getTypeByName - Return the type with the specified name, or null if there
00307   /// is none by that name.
00308   StructType *getTypeByName(StringRef Name) const;
00309 
00310 /// @}
00311 /// @name Function Accessors
00312 /// @{
00313 
00314   /// getOrInsertFunction - Look up the specified function in the module symbol
00315   /// table.  Four possibilities:
00316   ///   1. If it does not exist, add a prototype for the function and return it.
00317   ///   2. If it exists, and has a local linkage, the existing function is
00318   ///      renamed and a new one is inserted.
00319   ///   3. Otherwise, if the existing function has the correct prototype, return
00320   ///      the existing function.
00321   ///   4. Finally, the function exists but has the wrong prototype: return the
00322   ///      function with a constantexpr cast to the right prototype.
00323   Constant *getOrInsertFunction(StringRef Name, FunctionType *T,
00324                                 AttributeSet AttributeList);
00325 
00326   Constant *getOrInsertFunction(StringRef Name, FunctionType *T);
00327 
00328   /// getOrInsertFunction - Look up the specified function in the module symbol
00329   /// table.  If it does not exist, add a prototype for the function and return
00330   /// it.  This function guarantees to return a constant of pointer to the
00331   /// specified function type or a ConstantExpr BitCast of that type if the
00332   /// named function has a different type.  This version of the method takes a
00333   /// null terminated list of function arguments, which makes it easier for
00334   /// clients to use.
00335   Constant *getOrInsertFunction(StringRef Name,
00336                                 AttributeSet AttributeList,
00337                                 Type *RetTy, ...)  END_WITH_NULL;
00338 
00339   /// getOrInsertFunction - Same as above, but without the attributes.
00340   Constant *getOrInsertFunction(StringRef Name, Type *RetTy, ...)
00341     END_WITH_NULL;
00342 
00343   /// getFunction - Look up the specified function in the module symbol table.
00344   /// If it does not exist, return null.
00345   Function *getFunction(StringRef Name) const;
00346 
00347 /// @}
00348 /// @name Global Variable Accessors
00349 /// @{
00350 
00351   /// getGlobalVariable - Look up the specified global variable in the module
00352   /// symbol table.  If it does not exist, return null. If AllowInternal is set
00353   /// to true, this function will return types that have InternalLinkage. By
00354   /// default, these types are not returned.
00355   GlobalVariable *getGlobalVariable(StringRef Name,
00356                                     bool AllowInternal = false) const;
00357 
00358   /// getNamedGlobal - Return the global variable in the module with the
00359   /// specified name, of arbitrary type.  This method returns null if a global
00360   /// with the specified name is not found.
00361   GlobalVariable *getNamedGlobal(StringRef Name) const {
00362     return getGlobalVariable(Name, true);
00363   }
00364 
00365   /// getOrInsertGlobal - Look up the specified global in the module symbol
00366   /// table.
00367   ///   1. If it does not exist, add a declaration of the global and return it.
00368   ///   2. Else, the global exists but has the wrong type: return the function
00369   ///      with a constantexpr cast to the right type.
00370   ///   3. Finally, if the existing global is the correct declaration, return
00371   ///      the existing global.
00372   Constant *getOrInsertGlobal(StringRef Name, Type *Ty);
00373 
00374 /// @}
00375 /// @name Global Alias Accessors
00376 /// @{
00377 
00378   /// getNamedAlias - Return the global alias in the module with the
00379   /// specified name, of arbitrary type.  This method returns null if a global
00380   /// with the specified name is not found.
00381   GlobalAlias *getNamedAlias(StringRef Name) const;
00382 
00383 /// @}
00384 /// @name Named Metadata Accessors
00385 /// @{
00386 
00387   /// getNamedMetadata - Return the NamedMDNode in the module with the
00388   /// specified name. This method returns null if a NamedMDNode with the
00389   /// specified name is not found.
00390   NamedMDNode *getNamedMetadata(const Twine &Name) const;
00391 
00392   /// getOrInsertNamedMetadata - Return the named MDNode in the module
00393   /// with the specified name. This method returns a new NamedMDNode if a
00394   /// NamedMDNode with the specified name is not found.
00395   NamedMDNode *getOrInsertNamedMetadata(StringRef Name);
00396 
00397   /// eraseNamedMetadata - Remove the given NamedMDNode from this module
00398   /// and delete it.
00399   void eraseNamedMetadata(NamedMDNode *NMD);
00400 
00401 /// @}
00402 /// @name Module Flags Accessors
00403 /// @{
00404 
00405   /// getModuleFlagsMetadata - Returns the module flags in the provided vector.
00406   void getModuleFlagsMetadata(SmallVectorImpl<ModuleFlagEntry> &Flags) const;
00407 
00408   /// getModuleFlagsMetadata - Returns the NamedMDNode in the module that
00409   /// represents module-level flags. This method returns null if there are no
00410   /// module-level flags.
00411   NamedMDNode *getModuleFlagsMetadata() const;
00412 
00413   /// getOrInsertModuleFlagsMetadata - Returns the NamedMDNode in the module
00414   /// that represents module-level flags. If module-level flags aren't found,
00415   /// it creates the named metadata that contains them.
00416   NamedMDNode *getOrInsertModuleFlagsMetadata();
00417 
00418   /// addModuleFlag - Add a module-level flag to the module-level flags
00419   /// metadata. It will create the module-level flags named metadata if it
00420   /// doesn't already exist.
00421   void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, Value *Val);
00422   void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, uint32_t Val);
00423   void addModuleFlag(MDNode *Node);
00424 
00425 /// @}
00426 /// @name Materialization
00427 /// @{
00428 
00429   /// setMaterializer - Sets the GVMaterializer to GVM.  This module must not
00430   /// yet have a Materializer.  To reset the materializer for a module that
00431   /// already has one, call MaterializeAllPermanently first.  Destroying this
00432   /// module will destroy its materializer without materializing any more
00433   /// GlobalValues.  Without destroying the Module, there is no way to detach or
00434   /// destroy a materializer without materializing all the GVs it controls, to
00435   /// avoid leaving orphan unmaterialized GVs.
00436   void setMaterializer(GVMaterializer *GVM);
00437   /// getMaterializer - Retrieves the GVMaterializer, if any, for this Module.
00438   GVMaterializer *getMaterializer() const { return Materializer.get(); }
00439 
00440   /// isMaterializable - True if the definition of GV has yet to be materialized
00441   /// from the GVMaterializer.
00442   bool isMaterializable(const GlobalValue *GV) const;
00443   /// isDematerializable - Returns true if this GV was loaded from this Module's
00444   /// GVMaterializer and the GVMaterializer knows how to dematerialize the GV.
00445   bool isDematerializable(const GlobalValue *GV) const;
00446 
00447   /// Materialize - Make sure the GlobalValue is fully read.  If the module is
00448   /// corrupt, this returns true and fills in the optional string with
00449   /// information about the problem.  If successful, this returns false.
00450   bool Materialize(GlobalValue *GV, std::string *ErrInfo = 0);
00451   /// Dematerialize - If the GlobalValue is read in, and if the GVMaterializer
00452   /// supports it, release the memory for the function, and set it up to be
00453   /// materialized lazily.  If !isDematerializable(), this method is a noop.
00454   void Dematerialize(GlobalValue *GV);
00455 
00456   /// MaterializeAll - Make sure all GlobalValues in this Module are fully read.
00457   /// If the module is corrupt, this returns true and fills in the optional
00458   /// string with information about the problem.  If successful, this returns
00459   /// false.
00460   bool MaterializeAll(std::string *ErrInfo = 0);
00461 
00462   /// MaterializeAllPermanently - Make sure all GlobalValues in this Module are
00463   /// fully read and clear the Materializer.  If the module is corrupt, this
00464   /// returns true, fills in the optional string with information about the
00465   /// problem, and DOES NOT clear the old Materializer.  If successful, this
00466   /// returns false.
00467   bool MaterializeAllPermanently(std::string *ErrInfo = 0);
00468 
00469 /// @}
00470 /// @name Direct access to the globals list, functions list, and symbol table
00471 /// @{
00472 
00473   /// Get the Module's list of global variables (constant).
00474   const GlobalListType   &getGlobalList() const       { return GlobalList; }
00475   /// Get the Module's list of global variables.
00476   GlobalListType         &getGlobalList()             { return GlobalList; }
00477   static iplist<GlobalVariable> Module::*getSublistAccess(GlobalVariable*) {
00478     return &Module::GlobalList;
00479   }
00480   /// Get the Module's list of functions (constant).
00481   const FunctionListType &getFunctionList() const     { return FunctionList; }
00482   /// Get the Module's list of functions.
00483   FunctionListType       &getFunctionList()           { return FunctionList; }
00484   static iplist<Function> Module::*getSublistAccess(Function*) {
00485     return &Module::FunctionList;
00486   }
00487   /// Get the Module's list of aliases (constant).
00488   const AliasListType    &getAliasList() const        { return AliasList; }
00489   /// Get the Module's list of aliases.
00490   AliasListType          &getAliasList()              { return AliasList; }
00491   static iplist<GlobalAlias> Module::*getSublistAccess(GlobalAlias*) {
00492     return &Module::AliasList;
00493   }
00494   /// Get the Module's list of named metadata (constant).
00495   const NamedMDListType  &getNamedMDList() const      { return NamedMDList; }
00496   /// Get the Module's list of named metadata.
00497   NamedMDListType        &getNamedMDList()            { return NamedMDList; }
00498   static ilist<NamedMDNode> Module::*getSublistAccess(NamedMDNode*) {
00499     return &Module::NamedMDList;
00500   }
00501   /// Get the symbol table of global variable and function identifiers
00502   const ValueSymbolTable &getValueSymbolTable() const { return *ValSymTab; }
00503   /// Get the Module's symbol table of global variable and function identifiers.
00504   ValueSymbolTable       &getValueSymbolTable()       { return *ValSymTab; }
00505 
00506 /// @}
00507 /// @name Global Variable Iteration
00508 /// @{
00509 
00510   global_iterator       global_begin()       { return GlobalList.begin(); }
00511   const_global_iterator global_begin() const { return GlobalList.begin(); }
00512   global_iterator       global_end  ()       { return GlobalList.end(); }
00513   const_global_iterator global_end  () const { return GlobalList.end(); }
00514   bool                  global_empty() const { return GlobalList.empty(); }
00515 
00516 /// @}
00517 /// @name Function Iteration
00518 /// @{
00519 
00520   iterator                begin()       { return FunctionList.begin(); }
00521   const_iterator          begin() const { return FunctionList.begin(); }
00522   iterator                end  ()       { return FunctionList.end();   }
00523   const_iterator          end  () const { return FunctionList.end();   }
00524   size_t                  size() const  { return FunctionList.size(); }
00525   bool                    empty() const { return FunctionList.empty(); }
00526 
00527 /// @}
00528 /// @name Alias Iteration
00529 /// @{
00530 
00531   alias_iterator       alias_begin()            { return AliasList.begin(); }
00532   const_alias_iterator alias_begin() const      { return AliasList.begin(); }
00533   alias_iterator       alias_end  ()            { return AliasList.end();   }
00534   const_alias_iterator alias_end  () const      { return AliasList.end();   }
00535   size_t               alias_size () const      { return AliasList.size();  }
00536   bool                 alias_empty() const      { return AliasList.empty(); }
00537 
00538 
00539 /// @}
00540 /// @name Named Metadata Iteration
00541 /// @{
00542 
00543   named_metadata_iterator named_metadata_begin() { return NamedMDList.begin(); }
00544   const_named_metadata_iterator named_metadata_begin() const {
00545     return NamedMDList.begin();
00546   }
00547 
00548   named_metadata_iterator named_metadata_end() { return NamedMDList.end(); }
00549   const_named_metadata_iterator named_metadata_end() const {
00550     return NamedMDList.end();
00551   }
00552 
00553   size_t named_metadata_size() const { return NamedMDList.size();  }
00554   bool named_metadata_empty() const { return NamedMDList.empty(); }
00555 
00556 
00557 /// @}
00558 /// @name Utility functions for printing and dumping Module objects
00559 /// @{
00560 
00561   /// Print the module to an output stream with an optional
00562   /// AssemblyAnnotationWriter.
00563   void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW) const;
00564 
00565   /// Dump the module to stderr (for debugging).
00566   void dump() const;
00567   
00568   /// This function causes all the subinstructions to "let go" of all references
00569   /// that they are maintaining.  This allows one to 'delete' a whole class at
00570   /// a time, even though there may be circular references... first all
00571   /// references are dropped, and all use counts go to zero.  Then everything
00572   /// is delete'd for real.  Note that no operations are valid on an object
00573   /// that has "dropped all references", except operator delete.
00574   void dropAllReferences();
00575 /// @}
00576 };
00577 
00578 /// An raw_ostream inserter for modules.
00579 inline raw_ostream &operator<<(raw_ostream &O, const Module &M) {
00580   M.print(O, 0);
00581   return O;
00582 }
00583 
00584 // Create wrappers for C Binding types (see CBindingWrapping.h).
00585 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef)
00586 
00587 /* LLVMModuleProviderRef exists for historical reasons, but now just holds a
00588  * Module.
00589  */
00590 inline Module *unwrap(LLVMModuleProviderRef MP) {
00591   return reinterpret_cast<Module*>(MP);
00592 }
00593   
00594 } // End llvm namespace
00595 
00596 #endif