Search in sources :

Example 1 with GraphEdge

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

the class SpillLocationManager method getSpillPreference.

/**
 * Given the current state of the register allocator, compute the
 * available spill location to which ci has the highest preference.
 *
 * @param ci the interval to spill
 * @param spillSize the size of spill location needed
 * @param type the physical register's type
 * @return the interval to spill to.  null if no preference found.
 */
SpillLocationInterval getSpillPreference(CompoundInterval ci, int spillSize, int type) {
    // a mapping from SpillLocationInterval to Integer
    // (spill location to weight);
    HashMap<SpillLocationInterval, Integer> map = new HashMap<SpillLocationInterval, 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;
    RegisterAllocatorState regAllocState = ir.MIRInfo.regAllocState;
    // location 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() && neighbor.isSpilled()) {
            int spillOffset = regAllocState.getSpill(neighbor);
            // if this is a candidate interval, update its weight
            for (SpillLocationInterval s : freeIntervals) {
                if (s.getOffset() == spillOffset && s.getSize() == spillSize && !s.intersects(ci) && s.getType() == type) {
                    int w = edge.getWeight();
                    Integer oldW = map.get(s);
                    if (oldW == null) {
                        map.put(s, w);
                    } else {
                        map.put(s, oldW + w);
                    }
                    break;
                }
            }
        }
    }
    // location affinity
    for (Enumeration<GraphEdge> in = node.inEdges(); in.hasMoreElements(); ) {
        CoalesceGraph.Edge edge = (CoalesceGraph.Edge) in.nextElement();
        CoalesceGraph.Node dest = (CoalesceGraph.Node) edge.to();
        Register neighbor = dest.getRegister();
        if (neighbor.isSymbolic() && neighbor.isSpilled()) {
            int spillOffset = regAllocState.getSpill(neighbor);
            // if this is a candidate interval, update its weight
            for (SpillLocationInterval s : freeIntervals) {
                if (s.getOffset() == spillOffset && s.getSize() == spillSize && !s.intersects(ci) && s.getType() == type) {
                    int w = edge.getWeight();
                    Integer oldW = map.get(s);
                    if (oldW == null) {
                        map.put(s, w);
                    } else {
                        map.put(s, oldW + w);
                    }
                    break;
                }
            }
        }
    }
    // OK, now find the highest preference.
    SpillLocationInterval result = null;
    int weight = -1;
    for (Map.Entry<SpillLocationInterval, 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 2 with GraphEdge

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

the class CoalesceGraph method findOrCreateEdge.

private Edge findOrCreateEdge(Node src, Node dest) {
    Edge edge = null;
    for (GraphEdgeEnumeration<GraphEdge> e = src.outEdges(); e.hasMoreElements(); ) {
        Edge candidate = (Edge) e.next();
        if (candidate.toNode() == dest) {
            edge = candidate;
            break;
        }
    }
    if (edge == null) {
        edge = new Edge(src, dest);
        addGraphEdge(edge);
    }
    return edge;
}
Also used : SpaceEffGraphEdge(org.jikesrvm.compilers.opt.util.SpaceEffGraphEdge) GraphEdge(org.jikesrvm.compilers.opt.util.GraphEdge) SpaceEffGraphEdge(org.jikesrvm.compilers.opt.util.SpaceEffGraphEdge) GraphEdge(org.jikesrvm.compilers.opt.util.GraphEdge)

Example 3 with GraphEdge

use of org.jikesrvm.compilers.opt.util.GraphEdge 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 4 with GraphEdge

use of org.jikesrvm.compilers.opt.util.GraphEdge 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 5 with GraphEdge

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

the class GenerationContextTest method assertThatUnlockAndRethrowBlockIsCorrect.

private void assertThatUnlockAndRethrowBlockIsCorrect(GenerationContext gc, InlineSequence inlineSequence, BasicBlock prologue, Operand lockObject, BasicBlock epilogue) {
    ExceptionHandlerBasicBlockBag ehbb = gc.getEnclosingHandlers();
    Enumeration<BasicBlock> enumerator = ehbb.enumerator();
    ExceptionHandlerBasicBlock rethrow = (ExceptionHandlerBasicBlock) enumerator.nextElement();
    assertThat(enumerator.hasMoreElements(), is(false));
    assertThatRethrowBlockIsCorrect(inlineSequence, lockObject, rethrow);
    checkCodeOrderForRethrowBlock(gc, prologue, epilogue, rethrow);
    assertTrue(rethrow.mayThrowUncaughtException());
    assertTrue(rethrow.canThrowExceptions());
    OutEdgeEnumeration outEdges = rethrow.outEdges();
    boolean leadsToExit = false;
    while (outEdges.hasMoreElements()) {
        GraphEdge nextElement = outEdges.nextElement();
        BasicBlock target = (BasicBlock) nextElement.to();
        if (target == gc.getCfg().exit()) {
            leadsToExit = true;
        }
    }
    assertTrue(leadsToExit);
    assertSame(rethrow, gc.getUnlockAndRethrow());
    ExceptionHandlerBasicBlockBag ehbbb = gc.getEnclosingHandlers();
    assertNull(ehbbb.getCaller());
    assertThatEnclosingHandlersContainRethrow(rethrow, ehbbb);
}
Also used : OutEdgeEnumeration(org.jikesrvm.compilers.opt.util.SpaceEffGraphNode.OutEdgeEnumeration) BasicBlock(org.jikesrvm.compilers.opt.ir.BasicBlock) ExceptionHandlerBasicBlock(org.jikesrvm.compilers.opt.ir.ExceptionHandlerBasicBlock) ExceptionHandlerBasicBlock(org.jikesrvm.compilers.opt.ir.ExceptionHandlerBasicBlock) GraphEdge(org.jikesrvm.compilers.opt.util.GraphEdge) ExceptionHandlerBasicBlockBag(org.jikesrvm.compilers.opt.ir.ExceptionHandlerBasicBlockBag)

Aggregations

GraphEdge (org.jikesrvm.compilers.opt.util.GraphEdge)5 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Register (org.jikesrvm.compilers.opt.ir.Register)3 SpaceEffGraphNode (org.jikesrvm.compilers.opt.util.SpaceEffGraphNode)3 BasicBlock (org.jikesrvm.compilers.opt.ir.BasicBlock)1 ExceptionHandlerBasicBlock (org.jikesrvm.compilers.opt.ir.ExceptionHandlerBasicBlock)1 ExceptionHandlerBasicBlockBag (org.jikesrvm.compilers.opt.ir.ExceptionHandlerBasicBlockBag)1 SpaceEffGraphEdge (org.jikesrvm.compilers.opt.util.SpaceEffGraphEdge)1 OutEdgeEnumeration (org.jikesrvm.compilers.opt.util.SpaceEffGraphNode.OutEdgeEnumeration)1