Search in sources :

Example 1 with TrueGuardOperand

use of org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand 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);
    }
}
Also used : Operator(org.jikesrvm.compilers.opt.ir.Operator) Register(org.jikesrvm.compilers.opt.ir.Register) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) TrueGuardOperand(org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand) ConditionOperand(org.jikesrvm.compilers.opt.ir.operand.ConditionOperand) Operand(org.jikesrvm.compilers.opt.ir.operand.Operand) TIBConstantOperand(org.jikesrvm.compilers.opt.ir.operand.TIBConstantOperand) TrapCodeOperand(org.jikesrvm.compilers.opt.ir.operand.TrapCodeOperand) RVMType(org.jikesrvm.classloader.RVMType) TIBConstantOperand(org.jikesrvm.compilers.opt.ir.operand.TIBConstantOperand) TypeReference(org.jikesrvm.classloader.TypeReference) OptimizingCompilerException(org.jikesrvm.compilers.opt.OptimizingCompilerException) Instruction(org.jikesrvm.compilers.opt.ir.Instruction) TrueGuardOperand(org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand) HashSet(java.util.HashSet)

Example 2 with TrueGuardOperand

use of org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand in project JikesRVM by JikesRVM.

the class ValueGraph method findOrCreateVertex.

/**
 * Find or create an ValueGraphVertex corresponding to a
 * given constant operand
 *
 * @param op the constant operand
 * @return a value graph vertex corresponding to this variable
 */
private ValueGraphVertex findOrCreateVertex(ConstantOperand op) {
    Object name;
    if (op.isAddressConstant()) {
        name = (VM.BuildFor32Addr) ? op.asAddressConstant().value.toInt() : op.asAddressConstant().value.toLong();
    } else if (op.isIntConstant()) {
        name = op.asIntConstant().value;
    } else if (op.isFloatConstant()) {
        name = op.asFloatConstant().value;
    } else if (op.isLongConstant()) {
        name = op.asLongConstant().value;
    } else if (op.isDoubleConstant()) {
        name = op.asDoubleConstant().value;
    } else if (op instanceof ObjectConstantOperand) {
        name = op.asObjectConstant().value;
    } else if (op instanceof TIBConstantOperand) {
        name = op.asTIBConstant().value;
    } else if (op.isNullConstant()) {
        name = op;
    } else if (op instanceof TrueGuardOperand) {
        name = op;
    } else if (op instanceof UnreachableOperand) {
        name = op;
    } else {
        throw new OptimizingCompilerException("ValueGraph.findOrCreateVertex: unexpected constant operand: " + op);
    }
    ValueGraphVertex v = getVertex(name);
    if (v == null) {
        v = new ValueGraphVertex(op);
        v.setLabel(op, 0);
        graph.addGraphNode(v);
        nameMap.put(name, v);
    }
    return v;
}
Also used : ObjectConstantOperand(org.jikesrvm.compilers.opt.ir.operand.ObjectConstantOperand) TIBConstantOperand(org.jikesrvm.compilers.opt.ir.operand.TIBConstantOperand) UnreachableOperand(org.jikesrvm.compilers.opt.ir.operand.UnreachableOperand) OptimizingCompilerException(org.jikesrvm.compilers.opt.OptimizingCompilerException) TrueGuardOperand(org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand)

Example 3 with TrueGuardOperand

use of org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand 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);
    }
}
Also used : RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) Register(org.jikesrvm.compilers.opt.ir.Register) UnreachableOperand(org.jikesrvm.compilers.opt.ir.operand.UnreachableOperand) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) TrueGuardOperand(org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand) Operand(org.jikesrvm.compilers.opt.ir.operand.Operand) ConstantOperand(org.jikesrvm.compilers.opt.ir.operand.ConstantOperand) UnreachableOperand(org.jikesrvm.compilers.opt.ir.operand.UnreachableOperand) Instruction(org.jikesrvm.compilers.opt.ir.Instruction) TrueGuardOperand(org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand)

Example 4 with TrueGuardOperand

use of org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand in project JikesRVM by JikesRVM.

the class GenerationContextTest method assertThatGuardIsCorrectForMonitorEnter.

