llvm.org GIT mirror llvm / d6c0f65
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78906 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 10 years ago
1 changed file(s) with 27 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
818818 //===----------------------------------------------------------------------===//
819819
820820 static void WriteAsOperandInternal(raw_ostream &Out, const Value *V,
821 TypePrinting &TypePrinter,
821 TypePrinting *TypePrinter,
822822 SlotTracker *Machine);
823823
824824
880880 else {
881881 TypePrinter.print((*NI)->getType(), Out);
882882 Out << ' ';
883 WriteAsOperandInternal(Out, *NI, TypePrinter, &Machine);
883 WriteAsOperandInternal(Out, *NI, &TypePrinter, &Machine);
884884 }
885885 if (++NI != NE)
886886 Out << ", ";
10341034 TypePrinter.print(ETy, Out);
10351035 Out << ' ';
10361036 WriteAsOperandInternal(Out, CA->getOperand(0),
1037 TypePrinter, Machine);
1037 &TypePrinter, Machine);
10381038 for (unsigned i = 1, e = CA->getNumOperands(); i != e; ++i) {
10391039 Out << ", ";
10401040 TypePrinter.print(ETy, Out);
10411041 Out << ' ';
1042 WriteAsOperandInternal(Out, CA->getOperand(i), TypePrinter, Machine);
1042 WriteAsOperandInternal(Out, CA->getOperand(i), &TypePrinter, Machine);
10431043 }
10441044 }
10451045 Out << ']';
10571057 TypePrinter.print(CS->getOperand(0)->getType(), Out);
10581058 Out << ' ';
10591059
1060 WriteAsOperandInternal(Out, CS->getOperand(0), TypePrinter, Machine);
1060 WriteAsOperandInternal(Out, CS->getOperand(0), &TypePrinter, Machine);
10611061
10621062 for (unsigned i = 1; i < N; i++) {
10631063 Out << ", ";
10641064 TypePrinter.print(CS->getOperand(i)->getType(), Out);
10651065 Out << ' ';
10661066
1067 WriteAsOperandInternal(Out, CS->getOperand(i), TypePrinter, Machine);
1067 WriteAsOperandInternal(Out, CS->getOperand(i), &TypePrinter, Machine);
10681068 }
10691069 Out << ' ';
10701070 }
10821082 Out << '<';
10831083 TypePrinter.print(ETy, Out);
10841084 Out << ' ';
1085 WriteAsOperandInternal(Out, CP->getOperand(0), TypePrinter, Machine);
1085 WriteAsOperandInternal(Out, CP->getOperand(0), &TypePrinter, Machine);
10861086 for (unsigned i = 1, e = CP->getNumOperands(); i != e; ++i) {
10871087 Out << ", ";
10881088 TypePrinter.print(ETy, Out);
10891089 Out << ' ';
1090 WriteAsOperandInternal(Out, CP->getOperand(i), TypePrinter, Machine);
1090 WriteAsOperandInternal(Out, CP->getOperand(i), &TypePrinter, Machine);
10911091 }
10921092 Out << '>';
10931093 return;
11181118 for (User::const_op_iterator OI=CE->op_begin(); OI != CE->op_end(); ++OI) {
11191119 TypePrinter.print((*OI)->getType(), Out);
11201120 Out << ' ';
1121 WriteAsOperandInternal(Out, *OI, TypePrinter, Machine);
1121 WriteAsOperandInternal(Out, *OI, &TypePrinter, Machine);
11221122 if (OI+1 != CE->op_end())
11231123 Out << ", ";
11241124 }
11471147 /// the whole instruction that generated it.
11481148 ///
11491149 static void WriteAsOperandInternal(raw_ostream &Out, const Value *V,
1150 TypePrinting &TypePrinter,
1150 TypePrinting *TypePrinter,
11511151 SlotTracker *Machine) {
11521152 if (V->hasName()) {
11531153 PrintLLVMName(Out, V);
11561156
11571157 const Constant *CV = dyn_cast(V);
11581158 if (CV && !isa(CV)) {
1159 WriteConstantInt(Out, CV, TypePrinter, Machine);
1159 assert(TypePrinter && "Constants require TypePrinting!");
1160 WriteConstantInt(Out, CV, *TypePrinter, Machine);
11601161 return;
11611162 }
11621163
12021203 } else {
12031204 Slot = Machine->getLocalSlot(V);
12041205 }
1206 delete Machine;
12051207 } else {
12061208 Slot = -1;
12071209 }
1208 delete Machine;
12091210 }
12101211
12111212 if (Slot != -1)
12261227
12271228 void llvm::WriteAsOperand(raw_ostream &Out, const Value *V,
12281229 bool PrintType, const Module *Context) {
1230
1231 // Fast path: Don't construct and populate a TypePrinting object if we
1232 // won't be needing any types printed.
1233 if (!PrintType && !isa(V)) {
1234 WriteAsOperandInternal(Out, V, 0, 0);
1235 return;
1236 }
1237
12291238 if (Context == 0) Context = getModuleFromVal(V);
12301239
12311240 TypePrinting TypePrinter;
12361245 Out << ' ';
12371246 }
12381247
1239 WriteAsOperandInternal(Out, V, TypePrinter, 0);
1248 WriteAsOperandInternal(Out, V, &TypePrinter, 0);
12401249 }
12411250
12421251 namespace {
13061315 TypePrinter.print(Operand->getType(), Out);
13071316 Out << ' ';
13081317 }
1309 WriteAsOperandInternal(Out, Operand, TypePrinter, &Machine);
1318 WriteAsOperandInternal(Out, Operand, &TypePrinter, &Machine);
13101319 }
13111320 }
13121321
13221331 Out << ' ' << Attribute::getAsString(Attrs);
13231332 Out << ' ';
13241333 // Print the operand
1325 WriteAsOperandInternal(Out, Operand, TypePrinter, &Machine);
1334 WriteAsOperandInternal(Out, Operand, &TypePrinter, &Machine);
13261335 }
13271336 }
13281337
14491458 }
14501459
14511460 void AssemblyWriter::printGlobal(const GlobalVariable *GV) {
1452 WriteAsOperandInternal(Out, GV, TypePrinter, &Machine);
1461 WriteAsOperandInternal(Out, GV, &TypePrinter, &Machine);
14531462 Out << " = ";
14541463
14551464 if (!GV->hasInitializer() && GV->hasExternalLinkage())
15021511 TypePrinter.print(F->getFunctionType(), Out);
15031512 Out << "* ";
15041513
1505 WriteAsOperandInternal(Out, F, TypePrinter, &Machine);
1514 WriteAsOperandInternal(Out, F, &TypePrinter, &Machine);
15061515 } else if (const GlobalAlias *GA = dyn_cast(Aliasee)) {
15071516 TypePrinter.print(GA->getType(), Out);
15081517 Out << ' ';
15801589 Out << Attribute::getAsString(Attrs.getRetAttributes()) << ' ';
15811590 TypePrinter.print(F->getReturnType(), Out);
15821591 Out << ' ';
1583 WriteAsOperandInternal(Out, F, TypePrinter, &Machine);
1592 WriteAsOperandInternal(Out, F, &TypePrinter, &Machine);
15841593 Out << '(';
15851594 Machine.incorporateFunction(F);
15861595