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