[llvm-commits] [llvm] r92783 - in /llvm/trunk: lib/AsmParser/LLParser.cpp lib/Bitcode/Reader/BitcodeReader.cpp lib/Bitcode/Writer/BitcodeWriter.cpp lib/Bitcode/Writer/ValueEnumerator.cpp lib/VMCore/AsmWriter.cpp test/Feature/NamedMDNode.ll
Devang Patel
dpatel at apple.com
Tue Jan 5 13:47:33 PST 2010
Author: dpatel
Date: Tue Jan 5 15:47:32 2010
New Revision: 92783
URL: http://llvm.org/viewvc/llvm-project?rev=92783&view=rev
Log:
Allow null to be an element of NamedMDNode. e.g. !llvm.stuff = !{!0, !1, null}
Modified:
llvm/trunk/lib/AsmParser/LLParser.cpp
llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
llvm/trunk/lib/Bitcode/Writer/ValueEnumerator.cpp
llvm/trunk/lib/VMCore/AsmWriter.cpp
llvm/trunk/test/Feature/NamedMDNode.ll
Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=92783&r1=92782&r2=92783&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLParser.cpp Tue Jan 5 15:47:32 2010
@@ -512,6 +512,12 @@
SmallVector<MDNode *, 8> Elts;
do {
+ // Null is a special case since it is typeless.
+ if (EatIfPresent(lltok::kw_null)) {
+ Elts.push_back(0);
+ continue;
+ }
+
if (ParseToken(lltok::exclaim, "Expected '!' here"))
return true;
Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=92783&r1=92782&r2=92783&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Tue Jan 5 15:47:32 2010
@@ -789,9 +789,13 @@
unsigned Size = Record.size();
SmallVector<MDNode *, 8> Elts;
for (unsigned i = 0; i != Size; ++i) {
- Value *MD = MDValueList.getValueFwdRef(Record[i]);
- if (MDNode *B = dyn_cast_or_null<MDNode>(MD))
- Elts.push_back(B);
+ if (Record[i] == ~0U)
+ Elts.push_back(NULL);
+ else {
+ Value *MD = MDValueList.getValueFwdRef(Record[i]);
+ 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/Bitcode/Writer/BitcodeWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp?rev=92783&r1=92782&r2=92783&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp (original)
+++ llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp Tue Jan 5 15:47:32 2010
@@ -540,7 +540,7 @@
if (NMD->getOperand(i))
Record.push_back(VE.getValueID(NMD->getOperand(i)));
else
- Record.push_back(0);
+ Record.push_back(~0U);
}
Stream.EmitRecord(bitc::METADATA_NAMED_NODE, Record, 0);
Record.clear();
Modified: llvm/trunk/lib/Bitcode/Writer/ValueEnumerator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Writer/ValueEnumerator.cpp?rev=92783&r1=92782&r2=92783&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Writer/ValueEnumerator.cpp (original)
+++ llvm/trunk/lib/Bitcode/Writer/ValueEnumerator.cpp Tue Jan 5 15:47:32 2010
@@ -223,7 +223,8 @@
if (const NamedMDNode *N = dyn_cast<NamedMDNode>(MD)) {
for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
- EnumerateValue(N->getOperand(i));
+ if (MDNode *E = N->getOperand(i))
+ EnumerateValue(E);
MDValues.push_back(std::make_pair(MD, 1U));
MDValueMap[MD] = Values.size();
return;
Modified: llvm/trunk/lib/VMCore/AsmWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/AsmWriter.cpp?rev=92783&r1=92782&r2=92783&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/AsmWriter.cpp (original)
+++ llvm/trunk/lib/VMCore/AsmWriter.cpp Tue Jan 5 15:47:32 2010
@@ -615,8 +615,7 @@
E = TheModule->named_metadata_end(); I != E; ++I) {
const NamedMDNode *NMD = I;
for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
- // FIXME: Change accessor to be type safe.
- if (MDNode *MD = cast_or_null<MDNode>(NMD->getOperand(i)))
+ if (MDNode *MD = NMD->getOperand(i))
CreateMetadataSlot(MD);
}
}
@@ -1370,10 +1369,10 @@
Out << "!" << NMD->getName() << " = !{";
for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
if (i) Out << ", ";
- // FIXME: Change accessor to be typesafe.
- // FIXME: This doesn't handle null??
- MDNode *MD = cast_or_null<MDNode>(NMD->getOperand(i));
- Out << '!' << Machine.getMetadataSlot(MD);
+ if (MDNode *MD = NMD->getOperand(i))
+ Out << '!' << Machine.getMetadataSlot(MD);
+ else
+ Out << "null";
}
Out << "}\n";
}
Modified: llvm/trunk/test/Feature/NamedMDNode.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Feature/NamedMDNode.ll?rev=92783&r1=92782&r2=92783&view=diff
==============================================================================
--- llvm/trunk/test/Feature/NamedMDNode.ll (original)
+++ llvm/trunk/test/Feature/NamedMDNode.ll Tue Jan 5 15:47:32 2010
@@ -3,4 +3,4 @@
;; Simple NamedMDNode
!0 = metadata !{i32 42}
!1 = metadata !{metadata !"foo"}
-!llvm.stuff = !{!0, !1}
+!llvm.stuff = !{!0, !1, null}
More information about the llvm-commits
mailing list