Rework the routines that convert AP[S]Int into a string. Now, instead of
returning an std::string by value, it fills in a SmallString/SmallVector
passed in. This significantly reduces string thrashing in some cases.
More specifically, this:
- Adds an operator<< and a print method for APInt that allows you to
directly send them to an ostream.
- Reimplements APInt::toString to be much simpler and more efficient
algorithmically in addition to not thrashing strings quite as much.
This speeds up llvm-dis on kc++ by 7%, and may also slightly speed up the
asmprinter. This also fixes a bug I introduced into the asmwriter in a
previous patch w.r.t. alias printing.
llvm-svn: 54873
diff --git a/llvm/lib/VMCore/AsmWriter.cpp b/llvm/lib/VMCore/AsmWriter.cpp
index fa512e0..ad7b5c3 100644
--- a/llvm/lib/VMCore/AsmWriter.cpp
+++ b/llvm/lib/VMCore/AsmWriter.cpp
@@ -507,13 +507,18 @@
std::map<const Type *, std::string> &TypeTable,
SlotMachine *Machine) {
const int IndentSize = 4;
+ // FIXME: WHY IS INDENT STATIC??
static std::string Indent = "\n";
if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
- if (CI->getType() == Type::Int1Ty)
+ if (CI->getType() == Type::Int1Ty) {
Out << (CI->getZExtValue() ? "true" : "false");
- else
- Out << CI->getValue().toStringSigned(10);
- } else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
+ return;
+ }
+ Out << CI->getValue();
+ return;
+ }
+
+ if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
if (&CFP->getValueAPF().getSemantics() == &APFloat::IEEEdouble ||
&CFP->getValueAPF().getSemantics() == &APFloat::IEEEsingle) {
// We would like to output the FP constant value in exponential notation,
@@ -522,8 +527,8 @@
// the value back and get the same value.
//
bool isDouble = &CFP->getValueAPF().getSemantics()==&APFloat::IEEEdouble;
- double Val = (isDouble) ? CFP->getValueAPF().convertToDouble() :
- CFP->getValueAPF().convertToFloat();
+ double Val = isDouble ? CFP->getValueAPF().convertToDouble() :
+ CFP->getValueAPF().convertToFloat();
std::string StrVal = ftostr(CFP->getValueAPF());
// Check to make sure that the stringized number is not some string like
@@ -1054,7 +1059,7 @@
printType(F->getFunctionType());
Out << "* ";
- if (!F->hasName())
+ if (F->hasName())
PrintLLVMName(Out, F);
else
Out << "@\"\"";