Search in sources :

Example 11 with SpaceEffGraphNode

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

the class ActiveSet method getPhysicalPreference.

/**
 * Given the current state of the register allocator, compute the
 * available physical register to which a symbolic register has the
 * highest preference.
 *
 * @param r the symbolic register in question.
 * @return the preferred register, {@code null} if no preference found.
 */
private Register getPhysicalPreference(Register r) {
    // a mapping from Register to Integer
    // (physical register to weight);
    HashMap<Register, Integer> map = new HashMap<Register, Integer>();
    CoalesceGraph graph = ir.stackManager.getPreferences().getGraph();
    SpaceEffGraphNode node = graph.findNode(r);
    // Return null if no affinities.
    if (node == null)
        return null;
    // walk through all in edges of the node, searching for affinity
    for (Enumeration<GraphEdge> in = node.inEdges(); in.hasMoreElements(); ) {
        CoalesceGraph.Edge edge = (CoalesceGraph.Edge) in.nextElement();
        CoalesceGraph.Node src = (CoalesceGraph.Node) edge.from();
        Register neighbor = src.getRegister();
        if (neighbor.isSymbolic()) {
            // if r is assigned to a physical register r2, treat the
            // affinity as an affinity for r2
            Register r2 = regAllocState.getMapping(r);
            if (r2 != null && r2.isPhysical()) {
                neighbor = r2;
            }
        }
        if (neighbor.isPhysical()) {
            // if this is a candidate interval, update its weight
            if (allocateNewSymbolicToPhysical(r, neighbor)) {
                int w = edge.getWeight();
                Integer oldW = map.get(neighbor);
                if (oldW == null) {
                    map.put(neighbor, w);
                } else {
                    map.put(neighbor, oldW + w);
                }
                break;
            }
        }
    }
    // walk through all out edges of the node, searching for affinity
    for (Enumeration<GraphEdge> in = node.outEdges(); in.hasMoreElements(); ) {
        CoalesceGraph.Edge edge = (CoalesceGraph.Edge) in.nextElement();
        CoalesceGraph.Node dest = (CoalesceGraph.Node) edge.to();
        Register neighbor = dest.getRegister();
        if (neighbor.isSymbolic()) {
            // if r is assigned to a physical register r2, treat the
            // affinity as an affinity for r2
            Register r2 = regAllocState.getMapping(r);
            if (r2 != null && r2.isPhysical()) {
                neighbor = r2;
            }
        }
        if (neighbor.isPhysical()) {
            // if this is a candidate interval, update its weight
            if (allocateNewSymbolicToPhysical(r, neighbor)) {
                int w = edge.getWeight();
                Integer oldW = map.get(neighbor);
                if (oldW == null) {
                    map.put(neighbor, w);
                } else {
                    map.put(neighbor, oldW + w);
                }
                break;
            }
        }
    }
    // OK, now find the highest preference.
    Register result = null;
    int weight = -1;
    for (Map.Entry<Register, Integer> entry : map.entrySet()) {
        int w = entry.getValue();
        if (w > weight) {
            weight = w;
            result = entry.getKey();
        }
    }
    return result;
}
Also used : HashMap(java.util.HashMap) SpaceEffGraphNode(org.jikesrvm.compilers.opt.util.SpaceEffGraphNode) SpaceEffGraphNode(org.jikesrvm.compilers.opt.util.SpaceEffGraphNode) Register(org.jikesrvm.compilers.opt.ir.Register) GraphEdge(org.jikesrvm.compilers.opt.util.GraphEdge) GraphEdge(org.jikesrvm.compilers.opt.util.GraphEdge) Map(java.util.Map) HashMap(java.util.HashMap)

Example 12 with SpaceEffGraphNode

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

the class ActiveSet method getPhysicalPreference.

/**
 * Given the current state of the register allocator, compute the
 * available physical register to which an interval has the highest
 * preference.
 *
 * @param ci the interval in question
 * @return the preferred register, {@code null} if no preference found
 */
