Keep track of named mdnodes in a Module using an ilist.
llvm-svn: 77476
diff --git a/llvm/lib/VMCore/Metadata.cpp b/llvm/lib/VMCore/Metadata.cpp
index 73f89ca..2f6c153 100644
--- a/llvm/lib/VMCore/Metadata.cpp
+++ b/llvm/lib/VMCore/Metadata.cpp
@@ -13,6 +13,7 @@
#include "llvm/Metadata.h"
#include "llvm/Module.h"
+#include "SymbolTableListTraitsImpl.h"
using namespace llvm;
//===----------------------------------------------------------------------===//
@@ -36,9 +37,11 @@
MetadataBase*const* MDs, unsigned NumMDs,
Module *M)
: MetadataBase(Type::MetadataTy, Value::NamedMDNodeVal),
- Parent(M), Name(N, NameLength) {
+ Name(N, NameLength) {
+ setName(N);
for (unsigned i = 0; i != NumMDs; ++i)
Node.push_back(WeakMetadataVH(MDs[i]));
- // FIXME : Add into the parent module.
+ if (M)
+ M->getNamedMDList().push_back(this);
}
diff --git a/llvm/lib/VMCore/Module.cpp b/llvm/lib/VMCore/Module.cpp
index 35db8d2..c9d599eb 100644
--- a/llvm/lib/VMCore/Module.cpp
+++ b/llvm/lib/VMCore/Module.cpp
@@ -67,6 +67,7 @@
FunctionList.clear();
AliasList.clear();
LibraryList.clear();
+ NamedMDList.clear();
delete ValSymTab;
delete TypeSymTab;
}
@@ -288,6 +289,13 @@
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.
+NamedMDNode *Module::getNamedMetadata(const StringRef &Name) const {
+ return dyn_cast_or_null<NamedMDNode>(getNamedValue(Name));
+}
+
//===----------------------------------------------------------------------===//
// Methods for easy access to the types in the module.
//
diff --git a/llvm/lib/VMCore/Value.cpp b/llvm/lib/VMCore/Value.cpp
index af13973..2cdd552 100644
--- a/llvm/lib/VMCore/Value.cpp
+++ b/llvm/lib/VMCore/Value.cpp
@@ -142,6 +142,10 @@
} else if (Argument *A = dyn_cast<Argument>(V)) {
if (Function *P = A->getParent())
ST = &P->getValueSymbolTable();
+ } else if (NamedMDNode *N = dyn_cast<NamedMDNode>(V)) {
+ if (Module *P = N->getParent()) {
+ ST = &P->getValueSymbolTable();
+ }
} else if (isa<MDString>(V))
return true;
else {