[llvm-commits] [llvm] r77646 - in /llvm/trunk: include/llvm/Module.h lib/VMCore/Module.cpp

Devang Patel dpatel at apple.com
Thu Jul 30 16:59:05 PDT 2009


Author: dpatel
Date: Thu Jul 30 18:59:04 2009
New Revision: 77646

URL: http://llvm.org/viewvc/llvm-project?rev=77646&view=rev
Log:
Add getOrInsertNamedMetadata().

Modified:
    llvm/trunk/include/llvm/Module.h
    llvm/trunk/lib/VMCore/Module.cpp

Modified: llvm/trunk/include/llvm/Module.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Module.h?rev=77646&r1=77645&r2=77646&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Module.h (original)
+++ llvm/trunk/include/llvm/Module.h Thu Jul 30 18:59:04 2009
@@ -303,11 +303,16 @@
 /// @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
 /// @{

Modified: llvm/trunk/lib/VMCore/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Module.cpp?rev=77646&r1=77645&r2=77646&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Module.cpp (original)
+++ llvm/trunk/lib/VMCore/Module.cpp Thu Jul 30 18:59:04 2009
@@ -289,13 +289,24 @@
   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.
 //





More information about the llvm-commits mailing list