[llvm-commits] [llvm] r41378 - in /llvm/trunk: include/llvm/ADT/APFloat.h lib/CodeGen/SelectionDAG/SelectionDAG.cpp lib/Support/APFloat.cpp lib/VMCore/Constants.cpp
Dale Johannesen
dalej at apple.com
Fri Aug 24 15:09:56 PDT 2007
Author: johannes
Date: Fri Aug 24 17:09:56 2007
New Revision: 41378
URL: http://llvm.org/viewvc/llvm-project?rev=41378&view=rev
Log:
Poison APFloat::operator==. Replace existing uses with bitwiseIsEqual.
This means backing out the preceding change to Constants.cpp, alas.
Modified:
llvm/trunk/include/llvm/ADT/APFloat.h
llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
llvm/trunk/lib/Support/APFloat.cpp
llvm/trunk/lib/VMCore/Constants.cpp
Modified: llvm/trunk/include/llvm/ADT/APFloat.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/APFloat.h?rev=41378&r1=41377&r2=41378&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/APFloat.h (original)
+++ llvm/trunk/include/llvm/ADT/APFloat.h Fri Aug 24 17:09:56 2007
@@ -187,17 +187,17 @@
double convertToDouble() const;
float convertToFloat() const;
+ /* The definition of equality is not straightforward for floating point,
+ so we won't use operator==. Use one of the following, or write
+ whatever it is you really mean. */
+ bool operator==(const APFloat &) const; // DO NOT IMPLEMENT
+
/* IEEE comparison with another floating point number (QNaNs
compare unordered, 0==-0). */
cmpResult compare(const APFloat &) const;
/* Bitwise comparison for equality (QNaNs compare equal, 0!=-0). */
- bool operator==(const APFloat &) const;
-
- /* Inversion of the preceding. */
- inline bool operator!=(const APFloat &RHS) const {
- return !((*this)==RHS);
- }
+ bool bitwiseIsEqual(const APFloat &) const;
/* Simple queries. */
fltCategory getCategory() const { return category; }
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp?rev=41378&r1=41377&r2=41378&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Fri Aug 24 17:09:56 2007
@@ -49,7 +49,7 @@
/// As such, this method can be used to do an exact bit-for-bit comparison of
/// two floating point values.
bool ConstantFPSDNode::isExactlyValue(double V) const {
- return Value == APFloat(V);
+ return Value.bitwiseIsEqual(APFloat(V));
}
//===----------------------------------------------------------------------===//
Modified: llvm/trunk/lib/Support/APFloat.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/APFloat.cpp?rev=41378&r1=41377&r2=41378&view=diff
==============================================================================
--- llvm/trunk/lib/Support/APFloat.cpp (original)
+++ llvm/trunk/lib/Support/APFloat.cpp Fri Aug 24 17:09:56 2007
@@ -276,7 +276,7 @@
}
bool
-APFloat::operator==(const APFloat &rhs) const {
+APFloat::bitwiseIsEqual(const APFloat &rhs) const {
if (this == &rhs)
return true;
if (semantics != rhs.semantics ||
Modified: llvm/trunk/lib/VMCore/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Constants.cpp?rev=41378&r1=41377&r2=41378&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Constants.cpp (original)
+++ llvm/trunk/lib/VMCore/Constants.cpp Fri Aug 24 17:09:56 2007
@@ -248,19 +248,30 @@
}
bool ConstantFP::isExactlyValue(double V) const {
- return Val == APFloat(V);
+ return Val.bitwiseIsEqual(APFloat(V));
}
namespace {
struct DenseMapAPFloatKeyInfo {
- static inline APFloat getEmptyKey() {
- return APFloat(APFloat::Bogus,1);
+ struct KeyTy {
+ APFloat val;
+ KeyTy(const APFloat& V) : val(V){}
+ KeyTy(const KeyTy& that) : val(that.val) {}
+ bool operator==(const KeyTy& that) const {
+ return this->val.bitwiseIsEqual(that.val);
+ }
+ bool operator!=(const KeyTy& that) const {
+ return !this->operator==(that);
+ }
+ };
+ static inline KeyTy getEmptyKey() {
+ return KeyTy(APFloat(APFloat::Bogus,1));
}
- static inline APFloat getTombstoneKey() {
- return APFloat(APFloat::Bogus,2);
+ static inline KeyTy getTombstoneKey() {
+ return KeyTy(APFloat(APFloat::Bogus,2));
}
- static unsigned getHashValue(const APFloat &Key) {
- return Key.getHashValue();
+ static unsigned getHashValue(const KeyTy &Key) {
+ return Key.val.getHashValue();
}
static bool isPod() { return false; }
};
@@ -268,21 +279,21 @@
//---- ConstantFP::get() implementation...
//
-typedef DenseMap<APFloat, ConstantFP*,
+typedef DenseMap<DenseMapAPFloatKeyInfo::KeyTy, ConstantFP*,
DenseMapAPFloatKeyInfo> FPMapTy;
static ManagedStatic<FPMapTy> FPConstants;
ConstantFP *ConstantFP::get(const Type *Ty, double V) {
if (Ty == Type::FloatTy) {
- APFloat Key(APFloat((float)V));
+ DenseMapAPFloatKeyInfo::KeyTy Key(APFloat((float)V));
ConstantFP *&Slot = (*FPConstants)[Key];
if (Slot) return Slot;
return Slot = new ConstantFP(Ty, (float)V);
} else if (Ty == Type::DoubleTy) {
// Without the redundant cast, the following is taken to be
// a function declaration. What a language.
- APFloat Key(APFloat((double)V));
+ DenseMapAPFloatKeyInfo::KeyTy Key(APFloat((double)V));
ConstantFP *&Slot = (*FPConstants)[Key];
if (Slot) return Slot;
return Slot = new ConstantFP(Ty, V);
More information about the llvm-commits
mailing list