Search in sources :

Example 16 with BitVector

use of org.jikesrvm.util.BitVector in project JikesRVM by JikesRVM.

the class CFGTransformations method inLoopSuccessors.

private static BasicBlock[] inLoopSuccessors(LSTNode n) {
    BasicBlock header = n.header;
    BitVector loop = n.getLoop();
    int i = 0;
    Enumeration<BasicBlock> be = header.getOut();
    while (be.hasMoreElements()) if (inLoop(be.nextElement(), loop))
        i++;
    BasicBlock[] res = new BasicBlock[i];
    i = 0;
    be = header.getOut();
    while (be.hasMoreElements()) {
        BasicBlock in = be.nextElement();
        if (inLoop(in, loop))
            res[i++] = in;
    }
    return res;
}
Also used : BitVector(org.jikesrvm.util.BitVector) BasicBlock(org.jikesrvm.compilers.opt.ir.BasicBlock)

Example 17 with BitVector

use of org.jikesrvm.util.BitVector in project JikesRVM by JikesRVM.

the class DominanceFrontier method perform.

/**
 * Calculate the dominance frontier for each basic block in the
 * CFG. Stores the result in the DominatorTree for the governing
 * IR.
 *
 * <p> NOTE: The dominator tree MUST be calculated BEFORE calling this
 *      routine.
 *
 * @param ir the governing IR
 */
@Override
public void perform(IR ir) {
    final boolean DEBUG = false;
    // make sure the dominator computation completed successfully
    if (!ir.HIRInfo.dominatorsAreComputed) {
        return;
    }
    // make sure dominator tree is computed
    if (ir.HIRInfo.dominatorTree == null) {
        return;
    }
    // for each X in a bottom-up traversal of the dominator tree do
    DominatorTree tree = ir.HIRInfo.dominatorTree;
    for (Enumeration<TreeNode> x = tree.getBottomUpEnumerator(); x.hasMoreElements(); ) {
        DominatorTreeNode v = (DominatorTreeNode) x.nextElement();
        BasicBlock X = v.getBlock();
        if (DEBUG) {
            System.out.println("Computing frontier for node " + X);
        }
        BitVector DF = new BitVector(ir.getMaxBasicBlockNumber() + 1);
        v.setDominanceFrontier(DF);
        // for each Y in Succ(X) do
        for (Enumeration<BasicBlock> y = X.getOut(); y.hasMoreElements(); ) {
            BasicBlock Y = y.nextElement();
            // skip EXIT node
            if (Y.isExit()) {
                continue;
            }
            // if (idom(Y)!=X) then DF(X) <- DF(X) U Y
            if (LTDominatorInfo.getIdom(Y, ir) != X) {
                DF.set(Y.getNumber());
            }
        }
        if (DEBUG) {
            System.out.println("After local " + DF);
        }
        // for each Z in {idom(z) = X} do
        for (Enumeration<TreeNode> z = tree.getChildren(X); z.hasMoreElements(); ) {
            DominatorTreeNode zVertex = (DominatorTreeNode) z.nextElement();
            BasicBlock Z = zVertex.getBlock();
            if (DEBUG) {
                System.out.println("Processing Z = " + Z);
            }
            // for each Y in DF(Z) do
            for (Enumeration<BasicBlock> y = zVertex.domFrontierEnumerator(ir); y.hasMoreElements(); ) {
                BasicBlock Y = y.nextElement();
                // if (idom(Y)!=X) then DF(X) <- DF(X) U Y
                if (LTDominatorInfo.getIdom(Y, ir) != X) {
                    DF.set(Y.getNumber());
                }
            }
        }
        if (DEBUG) {
            System.out.println("After up " + DF);
        }
    }
    if (DEBUG) {
        for (Enumeration<BasicBlock> bbEnum = ir.cfg.basicBlocks(); bbEnum.hasMoreElements(); ) {
            BasicBlock block = bbEnum.nextElement();
            if (block.isExit()) {
                continue;
            }
            System.out.println(block + " DF: " + tree.getDominanceFrontier(block));
        }
    }
}
Also used : BitVector(org.jikesrvm.util.BitVector) TreeNode(org.jikesrvm.compilers.opt.util.TreeNode) BasicBlock(org.jikesrvm.compilers.opt.ir.BasicBlock)

Example 18 with BitVector

use of org.jikesrvm.util.BitVector in project JikesRVM by JikesRVM.

the class DominatorOperator method evaluate.

/**
 * Evaluate an equation with the MEET operation
 * @param operands the lhs(operands[0]) and rhs(operands[1])
 *       of the equation.
 * @return {@code true} if the value of the lhs changes. {@code false} otherwise
 */
@Override
public boolean evaluate(DF_LatticeCell[] operands) {
    DominatorCell lhs = (DominatorCell) operands[0];
    IR ir = lhs.ir;
    BasicBlock bb = lhs.block;
    BitVector oldSet = lhs.dominators.dup();
    BitVector newDominators = new BitVector(ir.getMaxBasicBlockNumber() + 1);
    if (operands.length > 1) {
        if (operands[1] != null) {
            newDominators.or(((DominatorCell) operands[1]).dominators);
        }
    }
    for (int i = 2; i < operands.length; i++) {
        newDominators.and(((DominatorCell) operands[i]).dominators);
    }
    newDominators.set(bb.getNumber());
    lhs.dominators = newDominators;
    return !lhs.dominators.equals(oldSet);
}
Also used : BitVector(org.jikesrvm.util.BitVector) BasicBlock(org.jikesrvm.compilers.opt.ir.BasicBlock) IR(org.jikesrvm.compilers.opt.ir.IR)

Example 19 with BitVector

use of org.jikesrvm.util.BitVector in project JikesRVM by JikesRVM.

