Search in sources :

Example 1 with SpaceEffGraphEdge

use of org.jikesrvm.compilers.opt.util.SpaceEffGraphEdge in project JikesRVM by JikesRVM.

the class LSTGraph method clearBackEdges.

/**
 * Clears the back edges for the basic block passed
 * @param bb the basic block
 */
private void clearBackEdges(SpaceEffGraphNode bb) {
    SpaceEffGraphNode.OutEdgeEnumeration f = bb.outEdges();
    while (f.hasMoreElements()) {
        SpaceEffGraphEdge outEdge = (SpaceEffGraphEdge) f.next();
        outEdge.clearBackEdge();
    }
}
Also used : SpaceEffGraphEdge(org.jikesrvm.compilers.opt.util.SpaceEffGraphEdge) SpaceEffGraphNode(org.jikesrvm.compilers.opt.util.SpaceEffGraphNode)

Example 2 with SpaceEffGraphEdge

use of org.jikesrvm.compilers.opt.util.SpaceEffGraphEdge in project JikesRVM by JikesRVM.

the class LSTGraph method findNaturalLoop.

/**
 * This routine implements part of the algorithm to compute natural loops
 *  as defined in Muchnick p 192.  See caller for more details.
 * @param edge the edge to process
 * @param loop bit vector to hold the results of the algorithm
 */
private void findNaturalLoop(SpaceEffGraphEdge edge, BitVector loop) {
    /* Algorithm to compute Natural Loops, Muchnick, pp. 192:
       procedure Nat_Loop(m,n,Pred) return set of Node
       m, n: in Node
       Pred: in Node -> set of Node
       begin
       Loop:  set of Node
       Stack: sequence of Node
       p, q: Node
       Stack := []
       Loop  := {m,n}
       if m != n then
       Stack += [m]
       while Stack != [] do
       // add predecessors of m that are not predecessors of n
       // to the set of nodes in the loop; since n dominates m,
       // this only adds nodes in the loop
       p := Stack drop -1
       Stack -= -1
       for each q in Pred(p) do
       if q belongs Loop then
       Loop U= {q}
       Stack += [q]

       return Loop
       end
    */
    SpaceEffGraphNode fromNode = edge.fromNode();
    if (!fromNode.dfsVisited()) {
        fromNode.setDfsVisited();
        loop.set(fromNode.getNumber());
        for (SpaceEffGraphEdge in = fromNode.firstInEdge(); in != null; in = in.getNextIn()) {
            findNaturalLoop(in, loop);
        }
    }
}
Also used : SpaceEffGraphEdge(org.jikesrvm.compilers.opt.util.SpaceEffGraphEdge) SpaceEffGraphNode(org.jikesrvm.compilers.opt.util.SpaceEffGraphNode)

Example 3 with SpaceEffGraphEdge

use of org.jikesrvm.compilers.opt.util.SpaceEffGraphEdge in project JikesRVM by JikesRVM.

the class NormalBURS method handleProblemEdges.

/**
 * Stage 1c: Mark src node of some problem edges as tree roots to avoid
 * cyclic dependencies.
 */
private void handleProblemEdges() {
    // Stage 1: Remove problem edges whose destination
    // is the root of their own tree; these edges
    // are trivially redundant with reg-true edges.
    int remaining = 0;
    for (int i = 0; i < numProblemEdges; i++) {
        SpaceEffGraphEdge e = problemEdges[i];
        SpaceEffGraphNode src = e.fromNode();
        SpaceEffGraphNode dst = e.toNode();
        SpaceEffGraphNode srcRoot = src.nextSorted;
        if (srcRoot != dst) {
            // might still be trouble
            problemEdges[remaining++] = e;
        }
    }
    numProblemEdges = remaining;
    if (numProblemEdges == 0)
        return;
    // Still some edges that might introduce cycles.
    int searchnum = 0;
    for (int i = 0; i < numProblemEdges; i++) {
        SpaceEffGraphEdge e = problemEdges[i];
        SpaceEffGraphNode src = e.fromNode();
        SpaceEffGraphNode dst = e.toNode();
        AbstractBURS_TreeNode n = castNode(src).getCurrentParent();
        // some other problem edge already forced it
        if (n.isTreeRoot())
            continue;
        SpaceEffGraphNode srcRoot = src.nextSorted;
        SpaceEffGraphNode dstRoot = dst.nextSorted;
        if (srcRoot == dstRoot && srcRoot != dst) {
            // potential for intra-tree cycle
            if (!trueEdgeRedundant(src, dst, srcRoot)) {
                if (DEBUG) {
                    VM.sysWriteln("Potential intra-tree cycle with edge " + e + " forcing " + n + " to be a tree root");
                }
                makeTreeRoot(n);
                problemEdgePrep(n, n.dg_node);
            }
        } else {
            // potential for inter-tree cycle
            if (reachableRoot(dstRoot, srcRoot, ++searchnum)) {
                if (DEBUG) {
                    VM.sysWriteln("Potential inter-tree cycle with edge " + e + " forcing " + n + " to be a tree root");
                }
                makeTreeRoot(n);
                problemEdgePrep(n, n.dg_node);
            }
        }
    }
}
Also used : SpaceEffGraphEdge(org.jikesrvm.compilers.opt.util.SpaceEffGraphEdge) SpaceEffGraphNode(org.jikesrvm.compilers.opt.util.SpaceEffGraphNode)

