aboutsummaryrefslogtreecommitdiffstats
path: root/lib/VMCore
diff options
context:
space:
mode:
authorDale Johannesen <dalej@apple.com>2007-08-24 00:56:33 +0000
committerDale Johannesen <dalej@apple.com>2007-08-24 00:56:33 +0000
commit343e770983dcf53a1ea2dfca4e04d28ebc41138a (patch)
tree7a47d5e48fde4a3990a915df06776a2122625610 /lib/VMCore
parent57e4785123d830cfaa827474485596c9943cd2ae (diff)
downloadexternal_llvm-343e770983dcf53a1ea2dfca4e04d28ebc41138a.zip
external_llvm-343e770983dcf53a1ea2dfca4e04d28ebc41138a.tar.gz
external_llvm-343e770983dcf53a1ea2dfca4e04d28ebc41138a.tar.bz2
Change internal representation of ConstantFP to use APFloat.
Interface to rest of the compiler unchanged, as yet. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41348 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r--lib/VMCore/Constants.cpp66
1 files changed, 33 insertions, 33 deletions
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp
index 87306fe..fc3f5c9 100644
--- a/lib/VMCore/Constants.cpp
+++ b/lib/VMCore/Constants.cpp
@@ -202,7 +202,7 @@ namespace {
return DenseMapKeyInfo<void*>::getHashValue(Key.type) ^
Key.val.getHashValue();
}
- static bool isPod() { return true; }
+ static bool isPod() { return false; }
};
}
@@ -240,63 +240,63 @@ ConstantInt *ConstantInt::get(const APInt& V) {
ConstantFP::ConstantFP(const Type *Ty, double V)
- : Constant(Ty, ConstantFPVal, 0, 0) {
- Val = V;
+ : Constant(Ty, ConstantFPVal, 0, 0), Val(APFloat(V)) {
}
bool ConstantFP::isNullValue() const {
- return DoubleToBits(Val) == 0;
+ return Val.isZero() && !Val.isNegative();
}
bool ConstantFP::isExactlyValue(double V) const {
- return DoubleToBits(V) == DoubleToBits(Val);
+ return Val == APFloat(V);
}
-
namespace {
- struct DenseMapInt64KeyInfo {
- typedef std::pair<uint64_t, const Type*> KeyTy;
- static inline KeyTy getEmptyKey() { return KeyTy(0, 0); }
- static inline KeyTy getTombstoneKey() { return KeyTy(1, 0); }
- static unsigned getHashValue(const KeyTy &Key) {
- return DenseMapKeyInfo<void*>::getHashValue(Key.second) ^ Key.first;
+ struct DenseMapAPFloatKeyInfo {
+ 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 == that.val;
+ }
+ bool operator!=(const KeyTy& that) const {
+ return !this->operator==(that);
+ }
+ };
+ static inline KeyTy getEmptyKey() {
+ return KeyTy(APFloat(APFloat::Bogus,1));
+ }
+ static inline KeyTy getTombstoneKey() {
+ return KeyTy(APFloat(APFloat::Bogus,2));
}
- static bool isPod() { return true; }
- };
- struct DenseMapInt32KeyInfo {
- typedef std::pair<uint32_t, const Type*> KeyTy;
- static inline KeyTy getEmptyKey() { return KeyTy(0, 0); }
- static inline KeyTy getTombstoneKey() { return KeyTy(1, 0); }
static unsigned getHashValue(const KeyTy &Key) {
- return DenseMapKeyInfo<void*>::getHashValue(Key.second) ^ Key.first;
+ return Key.val.getHashValue();
}
- static bool isPod() { return true; }
+ static bool isPod() { return false; }
};
}
//---- ConstantFP::get() implementation...
//
-typedef DenseMap<DenseMapInt32KeyInfo::KeyTy, ConstantFP*,
- DenseMapInt32KeyInfo> FloatMapTy;
-typedef DenseMap<DenseMapInt64KeyInfo::KeyTy, ConstantFP*,
- DenseMapInt64KeyInfo> DoubleMapTy;
+typedef DenseMap<DenseMapAPFloatKeyInfo::KeyTy, ConstantFP*,
+ DenseMapAPFloatKeyInfo> FPMapTy;
-static ManagedStatic<FloatMapTy> FloatConstants;
-static ManagedStatic<DoubleMapTy> DoubleConstants;
+static ManagedStatic<FPMapTy> FPConstants;
ConstantFP *ConstantFP::get(const Type *Ty, double V) {
if (Ty == Type::FloatTy) {
- uint32_t IntVal = FloatToBits((float)V);
-
- ConstantFP *&Slot = (*FloatConstants)[std::make_pair(IntVal, Ty)];
+ 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) {
- uint64_t IntVal = DoubleToBits(V);
- ConstantFP *&Slot = (*DoubleConstants)[std::make_pair(IntVal, Ty)];
+ } else if (Ty == Type::DoubleTy) {
+ // Without the redundant cast, the following is taken to be
+ // a function declaration. What a language.
+ DenseMapAPFloatKeyInfo::KeyTy Key(APFloat((double)V));
+ ConstantFP *&Slot = (*FPConstants)[Key];
if (Slot) return Slot;
return Slot = new ConstantFP(Ty, V);
- // FIXME: Make long double constants work.
} else if (Ty == Type::X86_FP80Ty ||
Ty == Type::PPC_FP128Ty || Ty == Type::FP128Ty) {
assert(0 && "Long double constants not handled yet.");