use of org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand in project JikesRVM by JikesRVM.
the class BC2IR method do_iinc.
// // INCREMENT A LOCAL VARIABLE.
/**
* Simulates the incrementing of a given int local variable.
*
* @param index local variable number
* @param amount amount to increment by
* @return the generated instruction, never {@code null}
*/
private Instruction do_iinc(int index, int amount) {
Operand r = getLocal(index);
if (VM.VerifyAssertions)
opt_assert(r.isIntLike());
if (LOCALS_ON_STACK) {
replaceLocalsOnStack(index, TypeReference.Int);
}
RegisterOperand op0 = gc.makeLocal(index, TypeReference.Int);
if (r instanceof IntConstantOperand) {
// do constant folding.
int res = amount + ((IntConstantOperand) r).value;
IntConstantOperand val = new IntConstantOperand(res);
if (CP_IN_LOCALS) {
setLocal(index, val);
} else {
setLocal(index, op0);
}
Instruction s = Move.create(INT_MOVE, op0, val);
setSourcePosition(s);
return s;
}
setLocal(index, op0);
return Binary.create(INT_ADD, op0, r, new IntConstantOperand(amount));
}
use of org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand in project JikesRVM by JikesRVM.
the class BC2IR method _intIfHelper.
// helper function for if?? bytecodes
private Instruction _intIfHelper(ConditionOperand cond) {
int offset = bcodes.getBranchOffset();
Operand op0 = popInt();
if (offset == 3) {
// remove frivolous IFs
return null;
}
if (CF_INTIF && op0 instanceof IntConstantOperand) {
int c = cond.evaluate(((IntConstantOperand) op0).value, 0);
if (c == ConditionOperand.TRUE) {
if (DBG_CF) {
db(cond + ": changed branch to goto because predicate (" + op0 + ") is constant true");
}
return _gotoHelper(offset);
} else if (c == ConditionOperand.FALSE) {
if (DBG_CF) {
db(cond + ": eliminated branch because predicate (" + op0 + ") is constant false");
}
return null;
}
}
fallThrough = true;
if (!(op0 instanceof RegisterOperand)) {
if (DBG_CF)
db("generated int_ifcmp of " + op0 + " with 0");
RegisterOperand guard = gc.getTemps().makeTempValidation();
return IfCmp.create(INT_IFCMP, guard, op0, new IntConstantOperand(0), cond, generateTarget(offset), gc.getConditionalBranchProfileOperand(instrIndex - bciAdjustment, offset < 0));
}
RegisterOperand val = (RegisterOperand) op0;
BranchOperand branch = null;
if (lastInstr != null) {
switch(lastInstr.getOpcode()) {
case INSTANCEOF_opcode:
case INSTANCEOF_UNRESOLVED_opcode:
{
if (DBG_TYPE)
db("last instruction was instanceof");
RegisterOperand res = InstanceOf.getResult(lastInstr);
if (DBG_TYPE)
db("result was in " + res + ", we are checking " + val);
if (val.getRegister() != res.getRegister()) {
// not our value
break;
}
Operand ref = InstanceOf.getRef(lastInstr);
// should've been constant folded anyway
if (!(ref instanceof RegisterOperand)) {
break;
}
RegisterOperand guard = null;
// Propagate types and non-nullness along the CFG edge where we
// know that refReg is an instanceof type2
RegisterOperand refReg = (RegisterOperand) ref;
TypeReference type2 = InstanceOf.getType(lastInstr).getTypeRef();
if (cond.isNOT_EQUAL()) {
// IS an instance of on the branch-taken edge
boolean generated = false;
if (refReg.getRegister().isLocal()) {
int locNum = gc.getLocalNumberFor(refReg.getRegister(), refReg.getType());
if (locNum != -1) {
Operand loc = getLocal(locNum);
if (loc instanceof RegisterOperand) {
if (DBG_TYPE) {
db(val + " is from instanceof test, propagating new type of " + refReg + " (" + type2 + ") to basic block at " + offset);
}
RegisterOperand locr = (RegisterOperand) loc;
RegisterOperand tlocr = locr.copyU2U();
guard = gc.makeNullCheckGuard(tlocr.getRegister());
setGuardForRegOp(tlocr, guard.copyD2U());
tlocr.clearDeclaredType();
tlocr.clearPreciseType();
tlocr.setType(type2);
setLocal(locNum, tlocr);
branch = generateTarget(offset);
generated = true;
setLocal(locNum, locr);
}
}
}
if (!generated) {
branch = generateTarget(offset);
}
} else if (cond.isEQUAL()) {
// IS an instance of on the fallthrough edge.
branch = generateTarget(offset);
if (refReg.getRegister().isLocal()) {
int locNum = gc.getLocalNumberFor(refReg.getRegister(), refReg.getType());
if (locNum != -1) {
Operand loc = getLocal(locNum);
if (loc instanceof RegisterOperand) {
if (DBG_TYPE) {
db(val + " is from instanceof test, propagating new type of " + refReg + " (" + type2 + ") along fallthrough edge");
}
RegisterOperand locr = (RegisterOperand) loc;
guard = gc.makeNullCheckGuard(locr.getRegister());
setGuardForRegOp(locr, guard.copyD2U());
locr.clearDeclaredType();
locr.clearPreciseType();
locr.setType(type2);
setLocal(locNum, loc);
}
}
}
}
if (guard == null) {
guard = gc.getTemps().makeTempValidation();
}
return IfCmp.create(INT_IFCMP, guard, val, new IntConstantOperand(0), cond, branch, gc.getConditionalBranchProfileOperand(instrIndex - bciAdjustment, offset < 0));
}
case INSTANCEOF_NOTNULL_opcode:
{
if (DBG_TYPE)
db("last instruction was instanceof");
RegisterOperand res = InstanceOf.getResult(lastInstr);
if (DBG_TYPE) {
db("result was in " + res + ", we are checking " + val);
}
if (val.getRegister() != res.getRegister()) {
// not our value
break;
}
Operand ref = InstanceOf.getRef(lastInstr);
// should've been constant folded anyway
if (!(ref instanceof RegisterOperand)) {
break;
}
// Propagate types along the CFG edge where we know that
// refReg is an instanceof type2
RegisterOperand refReg = (RegisterOperand) ref;
TypeReference type2 = InstanceOf.getType(lastInstr).getTypeRef();
if (cond.isNOT_EQUAL()) {
// IS an instance of on the branch-taken edge
boolean generated = false;
if (refReg.getRegister().isLocal()) {
int locNum = gc.getLocalNumberFor(refReg.getRegister(), refReg.getType());
if (locNum != -1) {
Operand loc = getLocal(locNum);
if (loc instanceof RegisterOperand) {
if (DBG_TYPE) {
db(val + " is from instanceof test, propagating new type of " + refReg + " (" + type2 + ") to basic block at " + offset);
}
RegisterOperand locr = (RegisterOperand) loc;
RegisterOperand tlocr = locr.copyU2U();
tlocr.clearDeclaredType();
tlocr.clearPreciseType();
tlocr.setType(type2);
setLocal(locNum, tlocr);
branch = generateTarget(offset);
generated = true;
setLocal(locNum, locr);
}
}
}
if (!generated) {
branch = generateTarget(offset);
}
} else if (cond.isEQUAL()) {
// IS an instance of on the fallthrough edge.
branch = generateTarget(offset);
if (refReg.getRegister().isLocal()) {
int locNum = gc.getLocalNumberFor(refReg.getRegister(), refReg.getType());
if (locNum != -1) {
Operand loc = getLocal(locNum);
if (loc instanceof RegisterOperand) {
if (DBG_TYPE) {
db(val + " is from instanceof test, propagating new type of " + refReg + " (" + type2 + ") along fallthrough edge");
}
RegisterOperand locr = (RegisterOperand) loc;
locr.setType(type2);
locr.clearDeclaredType();
setLocal(locNum, loc);
}
}
}
}
RegisterOperand guard = gc.getTemps().makeTempValidation();
return IfCmp.create(INT_IFCMP, guard, val, new IntConstantOperand(0), cond, branch, gc.getConditionalBranchProfileOperand(instrIndex - bciAdjustment, offset < 0));
}
case DOUBLE_CMPG_opcode:
case DOUBLE_CMPL_opcode:
case FLOAT_CMPG_opcode:
case FLOAT_CMPL_opcode:
case LONG_CMP_opcode:
{
RegisterOperand res = Binary.getResult(lastInstr);
if (val.getRegister() != res.getRegister()) {
// not our value
break;
}
Operator operator = null;
switch(lastInstr.getOpcode()) {
case DOUBLE_CMPG_opcode:
cond.translateCMPG();
operator = DOUBLE_IFCMP;
break;
case DOUBLE_CMPL_opcode:
cond.translateCMPL();
operator = DOUBLE_IFCMP;
break;
case FLOAT_CMPG_opcode:
cond.translateCMPG();
operator = FLOAT_IFCMP;
break;
case FLOAT_CMPL_opcode:
cond.translateCMPL();
operator = FLOAT_IFCMP;
break;
case LONG_CMP_opcode:
operator = LONG_IFCMP;
break;
default:
OptimizingCompilerException.UNREACHABLE();
break;
}
Operand val1 = Binary.getClearVal1(lastInstr);
Operand val2 = Binary.getClearVal2(lastInstr);
if (!(val1 instanceof RegisterOperand)) {
// swap operands
Operand temp = val1;
val1 = val2;
val2 = temp;
cond = cond.flipOperands();
}
lastInstr.remove();
lastInstr = null;
branch = generateTarget(offset);
RegisterOperand guard = gc.getTemps().makeTempValidation();
return IfCmp.create(operator, guard, val1, val2, cond, branch, gc.getConditionalBranchProfileOperand(instrIndex - bciAdjustment, offset < 0));
}
default:
// Fall through and Insert INT_IFCMP
break;
}
}
branch = generateTarget(offset);
RegisterOperand guard = gc.getTemps().makeTempValidation();
return IfCmp.create(INT_IFCMP, guard, val, new IntConstantOperand(0), cond, branch, gc.getConditionalBranchProfileOperand(instrIndex - bciAdjustment, offset < 0));
}
use of org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand in project JikesRVM by JikesRVM.
the class BC2IR method _intIfCmpHelper.
// helper function for if_icmp?? bytecodes
private Instruction _intIfCmpHelper(ConditionOperand cond) {
int offset = bcodes.getBranchOffset();
Operand op1 = popInt();
Operand op0 = popInt();
if (offset == 3) {
// remove frivolous INF_IFCMPs
return null;
}
if (!(op0 instanceof RegisterOperand)) {
// swap operands
Operand temp = op0;
op0 = op1;
op1 = temp;
cond = cond.flipOperands();
}
if (CF_INTIFCMP && (op0 instanceof IntConstantOperand) && (op1 instanceof IntConstantOperand)) {
int c = cond.evaluate(((IntConstantOperand) op0).value, ((IntConstantOperand) op1).value);
if (c == ConditionOperand.TRUE) {
if (DBG_CF) {
db(cond + ": changed branch to goto because predicate (" + op0 + ", " + op1 + ") is constant true");
}
return _gotoHelper(offset);
} else if (c == ConditionOperand.FALSE) {
if (DBG_CF) {
db(cond + ": eliminated branch because predicate (" + op0 + "," + op1 + ") is constant false");
}
return null;
}
}
fallThrough = true;
RegisterOperand guard = gc.getTemps().makeTempValidation();
return IfCmp.create(INT_IFCMP, guard, op0, op1, cond, generateTarget(offset), gc.getConditionalBranchProfileOperand(instrIndex - bciAdjustment, offset < 0));
}
use of org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand in project JikesRVM by JikesRVM.
the class BURS_Helpers method EMIT_BOOLCMP_BRANCH.
protected final void EMIT_BOOLCMP_BRANCH(BranchOperand target, BranchProfileOperand bp) {
if (VM.VerifyAssertions)
VM._assert(cc != null);
RegisterOperand cr = regpool.makeTempCondition();
Operator op;
if (VM.BuildFor64Addr && isAddress) {
if (val2 instanceof IntConstantOperand) {
op = cc.isUNSIGNED() ? PPC64_CMPLI : PPC64_CMPI;
} else {
op = cc.isUNSIGNED() ? PPC64_CMPL : PPC64_CMP;
}
} else if (val2 instanceof IntConstantOperand) {
op = cc.isUNSIGNED() ? PPC_CMPLI : PPC_CMPI;
} else {
op = cc.isUNSIGNED() ? PPC_CMPL : PPC_CMP;
}
EMIT(MIR_Binary.create(op, cr, R(val1), val2));
EMIT(MIR_CondBranch.create(PPC_BCOND, cr.copyD2U(), new PowerPCConditionOperand(cc), target, bp));
if (VM.VerifyAssertions) {
cc = null;
val1 = null;
val2 = null;
}
}
use of org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand in project JikesRVM by JikesRVM.
the class NormalizeConstants method asImmediateOrRegInt.
static Operand asImmediateOrRegInt(Operand addr, Instruction s, IR ir, boolean signed) {
if (addr instanceof IntConstantOperand) {
if (!canBeImmediate(((IntConstantOperand) addr).value, signed)) {
RegisterOperand rop = ir.regpool.makeTempInt();
s.insertBefore(Move.create(REF_MOVE, rop, addr));
return rop.copyD2U();
}
} else if (addr instanceof ConstantOperand) {
// must not happen
if (VM.VerifyAssertions)
VM._assert(VM.NOT_REACHED);
}
// Operand was OK as is.
return addr;
}
Aggregations