1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-20 19:42:54 +02:00

Implement the subset of the GetConstantValueAsSignedInt function that is needed, locally.

llvm-svn: 524
This commit is contained in:
Chris Lattner 2001-09-09 23:01:32 +00:00
parent 9b5fd40742
commit 3bce6b369a

View File

@ -305,31 +305,44 @@ ChooseRegOrImmed(Value* val,
// Check for the common case first: argument is not constant
//
if (val->getValueType() != Value::ConstantVal)
return opType;
ConstPoolVal *CPV = val->castConstant();
if (!CPV) return opType;
if (CPV->getType() == Type::BoolTy) {
ConstPoolBool *CPB = (ConstPoolBool*)CPV;
if (!CPB->getValue() && target.zeroRegNum >= 0) {
getMachineRegNum = target.zeroRegNum;
return MachineOperand::MO_MachineRegister;
}
getImmedValue = 1;
return MachineOperand::MO_SignExtendedImmed;
}
if (!CPV->getType()->isIntegral()) return opType;
// Now get the constant value and check if it fits in the IMMED field.
// Take advantage of the fact that the max unsigned value will rarely
// fit into any IMMED field and ignore that case (i.e., cast smaller
// unsigned constants to signed).
//
bool isValidConstant;
int64_t intValue = GetConstantValueAsSignedInt(val, isValidConstant);
int64_t intValue;
if (CPV->getType()->isSigned()) {
intValue = ((ConstPoolSInt*)CPV)->getValue();
} else {
uint64_t V = ((ConstPoolUInt*)CPV)->getValue();
if (V >= INT64_MAX) return opType;
intValue = (int64_t)V;
}
if (isValidConstant)
{
if (intValue == 0 && target.zeroRegNum >= 0)
{
opType = MachineOperand::MO_MachineRegister;
getMachineRegNum = target.zeroRegNum;
}
else if (canUseImmed &&
target.getInstrInfo().constantFitsInImmedField(opCode,intValue))
{
opType = MachineOperand::MO_SignExtendedImmed;
getImmedValue = intValue;
}
}
if (intValue == 0 && target.zeroRegNum >= 0){
opType = MachineOperand::MO_MachineRegister;
getMachineRegNum = target.zeroRegNum;
} else if (canUseImmed &&
target.getInstrInfo().constantFitsInImmedField(opCode, intValue)) {
opType = MachineOperand::MO_SignExtendedImmed;
getImmedValue = intValue;
}
return opType;
}