diff options
author | Devang Patel <dpatel@apple.com> | 2009-07-29 17:16:17 +0000 |
---|---|---|
committer | Devang Patel <dpatel@apple.com> | 2009-07-29 17:16:17 +0000 |
commit | 28bc9d88260a3e153ead4311c9129e3d3ad07736 (patch) | |
tree | 9766b258ed5ad960f24c6ad1ac54b93f6cff9fb1 /lib/VMCore | |
parent | 4baffeb6be3a224f7adadbee17512ded22610fd0 (diff) | |
download | external_llvm-28bc9d88260a3e153ead4311c9129e3d3ad07736.zip external_llvm-28bc9d88260a3e153ead4311c9129e3d3ad07736.tar.gz external_llvm-28bc9d88260a3e153ead4311c9129e3d3ad07736.tar.bz2 |
Keep track of named mdnodes in a Module using an ilist.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77476 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r-- | lib/VMCore/Metadata.cpp | 7 | ||||
-rw-r--r-- | lib/VMCore/Module.cpp | 8 | ||||
-rw-r--r-- | lib/VMCore/Value.cpp | 4 |
3 files changed, 17 insertions, 2 deletions
diff --git a/lib/VMCore/Metadata.cpp b/lib/VMCore/Metadata.cpp index 73f89ca..2f6c153 100644 --- a/lib/VMCore/Metadata.cpp +++ b/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 @@ NamedMDNode::NamedMDNode(const char *N, unsigned NameLength, 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/lib/VMCore/Module.cpp b/lib/VMCore/Module.cpp index 35db8d2..c9d599e 100644 --- a/lib/VMCore/Module.cpp +++ b/lib/VMCore/Module.cpp @@ -67,6 +67,7 @@ Module::~Module() { FunctionList.clear(); AliasList.clear(); LibraryList.clear(); + NamedMDList.clear(); delete ValSymTab; delete TypeSymTab; } @@ -288,6 +289,13 @@ 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. +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/lib/VMCore/Value.cpp b/lib/VMCore/Value.cpp index af13973..2cdd552 100644 --- a/lib/VMCore/Value.cpp +++ b/lib/VMCore/Value.cpp @@ -142,6 +142,10 @@ static bool getSymTab(Value *V, ValueSymbolTable *&ST) { } 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 { |