-static ConstantIntegral *getMaxValue(const Type *Ty, bool isSigned = false) {
- if (Ty == Type::BoolTy)
- return ConstantBool::getTrue();
- if (Ty->isInteger()) {
- if (isSigned) {
- // Calculate 011111111111111...
- unsigned TypeBits = Ty->getPrimitiveSize()*8;
- int64_t Val = INT64_MAX; // All ones
- Val >>= 64-TypeBits; // Shift out unwanted 1 bits...
- return ConstantInt::get(Ty, Val);
- }
- return ConstantInt::getAllOnesValue(Ty);
- }
- return 0;
-}
-
-// Static constructor to create the minimum constant for an integral type...
-static ConstantIntegral *getMinValue(const Type *Ty, bool isSigned = false) {
- if (Ty == Type::BoolTy)
- return ConstantBool::getFalse();
- if (Ty->isInteger()) {
- if (isSigned) {
- // Calculate 1111111111000000000000
- unsigned TypeBits = Ty->getPrimitiveSize()*8;
- int64_t Val = -1; // All ones
- Val <<= TypeBits-1; // Shift over to the right spot
- return ConstantInt::get(Ty, Val);
- }
- return ConstantInt::get(Ty, 0);
- }
- return 0;
-}
-static ConstantIntegral *Next(ConstantIntegral *CI) {
- if (ConstantBool *CB = dyn_cast<ConstantBool>(CI))
- return ConstantBool::get(!CB->getValue());
-
- Constant *Result = ConstantExpr::getAdd(CI,
- ConstantInt::get(CI->getType(), 1));
- return cast<ConstantIntegral>(Result);
-}
-
-static bool LT(ConstantIntegral *A, ConstantIntegral *B, bool isSigned) {
- Constant *C = ConstantExpr::getICmp(
- (isSigned ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT), A, B);
- assert(isa<ConstantBool>(C) && "Constant folding of integrals not impl??");
- return cast<ConstantBool>(C)->getValue();
-}
-
-static bool LTE(ConstantIntegral *A, ConstantIntegral *B, bool isSigned) {
- Constant *C = ConstantExpr::getICmp(
- (isSigned ? ICmpInst::ICMP_SLE : ICmpInst::ICMP_ULE), A, B);
- assert(isa<ConstantBool>(C) && "Constant folding of integrals not impl??");
- return cast<ConstantBool>(C)->getValue();
-}
-
-static bool GT(ConstantIntegral *A, ConstantIntegral *B, bool isSigned) {
- return LT(B, A, isSigned); }
-
-static ConstantIntegral *Min(ConstantIntegral *A, ConstantIntegral *B,
- bool isSigned) {
- return LT(A, B, isSigned) ? A : B;
-}
-static ConstantIntegral *Max(ConstantIntegral *A, ConstantIntegral *B,
- bool isSigned) {
- return GT(A, B, isSigned) ? A : B;
-}
-