Search in sources :

Example 51 with BasicBlock

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

the class LICM method upto.

/**
 * Visits the blocks between the late and the early position along
 * their path in the dominator tree.
 *
 * @param earlyPos the early position
 * @param lateBlock the late position
 * @param inst the instruction to schedule
 * @return the block with the smallest execution costs
 */
BasicBlock upto(Instruction earlyPos, BasicBlock lateBlock, Instruction inst) {
    BasicBlock _origBlock = getOrigBlock(inst);
    BasicBlock actBlock = lateBlock;
    BasicBlock bestBlock = lateBlock;
    BasicBlock earlyBlock = getBlock(earlyPos);
    if (VM.VerifyAssertions) {
        if (!dominator.dominates(earlyBlock.getNumber(), _origBlock.getNumber()) || !dominator.dominates(earlyBlock.getNumber(), lateBlock.getNumber())) {
            SSA.printInstructions(ir);
            VM.sysWriteln("> " + earlyBlock.getNumber() + ", " + _origBlock.getNumber() + ", " + lateBlock.getNumber());
            VM.sysWriteln(inst.toString());
        }
        VM._assert(dominator.dominates(earlyBlock.getNumber(), _origBlock.getNumber()));
        VM._assert(dominator.dominates(earlyBlock.getNumber(), lateBlock.getNumber()));
    }
    for (; ; ) {
        /* is the actual block better (less frequent)
         than the so far best block? */
        if (frequency(actBlock) < frequency(bestBlock)) {
            if (DEBUG) {
                VM.sysWriteln("going from " + frequency(_origBlock) + " to " + frequency(actBlock));
            }
            bestBlock = actBlock;
        }
        /* all candidates checked? */
        if (actBlock == earlyBlock) {
            break;
        }
        /* walk up the dominator tree for next candidate*/
        actBlock = dominator.getParent(actBlock);
    }
    if (bestBlock == _origBlock)
        return null;
    if (DEBUG)
        VM.sysWriteln("best Block: " + bestBlock);
    return bestBlock;
}
Also used : ExceptionHandlerBasicBlock(org.jikesrvm.compilers.opt.ir.ExceptionHandlerBasicBlock) BasicBlock(org.jikesrvm.compilers.opt.ir.BasicBlock)

Example 52 with BasicBlock

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

the class LICM method move.

void move(Instruction inst, BasicBlock to) {
    BasicBlock _origBlock = getOrigBlock(inst);
    Instruction cand = null;
    /* find a position within bestBlock */
    if (dominator.dominates(_origBlock.getNumber(), to.getNumber())) {
        // moved down, so insert in from
        Instruction last = null;
        Enumeration<Instruction> e = to.forwardInstrEnumerator();
        while (e.hasMoreElements()) {
            cand = e.nextElement();
            if (DEBUG)
                VM.sysWriteln(cand.toString());
            ;
            // skip labels, phis, and yieldpoints
            if (!Label.conforms(cand) && !cand.isYieldPoint() && !Phi.conforms(cand)) {
                break;
            }
            last = cand;
        }
        cand = last;
    } else {
        // moved up, so insert at end of block
        Enumeration<Instruction> e = to.reverseInstrEnumerator();
        while (e.hasMoreElements()) {
            cand = e.nextElement();
            if (DEBUG)
                VM.sysWriteln(cand.toString());
            // skip branches and newly placed insts
            if (!BBend.conforms(cand) && !cand.isBranch() && !relocated.contains(cand)) {
                break;
            }
        }
        if (DEBUG)
            VM.sysWriteln("Adding to relocated: " + inst);
        relocated.add(inst);
    }
    if (DEBUG && moved.add(inst.operator())) {
        VM.sysWriteln("m(" + (ir.isLIR() ? "l" : "h") + ") " + inst.operator());
    }
    if (VERBOSE) {
        VM.sysWrite(ir.isLIR() ? "%" : "#");
        VM.sysWriteln(" moving " + inst + " from " + _origBlock + " to " + to + "\n" + "behind  " + cand);
    }
    inst.remove();
    cand.insertAfter(inst);
}
Also used : ExceptionHandlerBasicBlock(org.jikesrvm.compilers.opt.ir.ExceptionHandlerBasicBlock) BasicBlock(org.jikesrvm.compilers.opt.ir.BasicBlock) Instruction(org.jikesrvm.compilers.opt.ir.Instruction)

