inline const APInt& getValue() const {
return Val;
}
+
+ /// getBitWidth - Return the bitwidth of this constant.
+ unsigned getBitWidth() const { return Val.getBitWidth(); }
/// Return the constant as a 64-bit unsigned integer value after it
/// has been zero extended as appropriate for the type of this constant. Note
}
/// Return a ConstantInt with the specified value for the specified type. The
- /// value V will be canonicalized to a uint64_t but accessing it with either
- /// getSExtValue() or getZExtValue() (ConstantInt) will yield the correct
- /// sized/signed value for the type Ty.
+ /// value V will be canonicalized to a an unsigned APInt. Accessing it with
+ /// either getSExtValue() or getZExtValue() will yield a correctly sized and
+ /// signed value for the type Ty.
/// @brief Get a ConstantInt for a specific value.
- static ConstantInt *get(const Type *Ty, int64_t V);
- static ConstantInt *get(const Type *Ty, const APInt& V);
+ static ConstantInt *get(const Type *Ty, uint64_t V, bool isSigned = false);
/// Return a ConstantInt with the specified value and an implied Type. The
/// type is the integer type that corresponds to the bit width of the value.
return Val == 0;
}
+ /// This is just a convenience method to make client code smaller for a
+ /// common code. It also correctly performs the comparison without the
+ /// potential for an assertion from getZExtValue().
+ bool isZero() const {
+ return Val == 0;
+ }
+
+ /// This is just a convenience method to make client code smaller for a
+ /// common case. It also correctly performs the comparison without the
+ /// potential for an assertion from getZExtValue().
+ /// @brief Determine if the value is one.
+ bool isOne() const {
+ return Val == 1;
+ }
+
/// This function will return true iff every bit in this constant is set
/// to true.
/// @returns true iff this constant's bits are all set to true.
return Val.isMinValue();
}
+ /// This function will return true iff this constant represents a value with
+ /// active bits bigger than 64 bits or a value greater than the given uint64_t
+ /// value.
+ /// @returns true iff this constant is greater or equal to the given number.
+ /// @brief Determine if the value is greater or equal to the given number.
+ bool uge(uint64_t Num) {
+ return Val.getActiveBits() > 64 || Val.getZExtValue() >= Num;
+ }
+
+ /// @returns the 64-bit value of this constant if its active bits number is
+ /// not greater than 64, otherwise, just return the given uint64_t number.
+ /// @brief Get the constant's value if possible.
+ uint64_t getLimitedValue(uint64_t Limit = ~0ULL) const {
+ return Val.getLimitedValue(Limit);
+ }
+
/// @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
/// @brief Methods to support type inquiry through isa, cast, and dyn_cast.
static inline bool classof(const ConstantInt *) { return true; }
static bool classof(const Value *V) {
- return V->getValueType() == ConstantIntVal;
+ return V->getValueID() == ConstantIntVal;
}
static void ResetTrueFalse() { TheTrueVal = TheFalseVal = 0; }
private:
/// 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) {
- return V->getValueType() == ConstantFPVal;
+ return V->getValueID() == ConstantFPVal;
}
};
friend struct ConstantCreator<ConstantAggregateZero, Type, char>;
ConstantAggregateZero(const ConstantAggregateZero &); // DO NOT IMPLEMENT
protected:
- ConstantAggregateZero(const Type *Ty)
+ explicit ConstantAggregateZero(const Type *Ty)
: Constant(Ty, ConstantAggregateZeroVal, 0, 0) {}
public:
/// get() - static factory method for creating a null aggregate. It is
///
static bool classof(const ConstantAggregateZero *) { return true; }
static bool classof(const Value *V) {
- return V->getValueType() == ConstantAggregateZeroVal;
+ return V->getValueID() == ConstantAggregateZeroVal;
}
};
/// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const ConstantArray *) { return true; }
static bool classof(const Value *V) {
- return V->getValueType() == ConstantArrayVal;
+ return V->getValueID() == ConstantArrayVal;
}
};
/// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const ConstantStruct *) { return true; }
static bool classof(const Value *V) {
- return V->getValueType() == ConstantStructVal;
+ return V->getValueID() == ConstantStructVal;
}
};
/// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const ConstantVector *) { return true; }
static bool classof(const Value *V) {
- return V->getValueType() == ConstantVectorVal;
+ return V->getValueID() == ConstantVectorVal;
}
};
friend struct ConstantCreator<ConstantPointerNull, PointerType, char>;
ConstantPointerNull(const ConstantPointerNull &); // DO NOT IMPLEMENT
protected:
- ConstantPointerNull(const PointerType *T)
+ explicit ConstantPointerNull(const PointerType *T)
: Constant(reinterpret_cast<const Type*>(T),
Value::ConstantPointerNullVal, 0, 0) {}
/// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const ConstantPointerNull *) { return true; }
static bool classof(const Value *V) {
- return V->getValueType() == ConstantPointerNullVal;
+ return V->getValueID() == ConstantPointerNullVal;
}
};
/// 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) {
- return V->getValueType() == ConstantExprVal;
+ return V->getValueID() == ConstantExprVal;
}
};
friend struct ConstantCreator<UndefValue, Type, char>;
UndefValue(const UndefValue &); // DO NOT IMPLEMENT
protected:
- UndefValue(const Type *T) : Constant(T, UndefValueVal, 0, 0) {}
+ explicit UndefValue(const Type *T) : Constant(T, UndefValueVal, 0, 0) {}
public:
/// get() - Static factory methods - Return an 'undef' object of the specified
/// type.
/// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const UndefValue *) { return true; }
static bool classof(const Value *V) {
- return V->getValueType() == UndefValueVal;
+ return V->getValueID() == UndefValueVal;
}
};