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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@54873 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter.cpp
index 16f26c4..1bc4868 100644
--- a/lib/CodeGen/AsmPrinter.cpp
+++ b/lib/CodeGen/AsmPrinter.cpp
@@ -31,6 +31,7 @@
#include "llvm/Target/TargetOptions.h"
#include "llvm/Target/TargetRegisterInfo.h"
#include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/ADT/SmallString.h"
#include <cerrno>
using namespace llvm;
@@ -800,7 +801,10 @@
O << "((";
EmitConstantValueOnly(Op);
APInt ptrMask = APInt::getAllOnesValue(TD->getABITypeSizeInBits(Ty));
- O << ") & " << ptrMask.toStringUnsigned() << ')';
+
+ SmallString<40> S;
+ ptrMask.toStringUnsigned(S);
+ O << ") & " << S.c_str() << ')';
break;
}
case Instruction::Add:
@@ -1058,15 +1062,14 @@
printDataDirective(type);
EmitConstantValueOnly(CV);
if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
- O << "\t\t\t"
- << TAI->getCommentString()
- << " 0x" << CI->getValue().toStringUnsigned(16);
+ SmallString<40> S;
+ CI->getValue().toStringUnsigned(S, 16);
+ O << "\t\t\t" << TAI->getCommentString() << " 0x" << S.c_str();
}
O << '\n';
}
-void
-AsmPrinter::EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) {
+void AsmPrinter::EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) {
// Target doesn't support this yet!
abort();
}
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 80dda1f..c372874 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -4992,7 +4992,7 @@
}
if (const ConstantSDNode *CSDN = dyn_cast<ConstantSDNode>(this)) {
- cerr << "<" << CSDN->getAPIntValue().toStringUnsigned() << ">";
+ cerr << "<" << CSDN->getAPIntValue() << ">";
} else if (const ConstantFPSDNode *CSDN = dyn_cast<ConstantFPSDNode>(this)) {
if (&CSDN->getValueAPF().getSemantics()==&APFloat::IEEEsingle)
cerr << "<" << CSDN->getValueAPF().convertToFloat() << ">";