- Renamed Type::isIntegral() to Type::isInteger()

- Added new method Type::isIntegral() that is the same as isInteger, but
    also accepts bool.

llvm-svn: 3574
This commit is contained in:
Chris Lattner 2002-09-03 01:08:28 +00:00
parent bc6bdc2992
commit b0b412e66e
11 changed files with 54 additions and 77 deletions

View File

@ -72,12 +72,12 @@ GetConstantValueAsUnsignedInt(const Value *V,
isValidConstant = true; isValidConstant = true;
if (isa<Constant>(V)) if (isa<Constant>(V))
if (V->getType() == Type::BoolTy) if (const ConstantBool *CB = dyn_cast<ConstantBool>(V))
return (int64_t) cast<ConstantBool>(V)->getValue(); return (int64_t)CB->getValue();
else if (V->getType()->isIntegral()) else if (const ConstantSInt *CS = dyn_cast<ConstantSInt>(V))
return (V->getType()->isUnsigned() return (uint64_t)CS->getValue();
? cast<ConstantUInt>(V)->getValue() else if (const ConstantUInt *CU = dyn_cast<ConstantUInt>(V))
: (uint64_t) cast<ConstantSInt>(V)->getValue()); return CU->getValue();
isValidConstant = false; isValidConstant = false;
return 0; return 0;
@ -343,7 +343,7 @@ ChooseRegOrImmed(Value* val,
} }
// Otherwise it needs to be an integer or a NULL pointer // Otherwise it needs to be an integer or a NULL pointer
if (! CPV->getType()->isIntegral() && if (! CPV->getType()->isInteger() &&
! (isa<PointerType>(CPV->getType()) && ! (isa<PointerType>(CPV->getType()) &&
CPV->isNullValue())) CPV->isNullValue()))
return opType; return opType;

View File

@ -1094,7 +1094,7 @@ void Interpreter::callMethod(Function *M, const vector<GenericValue> &ArgVals) {
cout << "\n"; cout << "\n";
if (RetTy->isIntegral()) if (RetTy->isIntegral())
ExitCode = Result.SByteVal; // Capture the exit code of the program ExitCode = Result.IntVal; // Capture the exit code of the program
} }
} }

View File

