+// Static constructor to create the minimum constant for an integral type...
+ConstantIntegral *ConstantIntegral::getMinValue(const Type *Ty) {
+ switch (Ty->getPrimitiveID()) {
+ case Type::BoolTyID: return ConstantBool::False;
+ case Type::SByteTyID:
+ case Type::ShortTyID:
+ case Type::IntTyID:
+ case Type::LongTyID: {
+ // Calculate 1111111111000000000000
+ unsigned TypeBits = Ty->getPrimitiveSize()*8;
+ int64_t Val = -1; // All ones
+ Val <<= TypeBits-1; // Shift over to the right spot
+ return ConstantSInt::get(Ty, Val);
+ }
+
+ case Type::UByteTyID:
+ case Type::UShortTyID:
+ case Type::UIntTyID:
+ case Type::ULongTyID: return ConstantUInt::get(Ty, 0);
+
+ default: return 0;
+ }
+}
+
+// Static constructor to create an integral constant with all bits set
+ConstantIntegral *ConstantIntegral::getAllOnesValue(const Type *Ty) {
+ switch (Ty->getPrimitiveID()) {
+ case Type::BoolTyID: return ConstantBool::True;
+ case Type::SByteTyID:
+ case Type::ShortTyID:
+ case Type::IntTyID:
+ case Type::LongTyID: return ConstantSInt::get(Ty, -1);
+
+ case Type::UByteTyID:
+ case Type::UShortTyID:
+ case Type::UIntTyID:
+ case Type::ULongTyID: {
+ // Calculate ~0 of the right type...
+ unsigned TypeBits = Ty->getPrimitiveSize()*8;
+ uint64_t Val = ~0ULL; // All ones
+ Val >>= 64-TypeBits; // Shift out unwanted 1 bits...
+ return ConstantUInt::get(Ty, Val);
+ }
+ default: return 0;
+ }