Search in sources :

Example 31 with BranchProfileOperand

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

the class DynamicTypeCheckExpansion method checkcast.

/**
 * Expand a checkcast instruction into the LIR sequence that implements the
 * dynamic type check, raising a ClassCastException when the type check
 * fails. Ref may contain a null ptr at runtime.
 *
 * @param s a CHECKCAST or CHECKCAST_UNRESOLVED instruction to expand
 * @param ir the enclosing IR
 * @return the last Instruction in the generated LIR sequence.
 */
static Instruction checkcast(Instruction s, IR ir) {
    Operand ref = TypeCheck.getClearRef(s);
    TypeReference LHStype = TypeCheck.getType(s).getTypeRef();
    RegisterOperand guard = ir.regpool.makeTempValidation();
    Instruction nullCond = IfCmp.create(REF_IFCMP, guard, ref.copy(), new NullConstantOperand(), ConditionOperand.EQUAL(), null, // KLUDGE...we haven't created the block yet!
    new BranchProfileOperand());
    s.insertBefore(nullCond);
    BasicBlock myBlock = s.getBasicBlock();
    BasicBlock failBlock = myBlock.createSubBlock(s.getBytecodeIndex(), ir, .0001f);
    BasicBlock instanceOfBlock = myBlock.splitNodeAt(nullCond, ir);
    BasicBlock succBlock = instanceOfBlock.splitNodeAt(s, ir);
    succBlock.firstInstruction().insertAfter(Move.create(REF_MOVE, TypeCheck.getClearResult(s), ref.copy()));
    // fixup KLUDGE
    IfCmp.setTarget(nullCond, succBlock.makeJumpTarget());
    myBlock.insertOut(instanceOfBlock);
    myBlock.insertOut(succBlock);
    instanceOfBlock.insertOut(failBlock);
    instanceOfBlock.insertOut(succBlock);
    ir.cfg.linkInCodeOrder(myBlock, instanceOfBlock);
    ir.cfg.linkInCodeOrder(instanceOfBlock, succBlock);
    ir.cfg.addLastInCodeOrder(failBlock);
    Instruction raiseError = Trap.create(TRAP, null, TrapCodeOperand.CheckCast());
    raiseError.copyPosition(s);
    failBlock.appendInstruction(raiseError);
    Operand RHStib = getTIB(s, ir, ref, guard.copyD2U());
    return generateBranchingTypeCheck(s, ir, ref.copy(), LHStype, RHStib, succBlock, failBlock, guard.copyRO(), BranchProfileOperand.never());
}
Also used : NullConstantOperand(org.jikesrvm.compilers.opt.ir.operand.NullConstantOperand) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) MethodOperand(org.jikesrvm.compilers.opt.ir.operand.MethodOperand) 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) NullConstantOperand(org.jikesrvm.compilers.opt.ir.operand.NullConstantOperand) BranchProfileOperand(org.jikesrvm.compilers.opt.ir.operand.BranchProfileOperand) TrapCodeOperand(org.jikesrvm.compilers.opt.ir.operand.TrapCodeOperand) LocationOperand(org.jikesrvm.compilers.opt.ir.operand.LocationOperand) IntConstantOperand(org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand) BasicBlock(org.jikesrvm.compilers.opt.ir.BasicBlock) BranchProfileOperand(org.jikesrvm.compilers.opt.ir.operand.BranchProfileOperand) TypeReference(org.jikesrvm.classloader.TypeReference) Instruction(org.jikesrvm.compilers.opt.ir.Instruction)

Example 32 with BranchProfileOperand

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

the class BranchOptimizations method booleanCompareHelper.

/**
 * Generate a boolean operation opcode
 *
 * <pre>
 * 1) IF br != 0 THEN x=1 ELSE x=0       replaced by INT_MOVE x=br
 *    IF br == 0 THEN x=0 ELSE x=1
 * 2) IF br == 0 THEN x=1 ELSE x=0       replaced by BOOLEAN_NOT x=br
 *    IF br != 0 THEN x=0 ELSE x=1
 * 3) IF v1 ~ v2 THEN x=1 ELSE x=0       replaced by BOOLEAN_CMP x=v1,v2,~
 * </pre>
 *
 * @param cb conditional branch instruction
 * @param res the operand for result
 * @param val1 value being compared
 * @param val2 value being compared with
 * @param cond comparison condition
 */
