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