private void assertThatGuardIsCorrectForMonitorEnter(Instruction inst) {
    Operand guard = MonitorOp.getGuard(inst);
    assertTrue(guard.similar(new TrueGuardOperand()));
}
Also used : MethodOperand(org.jikesrvm.compilers.opt.ir.operand.MethodOperand) TypeOperand(org.jikesrvm.compilers.opt.ir.operand.TypeOperand) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) TrueGuardOperand(org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand) Operand(org.jikesrvm.compilers.opt.ir.operand.Operand) ObjectConstantOperand(org.jikesrvm.compilers.opt.ir.operand.ObjectConstantOperand) ClassConstantOperand(org.jikesrvm.compilers.opt.ir.operand.ClassConstantOperand) TrueGuardOperand(org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand)

Example 5 with TrueGuardOperand

use of org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand in project JikesRVM by JikesRVM.

the class GenerationContextTest method makeNullCheckGuardAlwaysReturnsCopies.

@Test
public void makeNullCheckGuardAlwaysReturnsCopies() throws Exception {
    NormalMethod nm = TestingTools.getNormalMethod(MethodsForTests.class, "emptyInstanceMethodWithoutAnnotations");
    OptOptions opts = new OptOptions();
    GenerationContext gc = new GenerationContext(nm, null, null, opts, null);
    int localNumber = 0;
    TypeReference localType = nm.getDeclaringClass().getTypeRef();
    RegisterOperand regOp = gc.makeLocal(localNumber, localType);
    Register reg = regOp.getRegister();
    RegisterOperand expectedNullCheckGuard = gc.makeNullCheckGuard(reg);
    RegisterOperand copiedGuard = expectedNullCheckGuard.copy().asRegister();
    expectedNullCheckGuard.setGuard(new TrueGuardOperand());
    RegisterOperand actual = gc.makeNullCheckGuard(reg);
    assertTrue(actual.sameRegisterPropertiesAs(copiedGuard));
    assertNull(actual.getGuard());
}
Also used : RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) Register(org.jikesrvm.compilers.opt.ir.Register) NormalMethod(org.jikesrvm.classloader.NormalMethod) OptOptions(org.jikesrvm.compilers.opt.OptOptions) TypeReference(org.jikesrvm.classloader.TypeReference) TrueGuardOperand(org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand) Test(org.junit.Test)

Aggregations

TrueGuardOperand (org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand)26 RegisterOperand (org.jikesrvm.compilers.opt.ir.operand.RegisterOperand)22 Operand (org.jikesrvm.compilers.opt.ir.operand.Operand)16 Instruction (org.jikesrvm.compilers.opt.ir.Instruction)11 MethodOperand (org.jikesrvm.compilers.opt.ir.operand.MethodOperand)10 BranchProfileOperand (org.jikesrvm.compilers.opt.ir.operand.BranchProfileOperand)9 IntConstantOperand (org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand)9 TypeReference (org.jikesrvm.classloader.TypeReference)8 AddressConstantOperand (org.jikesrvm.compilers.opt.ir.operand.AddressConstantOperand)8 TypeOperand (org.jikesrvm.compilers.opt.ir.operand.TypeOperand)8 ConditionOperand (org.jikesrvm.compilers.opt.ir.operand.ConditionOperand)7 Register (org.jikesrvm.compilers.opt.ir.Register)6 ObjectConstantOperand (org.jikesrvm.compilers.opt.ir.operand.ObjectConstantOperand)6 TrapCodeOperand (org.jikesrvm.compilers.opt.ir.operand.TrapCodeOperand)6 ClassConstantOperand (org.jikesrvm.compilers.opt.ir.operand.ClassConstantOperand)5 ConstantOperand (org.jikesrvm.compilers.opt.ir.operand.ConstantOperand)5 LocationOperand (org.jikesrvm.compilers.opt.ir.operand.LocationOperand)5 LongConstantOperand (org.jikesrvm.compilers.opt.ir.operand.LongConstantOperand)5 NullConstantOperand (org.jikesrvm.compilers.opt.ir.operand.NullConstantOperand)5 UnreachableOperand (org.jikesrvm.compilers.opt.ir.operand.UnreachableOperand)4