diff options
author | Devang Patel <dpatel@apple.com> | 2009-07-30 23:59:04 +0000 |
---|---|---|
committer | Devang Patel <dpatel@apple.com> | 2009-07-30 23:59:04 +0000 |
commit | 7ee9e49f447ee409cef334303951db6f3be49772 (patch) | |
tree | 985d23cf65e67074b45ca6f7dd01947fa7d554ef | |
parent | db6134c2b40043b87d3bd3f10e6adf1935a1e76d (diff) | |
download | external_llvm-7ee9e49f447ee409cef334303951db6f3be49772.zip external_llvm-7ee9e49f447ee409cef334303951db6f3be49772.tar.gz external_llvm-7ee9e49f447ee409cef334303951db6f3be49772.tar.bz2 |
Add getOrInsertNamedMetadata().
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77646 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/Module.h | 11 | ||||
-rw-r--r-- | lib/VMCore/Module.cpp | 17 |
2 files changed, 22 insertions, 6 deletions
diff --git a/include/llvm/Module.h b/include/llvm/Module.h index 0f8722dc..8b0c104 100644 --- a/include/llvm/Module.h +++ b/include/llvm/Module.h @@ -303,11 +303,16 @@ public: /// @name Named Metadata Accessors /// @{ public: - /// getNamedMetadata - Return the first named MDNode in the module with the - /// specified name. This method returns null if a MDNode with the specified - /// name is not found. + /// getNamedMetadata - Return the first 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 StringRef &Name) const; + /// getOrInsertNamedMetadata - Return the first 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(const StringRef &Name); + /// @} /// @name Type Accessors /// @{ diff --git a/lib/VMCore/Module.cpp b/lib/VMCore/Module.cpp index 9e1622e..e06e79a 100644 --- a/lib/VMCore/Module.cpp +++ b/lib/VMCore/Module.cpp @@ -289,13 +289,24 @@ GlobalAlias *Module::getNamedAlias(const StringRef &Name) const { return dyn_cast_or_null<GlobalAlias>(getNamedValue(Name)); } -/// getNamedMetadata - Return the first named MDNode in the module with the -/// specified name. This method returns null if a MDNode with the specified -/// name is not found. +/// getNamedMetadata - Return the first NamedMDNode in the module with the +/// specified name. This method returns null if a NamedMDNode with the +//// specified name is not found. NamedMDNode *Module::getNamedMetadata(const StringRef &Name) const { return dyn_cast_or_null<NamedMDNode>(getValueSymbolTable().lookup(Name)); } +/// getOrInsertNamedMetadata - Return the first 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 *Module::getOrInsertNamedMetadata(const StringRef &Name) { + NamedMDNode *NMD = + dyn_cast_or_null<NamedMDNode>(getValueSymbolTable().lookup(Name)); + if (!NMD) + NMD = NamedMDNode::Create(Name, NULL, 0, this); + return NMD; +} + //===----------------------------------------------------------------------===// // Methods for easy access to the types in the module. // |