1 /* |
1 /* |
2 * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
23 |
23 |
24 |
24 |
25 package org.graalvm.compiler.core.test; |
25 package org.graalvm.compiler.core.test; |
26 |
26 |
27 import org.graalvm.compiler.debug.DebugContext; |
27 import org.graalvm.compiler.debug.DebugContext; |
|
28 import org.graalvm.compiler.loop.phases.ConvertDeoptimizeToGuardPhase; |
28 import org.graalvm.compiler.nodes.ProxyNode; |
29 import org.graalvm.compiler.nodes.ProxyNode; |
29 import org.graalvm.compiler.nodes.StructuredGraph; |
30 import org.graalvm.compiler.nodes.StructuredGraph; |
30 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions; |
31 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions; |
|
32 import org.graalvm.compiler.nodes.spi.CoreProviders; |
31 import org.graalvm.compiler.nodes.spi.LoweringTool; |
33 import org.graalvm.compiler.nodes.spi.LoweringTool; |
32 import org.graalvm.compiler.phases.OptimisticOptimizations; |
34 import org.graalvm.compiler.phases.OptimisticOptimizations; |
33 import org.graalvm.compiler.phases.OptimisticOptimizations.Optimization; |
35 import org.graalvm.compiler.phases.OptimisticOptimizations.Optimization; |
34 import org.graalvm.compiler.phases.common.CanonicalizerPhase; |
36 import org.graalvm.compiler.phases.common.CanonicalizerPhase; |
35 import org.graalvm.compiler.phases.common.ConditionalEliminationPhase; |
37 import org.graalvm.compiler.phases.common.ConditionalEliminationPhase; |
36 import org.graalvm.compiler.loop.phases.ConvertDeoptimizeToGuardPhase; |
|
37 import org.graalvm.compiler.phases.common.IterativeConditionalEliminationPhase; |
38 import org.graalvm.compiler.phases.common.IterativeConditionalEliminationPhase; |
38 import org.graalvm.compiler.phases.common.LoweringPhase; |
39 import org.graalvm.compiler.phases.common.LoweringPhase; |
39 import org.graalvm.compiler.phases.schedule.SchedulePhase; |
40 import org.graalvm.compiler.phases.schedule.SchedulePhase; |
40 import org.graalvm.compiler.phases.tiers.HighTierContext; |
41 import org.graalvm.compiler.phases.tiers.HighTierContext; |
41 import org.graalvm.compiler.phases.tiers.PhaseContext; |
|
42 import org.junit.Assert; |
42 import org.junit.Assert; |
43 |
43 |
44 /** |
44 /** |
45 * Collection of tests for {@link org.graalvm.compiler.phases.common.ConditionalEliminationPhase} |
45 * Collection of tests for {@link org.graalvm.compiler.phases.common.ConditionalEliminationPhase} |
46 * including those that triggered bugs in this phase. |
46 * including those that triggered bugs in this phase. |
66 @SuppressWarnings("try") |
66 @SuppressWarnings("try") |
67 protected void testConditionalElimination(String snippet, String referenceSnippet, boolean applyConditionalEliminationOnReference, boolean applyLowering) { |
67 protected void testConditionalElimination(String snippet, String referenceSnippet, boolean applyConditionalEliminationOnReference, boolean applyLowering) { |
68 StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES); |
68 StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES); |
69 DebugContext debug = graph.getDebug(); |
69 DebugContext debug = graph.getDebug(); |
70 debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph"); |
70 debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph"); |
71 PhaseContext context = new PhaseContext(getProviders()); |
71 CoreProviders context = getProviders(); |
72 CanonicalizerPhase canonicalizer1 = new CanonicalizerPhase(); |
72 CanonicalizerPhase canonicalizer1 = new CanonicalizerPhase(); |
73 CanonicalizerPhase canonicalizer = new CanonicalizerPhase(); |
73 CanonicalizerPhase canonicalizer = new CanonicalizerPhase(); |
74 try (DebugContext.Scope scope = debug.scope("ConditionalEliminationTest", graph)) { |
74 try (DebugContext.Scope scope = debug.scope("ConditionalEliminationTest", graph)) { |
75 prepareGraph(graph, canonicalizer1, context, applyLowering); |
75 prepareGraph(graph, canonicalizer1, context, applyLowering); |
76 new IterativeConditionalEliminationPhase(canonicalizer, true).apply(graph, context); |
76 new IterativeConditionalEliminationPhase(canonicalizer, true).apply(graph, context); |
91 debug.handle(t); |
91 debug.handle(t); |
92 } |
92 } |
93 assertEquals(referenceGraph, graph); |
93 assertEquals(referenceGraph, graph); |
94 } |
94 } |
95 |
95 |
96 protected void prepareGraph(StructuredGraph graph, CanonicalizerPhase canonicalizer, PhaseContext context, boolean applyLowering) { |
96 protected void prepareGraph(StructuredGraph graph, CanonicalizerPhase canonicalizer, CoreProviders context, boolean applyLowering) { |
97 if (applyLowering) { |
97 if (applyLowering) { |
98 new ConvertDeoptimizeToGuardPhase().apply(graph, context); |
98 new ConvertDeoptimizeToGuardPhase().apply(graph, context); |
99 new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context); |
99 new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context); |
100 canonicalizer.apply(graph, context); |
100 canonicalizer.apply(graph, context); |
101 } |
101 } |
103 new ConvertDeoptimizeToGuardPhase().apply(graph, context); |
103 new ConvertDeoptimizeToGuardPhase().apply(graph, context); |
104 } |
104 } |
105 |
105 |
106 public void testProxies(String snippet, int expectedProxiesCreated) { |
106 public void testProxies(String snippet, int expectedProxiesCreated) { |
107 StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES); |
107 StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES); |
108 PhaseContext context = new PhaseContext(getProviders()); |
108 CoreProviders context = getProviders(); |
109 CanonicalizerPhase canonicalizer1 = new CanonicalizerPhase(); |
109 CanonicalizerPhase canonicalizer1 = new CanonicalizerPhase(); |
110 canonicalizer1.disableSimplification(); |
110 canonicalizer1.disableSimplification(); |
111 canonicalizer1.apply(graph, context); |
111 canonicalizer1.apply(graph, context); |
112 CanonicalizerPhase canonicalizer = new CanonicalizerPhase(); |
112 CanonicalizerPhase canonicalizer = new CanonicalizerPhase(); |
113 new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context); |
113 new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context); |