1 /* |
1 /* |
2 * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2011, 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. |
30 import org.graalvm.compiler.nodes.FrameState; |
30 import org.graalvm.compiler.nodes.FrameState; |
31 import org.graalvm.compiler.nodes.IfNode; |
31 import org.graalvm.compiler.nodes.IfNode; |
32 import org.graalvm.compiler.nodes.ParameterNode; |
32 import org.graalvm.compiler.nodes.ParameterNode; |
33 import org.graalvm.compiler.nodes.StructuredGraph; |
33 import org.graalvm.compiler.nodes.StructuredGraph; |
34 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions; |
34 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions; |
|
35 import org.graalvm.compiler.nodes.spi.CoreProviders; |
35 import org.graalvm.compiler.nodes.spi.LoweringTool; |
36 import org.graalvm.compiler.nodes.spi.LoweringTool; |
36 import org.graalvm.compiler.phases.OptimisticOptimizations; |
37 import org.graalvm.compiler.phases.OptimisticOptimizations; |
37 import org.graalvm.compiler.phases.common.CanonicalizerPhase; |
38 import org.graalvm.compiler.phases.common.CanonicalizerPhase; |
38 import org.graalvm.compiler.phases.common.FloatingReadPhase; |
39 import org.graalvm.compiler.phases.common.FloatingReadPhase; |
39 import org.graalvm.compiler.phases.common.GuardLoweringPhase; |
40 import org.graalvm.compiler.phases.common.GuardLoweringPhase; |
40 import org.graalvm.compiler.phases.common.LoweringPhase; |
41 import org.graalvm.compiler.phases.common.LoweringPhase; |
41 import org.graalvm.compiler.phases.tiers.MidTierContext; |
42 import org.graalvm.compiler.phases.tiers.MidTierContext; |
42 import org.graalvm.compiler.phases.tiers.PhaseContext; |
|
43 import org.junit.Test; |
43 import org.junit.Test; |
44 |
44 |
45 /** |
45 /** |
46 * In the following tests, the usages of local variable "a" are replaced with the integer constant |
46 * In the following tests, the usages of local variable "a" are replaced with the integer constant |
47 * 0. Then canonicalization is applied and it is verified that the resulting graph is equal to the |
47 * 0. Then canonicalization is applied and it is verified that the resulting graph is equal to the |
224 return (x < y) ? -1L : ((x == y) ? 0L : 1L); |
224 return (x < y) ? -1L : ((x == y) ? 0L : 1L); |
225 } |
225 } |
226 |
226 |
227 private void testCombinedIf(String snippet, int count) { |
227 private void testCombinedIf(String snippet, int count) { |
228 StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES); |
228 StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES); |
229 PhaseContext context = new PhaseContext(getProviders()); |
229 CoreProviders context = getProviders(); |
230 new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context); |
230 new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context); |
231 new FloatingReadPhase().apply(graph); |
231 new FloatingReadPhase().apply(graph); |
232 MidTierContext midContext = new MidTierContext(getProviders(), getTargetProvider(), OptimisticOptimizations.ALL, graph.getProfilingInfo()); |
232 MidTierContext midContext = new MidTierContext(getProviders(), getTargetProvider(), OptimisticOptimizations.ALL, graph.getProfilingInfo()); |
233 new GuardLoweringPhase().apply(graph, midContext); |
233 new GuardLoweringPhase().apply(graph, midContext); |
234 new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.MID_TIER).apply(graph, midContext); |
234 new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.MID_TIER).apply(graph, midContext); |
245 if (!(n instanceof FrameState)) { |
245 if (!(n instanceof FrameState)) { |
246 n.replaceFirstInput(param, constant); |
246 n.replaceFirstInput(param, constant); |
247 } |
247 } |
248 } |
248 } |
249 debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph"); |
249 debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph"); |
250 new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders())); |
250 new CanonicalizerPhase().apply(graph, getProviders()); |
251 for (FrameState fs : param.usages().filter(FrameState.class).snapshot()) { |
251 for (FrameState fs : param.usages().filter(FrameState.class).snapshot()) { |
252 fs.replaceFirstInput(param, null); |
252 fs.replaceFirstInput(param, null); |
253 param.safeDelete(); |
253 param.safeDelete(); |
254 } |
254 } |
255 StructuredGraph referenceGraph = parseEager(REFERENCE_SNIPPET, AllowAssumptions.YES); |
255 StructuredGraph referenceGraph = parseEager(REFERENCE_SNIPPET, AllowAssumptions.YES); |