1 /* |
1 /* |
2 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2018, 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. |
73 CanonicalizerPhase canonicalizerPhase = new CanonicalizerPhase(); |
73 CanonicalizerPhase canonicalizerPhase = new CanonicalizerPhase(); |
74 HighTierContext highTierContext = getDefaultHighTierContext(); |
74 HighTierContext highTierContext = getDefaultHighTierContext(); |
75 StructuredGraph graph = parseEager("snippet", StructuredGraph.AllowAssumptions.YES); |
75 StructuredGraph graph = parseEager("snippet", StructuredGraph.AllowAssumptions.YES); |
76 // there should be 1 loop and 1 switch |
76 // there should be 1 loop and 1 switch |
77 assertThat(graph.getNodes(LoopBeginNode.TYPE), hasCount(1)); |
77 assertThat(graph.getNodes(LoopBeginNode.TYPE), hasCount(1)); |
78 assertThat(graph.getNodes(IntegerSwitchNode.TYPE), hasCount(1)); |
78 assertThat(graph.getNodes().filter(IntegerSwitchNode.class), hasCount(1)); |
79 canonicalizerPhase.apply(graph, highTierContext); |
79 canonicalizerPhase.apply(graph, highTierContext); |
80 // after canonicalization, the loop and switch should still be there |
80 // after canonicalization, the loop and switch should still be there |
81 assertThat(graph.getNodes(LoopBeginNode.TYPE), hasCount(1)); |
81 assertThat(graph.getNodes(LoopBeginNode.TYPE), hasCount(1)); |
82 assertThat(graph.getNodes(IntegerSwitchNode.TYPE), hasCount(1)); |
82 assertThat(graph.getNodes().filter(IntegerSwitchNode.class), hasCount(1)); |
83 // add stamp to `a` so that paths leading to continue can be trimmed |
83 // add stamp to `a` so that paths leading to continue can be trimmed |
84 ParameterNode parameter = graph.getParameter(0); |
84 ParameterNode parameter = graph.getParameter(0); |
85 assertNotNull(parameter); |
85 assertNotNull(parameter); |
86 parameter.setStamp(StampFactory.forInteger(JavaKind.Int, 0, 255, 0, 0xf)); |
86 parameter.setStamp(StampFactory.forInteger(JavaKind.Int, 0, 255, 0, 0xf)); |
87 canonicalizerPhase.apply(graph, highTierContext); |
87 canonicalizerPhase.apply(graph, highTierContext); |
88 // the loop should have disappeared and there should still be a switch |
88 // the loop should have disappeared and there should still be a switch |
89 assertThat(graph.getNodes(LoopBeginNode.TYPE), isEmpty()); |
89 assertThat(graph.getNodes(LoopBeginNode.TYPE), isEmpty()); |
90 assertThat(graph.getNodes(IntegerSwitchNode.TYPE), hasCount(1)); |
90 assertThat(graph.getNodes().filter(IntegerSwitchNode.class), hasCount(1)); |
91 } |
91 } |
92 } |
92 } |