/// constant's type.
/// @returns true if the constant's value is maximal.
/// @brief Determine if the value is maximal.
- virtual bool isMaxValue() const = 0;
+ virtual bool isMaxValue(bool isSigned) const = 0;
/// This function is implemented by subclasses and will return true iff this
/// constant represents the smallest value that may be represented by this
/// constant's type.
/// @returns true if the constant's value is minimal
/// @brief Determine if the value is minimal.
- virtual bool isMinValue() const = 0;
+ virtual bool isMinValue(bool isSigned) const = 0;
/// This function is implemented by subclasses and will return true iff every
/// bit in this constant is set to true.
/// @brief Determine if the value is all ones.
virtual bool isAllOnesValue() const = 0;
- /// @returns the largest value for an integer constant of the given type
- /// @brief Get the maximal value
- static ConstantIntegral *getMaxValue(const Type *Ty);
-
- /// @returns the smallest value for an integer constant of the given type
- /// @brief Get the minimal value
- static ConstantIntegral *getMinValue(const Type *Ty);
-
/// @returns the value for an integer constant of the given type that has all
/// its bits set to true.
/// @brief Get the all ones value
/// @see ConstantIntegral for details
/// @brief Implement overrides
virtual bool isNullValue() const { return getValue() == false; }
- virtual bool isMaxValue() const { return getValue() == true; }
- virtual bool isMinValue() const { return getValue() == false; }
+ virtual bool isMaxValue(bool isSigned) const { return getValue() == true; }
+ virtual bool isMinValue(bool isSigned) const { return getValue() == false; }
virtual bool isAllOnesValue() const { return getValue() == true; }
/// @brief Methods to support type inquiry through isa, cast, and dyn_cast:
/// by this type.
/// @see ConstantIntegeral
/// @brief Override implementation
- virtual bool isMaxValue() const {
- if (getType()->isSigned()) {
+ virtual bool isMaxValue(bool isSigned) const {
+ if (isSigned) {
int64_t V = getSExtValue();
if (V < 0) return false; // Be careful about wrap-around on 'long's
++V;
- return !isValueValidForType(getType(), V) || V < 0;
+ return !isValueValidForType(getType()->getSignedVersion(), V) || V < 0;
}
return isAllOnesValue();
}
/// this type.
/// @see ConstantIntegral
/// @brief Override implementation
- virtual bool isMinValue() const {
- if (getType()->isSigned()) {
+ virtual bool isMinValue(bool isSigned) const {
+ if (isSigned) {
int64_t V = getSExtValue();
if (V > 0) return false; // Be careful about wrap-around on 'long's
--V;
- return !isValueValidForType(getType(), V) || V > 0;
+ return !isValueValidForType(getType()->getSignedVersion(), V) || V > 0;
}
return getZExtValue() == 0;
}
/// get() - Static factory methods - Return objects of the specified value
///
static Constant *get(const StructType *T, const std::vector<Constant*> &V);
- static Constant *get(const std::vector<Constant*> &V);
+ static Constant *get(const std::vector<Constant*> &V, bool packed = false);
/// getType() specialization - Reduce amount of casting...
///
// These private methods are used by the type resolution code to create
// ConstantExprs in intermediate forms.
static Constant *getTy(const Type *Ty, unsigned Opcode,
- Constant *C1, Constant *C2, unsigned short pred = 0);
+ Constant *C1, Constant *C2);
+ static Constant *getCompareTy(unsigned Opcode, unsigned short pred,
+ Constant *C1, Constant *C2);
static Constant *getShiftTy(const Type *Ty,
unsigned Opcode, Constant *C1, Constant *C2);
static Constant *getSelectTy(const Type *Ty,
/// Cast constant expr
///
- static Constant *getTrunc (Constant *C, const Type *Ty);
- static Constant *getSignExtend (Constant *C, const Type *Ty);
- static Constant *getZeroExtend (Constant *C, const Type *Ty);
- static Constant *getFPTrunc (Constant *C, const Type *Ty);
- static Constant *getFPExtend (Constant *C, const Type *Ty);
- static Constant *getUIToFP (Constant *C, const Type *Ty);
- static Constant *getSIToFP (Constant *C, const Type *Ty);
- static Constant *getFPToUI (Constant *C, const Type *Ty);
- static Constant *getFPToSI (Constant *C, const Type *Ty);
- static Constant *getPtrToInt (Constant *C, const Type *Ty);
- static Constant *getIntToPtr (Constant *C, const Type *Ty);
- static Constant *getBitCast (Constant *C, const Type *Ty);
+ static Constant *getTrunc (Constant *C, const Type *Ty);
+ static Constant *getSExt (Constant *C, const Type *Ty);
+ static Constant *getZExt (Constant *C, const Type *Ty);
+ static Constant *getFPTrunc (Constant *C, const Type *Ty);
+ static Constant *getFPExtend(Constant *C, const Type *Ty);
+ static Constant *getUIToFP (Constant *C, const Type *Ty);
+ static Constant *getSIToFP (Constant *C, const Type *Ty);
+ static Constant *getFPToUI (Constant *C, const Type *Ty);
+ static Constant *getFPToSI (Constant *C, const Type *Ty);
+ static Constant *getPtrToInt(Constant *C, const Type *Ty);
+ static Constant *getIntToPtr(Constant *C, const Type *Ty);
+ static Constant *getBitCast (Constant *C, const Type *Ty);
// @brief Convenience function for getting one of the casting operations
// using a CastOps opcode.
const Type *Ty ///< The type to which the constant is converted
);
- // This method uses the CastInst::getCastOpcode method to infer the
- // cast opcode to use.
- // @brief Get a ConstantExpr Conversion operator that casts C to Ty
- static Constant *getInferredCast(Constant *C, bool SrcIsSigned,
- const Type *Ty, bool DestIsSigned);
+ // @brief Create a ZExt or BitCast cast constant expression
+ static Constant *getZExtOrBitCast(
+ Constant *C, ///< The constant to zext or bitcast
+ const Type *Ty ///< The type to zext or bitcast C to
+ );
+
+ // @brief Create a SExt or BitCast cast constant expression
+ static Constant *getSExtOrBitCast(
+ Constant *C, ///< The constant to sext or bitcast
+ const Type *Ty ///< The type to sext or bitcast C to
+ );
- static Constant *getCast(Constant *C, const Type *Ty) {
- return getInferredCast(C, C->getType()->isSigned(), Ty, Ty->isSigned());
- }
+ // @brief Create a Trunc or BitCast cast constant expression
+ static Constant *getTruncOrBitCast(
+ Constant *C, ///< The constant to trunc or bitcast
+ const Type *Ty ///< The type to trunc or bitcast C to
+ );
+
+ /// @brief Create a BitCast or a PtrToInt cast constant expression
+ static Constant *getPointerCast(
+ Constant *C, ///< The pointer value to be casted (operand 0)
+ const Type *Ty ///< The type to which cast should be made
+ );
+
+ /// @brief Create a ZExt, Bitcast or Trunc for integer -> integer casts
+ static Constant *getIntegerCast(
+ Constant *C, ///< The integer constant to be casted
+ const Type *Ty, ///< The integer type to cast to
+ bool isSigned ///< Whether C should be treated as signed or not
+ );
+
+ /// @brief Create a FPExt, Bitcast or FPTrunc for fp -> fp casts
+ static Constant *getFPCast(
+ Constant *C, ///< The integer constant to be casted
+ const Type *Ty ///< The integer type to cast to
+ );
/// @brief Return true if this is a convert constant expression
bool isCast() const;
/// ConstantExpr::get - Return a binary or shift operator constant expression,
/// folding if possible.
///
- static Constant *get(unsigned Opcode, Constant *C1, Constant *C2,
- unsigned short pred = 0);
+ static Constant *get(unsigned Opcode, Constant *C1, Constant *C2);
+
+ /// @brief Return an ICmp or FCmp comparison operator constant expression.
+ static Constant *getCompare(unsigned Opcode, unsigned short pred,
+ Constant *C1, Constant *C2);
/// ConstantExpr::get* - Return some common constants without having to
/// specify the full Instruction::OPCODE identifier.