use of org.jikesrvm.compilers.opt.ir.operand.RegisterOperand in project JikesRVM by JikesRVM.
the class ShortArrayReplacer method transform.
@Override
public void transform() {
// first set up temporary scalars for the array elements
// initialize them before the def.
RegisterOperand[] scalars = new RegisterOperand[size];
TypeReference elementType = vmArray.getElementType().getTypeRef();
RegisterOperand def = reg.defList;
Instruction defI = def.instruction;
Operand defaultValue = IRTools.getDefaultOperand(elementType);
for (int i = 0; i < size; i++) {
scalars[i] = IRTools.moveIntoRegister(elementType, IRTools.getMoveOp(elementType), ir.regpool, defI, defaultValue.copy());
}
transform2(this.reg, defI, scalars);
}
use of org.jikesrvm.compilers.opt.ir.operand.RegisterOperand in project JikesRVM by JikesRVM.
the class ShortArrayReplacer method scalarReplace.
/**
* Replace a given use of an array with its scalar equivalent.
*
* @param use the use to replace
* @param scalars an array of scalar register operands to replace
* the array with
* @param visited TODO currently useless. Is this parameter
* necessary or should it be removed?
*/
private void scalarReplace(RegisterOperand use, RegisterOperand[] scalars, Set<Register> visited) {
Instruction inst = use.instruction;
RVMType type = vmArray.getElementType();
switch(inst.getOpcode()) {
case INT_ALOAD_opcode:
case LONG_ALOAD_opcode:
case FLOAT_ALOAD_opcode:
case DOUBLE_ALOAD_opcode:
case BYTE_ALOAD_opcode:
case UBYTE_ALOAD_opcode:
case USHORT_ALOAD_opcode:
case SHORT_ALOAD_opcode:
case REF_ALOAD_opcode:
{
// of a trap
if (ALoad.getIndex(inst).isIntConstant()) {
Operator moveOp = IRTools.getMoveOp(type.getTypeRef());
int index = ALoad.getIndex(inst).asIntConstant().value;
if (index >= 0 && index < size) {
Instruction i2 = Move.create(moveOp, ALoad.getClearResult(inst), scalars[index].copyRO());
DefUse.replaceInstructionAndUpdateDU(inst, i2);
} else {
DefUse.removeInstructionAndUpdateDU(inst);
}
} else {
if (VM.BuildForIA32) {
if (size == 0) {
DefUse.removeInstructionAndUpdateDU(inst);
} else if (size == 1) {
int index = 0;
Operator moveOp = IRTools.getMoveOp(type.getTypeRef());
Instruction i2 = Move.create(moveOp, ALoad.getClearResult(inst), scalars[index].copyRO());
DefUse.replaceInstructionAndUpdateDU(inst, i2);
} else {
Operator moveOp = IRTools.getCondMoveOp(type.getTypeRef());
Instruction i2 = CondMove.create(moveOp, ALoad.getClearResult(inst), ALoad.getClearIndex(inst), IC(0), ConditionOperand.EQUAL(), scalars[0].copyRO(), scalars[1].copyRO());
DefUse.replaceInstructionAndUpdateDU(inst, i2);
}
} else {
if (size == 1) {
int index = 0;
Operator moveOp = IRTools.getMoveOp(type.getTypeRef());
Instruction i2 = Move.create(moveOp, ALoad.getClearResult(inst), scalars[index].copyRO());
DefUse.replaceInstructionAndUpdateDU(inst, i2);
} else {
DefUse.removeInstructionAndUpdateDU(inst);
}
}
}
}
break;
case INT_ASTORE_opcode:
case LONG_ASTORE_opcode:
case FLOAT_ASTORE_opcode:
case DOUBLE_ASTORE_opcode:
case BYTE_ASTORE_opcode:
case SHORT_ASTORE_opcode:
case REF_ASTORE_opcode:
{
// of a trap
if (AStore.getIndex(inst).isIntConstant()) {
int index = AStore.getIndex(inst).asIntConstant().value;
if (index >= 0 && index < size) {
Operator moveOp = IRTools.getMoveOp(type.getTypeRef());
Instruction i2 = Move.create(moveOp, scalars[index].copyRO(), AStore.getClearValue(inst));
DefUse.replaceInstructionAndUpdateDU(inst, i2);
} else {
DefUse.removeInstructionAndUpdateDU(inst);
}
} else {
if (VM.BuildForIA32) {
if (size == 0) {
DefUse.removeInstructionAndUpdateDU(inst);
} else if (size == 1) {
int index = 0;
Operator moveOp = IRTools.getMoveOp(type.getTypeRef());
Instruction i2 = Move.create(moveOp, scalars[index].copyRO(), AStore.getClearValue(inst));
DefUse.replaceInstructionAndUpdateDU(inst, i2);
} else {
Operator moveOp = IRTools.getCondMoveOp(type.getTypeRef());
Operand value = AStore.getClearValue(inst);
Instruction i2 = CondMove.create(moveOp, scalars[0].copyRO(), AStore.getIndex(inst), IC(0), ConditionOperand.EQUAL(), value, scalars[0].copyRO());
DefUse.replaceInstructionAndUpdateDU(inst, i2);
Instruction i3 = CondMove.create(moveOp, scalars[1].copyRO(), AStore.getIndex(inst), IC(0), ConditionOperand.NOT_EQUAL(), value, scalars[1].copyRO());
i2.insertAfter(i3);
DefUse.updateDUForNewInstruction(i3);
}
} else {
if (size == 1) {
int index = 0;
Operator moveOp = IRTools.getMoveOp(type.getTypeRef());
Instruction i2 = Move.create(moveOp, scalars[index].copyRO(), AStore.getClearValue(inst));
DefUse.replaceInstructionAndUpdateDU(inst, i2);
} else {
DefUse.removeInstructionAndUpdateDU(inst);
}
}
}
}
break;
case NULL_CHECK_opcode:
{
// Null check on result of new array must succeed
Instruction i2 = Move.create(GUARD_MOVE, NullCheck.getClearGuardResult(inst), new TrueGuardOperand());
DefUse.replaceInstructionAndUpdateDU(inst, i2);
}
break;
case BOUNDS_CHECK_opcode:
{
// Remove or create trap as appropriate
Instruction i2 = TrapIf.create(TRAP_IF, BoundsCheck.getClearGuardResult(inst), IC(size), BoundsCheck.getClearIndex(inst), ConditionOperand.LOWER_EQUAL(), TrapCodeOperand.ArrayBounds());
DefUse.replaceInstructionAndUpdateDU(inst, i2);
}
break;
case CHECKCAST_opcode:
case CHECKCAST_NOTNULL_opcode:
case CHECKCAST_UNRESOLVED_opcode:
{
// We cannot handle removing the checkcast if the result of the
// checkcast test is unknown
TypeReference lhsType = TypeCheck.getType(inst).getTypeRef();
if (ClassLoaderProxy.includesType(lhsType, vmArray.getTypeRef()) == YES) {
if (visited == null) {
visited = new HashSet<Register>();
}
Register copy = TypeCheck.getResult(inst).getRegister();
if (!visited.contains(copy)) {
visited.add(copy);
transform2(copy, inst, scalars);
// NB will remove inst
} else {
DefUse.removeInstructionAndUpdateDU(inst);
}
} else {
Instruction i2 = Trap.create(TRAP, null, TrapCodeOperand.CheckCast());
DefUse.replaceInstructionAndUpdateDU(inst, i2);
}
}
break;
case INSTANCEOF_opcode:
case INSTANCEOF_NOTNULL_opcode:
case INSTANCEOF_UNRESOLVED_opcode:
{
// We cannot handle removing the instanceof if the result of the
// instanceof test is unknown
TypeReference lhsType = InstanceOf.getType(inst).getTypeRef();
Instruction i2;
if (ClassLoaderProxy.includesType(lhsType, vmArray.getTypeRef()) == YES) {
i2 = Move.create(INT_MOVE, InstanceOf.getClearResult(inst), IC(1));
} else {
i2 = Move.create(INT_MOVE, InstanceOf.getClearResult(inst), IC(0));
}
DefUse.replaceInstructionAndUpdateDU(inst, i2);
}
break;
case GET_OBJ_TIB_opcode:
{
Instruction i2 = Move.create(REF_MOVE, GuardedUnary.getClearResult(inst), new TIBConstantOperand(vmArray));
DefUse.replaceInstructionAndUpdateDU(inst, i2);
}
break;
case REF_MOVE_opcode:
{
if (visited == null) {
visited = new HashSet<Register>();
}
Register copy = Move.getResult(inst).getRegister();
if (!visited.contains(copy)) {
visited.add(copy);
transform2(copy, inst, scalars);
// NB will remove inst
} else {
DefUse.removeInstructionAndUpdateDU(inst);
}
}
break;
default:
throw new OptimizingCompilerException("Unexpected instruction: " + inst);
}
}
use of org.jikesrvm.compilers.opt.ir.operand.RegisterOperand in project JikesRVM by JikesRVM.
the class SimpleEscape method simpleEscapeAnalysis.
/**
* Performs the escape analysis for a method.
*
* <p> Side effect: updates method summary database to hold
* escape analysis result for parameters
*
* @param ir IR for the target method
* @return an object holding the result of the analysis
*/
public FI_EscapeSummary simpleEscapeAnalysis(IR ir) {
final boolean DEBUG = false;
if (DEBUG) {
VM.sysWriteln("ENTER Simple Escape Analysis " + ir.method);
}
if (DEBUG) {
ir.printInstructions();
}
// create a method summary object for this method
RVMMethod m = ir.method;
MethodSummary summ = SummaryDatabase.findOrCreateMethodSummary(m);
summ.setInProgress(true);
FI_EscapeSummary result = new FI_EscapeSummary();
// set up register lists, SSA flags
DefUse.computeDU(ir);
DefUse.recomputeSSA(ir);
// pass through registers, and mark escape information
for (Register reg = ir.regpool.getFirstSymbolicRegister(); reg != null; reg = reg.getNext()) {
// skip the following types of registers:
if (reg.isFloatingPoint()) {
continue;
}
if (reg.isInteger()) {
continue;
}
if (reg.isLong()) {
continue;
}
if (reg.isCondition()) {
continue;
}
if (reg.isValidation()) {
continue;
}
if (reg.isPhysical()) {
continue;
}
if (!reg.isSSA()) {
continue;
}
AnalysisResult escapes = checkAllAppearances(reg, ir);
if (escapes.threadLocal) {
result.setThreadLocal(reg, true);
}
if (escapes.methodLocal) {
result.setMethodLocal(reg, true);
}
}
// update the method summary database to note whether
// parameters may escape
int numParam = 0;
for (Enumeration<Operand> e = ir.getParameters(); e.hasMoreElements(); numParam++) {
Register p = ((RegisterOperand) e.nextElement()).getRegister();
if (result.isThreadLocal(p)) {
summ.setParameterMayEscapeThread(numParam, false);
} else {
summ.setParameterMayEscapeThread(numParam, true);
}
}
// update the method summary to note whether the return value
// may escape
boolean foundEscapingReturn = false;
for (Iterator<Operand> itr = iterateReturnValues(ir); itr.hasNext(); ) {
Operand op = itr.next();
if (op == null) {
continue;
}
if (op.isRegister()) {
Register r = op.asRegister().getRegister();
if (!result.isThreadLocal(r)) {
foundEscapingReturn = true;
}
}
}
if (!foundEscapingReturn) {
summ.setResultMayEscapeThread(false);
}
// record that we're done with analysis
summ.setInProgress(false);
if (DEBUG) {
VM.sysWriteln("LEAVE Simple Escape Analysis " + ir.method);
}
return result;
}
use of org.jikesrvm.compilers.opt.ir.operand.RegisterOperand in project JikesRVM by JikesRVM.
the class SimpleEscape method checkEscapesThread.
/**
* Checks a single use, to see if this use may cause the object
* referenced to escape from this thread.
*
* @param use the use to check
* @param ir the governing IR
* @param visited visited registers
* @return {@code true} if it may escape, {@code false} otherwise
*/
private static boolean checkEscapesThread(RegisterOperand use, IR ir, Set<Register> visited) {
Instruction inst = use.instruction;
switch(inst.getOpcode()) {
case INT_ASTORE_opcode:
case LONG_ASTORE_opcode:
case FLOAT_ASTORE_opcode:
case DOUBLE_ASTORE_opcode:
case BYTE_ASTORE_opcode:
case SHORT_ASTORE_opcode:
case REF_ASTORE_opcode:
// as long as we don't store this operand elsewhere, all
// is OK
Operand value = AStore.getValue(inst);
return value == use;
case GETFIELD_opcode:
case GETSTATIC_opcode:
case INT_ALOAD_opcode:
case LONG_ALOAD_opcode:
case FLOAT_ALOAD_opcode:
case DOUBLE_ALOAD_opcode:
case BYTE_ALOAD_opcode:
case UBYTE_ALOAD_opcode:
case BYTE_LOAD_opcode:
case UBYTE_LOAD_opcode:
case SHORT_ALOAD_opcode:
case USHORT_ALOAD_opcode:
case SHORT_LOAD_opcode:
case USHORT_LOAD_opcode:
case REF_ALOAD_opcode:
case INT_LOAD_opcode:
case LONG_LOAD_opcode:
case FLOAT_LOAD_opcode:
case DOUBLE_LOAD_opcode:
case REF_LOAD_opcode:
// all is OK, unless we load this register from memory
Operand result = ResultCarrier.getResult(inst);
return result == use;
case PUTFIELD_opcode:
// as long as we don't store this operand elsewhere, all
// is OK. TODO: add more smarts.
value = PutField.getValue(inst);
return value == use;
case PUTSTATIC_opcode:
// as long as we don't store this operand elsewhere, all
// is OK. TODO: add more smarts.
value = PutStatic.getValue(inst);
return value == use;
case BYTE_STORE_opcode:
case SHORT_STORE_opcode:
case REF_STORE_opcode:
case INT_STORE_opcode:
case LONG_STORE_opcode:
case FLOAT_STORE_opcode:
case DOUBLE_STORE_opcode:
// as long as we don't store this operand elsewhere, all
// is OK. TODO: add more smarts.
value = Store.getValue(inst);
return value == use;
// escape
case BOUNDS_CHECK_opcode:
case MONITORENTER_opcode:
case MONITOREXIT_opcode:
case NULL_CHECK_opcode:
case ARRAYLENGTH_opcode:
case REF_IFCMP_opcode:
case INT_IFCMP_opcode:
case IG_PATCH_POINT_opcode:
case IG_CLASS_TEST_opcode:
case IG_METHOD_TEST_opcode:
case BOOLEAN_CMP_INT_opcode:
case BOOLEAN_CMP_ADDR_opcode:
case OBJARRAY_STORE_CHECK_opcode:
case OBJARRAY_STORE_CHECK_NOTNULL_opcode:
case GET_OBJ_TIB_opcode:
case GET_TYPE_FROM_TIB_opcode:
case NEW_opcode:
case NEWARRAY_opcode:
case NEWOBJMULTIARRAY_opcode:
case NEW_UNRESOLVED_opcode:
case NEWARRAY_UNRESOLVED_opcode:
case INSTANCEOF_opcode:
case INSTANCEOF_NOTNULL_opcode:
case INSTANCEOF_UNRESOLVED_opcode:
case MUST_IMPLEMENT_INTERFACE_opcode:
case GET_CAUGHT_EXCEPTION_opcode:
case IR_PROLOGUE_opcode:
return false;
case RETURN_opcode:
// by caller)
return !ir.isParameter(use);
case CALL_opcode:
MethodOperand mop = Call.getMethod(inst);
if (mop == null) {
return true;
}
if (!mop.hasPreciseTarget()) {
// if we're not sure of the dynamic target, give up
return true;
}
// pure methods don't let object escape
if (mop.getTarget().isPure()) {
return false;
}
// Assume non-annotated native methods let object escape
if (mop.getTarget().isNative()) {
return true;
}
// try to get a method summary for the called method
MethodSummary summ = getMethodSummaryIfAvailable(mop.getTarget(), ir.options);
if (summ == null) {
// couldn't get one. assume the object escapes
return true;
}
// if use is result of the call...
if (use == Call.getResult(inst)) {
return summ.resultMayEscapeThread();
}
// use is a parameter to the call. Find out which one.
int p = getParameterIndex(use, inst);
return summ.parameterMayEscapeThread(p);
case CHECKCAST_opcode:
case CHECKCAST_NOTNULL_opcode:
case CHECKCAST_UNRESOLVED_opcode:
case REF_MOVE_opcode:
{
Register copy = ResultCarrier.getResult(inst).getRegister();
if (!copy.isSSA()) {
return true;
} else {
if (visited == null) {
visited = new HashSet<Register>();
}
visited.add(use.getRegister());
if (visited.contains(copy)) {
return false;
} else {
return checkIfUseEscapesThread(copy, ir, visited);
}
}
}
case ATHROW_opcode:
case PREPARE_INT_opcode:
case PREPARE_ADDR_opcode:
case PREPARE_LONG_opcode:
case ATTEMPT_LONG_opcode:
case ATTEMPT_INT_opcode:
case ATTEMPT_ADDR_opcode:
case INT_MOVE_opcode:
case INT_ADD_opcode:
case REF_ADD_opcode:
case INT_MUL_opcode:
case INT_DIV_opcode:
case INT_REM_opcode:
case INT_NEG_opcode:
case INT_ZERO_CHECK_opcode:
case INT_OR_opcode:
case INT_AND_opcode:
case INT_XOR_opcode:
case REF_OR_opcode:
case REF_AND_opcode:
case REF_XOR_opcode:
case INT_SUB_opcode:
case REF_SUB_opcode:
case INT_SHL_opcode:
case INT_SHR_opcode:
case INT_USHR_opcode:
case SYSCALL_opcode:
case REF_SHL_opcode:
case REF_SHR_opcode:
case REF_USHR_opcode:
case SET_CAUGHT_EXCEPTION_opcode:
case PHI_opcode:
case INT_2LONG_opcode:
case REF_COND_MOVE_opcode:
case INT_COND_MOVE_opcode:
case INT_2ADDRSigExt_opcode:
case INT_2ADDRZerExt_opcode:
case ADDR_2INT_opcode:
case ADDR_2LONG_opcode:
case LONG_OR_opcode:
case LONG_AND_opcode:
case LONG_XOR_opcode:
case LONG_SUB_opcode:
case LONG_SHL_opcode:
case LONG_ADD_opcode:
case LONG_SHR_opcode:
case LONG_USHR_opcode:
case LONG_NEG_opcode:
case LONG_MOVE_opcode:
case LONG_2ADDR_opcode:
// TODO: add more smarts
case YIELDPOINT_OSR_opcode:
// we do not know exactly, so be conservative
return true;
default:
if (VM.BuildForPowerPC) {
switch(inst.getOpcode()) {
case DCBST_opcode:
case DCBT_opcode:
case DCBTST_opcode:
case DCBZ_opcode:
case DCBZL_opcode:
case ICBI_opcode:
return false;
}
} else {
switch(inst.getOpcode()) {
case PREFETCH_opcode:
return false;
}
}
throw new OptimizingCompilerException("SimpleEscapge: Unexpected " + inst);
}
}
use of org.jikesrvm.compilers.opt.ir.operand.RegisterOperand in project JikesRVM by JikesRVM.
the class DepGraph method computeBackwardDependencesDef.
/**
* Compute backward dependences from a given def to a given node.
* @param op source operand
* @param destNode destination node
* @param lastExceptionNode node representing the last PEI
*/
private void computeBackwardDependencesDef(Operand op, DepGraphNode destNode, DepGraphNode lastExceptionNode) {
if (!(op instanceof RegisterOperand))
return;
RegisterOperand regOp = (RegisterOperand) op;
// being defined may be live in some reachable catch block
if (lastExceptionNode != null && regOp.getRegister().spansBasicBlock() && currentBlock.hasExceptionHandlers()) {
if (!ir.getHandlerLivenessComputed() || handlerLiveSet.contains(regOp.getRegister())) {
destNode.insertOutEdge(lastExceptionNode, EXCEPTION_R);
}
}
setDepGraphNodeForRegister(destNode, regOp.getRegister());
}
Aggregations