diff options
Diffstat (limited to 'llvm/lib/VMCore')
-rw-r--r-- | llvm/lib/VMCore/Metadata.cpp | 18 | ||||
-rw-r--r-- | llvm/lib/VMCore/Module.cpp | 12 |
2 files changed, 24 insertions, 6 deletions
diff --git a/llvm/lib/VMCore/Metadata.cpp b/llvm/lib/VMCore/Metadata.cpp index 09cd1d5cbae..6cc1e1bdedb 100644 --- a/llvm/lib/VMCore/Metadata.cpp +++ b/llvm/lib/VMCore/Metadata.cpp @@ -214,20 +214,21 @@ static SmallVector<WeakVH, 4> &getNMDOps(void *Operands) { return *(SmallVector<WeakVH, 4>*)Operands; } -NamedMDNode::NamedMDNode(LLVMContext &C, const Twine &N, +NamedMDNode::NamedMDNode(LLVMContext &C, StringRef N, MDNode *const *MDs, unsigned NumMDs, Module *ParentModule) : MetadataBase(Type::getMetadataTy(C), Value::NamedMDNodeVal), Parent(0) { setName(N); - Operands = new SmallVector<WeakVH, 4>(); SmallVector<WeakVH, 4> &Node = getNMDOps(Operands); for (unsigned i = 0; i != NumMDs; ++i) Node.push_back(WeakVH(MDs[i])); - if (ParentModule) + if (ParentModule) { ParentModule->getNamedMDList().push_back(this); + ParentModule->addMDNodeName(N, this); + } } NamedMDNode *NamedMDNode::Create(const NamedMDNode *NMD, Module *M) { @@ -265,6 +266,7 @@ void NamedMDNode::addOperand(MDNode *M) { /// eraseFromParent - Drop all references and remove the node from parent /// module. void NamedMDNode::eraseFromParent() { + getParent()->getMDSymbolTable().remove(getName()); getParent()->getNamedMDList().erase(this); } @@ -273,6 +275,16 @@ void NamedMDNode::dropAllReferences() { getNMDOps(Operands).clear(); } +/// setName - Set the name of this named metadata. +void NamedMDNode::setName(StringRef N) { + if (!N.empty()) + Name = N.str(); +} + +/// getName - Return a constant reference to this named metadata's name. +StringRef NamedMDNode::getName() const { + return StringRef(Name); +} //===----------------------------------------------------------------------===// // LLVMContext MDKind naming implementation. diff --git a/llvm/lib/VMCore/Module.cpp b/llvm/lib/VMCore/Module.cpp index a7f503bacb9..e25a29517a4 100644 --- a/llvm/lib/VMCore/Module.cpp +++ b/llvm/lib/VMCore/Module.cpp @@ -59,6 +59,7 @@ Module::Module(StringRef MID, LLVMContext& C) : Context(C), ModuleID(MID), DataLayout("") { ValSymTab = new ValueSymbolTable(); TypeSymTab = new TypeSymbolTable(); + NamedMDSymTab = new MDSymbolTable(); } Module::~Module() { @@ -307,20 +308,25 @@ GlobalAlias *Module::getNamedAlias(StringRef Name) const { /// specified name. This method returns null if a NamedMDNode with the //// specified name is not found. NamedMDNode *Module::getNamedMetadata(StringRef Name) const { - return dyn_cast_or_null<NamedMDNode>(getValueSymbolTable().lookup(Name)); + return NamedMDSymTab->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(StringRef Name) { - NamedMDNode *NMD = - dyn_cast_or_null<NamedMDNode>(getValueSymbolTable().lookup(Name)); + NamedMDNode *NMD = NamedMDSymTab->lookup(Name); if (!NMD) NMD = NamedMDNode::Create(getContext(), Name, NULL, 0, this); return NMD; } +/// addMDNodeName - Insert an entry in the NamedMDNode symbol table mapping +/// Name to NMD. +void Module::addMDNodeName(StringRef Name, NamedMDNode *NMD) { + NamedMDSymTab->insert(Name, NMD); +} + //===----------------------------------------------------------------------===// // Methods for easy access to the types in the module. // |