@ -294,8 +294,8 @@ bool Interpreter::callMainMethod(const string &Name,
} }
// fallthrough // fallthrough
case 1: case 1:
if (!MT->getParamTypes()[0]->isIntegral()) { if (!MT->getParamTypes()[0]->isInteger()) {
cout << "First argument of '" << Name << "' should be integral!\n"; cout << "First argument of '" << Name << "' should be an integer!\n";
return true; return true;
} else { } else {
GenericValue GV; GV.UIntVal = InputArgv.size(); GenericValue GV; GV.UIntVal = InputArgv.size();

View File

@ -308,7 +308,7 @@ UltraSparcInstrInfo::CreateCodeToLoadConst(const TargetMachine& target,
mcfi.addTemp(tmpReg); mcfi.addTemp(tmpReg);
CreateSETXLabel(target, val, tmpReg, dest, mvec); CreateSETXLabel(target, val, tmpReg, dest, mvec);
} }
else if (valType->isIntegral() || valType == Type::BoolTy) else if (valType->isIntegral())
{ {
bool isValidConstant; bool isValidConstant;
unsigned opSize = target.DataLayout.getTypeSize(val->getType()); unsigned opSize = target.DataLayout.getTypeSize(val->getType());
@ -396,8 +396,8 @@ UltraSparcInstrInfo::CreateCodeToCopyIntToFloat(const TargetMachine& target,
vector<MachineInstr*>& mvec, vector<MachineInstr*>& mvec,
MachineCodeForInstruction& mcfi) const MachineCodeForInstruction& mcfi) const
{ {
assert((val->getType()->isIntegral() || isa<PointerType>(val->getType())) assert((val->getType()->isInteger() || isa<PointerType>(val->getType()))
&& "Source type must be integral"); && "Source type must be integer or pointer");
assert(dest->getType()->isFloatingPoint() assert(dest->getType()->isFloatingPoint()
&& "Dest type must be float/double"); && "Dest type must be float/double");
@ -445,8 +445,8 @@ UltraSparcInstrInfo::CreateCodeToCopyFloatToInt(const TargetMachine& target,
const Type* destTy = dest->getType(); const Type* destTy = dest->getType();
assert(opTy->isFloatingPoint() && "Source type must be float/double"); assert(opTy->isFloatingPoint() && "Source type must be float/double");
assert((destTy->isIntegral() || isa<PointerType>(destTy)) assert((destTy->isInteger() || isa<PointerType>(destTy))
&& "Dest type must be integral"); && "Dest type must be integer or pointer");
int offset = MachineCodeForMethod::get(F).allocateLocalVar(target, val); int offset = MachineCodeForMethod::get(F).allocateLocalVar(target, val);

View File

@ -396,7 +396,7 @@ ChooseSubInstructionByType(const Type* resultType)
{ {
MachineOpCode opCode = INVALID_OPCODE; MachineOpCode opCode = INVALID_OPCODE;
if (resultType->isIntegral() || isa<PointerType>(resultType)) if (resultType->isInteger() || isa<PointerType>(resultType))
{ {
opCode = SUB; opCode = SUB;
} }
@ -474,7 +474,7 @@ ChooseMulInstructionByType(const Type* resultType)
{ {
MachineOpCode opCode = INVALID_OPCODE; MachineOpCode opCode = INVALID_OPCODE;
if (resultType->isIntegral()) if (resultType->isInteger())
opCode = MULX; opCode = MULX;
else else
switch(resultType->getPrimitiveID()) switch(resultType->getPrimitiveID())
@ -577,7 +577,7 @@ CreateMulConstInstruction(const TargetMachine &target, Function* F,
// //
const Type* resultType = destVal->getType(); const Type* resultType = destVal->getType();
if (resultType->isIntegral() || isa<PointerType>(resultType)) if (resultType->isInteger() || isa<PointerType>(resultType))
{ {
bool isValidConst; bool isValidConst;
int64_t C = GetConstantValueAsSignedInt(constOp, isValidConst); int64_t C = GetConstantValueAsSignedInt(constOp, isValidConst);
@ -719,7 +719,7 @@ ChooseDivInstruction(TargetMachine &target,
const Type* resultType = instrNode->getInstruction()->getType(); const Type* resultType = instrNode->getInstruction()->getType();
if (resultType->isIntegral()) if (resultType->isInteger())
opCode = resultType->isSigned()? SDIVX : UDIVX; opCode = resultType->isSigned()? SDIVX : UDIVX;
else else
switch(resultType->getPrimitiveID()) switch(resultType->getPrimitiveID())
@ -752,7 +752,7 @@ CreateDivConstInstruction(TargetMachine &target,
// //
const Type* resultType = instrNode->getInstruction()->getType(); const Type* resultType = instrNode->getInstruction()->getType();
if (resultType->isIntegral()) if (resultType->isInteger())
{ {
unsigned pow; unsigned pow;
bool isValidConst; bool isValidConst;
@ -1296,7 +1296,7 @@ GetInstructionsByRule(InstructionNode* subtreeRoot,
Constant *constVal = cast<Constant>(constNode->getValue()); Constant *constVal = cast<Constant>(constNode->getValue());
bool isValidConst; bool isValidConst;
if ((constVal->getType()->isIntegral() if ((constVal->getType()->isInteger()
|| isa<PointerType>(constVal->getType())) || isa<PointerType>(constVal->getType()))
&& GetConstantValueAsSignedInt(constVal, isValidConst) == 0 && GetConstantValueAsSignedInt(constVal, isValidConst) == 0
&& isValidConst) && isValidConst)
@ -1432,8 +1432,7 @@ GetInstructionsByRule(InstructionNode* subtreeRoot,
case 22: // reg: ToBoolTy(reg): case 22: // reg: ToBoolTy(reg):
{ {
const Type* opType = subtreeRoot->leftChild()->getValue()->getType(); const Type* opType = subtreeRoot->leftChild()->getValue()->getType();
assert(opType->isIntegral() || isa<PointerType>(opType) assert(opType->isIntegral() || isa<PointerType>(opType));
|| opType == Type::BoolTy);
forwardOperandNum = 0; // forward first operand to user forwardOperandNum = 0; // forward first operand to user
break; break;
} }
@ -1446,9 +1445,7 @@ GetInstructionsByRule(InstructionNode* subtreeRoot,
Instruction* destI = subtreeRoot->getInstruction(); Instruction* destI = subtreeRoot->getInstruction();
Value* opVal = subtreeRoot->leftChild()->getValue(); Value* opVal = subtreeRoot->leftChild()->getValue();
const Type* opType = subtreeRoot->leftChild()->getValue()->getType(); const Type* opType = subtreeRoot->leftChild()->getValue()->getType();
if (opType->isIntegral() if (opType->isIntegral() || isa<PointerType>(opType))
|| isa<PointerType>(opType)
|| opType == Type::BoolTy)
{ {
unsigned opSize = target.DataLayout.getTypeSize(opType); unsigned opSize = target.DataLayout.getTypeSize(opType);
unsigned destSize = target.DataLayout.getTypeSize(destI->getType()); unsigned destSize = target.DataLayout.getTypeSize(destI->getType());
@ -1490,9 +1487,7 @@ GetInstructionsByRule(InstructionNode* subtreeRoot,
MachineCodeForInstruction& mcfi =MachineCodeForInstruction::get(destI); MachineCodeForInstruction& mcfi =MachineCodeForInstruction::get(destI);
const Type* opType = opVal->getType(); const Type* opType = opVal->getType();
if (opType->isIntegral() if (opType->isIntegral() || isa<PointerType>(opType))
|| isa<PointerType>(opType)
|| opType == Type::BoolTy)
{ {
// These operand types have the same format as the destination, // These operand types have the same format as the destination,
// but may have different size: add sign bits or mask as needed. // but may have different size: add sign bits or mask as needed.
@ -2091,9 +2086,8 @@ GetInstructionsByRule(InstructionNode* subtreeRoot,
Instruction* shlInstr = subtreeRoot->getInstruction(); Instruction* shlInstr = subtreeRoot->getInstruction();
const Type* opType = argVal1->getType(); const Type* opType = argVal1->getType();
assert(opType->isIntegral() assert((opType->isInteger() || isa<PointerType>(opType)) &&
|| opType == Type::BoolTy "Shl unsupported for other types");
|| isa<PointerType>(opType)&&"Shl unsupported for other types");
CreateShiftInstructions(target, shlInstr->getParent()->getParent(), CreateShiftInstructions(target, shlInstr->getParent()->getParent(),
(opType == Type::LongTy)? SLLX : SLL, (opType == Type::LongTy)? SLLX : SLL,
@ -2104,8 +2098,8 @@ GetInstructionsByRule(InstructionNode* subtreeRoot,
case 63: // reg: Shr(reg, reg) case 63: // reg: Shr(reg, reg)
{ const Type* opType = subtreeRoot->leftChild()->getValue()->getType(); { const Type* opType = subtreeRoot->leftChild()->getValue()->getType();
assert(opType->isIntegral() assert((opType->isInteger() || isa<PointerType>(opType)) &&
|| isa<PointerType>(opType)&&"Shr unsupported for other types"); "Shr unsupported for other types");
mvec.push_back(new MachineInstr((opType->isSigned() mvec.push_back(new MachineInstr((opType->isSigned()
? ((opType == Type::LongTy)? SRAX : SRA) ? ((opType == Type::LongTy)? SRAX : SRA)
: ((opType == Type::LongTy)? SRLX : SRL)))); : ((opType == Type::LongTy)? SRLX : SRL))));

View File

@ -62,8 +62,7 @@ ChooseAddInstructionByType(const Type* resultType)
if (resultType->isIntegral() || if (resultType->isIntegral() ||
isa<PointerType>(resultType) || isa<PointerType>(resultType) ||
isa<FunctionType>(resultType) || isa<FunctionType>(resultType) ||
resultType == Type::LabelTy || resultType == Type::LabelTy)
resultType == Type::BoolTy)
{ {
opCode = ADD; opCode = ADD;
} }

View File

@ -651,7 +651,7 @@ void UltraSparcRegInfo::suggestRegs4CallArgs(MachineInstr *CallMI,
const Value *argCopy = argDesc->getArgInfo(i).getArgCopy(); const Value *argCopy = argDesc->getArgInfo(i).getArgCopy();
if (argCopy != NULL) if (argCopy != NULL)
{ {
assert(regType != IntRegType && argCopy->getType()->isIntegral() assert(regType != IntRegType && argCopy->getType()->isInteger()
&& "Must be passing copy of FP argument in int register"); && "Must be passing copy of FP argument in int register");
int copyRegNum = regNumForIntArg(/*inCallee*/false, /*isVarArgs*/false, int copyRegNum = regNumForIntArg(/*inCallee*/false, /*isVarArgs*/false,
argNo, intArgNo, fpArgNo-1, argNo, intArgNo, fpArgNo-1,
@ -907,7 +907,7 @@ void UltraSparcRegInfo::colorCallArgs(MachineInstr *CallMI,
const Value *argCopy = argDesc->getArgInfo(i).getArgCopy(); const Value *argCopy = argDesc->getArgInfo(i).getArgCopy();
if (argCopy != NULL) if (argCopy != NULL)
{ {
assert(regType != IntRegType && argCopy->getType()->isIntegral() assert(regType != IntRegType && argCopy->getType()->isInteger()
&& "Must be passing copy of FP argument in int register"); && "Must be passing copy of FP argument in int register");
unsigned copyRegClassID = getRegClassIDOfValue(argCopy); unsigned copyRegClassID = getRegClassIDOfValue(argCopy);

View File

@ -165,7 +165,7 @@ static bool PeepholeOptimizeAddCast(BasicBlock *BB, BasicBlock::iterator &BI,
} }
// Only proceed if we have detected all of our conditions successfully... // Only proceed if we have detected all of our conditions successfully...
if (!CompTy || !SrcPtr || !OffsetVal->getType()->isIntegral()) if (!CompTy || !SrcPtr || !OffsetVal->getType()->isInteger())
return false; return false;
std::vector<Value*> Indices; std::vector<Value*> Indices;

View File

@ -217,10 +217,10 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) {
// Simplify mul instructions with a constant RHS... // Simplify mul instructions with a constant RHS...
if (Constant *Op2 = dyn_cast<Constant>(I.getOperand(1))) { if (Constant *Op2 = dyn_cast<Constant>(I.getOperand(1))) {
if (I.getType()->isIntegral() && cast<ConstantInt>(Op2)->equalsInt(1)) if (I.getType()->isInteger() && cast<ConstantInt>(Op2)->equalsInt(1))
return ReplaceInstUsesWith(I, Op1); // Eliminate 'mul int %X, 1' return ReplaceInstUsesWith(I, Op1); // Eliminate 'mul int %X, 1'
if (I.getType()->isIntegral() && cast<ConstantInt>(Op2)->equalsInt(2)) if (I.getType()->isInteger() && cast<ConstantInt>(Op2)->equalsInt(2))
// Convert 'mul int %X, 2' to 'add int %X, %X' // Convert 'mul int %X, 2' to 'add int %X, %X'
return BinaryOperator::create(Instruction::Add, Op1, Op1, I.getName()); return BinaryOperator::create(Instruction::Add, Op1, Op1, I.getName());
@ -499,13 +499,6 @@ Instruction *InstCombiner::visitShiftInst(Instruction &I) {
} }
// isCIntegral - For the purposes of casting, we allow conversion of sizes and
// stuff as long as the value type acts basically integral like.
//
static bool isCIntegral(const Type *Ty) {
return Ty->isIntegral() || Ty == Type::BoolTy;
}
// isEliminableCastOfCast - Return true if it is valid to eliminate the CI // isEliminableCastOfCast - Return true if it is valid to eliminate the CI
// instruction. // instruction.
// //
@ -524,7 +517,7 @@ static inline bool isEliminableCastOfCast(const CastInst &CI,
// Allow free casting and conversion of sizes as long as the sign doesn't // Allow free casting and conversion of sizes as long as the sign doesn't
// change... // change...
if (isCIntegral(SrcTy) && isCIntegral(MidTy) && isCIntegral(DstTy)) { if (SrcTy->isIntegral() && MidTy->isIntegral() && DstTy->isIntegral()) {
unsigned SrcSize = SrcTy->getPrimitiveSize(); unsigned SrcSize = SrcTy->getPrimitiveSize();
unsigned MidSize = MidTy->getPrimitiveSize(); unsigned MidSize = MidTy->getPrimitiveSize();
unsigned DstSize = DstTy->getPrimitiveSize(); unsigned DstSize = DstTy->getPrimitiveSize();
@ -597,7 +590,7 @@ Instruction *InstCombiner::visitCastInst(CastInst &CI) {
// to convert this into a logical 'and' instruction. // to convert this into a logical 'and' instruction.
// //
if (CSrc->getOperand(0)->getType() == CI.getType() && if (CSrc->getOperand(0)->getType() == CI.getType() &&
CI.getType()->isIntegral() && CSrc->getType()->isIntegral() && CI.getType()->isInteger() && CSrc->getType()->isInteger() &&
CI.getType()->isUnsigned() && CSrc->getType()->isUnsigned() && CI.getType()->isUnsigned() && CSrc->getType()->isUnsigned() &&
CSrc->getType()->getPrimitiveSize() < CI.getType()->getPrimitiveSize()){ CSrc->getType()->getPrimitiveSize() < CI.getType()->getPrimitiveSize()){
assert(CSrc->getType() != Type::ULongTy && assert(CSrc->getType() != Type::ULongTy &&

View File

@ -236,12 +236,11 @@ ConstantExpr::ConstantExpr(Constant *C, const std::vector<Constant*> &IdxList,
// classof implementations // classof implementations
bool ConstantIntegral::classof(const Constant *CPV) { bool ConstantIntegral::classof(const Constant *CPV) {
return (CPV->getType()->isIntegral() || CPV->getType() == Type::BoolTy) && return CPV->getType()->isIntegral() && !isa<ConstantExpr>(CPV);
!isa<ConstantExpr>(CPV);
} }
bool ConstantInt::classof(const Constant *CPV) { bool ConstantInt::classof(const Constant *CPV) {
return CPV->getType()->isIntegral() && !isa<ConstantExpr>(CPV); return CPV->getType()->isInteger() && !isa<ConstantExpr>(CPV);
} }
bool ConstantSInt::classof(const Constant *CPV) { bool ConstantSInt::classof(const Constant *CPV) {
return CPV->getType()->isSigned() && !isa<ConstantExpr>(CPV); return CPV->getType()->isSigned() && !isa<ConstantExpr>(CPV);

View File

@ -151,36 +151,28 @@ const Type *StructType::getTypeAtIndex(const Value *V) const {
// These classes are used to implement specialized behavior for each different // These classes are used to implement specialized behavior for each different
// type. // type.
// //
class SignedIntType : public Type { struct SignedIntType : public Type {
int Size; SignedIntType(const string &Name, PrimitiveID id) : Type(Name, id) {}
public:
SignedIntType(const string &Name, PrimitiveID id, int size) : Type(Name, id) {
Size = size;
}
// isSigned - Return whether a numeric type is signed. // isSigned - Return whether a numeric type is signed.
virtual bool isSigned() const { return 1; } virtual bool isSigned() const { return 1; }
// isIntegral - Equivalent to isSigned() || isUnsigned, but with only a single // isInteger - Equivalent to isSigned() || isUnsigned, but with only a single
// virtual function invocation. // virtual function invocation.
// //
virtual bool isIntegral() const { return 1; } virtual bool isInteger() const { return 1; }
}; };
class UnsignedIntType : public Type { struct UnsignedIntType : public Type {
uint64_t Size; UnsignedIntType(const string &N, PrimitiveID id) : Type(N, id) {}
public:
UnsignedIntType(const string &N, PrimitiveID id, int size) : Type(N, id) {
Size = size;
}
// isUnsigned - Return whether a numeric type is signed. // isUnsigned - Return whether a numeric type is signed.
virtual bool isUnsigned() const { return 1; } virtual bool isUnsigned() const { return 1; }
// isIntegral - Equivalent to isSigned() || isUnsigned, but with only a single // isInteger - Equivalent to isSigned() || isUnsigned, but with only a single
// virtual function invocation. // virtual function invocation.
// //
virtual bool isIntegral() const { return 1; } virtual bool isInteger() const { return 1; }
}; };
static struct TypeType : public Type { static struct TypeType : public Type {
@ -194,14 +186,14 @@ static struct TypeType : public Type {
Type *Type::VoidTy = new Type("void" , VoidTyID), Type *Type::VoidTy = new Type("void" , VoidTyID),
*Type::BoolTy = new Type("bool" , BoolTyID), *Type::BoolTy = new Type("bool" , BoolTyID),
*Type::SByteTy = new SignedIntType("sbyte" , SByteTyID, 1), *Type::SByteTy = new SignedIntType("sbyte" , SByteTyID),
*Type::UByteTy = new UnsignedIntType("ubyte" , UByteTyID, 1), *Type::UByteTy = new UnsignedIntType("ubyte" , UByteTyID),
*Type::ShortTy = new SignedIntType("short" , ShortTyID, 2), *Type::ShortTy = new SignedIntType("short" , ShortTyID),
*Type::UShortTy = new UnsignedIntType("ushort", UShortTyID, 2), *Type::UShortTy = new UnsignedIntType("ushort", UShortTyID),
*Type::IntTy = new SignedIntType("int" , IntTyID, 4), *Type::IntTy = new SignedIntType("int" , IntTyID),
*Type::UIntTy = new UnsignedIntType("uint" , UIntTyID, 4), *Type::UIntTy = new UnsignedIntType("uint" , UIntTyID),
*Type::LongTy = new SignedIntType("long" , LongTyID, 8), *Type::LongTy = new SignedIntType("long" , LongTyID),
*Type::ULongTy = new UnsignedIntType("ulong" , ULongTyID, 8), *Type::ULongTy = new UnsignedIntType("ulong" , ULongTyID),
*Type::FloatTy = new Type("float" , FloatTyID), *Type::FloatTy = new Type("float" , FloatTyID),
*Type::DoubleTy = new Type("double", DoubleTyID), *Type::DoubleTy = new Type("double", DoubleTyID),
*Type::TypeTy = &TheTypeType, *Type::TypeTy = &TheTypeType,