Change LegalFPImmediates to use APFloat.

Add APFloat interfaces to ConstantFP, SelectionDAG.
Fix integer bit in double->APFloat conversion.
Convert LegalizeDAG to use APFloat interface in
ConstantFPSDNode uses.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41587 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dale Johannesen
2007-08-30 00:23:21 +00:00
parent 055c5449a4
commit f04afdbb48
11 changed files with 141 additions and 35 deletions

View File

@ -218,12 +218,20 @@ class ConstantFP : public Constant {
ConstantFP(const ConstantFP &); // DO NOT IMPLEMENT
protected:
ConstantFP(const Type *Ty, double V);
ConstantFP(const Type *Ty, const APFloat& V);
public:
/// get() - Static factory methods - Return objects of the specified value
static ConstantFP *get(const Type *Ty, double V);
static ConstantFP *get(const Type *Ty, const APFloat& V);
/// isValueValidForType - return true if Ty is big enough to represent V.
static bool isValueValidForType(const Type *Ty, double V);
static bool isValueValidForType(const Type *Ty, const APFloat& V);
static bool isValueValidForType(const Type *Ty, double V) {
if (Ty == Type::FloatTy)
return isValueValidForType(Ty, APFloat((float)V));
else
return isValueValidForType(Ty, APFloat(V));
}
inline double getValue() const {
if (&Val.getSemantics() == &APFloat::IEEEdouble)
return Val.convertToDouble();
@ -232,6 +240,7 @@ public:
else
assert(0);
}
inline const APFloat& getValueAPF() const { return Val; }
/// isNullValue - Return true if this is the value that would be returned by
/// getNullValue. Don't depend on == for doubles to tell us it's zero, it
@ -242,8 +251,15 @@ public:
/// it returns true for things that are clearly not equal, like -0.0 and 0.0.
/// As such, this method can be used to do an exact bit-for-bit comparison of
/// two floating point values.
bool isExactlyValue(double V) const;
bool isExactlyValue(const APFloat& V) const;
bool isExactlyValue(double V) const {
if (&Val.getSemantics() == &APFloat::IEEEdouble)
return isExactlyValue(APFloat(V));
else if (&Val.getSemantics() == &APFloat::IEEEsingle)
return isExactlyValue(APFloat((float)V));
else
assert(0);
}
/// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const ConstantFP *) { return true; }
static bool classof(const Value *V) {