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());
}
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());
}
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);
}
Aggregations