Allow null to be an element of NamedMDNode. e.g. !llvm.stuff = !{!0, !1, null}

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92783 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Devang Patel 2010-01-05 21:47:32 +00:00
parent 6ae68a28b9
commit 69d02e0a17
6 changed files with 22 additions and 12 deletions

View File

@ -512,6 +512,12 @@ bool LLParser::ParseNamedMetadata() {
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;

View File

@ -789,9 +789,13 @@ bool BitcodeReader::ParseMetadata() {
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);

View File

@ -540,7 +540,7 @@ static void WriteModuleMetadata(const ValueEnumerator &VE,
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();

View File

@ -223,7 +223,8 @@ void ValueEnumerator::EnumerateMetadata(const MetadataBase *MD) {
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;

View File

@ -615,8 +615,7 @@ void SlotTracker::processModule() {
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 @@ void AssemblyWriter::printNamedMDNode(const NamedMDNode *NMD) {
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";
}

View File

@ -3,4 +3,4 @@
;; Simple NamedMDNode
!0 = metadata !{i32 42}
!1 = metadata !{metadata !"foo"}
!llvm.stuff = !{!0, !1}
!llvm.stuff = !{!0, !1, null}