Example 53 with BasicBlock

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

the class LICM method scheduleLate.

BasicBlock scheduleLate(Instruction inst) {
    if (DEBUG)
        VM.sysWriteln("Schedule Late: " + inst);
    BasicBlock lateBlock = null;
    int _state = getState(inst);
    if (_state == late || _state == done)
        return getBlock(inst);
    setState(inst, late);
    if (ir.options.FREQ_FOCUS_EFFORT) {
        BasicBlock _origBlock = getOrigBlock(inst);
        if (_origBlock.getInfrequent()) {
            return _origBlock;
        }
    }
    // explicitly INCLUDE instructions
    if (!shouldMove(inst, ir)) {
        return getOrigBlock(inst);
    }
    // dependencies via scalar operands
    lateBlock = scheduleScalarUsesLate(inst, lateBlock);
    if (DEBUG)
        VM.sysWriteln("lateBlock1: " + lateBlock + " for " + inst);
    // dependencies via heap operands
    if (ir.isHIR()) {
        lateBlock = scheduleHeapUsesLate(inst, lateBlock);
        if (DEBUG)
            VM.sysWriteln("lateBlock2: " + lateBlock + " for " + inst);
    }
    // if there are no uses, this instruction is dead.
    if (lateBlock == null) {
        if (VERBOSE)
            VM.sysWriteln("deleting " + inst);
        inst.remove();
    } else {
        if (DEBUG && lateBlock != getOrigBlock(inst)) {
            VM.sysWriteln("new lateBlock: " + lateBlock + " for " + getOrigBlock(inst) + ": " + inst);
        }
        BasicBlock to = upto(getEarlyPos(inst), lateBlock, inst);
        if (to == null) {
            lateBlock = getOrigBlock(inst);
        } else {
            if (VM.VerifyAssertions)
                VM._assert(getState(inst) != done);
            lateBlock = to;
            if (getOrigBlock(inst) != to)
                move(inst, to);
        }
    }
    setState(inst, done);
    setBlock(inst, lateBlock);
    return lateBlock;
}
Also used : ExceptionHandlerBasicBlock(org.jikesrvm.compilers.opt.ir.ExceptionHandlerBasicBlock) BasicBlock(org.jikesrvm.compilers.opt.ir.BasicBlock)

Example 54 with BasicBlock

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

the class LeaveSSA method translateFromSSA.

/**
 * Main driver to translate an IR out of SSA form.
 *
 * @param ir the IR in SSA form
 */
public void translateFromSSA(IR ir) {
    // 0. Deal with guards (validation registers)
    unSSAGuards(ir);
    // 1. re-compute dominator tree in case of control flow changes
    LTDominators.perform(ir, true, true);
    DominatorTree dom = new DominatorTree(ir, true);
    // 1.5 Perform Sreedhar's naive translation from TSSA to CSSA
    // if (ir.options.UNROLL_LOG == 0) normalizeSSA(ir);
    // 2. compute liveness
    LiveAnalysis live = new // don't create GC maps
    LiveAnalysis(// don't create GC maps
    false, // skip (final) local propagation step
    true, // don't store information at handlers
    false, // don't skip guards
    false);
    live.perform(ir);
    // 3. initialization
    VariableStacks s = new VariableStacks();
    // 4. convert phi nodes into copies
    BasicBlock b = ((DominatorTreeNode) dom.getRoot()).getBlock();
    insertCopies(b, dom, live);
    // 5. If necessary, recompute dominators to account for new control flow.
    if (splitSomeBlock) {
        LTDominators.perform(ir, true, true);
        dom = new DominatorTree(ir, true);
    }
    // 6. compensate for copies required by simultaneous liveness
    performRename(b, dom, s);
    // 7. phis are now redundant
    removeAllPhis(ir);
}
Also used : DominatorTree(org.jikesrvm.compilers.opt.controlflow.DominatorTree) DominatorTreeNode(org.jikesrvm.compilers.opt.controlflow.DominatorTreeNode) LiveAnalysis(org.jikesrvm.compilers.opt.liveness.LiveAnalysis) BasicBlock(org.jikesrvm.compilers.opt.ir.BasicBlock)

Example 55 with BasicBlock

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

the class LeaveSSA method performRename.

