[llvm-commits] [llvm] r78906 - /llvm/trunk/lib/VMCore/AsmWriter.cpp
Dan Gohman
gohman at apple.com
Thu Aug 13 08:27:57 PDT 2009
Author: djg
Date: Thu Aug 13 10:27:57 2009
New Revision: 78906
URL: http://llvm.org/viewvc/llvm-project?rev=78906&view=rev
Log:
Fix a 4x slowdown in llc -asm-verbose caused by the use of
WriteAsOperand in more places.
Now that more things are using WriteAsOperand, its behavior of
constructing a TypePrinting object and populating it with strings for all
the numbered types in the Module on each call is a significant bottleneck.
Fancier solutions could be pursued here, but for now, just bypass the
TypePrinting overhead in obvious cases.
Modified:
llvm/trunk/lib/VMCore/AsmWriter.cpp
Modified: llvm/trunk/lib/VMCore/AsmWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/AsmWriter.cpp?rev=78906&r1=78905&r2=78906&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/AsmWriter.cpp (original)
+++ llvm/trunk/lib/VMCore/AsmWriter.cpp Thu Aug 13 10:27:57 2009
@@ -819,7 +819,7 @@
//===----------------------------------------------------------------------===//
static void WriteAsOperandInternal(raw_ostream &Out, const Value *V,
- TypePrinting &TypePrinter,
+ TypePrinting *TypePrinter,
SlotTracker *Machine);
@@ -881,7 +881,7 @@
else {
TypePrinter.print((*NI)->getType(), Out);
Out << ' ';
- WriteAsOperandInternal(Out, *NI, TypePrinter, &Machine);
+ WriteAsOperandInternal(Out, *NI, &TypePrinter, &Machine);
}
if (++NI != NE)
Out << ", ";
@@ -1035,12 +1035,12 @@
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 << ']';
@@ -1058,14 +1058,14 @@
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 << ' ';
}
@@ -1083,12 +1083,12 @@
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;
@@ -1119,7 +1119,7 @@
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 << ", ";
}
@@ -1148,7 +1148,7 @@
/// 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);
@@ -1157,7 +1157,8 @@
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;
}
@@ -1203,10 +1204,10 @@
} else {
Slot = Machine->getLocalSlot(V);
}
+ delete Machine;
} else {
Slot = -1;
}
- delete Machine;
}
if (Slot != -1)
@@ -1227,6 +1228,14 @@
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;
@@ -1237,7 +1246,7 @@
Out << ' ';
}
- WriteAsOperandInternal(Out, V, TypePrinter, 0);
+ WriteAsOperandInternal(Out, V, &TypePrinter, 0);
}
namespace {
@@ -1307,7 +1316,7 @@
TypePrinter.print(Operand->getType(), Out);
Out << ' ';
}
- WriteAsOperandInternal(Out, Operand, TypePrinter, &Machine);
+ WriteAsOperandInternal(Out, Operand, &TypePrinter, &Machine);
}
}
@@ -1323,7 +1332,7 @@
Out << ' ' << Attribute::getAsString(Attrs);
Out << ' ';
// Print the operand
- WriteAsOperandInternal(Out, Operand, TypePrinter, &Machine);
+ WriteAsOperandInternal(Out, Operand, &TypePrinter, &Machine);
}
}
@@ -1450,7 +1459,7 @@
}
void AssemblyWriter::printGlobal(const GlobalVariable *GV) {
- WriteAsOperandInternal(Out, GV, TypePrinter, &Machine);
+ WriteAsOperandInternal(Out, GV, &TypePrinter, &Machine);
Out << " = ";
if (!GV->hasInitializer() && GV->hasExternalLinkage())
@@ -1503,7 +1512,7 @@
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 << ' ';
@@ -1581,7 +1590,7 @@
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);
More information about the llvm-commits
mailing list