Add getOrInsertNamedMetadata().
authorDevang Patel <dpatel@apple.com>
Thu, 30 Jul 2009 23:59:04 +0000 (23:59 +0000)
committerDevang Patel <dpatel@apple.com>
Thu, 30 Jul 2009 23:59:04 +0000 (23:59 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77646 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Module.h
lib/VMCore/Module.cpp

index 0f8722dc9d37ef210219824bd1518b26181b5b40..8b0c104a2baeed2a654170321cff33ffad93a268 100644 (file)
@@ -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
 /// @{
index 9e1622e93d0a5eb8cc3c20abf6679976fc9e3c22..e06e79a026820e96dbb163e5c67f3dfba14d7608 100644 (file)
@@ -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.
 //