// substitute variables renamed in control parents
private void performRename(BasicBlock bb, DominatorTree dom, VariableStacks s) {
    if (DEBUG)
        VM.sysWriteln("performRename: " + bb);
    Enumeration<Instruction> e = bb.forwardRealInstrEnumerator();
    while (e.hasMoreElements()) {
        Instruction i = e.nextElement();
        Enumeration<Operand> ee = i.getUses();
        while (ee.hasMoreElements()) {
            Operand o = ee.nextElement();
            if (o instanceof RegisterOperand) {
                Register r1 = ((RegisterOperand) o).getRegister();
                if (r1.isValidation())
                    continue;
                Operand r2 = s.peek(r1);
                if (r2 != null) {
                    if (DEBUG) {
                        VM.sysWriteln("replace operand in " + i + "(" + r2 + " for " + o);
                    }
                    i.replaceOperand(o, r2.copy());
                }
            }
        }
    }
    // record renamings required in children
    e = bb.forwardRealInstrEnumerator();
    while (e.hasMoreElements()) {
        Instruction i = e.nextElement();
        if (globalRenameTable.contains(i)) {
            Register original = Move.getVal(i).asRegister().getRegister();
            RegisterOperand rename = Move.getResult(i);
            if (DEBUG)
                VM.sysWriteln("record rename " + rename + " for " + original);
            s.push(original, rename);
        }
    }
    // insert copies in control children
    Enumeration<TreeNode> children = dom.getChildren(bb);
    while (children.hasMoreElements()) {
        BasicBlock c = ((DominatorTreeNode) children.nextElement()).getBlock();
        performRename(c, dom, s);
    }
    // pop renamings from this block off stack
    e = bb.forwardRealInstrEnumerator();
    while (e.hasMoreElements()) {
        Instruction i = e.nextElement();
        if (globalRenameTable.contains(i)) {
            Register original = Move.getVal(i).asRegister().getRegister();
            s.pop(original);
        }
    }
}
Also used : RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) Register(org.jikesrvm.compilers.opt.ir.Register) DominatorTreeNode(org.jikesrvm.compilers.opt.controlflow.DominatorTreeNode) UnreachableOperand(org.jikesrvm.compilers.opt.ir.operand.UnreachableOperand) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) TrueGuardOperand(org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand) Operand(org.jikesrvm.compilers.opt.ir.operand.Operand) ConstantOperand(org.jikesrvm.compilers.opt.ir.operand.ConstantOperand) TreeNode(org.jikesrvm.compilers.opt.util.TreeNode) DominatorTreeNode(org.jikesrvm.compilers.opt.controlflow.DominatorTreeNode) BasicBlock(org.jikesrvm.compilers.opt.ir.BasicBlock) Instruction(org.jikesrvm.compilers.opt.ir.Instruction)

Aggregations

BasicBlock (org.jikesrvm.compilers.opt.ir.BasicBlock)219 Instruction (org.jikesrvm.compilers.opt.ir.Instruction)117 RegisterOperand (org.jikesrvm.compilers.opt.ir.operand.RegisterOperand)93 Operand (org.jikesrvm.compilers.opt.ir.operand.Operand)66 ExceptionHandlerBasicBlock (org.jikesrvm.compilers.opt.ir.ExceptionHandlerBasicBlock)52 Register (org.jikesrvm.compilers.opt.ir.Register)50 BranchProfileOperand (org.jikesrvm.compilers.opt.ir.operand.BranchProfileOperand)48 IntConstantOperand (org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand)37 ConditionOperand (org.jikesrvm.compilers.opt.ir.operand.ConditionOperand)33 MethodOperand (org.jikesrvm.compilers.opt.ir.operand.MethodOperand)27 LocationOperand (org.jikesrvm.compilers.opt.ir.operand.LocationOperand)24 HeapOperand (org.jikesrvm.compilers.opt.ir.operand.HeapOperand)21 BasicBlockOperand (org.jikesrvm.compilers.opt.ir.operand.BasicBlockOperand)20 TrueGuardOperand (org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand)19 TypeReference (org.jikesrvm.classloader.TypeReference)18 NullConstantOperand (org.jikesrvm.compilers.opt.ir.operand.NullConstantOperand)18 Test (org.junit.Test)17 BranchOperand (org.jikesrvm.compilers.opt.ir.operand.BranchOperand)16 InlineSequence (org.jikesrvm.compilers.opt.inlining.InlineSequence)14 MemoryOperand (org.jikesrvm.compilers.opt.ir.operand.MemoryOperand)14