private void booleanCompareHelper(Instruction cb, RegisterOperand res, Operand val1, Operand val2, ConditionOperand cond) {
    if ((val1 instanceof RegisterOperand) && ((RegisterOperand) val1).getType().isBooleanType() && (val2 instanceof IntConstantOperand)) {
        int value = ((IntConstantOperand) val2).value;
        if (VM.VerifyAssertions && (value != 0) && (value != 1)) {
            throw new OptimizingCompilerException("Invalid boolean value");
        }
        int c = cond.evaluate(value, 0);
        if (c == ConditionOperand.TRUE) {
            Unary.mutate(cb, BOOLEAN_NOT, res, val1);
            return;
        } else if (c == ConditionOperand.FALSE) {
            Move.mutate(cb, INT_MOVE, res, val1);
            return;
        }
    }
    BooleanCmp.mutate(cb, (cb.operator() == REF_IFCMP) ? BOOLEAN_CMP_ADDR : BOOLEAN_CMP_INT, res, val1, val2, cond, new BranchProfileOperand());
}
Also used : RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) IntConstantOperand(org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand) BranchProfileOperand(org.jikesrvm.compilers.opt.ir.operand.BranchProfileOperand) OptimizingCompilerException(org.jikesrvm.compilers.opt.OptimizingCompilerException)

Example 33 with BranchProfileOperand

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

the class InstrumentationSamplingFramework method createCheck.

/**
 * Append a check to a basic block, and make it jump to the right places.
 *
 * @param checkBB The block to append the CBS check to.
 * @param noInstBB The basic block to jump to if the CBS check fails
 * @param instBB The basicBlock to jump to if the CBS check succeeds
 * @param fallthroughToInstBB Should checkBB fallthrough to instBB
 *                            (otherwise it must fallthrough to noInstBB)
 * @param ir the IR that contains the blocks
 */
private void createCheck(BasicBlock checkBB, BasicBlock noInstBB, BasicBlock instBB, boolean fallthroughToInstBB, IR ir) {
    appendLoad(checkBB, ir);
    // Depending on where you fallthrough, set the condition correctly
    ConditionOperand cond = null;
    BranchOperand target = null;
    BranchProfileOperand profileOperand = null;
    if (fallthroughToInstBB) {
        // The instrumented basic block is the fallthrough of checkBB,
        // so make the branch jump to the non-instrumented block.
        cond = ConditionOperand.GREATER();
        target = noInstBB.makeJumpTarget();
        // Taken frequently
        profileOperand = new BranchProfileOperand(1.0f);
    } else {
        // The non-instrumented basic block is the fallthrough of checkBB,
        // so make the branch jump to the instrumented block.
        cond = ConditionOperand.LESS_EQUAL();
        target = instBB.makeJumpTarget();
        // Taken infrequently
        profileOperand = new BranchProfileOperand(0.0f);
    }
    RegisterOperand guard = ir.regpool.makeTempValidation();
    checkBB.appendInstruction(IfCmp.create(INT_IFCMP, guard, cbsReg.copyRO(), new IntConstantOperand(0), cond, target, profileOperand));
    checkBB.recomputeNormalOut(ir);
    // Insert the decrement and store in the block that is the
    // successor of the check
    prependStore(noInstBB, ir);
    prependDecrement(noInstBB, ir);
    // Insert a counter reset in the duplicated block.
    prependCounterReset(instBB, ir);
}
Also used : RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) IntConstantOperand(org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand) BranchProfileOperand(org.jikesrvm.compilers.opt.ir.operand.BranchProfileOperand) ConditionOperand(org.jikesrvm.compilers.opt.ir.operand.ConditionOperand) BranchOperand(org.jikesrvm.compilers.opt.ir.operand.BranchOperand)

Aggregations

BranchProfileOperand (org.jikesrvm.compilers.opt.ir.operand.BranchProfileOperand)33 RegisterOperand (org.jikesrvm.compilers.opt.ir.operand.RegisterOperand)29 BasicBlock (org.jikesrvm.compilers.opt.ir.BasicBlock)24 IntConstantOperand (org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand)18 ConditionOperand (org.jikesrvm.compilers.opt.ir.operand.ConditionOperand)17 Operand (org.jikesrvm.compilers.opt.ir.operand.Operand)15 LocationOperand (org.jikesrvm.compilers.opt.ir.operand.LocationOperand)12 Instruction (org.jikesrvm.compilers.opt.ir.Instruction)11 Register (org.jikesrvm.compilers.opt.ir.Register)10 BranchOperand (org.jikesrvm.compilers.opt.ir.operand.BranchOperand)9 MethodOperand (org.jikesrvm.compilers.opt.ir.operand.MethodOperand)9 TrapCodeOperand (org.jikesrvm.compilers.opt.ir.operand.TrapCodeOperand)8 TrueGuardOperand (org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand)8 NullConstantOperand (org.jikesrvm.compilers.opt.ir.operand.NullConstantOperand)7 PowerPCConditionOperand (org.jikesrvm.compilers.opt.ir.operand.ppc.PowerPCConditionOperand)5 RVMClass (org.jikesrvm.classloader.RVMClass)4 RVMMethod (org.jikesrvm.classloader.RVMMethod)4 RVMType (org.jikesrvm.classloader.RVMType)4 TypeReference (org.jikesrvm.classloader.TypeReference)4 AddressConstantOperand (org.jikesrvm.compilers.opt.ir.operand.AddressConstantOperand)4