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:
Chris Lattner 2008-08-17 07:19:36 +00:00
parent b6c8a4098f
commit fad86b003a
13 changed files with 170 additions and 140 deletions

View File

@ -116,6 +116,6 @@ int main(int argc, char **argv) {
GenericValue GV = EE->runFunction(FibF, Args); GenericValue GV = EE->runFunction(FibF, Args);
// import result of execution // import result of execution
std::cout << "Result: " << GV.IntVal.toStringUnsigned(10) << "\n"; std::cout << "Result: " << GV.IntVal << "\n";
return 0; return 0;
} }

View File

@ -107,6 +107,6 @@ int main() {
GenericValue gv = EE->runFunction(FooF, noargs); GenericValue gv = EE->runFunction(FooF, noargs);
// Import result of execution: // Import result of execution:
std::cout << "Result: " << gv.IntVal.toStringUnsigned(10) << "\n"; std::cout << "Result: " << gv.IntVal << "\n";
return 0; return 0;
} }

View File

@ -17,6 +17,7 @@
#include "llvm/Support/DataTypes.h" #include "llvm/Support/DataTypes.h"
#include <cassert> #include <cassert>
#include <iosfwd>
#include <string> #include <string>
namespace llvm { namespace llvm {
@ -24,6 +25,9 @@ namespace llvm {
class Deserializer; class Deserializer;
class FoldingSetNodeID; class FoldingSetNodeID;
template<typename T>
class SmallVectorImpl;
/* An unsigned host type used as a single part of a multi-part /* An unsigned host type used as a single part of a multi-part
bignum. */ bignum. */
typedef uint64_t integerPart; typedef uint64_t integerPart;
@ -468,7 +472,7 @@ public:
/// Performs logical negation operation on this APInt. /// Performs logical negation operation on this APInt.
/// @returns true if *this is zero, false otherwise. /// @returns true if *this is zero, false otherwise.
/// @brief Logical negation operator. /// @brief Logical negation operator.
bool operator !() const; bool operator!() const;
/// @} /// @}
/// @name Assignment Operators /// @name Assignment Operators
@ -972,25 +976,29 @@ public:
/// @name Conversion Functions /// @name Conversion Functions
/// @{ /// @{
/// This is used internally to convert an APInt to a string. void print(std::ostream &OS, bool isSigned) const;
/// @brief Converts an APInt to a std::string
std::string toString(uint8_t radix, bool wantSigned) const; /// toString - Converts an APInt to a string and append it to Str. Str is
/// commonly a SmallString.
void toString(SmallVectorImpl<char> &Str, unsigned Radix, bool Signed) const;
/// Considers the APInt to be unsigned and converts it into a string in the /// Considers the APInt to be unsigned and converts it into a string in the
/// radix given. The radix can be 2, 8, 10 or 16. /// radix given. The radix can be 2, 8, 10 or 16.
/// @returns a character interpretation of the APInt void toStringUnsigned(SmallVectorImpl<char> &Str, unsigned Radix = 10) const {
/// @brief Convert unsigned APInt to string representation. return toString(Str, Radix, false);
std::string toStringUnsigned(uint8_t radix = 10) const {
return toString(radix, false);
} }
/// Considers the APInt to be signed and converts it into a string in the /// Considers the APInt to be signed and converts it into a string in the
/// radix given. The radix can be 2, 8, 10 or 16. /// radix given. The radix can be 2, 8, 10 or 16.
/// @returns a character interpretation of the APInt void toStringSigned(SmallVectorImpl<char> &Str, unsigned Radix = 10) const {
/// @brief Convert signed APInt to string representation. return toString(Str, Radix, true);
std::string toStringSigned(uint8_t radix = 10) const {
return toString(radix, true);
} }
/// toString - This returns the APInt as a std::string. Note that this is an
/// inefficient method. It is better to pass in a SmallVector/SmallString
/// to the methods above to avoid thrashing the heap for the string.
std::string toString(unsigned Radix, bool Signed) const;
/// @returns a byte-swapped representation of this APInt Value. /// @returns a byte-swapped representation of this APInt Value.
APInt byteSwap() const; APInt byteSwap() const;
@ -1237,6 +1245,11 @@ inline bool operator!=(uint64_t V1, const APInt& V2) {
return V2 != V1; return V2 != V1;
} }
inline std::ostream &operator<<(std::ostream &OS, const APInt &I) {
I.print(OS, true);
return OS;
}
namespace APIntOps { namespace APIntOps {
/// @brief Determine the smaller of two APInts considered to be signed. /// @brief Determine the smaller of two APInts considered to be signed.

View File

@ -19,7 +19,6 @@
namespace llvm { namespace llvm {
class APSInt : public APInt { class APSInt : public APInt {
bool IsUnsigned; bool IsUnsigned;
public: public:
@ -58,11 +57,16 @@ public:
void setIsUnsigned(bool Val) { IsUnsigned = Val; } void setIsUnsigned(bool Val) { IsUnsigned = Val; }
void setIsSigned(bool Val) { IsUnsigned = !Val; } void setIsSigned(bool Val) { IsUnsigned = !Val; }
/// This is used internally to convert an APInt to a string. /// toString - Append this APSInt to the specified SmallString.
/// @brief Converts an APInt to a std::string void toString(SmallVectorImpl<char> &Str, unsigned Radix = 10) const {
std::string toString(uint8_t 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()); return APInt::toString(Radix, isSigned());
} }
using APInt::toString;
APSInt& extend(uint32_t width) { APSInt& extend(uint32_t width) {
if (IsUnsigned) if (IsUnsigned)
@ -235,6 +239,12 @@ public:
void Profile(FoldingSetNodeID& ID) const; 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 } // end namespace llvm
#endif #endif

View File

@ -170,7 +170,7 @@ struct ValID {
case GlobalID : return '@' + utostr(Num); case GlobalID : return '@' + utostr(Num);
case LocalName : return *Name; case LocalName : return *Name;
case GlobalName : return *Name; case GlobalName : return *Name;
case ConstAPInt : return ConstPoolInt->toString(); case ConstAPInt : return ConstPoolInt->toString(10);
case ConstFPVal : return ftostr(*ConstPoolFP); case ConstFPVal : return ftostr(*ConstPoolFP);
case ConstNullVal : return "null"; case ConstNullVal : return "null";
case ConstUndefVal : return "undef"; case ConstUndefVal : return "undef";

View File

@ -31,6 +31,7 @@
#include "llvm/Target/TargetOptions.h" #include "llvm/Target/TargetOptions.h"
#include "llvm/Target/TargetRegisterInfo.h" #include "llvm/Target/TargetRegisterInfo.h"
#include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallString.h"
#include <cerrno> #include <cerrno>
using namespace llvm; using namespace llvm;
@ -800,7 +801,10 @@ void AsmPrinter::EmitConstantValueOnly(const Constant *CV) {
O << "(("; O << "((";
EmitConstantValueOnly(Op); EmitConstantValueOnly(Op);
APInt ptrMask = APInt::getAllOnesValue(TD->getABITypeSizeInBits(Ty)); APInt ptrMask = APInt::getAllOnesValue(TD->getABITypeSizeInBits(Ty));
O << ") & " << ptrMask.toStringUnsigned() << ')';
SmallString<40> S;
ptrMask.toStringUnsigned(S);
O << ") & " << S.c_str() << ')';
break; break;
} }
case Instruction::Add: case Instruction::Add:
@ -1058,15 +1062,14 @@ void AsmPrinter::EmitGlobalConstant(const Constant *CV) {
printDataDirective(type); printDataDirective(type);
EmitConstantValueOnly(CV); EmitConstantValueOnly(CV);
if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) { if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
O << "\t\t\t" SmallString<40> S;
<< TAI->getCommentString() CI->getValue().toStringUnsigned(S, 16);
<< " 0x" << CI->getValue().toStringUnsigned(16); O << "\t\t\t" << TAI->getCommentString() << " 0x" << S.c_str();
} }
O << '\n'; O << '\n';
} }
void void AsmPrinter::EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) {
AsmPrinter::EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) {
// Target doesn't support this yet! // Target doesn't support this yet!
abort(); abort();
} }

