Rework the routines that convert AP[S]Int into a string. Now, instead of
authorChris Lattner <sabre@nondot.org>
Sun, 17 Aug 2008 07:19:36 +0000 (07:19 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 17 Aug 2008 07:19:36 +0000 (07:19 +0000)
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

13 files changed:
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

index 73dff11031cd07aececcbe9e0ec273e7adf3f691..f4c5c3d698ae3d2aa8b927980886744d03f6c7ab 100644 (file)
@@ -116,6 +116,6 @@ int main(int argc, char **argv) {
   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;
 }
index 5fa4237179f7605fd0694f0b02394ec3ef17ea48..d50000579efc1f00a8bb7d1f26ccff8aba6c0e5f 100644 (file)
@@ -107,6 +107,6 @@ int main() {
   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;
 }
index 9e8119d7a365020f09510cc411a1453a9a9702c1..c475cf3f71c51f708241b9b948b2245538334252 100644 (file)
@@ -17,6 +17,7 @@
 
 #include "llvm/Support/DataTypes.h"
 #include <cassert>
+#include <iosfwd>
 #include <string>
 
 namespace llvm {
@@ -24,6 +25,9 @@ namespace llvm {
   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 @@ public:
   /// 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 @@ public:
   /// @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 @@ inline bool operator!=(uint64_t V1, const APInt& V2) {
   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.
index edb36bafe4a4c7331bb2778ca2320a6956d186b2..00bece62adec0ad05089fb10f0459aeda5dbfddd 100644 (file)
@@ -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
index aae1d53535a4c35503f71879187848acbcf11432..cc35038a4189a85b669843d211f9f4e08481084b 100644 (file)
@@ -170,7 +170,7 @@ struct ValID {
     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";
index 16f26c429921319f512628b78417e2454615347b..1bc4868a608e44b8a4f3d704d8b805de45a8aa8a 100644 (file)
@@ -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 @@ void AsmPrinter::EmitConstantValueOnly(const Constant *CV) {
       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 @@ void AsmPrinter::EmitGlobalConstant(const Constant *CV) {
   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();
 }
index 80dda1f280e59a5f5519b185e5b05bd1a5509493..c372874957795e5f92f263fecc2fc5b2619339a2 100644 (file)
@@ -4992,7 +4992,7 @@ void SDNode::dump(const SelectionDAG *G) const {
   }
 
   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() << ">";
index a6b7ed37587eac5ceda30e8fe290644428adfa41..b948e8f43ac4f3e726c6aff6ceabcc241ded6bd7 100644 (file)
@@ -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;
 
index d579ae0965b338eb84b934717fabe1b616f0e2e7..80747fd12a9d9a249e3d98cbb365d9e8eb0293e6 100644 (file)
 #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 @@ 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.
   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 @@ static void KnuthDiv(uint32_t *u, uint32_t *v, uint32_t *q, uint32_t* r,
     }
   }
   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 @@ static void KnuthDiv(uint32_t *u, uint32_t *v, uint32_t *q, uint32_t* r,
     }
     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 @@ void APInt::fromString(uint32_t numbits, const char *str, uint32_t slen,
   }
 }
 
-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.
 
index 0d22b323502174376c92db9023299ea1be7f338f..9c83b7c59de4e340f0e50268a803ed2d4e0de4f9 100644 (file)
@@ -463,8 +463,7 @@ ConstantRange ConstantRange::truncate(uint32_t DstTySize) const {
 /// 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...
index 6aa085bc83df930bdf7bec56f688735923f97dc1..ce86452737d91b428b10b1daca9e20ecf4eed382 100644 (file)
@@ -733,8 +733,8 @@ namespace {
     }
     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 << ");";
index 630f97cd6dac68ce376e57704391d2e08c1e3fae..7409e779f80bad2981f0aa8ba814a4eaa8cb630b 100644 (file)
@@ -144,11 +144,9 @@ BasicBlock* LowerSwitch::switchConvert(CaseItr Begin, CaseItr End,
   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);
index fa512e01711ee1c7d3d17aac9eb6c4b413865450..ad7b5c3ffe3f83a2c821ab122b10fc0c6bcb8242 100644 (file)
@@ -507,13 +507,18 @@ static void WriteConstantInt(std::ostream &Out, const Constant *CV,
                              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 @@ static void WriteConstantInt(std::ostream &Out, const Constant *CV,
       // 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 @@ void AssemblyWriter::printAlias(const GlobalAlias *GA) {
     printType(F->getFunctionType());
     Out << "* ";
 
-    if (!F->hasName())
+    if (F->hasName())
       PrintLLVMName(Out, F);
     else
       Out << "@\"\"";