#include "llvm/Constant.h"
#include "llvm/Type.h"
+#include "llvm/OperandTraits.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/APFloat.h"
public:
/// get() - Static factory methods - Return objects of the specified value
static ConstantFP *get(const APFloat &V);
- static ConstantFP *get(const Type *Ty, const APFloat &V) {
- return get(V);
- }
+
+ /// get() - This returns a constant fp for the specified value in the
+ /// specified type. This should only be used for simple constant values like
+ /// 2.0/1.0 etc, that are known-valid both as double and as the target format.
+ static ConstantFP *get(const Type *Ty, double V);
/// isValueValidForType - return true if Ty is big enough to represent V.
static bool isValueValidForType(const Type *Ty, const APFloat& V);
bool isExactlyValue(const APFloat& V) const;
bool isExactlyValue(double V) const {
+ // convert is not supported on this type
+ if (&Val.getSemantics() == &APFloat::PPCDoubleDouble)
+ return false;
APFloat FV(V);
FV.convert(Val.getSemantics(), APFloat::rmNearestTiesToEven);
return isExactlyValue(FV);
void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
ConstantAggregateZero(const ConstantAggregateZero &); // DO NOT IMPLEMENT
protected:
- explicit ConstantAggregateZero(const Type *Ty)
- : Constant(Ty, ConstantAggregateZeroVal, 0, 0) {}
+ explicit ConstantAggregateZero(const Type *ty)
+ : Constant(ty, ConstantAggregateZeroVal, 0, 0) {}
protected:
// allocate space for exactly zero operands
void *operator new(size_t s) {
ConstantArray(const ConstantArray &); // DO NOT IMPLEMENT
protected:
ConstantArray(const ArrayType *T, const std::vector<Constant*> &Val);
- ~ConstantArray();
public:
/// get() - Static factory methods - Return objects of the specified value
static Constant *get(const ArrayType *T, const std::vector<Constant*> &);
/// null termination.
static Constant *get(const std::string &Initializer, bool AddNull = true);
+ /// Transparently provide more efficient getOperand methods.
+ DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
+
/// getType - Specialize the getType() method to always return an ArrayType,
/// which reduces the amount of casting needed in parts of the compiler.
///
}
};
+template <>
+struct OperandTraits<ConstantArray> : VariadicOperandTraits<> {
+};
+
+DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantArray, Constant)
//===----------------------------------------------------------------------===//
// ConstantStruct - Constant Struct Declarations
ConstantStruct(const ConstantStruct &); // DO NOT IMPLEMENT
protected:
ConstantStruct(const StructType *T, const std::vector<Constant*> &Val);
- ~ConstantStruct();
public:
/// get() - Static factory methods - Return objects of the specified value
///
return get(std::vector<Constant*>(Vals, Vals+NumVals), Packed);
}
+ /// Transparently provide more efficient getOperand methods.
+ DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
+
/// getType() specialization - Reduce amount of casting...
///
inline const StructType *getType() const {
}
};
+template <>
+struct OperandTraits<ConstantStruct> : VariadicOperandTraits<> {
+};
+
+DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantStruct, Constant)
+
//===----------------------------------------------------------------------===//
/// ConstantVector - Constant Vector Declarations
///
ConstantVector(const ConstantVector &); // DO NOT IMPLEMENT
protected:
ConstantVector(const VectorType *T, const std::vector<Constant*> &Val);
- ~ConstantVector();
public:
/// get() - Static factory methods - Return objects of the specified value
static Constant *get(const VectorType *T, const std::vector<Constant*> &);
return get(std::vector<Constant*>(Vals, Vals+NumVals));
}
+ /// Transparently provide more efficient getOperand methods.
+ DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
+
/// getType - Specialize the getType() method to always return a VectorType,
/// which reduces the amount of casting needed in parts of the compiler.
///
}
};
+template <>
+struct OperandTraits<ConstantVector> : VariadicOperandTraits<> {
+};
+
+DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantVector, Constant)
+
//===----------------------------------------------------------------------===//
/// ConstantPointerNull - a constant pointer value that points to null
///
friend struct ConvertConstantType<ConstantExpr, Type>;
protected:
- ConstantExpr(const Type *Ty, unsigned Opcode, Use *Ops, unsigned NumOps)
- : Constant(Ty, ConstantExprVal, Ops, NumOps) {
+ ConstantExpr(const Type *ty, unsigned Opcode, Use *Ops, unsigned NumOps)
+ : Constant(ty, ConstantExprVal, Ops, NumOps) {
// Operation type (an Instruction opcode) is stored as the SubclassData.
SubclassData = Opcode;
}
Constant *Elt, Constant *Idx);
static Constant *getShuffleVectorTy(const Type *Ty, Constant *V1,
Constant *V2, Constant *Mask);
+ static Constant *getExtractValueTy(const Type *Ty, Constant *Agg,
+ Constant * const *Idxs, unsigned NumIdxs);
+ static Constant *getInsertValueTy(const Type *Ty, Constant *Agg,
+ Constant *Val,
+ Constant * const *Idxs, unsigned NumIdxs);
public:
// Static methods to construct a ConstantExpr of different kinds. Note that
static Constant *getIntToPtr(Constant *C, const Type *Ty);
static Constant *getBitCast (Constant *C, const Type *Ty);
+ /// Transparently provide more efficient getOperand methods.
+ DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
+
// @brief Convenience function for getting one of the casting operations
// using a CastOps opcode.
static Constant *getCast(
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 *getVICmp(unsigned short pred, Constant *LHS, Constant *RHS);
+ static Constant *getVFCmp(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);
static Constant *getExtractElement(Constant *Vec, Constant *Idx);
static Constant *getInsertElement(Constant *Vec, Constant *Elt,Constant *Idx);
static Constant *getShuffleVector(Constant *V1, Constant *V2, Constant *Mask);
+ static Constant *getExtractValue(Constant *Agg,
+ Constant* const *IdxList, unsigned NumIdx);
+ static Constant *getInsertValue(Constant *Agg, Constant *Val,
+ Constant* const *IdxList, unsigned NumIdx);
/// Floating point negation must be implemented with f(x) = -0.0 - x. This
/// method returns the negative zero constant for floating point or vector
virtual void destroyConstant();
virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
- /// Override methods to provide more type information...
- inline Constant *getOperand(unsigned i) {
- return cast<Constant>(User::getOperand(i));
- }
- inline Constant *getOperand(unsigned i) const {
- return const_cast<Constant*>(cast<Constant>(User::getOperand(i)));
- }
-
-
/// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const ConstantExpr *) { return true; }
static inline bool classof(const Value *V) {
}
};
+template <>
+struct OperandTraits<ConstantExpr> : VariadicOperandTraits<1> {
+};
+
+DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantExpr, Constant)
//===----------------------------------------------------------------------===//
/// UndefValue - 'undef' values are things that do not have specified contents.