View File

@ -4992,7 +4992,7 @@ void SDNode::dump(const SelectionDAG *G) const {
} }
if (const ConstantSDNode *CSDN = dyn_cast<ConstantSDNode>(this)) { if (const ConstantSDNode *CSDN = dyn_cast<ConstantSDNode>(this)) {
cerr << "<" << CSDN->getAPIntValue().toStringUnsigned() << ">"; cerr << "<" << CSDN->getAPIntValue() << ">";
} else if (const ConstantFPSDNode *CSDN = dyn_cast<ConstantFPSDNode>(this)) { } else if (const ConstantFPSDNode *CSDN = dyn_cast<ConstantFPSDNode>(this)) {
if (&CSDN->getValueAPF().getSemantics()==&APFloat::IEEEsingle) if (&CSDN->getValueAPF().getSemantics()==&APFloat::IEEEsingle)
cerr << "<" << CSDN->getValueAPF().convertToFloat() << ">"; cerr << "<" << CSDN->getValueAPF().convertToFloat() << ">";

View File

@ -14,9 +14,8 @@
#include "llvm/ADT/APFloat.h" #include "llvm/ADT/APFloat.h"
#include "llvm/ADT/FoldingSet.h" #include "llvm/ADT/FoldingSet.h"
#include <cassert>
#include <cstring>
#include "llvm/Support/MathExtras.h" #include "llvm/Support/MathExtras.h"
#include <cstring>
using namespace llvm; using namespace llvm;

View File

@ -15,14 +15,13 @@
#define DEBUG_TYPE "apint" #define DEBUG_TYPE "apint"
#include "llvm/ADT/APInt.h" #include "llvm/ADT/APInt.h"
#include "llvm/ADT/FoldingSet.h" #include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/Debug.h" #include "llvm/Support/Debug.h"
#include "llvm/Support/MathExtras.h" #include "llvm/Support/MathExtras.h"
#include <math.h> #include <cmath>
#include <limits> #include <limits>
#include <cstring> #include <cstring>
#include <cstdlib> #include <cstdlib>
#include <iomanip>
using namespace llvm; using namespace llvm;
/// This enumeration just provides for internal constants used in this /// This enumeration just provides for internal constants used in this
@ -1478,12 +1477,14 @@ static void KnuthDiv(uint32_t *u, uint32_t *v, uint32_t *q, uint32_t* r,
// is 2^31 so we just set it to -1u. // is 2^31 so we just set it to -1u.
uint64_t b = uint64_t(1) << 32; uint64_t b = uint64_t(1) << 32;
#if 0
DEBUG(cerr << "KnuthDiv: m=" << m << " n=" << n << '\n'); DEBUG(cerr << "KnuthDiv: m=" << m << " n=" << n << '\n');
DEBUG(cerr << "KnuthDiv: original:"); DEBUG(cerr << "KnuthDiv: original:");
DEBUG(for (int i = m+n; i >=0; i--) cerr << " " << std::setbase(16) << u[i]); DEBUG(for (int i = m+n; i >=0; i--) cerr << " " << std::setbase(16) << u[i]);
DEBUG(cerr << " by"); DEBUG(cerr << " by");
DEBUG(for (int i = n; i >0; i--) cerr << " " << std::setbase(16) << v[i-1]); DEBUG(for (int i = n; i >0; i--) cerr << " " << std::setbase(16) << v[i-1]);
DEBUG(cerr << '\n'); DEBUG(cerr << '\n');
#endif
// D1. [Normalize.] Set d = b / (v[n-1] + 1) and multiply all the digits of // D1. [Normalize.] Set d = b / (v[n-1] + 1) and multiply all the digits of
// u and v by d. Note that we have taken Knuth's advice here to use a power // u and v by d. Note that we have taken Knuth's advice here to use a power
// of 2 value for d such that d * v[n-1] >= b/2 (b is the base). A power of // of 2 value for d such that d * v[n-1] >= b/2 (b is the base). A power of
@ -1508,11 +1509,13 @@ static void KnuthDiv(uint32_t *u, uint32_t *v, uint32_t *q, uint32_t* r,
} }
} }
u[m+n] = u_carry; u[m+n] = u_carry;
#if 0
DEBUG(cerr << "KnuthDiv: normal:"); DEBUG(cerr << "KnuthDiv: normal:");
DEBUG(for (int i = m+n; i >=0; i--) cerr << " " << std::setbase(16) << u[i]); DEBUG(for (int i = m+n; i >=0; i--) cerr << " " << std::setbase(16) << u[i]);
DEBUG(cerr << " by"); DEBUG(cerr << " by");
DEBUG(for (int i = n; i >0; i--) cerr << " " << std::setbase(16) << v[i-1]); DEBUG(for (int i = n; i >0; i--) cerr << " " << std::setbase(16) << v[i-1]);
DEBUG(cerr << '\n'); DEBUG(cerr << '\n');
#endif
// D2. [Initialize j.] Set j to m. This is the loop counter over the places. // D2. [Initialize j.] Set j to m. This is the loop counter over the places.
int j = m; int j = m;
@ -1636,7 +1639,9 @@ static void KnuthDiv(uint32_t *u, uint32_t *v, uint32_t *q, uint32_t* r,
} }
DEBUG(cerr << '\n'); DEBUG(cerr << '\n');
} }
#if 0
DEBUG(cerr << std::setbase(10) << '\n'); DEBUG(cerr << std::setbase(10) << '\n');
#endif
} }
void APInt::divide(const APInt LHS, uint32_t lhsWords, void APInt::divide(const APInt LHS, uint32_t lhsWords,
@ -2001,114 +2006,112 @@ void APInt::fromString(uint32_t numbits, const char *str, uint32_t slen,
} }
} }
std::string APInt::toString(uint8_t radix, bool wantSigned) const { void APInt::toString(SmallVectorImpl<char> &Str, unsigned Radix,
assert((radix == 10 || radix == 8 || radix == 16 || radix == 2) && bool Signed) const {
assert((Radix == 10 || Radix == 8 || Radix == 16 || Radix == 2) &&
"Radix should be 2, 8, 10, or 16!"); "Radix should be 2, 8, 10, or 16!");
static const char *const digits[] = {
"0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F" // First, check for a zero value and just short circuit the logic below.
}; if (*this == 0) {
std::string result; Str.push_back('0');
uint32_t bits_used = getActiveBits(); return;
}
static const char Digits[] = "0123456789ABCDEF";
if (isSingleWord()) { if (isSingleWord()) {
char buf[65]; char Buffer[65];
const char *format = (radix == 10 ? (wantSigned ? "%lld" : "%llu") : char *BufPtr = Buffer+65;
(radix == 16 ? "%llX" : (radix == 8 ? "%llo" : 0)));
if (format) { uint64_t N;
if (wantSigned) { if (Signed) {
int64_t sextVal = (int64_t(VAL) << (APINT_BITS_PER_WORD-BitWidth)) >> int64_t I = getSExtValue();
(APINT_BITS_PER_WORD-BitWidth); if (I < 0) {
sprintf(buf, format, sextVal); Str.push_back('-');
} else I = -I;
sprintf(buf, format, VAL); }
N = I;
} else { } else {
memset(buf, 0, 65); N = getZExtValue();
uint64_t v = VAL;
while (bits_used) {
uint32_t bit = (uint32_t)v & 1;
bits_used--;
buf[bits_used] = digits[bit][0];
v >>=1;
}
} }
result = buf;
return result; while (N) {
*--BufPtr = Digits[N % Radix];
N /= Radix;
}
Str.append(BufPtr, Buffer+65);
return;
} }
if (radix != 10) { APInt Tmp(*this);
// For the 2, 8 and 16 bit cases, we can just shift instead of divide
// because the number of bits per digit (1,3 and 4 respectively) divides if (Signed && isNegative()) {
// equaly. We just shift until there value is zero.
// First, check for a zero value and just short circuit the logic below.
if (*this == 0)
result = "0";
else {
APInt tmp(*this);
size_t insert_at = 0;
if (wantSigned && this->isNegative()) {
// They want to print the signed version and it is a negative value
// Flip the bits and add one to turn it into the equivalent positive
// value and put a '-' in the result.
tmp.flip();
tmp++;
result = "-";
insert_at = 1;
}
// Just shift tmp right for each digit width until it becomes zero
uint32_t shift = (radix == 16 ? 4 : (radix == 8 ? 3 : 1));
uint64_t mask = radix - 1;
APInt zero(tmp.getBitWidth(), 0);
while (tmp.ne(zero)) {
unsigned digit =
(unsigned)((tmp.isSingleWord() ? tmp.VAL : tmp.pVal[0]) & mask);
result.insert(insert_at, digits[digit]);
tmp = tmp.lshr(shift);
}
}
return result;
}
APInt tmp(*this);
APInt divisor(4, radix);
APInt zero(tmp.getBitWidth(), 0);
size_t insert_at = 0;
if (wantSigned && tmp[BitWidth-1]) {
// They want to print the signed version and it is a negative value // They want to print the signed version and it is a negative value
// Flip the bits and add one to turn it into the equivalent positive // Flip the bits and add one to turn it into the equivalent positive
// value and put a '-' in the result. // value and put a '-' in the result.
tmp.flip(); Tmp.flip();
tmp++; Tmp++;
result = "-"; Str.push_back('-');
insert_at = 1;
} }
if (tmp == zero)
result = "0"; // We insert the digits backward, then reverse them to get the right order.
else while (tmp.ne(zero)) { unsigned StartDig = Str.size();
APInt APdigit(1,0);
APInt tmp2(tmp.getBitWidth(), 0); // For the 2, 8 and 16 bit cases, we can just shift instead of divide
divide(tmp, tmp.getNumWords(), divisor, divisor.getNumWords(), &tmp2, // because the number of bits per digit (1, 3 and 4 respectively) divides
&APdigit); // equaly. We just shift until the value is zero.
uint32_t digit = (uint32_t)APdigit.getZExtValue(); if (Radix != 10) {
assert(digit < radix && "divide failed"); // Just shift tmp right for each digit width until it becomes zero
result.insert(insert_at,digits[digit]); unsigned ShiftAmt = (Radix == 16 ? 4 : (Radix == 8 ? 3 : 1));
tmp = tmp2; unsigned MaskAmt = Radix - 1;
while (Tmp != 0) {
unsigned Digit = unsigned(Tmp.getRawData()[0]) & MaskAmt;
Str.push_back(Digits[Digit]);
Tmp = Tmp.lshr(ShiftAmt);
}
} else {
APInt divisor(4, 10);
while (Tmp != 0) {
APInt APdigit(1, 0);
APInt tmp2(Tmp.getBitWidth(), 0);
divide(Tmp, Tmp.getNumWords(), divisor, divisor.getNumWords(), &tmp2,
&APdigit);
uint32_t Digit = (uint32_t)APdigit.getZExtValue();
assert(Digit < Radix && "divide failed");
Str.push_back(Digits[Digit]);
Tmp = tmp2;
}
} }
return result; // Reverse the digits before returning.
std::reverse(Str.begin()+StartDig, Str.end());
} }
void APInt::dump() const /// toString - This returns the APInt as a std::string. Note that this is an
{ /// inefficient method. It is better to pass in a SmallVector/SmallString
cerr << "APInt(" << BitWidth << ")=" << std::setbase(16); /// to the methods above.
if (isSingleWord()) std::string APInt::toString(unsigned Radix = 10, bool Signed = true) const {
cerr << VAL; SmallString<40> S;
else for (unsigned i = getNumWords(); i > 0; i--) { toString(S, Radix, Signed);
cerr << pVal[i-1] << " "; return S.c_str();
}
cerr << " U(" << this->toStringUnsigned(10) << ") S("
<< this->toStringSigned(10) << ")" << std::setbase(10);
} }
void APInt::dump() const {
SmallString<40> S, U;
this->toStringUnsigned(U);
this->toStringSigned(S);
fprintf(stderr, "APInt(%db, %su %ss)", BitWidth, U.c_str(), S.c_str());
}
void APInt::print(std::ostream &OS, bool isSigned) const {
SmallString<40> S;
this->toString(S, 10, isSigned);
OS << S.c_str();
}
// This implements a variety of operations on a representation of // This implements a variety of operations on a representation of
// arbitrary precision, two's-complement, bignum integer values. // arbitrary precision, two's-complement, bignum integer values.

