diff options
author | Jay Foad <jay.foad@gmail.com> | 2010-11-28 21:04:48 +0000 |
---|---|---|
committer | Jay Foad <jay.foad@gmail.com> | 2010-11-28 21:04:48 +0000 |
commit | e4d19c9eb22899c9a555395d446a9ceef3bea7eb (patch) | |
tree | 0e8700eca311224bf9289faf4b222029b521c48c | |
parent | d8f717911dcdccb1a60b3049ea22c7767970dcb7 (diff) |
PR5207: change APInt::doubleToBits() and APInt::floatToBits() to be
static methods that return a new APInt.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120261 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/ADT/APInt.h | 22 | ||||
-rw-r--r-- | lib/ExecutionEngine/ExecutionEngine.cpp | 4 | ||||
-rw-r--r-- | lib/ExecutionEngine/Interpreter/Execution.cpp | 6 | ||||
-rw-r--r-- | lib/Support/APFloat.cpp | 6 |
4 files changed, 12 insertions, 26 deletions
diff --git a/include/llvm/ADT/APInt.h b/include/llvm/ADT/APInt.h index d398f8e3f6..22d9738333 100644 --- a/include/llvm/ADT/APInt.h +++ b/include/llvm/ADT/APInt.h @@ -1293,37 +1293,27 @@ public: } /// The conversion does not do a translation from double to integer, it just - /// re-interprets the bits of the double. Note that it is valid to do this on - /// any bit width but bits from V may get truncated. + /// re-interprets the bits of the double. /// @brief Converts a double to APInt bits. - APInt& doubleToBits(double V) { + static APInt doubleToBits(double V) { union { uint64_t I; double D; } T; T.D = V; - if (isSingleWord()) - VAL = T.I; - else - pVal[0] = T.I; - return clearUnusedBits(); + return APInt(sizeof T * CHAR_BIT, T.I); } /// The conversion does not do a translation from float to integer, it just - /// re-interprets the bits of the float. Note that it is valid to do this on - /// any bit width but bits from V may get truncated. + /// re-interprets the bits of the float. /// @brief Converts a float to APInt bits. - APInt& floatToBits(float V) { + static APInt floatToBits(float V) { union { unsigned I; float F; } T; T.F = V; - if (isSingleWord()) - VAL = T.I; - else - pVal[0] = T.I; - return clearUnusedBits(); + return APInt(sizeof T * CHAR_BIT, T.I); } /// @} diff --git a/lib/ExecutionEngine/ExecutionEngine.cpp b/lib/ExecutionEngine/ExecutionEngine.cpp index 91d68fb1e2..1f5711c4e4 100644 --- a/lib/ExecutionEngine/ExecutionEngine.cpp +++ b/lib/ExecutionEngine/ExecutionEngine.cpp @@ -637,11 +637,11 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) { break; case Type::FloatTyID: assert(DestTy->isIntegerTy(32) && "Invalid bitcast"); - GV.IntVal.floatToBits(GV.FloatVal); + GV.IntVal = APInt::floatToBits(GV.FloatVal); break; case Type::DoubleTyID: assert(DestTy->isIntegerTy(64) && "Invalid bitcast"); - GV.IntVal.doubleToBits(GV.DoubleVal); + GV.IntVal = APInt::doubleToBits(GV.DoubleVal); break; case Type::PointerTyID: assert(DestTy->isPointerTy() && "Invalid bitcast"); diff --git a/lib/ExecutionEngine/Interpreter/Execution.cpp b/lib/ExecutionEngine/Interpreter/Execution.cpp index 59ebe6e2a8..498063bf65 100644 --- a/lib/ExecutionEngine/Interpreter/Execution.cpp +++ b/lib/ExecutionEngine/Interpreter/Execution.cpp @@ -1060,11 +1060,9 @@ GenericValue Interpreter::executeBitCastInst(Value *SrcVal, const Type *DstTy, Dest.PointerVal = Src.PointerVal; } else if (DstTy->isIntegerTy()) { if (SrcTy->isFloatTy()) { - Dest.IntVal.zext(sizeof(Src.FloatVal) * CHAR_BIT); - Dest.IntVal.floatToBits(Src.FloatVal); + Dest.IntVal = APInt::floatToBits(Src.FloatVal); } else if (SrcTy->isDoubleTy()) { - Dest.IntVal.zext(sizeof(Src.DoubleVal) * CHAR_BIT); - Dest.IntVal.doubleToBits(Src.DoubleVal); + Dest.IntVal = APInt::doubleToBits(Src.DoubleVal); } else if (SrcTy->isIntegerTy()) { Dest.IntVal = Src.IntVal; } else diff --git a/lib/Support/APFloat.cpp b/lib/Support/APFloat.cpp index b87ddf9c95..c0151e26fb 100644 --- a/lib/Support/APFloat.cpp +++ b/lib/Support/APFloat.cpp @@ -3258,14 +3258,12 @@ APFloat::APFloat(const APInt& api, bool isIEEE) APFloat::APFloat(float f) { - APInt api = APInt(32, 0); - initFromAPInt(api.floatToBits(f)); + initFromAPInt(APInt::floatToBits(f)); } APFloat::APFloat(double d) { - APInt api = APInt(64, 0); - initFromAPInt(api.doubleToBits(d)); + initFromAPInt(APInt::doubleToBits(d)); } namespace { |