use of org.jikesrvm.compilers.opt.ir.Instruction 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.Instruction 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.Instruction 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.Instruction in project JikesRVM by JikesRVM.
the class ReorderingPhase method exileInfrequentBlocks.
// ///////////////////////
// Code for trivial algorithm
// ///////////////////////
/**
* Select a new basic block ordering via a simple heuristic
* that moves all infrequent basic blocks to the end.
* @param ir the IR object to reorder
*/
private void exileInfrequentBlocks(IR ir) {
// (1) Look to see if there are infrequent blocks
// Also count how many blocks there are.
int numBlocks = 0;
boolean foundSome = false;
for (Enumeration<BasicBlock> e = ir.getBasicBlocks(); e.hasMoreElements(); ) {
BasicBlock bb = e.nextElement();
numBlocks++;
foundSome |= bb.getInfrequent();
}
// Nothing to do
if (!foundSome)
return;
// Reorder the blocks to exile the infrequent blocks.
// Relative order within the set of frequent and infrequent is unchanged.
BasicBlock[] newOrdering = new BasicBlock[numBlocks];
int idx = 0;
// First append frequent blocks to newOrdering
for (BasicBlock bb = ir.cfg.firstInCodeOrder(); bb != null; bb = bb.nextBasicBlockInCodeOrder()) {
if (!bb.getInfrequent()) {
newOrdering[idx++] = bb;
}
}
// Next append infrequent blocks to newOrdering
for (BasicBlock bb = ir.cfg.firstInCodeOrder(); bb != null; bb = bb.nextBasicBlockInCodeOrder()) {
if (bb.getInfrequent()) {
newOrdering[idx++] = bb;
}
}
// don't lose blocks!
if (VM.VerifyAssertions)
VM._assert(idx == numBlocks);
if (VM.VerifyAssertions)
VM._assert(ir.cfg.entry() == newOrdering[0]);
// Add/remove unconditional goto's as needed.
for (int i = 0; i < newOrdering.length; i++) {
Instruction lastInstr = newOrdering[i].lastRealInstruction();
// Append a GOTO if needed to maintain old fallthrough semantics.
BasicBlock fallthroughBlock = newOrdering[i].getFallThroughBlock();
if (fallthroughBlock != null) {
if (i == newOrdering.length - 1 || fallthroughBlock != newOrdering[i + 1]) {
// Add unconditional goto to preserve old fallthrough semantics
newOrdering[i].appendInstruction(fallthroughBlock.makeGOTO());
}
}
// (Only possible if newOrdering[i] is not the last basic block.)
if (i < newOrdering.length - 1 && lastInstr != null && lastInstr.operator() == GOTO) {
BranchOperand op = Goto.getTarget(lastInstr);
if (op.target.getBasicBlock() == newOrdering[i + 1]) {
// unconditional goto is redundant in new ordering
lastInstr.remove();
}
}
}
// Re-insert all basic blocks according to new ordering
ir.cfg.clearCodeOrder();
for (BasicBlock bb : newOrdering) {
ir.cfg.addLastInCodeOrder(bb);
}
}
use of org.jikesrvm.compilers.opt.ir.Instruction in project JikesRVM by JikesRVM.
the class StaticSplitting method splitCandidate.
/**
* Splits a node where we can safely not
* replicate the on-branch in the cloned node.
* @param ci description of the split candidate.
* @param ir the governing IR
*/
private void splitCandidate(CandInfo ci, IR ir) {
BasicBlock cand = ci.candBB;
BasicBlock prev = ci.prevBB;
BasicBlock succ = ci.succBB;
BasicBlock clone = cand.copyWithoutLinks(ir);
// Redirect clone to always stay on cold path.
Instruction s = clone.lastRealInstruction();
while (s.isBranch()) {
s = s.remove();
}
clone.appendInstruction(Goto.create(GOTO, succ.makeJumpTarget()));
// inject clone in code order;
// force prev to go to clone instead of cand.
prev.redirectOuts(cand, clone, ir);
clone.recomputeNormalOut(ir);
ir.cfg.addLastInCodeOrder(clone);
clone.setInfrequent();
}
Aggregations