# HG changeset patch # User Gilles Duboscq # Date 1333996241 -7200 # Node ID ae367987a18c7354cc7f0c9ddab9c4e4b4aed20f # Parent 1020e363a05dafefb72e6f659cc0ede24afca61d Add options for OptLoopTransform and OptSafepointElimination diff -r 1020e363a05d -r ae367987a18c graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java Mon Apr 09 19:59:01 2012 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java Mon Apr 09 20:30:41 2012 +0200 @@ -168,8 +168,12 @@ } } if (GraalOptions.OptLoops) { - new LoopTransformPhase().apply(graph); - new SafepointPollingEliminationPhase().apply(graph); + if (GraalOptions.OptLoopTransform) { + new LoopTransformPhase().apply(graph); + } + if (GraalOptions.OptSafepointElimination) { + new SafepointPollingEliminationPhase().apply(graph); + } } new RemoveValueProxyPhase().apply(graph); if (GraalOptions.OptCanonicalizer) { diff -r 1020e363a05d -r ae367987a18c graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalOptions.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalOptions.java Mon Apr 09 19:59:01 2012 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalOptions.java Mon Apr 09 20:30:41 2012 +0200 @@ -193,12 +193,14 @@ public static boolean OptReadElimination = true; public static boolean OptGVN = true; public static boolean OptCanonicalizer = true; - public static boolean OptLoops = ____; + public static boolean OptLoops = true; public static boolean ScheduleOutOfLoops = true; public static boolean OptReorderLoops = true; public static boolean OptEliminateGuards = true; public static boolean OptImplicitNullChecks = true; public static boolean OptLivenessAnalysis = true; + public static boolean OptLoopTransform = true; + public static boolean OptSafepointElimination = true; /** * Flag to turn on SSA-based register allocation, which is currently under development. diff -r 1020e363a05d -r ae367987a18c graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/loop/SuperBlock.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/loop/SuperBlock.java Mon Apr 09 19:59:01 2012 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/loop/SuperBlock.java Mon Apr 09 20:30:41 2012 +0200 @@ -39,6 +39,7 @@ protected LoopBeginNode loop; protected Map duplicationMapping; protected SuperBlock original; + protected NodeBitMap loopNodes; public SuperBlock(BeginNode entry, BeginNode exit, List blocks, List earlyExits, LoopBeginNode loop) { this.entry = entry; @@ -58,8 +59,15 @@ return entry; } + public NodeBitMap loopNodes() { + if (loopNodes == null) { + loopNodes = computeNodes(); + } + return loopNodes; + } + public SuperBlock duplicate() { - NodeBitMap nodes = computeNodes(); + NodeBitMap nodes = loopNodes(); Map replacements = new HashMap<>(); StructuredGraph graph = (StructuredGraph) entry.graph(); BeginNode newEntry = graph.add(new BeginNode()); @@ -264,46 +272,46 @@ } private NodeBitMap computeNodes() { - NodeBitMap loopNodes = entry.graph().createNodeBitMap(); + NodeBitMap nodes = entry.graph().createNodeBitMap(); for (BeginNode b : blocks) { for (Node n : b.getBlockNodes()) { if (n instanceof Invoke) { - loopNodes.mark(((Invoke) n).callTarget()); + nodes.mark(((Invoke) n).callTarget()); } if (n instanceof StateSplit) { FrameState stateAfter = ((StateSplit) n).stateAfter(); if (stateAfter != null) { - loopNodes.mark(stateAfter); + nodes.mark(stateAfter); } } - loopNodes.mark(n); + nodes.mark(n); } } for (BeginNode earlyExit : earlyExits) { FrameState stateAfter = earlyExit.stateAfter(); assert stateAfter != null; - loopNodes.mark(stateAfter); - loopNodes.mark(earlyExit); + nodes.mark(stateAfter); + nodes.mark(earlyExit); for (ValueProxyNode proxy : earlyExit.proxies()) { - loopNodes.mark(proxy); + nodes.mark(proxy); } } for (BeginNode b : blocks) { for (Node n : b.getBlockNodes()) { for (Node usage : n.usages()) { - markFloating(usage, loopNodes, ""); + markFloating(usage, nodes, ""); } } } if (entry instanceof LoopBeginNode) { for (PhiNode phi : ((LoopBeginNode) entry).phis()) { - loopNodes.clear(phi); + nodes.clear(phi); } } - return loopNodes; + return nodes; } private static boolean markFloating(Node n, NodeBitMap loopNodes, String ind) { diff -r 1020e363a05d -r ae367987a18c graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/LoopTransformPhase.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/LoopTransformPhase.java Mon Apr 09 19:59:01 2012 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/LoopTransformPhase.java Mon Apr 09 20:30:41 2012 +0200 @@ -36,6 +36,7 @@ if (graph.hasLoops()) { ControlFlowGraph cfg = ControlFlowGraph.compute(graph, true, true, false, false); Loop[] loops = cfg.getLoops(); + // outermost first Arrays.sort(loops, new Comparator() { @Override public int compare(Loop o1, Loop o2) { diff -r 1020e363a05d -r ae367987a18c graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/BeginNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/BeginNode.java Mon Apr 09 19:59:01 2012 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/BeginNode.java Mon Apr 09 20:30:41 2012 +0200 @@ -61,27 +61,26 @@ // This begin node is necessary. } else { // This begin node can be removed and all guards moved up to the preceding begin node. - if (!usages().isEmpty()) { - Node prevBegin = prev; - while (!(prevBegin instanceof BeginNode)) { - prevBegin = prevBegin.predecessor(); - } - for (Node usage : usages()) { - tool.addToWorkList(usage); - } - replaceAtUsages(prevBegin); - } + prepareDelete(); ((StructuredGraph) graph()).removeFixed(this); } } + public static BeginNode prevBegin(FixedNode from) { + Node prevBegin = from; + while (prevBegin != null) { + if (prevBegin instanceof BeginNode) { + return (BeginNode) prevBegin; + } + prevBegin = prevBegin.predecessor(); + } + return null; + } + public void evacuateGuards(FixedNode evacuateFrom) { if (!usages().isEmpty()) { - Node prevBegin = evacuateFrom; + BeginNode prevBegin = prevBegin(evacuateFrom); assert prevBegin != null; - while (!(prevBegin instanceof BeginNode)) { - prevBegin = prevBegin.predecessor(); - } for (Node anchored : anchored().snapshot()) { anchored.replaceFirstInput(this, prevBegin); }