mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-05 13:26:55 +00:00
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
This commit is contained in:
@@ -19,7 +19,6 @@
|
||||
|
||||
namespace llvm {
|
||||
|
||||
|
||||
class APSInt : public APInt {
|
||||
bool IsUnsigned;
|
||||
public:
|
||||
@@ -58,11 +57,16 @@ public:
|
||||
void setIsUnsigned(bool Val) { IsUnsigned = Val; }
|
||||
void setIsSigned(bool Val) { IsUnsigned = !Val; }
|
||||
|
||||
/// This is used internally to convert an APInt to a string.
|
||||
/// @brief Converts an APInt to a std::string
|
||||
std::string toString(uint8_t Radix = 10) const {
|
||||
/// toString - Append this APSInt to the specified SmallString.
|
||||
void toString(SmallVectorImpl<char> &Str, unsigned Radix = 10) const {
|
||||
return APInt::toString(Str, Radix, isSigned());
|
||||
}
|
||||
/// toString - Converts an APInt to a std::string. This is an inefficient
|
||||
/// method, your should prefer passing in a SmallString instead.
|
||||
std::string toString(unsigned Radix) const {
|
||||
return APInt::toString(Radix, isSigned());
|
||||
}
|
||||
using APInt::toString;
|
||||
|
||||
APSInt& extend(uint32_t width) {
|
||||
if (IsUnsigned)
|
||||
@@ -235,6 +239,12 @@ public:
|
||||
void Profile(FoldingSetNodeID& ID) const;
|
||||
};
|
||||
|
||||
inline std::ostream &operator<<(std::ostream &OS, const APSInt &I) {
|
||||
I.print(OS, I.isSigned());
|
||||
return OS;
|
||||
}
|
||||
|
||||
|
||||
} // end namespace llvm
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user