Teach AsmWriter to write inline (not via a global metadata slot) metadata that contains an instruction

llvm-svn: 90512
This commit is contained in:
Victor Hernandez 2009-12-04 01:35:02 +00:00
parent 2107eb70d9
commit b7176a13a4
1 changed files with 25 additions and 1 deletions

View File

@ -695,8 +695,13 @@ void SlotTracker::processFunction() {
!I->hasName()) !I->hasName())
CreateFunctionSlot(I); CreateFunctionSlot(I);
for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i) for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i)
if (MDNode *N = dyn_cast_or_null<MDNode>(I->getOperand(i))) if (MDNode *N = dyn_cast_or_null<MDNode>(I->getOperand(i))) {
// Create a metadata slot only if N contains no instructions.
for (unsigned n = 0, e = N->getNumElements(); n != e; ++n)
if (isa<Instruction>(N->getElement(n)))
continue;
CreateMetadataSlot(N); CreateMetadataSlot(N);
}
// Process metadata attached with this instruction. // Process metadata attached with this instruction.
MDs.clear(); MDs.clear();
@ -1227,6 +1232,25 @@ static void WriteAsOperandInternal(raw_ostream &Out, const Value *V,
} }
if (const MDNode *N = dyn_cast<MDNode>(V)) { if (const MDNode *N = dyn_cast<MDNode>(V)) {
if (Machine->getMetadataSlot(N) == -1) {
// Print metadata inline, not via slot reference number.
Out << "!{";
for (unsigned mi = 0, me = N->getNumElements(); mi != me; ++mi) {
const Value *Val = N->getElement(mi);
if (!Val)
Out << "null";
else {
TypePrinter->print(N->getElement(0)->getType(), Out);
Out << ' ';
WriteAsOperandInternal(Out, N->getElement(0), TypePrinter, Machine);
}
if (mi + 1 != me)
Out << ", ";
}
Out << '}';
return;
}
Out << '!' << Machine->getMetadataSlot(N); Out << '!' << Machine->getMetadataSlot(N);
return; return;
} }