use of org.jikesrvm.compilers.opt.ir.Instruction in project JikesRVM by JikesRVM.
the class LoopUnrolling method perform.
@Override
public void perform(IR ir) {
unrollFactor = (1 << ir.options.CONTROL_UNROLL_LOG);
if (ir.hasReachableExceptionHandlers())
return;
DefUse.computeDU(ir);
new Simple(1, true, true, true, false).perform(ir);
new BranchOptimizations(-1, true, true).perform(ir, true);
// new CFGTransformations().perform(ir);
// Note: the following unfactors the CFG
new DominatorsPhase(true).perform(ir);
DefUse.computeDU(ir);
visitInts = new HashMap<Instruction, Integer>();
Enumeration<Instruction> instEnum = ir.forwardInstrEnumerator();
while (instEnum.hasMoreElements()) {
Instruction inst = instEnum.nextElement();
visitInts.put(inst, Integer.valueOf(0));
}
unrollLoops(ir);
CFGTransformations.splitCriticalEdges(ir);
ir.cfg.compactNodeNumbering();
}
use of org.jikesrvm.compilers.opt.ir.Instruction in project JikesRVM by JikesRVM.
the class LoopUnrolling method printDefs.
private static boolean printDefs(Operand op, BitVector nloop, int depth) {
if (depth <= 0)
return false;
if (op instanceof ConstantOperand) {
VM.sysWriteln(">> " + op);
return true;
}
if (op instanceof RegisterOperand) {
boolean invariant = true;
Register reg = ((RegisterOperand) op).getRegister();
Enumeration<RegisterOperand> defs = DefUse.defs(reg);
while (defs.hasMoreElements()) {
Instruction inst = defs.nextElement().instruction;
VM.sysWriteln(">> " + inst.getBasicBlock() + ": " + inst);
if (CFGTransformations.inLoop(inst.getBasicBlock(), nloop)) {
if (Move.conforms(inst)) {
invariant &= printDefs(Move.getVal(inst), nloop, depth - 1);
} else if (inst.getOpcode() == ARRAYLENGTH_opcode) {
invariant &= printDefs(GuardedUnary.getVal(inst), nloop, depth);
} else {
invariant = false;
}
}
if (!invariant)
break;
}
return invariant;
}
return false;
}
use of org.jikesrvm.compilers.opt.ir.Instruction in project JikesRVM by JikesRVM.
the class LoopUnrolling method loopInvariant.
private static boolean loopInvariant(Operand op, BitVector nloop, int depth) {
if (depth <= 0) {
return false;
} else if (op instanceof ConstantOperand) {
return true;
} else if (op instanceof RegisterOperand) {
Register reg = ((RegisterOperand) op).getRegister();
Enumeration<RegisterOperand> defs = DefUse.defs(reg);
// if no definitions of this register (very strange) give up
if (!defs.hasMoreElements())
return false;
Instruction inst = defs.nextElement().instruction;
// fail to give the correct invariant
return !defs.hasMoreElements() && !CFGTransformations.inLoop(inst.getBasicBlock(), nloop);
} else {
return false;
}
}
use of org.jikesrvm.compilers.opt.ir.Instruction in project JikesRVM by JikesRVM.
the class MIRBranchOptimizations method processGoto.
/**
* Perform optimizations for an unconditonal branch.
*
* <p> Patterns:
* <pre>
* 1) GOTO A replaced by GOTO B
* A: GOTO B
*
* 2) GOTO next instruction eliminated
* 3) GOTO A replaced by GOTO B
* A: LABEL
* BBEND
* B:
* </pre>
*
* <p> Precondition: MIR_Branch.conforms(g)
*
* @param ir governing IR
* @param g the instruction to optimize
* @param bb the basic block holding g
* @return {@code true} if made a transformation
*/
private boolean processGoto(IR ir, Instruction g, BasicBlock bb) {
BasicBlock targetBlock = g.getBranchTarget();
Instruction targetLabel = targetBlock.firstInstruction();
// get the first real instruction at the g target
// NOTE: this instruction is not necessarily in targetBlock,
// iff targetBlock has no real instructions
Instruction targetInst = firstRealInstructionFollowing(targetLabel);
if (targetInst == null || targetInst == g) {
return false;
}
Instruction nextLabel = firstLabelFollowing(g);
if (targetLabel == nextLabel) {
// found a GOTO to the next instruction. just remove it.
g.remove();
return true;
}
if (isMIR_Branch(targetInst)) {
// unconditional branch to unconditional branch.
// replace g with goto to targetInst's target
Instruction target2 = firstRealInstructionFollowing(targetInst.getBranchTarget().firstInstruction());
if (target2 == targetInst) {
// This happens in jByteMark.EmFloatPnt.denormalize() due to a while(true) {}
return false;
}
BranchOperand top = (BranchOperand) (MIR_Branch_getTarget(targetInst).copy());
MIR_Branch_setTarget(g, top);
// fix the CFG
bb.recomputeNormalOut(ir);
return true;
}
if (targetBlock.isEmpty()) {
// GOTO an empty block. Change target to the next block.
BasicBlock nextBlock = targetBlock.getFallThroughBlock();
MIR_Branch_setTarget(g, nextBlock.makeJumpTarget());
// fix the CFG
bb.recomputeNormalOut(ir);
return true;
}
return false;
}
use of org.jikesrvm.compilers.opt.ir.Instruction in project JikesRVM by JikesRVM.
the class BURS_Helpers method LONG_LOAD_addx.
protected final void LONG_LOAD_addx(Instruction s, RegisterOperand def, RegisterOperand left, RegisterOperand right, LocationOperand loc, Operand guard) {
if (VM.VerifyAssertions)
VM._assert(VM.BuildFor32Addr);
Register defHigh = def.getRegister();
Register defLow = regpool.getSecondReg(defHigh);
Instruction inst = MIR_Load.create(PPC_LWZX, I(defHigh), left, right, loc, guard);
inst.copyPosition(s);
EMIT(inst);
RegisterOperand kk = regpool.makeTempInt();
EMIT(MIR_Binary.create(PPC_ADDI, kk, right.copyU2U(), IC(4)));
if (loc != null) {
loc = (LocationOperand) loc.copy();
}
if (guard != null) {
guard = guard.copy();
}
inst = MIR_Load.create(PPC_LWZX, I(defLow), left.copyU2U(), kk.copyD2U(), loc, guard);
inst.copyPosition(s);
EMIT(inst);
}
Aggregations