use of org.jikesrvm.compilers.opt.ir.operand.Operand in project JikesRVM by JikesRVM.
the class LICM method simplify.
private boolean simplify(Instruction inst, BasicBlock block) {
// no phi
if (!Phi.conforms(inst))
return false;
// if (Phi.getNumberOfValues (inst) != 2) return false; // want exactly 2 inputs
// VM.sysWriteln ("Simplify " + inst);
Operand resOp = Phi.getResult(inst);
if (!(resOp instanceof HeapOperand)) {
// scalar phi
return false;
}
int xidx = -1;
Instruction x = null;
for (int i = Phi.getNumberOfValues(inst) - 1; i >= 0; --i) {
Instruction in = definingInstruction(Phi.getValue(inst, i));
if (getOrigBlock(in) != getOrigBlock(inst) && dominator.dominates(getOrigBlock(in), getOrigBlock(inst))) {
if (xidx != -1)
return false;
xidx = i;
x = in;
} else if (!dominator.dominates(getOrigBlock(inst), getOrigBlock(in))) {
return false;
}
}
if (x == null)
return false;
replaceUses(inst, (HeapOperand<?>) Phi.getValue(inst, xidx), Phi.getPred(inst, xidx), true);
// Cast to generic HeapOperand
@SuppressWarnings("unchecked") HeapOperand<Object> hop = (HeapOperand) resOp;
if (hop.value.isExceptionHeapType())
return false;
/* check that inside the loop, the heap variable is only used/defed
by simple, non-volatile loads or only by stores
if so, replace uses of inst (a memory phi) with its dominating input
*/
int type = checkLoop(inst, hop, xidx, block);
if (type == CL_LOADS_ONLY || type == CL_STORES_ONLY || type == CL_NONE) {
replaceUses(inst, (HeapOperand<?>) Phi.getValue(inst, xidx), Phi.getPred(inst, xidx), false);
}
return false;
}
use of org.jikesrvm.compilers.opt.ir.operand.Operand in project JikesRVM by JikesRVM.
the class LeaveSSA method unSSAGuardsDetermineReg.
/**
* Determine target register for guard phi operands
*
* @param ir the governing IR, currently in SSA form
*/
private void unSSAGuardsDetermineReg(IR ir) {
Instruction inst = guardPhis;
while (inst != null) {
Register r = Phi.getResult(inst).asRegister().getRegister();
int values = Phi.getNumberOfValues(inst);
for (int i = 0; i < values; ++i) {
Operand op = Phi.getValue(inst, i);
if (op instanceof RegisterOperand) {
guardUnion(op.asRegister().getRegister(), r);
} else {
if (VM.VerifyAssertions) {
VM._assert(op instanceof TrueGuardOperand || op instanceof UnreachableOperand);
}
}
}
inst = inst2guardPhi.get(inst);
}
}
use of org.jikesrvm.compilers.opt.ir.operand.Operand in project JikesRVM by JikesRVM.
the class LeaveSSA method performRename.
// substitute variables renamed in control parents
private void performRename(BasicBlock bb, DominatorTree dom, VariableStacks s) {
if (DEBUG)
VM.sysWriteln("performRename: " + bb);
Enumeration<Instruction> e = bb.forwardRealInstrEnumerator();
while (e.hasMoreElements()) {
Instruction i = e.nextElement();
Enumeration<Operand> ee = i.getUses();
while (ee.hasMoreElements()) {
Operand o = ee.nextElement();
if (o instanceof RegisterOperand) {
Register r1 = ((RegisterOperand) o).getRegister();
if (r1.isValidation())
continue;
Operand r2 = s.peek(r1);
if (r2 != null) {
if (DEBUG) {
VM.sysWriteln("replace operand in " + i + "(" + r2 + " for " + o);
}
i.replaceOperand(o, r2.copy());
}
}
}
}
// record renamings required in children
e = bb.forwardRealInstrEnumerator();
while (e.hasMoreElements()) {
Instruction i = e.nextElement();
if (globalRenameTable.contains(i)) {
Register original = Move.getVal(i).asRegister().getRegister();
RegisterOperand rename = Move.getResult(i);
if (DEBUG)
VM.sysWriteln("record rename " + rename + " for " + original);
s.push(original, rename);
}
}
// insert copies in control children
Enumeration<TreeNode> children = dom.getChildren(bb);
while (children.hasMoreElements()) {
BasicBlock c = ((DominatorTreeNode) children.nextElement()).getBlock();
performRename(c, dom, s);
}
// pop renamings from this block off stack
e = bb.forwardRealInstrEnumerator();
while (e.hasMoreElements()) {
Instruction i = e.nextElement();
if (globalRenameTable.contains(i)) {
Register original = Move.getVal(i).asRegister().getRegister();
s.pop(original);
}
}
}
use of org.jikesrvm.compilers.opt.ir.operand.Operand in project JikesRVM by JikesRVM.
the class GenerationContextTest method buildLockObjectForStaticMethod.
private Operand buildLockObjectForStaticMethod(NormalMethod nm) {
Class<?> klass = nm.getDeclaringClass().getClassForType();
Offset offs = Offset.fromIntSignExtend(Statics.findOrCreateObjectLiteral(klass));
Operand expectedLockObject = new ClassConstantOperand(klass, offs);
return expectedLockObject;
}
use of org.jikesrvm.compilers.opt.ir.operand.Operand in project JikesRVM by JikesRVM.
the class GenerationContextTest method assertThatRethrowBlockIsCorrect.
private void assertThatRethrowBlockIsCorrect(InlineSequence inlineSequence, Operand lockObject, ExceptionHandlerBasicBlock rethrow) {
Enumeration<TypeOperand> exceptionTypes = rethrow.getExceptionTypes();
TypeOperand firstHandledException = exceptionTypes.nextElement();
assertThat(exceptionTypes.hasMoreElements(), is(false));
assertTrue(firstHandledException.similar(new TypeOperand(RVMType.JavaLangThrowableType)));
Enumeration<Instruction> rethrowInstructions = rethrow.forwardRealInstrEnumerator();
Instruction firstInstructionInRethrow = rethrowInstructions.nextElement();
assertThat(firstInstructionInRethrow.operator(), is(GET_CAUGHT_EXCEPTION));
assertThat(firstInstructionInRethrow.getBytecodeIndex(), is(SYNTH_CATCH_BCI));
assertTrue(firstInstructionInRethrow.position().equals(inlineSequence));
RegisterOperand catchExceptionObject = Nullary.getResult(firstInstructionInRethrow);
assertThat(catchExceptionObject.getType(), is(TypeReference.JavaLangThrowable));
Instruction secondInstructionInRethrow = rethrowInstructions.nextElement();
assertThatNoMoreInstructionsExist(rethrowInstructions);
assertThat(secondInstructionInRethrow.operator(), is(CALL));
MethodOperand methodOp = Call.getMethod(secondInstructionInRethrow);
assertTrue(methodOp.getTarget().equals(Entrypoints.unlockAndThrowMethod));
assertTrue(methodOp.isNonReturningCall());
Operand callAddress = Call.getAddress(secondInstructionInRethrow);
Address actualAddress = callAddress.asAddressConstant().value;
Address expectedAddress = Entrypoints.unlockAndThrowMethod.getOffset().toWord().toAddress();
assertTrue(actualAddress.EQ(expectedAddress));
Operand lockObjectFromRethrow = Call.getParam(secondInstructionInRethrow, 0);
assertTrue(lockObjectFromRethrow.similar(lockObject));
RegisterOperand catchOperand = Call.getParam(secondInstructionInRethrow, 1).asRegister();
assertTrue(catchOperand.sameRegisterPropertiesAs(catchExceptionObject));
assertTrue(rethrow.mayThrowUncaughtException());
assertTrue(rethrow.canThrowExceptions());
}
Aggregations