- /// symbol table. If it does not exist, return null. Note that this only
- /// returns a global variable if it does not have internal linkage. The type
- /// argument should be the underlying type of the global, ie, it should not
- /// have the top-level PointerType, which represents the address of the
- /// global.
- ///
- GlobalVariable *getGlobalVariable(const std::string &Name, const Type *Ty);
-
-
- //===--------------------------------------------------------------------===//
- // Methods for easy access to the types in the module.
- //
-
- /// addTypeName - Insert an entry in the symbol table mapping Str to Type. If
- /// there is already an entry for this name, true is returned and the symbol
- /// table is not modified.
- ///
- bool addTypeName(const std::string &Name, const Type *Ty);
-
- /// getTypeName - If there is at least one entry in the symbol table for the
- /// specified type, return it.
- ///
- std::string getTypeName(const Type *Ty) const;
-
- /// getTypeByName - Return the type with the specified name in this module, or
- /// null if there is none by that name.
- const Type *getTypeByName(const std::string &Name) const;
-
-
- //===--------------------------------------------------------------------===//
- // Methods for direct access to the globals list, functions list, and symbol
- // table.
- //
-
- /// Get the underlying elements of the Module...
- inline const GlobalListType &getGlobalList() const { return GlobalList; }
- inline GlobalListType &getGlobalList() { return GlobalList; }
- inline const FunctionListType &getFunctionList() const { return FunctionList;}
- inline FunctionListType &getFunctionList() { return FunctionList;}
-
- /// getSymbolTable() - Get access to the symbol table for the module, where
- /// global variables and functions are identified.
- ///
- inline SymbolTable &getSymbolTable() { return *SymTab; }
- inline const SymbolTable &getSymbolTable() const { return *SymTab; }
-
-
- //===--------------------------------------------------------------------===//
- // Module iterator forwarding functions
- //
- inline giterator gbegin() { return GlobalList.begin(); }
- inline const_giterator gbegin() const { return GlobalList.begin(); }
- inline giterator gend () { return GlobalList.end(); }
- inline const_giterator gend () const { return GlobalList.end(); }
-
- inline reverse_giterator grbegin() { return GlobalList.rbegin(); }
- inline const_reverse_giterator grbegin() const { return GlobalList.rbegin(); }
- inline reverse_giterator grend () { return GlobalList.rend(); }
- inline const_reverse_giterator grend () const { return GlobalList.rend(); }
-
- inline unsigned gsize() const { return GlobalList.size(); }
- inline bool gempty() const { return GlobalList.empty(); }
- inline const GlobalVariable &gfront() const { return GlobalList.front(); }
- inline GlobalVariable &gfront() { return GlobalList.front(); }
- inline const GlobalVariable &gback() const { return GlobalList.back(); }
- inline GlobalVariable &gback() { return GlobalList.back(); }
-
-
-
- inline iterator begin() { return FunctionList.begin(); }
- inline const_iterator begin() const { return FunctionList.begin(); }
- inline iterator end () { return FunctionList.end(); }
- inline const_iterator end () const { return FunctionList.end(); }
-
- inline reverse_iterator rbegin() { return FunctionList.rbegin(); }
- inline const_reverse_iterator rbegin() const { return FunctionList.rbegin(); }
- inline reverse_iterator rend () { return FunctionList.rend(); }
- inline const_reverse_iterator rend () const { return FunctionList.rend(); }
-
- inline unsigned size() const { return FunctionList.size(); }
- inline bool empty() const { return FunctionList.empty(); }
- inline const Function &front() const { return FunctionList.front(); }
- inline Function &front() { return FunctionList.front(); }
- inline const Function &back() const { return FunctionList.back(); }
- inline Function &back() { return FunctionList.back(); }
-
- void print(std::ostream &OS) const { print(OS, 0); }
- void print(std::ostream &OS, AssemblyAnnotationWriter *AAW) const;
-
+ /// symbol table. If it does not exist, return null. If AllowInternal is set
+ /// to true, this function will return types that have InternalLinkage. By
+ /// default, these types are not returned.
+ GlobalVariable *getGlobalVariable(StringRef Name,
+ bool AllowInternal = false) const;
+
+ /// getNamedGlobal - Return the global variable in the module with the
+ /// specified name, of arbitrary type. This method returns null if a global
+ /// with the specified name is not found.
+ GlobalVariable *getNamedGlobal(StringRef Name) const {
+ return getGlobalVariable(Name, true);
+ }
+
+ /// getOrInsertGlobal - Look up the specified global in the module symbol
+ /// table.
+ /// 1. If it does not exist, add a declaration of the global and return it.
+ /// 2. Else, the global exists but has the wrong type: return the function
+ /// with a constantexpr cast to the right type.
+ /// 3. Finally, if the existing global is the correct declaration, return
+ /// the existing global.
+ Constant *getOrInsertGlobal(StringRef Name, Type *Ty);
+
+/// @}
+/// @name Global Alias Accessors
+/// @{
+
+ /// getNamedAlias - Return the global alias in the module with the
+ /// specified name, of arbitrary type. This method returns null if a global
+ /// with the specified name is not found.
+ GlobalAlias *getNamedAlias(StringRef Name) const;
+
+/// @}
+/// @name Named Metadata Accessors
+/// @{
+
+ /// getNamedMetadata - Return the NamedMDNode in the module with the
+ /// specified name. This method returns null if a NamedMDNode with the
+ /// specified name is not found.
+ NamedMDNode *getNamedMetadata(const Twine &Name) const;
+
+ /// getOrInsertNamedMetadata - Return the named MDNode in the module
+ /// with the specified name. This method returns a new NamedMDNode if a
+ /// NamedMDNode with the specified name is not found.
+ NamedMDNode *getOrInsertNamedMetadata(StringRef Name);
+
+ /// eraseNamedMetadata - Remove the given NamedMDNode from this module
+ /// and delete it.
+ void eraseNamedMetadata(NamedMDNode *NMD);
+
+/// @}
+/// @name Module Flags Accessors
+/// @{
+
+ /// getModuleFlagsMetadata - Returns the module flags in the provided vector.
+ void getModuleFlagsMetadata(SmallVectorImpl<ModuleFlagEntry> &Flags) const;
+
+ /// getModuleFlagsMetadata - Returns the NamedMDNode in the module that
+ /// represents module-level flags. This method returns null if there are no
+ /// module-level flags.
+ NamedMDNode *getModuleFlagsMetadata() const;
+
+ /// getOrInsertModuleFlagsMetadata - Returns the NamedMDNode in the module
+ /// that represents module-level flags. If module-level flags aren't found,
+ /// it creates the named metadata that contains them.
+ NamedMDNode *getOrInsertModuleFlagsMetadata();
+
+ /// addModuleFlag - Add a module-level flag to the module-level flags
+ /// metadata. It will create the module-level flags named metadata if it
+ /// doesn't already exist.
+ void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, Value *Val);
+ void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, uint32_t Val);
+ void addModuleFlag(MDNode *Node);
+
+/// @}
+/// @name Materialization
+/// @{
+
+ /// setMaterializer - Sets the GVMaterializer to GVM. This module must not
+ /// yet have a Materializer. To reset the materializer for a module that
+ /// already has one, call MaterializeAllPermanently first. Destroying this
+ /// module will destroy its materializer without materializing any more
+ /// GlobalValues. Without destroying the Module, there is no way to detach or
+ /// destroy a materializer without materializing all the GVs it controls, to
+ /// avoid leaving orphan unmaterialized GVs.
+ void setMaterializer(GVMaterializer *GVM);
+ /// getMaterializer - Retrieves the GVMaterializer, if any, for this Module.
+ GVMaterializer *getMaterializer() const { return Materializer.get(); }
+
+ /// isMaterializable - True if the definition of GV has yet to be materialized
+ /// from the GVMaterializer.
+ bool isMaterializable(const GlobalValue *GV) const;
+ /// isDematerializable - Returns true if this GV was loaded from this Module's
+ /// GVMaterializer and the GVMaterializer knows how to dematerialize the GV.
+ bool isDematerializable(const GlobalValue *GV) const;
+
+ /// Materialize - Make sure the GlobalValue is fully read. If the module is
+ /// corrupt, this returns true and fills in the optional string with
+ /// information about the problem. If successful, this returns false.
+ bool Materialize(GlobalValue *GV, std::string *ErrInfo = 0);
+ /// Dematerialize - If the GlobalValue is read in, and if the GVMaterializer
+ /// supports it, release the memory for the function, and set it up to be
+ /// materialized lazily. If !isDematerializable(), this method is a noop.
+ void Dematerialize(GlobalValue *GV);
+
+ /// MaterializeAll - Make sure all GlobalValues in this Module are fully read.
+ /// If the module is corrupt, this returns true and fills in the optional
+ /// string with information about the problem. If successful, this returns
+ /// false.
+ bool MaterializeAll(std::string *ErrInfo = 0);
+
+ /// MaterializeAllPermanently - Make sure all GlobalValues in this Module are
+ /// fully read and clear the Materializer. If the module is corrupt, this
+ /// returns true, fills in the optional string with information about the
+ /// problem, and DOES NOT clear the old Materializer. If successful, this
+ /// returns false.
+ bool MaterializeAllPermanently(std::string *ErrInfo = 0);
+
+/// @}
+/// @name Direct access to the globals list, functions list, and symbol table
+/// @{
+
+ /// Get the Module's list of global variables (constant).
+ const GlobalListType &getGlobalList() const { return GlobalList; }
+ /// Get the Module's list of global variables.
+ GlobalListType &getGlobalList() { return GlobalList; }
+ static iplist<GlobalVariable> Module::*getSublistAccess(GlobalVariable*) {
+ return &Module::GlobalList;
+ }
+ /// Get the Module's list of functions (constant).
+ const FunctionListType &getFunctionList() const { return FunctionList; }
+ /// Get the Module's list of functions.
+ FunctionListType &getFunctionList() { return FunctionList; }
+ static iplist<Function> Module::*getSublistAccess(Function*) {
+ return &Module::FunctionList;
+ }
+ /// Get the Module's list of aliases (constant).
+ const AliasListType &getAliasList() const { return AliasList; }
+ /// Get the Module's list of aliases.
+ AliasListType &getAliasList() { return AliasList; }
+ static iplist<GlobalAlias> Module::*getSublistAccess(GlobalAlias*) {
+ return &Module::AliasList;
+ }
+ /// Get the Module's list of named metadata (constant).
+ const NamedMDListType &getNamedMDList() const { return NamedMDList; }
+ /// Get the Module's list of named metadata.
+ NamedMDListType &getNamedMDList() { return NamedMDList; }
+ static ilist<NamedMDNode> Module::*getSublistAccess(NamedMDNode*) {
+ return &Module::NamedMDList;
+ }
+ /// Get the symbol table of global variable and function identifiers
+ const ValueSymbolTable &getValueSymbolTable() const { return *ValSymTab; }
+ /// Get the Module's symbol table of global variable and function identifiers.
+ ValueSymbolTable &getValueSymbolTable() { return *ValSymTab; }
+
+/// @}
+/// @name Global Variable Iteration
+/// @{
+
+ global_iterator global_begin() { return GlobalList.begin(); }
+ const_global_iterator global_begin() const { return GlobalList.begin(); }
+ global_iterator global_end () { return GlobalList.end(); }
+ const_global_iterator global_end () const { return GlobalList.end(); }
+ bool global_empty() const { return GlobalList.empty(); }
+
+/// @}
+/// @name Function Iteration
+/// @{
+
+ iterator begin() { return FunctionList.begin(); }
+ const_iterator begin() const { return FunctionList.begin(); }
+ iterator end () { return FunctionList.end(); }
+ const_iterator end () const { return FunctionList.end(); }
+ size_t size() const { return FunctionList.size(); }
+ bool empty() const { return FunctionList.empty(); }
+
+/// @}
+/// @name Alias Iteration
+/// @{
+
+ alias_iterator alias_begin() { return AliasList.begin(); }
+ const_alias_iterator alias_begin() const { return AliasList.begin(); }
+ alias_iterator alias_end () { return AliasList.end(); }
+ const_alias_iterator alias_end () const { return AliasList.end(); }
+ size_t alias_size () const { return AliasList.size(); }
+ bool alias_empty() const { return AliasList.empty(); }
+
+
+/// @}
+/// @name Named Metadata Iteration
+/// @{
+
+ named_metadata_iterator named_metadata_begin() { return NamedMDList.begin(); }
+ const_named_metadata_iterator named_metadata_begin() const {
+ return NamedMDList.begin();
+ }
+
+ named_metadata_iterator named_metadata_end() { return NamedMDList.end(); }
+ const_named_metadata_iterator named_metadata_end() const {
+ return NamedMDList.end();
+ }
+
+ size_t named_metadata_size() const { return NamedMDList.size(); }
+ bool named_metadata_empty() const { return NamedMDList.empty(); }
+
+
+/// @}
+/// @name Utility functions for printing and dumping Module objects
+/// @{
+
+ /// Print the module to an output stream with an optional
+ /// AssemblyAnnotationWriter.
+ void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW) const;
+
+ /// Dump the module to stderr (for debugging).