Search in sources :

Example 1 with SpaceEffGraphNode

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

the class ControlFlowGraph method insertAfterInCodeOrder.

/**
 * Insert a block 'toAdd' not currently in the code ordering after
 * a block 'old' that is currently in the code ordering.
 * If necessary, _lastNode is updated.
 * No impact on FCFG edges.
 *
 * @param old a block currently in the code ordering
 * @param toAdd a block to add after old in the code ordering
 */
public void insertAfterInCodeOrder(BasicBlock old, BasicBlock toAdd) {
    if (IR.SANITY_CHECK)
        VM._assert(toAdd.next == null);
    if (IR.SANITY_CHECK)
        VM._assert(toAdd.prev == null);
    SpaceEffGraphNode oldNext = old.next;
    if (oldNext == null) {
        if (IR.SANITY_CHECK)
            VM._assert(_lastNode == old);
        old.append(toAdd);
        _lastNode = toAdd;
    } else {
        old.append(toAdd);
        toAdd.append(oldNext);
    }
}
Also used : SpaceEffGraphNode(org.jikesrvm.compilers.opt.util.SpaceEffGraphNode)

Example 2 with SpaceEffGraphNode

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

the class ControlFlowGraph method clearCodeOrder.

/**
 * Clear the code ordering information for the CFG.<p>
 * NOTE: This method should only be called as part of a
 *       whole scale recomputation of the code order, for example
 *       by ReorderingPhase
 */
public void clearCodeOrder() {
    SpaceEffGraphNode cur = _firstNode;
    if (cur == null)
        return;
    while (true) {
        SpaceEffGraphNode next = cur.next;
        if (next == null)
            break;
        cur.next = null;
        next.prev = null;
        cur = next;
    }
    _firstNode = null;
    _lastNode = null;
}
Also used : SpaceEffGraphNode(org.jikesrvm.compilers.opt.util.SpaceEffGraphNode)

Example 3 with SpaceEffGraphNode

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

the class ControlFlowGraph method insertBeforeInCodeOrder.

/**
 * Insert a block 'toAdd' not currently in the code ordering before
 * a block 'old' that is currently in the code ordering.
 * If necessary, _firstNode is updated.
 * No impact on FCFG edges.
 *
 * @param old a block currently in the code ordering
 * @param toAdd a block to add before old in the code ordering
 */
public void insertBeforeInCodeOrder(BasicBlock old, BasicBlock toAdd) {
    if (IR.SANITY_CHECK)
        VM._assert(toAdd.next == null);
    if (IR.SANITY_CHECK)
        VM._assert(toAdd.prev == null);
    SpaceEffGraphNode oldPrev = old.prev;
    if (oldPrev == null) {
        if (IR.SANITY_CHECK)
            VM._assert(_firstNode == old);
        _firstNode = toAdd;
        toAdd.append(old);
    } else {
        oldPrev.append(toAdd);
        toAdd.append(old);
    }
}
Also used : SpaceEffGraphNode(org.jikesrvm.compilers.opt.util.SpaceEffGraphNode)

Example 4 with SpaceEffGraphNode

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

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

the class BranchOptimizationDriver method removeUnreachableCode.

/**
 * Remove unreachable code
 *
 * @param ir the IR to optimize
 * @return true if did something, false otherwise
 */
protected final boolean removeUnreachableCode(IR ir) {
    boolean result = false;
    // trap instruction is dead.
    for (Instruction s = ir.firstInstructionInCodeOrder(); s != null; s = s.nextInstructionInCodeOrder()) {
        if (Trap.conforms(s)) {
            Instruction p = s.nextInstructionInCodeOrder();
            if (p.operator() != BBEND) {
                BasicBlock bb = s.getBasicBlock();
                do {
                    Instruction q = p;
                    p = p.nextInstructionInCodeOrder();
                    q.remove();
                } while (p.operator() != BBEND);
                bb.recomputeNormalOut(ir);
                result = true;
            }
        }
    }
    // (2) perform a Depth-first search of the control flow graph,
    // and remove any nodes not reachable from entry.
    BasicBlock entry = ir.cfg.entry();
    ir.cfg.clearDFS();
    entry.sortDFS();
    for (SpaceEffGraphNode node = entry; node != null; ) {
        // save it now before removeFromCFGAndCodeOrder nulls it out!!!
        SpaceEffGraphNode nextNode = node.getNext();
        if (!node.dfsVisited()) {
            BasicBlock bb = (BasicBlock) node;
            ir.cfg.removeFromCFGAndCodeOrder(bb);
            result = true;
        }
        node = nextNode;
    }
    return result;
}
Also used : BasicBlock(org.jikesrvm.compilers.opt.ir.BasicBlock) 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