#include "llvm/OperandTraits.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/APFloat.h"
-#include "llvm/ADT/SmallVector.h"
#include <vector>
namespace llvm {
struct ConstantCreator;
template<class ConstantClass, class TypeClass>
struct ConvertConstantType;
+template<typename T, unsigned N>
+class SmallVector;
//===----------------------------------------------------------------------===//
/// This is the shared class of boolean and integer constants. This class
/// Return a ConstantInt constructed from the string strStart with the given
/// radix.
- static ConstantInt *get(const IntegerType *Ty, const StringRef &Str,
+ static ConstantInt *get(const IntegerType *Ty, StringRef Str,
uint8_t radix);
/// If Ty is a vector type, return a Constant with a splat of the given
/// only be used for simple constant values like 2.0/1.0 etc, that are
/// known-valid both as host double and as the target format.
static Constant *get(const Type* Ty, double V);
- static Constant *get(const Type* Ty, const StringRef &Str);
+ static Constant *get(const Type* Ty, StringRef Str);
static ConstantFP *get(LLVMContext &Context, const APFloat &V);
static ConstantFP *getNegativeZero(const Type* Ty);
static ConstantFP *getInfinity(const Type *Ty, bool Negative = false);
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
- /// considers -0.0 to be null as well as 0.0. :(
+ /// getNullValue. For ConstantFP, this is +0.0, but not -0.0. To handle the
+ /// two the same, use isZero().
virtual bool isNullValue() const;
/// isNegativeZeroValue - Return true if the value is what would be returned
return Val.isZero() && Val.isNegative();
}
+ /// isZero - Return true if the value is positive or negative zero.
+ bool isZero() const { return Val.isZero(); }
+
+ /// isNaN - Return true if the value is a NaN.
+ bool isNaN() const { return Val.isNaN(); }
+
/// 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
/// of the array by one (you've been warned). However, in some situations
/// this is not desired so if AddNull==false then the string is copied without
/// null termination.
- static Constant *get(LLVMContext &Context, const StringRef &Initializer,
+ static Constant *get(LLVMContext &Context, StringRef Initializer,
bool AddNull = true);
/// Transparently provide more efficient getOperand methods.
};
template <>
-struct OperandTraits<ConstantArray> : public VariadicOperandTraits<> {
+struct OperandTraits<ConstantArray> :
+ public VariadicOperandTraits<ConstantArray> {
};
DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantArray, Constant)
};
template <>
-struct OperandTraits<ConstantStruct> : public VariadicOperandTraits<> {
+struct OperandTraits<ConstantStruct> :
+ public VariadicOperandTraits<ConstantStruct> {
};
DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantStruct, Constant)
+
//===----------------------------------------------------------------------===//
/// ConstantVector - Constant Vector Declarations
///
};
template <>
-struct OperandTraits<ConstantVector> : public VariadicOperandTraits<> {
+struct OperandTraits<ConstantVector> :
+ public VariadicOperandTraits<ConstantVector> {
};
DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantVector, Constant)
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
Function *getFunction() const { return (Function*)Op<0>().get(); }
-
- /// getBasicBlock - This returns the block associated with this BlockAddress.
- /// Note that this can return null if the block this originally referred to
- /// was deleted.
BasicBlock *getBasicBlock() const { return (BasicBlock*)Op<1>().get(); }
/// isNullValue - Return true if this is the value that would be returned by
};
template <>
-struct OperandTraits<BlockAddress> : public FixedNumOperandTraits<2> {
+struct OperandTraits<BlockAddress> :
+ public FixedNumOperandTraits<BlockAddress, 2> {
};
DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(BlockAddress, Value)
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;
+ setValueSubclassData(Opcode);
}
// These private methods are used by the type resolution code to create
Constant *C2);
static Constant *getSelectTy(const Type *Ty,
Constant *C1, Constant *C2, Constant *C3);
+ template<typename IndexTy>
static Constant *getGetElementPtrTy(const Type *Ty, Constant *C,
- Value* const *Idxs, unsigned NumIdxs);
+ IndexTy const *Idxs, unsigned NumIdxs);
+ template<typename IndexTy>
static Constant *getInBoundsGetElementPtrTy(const Type *Ty, Constant *C,
- Value* const *Idxs,
+ IndexTy const *Idxs,
unsigned NumIdxs);
static Constant *getExtractElementTy(const Type *Ty, Constant *Val,
Constant *Idx);
static Constant *getInsertValueTy(const Type *Ty, Constant *Agg,
Constant *Val,
const unsigned *Idxs, unsigned NumIdxs);
+ template<typename IndexTy>
+ static Constant *getGetElementPtrImpl(Constant *C,
+ IndexTy const *IdxList,
+ unsigned NumIdx);
+ template<typename IndexTy>
+ static Constant *getInBoundsGetElementPtrImpl(Constant *C,
+ IndexTy const *IdxList,
+ unsigned NumIdx);
public:
// Static methods to construct a ConstantExpr of different kinds. Note that
// ConstantExpr class, because they will attempt to fold the constant
// expression into something simpler if possible.
- /// Cast constant expr
- ///
-
/// getAlignOf constant expr - computes the alignment of a type in a target
- /// independent way (Note: the return type is an i32; Note: assumes that i8
- /// is byte aligned).
+ /// independent way (Note: the return type is an i64).
static Constant *getAlignOf(const Type* Ty);
- /// getSizeOf constant expr - computes the size of a type in a target
- /// independent way (Note: the return type is an i64).
+ /// getSizeOf constant expr - computes the (alloc) size of a type (in
+ /// address-units, not bits) in a target independent way (Note: the return
+ /// type is an i64).
///
static Constant *getSizeOf(const Type* Ty);
- /// getOffsetOf constant expr - computes the offset of a field in a target
- /// independent way (Note: the return type is an i64).
+ /// getOffsetOf constant expr - computes the offset of a struct field in a
+ /// target independent way (Note: the return type is an i64).
+ ///
+ static Constant *getOffsetOf(const StructType* STy, unsigned FieldNo);
+
+ /// getOffsetOf constant expr - This is a generalized form of getOffsetOf,
+ /// which supports any aggregate type, and any Constant index.
///
- static Constant *getOffsetOf(const StructType* Ty, unsigned FieldNo);
+ static Constant *getOffsetOf(const Type* Ty, Constant *FieldNo);
static Constant *getNeg(Constant *C);
static Constant *getFNeg(Constant *C);
static Constant *getIntToPtr(Constant *C, const Type *Ty);
static Constant *getBitCast (Constant *C, const Type *Ty);
+ static Constant *getNSWNeg(Constant *C);
+ static Constant *getNUWNeg(Constant *C);
static Constant *getNSWAdd(Constant *C1, Constant *C2);
+ static Constant *getNUWAdd(Constant *C1, Constant *C2);
static Constant *getNSWSub(Constant *C1, Constant *C2);
+ static Constant *getNUWSub(Constant *C1, Constant *C2);
+ static Constant *getNSWMul(Constant *C1, Constant *C2);
+ static Constant *getNUWMul(Constant *C1, Constant *C2);
static Constant *getExactSDiv(Constant *C1, Constant *C2);
/// Transparently provide more efficient getOperand methods.
virtual bool isNullValue() const { return false; }
/// getOpcode - Return the opcode at the root of this constant expression
- unsigned getOpcode() const { return SubclassData; }
+ unsigned getOpcode() const { return getSubclassDataFromValue(); }
/// getPredicate - Return the ICMP or FCMP predicate value. Assert if this is
/// not an ICMP or FCMP constant expression.
static inline bool classof(const Value *V) {
return V->getValueID() == ConstantExprVal;
}
+
+private:
+ // Shadow Value::setValueSubclassData with a private forwarding method so that
+ // subclasses cannot accidentally use it.
+ void setValueSubclassData(unsigned short D) {
+ Value::setValueSubclassData(D);
+ }
};
template <>
-struct OperandTraits<ConstantExpr> : public VariadicOperandTraits<1> {
+struct OperandTraits<ConstantExpr> :
+ public VariadicOperandTraits<ConstantExpr, 1> {
};
DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantExpr, Constant)
/// UndefValue - 'undef' values are things that do not have specified contents.
/// These are used for a variety of purposes, including global variable
/// initializers and operands to instructions. 'undef' values can occur with
-/// any type.
+/// any first-class type.
+///
+/// Undef values aren't exactly constants; if they have multiple uses, they
+/// can appear to have different bit patterns at each use. See
+/// LangRef.html#undefvalues for details.
///
class UndefValue : public Constant {
friend struct ConstantCreator<UndefValue, Type, char>;
return V->getValueID() == UndefValueVal;
}
};
+
} // End llvm namespace
#endif