# HG changeset patch # User Gilles Duboscq # Date 1340722484 -7200 # Node ID f592c22421e7474ff1a3410d306f2393fddb9f81 # Parent a63ed59939875f79f9bc68d50c6b73e807a95a46 Look for LoopUnswitch opportunities (LoopUnswitch currently disabled) diff -r a63ed5993987 -r f592c22421e7 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 Tue Jun 26 16:51:48 2012 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalOptions.java Tue Jun 26 16:54:44 2012 +0200 @@ -104,6 +104,7 @@ public static boolean ReassociateInvariants = true; public static boolean FullUnroll = true; public static int FullUnrollMaxNodes = 150; // TODO (gd) tune + public static boolean LoopUnswitch = ____; // debugging settings public static int MethodEndBreakpointGuards = 0; diff -r a63ed5993987 -r f592c22421e7 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/loop/LoopPolicies.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/loop/LoopPolicies.java Tue Jun 26 16:51:48 2012 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/loop/LoopPolicies.java Tue Jun 26 16:54:44 2012 +0200 @@ -47,4 +47,9 @@ int size = Math.max(1, loop.size() - 1 - loop.loopBegin().phis().count()); return size * exactTrips <= maxNodes; } + + public static boolean shouldTryUnswitch(@SuppressWarnings("unused") LoopEx loop) { + // TODO (gd) maybe there should be a may number of unswitching per loop + return true; + } } diff -r a63ed5993987 -r f592c22421e7 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/LoopTransformLowPhase.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/LoopTransformLowPhase.java Tue Jun 26 16:51:48 2012 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/LoopTransformLowPhase.java Tue Jun 26 16:54:44 2012 +0200 @@ -25,9 +25,11 @@ import com.oracle.graal.compiler.*; import com.oracle.graal.compiler.loop.*; import com.oracle.graal.debug.*; +import com.oracle.graal.graph.*; import com.oracle.graal.nodes.*; public class LoopTransformLowPhase extends Phase { + private static final DebugMetric UNSWITCHED = Debug.metric("Unswitched"); @Override protected void run(StructuredGraph graph) { @@ -43,6 +45,28 @@ } }); } + if (GraalOptions.LoopUnswitch) { + NodeBitMap unswitchedDebug = graph.createNodeBitMap(); + boolean unswitched; + do { + unswitched = false; + final LoopsData dataUnswitch = new LoopsData(graph); + for (LoopEx loop : dataUnswitch.loops()) { + if (LoopPolicies.shouldTryUnswitch(loop)) { + IfNode ifNode = LoopTransformations.findUnswitchableIf(loop); + if (ifNode != null && !unswitchedDebug.isMarked(ifNode)) { + unswitchedDebug.mark(ifNode); + Debug.log("Unswitching %s at %s [%f - %f]", loop, ifNode, ifNode.probability(0), ifNode.probability(1)); + //LoopTransformations.unswitch(loop, ifNode); + UNSWITCHED.increment(); + //Debug.dump(graph, "After unswitch %s", loop); + unswitched = true; + break; + } + } + } + } while(unswitched); + } } } }