the class LoopUnrolling method makeSomeCopies.

// inserts unrollFactor copies of the loop after seqStart
BasicBlock[] makeSomeCopies(int unrollFactor, IR ir, BitVector nloop, int blocks, BasicBlock header, BasicBlock exitBlock, BasicBlock seqStart) {
    // make some copies of the original loop
    // first, capture the blocks in the loop body.
    BitVector loop = new BitVector(nloop);
    loop.clear(header.getNumber());
    loop.clear(exitBlock.getNumber());
    int bodyBlocks = 0;
    Enumeration<BasicBlock> bs = ir.getBasicBlocks(loop);
    while (bs.hasMoreElements()) {
        bodyBlocks++;
        bs.nextElement();
    }
    BasicBlock[] body = new BasicBlock[bodyBlocks];
    {
        int i = 0;
        bs = ir.getBasicBlocks(loop);
        while (bs.hasMoreElements()) {
            body[i++] = bs.nextElement();
        }
    }
    BasicBlock seqEnd = seqStart.nextBasicBlockInCodeOrder();
    if (seqEnd != null)
        ir.cfg.breakCodeOrder(seqStart, seqEnd);
    BasicBlock seqLast = seqStart;
    BasicBlock firstHeader = null;
    BasicBlock lastHeader = null;
    BasicBlock lastExit = null;
    BasicBlock[] handles = new BasicBlock[2];
    for (int i = 0; i < unrollFactor; ++i) {
        // copy header
        seqLast = copyAndLinkBlock(ir, seqLast, header);
        lastHeader = seqLast;
        if (i == 0) {
            firstHeader = seqLast;
        } else {
            // link copies by jumps
            lastExit.appendInstruction(Goto.create(GOTO, seqLast.makeJumpTarget()));
            lastExit.recomputeNormalOut(ir);
        }
        // copy body
        for (BasicBlock bb : body) {
            seqLast = copyAndLinkBlock(ir, seqLast, bb);
        }
        // copy exit block
        if (exitBlock != header) {
            seqLast = copyAndLinkBlock(ir, seqLast, exitBlock);
            lastExit = seqLast;
        } else {
            lastExit = lastHeader;
        }
        // delete all branches in the copies of the exit block
        deleteBranches(lastExit);
        // redirect internal branches
        BasicBlock cb = seqLast;
        for (int j = 0; j < blocks; ++j) {
            cb.recomputeNormalOut(ir);
            Enumeration<BasicBlock> be = cb.getOut();
            while (be.hasMoreElements()) {
                BasicBlock out = be.nextElement();
                if (CFGTransformations.inLoop(out, nloop)) {
                    cb.redirectOuts(out, copiedBlocks.get(out), ir);
                }
            }
            cb.recomputeNormalOut(ir);
            cb = cb.prevBasicBlockInCodeOrder();
        }
    }
    if (seqEnd != null)
        ir.cfg.linkInCodeOrder(seqLast, seqEnd);
    handles[0] = firstHeader;
    handles[1] = lastExit;
    return handles;
}
Also used : BitVector(org.jikesrvm.util.BitVector) ExceptionHandlerBasicBlock(org.jikesrvm.compilers.opt.ir.ExceptionHandlerBasicBlock) BasicBlock(org.jikesrvm.compilers.opt.ir.BasicBlock)

Example 20 with BitVector

use of org.jikesrvm.util.BitVector in project JikesRVM by JikesRVM.

the class LSTGraph method setDepth.

private void setDepth(IR ir, LSTNode node, int depth) {
    if (VM.VerifyAssertions)
        VM._assert(node.depth == 0);
    node.depth = depth;
    for (Enumeration<LSTNode> e = node.getChildren(); e.hasMoreElements(); ) {
        setDepth(ir, e.nextElement(), depth + 1);
    }
    BitVector loop = node.getLoop();
    if (loop != null) {
        for (int i = 0; i < loop.length(); i++) {
            if (loop.get(i)) {
                BasicBlock bb = ir.getBasicBlock(i);
                if (loopMap.get(bb) == null) {
                    loopMap.put(bb, node);
                }
            }
        }
    }
}
Also used : BitVector(org.jikesrvm.util.BitVector) BasicBlock(org.jikesrvm.compilers.opt.ir.BasicBlock)

Aggregations

BitVector (org.jikesrvm.util.BitVector)20 BasicBlock (org.jikesrvm.compilers.opt.ir.BasicBlock)12 ExceptionHandlerBasicBlock (org.jikesrvm.compilers.opt.ir.ExceptionHandlerBasicBlock)3 Instruction (org.jikesrvm.compilers.opt.ir.Instruction)2 Operand (org.jikesrvm.compilers.opt.ir.operand.Operand)2 RegisterOperand (org.jikesrvm.compilers.opt.ir.operand.RegisterOperand)2 HashSet (java.util.HashSet)1 IR (org.jikesrvm.compilers.opt.ir.IR)1 Register (org.jikesrvm.compilers.opt.ir.Register)1 BasicBlockOperand (org.jikesrvm.compilers.opt.ir.operand.BasicBlockOperand)1 BranchProfileOperand (org.jikesrvm.compilers.opt.ir.operand.BranchProfileOperand)1 ConditionOperand (org.jikesrvm.compilers.opt.ir.operand.ConditionOperand)1 ConstantOperand (org.jikesrvm.compilers.opt.ir.operand.ConstantOperand)1 HeapOperand (org.jikesrvm.compilers.opt.ir.operand.HeapOperand)1 IntConstantOperand (org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand)1 UnreachableOperand (org.jikesrvm.compilers.opt.ir.operand.UnreachableOperand)1 TreeNode (org.jikesrvm.compilers.opt.util.TreeNode)1