1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 03:33:20 +01:00

Give MDNode printing has access to the current Module in more

cases. This will be needed when function-local metadata can
appear in places that aren't intrinsic function arguments.

llvm-svn: 108971
This commit is contained in:
Dan Gohman 2010-07-20 23:55:01 +00:00
parent 2e78d6ed2e
commit 09326457a8

View File

@ -581,8 +581,12 @@ static SlotTracker *createSlotTracker(const Value *V) {
if (const Function *Func = dyn_cast<Function>(V))
return new SlotTracker(Func);
if (isa<MDNode>(V))
if (const MDNode *MD = dyn_cast<MDNode>(V)) {
if (!MD->isFunctionLocal())
return new SlotTracker(MD->getFunction());
return new SlotTracker((Function *)0);
}
return 0;
}
@ -778,15 +782,14 @@ void SlotTracker::CreateMetadataSlot(const MDNode *N) {
// Don't insert if N is a function-local metadata, these are always printed
// inline.
if (N->isFunctionLocal())
return;
if (!N->isFunctionLocal()) {
mdn_iterator I = mdnMap.find(N);
if (I != mdnMap.end())
return;
mdn_iterator I = mdnMap.find(N);
if (I != mdnMap.end())
return;
unsigned DestSlot = mdnNext++;
mdnMap[N] = DestSlot;
unsigned DestSlot = mdnNext++;
mdnMap[N] = DestSlot;
}
// Recursively add any MDNodes referenced by operands.
for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
@ -800,7 +803,8 @@ void SlotTracker::CreateMetadataSlot(const MDNode *N) {
static void WriteAsOperandInternal(raw_ostream &Out, const Value *V,
TypePrinting *TypePrinter,
SlotTracker *Machine);
SlotTracker *Machine,
const Module *Context);
@ -856,7 +860,8 @@ static void WriteOptimizationInfo(raw_ostream &Out, const User *U) {
static void WriteConstantInternal(raw_ostream &Out, const Constant *CV,
TypePrinting &TypePrinter,
SlotTracker *Machine) {
SlotTracker *Machine,
const Module *Context) {
if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
if (CI->getType()->isIntegerTy(1)) {
Out << (CI->getZExtValue() ? "true" : "false");
@ -972,9 +977,11 @@ static void WriteConstantInternal(raw_ostream &Out, const Constant *CV,
if (const BlockAddress *BA = dyn_cast<BlockAddress>(CV)) {
Out << "blockaddress(";
WriteAsOperandInternal(Out, BA->getFunction(), &TypePrinter, Machine);
WriteAsOperandInternal(Out, BA->getFunction(), &TypePrinter, Machine,
Context);
Out << ", ";
WriteAsOperandInternal(Out, BA->getBasicBlock(), &TypePrinter, Machine);
WriteAsOperandInternal(Out, BA->getBasicBlock(), &TypePrinter, Machine,
Context);
Out << ")";
return;
}
@ -994,12 +1001,14 @@ static void WriteConstantInternal(raw_ostream &Out, const Constant *CV,
TypePrinter.print(ETy, Out);
Out << ' ';
WriteAsOperandInternal(Out, CA->getOperand(0),
&TypePrinter, Machine);
&TypePrinter, Machine,
Context);
for (unsigned i = 1, e = CA->getNumOperands(); i != e; ++i) {
Out << ", ";
TypePrinter.print(ETy, Out);
Out << ' ';
WriteAsOperandInternal(Out, CA->getOperand(i), &TypePrinter, Machine);
WriteAsOperandInternal(Out, CA->getOperand(i), &TypePrinter, Machine,
Context);
}
}
Out << ']';
@ -1017,14 +1026,16 @@ static void WriteConstantInternal(raw_ostream &Out, const Constant *CV,
TypePrinter.print(CS->getOperand(0)->getType(), Out);
Out << ' ';
WriteAsOperandInternal(Out, CS->getOperand(0), &TypePrinter, Machine);
WriteAsOperandInternal(Out, CS->getOperand(0), &TypePrinter, Machine,
Context);
for (unsigned i = 1; i < N; i++) {
Out << ", ";
TypePrinter.print(CS->getOperand(i)->getType(), Out);
Out << ' ';
WriteAsOperandInternal(Out, CS->getOperand(i), &TypePrinter, Machine);
WriteAsOperandInternal(Out, CS->getOperand(i), &TypePrinter, Machine,
Context);
}
Out << ' ';
}
@ -1039,7 +1050,8 @@ static void WriteConstantInternal(raw_ostream &Out, const Constant *CV,
Out << "{ ";
TypePrinter.print(CU->getOperand(0)->getType(), Out);
Out << ' ';
WriteAsOperandInternal(Out, CU->getOperand(0), &TypePrinter, Machine);
WriteAsOperandInternal(Out, CU->getOperand(0), &TypePrinter, Machine,
Context);
Out << " }";
return;
}
@ -1051,12 +1063,14 @@ static void WriteConstantInternal(raw_ostream &Out, const Constant *CV,
Out << '<';
TypePrinter.print(ETy, Out);
Out << ' ';
WriteAsOperandInternal(Out, CP->getOperand(0), &TypePrinter, Machine);
WriteAsOperandInternal(Out, CP->getOperand(0), &TypePrinter, Machine,
Context);
for (unsigned i = 1, e = CP->getNumOperands(); i != e; ++i) {
Out << ", ";
TypePrinter.print(ETy, Out);
Out << ' ';
WriteAsOperandInternal(Out, CP->getOperand(i), &TypePrinter, Machine);
WriteAsOperandInternal(Out, CP->getOperand(i), &TypePrinter, Machine,
Context);
}
Out << '>';
return;
@ -1087,7 +1101,7 @@ static void WriteConstantInternal(raw_ostream &Out, const Constant *CV,
for (User::const_op_iterator OI=CE->op_begin(); OI != CE->op_end(); ++OI) {
TypePrinter.print((*OI)->getType(), Out);
Out << ' ';
WriteAsOperandInternal(Out, *OI, &TypePrinter, Machine);
WriteAsOperandInternal(Out, *OI, &TypePrinter, Machine, Context);
if (OI+1 != CE->op_end())
Out << ", ";
}
@ -1112,7 +1126,8 @@ static void WriteConstantInternal(raw_ostream &Out, const Constant *CV,
static void WriteMDNodeBodyInternal(raw_ostream &Out, const MDNode *Node,
TypePrinting *TypePrinter,
SlotTracker *Machine) {
SlotTracker *Machine,
const Module *Context) {
Out << "!{";
for (unsigned mi = 0, me = Node->getNumOperands(); mi != me; ++mi) {
const Value *V = Node->getOperand(mi);
@ -1122,7 +1137,7 @@ static void WriteMDNodeBodyInternal(raw_ostream &Out, const MDNode *Node,
TypePrinter->print(V->getType(), Out);
Out << ' ';
WriteAsOperandInternal(Out, Node->getOperand(mi),
TypePrinter, Machine);
TypePrinter, Machine, Context);
}
if (mi + 1 != me)
Out << ", ";
@ -1138,7 +1153,8 @@ static void WriteMDNodeBodyInternal(raw_ostream &Out, const MDNode *Node,
///
static void WriteAsOperandInternal(raw_ostream &Out, const Value *V,
TypePrinting *TypePrinter,
SlotTracker *Machine) {
SlotTracker *Machine,
const Module *Context) {
if (V->hasName()) {
PrintLLVMName(Out, V);
return;
@ -1147,7 +1163,7 @@ static void WriteAsOperandInternal(raw_ostream &Out, const Value *V,
const Constant *CV = dyn_cast<Constant>(V);
if (CV && !isa<GlobalValue>(CV)) {
assert(TypePrinter && "Constants require TypePrinting!");
WriteConstantInternal(Out, CV, *TypePrinter, Machine);
WriteConstantInternal(Out, CV, *TypePrinter, Machine, Context);
return;
}
@ -1168,12 +1184,16 @@ static void WriteAsOperandInternal(raw_ostream &Out, const Value *V,
if (const MDNode *N = dyn_cast<MDNode>(V)) {
if (N->isFunctionLocal()) {
// Print metadata inline, not via slot reference number.
WriteMDNodeBodyInternal(Out, N, TypePrinter, Machine);
WriteMDNodeBodyInternal(Out, N, TypePrinter, Machine, Context);
return;
}
if (!Machine)
Machine = createSlotTracker(V);
if (!Machine) {
if (N->isFunctionLocal())
Machine = new SlotTracker(N->getFunction());
else
Machine = new SlotTracker(Context);
}
Out << '!' << Machine->getMetadataSlot(N);
return;
}
@ -1227,8 +1247,9 @@ void llvm::WriteAsOperand(raw_ostream &Out, const Value *V,
// Fast path: Don't construct and populate a TypePrinting object if we
// won't be needing any types printed.
if (!PrintType &&
(!isa<Constant>(V) || V->hasName() || isa<GlobalValue>(V))) {
WriteAsOperandInternal(Out, V, 0, 0);
((!isa<Constant>(V) && !isa<MDNode>(V)) ||
V->hasName() || isa<GlobalValue>(V))) {
WriteAsOperandInternal(Out, V, 0, 0, Context);
return;
}
@ -1242,7 +1263,7 @@ void llvm::WriteAsOperand(raw_ostream &Out, const Value *V,
Out << ' ';
}
WriteAsOperandInternal(Out, V, &TypePrinter, 0);
WriteAsOperandInternal(Out, V, &TypePrinter, 0, Context);
}
namespace {
@ -1297,7 +1318,7 @@ void AssemblyWriter::writeOperand(const Value *Operand, bool PrintType) {
TypePrinter.print(Operand->getType(), Out);
Out << ' ';
}
WriteAsOperandInternal(Out, Operand, &TypePrinter, &Machine);
WriteAsOperandInternal(Out, Operand, &TypePrinter, &Machine, TheModule);
}
void AssemblyWriter::writeParamOperand(const Value *Operand,
@ -1314,7 +1335,7 @@ void AssemblyWriter::writeParamOperand(const Value *Operand,
Out << ' ' << Attribute::getAsString(Attrs);
Out << ' ';
// Print the operand
WriteAsOperandInternal(Out, Operand, &TypePrinter, &Machine);
WriteAsOperandInternal(Out, Operand, &TypePrinter, &Machine, TheModule);
}
void AssemblyWriter::printModule(const Module *M) {
@ -1451,7 +1472,7 @@ void AssemblyWriter::printGlobal(const GlobalVariable *GV) {
if (GV->isMaterializable())
Out << "; Materializable\n";
WriteAsOperandInternal(Out, GV, &TypePrinter, &Machine);
WriteAsOperandInternal(Out, GV, &TypePrinter, &Machine, GV->getParent());
Out << " = ";
if (!GV->hasInitializer() && GV->hasExternalLinkage())
@ -1510,7 +1531,7 @@ void AssemblyWriter::printAlias(const GlobalAlias *GA) {
TypePrinter.print(F->getFunctionType(), Out);
Out << "* ";
WriteAsOperandInternal(Out, F, &TypePrinter, &Machine);
WriteAsOperandInternal(Out, F, &TypePrinter, &Machine, F->getParent());
} else if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(Aliasee)) {
TypePrinter.print(GA->getType(), Out);
Out << ' ';
@ -1593,7 +1614,7 @@ void AssemblyWriter::printFunction(const Function *F) {
Out << Attribute::getAsString(Attrs.getRetAttributes()) << ' ';
TypePrinter.print(F->getReturnType(), Out);
Out << ' ';
WriteAsOperandInternal(Out, F, &TypePrinter, &Machine);
WriteAsOperandInternal(Out, F, &TypePrinter, &Machine, F->getParent());
Out << '(';
Machine.incorporateFunction(F);
@ -2029,7 +2050,9 @@ void AssemblyWriter::printInstruction(const Instruction &I) {
} else {
Out << ", !<unknown kind #" << Kind << ">";
}
Out << " !" << Machine.getMetadataSlot(InstMD[i].second);
Out << ' ';
WriteAsOperandInternal(Out, InstMD[i].second, &TypePrinter, &Machine,
TheModule);
}
}
printInfoComment(I);
@ -2077,7 +2100,7 @@ void AssemblyWriter::writeAllMDNodes() {
}
void AssemblyWriter::printMDNodeBody(const MDNode *Node) {
WriteMDNodeBodyInternal(Out, Node, &TypePrinter, &Machine);
WriteMDNodeBodyInternal(Out, Node, &TypePrinter, &Machine, TheModule);
WriteMDNodeComment(Node, Out);
Out << "\n";
}
@ -2138,7 +2161,7 @@ void Value::print(raw_ostream &ROS, AssemblyAnnotationWriter *AAW) const {
TypePrinting TypePrinter;
TypePrinter.print(C->getType(), OS);
OS << ' ';
WriteConstantInternal(OS, C, TypePrinter, 0);
WriteConstantInternal(OS, C, TypePrinter, 0, 0);
} else if (isa<InlineAsm>(this) || isa<MDString>(this) ||
isa<Argument>(this)) {
WriteAsOperand(OS, this, true, 0);