APFloat Val;
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, 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();
- else if (&Val.getSemantics() == &APFloat::IEEEsingle)
- return (double)Val.convertToFloat();
- else
- assert(0);
- }
inline const APFloat& getValueAPF() const { return Val; }
/// isNullValue - Return true if this is the value that would be returned by
/// considers -0.0 to be null as well as 0.0. :(
virtual bool isNullValue() const;
+ // Get a negative zero.
+ static ConstantFP *getNegativeZero(const Type* Ty);
+
/// isExactlyValue - We don't rely on operator== working on double values, as
/// 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.
+ /// two floating point values. The version with a double operand is retained
+ /// because it's so convenient to write isExactlyValue(2.0), but please use
+ /// it only for constants.
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);
+ assert(0);
+ return false;
}
/// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const ConstantFP *) { return true; }
/// @brief Determine if the value is all ones.
bool isAllOnesValue() const;
+ /// getSplatValue - If this is a splat constant, meaning that all of the
+ /// elements have the same value, return that value. Otherwise return NULL.
+ Constant *getSplatValue();
+
virtual void destroyConstant();
virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
}
/// getSizeOf constant expr - computes the size of a type in a target
- /// independent way (Note: the return type is a ULong).
+ /// independent way (Note: the return type is an i64).
///
static Constant *getSizeOf(const Type *Ty);
static Constant *getAnd(Constant *C1, Constant *C2);
static Constant *getOr(Constant *C1, Constant *C2);
static Constant *getXor(Constant *C1, Constant *C2);
- static Constant* getICmp(unsigned short pred, Constant* LHS, Constant* RHS);
- static Constant* getFCmp(unsigned short pred, Constant* LHS, Constant* RHS);
+ static Constant *getICmp(unsigned short pred, Constant *LHS, Constant *RHS);
+ static Constant *getFCmp(unsigned short pred, Constant *LHS, Constant *RHS);
static Constant *getShl(Constant *C1, Constant *C2);
static Constant *getLShr(Constant *C1, Constant *C2);
static Constant *getAShr(Constant *C1, Constant *C2);