aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2001-09-09 23:01:32 +0000
committerChris Lattner <sabre@nondot.org>2001-09-09 23:01:32 +0000
commit990f2a5a1a0b16d0dc07cee486033c0a3864334e (patch)
tree7199a0b651cbb36715beb88fc2500ed0c8c44efc
parent85cdba3bb6ad5a17864f703fec3e11fd9c0d599c (diff)
Implement the subset of the GetConstantValueAsSignedInt function that is needed, locally.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@524 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/CodeGen/MachineInstr.cpp51
1 files changed, 32 insertions, 19 deletions
diff --git a/lib/CodeGen/MachineInstr.cpp b/lib/CodeGen/MachineInstr.cpp
index aa9765d21d..7a5214d260 100644
--- a/lib/CodeGen/MachineInstr.cpp
+++ b/lib/CodeGen/MachineInstr.cpp
@@ -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);
-
- 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;
- }
- }
+ 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 (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;
}