private Register getPhysicalPreference(CompoundInterval ci) {
    // a mapping from Register to Integer
    // (physical register to weight);
    HashMap<Register, Integer> map = new HashMap<Register, Integer>();
    Register r = ci.getRegister();
    CoalesceGraph graph = ir.stackManager.getPreferences().getGraph();
    SpaceEffGraphNode node = graph.findNode(r);
    // Return null if no affinities.
    if (node == null)
        return null;
    // walk through all in edges of the node, searching for affinity
    for (Enumeration<GraphEdge> in = node.inEdges(); in.hasMoreElements(); ) {
        CoalesceGraph.Edge edge = (CoalesceGraph.Edge) in.nextElement();
        CoalesceGraph.Node src = (CoalesceGraph.Node) edge.from();
        Register neighbor = src.getRegister();
        if (neighbor.isSymbolic()) {
            // if r is assigned to a physical register r2, treat the
            // affinity as an affinity for r2
            Register r2 = regAllocState.getMapping(r);
            if (r2 != null && r2.isPhysical()) {
                neighbor = r2;
            }
        }
        if (neighbor.isPhysical()) {
            // if this is a candidate interval, update its weight
            if (allocateToPhysical(ci, neighbor)) {
                int w = edge.getWeight();
                Integer oldW = map.get(neighbor);
                if (oldW == null) {
                    map.put(neighbor, w);
                } else {
                    map.put(neighbor, oldW + w);
                }
                break;
            }
        }
    }
    // walk through all out edges of the node, searching for affinity
    for (Enumeration<GraphEdge> in = node.outEdges(); in.hasMoreElements(); ) {
        CoalesceGraph.Edge edge = (CoalesceGraph.Edge) in.nextElement();
        CoalesceGraph.Node dest = (CoalesceGraph.Node) edge.to();
        Register neighbor = dest.getRegister();
        if (neighbor.isSymbolic()) {
            // if r is assigned to a physical register r2, treat the
            // affinity as an affinity for r2
            Register r2 = regAllocState.getMapping(r);
            if (r2 != null && r2.isPhysical()) {
                neighbor = r2;
            }
        }
        if (neighbor.isPhysical()) {
            // if this is a candidate interval, update its weight
            if (allocateToPhysical(ci, neighbor)) {
                int w = edge.getWeight();
                Integer oldW = map.get(neighbor);
                if (oldW == null) {
                    map.put(neighbor, w);
                } else {
                    map.put(neighbor, oldW + w);
                }
                break;
            }
        }
    }
    // OK, now find the highest preference.
    Register result = null;
    int weight = -1;
    for (Map.Entry<Register, Integer> entry : map.entrySet()) {
        int w = entry.getValue();
        if (w > weight) {
            weight = w;
            result = entry.getKey();
        }
    }
    return result;
}
Also used : HashMap(java.util.HashMap) SpaceEffGraphNode(org.jikesrvm.compilers.opt.util.SpaceEffGraphNode) SpaceEffGraphNode(org.jikesrvm.compilers.opt.util.SpaceEffGraphNode) Register(org.jikesrvm.compilers.opt.ir.Register) GraphEdge(org.jikesrvm.compilers.opt.util.GraphEdge) GraphEdge(org.jikesrvm.compilers.opt.util.GraphEdge) Map(java.util.Map) HashMap(java.util.HashMap)

Example 13 with SpaceEffGraphNode

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

the class NormalBURS method mustBeTreeRoot.

/**
 * Checks if the given node needs to be a tree rode.
 * If the node does not need to be a tree root right now
 * but might later have to be marked as a tree
 * root, then include in a set of problem nodes.
 *
 * @param n the dep graph node in question.
 * @return {@code true} if node n must be a root of a BURS tree
 * based only on its register true dependencies.
 */
private boolean mustBeTreeRoot(DepGraphNode n) {
    // A "fan-out" node must be a root of a BURS tree.
    // (A fan-out node is a node with > 1 outgoing register-true dependences)
    SpaceEffGraphEdge trueDepEdge = null;
    for (SpaceEffGraphEdge out = n.firstOutEdge(); out != null; out = out.getNextOut()) {
        if (DepGraphEdge.isRegTrue(out)) {
            if (trueDepEdge != null)
                return true;
            trueDepEdge = out;
        }
    }
    if (trueDepEdge == null) {
        // 0 outgoing register-true dependencies
        return true;
    } else {
        // Exactly 1 true edge, since we would have bailed out of above
        // loop if we'd found a second one.
        // If the node produces a register value that is live on exit
        // from the basic block then it must be the root of a BURS tree.
        Instruction instr = n.instruction();
        if (instr.operator() == IR_PROLOGUE)
            return true;
        RegisterOperand rop = ResultCarrier.getResult(instr);
        if (rop.getRegister().spansBasicBlock())
            return true;
        SpaceEffGraphNode parent = trueDepEdge.toNode();
        // by not forcing n to be a tree root.
        for (SpaceEffGraphEdge out = n.firstOutEdge(); out != null; out = out.getNextOut()) {
            if (out != trueDepEdge) {
                boolean match = false;
                for (SpaceEffGraphEdge out2 = parent.firstOutEdge(); out2 != null; out2 = out2.getNextOut()) {
                    if (out2.toNode() == out.toNode()) {
                        match = true;
                        break;
                    }
                }
                if (!match) {
                    // could be trouble. Remember for later processing.
                    rememberAsProblemEdge(out);
                }
            }
        }
        return false;
    }
}
Also used : RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) SpaceEffGraphEdge(org.jikesrvm.compilers.opt.util.SpaceEffGraphEdge) Instruction(org.jikesrvm.compilers.opt.ir.Instruction) SpaceEffGraphNode(org.jikesrvm.compilers.opt.util.SpaceEffGraphNode)

Aggregations

SpaceEffGraphNode (org.jikesrvm.compilers.opt.util.SpaceEffGraphNode)13 SpaceEffGraphEdge (org.jikesrvm.compilers.opt.util.SpaceEffGraphEdge)6 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Register (org.jikesrvm.compilers.opt.ir.Register)3 GraphEdge (org.jikesrvm.compilers.opt.util.GraphEdge)3 Instruction (org.jikesrvm.compilers.opt.ir.Instruction)2 DepGraphNode (org.jikesrvm.compilers.opt.depgraph.DepGraphNode)1 BasicBlock (org.jikesrvm.compilers.opt.ir.BasicBlock)1 RegisterOperand (org.jikesrvm.compilers.opt.ir.operand.RegisterOperand)1