use of org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand in project JikesRVM by JikesRVM.
the class BranchSimplifier method processLookupSwitch.
static boolean processLookupSwitch(IR ir, BasicBlock bb, Instruction s) {
Operand val = LookupSwitch.getValue(s);
int numMatches = LookupSwitch.getNumberOfMatches(s);
if (numMatches == 0) {
// Can only goto default
Goto.mutate(s, GOTO, LookupSwitch.getDefault(s));
} else if (val.isConstant()) {
// lookup value is constant
int value = ((IntConstantOperand) val).value;
BranchOperand target = LookupSwitch.getDefault(s);
for (int i = 0; i < numMatches; i++) {
if (value == LookupSwitch.getMatch(s, i).value) {
target = LookupSwitch.getTarget(s, i);
break;
}
}
Goto.mutate(s, GOTO, target);
} else if (numMatches == 1) {
// only 1 match, simplify to ifcmp
BranchOperand defaultTarget = LookupSwitch.getClearDefault(s);
IfCmp.mutate(s, INT_IFCMP, ir.regpool.makeTempValidation(), val, LookupSwitch.getMatch(s, 0), ConditionOperand.EQUAL(), LookupSwitch.getTarget(s, 0), LookupSwitch.getBranchProfile(s, 0));
s.insertAfter(Goto.create(GOTO, defaultTarget));
} else {
// no optimisation, just continue
return false;
}
return true;
}
use of org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand in project JikesRVM by JikesRVM.
the class BranchSimplifier method processTableSwitch.
static boolean processTableSwitch(IR ir, BasicBlock bb, Instruction s) {
Operand val = TableSwitch.getValue(s);
int low = TableSwitch.getLow(s).value;
int high = TableSwitch.getHigh(s).value;
if (val.isConstant()) {
int value = ((IntConstantOperand) val).value;
BranchOperand target = TableSwitch.getDefault(s);
if (value >= low && value <= high) {
target = TableSwitch.getTarget(s, value - low);
}
Goto.mutate(s, GOTO, target);
} else if (low == high) {
// only 1 match, simplify to ifcmp
BranchOperand defaultTarget = TableSwitch.getClearDefault(s);
IfCmp.mutate(s, INT_IFCMP, ir.regpool.makeTempValidation(), val, new IntConstantOperand(low), ConditionOperand.EQUAL(), TableSwitch.getTarget(s, 0), TableSwitch.getBranchProfile(s, 0));
s.insertAfter(Goto.create(GOTO, defaultTarget));
} else {
// no optimisation, just continue
return false;
}
return true;
}
use of org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand in project JikesRVM by JikesRVM.
the class BranchSimplifier method processIfCmp.
static boolean processIfCmp(IR ir, BasicBlock bb, Instruction s) {
RegisterOperand guard = IfCmp.getGuardResult(s);
Operand val1 = IfCmp.getVal1(s);
Operand val2 = IfCmp.getVal2(s);
{
int cond = IfCmp.getCond(s).evaluate(val1, val2);
if (cond != ConditionOperand.UNKNOWN) {
// constant fold
if (cond == ConditionOperand.TRUE) {
// branch taken
insertTrueGuard(s, guard);
Goto.mutate(s, GOTO, IfCmp.getTarget(s));
removeBranchesAfterGotos(bb);
} else {
// branch not taken
insertTrueGuard(s, guard);
s.remove();
}
return true;
}
}
if (val1.isConstant() && !val2.isConstant()) {
// Canonicalize by making second argument the constant
IfCmp.setVal1(s, val2);
IfCmp.setVal2(s, val1);
IfCmp.setCond(s, IfCmp.getCond(s).flipOperands());
}
if (val2.isIntConstant()) {
// Tricks to get compare against zero.
int value = ((IntConstantOperand) val2).value;
ConditionOperand cond = IfCmp.getCond(s);
if (value == 1) {
if (cond.isLESS()) {
IfCmp.setCond(s, ConditionOperand.LESS_EQUAL());
IfCmp.setVal2(s, new IntConstantOperand(0));
} else if (cond.isGREATER_EQUAL()) {
IfCmp.setCond(s, ConditionOperand.GREATER());
IfCmp.setVal2(s, new IntConstantOperand(0));
}
} else if (value == -1) {
if (cond.isGREATER()) {
IfCmp.setCond(s, ConditionOperand.GREATER_EQUAL());
IfCmp.setVal2(s, new IntConstantOperand(0));
} else if (cond.isLESS_EQUAL()) {
IfCmp.setCond(s, ConditionOperand.LESS());
IfCmp.setVal2(s, new IntConstantOperand(0));
}
}
}
return false;
}
use of org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand 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