diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/llvm/Metadata.h | 13 | ||||
-rw-r--r-- | include/llvm/Module.h | 36 | ||||
-rw-r--r-- | include/llvm/ValueSymbolTable.h | 80 |
3 files changed, 112 insertions, 17 deletions
diff --git a/include/llvm/Metadata.h b/include/llvm/Metadata.h index 491b469193..87fe17cf7e 100644 --- a/include/llvm/Metadata.h +++ b/include/llvm/Metadata.h @@ -175,15 +175,16 @@ class NamedMDNode : public MetadataBase, public ilist_node<NamedMDNode> { NamedMDNode(const NamedMDNode &); // DO NOT IMPLEMENT + std::string Name; Module *Parent; void *Operands; // SmallVector<WeakVH<MDNode>, 4> void setParent(Module *M) { Parent = M; } protected: - explicit NamedMDNode(LLVMContext &C, const Twine &N, MDNode*const *Vals, + explicit NamedMDNode(LLVMContext &C, StringRef N, MDNode*const *Vals, unsigned NumVals, Module *M = 0); public: - static NamedMDNode *Create(LLVMContext &C, const Twine &N, + static NamedMDNode *Create(LLVMContext &C, StringRef N, MDNode *const *MDs, unsigned NumMDs, Module *M = 0) { return new NamedMDNode(C, N, MDs, NumMDs, M); @@ -213,7 +214,13 @@ public: /// addOperand - Add metadata operand. void addOperand(MDNode *M); - + + /// setName - Set the name of this named metadata. + void setName(StringRef Name); + + /// getName - Return a constant reference to this named metadata's name. + StringRef getName() const; + /// Methods for support type inquiry through isa, cast, and dyn_cast: static inline bool classof(const NamedMDNode *) { return true; } static bool classof(const Value *V) { diff --git a/include/llvm/Module.h b/include/llvm/Module.h index 9a8b53ac58..a5a2ad4600 100644 --- a/include/llvm/Module.h +++ b/include/llvm/Module.h @@ -26,6 +26,7 @@ namespace llvm { class FunctionType; class LLVMContext; +class MDSymbolTable; template<> struct ilist_traits<Function> : public SymbolTableListTraits<Function, Module> { @@ -131,19 +132,20 @@ public: /// @name Member Variables /// @{ private: - LLVMContext &Context; ///< The LLVMContext from which types and - ///< constants are allocated. - GlobalListType GlobalList; ///< The Global Variables in the module - FunctionListType FunctionList; ///< The Functions in the module - AliasListType AliasList; ///< The Aliases in the module - LibraryListType LibraryList; ///< The Libraries needed by the module - NamedMDListType NamedMDList; ///< The named metadata in the module - std::string GlobalScopeAsm; ///< Inline Asm at global scope. - ValueSymbolTable *ValSymTab; ///< Symbol table for values - TypeSymbolTable *TypeSymTab; ///< Symbol table for types - std::string ModuleID; ///< Human readable identifier for the module - std::string TargetTriple; ///< Platform target triple Module compiled on - std::string DataLayout; ///< Target data description + LLVMContext &Context; ///< The LLVMContext from which types and + ///< constants are allocated. + GlobalListType GlobalList; ///< The Global Variables in the module + FunctionListType FunctionList; ///< The Functions in the module + AliasListType AliasList; ///< The Aliases in the module + LibraryListType LibraryList; ///< The Libraries needed by the module + NamedMDListType NamedMDList; ///< The named metadata in the module + std::string GlobalScopeAsm; ///< Inline Asm at global scope. + ValueSymbolTable *ValSymTab; ///< Symbol table for values + TypeSymbolTable *TypeSymTab; ///< Symbol table for types + std::string ModuleID; ///< Human readable identifier for the module + std::string TargetTriple; ///< Platform target triple Module compiled on + std::string DataLayout; ///< Target data description + MDSymbolTable *NamedMDSymTab; ///< NamedMDNode names. friend class Constant; @@ -322,6 +324,10 @@ public: /// NamedMDNode with the specified name is not found. NamedMDNode *getOrInsertNamedMetadata(StringRef Name); + /// addMDNodeName - Insert an entry in the NamedMDNode symbol table mapping + /// Name to NMD. + void addMDNodeName(StringRef Name, NamedMDNode *NMD); + /// @} /// @name Type Accessors /// @{ @@ -379,6 +385,10 @@ public: const TypeSymbolTable &getTypeSymbolTable() const { return *TypeSymTab; } /// Get the Module's symbol table of types TypeSymbolTable &getTypeSymbolTable() { return *TypeSymTab; } + /// Get the symbol table of named metadata + const MDSymbolTable &getMDSymbolTable() const { return *NamedMDSymTab; } + /// Get the Module's symbol table of named metadata + MDSymbolTable &getMDSymbolTable() { return *NamedMDSymTab; } /// @} /// @name Global Variable Iteration diff --git a/include/llvm/ValueSymbolTable.h b/include/llvm/ValueSymbolTable.h index e05fdbd08d..e5ea49f39b 100644 --- a/include/llvm/ValueSymbolTable.h +++ b/include/llvm/ValueSymbolTable.h @@ -26,7 +26,7 @@ namespace llvm { class NamedMDNode; class Module; class StringRef; - + /// This class provides a symbol table of name/value pairs. It is essentially /// a std::map<std::string,Value*> but has a controlled interface provided by /// LLVM as well as ensuring uniqueness of names. @@ -129,6 +129,84 @@ private: /// @} }; +/// This class provides a symbol table of name/NamedMDNode pairs. It is +/// essentially a StringMap wrapper. + +class MDSymbolTable { +/// @name Types +/// @{ +public: + /// @brief A mapping of names to metadata + typedef StringMap<NamedMDNode*> MDMap; + + /// @brief An iterator over a ValueMap. + typedef MDMap::iterator iterator; + + /// @brief A const_iterator over a ValueMap. + typedef MDMap::const_iterator const_iterator; + +/// @} +/// @name Constructors +/// @{ +public: + + MDSymbolTable() : mmap(0) {} + ~MDSymbolTable(); + +/// @} +/// @name Accessors +/// @{ +public: + + /// This method finds the value with the given \p Name in the + /// the symbol table. + /// @returns the NamedMDNode associated with the \p Name + /// @brief Lookup a named Value. + NamedMDNode *lookup(StringRef Name) const { return mmap.lookup(Name); } + + /// @returns true iff the symbol table is empty + /// @brief Determine if the symbol table is empty + inline bool empty() const { return mmap.empty(); } + + /// @brief The number of name/type pairs is returned. + inline unsigned size() const { return unsigned(mmap.size()); } + +/// @} +/// @name Iteration +/// @{ +public: + /// @brief Get an iterator that from the beginning of the symbol table. + inline iterator begin() { return mmap.begin(); } + + /// @brief Get a const_iterator that from the beginning of the symbol table. + inline const_iterator begin() const { return mmap.begin(); } + + /// @brief Get an iterator to the end of the symbol table. + inline iterator end() { return mmap.end(); } + + /// @brief Get a const_iterator to the end of the symbol table. + inline const_iterator end() const { return mmap.end(); } + +/// @} +/// @name Mutators +/// @{ +public: + /// insert - The method inserts a new entry into the stringmap. + void insert(StringRef Name, NamedMDNode *Node) { + (void) mmap.GetOrCreateValue(Name, Node); + } + + /// This method removes a NamedMDNode from the symbol table. + void remove(StringRef Name) { mmap.erase(Name); } + +/// @} +/// @name Internal Data +/// @{ +private: + MDMap mmap; ///< The map that holds the symbol table. +/// @} +}; + } // End llvm namespace #endif |