View File

@ -463,8 +463,7 @@ ConstantRange ConstantRange::truncate(uint32_t DstTySize) const {
/// print - Print out the bounds to a stream... /// print - Print out the bounds to a stream...
/// ///
void ConstantRange::print(std::ostream &OS) const { void ConstantRange::print(std::ostream &OS) const {
OS << "[" << Lower.toStringSigned(10) << "," OS << "[" << Lower << "," << Upper << ")";
<< Upper.toStringSigned(10) << ")";
} }
/// dump - Allow printing from a debugger easily... /// dump - Allow printing from a debugger easily...

View File

@ -733,8 +733,8 @@ namespace {
} }
if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) { if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
Out << "ConstantInt* " << constName << " = ConstantInt::get(APInt(" Out << "ConstantInt* " << constName << " = ConstantInt::get(APInt("
<< cast<IntegerType>(CI->getType())->getBitWidth() << ", " << cast<IntegerType>(CI->getType())->getBitWidth() << ", \""
<< " \"" << CI->getValue().toStringSigned(10) << "\", 10));"; << CI->getValue() << "\", 10));";
} else if (isa<ConstantAggregateZero>(CV)) { } else if (isa<ConstantAggregateZero>(CV)) {
Out << "ConstantAggregateZero* " << constName Out << "ConstantAggregateZero* " << constName
<< " = ConstantAggregateZero::get(" << typeName << ");"; << " = ConstantAggregateZero::get(" << typeName << ");";

View File

@ -144,11 +144,9 @@ BasicBlock* LowerSwitch::switchConvert(CaseItr Begin, CaseItr End,
DOUT << "RHS: " << RHS << "\n"; DOUT << "RHS: " << RHS << "\n";
CaseRange& Pivot = *(Begin + Mid); CaseRange& Pivot = *(Begin + Mid);
DEBUG( DOUT << "Pivot ==> " DEBUG(cerr << "Pivot ==> "
<< cast<ConstantInt>(Pivot.Low)->getValue().toStringSigned(10) << cast<ConstantInt>(Pivot.Low)->getValue() << " -"
<< " -" << cast<ConstantInt>(Pivot.High)->getValue() << "\n");
<< cast<ConstantInt>(Pivot.High)->getValue().toStringSigned(10)
<< "\n");
BasicBlock* LBranch = switchConvert(LHS.begin(), LHS.end(), Val, BasicBlock* LBranch = switchConvert(LHS.begin(), LHS.end(), Val,
OrigBlock, Default); OrigBlock, Default);

View File

@ -507,13 +507,18 @@ static void WriteConstantInt(std::ostream &Out, const Constant *CV,
std::map<const Type *, std::string> &TypeTable, std::map<const Type *, std::string> &TypeTable,
SlotMachine *Machine) { SlotMachine *Machine) {
const int IndentSize = 4; const int IndentSize = 4;
// FIXME: WHY IS INDENT STATIC??
static std::string Indent = "\n"; static std::string Indent = "\n";
if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) { if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
if (CI->getType() == Type::Int1Ty) if (CI->getType() == Type::Int1Ty) {
Out << (CI->getZExtValue() ? "true" : "false"); Out << (CI->getZExtValue() ? "true" : "false");
else return;
Out << CI->getValue().toStringSigned(10); }
} else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) { Out << CI->getValue();
return;
}
if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
if (&CFP->getValueAPF().getSemantics() == &APFloat::IEEEdouble || if (&CFP->getValueAPF().getSemantics() == &APFloat::IEEEdouble ||
&CFP->getValueAPF().getSemantics() == &APFloat::IEEEsingle) { &CFP->getValueAPF().getSemantics() == &APFloat::IEEEsingle) {
// We would like to output the FP constant value in exponential notation, // We would like to output the FP constant value in exponential notation,
@ -522,8 +527,8 @@ static void WriteConstantInt(std::ostream &Out, const Constant *CV,
// the value back and get the same value. // the value back and get the same value.
// //
bool isDouble = &CFP->getValueAPF().getSemantics()==&APFloat::IEEEdouble; bool isDouble = &CFP->getValueAPF().getSemantics()==&APFloat::IEEEdouble;
double Val = (isDouble) ? CFP->getValueAPF().convertToDouble() : double Val = isDouble ? CFP->getValueAPF().convertToDouble() :
CFP->getValueAPF().convertToFloat(); CFP->getValueAPF().convertToFloat();
std::string StrVal = ftostr(CFP->getValueAPF()); std::string StrVal = ftostr(CFP->getValueAPF());
// Check to make sure that the stringized number is not some string like // Check to make sure that the stringized number is not some string like
@ -1054,7 +1059,7 @@ void AssemblyWriter::printAlias(const GlobalAlias *GA) {
printType(F->getFunctionType()); printType(F->getFunctionType());
Out << "* "; Out << "* ";
if (!F->hasName()) if (F->hasName())
PrintLLVMName(Out, F); PrintLLVMName(Out, F);
else else
Out << "@\"\""; Out << "@\"\"";