diff options
Diffstat (limited to 'include/llvm/IR/Module.h')
| -rw-r--r-- | include/llvm/IR/Module.h | 114 |
1 files changed, 30 insertions, 84 deletions
diff --git a/include/llvm/IR/Module.h b/include/llvm/IR/Module.h index 632b27e2d0dd5..79870b9455a6e 100644 --- a/include/llvm/IR/Module.h +++ b/include/llvm/IR/Module.h @@ -26,36 +26,18 @@ #include "llvm/Support/CBindingWrapping.h" #include "llvm/Support/CodeGen.h" #include "llvm/Support/DataTypes.h" -#include <system_error> namespace llvm { template <typename T> class Optional; +class Error; class FunctionType; class GVMaterializer; class LLVMContext; +class MemoryBuffer; class RandomNumberGenerator; class StructType; template <class PtrType> class SmallPtrSetImpl; -template<> struct ilist_traits<NamedMDNode> - : public ilist_default_traits<NamedMDNode> { - // createSentinel is used to get hold of a node that marks the end of - // the list... - NamedMDNode *createSentinel() const { - return static_cast<NamedMDNode*>(&Sentinel); - } - static void destroySentinel(NamedMDNode*) {} - - NamedMDNode *provideInitialHead() const { return createSentinel(); } - NamedMDNode *ensureHead(NamedMDNode*) const { return createSentinel(); } - static void noteHead(NamedMDNode*, NamedMDNode*) {} - void addNodeToList(NamedMDNode *) {} - void removeNodeFromList(NamedMDNode *) {} - -private: - mutable ilist_node<NamedMDNode> Sentinel; -}; - /// A Module instance is used to store all the information related to an /// LLVM module. Modules are the top level container of all other LLVM /// Intermediate Representation (IR) objects. Each module directly contains a @@ -177,6 +159,9 @@ private: std::string GlobalScopeAsm; ///< Inline Asm at global scope. ValueSymbolTable *ValSymTab; ///< Symbol table for values ComdatSymTabType ComdatSymTab; ///< Symbol table for COMDATs + std::unique_ptr<MemoryBuffer> + OwnedMemoryBuffer; ///< Memory buffer directly owned by this + ///< module, for legacy clients only. std::unique_ptr<GVMaterializer> Materializer; ///< Used to materialize GlobalValues std::string ModuleID; ///< Human readable identifier for the module @@ -469,16 +454,14 @@ public: GVMaterializer *getMaterializer() const { return Materializer.get(); } bool isMaterialized() const { return !getMaterializer(); } - /// 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. - std::error_code materialize(GlobalValue *GV); + /// Make sure the GlobalValue is fully read. + llvm::Error materialize(GlobalValue *GV); /// Make sure all GlobalValues in this Module are fully read and clear the /// Materializer. - std::error_code materializeAll(); + llvm::Error materializeAll(); - std::error_code materializeMetadata(); + llvm::Error materializeMetadata(); /// @} /// @name Direct access to the globals list, functions list, and symbol table @@ -603,73 +586,33 @@ public: return make_range(ifunc_begin(), ifunc_end()); } -/// @} -/// @name Convenience iterators -/// @{ - - template <bool IsConst> class global_object_iterator_t { - friend Module; - - typename std::conditional<IsConst, const_iterator, iterator>::type - function_i, - function_e; - typename std::conditional<IsConst, const_global_iterator, - global_iterator>::type global_i; - - typedef - typename std::conditional<IsConst, const Module, Module>::type ModuleTy; - - global_object_iterator_t(ModuleTy &M) - : function_i(M.begin()), function_e(M.end()), - global_i(M.global_begin()) {} - global_object_iterator_t(ModuleTy &M, int) - : function_i(M.end()), function_e(M.end()), global_i(M.global_end()) {} - - public: - global_object_iterator_t &operator++() { - if (function_i != function_e) - ++function_i; - else - ++global_i; - return *this; - } - - typename std::conditional<IsConst, const GlobalObject, GlobalObject>::type & - operator*() const { - if (function_i != function_e) - return *function_i; - else - return *global_i; - } - - bool operator!=(const global_object_iterator_t &other) const { - return function_i != other.function_i || global_i != other.global_i; - } - }; + /// @} + /// @name Convenience iterators + /// @{ - typedef global_object_iterator_t</*IsConst=*/false> global_object_iterator; - typedef global_object_iterator_t</*IsConst=*/true> + typedef concat_iterator<GlobalObject, iterator, global_iterator> + global_object_iterator; + typedef concat_iterator<const GlobalObject, const_iterator, + const_global_iterator> const_global_object_iterator; - global_object_iterator global_object_begin() { - return global_object_iterator(*this); + iterator_range<global_object_iterator> global_objects() { + return concat<GlobalObject>(functions(), globals()); } - global_object_iterator global_object_end() { - return global_object_iterator(*this, 0); + iterator_range<const_global_object_iterator> global_objects() const { + return concat<const GlobalObject>(functions(), globals()); } - const_global_object_iterator global_object_begin() const { - return const_global_object_iterator(*this); - } - const_global_object_iterator global_object_end() const { - return const_global_object_iterator(*this, 0); + global_object_iterator global_object_begin() { + return global_objects().begin(); } + global_object_iterator global_object_end() { return global_objects().end(); } - iterator_range<global_object_iterator> global_objects() { - return make_range(global_object_begin(), global_object_end()); + const_global_object_iterator global_object_begin() const { + return global_objects().begin(); } - iterator_range<const_global_object_iterator> global_objects() const { - return make_range(global_object_begin(), global_object_end()); + const_global_object_iterator global_object_end() const { + return global_objects().end(); } /// @} @@ -821,6 +764,9 @@ public: /// \brief Returns profile summary metadata Metadata *getProfileSummary(); /// @} + + /// Take ownership of the given memory buffer. + void setOwnedMemoryBuffer(std::unique_ptr<MemoryBuffer> MB); }; /// \brief Given "llvm.used" or "llvm.compiler.used" as a global name, collect |
