7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package org.graalvm.compiler.core.test;
24
25 import jdk.vm.ci.meta.JavaConstant;
26
27 import static org.graalvm.compiler.core.common.CompilationIdentifier.INVALID_COMPILATION_ID;
28
29 import org.junit.Assert;
30 import org.junit.Test;
31
32 import org.graalvm.compiler.nodes.ConstantNode;
33 import org.graalvm.compiler.nodes.ReturnNode;
34 import org.graalvm.compiler.nodes.StructuredGraph;
35 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
36 import org.graalvm.compiler.nodes.ValueNode;
37 import org.graalvm.compiler.nodes.calc.AddNode;
38 import org.graalvm.compiler.nodes.debug.OpaqueNode;
39 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
40 import org.graalvm.compiler.phases.schedule.SchedulePhase;
41 import org.graalvm.compiler.phases.schedule.SchedulePhase.SchedulingStrategy;
42 import org.graalvm.compiler.phases.tiers.HighTierContext;
43
44 public class LongNodeChainTest extends GraalCompilerTest {
45
46 public static final int N = 10000;
47
48 private static final SchedulingStrategy[] Strategies = new SchedulingStrategy[]{SchedulingStrategy.EARLIEST};
49
50 @Test
51 public void testLongAddChain() {
52 longAddChain(true);
53 longAddChain(false);
54 }
55
56 private void longAddChain(boolean reverse) {
57 HighTierContext context = getDefaultHighTierContext();
58 StructuredGraph graph = new StructuredGraph(AllowAssumptions.NO, INVALID_COMPILATION_ID);
59 ValueNode constant = graph.unique(ConstantNode.forPrimitive(JavaConstant.INT_1));
60 ValueNode value = null;
61 if (reverse) {
62 // Make sure the constant's stamp is not used to infer the add node's stamp.
63 OpaqueNode opaque = graph.unique(new OpaqueNode(constant));
64 constant = opaque;
65 AddNode addNode = graph.unique(new AddNode(constant, constant));
66 value = addNode;
67 for (int i = 1; i < N; ++i) {
68 AddNode newAddNode = graph.addWithoutUnique(new AddNode(constant, constant));
69 addNode.setY(newAddNode);
70 addNode = newAddNode;
71 }
72 opaque.replaceAndDelete(opaque.getValue());
73 } else {
74 value = constant;
75 for (int i = 0; i < N; ++i) {
76 value = graph.unique(new AddNode(constant, value));
77 }
78 }
|
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package org.graalvm.compiler.core.test;
24
25 import jdk.vm.ci.meta.JavaConstant;
26
27 import org.junit.Assert;
28 import org.junit.Test;
29
30 import org.graalvm.compiler.nodes.ConstantNode;
31 import org.graalvm.compiler.nodes.ReturnNode;
32 import org.graalvm.compiler.nodes.StructuredGraph;
33 import org.graalvm.compiler.nodes.ValueNode;
34 import org.graalvm.compiler.nodes.calc.AddNode;
35 import org.graalvm.compiler.nodes.debug.OpaqueNode;
36 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
37 import org.graalvm.compiler.phases.schedule.SchedulePhase;
38 import org.graalvm.compiler.phases.schedule.SchedulePhase.SchedulingStrategy;
39 import org.graalvm.compiler.phases.tiers.HighTierContext;
40
41 public class LongNodeChainTest extends GraalCompilerTest {
42
43 public static final int N = 10000;
44
45 private static final SchedulingStrategy[] Strategies = new SchedulingStrategy[]{SchedulingStrategy.EARLIEST};
46
47 @Test
48 public void testLongAddChain() {
49 longAddChain(true);
50 longAddChain(false);
51 }
52
53 private void longAddChain(boolean reverse) {
54 HighTierContext context = getDefaultHighTierContext();
55 StructuredGraph graph = new StructuredGraph.Builder(getInitialOptions()).build();
56 ValueNode constant = graph.unique(ConstantNode.forPrimitive(JavaConstant.INT_1));
57 ValueNode value = null;
58 if (reverse) {
59 // Make sure the constant's stamp is not used to infer the add node's stamp.
60 OpaqueNode opaque = graph.unique(new OpaqueNode(constant));
61 constant = opaque;
62 AddNode addNode = graph.unique(new AddNode(constant, constant));
63 value = addNode;
64 for (int i = 1; i < N; ++i) {
65 AddNode newAddNode = graph.addWithoutUnique(new AddNode(constant, constant));
66 addNode.setY(newAddNode);
67 addNode = newAddNode;
68 }
69 opaque.replaceAndDelete(opaque.getValue());
70 } else {
71 value = constant;
72 for (int i = 0; i < N; ++i) {
73 value = graph.unique(new AddNode(constant, value));
74 }
75 }
|