22 */ |
22 */ |
23 |
23 |
24 |
24 |
25 package org.graalvm.compiler.loop.phases; |
25 package org.graalvm.compiler.loop.phases; |
26 |
26 |
|
27 import org.graalvm.compiler.debug.CounterKey; |
27 import org.graalvm.compiler.debug.DebugContext; |
28 import org.graalvm.compiler.debug.DebugContext; |
28 import org.graalvm.compiler.loop.LoopEx; |
29 import org.graalvm.compiler.loop.LoopEx; |
29 import org.graalvm.compiler.loop.LoopPolicies; |
30 import org.graalvm.compiler.loop.LoopPolicies; |
30 import org.graalvm.compiler.loop.LoopsData; |
31 import org.graalvm.compiler.loop.LoopsData; |
31 import org.graalvm.compiler.nodes.StructuredGraph; |
32 import org.graalvm.compiler.nodes.StructuredGraph; |
32 import org.graalvm.compiler.nodes.spi.CoreProviders; |
33 import org.graalvm.compiler.nodes.spi.CoreProviders; |
33 |
34 |
34 public class LoopPeelingPhase extends LoopPhase<LoopPolicies> { |
35 public class LoopPeelingPhase extends LoopPhase<LoopPolicies> { |
|
36 |
|
37 public static final CounterKey PEELED = DebugContext.counter("Peeled"); |
35 |
38 |
36 public LoopPeelingPhase(LoopPolicies policies) { |
39 public LoopPeelingPhase(LoopPolicies policies) { |
37 super(policies); |
40 super(policies); |
38 } |
41 } |
39 |
42 |
43 DebugContext debug = graph.getDebug(); |
46 DebugContext debug = graph.getDebug(); |
44 if (graph.hasLoops()) { |
47 if (graph.hasLoops()) { |
45 LoopsData data = new LoopsData(graph); |
48 LoopsData data = new LoopsData(graph); |
46 try (DebugContext.Scope s = debug.scope("peeling", data.getCFG())) { |
49 try (DebugContext.Scope s = debug.scope("peeling", data.getCFG())) { |
47 for (LoopEx loop : data.outerFirst()) { |
50 for (LoopEx loop : data.outerFirst()) { |
48 if (getPolicies().shouldPeel(loop, data.getCFG(), context.getMetaAccess())) { |
51 if (loop.canDuplicateLoop() && loop.loopBegin().getLoopEndCount() > 0) { |
49 debug.log("Peeling %s", loop); |
52 if (LoopPolicies.Options.PeelALot.getValue(graph.getOptions()) || getPolicies().shouldPeel(loop, data.getCFG(), context.getMetaAccess())) { |
50 LoopTransformations.peel(loop); |
53 debug.log("Peeling %s", loop); |
51 debug.dump(DebugContext.DETAILED_LEVEL, graph, "Peeling %s", loop); |
54 PEELED.add(debug, 1); |
|
55 LoopTransformations.peel(loop); |
|
56 debug.dump(DebugContext.DETAILED_LEVEL, graph, "Peeling %s", loop); |
|
57 } |
52 } |
58 } |
53 } |
59 } |
54 data.deleteUnusedNodes(); |
60 data.deleteUnusedNodes(); |
55 } catch (Throwable t) { |
61 } catch (Throwable t) { |
56 throw debug.handle(t); |
62 throw debug.handle(t); |