[llvm-commits] [llvm] r92761 - in /llvm/trunk: docs/LangRef.html include/llvm/Metadata.h lib/AsmParser/LLParser.cpp lib/Bitcode/Reader/BitcodeReader.cpp lib/VMCore/Metadata.cpp unittests/VMCore/MetadataTest.cpp
Devang Patel
dpatel at apple.com
Tue Jan 5 12:41:31 PST 2010
Author: dpatel
Date: Tue Jan 5 14:41:31 2010
New Revision: 92761
URL: http://llvm.org/viewvc/llvm-project?rev=92761&view=rev
Log:
NamedMDNode is a collection MDNodes.
Modified:
llvm/trunk/docs/LangRef.html
llvm/trunk/include/llvm/Metadata.h
llvm/trunk/lib/AsmParser/LLParser.cpp
llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/trunk/lib/VMCore/Metadata.cpp
llvm/trunk/unittests/VMCore/MetadataTest.cpp
Modified: llvm/trunk/docs/LangRef.html
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/LangRef.html?rev=92761&r1=92760&r2=92761&view=diff
==============================================================================
--- llvm/trunk/docs/LangRef.html (original)
+++ llvm/trunk/docs/LangRef.html Tue Jan 5 14:41:31 2010
@@ -2329,6 +2329,9 @@
event that a value is deleted, it will be replaced with a typeless
"<tt>null</tt>", such as "<tt>metadata !{null, i32 10}</tt>".</p>
+<p>A named metadata is a collection of metadata nodes. For example: "<tt>!foo =
+ metadata !{!4, !3}</tt>".
+
<p>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
Modified: llvm/trunk/include/llvm/Metadata.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Metadata.h?rev=92761&r1=92760&r2=92761&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Metadata.h (original)
+++ llvm/trunk/include/llvm/Metadata.h Tue Jan 5 14:41:31 2010
@@ -167,7 +167,7 @@
};
//===----------------------------------------------------------------------===//
-/// 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<NamedMDNode> {
friend class SymbolTableListTraits<NamedMDNode, Module>;
@@ -176,15 +176,15 @@
NamedMDNode(const NamedMDNode &); // DO NOT IMPLEMENT
Module *Parent;
- void *Operands; // SmallVector<TrackingVH<MetadataBase>, 4>
+ void *Operands; // SmallVector<WeakVH<MDNode>, 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 @@
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; }
Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=92761&r1=92760&r2=92761&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLParser.cpp Tue Jan 5 14:41:31 2010
@@ -510,12 +510,11 @@
ParseToken(lltok::lbrace, "Expected '{' here"))
return true;
- SmallVector<MetadataBase *, 8> Elts;
+ SmallVector<MDNode *, 8> 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);
Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=92761&r1=92760&r2=92761&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Tue Jan 5 14:41:31 2010
@@ -787,11 +787,11 @@
// Read named metadata elements.
unsigned Size = Record.size();
- SmallVector<MetadataBase*, 8> Elts;
+ SmallVector<MDNode *, 8> Elts;
for (unsigned i = 0; i != Size; ++i) {
Value *MD = MDValueList.getValueFwdRef(Record[i]);
- if (MetadataBase *B = dyn_cast<MetadataBase>(MD))
- Elts.push_back(B);
+ if (MDNode *B = dyn_cast_or_null<MDNode>(MD))
+ Elts.push_back(B);
}
Value *V = NamedMDNode::Create(Context, Name.str(), Elts.data(),
Elts.size(), TheModule);
Modified: llvm/trunk/lib/VMCore/Metadata.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Metadata.cpp?rev=92761&r1=92760&r2=92761&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Metadata.cpp (original)
+++ llvm/trunk/lib/VMCore/Metadata.cpp Tue Jan 5 14:41:31 2010
@@ -210,21 +210,21 @@
//===----------------------------------------------------------------------===//
// NamedMDNode implementation.
//
-static SmallVector<TrackingVH<MetadataBase>, 4> &getNMDOps(void *Operands) {
- return *(SmallVector<TrackingVH<MetadataBase>, 4>*)Operands;
+static SmallVector<WeakVH, 4> &getNMDOps(void *Operands) {
+ return *(SmallVector<WeakVH, 4>*)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<TrackingVH<MetadataBase>, 4>();
+ Operands = new SmallVector<WeakVH, 4>();
- SmallVector<TrackingVH<MetadataBase>, 4> &Node = getNMDOps(Operands);
+ SmallVector<WeakVH, 4> &Node = getNMDOps(Operands);
for (unsigned i = 0; i != NumMDs; ++i)
- Node.push_back(TrackingVH<MetadataBase>(MDs[i]));
+ Node.push_back(WeakVH(MDs[i]));
if (ParentModule)
ParentModule->getNamedMDList().push_back(this);
@@ -232,7 +232,7 @@
NamedMDNode *NamedMDNode::Create(const NamedMDNode *NMD, Module *M) {
assert(NMD && "Invalid source NamedMDNode!");
- SmallVector<MetadataBase *, 4> Elems;
+ SmallVector<MDNode *, 4> Elems;
Elems.reserve(NMD->getNumOperands());
for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i)
@@ -252,14 +252,14 @@
}
/// 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<MDNode>(getNMDOps(Operands)[i]);
}
/// addOperand - Add metadata Operand.
-void NamedMDNode::addOperand(MetadataBase *M) {
- getNMDOps(Operands).push_back(TrackingVH<MetadataBase>(M));
+void NamedMDNode::addOperand(MDNode *M) {
+ getNMDOps(Operands).push_back(WeakVH(M));
}
/// eraseFromParent - Drop all references and remove the node from parent
Modified: llvm/trunk/unittests/VMCore/MetadataTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/VMCore/MetadataTest.cpp?rev=92761&r1=92760&r2=92761&view=diff
==============================================================================
--- llvm/trunk/unittests/VMCore/MetadataTest.cpp (original)
+++ llvm/trunk/unittests/VMCore/MetadataTest.cpp Tue Jan 5 14:41:31 2010
@@ -123,7 +123,7 @@
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";
More information about the llvm-commits
mailing list