From 3e30c2a3c54c50246e6cccf0c8842619e29fe66c Mon Sep 17 00:00:00 2001 From: Devang Patel Date: Tue, 5 Jan 2010 20:41:31 +0000 Subject: [PATCH] NamedMDNode is a collection MDNodes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92761 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/LangRef.html | 3 +++ include/llvm/Metadata.h | 12 ++++++------ lib/AsmParser/LLParser.cpp | 3 +-- lib/Bitcode/Reader/BitcodeReader.cpp | 6 +++--- lib/VMCore/Metadata.cpp | 22 +++++++++++----------- unittests/VMCore/MetadataTest.cpp | 2 +- 6 files changed, 25 insertions(+), 23 deletions(-) diff --git a/docs/LangRef.html b/docs/LangRef.html index 526f119a628..78d4818aeda 100644 --- a/docs/LangRef.html +++ b/docs/LangRef.html @@ -2329,6 +2329,9 @@ has undefined behavior.

event that a value is deleted, it will be replaced with a typeless "null", such as "metadata !{null, i32 10}".

+

A named metadata is a collection of metadata nodes. For example: "!foo = + metadata !{!4, !3}". +

Optimizations may rely on metadata to provide additional information about the program that isn't available in the instructions, or that isn't easily computable. Similarly, the code generator may expect a certain metadata diff --git a/include/llvm/Metadata.h b/include/llvm/Metadata.h index ec6ba1b63d5..491b469193d 100644 --- a/include/llvm/Metadata.h +++ b/include/llvm/Metadata.h @@ -167,7 +167,7 @@ private: }; //===----------------------------------------------------------------------===// -/// NamedMDNode - a tuple of other metadata. +/// NamedMDNode - a tuple of MDNodes. /// NamedMDNode is always named. All NamedMDNode operand has a type of metadata. class NamedMDNode : public MetadataBase, public ilist_node { friend class SymbolTableListTraits; @@ -176,15 +176,15 @@ class NamedMDNode : public MetadataBase, public ilist_node { NamedMDNode(const NamedMDNode &); // DO NOT IMPLEMENT Module *Parent; - void *Operands; // SmallVector, 4> + void *Operands; // SmallVector, 4> void setParent(Module *M) { Parent = M; } protected: - explicit NamedMDNode(LLVMContext &C, const Twine &N, MetadataBase*const *Vals, + explicit NamedMDNode(LLVMContext &C, const Twine &N, MDNode*const *Vals, unsigned NumVals, Module *M = 0); public: static NamedMDNode *Create(LLVMContext &C, const Twine &N, - MetadataBase *const *MDs, + MDNode *const *MDs, unsigned NumMDs, Module *M = 0) { return new NamedMDNode(C, N, MDs, NumMDs, M); } @@ -206,13 +206,13 @@ public: inline const Module *getParent() const { return Parent; } /// getOperand - Return specified operand. - MetadataBase *getOperand(unsigned i) const; + MDNode *getOperand(unsigned i) const; /// getNumOperands - Return the number of NamedMDNode operands. unsigned getNumOperands() const; /// addOperand - Add metadata operand. - void addOperand(MetadataBase *M); + void addOperand(MDNode *M); /// Methods for support type inquiry through isa, cast, and dyn_cast: static inline bool classof(const NamedMDNode *) { return true; } diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp index 01cd531dac2..0a3617575ef 100644 --- a/lib/AsmParser/LLParser.cpp +++ b/lib/AsmParser/LLParser.cpp @@ -510,12 +510,11 @@ bool LLParser::ParseNamedMetadata() { ParseToken(lltok::lbrace, "Expected '{' here")) return true; - SmallVector Elts; + SmallVector Elts; do { if (ParseToken(lltok::exclaim, "Expected '!' here")) return true; - // FIXME: This rejects MDStrings. Are they legal in an named MDNode or not? MDNode *N = 0; if (ParseMDNodeID(N)) return true; Elts.push_back(N); diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index 98243e0e249..c8097a09996 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -787,11 +787,11 @@ bool BitcodeReader::ParseMetadata() { // Read named metadata elements. unsigned Size = Record.size(); - SmallVector Elts; + SmallVector Elts; for (unsigned i = 0; i != Size; ++i) { Value *MD = MDValueList.getValueFwdRef(Record[i]); - if (MetadataBase *B = dyn_cast(MD)) - Elts.push_back(B); + if (MDNode *B = dyn_cast_or_null(MD)) + Elts.push_back(B); } Value *V = NamedMDNode::Create(Context, Name.str(), Elts.data(), Elts.size(), TheModule); diff --git a/lib/VMCore/Metadata.cpp b/lib/VMCore/Metadata.cpp index 8e9aab93a14..09cd1d5cbae 100644 --- a/lib/VMCore/Metadata.cpp +++ b/lib/VMCore/Metadata.cpp @@ -210,21 +210,21 @@ void MDNode::replaceOperand(MDNodeOperand *Op, Value *To) { //===----------------------------------------------------------------------===// // NamedMDNode implementation. // -static SmallVector, 4> &getNMDOps(void *Operands) { - return *(SmallVector, 4>*)Operands; +static SmallVector &getNMDOps(void *Operands) { + return *(SmallVector*)Operands; } NamedMDNode::NamedMDNode(LLVMContext &C, const Twine &N, - MetadataBase *const *MDs, + MDNode *const *MDs, unsigned NumMDs, Module *ParentModule) : MetadataBase(Type::getMetadataTy(C), Value::NamedMDNodeVal), Parent(0) { setName(N); - Operands = new SmallVector, 4>(); + Operands = new SmallVector(); - SmallVector, 4> &Node = getNMDOps(Operands); + SmallVector &Node = getNMDOps(Operands); for (unsigned i = 0; i != NumMDs; ++i) - Node.push_back(TrackingVH(MDs[i])); + Node.push_back(WeakVH(MDs[i])); if (ParentModule) ParentModule->getNamedMDList().push_back(this); @@ -232,7 +232,7 @@ NamedMDNode::NamedMDNode(LLVMContext &C, const Twine &N, NamedMDNode *NamedMDNode::Create(const NamedMDNode *NMD, Module *M) { assert(NMD && "Invalid source NamedMDNode!"); - SmallVector Elems; + SmallVector Elems; Elems.reserve(NMD->getNumOperands()); for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) @@ -252,14 +252,14 @@ unsigned NamedMDNode::getNumOperands() const { } /// getOperand - Return specified operand. -MetadataBase *NamedMDNode::getOperand(unsigned i) const { +MDNode *NamedMDNode::getOperand(unsigned i) const { assert(i < getNumOperands() && "Invalid Operand number!"); - return getNMDOps(Operands)[i]; + return dyn_cast_or_null(getNMDOps(Operands)[i]); } /// addOperand - Add metadata Operand. -void NamedMDNode::addOperand(MetadataBase *M) { - getNMDOps(Operands).push_back(TrackingVH(M)); +void NamedMDNode::addOperand(MDNode *M) { + getNMDOps(Operands).push_back(WeakVH(M)); } /// eraseFromParent - Drop all references and remove the node from parent diff --git a/unittests/VMCore/MetadataTest.cpp b/unittests/VMCore/MetadataTest.cpp index e1185681c85..e3747892fdf 100644 --- a/unittests/VMCore/MetadataTest.cpp +++ b/unittests/VMCore/MetadataTest.cpp @@ -123,7 +123,7 @@ TEST(NamedMDNodeTest, Search) { MDNode *n = MDNode::get(Context, &V, 1); MDNode *n2 = MDNode::get(Context, &V2, 1); - MetadataBase *Nodes[2] = { n, n2 }; + MDNode *Nodes[2] = { n, n2 }; Module *M = new Module("MyModule", getGlobalContext()); const char *Name = "llvm.NMD1";