use of org.jikesrvm.compilers.opt.ir.operand.ConstantOperand in project JikesRVM by JikesRVM.
the class LoopUnrolling method printDefs.
private static boolean printDefs(Operand op, BitVector nloop, int depth) {
if (depth <= 0)
return false;
if (op instanceof ConstantOperand) {
VM.sysWriteln(">> " + op);
return true;
}
if (op instanceof RegisterOperand) {
boolean invariant = true;
Register reg = ((RegisterOperand) op).getRegister();
Enumeration<RegisterOperand> defs = DefUse.defs(reg);
while (defs.hasMoreElements()) {
Instruction inst = defs.nextElement().instruction;
VM.sysWriteln(">> " + inst.getBasicBlock() + ": " + inst);
if (CFGTransformations.inLoop(inst.getBasicBlock(), nloop)) {
if (Move.conforms(inst)) {
invariant &= printDefs(Move.getVal(inst), nloop, depth - 1);
} else if (inst.getOpcode() == ARRAYLENGTH_opcode) {
invariant &= printDefs(GuardedUnary.getVal(inst), nloop, depth);
} else {
invariant = false;
}
}
if (!invariant)
break;
}
return invariant;
}
return false;
}
use of org.jikesrvm.compilers.opt.ir.operand.ConstantOperand in project JikesRVM by JikesRVM.
the class LoopUnrolling method loopInvariant.
private static boolean loopInvariant(Operand op, BitVector nloop, int depth) {
if (depth <= 0) {
return false;
} else if (op instanceof ConstantOperand) {
return true;
} else if (op instanceof RegisterOperand) {
Register reg = ((RegisterOperand) op).getRegister();
Enumeration<RegisterOperand> defs = DefUse.defs(reg);
// if no definitions of this register (very strange) give up
if (!defs.hasMoreElements())
return false;
Instruction inst = defs.nextElement().instruction;
// fail to give the correct invariant
return !defs.hasMoreElements() && !CFGTransformations.inLoop(inst.getBasicBlock(), nloop);
} else {
return false;
}
}
use of org.jikesrvm.compilers.opt.ir.operand.ConstantOperand in project JikesRVM by JikesRVM.
the class BURS_Helpers method TRAP_IF_IMM.
/**
* Take the generic LIR trap_if and coerce into the limited
* vocabulary understood by the C trap handler on PPC. See
* TrapConstants.java. Also see ConvertToLowLevelIR.java
* which generates most of these TRAP_IFs.
*
* @param s the instruction to expand
* @param longConstant is the argument a long constant?
*/
protected final void TRAP_IF_IMM(Instruction s, boolean longConstant) {
RegisterOperand gRes = TrapIf.getClearGuardResult(s);
RegisterOperand v1 = (RegisterOperand) TrapIf.getClearVal1(s);
ConditionOperand cond = TrapIf.getClearCond(s);
TrapCodeOperand tc = TrapIf.getClearTCode(s);
switch(tc.getTrapCode()) {
case RuntimeEntrypoints.TRAP_ARRAY_BOUNDS:
{
IntConstantOperand v2 = (IntConstantOperand) TrapIf.getClearVal2(s);
if (cond.isLOWER_EQUAL()) {
EMIT(MIR_Trap.mutate(s, PPC_TWI, gRes, new PowerPCTrapOperand(cond), v1, v2, tc));
} else if (cond.isHIGHER_EQUAL()) {
// have flip the operands and use non-immediate so trap handler can recognize.
RegisterOperand tmp = regpool.makeTempInt();
IntConstant(tmp.getRegister(), v2.value);
EMIT(MIR_Trap.mutate(s, PPC_TW, gRes, new PowerPCTrapOperand(cond.flipOperands()), tmp, v1, tc));
} else {
throw new OptimizingCompilerException("Unexpected case of trap_if" + s);
}
}
break;
case RuntimeEntrypoints.TRAP_DIVIDE_BY_ZERO:
{
ConstantOperand v2 = (ConstantOperand) TrapIf.getClearVal2(s);
if (VM.VerifyAssertions) {
if (longConstant) {
long val = ((LongConstantOperand) v2).value;
boolean caseMatchesExpected = val == 0L && cond.isEQUAL();
if (!caseMatchesExpected) {
String msg = "Unexpected case of trap_if" + s;
VM._assert(VM.NOT_REACHED, msg);
}
} else {
int val = ((IntConstantOperand) v2).value;
boolean caseMatchesExpected = val == 0L && cond.isEQUAL();
if (!caseMatchesExpected) {
String msg = "Unexpected case of trap_if" + s;
VM._assert(VM.NOT_REACHED, msg);
}
}
}
if (longConstant) {
if (VM.BuildFor32Addr) {
// A slightly ugly matter, but we need to deal with combining
// the two pieces of a long register from a LONG_ZERO_CHECK.
// A little awkward, but probably the easiest workaround...
RegisterOperand rr = regpool.makeTempInt();
EMIT(MIR_Binary.create(PPC_OR, rr, v1, I(regpool.getSecondReg(v1.getRegister()))));
v1 = rr.copyD2U();
v2 = IC(0);
EMIT(MIR_Trap.mutate(s, PPC_TWI, gRes, new PowerPCTrapOperand(cond), v1, v2, tc));
} else {
EMIT(MIR_Trap.mutate(s, PPC64_TDI, gRes, new PowerPCTrapOperand(cond), v1, v2, tc));
}
} else {
EMIT(MIR_Trap.mutate(s, PPC_TWI, gRes, new PowerPCTrapOperand(cond), v1, v2, tc));
}
}
break;
default:
throw new OptimizingCompilerException("Unexpected case of trap_if" + s);
}
}
use of org.jikesrvm.compilers.opt.ir.operand.ConstantOperand in project JikesRVM by JikesRVM.
the class NormalizeConstants method asRegOffset.
static Operand asRegOffset(Operand addr, Instruction s, IR ir) {
if (addr instanceof AddressConstantOperand) {
RegisterOperand rop = ir.regpool.makeTempOffset();
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;
}
use of org.jikesrvm.compilers.opt.ir.operand.ConstantOperand in project JikesRVM by JikesRVM.
the class NormalizeConstants method asImmediateOrRegOffset.
static Operand asImmediateOrRegOffset(Operand addr, Instruction s, IR ir, boolean signed) {
if (addr instanceof AddressConstantOperand) {
if (!canBeImmediate(((AddressConstantOperand) addr).value, signed)) {
RegisterOperand rop = ir.regpool.makeTempOffset();
s.insertBefore(Move.create(REF_MOVE, rop, addr));
return rop.copyD2U();
} else {
// can be immediate --> convert to int
return new IntConstantOperand(((AddressConstantOperand) addr).value.toInt());
}
} else if (addr instanceof ConstantOperand) {
// must not happen, because is 64-bit unsafe
if (VM.VerifyAssertions)
VM._assert(VM.NOT_REACHED);
}
// Operand was OK as is.
return addr;
}
Aggregations