Search in sources :

Example 26 with Instruction

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();
}
Also used : Instruction(org.jikesrvm.compilers.opt.ir.Instruction) Simple(org.jikesrvm.compilers.opt.Simple)

Example 27 with Instruction

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

Example 28 with Instruction

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

Example 29 with Instruction

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;
}
Also used : BasicBlock(org.jikesrvm.compilers.opt.ir.BasicBlock) Instruction(org.jikesrvm.compilers.opt.ir.Instruction) BranchOperand(org.jikesrvm.compilers.opt.ir.operand.BranchOperand)

Example 30 with Instruction

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

Aggregations

Instruction (org.jikesrvm.compilers.opt.ir.Instruction)356 RegisterOperand (org.jikesrvm.compilers.opt.ir.operand.RegisterOperand)204 Operand (org.jikesrvm.compilers.opt.ir.operand.Operand)144 BasicBlock (org.jikesrvm.compilers.opt.ir.BasicBlock)117 Register (org.jikesrvm.compilers.opt.ir.Register)106 IntConstantOperand (org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand)72 BranchProfileOperand (org.jikesrvm.compilers.opt.ir.operand.BranchProfileOperand)61 ConditionOperand (org.jikesrvm.compilers.opt.ir.operand.ConditionOperand)61 MethodOperand (org.jikesrvm.compilers.opt.ir.operand.MethodOperand)54 LocationOperand (org.jikesrvm.compilers.opt.ir.operand.LocationOperand)53 Test (org.junit.Test)49 TrueGuardOperand (org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand)46 TypeReference (org.jikesrvm.classloader.TypeReference)38 BranchOperand (org.jikesrvm.compilers.opt.ir.operand.BranchOperand)38 NullConstantOperand (org.jikesrvm.compilers.opt.ir.operand.NullConstantOperand)35 BasicBlockOperand (org.jikesrvm.compilers.opt.ir.operand.BasicBlockOperand)33 HeapOperand (org.jikesrvm.compilers.opt.ir.operand.HeapOperand)33 TrapCodeOperand (org.jikesrvm.compilers.opt.ir.operand.TrapCodeOperand)31 AddressConstantOperand (org.jikesrvm.compilers.opt.ir.operand.AddressConstantOperand)28 TypeOperand (org.jikesrvm.compilers.opt.ir.operand.TypeOperand)27