[llvm-commits] [llvm] r54873 - in /llvm/trunk: examples/Fibonacci/fibonacci.cpp examples/HowToUseJIT/HowToUseJIT.cpp include/llvm/ADT/APInt.h include/llvm/ADT/APSInt.h lib/AsmParser/ParserInternals.h lib/CodeGen/AsmPrinter.cpp lib/CodeGen/SelectionDAG/SelectionDAG.cpp lib/Support/APFloat.cpp lib/Support/APInt.cpp lib/Support/ConstantRange.cpp lib/Target/CppBackend/CPPBackend.cpp lib/Transforms/Utils/LowerSwitch.cpp lib/VMCore/AsmWriter.cpp
Chris Lattner
sabre at nondot.org
Sun Aug 17 00:19:37 PDT 2008
Author: lattner
Date: Sun Aug 17 02:19:36 2008
New Revision: 54873
URL: http://llvm.org/viewvc/llvm-project?rev=54873&view=rev
Log:
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.
Modified:
llvm/trunk/examples/Fibonacci/fibonacci.cpp
llvm/trunk/examples/HowToUseJIT/HowToUseJIT.cpp
llvm/trunk/include/llvm/ADT/APInt.h
llvm/trunk/include/llvm/ADT/APSInt.h
llvm/trunk/lib/AsmParser/ParserInternals.h
llvm/trunk/lib/CodeGen/AsmPrinter.cpp
llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
llvm/trunk/lib/Support/APFloat.cpp
llvm/trunk/lib/Support/APInt.cpp
llvm/trunk/lib/Support/ConstantRange.cpp
llvm/trunk/lib/Target/CppBackend/CPPBackend.cpp
llvm/trunk/lib/Transforms/Utils/LowerSwitch.cpp
llvm/trunk/lib/VMCore/AsmWriter.cpp
Modified: llvm/trunk/examples/Fibonacci/fibonacci.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/examples/Fibonacci/fibonacci.cpp?rev=54873&r1=54872&r2=54873&view=diff
==============================================================================
--- llvm/trunk/examples/Fibonacci/fibonacci.cpp (original)
+++ llvm/trunk/examples/Fibonacci/fibonacci.cpp Sun Aug 17 02:19:36 2008
@@ -116,6 +116,6 @@
GenericValue GV = EE->runFunction(FibF, Args);
// import result of execution
- std::cout << "Result: " << GV.IntVal.toStringUnsigned(10) << "\n";
+ std::cout << "Result: " << GV.IntVal << "\n";
return 0;
}
Modified: llvm/trunk/examples/HowToUseJIT/HowToUseJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/examples/HowToUseJIT/HowToUseJIT.cpp?rev=54873&r1=54872&r2=54873&view=diff
==============================================================================
--- llvm/trunk/examples/HowToUseJIT/HowToUseJIT.cpp (original)
+++ llvm/trunk/examples/HowToUseJIT/HowToUseJIT.cpp Sun Aug 17 02:19:36 2008
@@ -107,6 +107,6 @@
GenericValue gv = EE->runFunction(FooF, noargs);
// Import result of execution:
- std::cout << "Result: " << gv.IntVal.toStringUnsigned(10) << "\n";
+ std::cout << "Result: " << gv.IntVal << "\n";
return 0;
}
Modified: llvm/trunk/include/llvm/ADT/APInt.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/APInt.h?rev=54873&r1=54872&r2=54873&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/APInt.h (original)
+++ llvm/trunk/include/llvm/ADT/APInt.h Sun Aug 17 02:19:36 2008
@@ -17,6 +17,7 @@
#include "llvm/Support/DataTypes.h"
#include <cassert>
+#include <iosfwd>
#include <string>
namespace llvm {
@@ -24,6 +25,9 @@
class Deserializer;
class FoldingSetNodeID;
+ template<typename T>
+ class SmallVectorImpl;
+
/* An unsigned host type used as a single part of a multi-part
bignum. */
typedef uint64_t integerPart;
@@ -468,7 +472,7 @@
/// Performs logical negation operation on this APInt.
/// @returns true if *this is zero, false otherwise.
/// @brief Logical negation operator.
- bool operator !() const;
+ bool operator!() const;
/// @}
/// @name Assignment Operators
@@ -972,25 +976,29 @@
/// @name Conversion Functions
/// @{
- /// 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, bool wantSigned) const;
+ void print(std::ostream &OS, bool isSigned) 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
/// radix given. The radix can be 2, 8, 10 or 16.
- /// @returns a character interpretation of the APInt
- /// @brief Convert unsigned APInt to string representation.
- std::string toStringUnsigned(uint8_t radix = 10) const {
- return toString(radix, false);
+ void toStringUnsigned(SmallVectorImpl<char> &Str, unsigned Radix = 10) const {
+ return toString(Str, Radix, false);
}
/// 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.
- /// @returns a character interpretation of the APInt
- /// @brief Convert signed APInt to string representation.
- std::string toStringSigned(uint8_t radix = 10) const {
- return toString(radix, true);
+ void toStringSigned(SmallVectorImpl<char> &Str, unsigned Radix = 10) const {
+ return toString(Str, 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.
APInt byteSwap() const;
@@ -1237,6 +1245,11 @@
return V2 != V1;
}
+inline std::ostream &operator<<(std::ostream &OS, const APInt &I) {
+ I.print(OS, true);
+ return OS;
+}
+
namespace APIntOps {
/// @brief Determine the smaller of two APInts considered to be signed.
Modified: llvm/trunk/include/llvm/ADT/APSInt.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/APSInt.h?rev=54873&r1=54872&r2=54873&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/APSInt.h (original)
+++ llvm/trunk/include/llvm/ADT/APSInt.h Sun Aug 17 02:19:36 2008
@@ -19,7 +19,6 @@
namespace llvm {
-
class APSInt : public APInt {
bool IsUnsigned;
public:
@@ -58,11 +57,16 @@
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 @@
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
Modified: llvm/trunk/lib/AsmParser/ParserInternals.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/ParserInternals.h?rev=54873&r1=54872&r2=54873&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/ParserInternals.h (original)
+++ llvm/trunk/lib/AsmParser/ParserInternals.h Sun Aug 17 02:19:36 2008
@@ -170,7 +170,7 @@
case GlobalID : return '@' + utostr(Num);
case LocalName : return *Name;
case GlobalName : return *Name;
- case ConstAPInt : return ConstPoolInt->toString();
+ case ConstAPInt : return ConstPoolInt->toString(10);
case ConstFPVal : return ftostr(*ConstPoolFP);
case ConstNullVal : return "null";
case ConstUndefVal : return "undef";
Modified: llvm/trunk/lib/CodeGen/AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter.cpp?rev=54873&r1=54872&r2=54873&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter.cpp Sun Aug 17 02:19:36 2008
@@ -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();
}
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp?rev=54873&r1=54872&r2=54873&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Sun Aug 17 02:19:36 2008
@@ -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() << ">";
Modified: llvm/trunk/lib/Support/APFloat.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/APFloat.cpp?rev=54873&r1=54872&r2=54873&view=diff
==============================================================================
--- llvm/trunk/lib/Support/APFloat.cpp (original)
+++ llvm/trunk/lib/Support/APFloat.cpp Sun Aug 17 02:19:36 2008
@@ -14,9 +14,8 @@
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/FoldingSet.h"
-#include <cassert>
-#include <cstring>
#include "llvm/Support/MathExtras.h"
+#include <cstring>
using namespace llvm;
Modified: llvm/trunk/lib/Support/APInt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/APInt.cpp?rev=54873&r1=54872&r2=54873&view=diff
==============================================================================
--- llvm/trunk/lib/Support/APInt.cpp (original)
+++ llvm/trunk/lib/Support/APInt.cpp Sun Aug 17 02:19:36 2008
@@ -15,14 +15,13 @@
#define DEBUG_TYPE "apint"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/FoldingSet.h"
+#include "llvm/ADT/SmallString.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/MathExtras.h"
-#include <math.h>
+#include <cmath>
#include <limits>
#include <cstring>
#include <cstdlib>
-#include <iomanip>
-
using namespace llvm;
/// This enumeration just provides for internal constants used in this
@@ -1478,12 +1477,14 @@
// is 2^31 so we just set it to -1u.
uint64_t b = uint64_t(1) << 32;
+#if 0
DEBUG(cerr << "KnuthDiv: m=" << m << " n=" << n << '\n');
DEBUG(cerr << "KnuthDiv: original:");
DEBUG(for (int i = m+n; i >=0; i--) cerr << " " << std::setbase(16) << u[i]);
DEBUG(cerr << " by");
DEBUG(for (int i = n; i >0; i--) cerr << " " << std::setbase(16) << v[i-1]);
DEBUG(cerr << '\n');
+#endif
// 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
// of 2 value for d such that d * v[n-1] >= b/2 (b is the base). A power of
@@ -1508,11 +1509,13 @@
}
}
u[m+n] = u_carry;
+#if 0
DEBUG(cerr << "KnuthDiv: normal:");
DEBUG(for (int i = m+n; i >=0; i--) cerr << " " << std::setbase(16) << u[i]);
DEBUG(cerr << " by");
DEBUG(for (int i = n; i >0; i--) cerr << " " << std::setbase(16) << v[i-1]);
DEBUG(cerr << '\n');
+#endif
// D2. [Initialize j.] Set j to m. This is the loop counter over the places.
int j = m;
@@ -1636,7 +1639,9 @@
}
DEBUG(cerr << '\n');
}
+#if 0
DEBUG(cerr << std::setbase(10) << '\n');
+#endif
}
void APInt::divide(const APInt LHS, uint32_t lhsWords,
@@ -2001,114 +2006,112 @@
}
}
-std::string APInt::toString(uint8_t radix, bool wantSigned) const {
- assert((radix == 10 || radix == 8 || radix == 16 || radix == 2) &&
+void APInt::toString(SmallVectorImpl<char> &Str, unsigned Radix,
+ bool Signed) const {
+ assert((Radix == 10 || Radix == 8 || Radix == 16 || Radix == 2) &&
"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"
- };
- std::string result;
- uint32_t bits_used = getActiveBits();
+
+ // First, check for a zero value and just short circuit the logic below.
+ if (*this == 0) {
+ Str.push_back('0');
+ return;
+ }
+
+ static const char Digits[] = "0123456789ABCDEF";
+
if (isSingleWord()) {
- char buf[65];
- const char *format = (radix == 10 ? (wantSigned ? "%lld" : "%llu") :
- (radix == 16 ? "%llX" : (radix == 8 ? "%llo" : 0)));
- if (format) {
- if (wantSigned) {
- int64_t sextVal = (int64_t(VAL) << (APINT_BITS_PER_WORD-BitWidth)) >>
- (APINT_BITS_PER_WORD-BitWidth);
- sprintf(buf, format, sextVal);
- } else
- sprintf(buf, format, VAL);
- } else {
- memset(buf, 0, 65);
- uint64_t v = VAL;
- while (bits_used) {
- uint32_t bit = (uint32_t)v & 1;
- bits_used--;
- buf[bits_used] = digits[bit][0];
- v >>=1;
+ char Buffer[65];
+ char *BufPtr = Buffer+65;
+
+ uint64_t N;
+ if (Signed) {
+ int64_t I = getSExtValue();
+ if (I < 0) {
+ Str.push_back('-');
+ I = -I;
}
+ N = I;
+ } else {
+ N = getZExtValue();
}
- result = buf;
- return result;
- }
-
- if (radix != 10) {
- // 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
- // 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);
- }
+
+ while (N) {
+ *--BufPtr = Digits[N % Radix];
+ N /= Radix;
}
- return result;
+ Str.append(BufPtr, Buffer+65);
+ return;
}
- APInt tmp(*this);
- APInt divisor(4, radix);
- APInt zero(tmp.getBitWidth(), 0);
- size_t insert_at = 0;
- if (wantSigned && tmp[BitWidth-1]) {
+ APInt Tmp(*this);
+
+ if (Signed && 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;
- }
- if (tmp == zero)
- result = "0";
- else while (tmp.ne(zero)) {
- 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");
- result.insert(insert_at,digits[digit]);
- tmp = tmp2;
+ Tmp.flip();
+ Tmp++;
+ Str.push_back('-');
}
+
+ // We insert the digits backward, then reverse them to get the right order.
+ unsigned StartDig = Str.size();
+
+ // 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
+ // equaly. We just shift until the value is zero.
+ if (Radix != 10) {
+ // Just shift tmp right for each digit width until it becomes zero
+ unsigned ShiftAmt = (Radix == 16 ? 4 : (Radix == 8 ? 3 : 1));
+ 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;
+ }
+ }
+
+ // Reverse the digits before returning.
+ std::reverse(Str.begin()+StartDig, Str.end());
+}
- return result;
+/// 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.
+std::string APInt::toString(unsigned Radix = 10, bool Signed = true) const {
+ SmallString<40> S;
+ toString(S, Radix, Signed);
+ return S.c_str();
}
-void APInt::dump() const
-{
- cerr << "APInt(" << BitWidth << ")=" << std::setbase(16);
- if (isSingleWord())
- cerr << VAL;
- else for (unsigned i = getNumWords(); i > 0; i--) {
- cerr << pVal[i-1] << " ";
- }
- 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
// arbitrary precision, two's-complement, bignum integer values.
Modified: llvm/trunk/lib/Support/ConstantRange.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/ConstantRange.cpp?rev=54873&r1=54872&r2=54873&view=diff
==============================================================================
--- llvm/trunk/lib/Support/ConstantRange.cpp (original)
+++ llvm/trunk/lib/Support/ConstantRange.cpp Sun Aug 17 02:19:36 2008
@@ -463,8 +463,7 @@
/// print - Print out the bounds to a stream...
///
void ConstantRange::print(std::ostream &OS) const {
- OS << "[" << Lower.toStringSigned(10) << ","
- << Upper.toStringSigned(10) << ")";
+ OS << "[" << Lower << "," << Upper << ")";
}
/// dump - Allow printing from a debugger easily...
Modified: llvm/trunk/lib/Target/CppBackend/CPPBackend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/CppBackend/CPPBackend.cpp?rev=54873&r1=54872&r2=54873&view=diff
==============================================================================
--- llvm/trunk/lib/Target/CppBackend/CPPBackend.cpp (original)
+++ llvm/trunk/lib/Target/CppBackend/CPPBackend.cpp Sun Aug 17 02:19:36 2008
@@ -733,8 +733,8 @@
}
if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
Out << "ConstantInt* " << constName << " = ConstantInt::get(APInt("
- << cast<IntegerType>(CI->getType())->getBitWidth() << ", "
- << " \"" << CI->getValue().toStringSigned(10) << "\", 10));";
+ << cast<IntegerType>(CI->getType())->getBitWidth() << ", \""
+ << CI->getValue() << "\", 10));";
} else if (isa<ConstantAggregateZero>(CV)) {
Out << "ConstantAggregateZero* " << constName
<< " = ConstantAggregateZero::get(" << typeName << ");";
Modified: llvm/trunk/lib/Transforms/Utils/LowerSwitch.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/LowerSwitch.cpp?rev=54873&r1=54872&r2=54873&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/LowerSwitch.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/LowerSwitch.cpp Sun Aug 17 02:19:36 2008
@@ -144,11 +144,9 @@
DOUT << "RHS: " << RHS << "\n";
CaseRange& Pivot = *(Begin + Mid);
- DEBUG( DOUT << "Pivot ==> "
- << cast<ConstantInt>(Pivot.Low)->getValue().toStringSigned(10)
- << " -"
- << cast<ConstantInt>(Pivot.High)->getValue().toStringSigned(10)
- << "\n");
+ DEBUG(cerr << "Pivot ==> "
+ << cast<ConstantInt>(Pivot.Low)->getValue() << " -"
+ << cast<ConstantInt>(Pivot.High)->getValue() << "\n");
BasicBlock* LBranch = switchConvert(LHS.begin(), LHS.end(), Val,
OrigBlock, Default);
Modified: llvm/trunk/lib/VMCore/AsmWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/AsmWriter.cpp?rev=54873&r1=54872&r2=54873&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/AsmWriter.cpp (original)
+++ llvm/trunk/lib/VMCore/AsmWriter.cpp Sun Aug 17 02:19:36 2008
@@ -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 << "@\"\"";
More information about the llvm-commits
mailing list