Example 4 with SpaceEffGraphEdge

use of org.jikesrvm.compilers.opt.util.SpaceEffGraphEdge in project JikesRVM by JikesRVM.

the class NormalBURS method orderTrees.

/**
 * Stage 2: Construct topological ordering of tree roots based on the
 * dependencies between nodes in the tree.
 *
 * @param dg  The dependence graph.
 */
private void orderTrees(DepGraph dg) {
    // Initialize tree root field for all nodes
    for (int i = 0; i < numTreeRoots; i++) {
        AbstractBURS_TreeNode n = treeRoots[i];
        castNode(n.dg_node).setPredecessorCount(0);
        initTreeRootNode(n, n.dg_node);
    }
    // Initialize predCount[*]
    for (SpaceEffGraphNode node = dg.firstNode(); node != null; node = node.getNext()) {
        SpaceEffGraphNode n_treeRoot = node.nextSorted;
        for (SpaceEffGraphEdge in = node.firstInEdge(); in != null; in = in.getNextIn()) {
            SpaceEffGraphNode source_treeRoot = in.fromNode().nextSorted;
            if (source_treeRoot != n_treeRoot) {
                castNode(n_treeRoot).incPredecessorCount();
            }
        }
    }
    if (DEBUG) {
        for (int i = 0; i < numTreeRoots; i++) {
            AbstractBURS_TreeNode n = treeRoots[i];
            VM.sysWriteln(castNode(n.dg_node).getPredecessorCount() + ":" + n);
        }
    }
}
Also used : SpaceEffGraphEdge(org.jikesrvm.compilers.opt.util.SpaceEffGraphEdge) SpaceEffGraphNode(org.jikesrvm.compilers.opt.util.SpaceEffGraphNode)

Example 5 with SpaceEffGraphEdge

use of org.jikesrvm.compilers.opt.util.SpaceEffGraphEdge in project JikesRVM by JikesRVM.

the class NormalBURS method generateTree.

// Generate code for a single tree root.
// Also process inter-tree dependencies from this tree to other trees.
private void generateTree(AbstractBURS_TreeNode k, BURS_StateCoder burs) {
    AbstractBURS_TreeNode child1 = k.child1;
    AbstractBURS_TreeNode child2 = k.child2;
    if (child1 != null) {
        if (child2 != null) {
            // determine order that minimizes register pressure
            if (k.isSuperNodeRoot()) {
                byte act = action(k.rule(k.getNonTerminal()));
                if ((act & BURS_StateCoder.LEFT_CHILD_FIRST) != 0) {
                    // rule selected forces order of evaluation
                    generateTree(child1, burs);
                    generateTree(child2, burs);
                } else if ((act & BURS_StateCoder.RIGHT_CHILD_FIRST) != 0) {
                    // rule selected forces order of evaluation
                    generateTree(child2, burs);
                    generateTree(child1, burs);
                } else if (child2.numRegisters() > child1.numRegisters()) {
                    generateTree(child2, burs);
                    generateTree(child1, burs);
                } else {
                    generateTree(child1, burs);
                    generateTree(child2, burs);
                }
            } else {
                if (child2.numRegisters() > child1.numRegisters()) {
                    generateTree(child2, burs);
                    generateTree(child1, burs);
                } else {
                    generateTree(child1, burs);
                    generateTree(child2, burs);
                }
            }
        } else {
            generateTree(child1, burs);
        }
    } else if (child2 != null) {
        generateTree(child2, burs);
    }
    if (k.isSuperNodeRoot()) {
        int nonterminal = k.getNonTerminal();
        int rule = k.rule(nonterminal);
        burs.code(k, nonterminal, rule);
        if (DEBUG)
            VM.sysWriteln(k + " " + debug(rule));
    }
    DepGraphNode dgnode = k.dg_node;
    if (dgnode != null) {
        SpaceEffGraphNode source = dgnode.nextSorted;
        for (SpaceEffGraphEdge out = dgnode.firstOutEdge(); out != null; out = out.getNextOut()) {
            SpaceEffGraphNode dest = out.toNode().nextSorted;
            if (source != dest) {
                castNode(dest).decPredecessorCount();
                int count = castNode(dest).getPredecessorCount();
                if (DEBUG)
                    VM.sysWriteln(count + ": edge " + source + " to " + dest);
                if (count == 0) {
                    readySetInsert(castNode(dest).getCurrentParent());
                }
            }
        }
    }
}
Also used : SpaceEffGraphEdge(org.jikesrvm.compilers.opt.util.SpaceEffGraphEdge) DepGraphNode(org.jikesrvm.compilers.opt.depgraph.DepGraphNode) SpaceEffGraphNode(org.jikesrvm.compilers.opt.util.SpaceEffGraphNode)

Aggregations

SpaceEffGraphEdge (org.jikesrvm.compilers.opt.util.SpaceEffGraphEdge)8 SpaceEffGraphNode (org.jikesrvm.compilers.opt.util.SpaceEffGraphNode)6 Enumeration (java.util.Enumeration)1 HashSet (java.util.HashSet)1 DepGraphNode (org.jikesrvm.compilers.opt.depgraph.DepGraphNode)1 Instruction (org.jikesrvm.compilers.opt.ir.Instruction)1 RegisterOperand (org.jikesrvm.compilers.opt.ir.operand.RegisterOperand)1