//===----------------------------------------------------------------------===//
static void WriteAsOperandInternal(raw_ostream &Out, const Value *V,
- TypePrinting &TypePrinter,
+ TypePrinting *TypePrinter,
SlotTracker *Machine);
else {
TypePrinter.print((*NI)->getType(), Out);
Out << ' ';
- WriteAsOperandInternal(Out, *NI, TypePrinter, &Machine);
+ WriteAsOperandInternal(Out, *NI, &TypePrinter, &Machine);
}
if (++NI != NE)
Out << ", ";
TypePrinter.print(ETy, Out);
Out << ' ';
WriteAsOperandInternal(Out, CA->getOperand(0),
- TypePrinter, Machine);
+ &TypePrinter, Machine);
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);
}
}
Out << ']';
TypePrinter.print(CS->getOperand(0)->getType(), Out);
Out << ' ';
- WriteAsOperandInternal(Out, CS->getOperand(0), TypePrinter, Machine);
+ WriteAsOperandInternal(Out, CS->getOperand(0), &TypePrinter, Machine);
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);
}
Out << ' ';
}
Out << '<';
TypePrinter.print(ETy, Out);
Out << ' ';
- WriteAsOperandInternal(Out, CP->getOperand(0), TypePrinter, Machine);
+ WriteAsOperandInternal(Out, CP->getOperand(0), &TypePrinter, Machine);
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);
}
Out << '>';
return;
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);
if (OI+1 != CE->op_end())
Out << ", ";
}
/// the whole instruction that generated it.
///
static void WriteAsOperandInternal(raw_ostream &Out, const Value *V,
- TypePrinting &TypePrinter,
+ TypePrinting *TypePrinter,
SlotTracker *Machine) {
if (V->hasName()) {
PrintLLVMName(Out, V);
const Constant *CV = dyn_cast<Constant>(V);
if (CV && !isa<GlobalValue>(CV)) {
- WriteConstantInt(Out, CV, TypePrinter, Machine);
+ assert(TypePrinter && "Constants require TypePrinting!");
+ WriteConstantInt(Out, CV, *TypePrinter, Machine);
return;
}
} else {
Slot = Machine->getLocalSlot(V);
}
+ delete Machine;
} else {
Slot = -1;
}
- delete Machine;
}
if (Slot != -1)
void llvm::WriteAsOperand(raw_ostream &Out, const Value *V,
bool PrintType, const Module *Context) {
+
+ // Fast path: Don't construct and populate a TypePrinting object if we
+ // won't be needing any types printed.
+ if (!PrintType && !isa<Constant>(V)) {
+ WriteAsOperandInternal(Out, V, 0, 0);
+ return;
+ }
+
if (Context == 0) Context = getModuleFromVal(V);
TypePrinting TypePrinter;
Out << ' ';
}
- WriteAsOperandInternal(Out, V, TypePrinter, 0);
+ WriteAsOperandInternal(Out, V, &TypePrinter, 0);
}
namespace {
TypePrinter.print(Operand->getType(), Out);
Out << ' ';
}
- WriteAsOperandInternal(Out, Operand, TypePrinter, &Machine);
+ WriteAsOperandInternal(Out, Operand, &TypePrinter, &Machine);
}
}
Out << ' ' << Attribute::getAsString(Attrs);
Out << ' ';
// Print the operand
- WriteAsOperandInternal(Out, Operand, TypePrinter, &Machine);
+ WriteAsOperandInternal(Out, Operand, &TypePrinter, &Machine);
}
}
}
void AssemblyWriter::printGlobal(const GlobalVariable *GV) {
- WriteAsOperandInternal(Out, GV, TypePrinter, &Machine);
+ WriteAsOperandInternal(Out, GV, &TypePrinter, &Machine);
Out << " = ";
if (!GV->hasInitializer() && GV->hasExternalLinkage())
TypePrinter.print(F->getFunctionType(), Out);
Out << "* ";
- WriteAsOperandInternal(Out, F, TypePrinter, &Machine);
+ WriteAsOperandInternal(Out, F, &TypePrinter, &Machine);
} else if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(Aliasee)) {
TypePrinter.print(GA->getType(), Out);
Out << ' ';
Out << Attribute::getAsString(Attrs.getRetAttributes()) << ' ';
TypePrinter.print(F->getReturnType(), Out);
Out << ' ';
- WriteAsOperandInternal(Out, F, TypePrinter, &Machine);
+ WriteAsOperandInternal(Out, F, &TypePrinter, &Machine);
Out << '(';
Machine.incorporateFunction(F);