annotate graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/CountedLoopTest.java @ 22054:0e095e2c24e2

Rename com.oracle.jvmci to jdk.internal.jvmci
author twisti
date Mon, 22 Jun 2015 12:12:53 -0700
parents 2a7f8723d5b2
children a7bc10cc711c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21933
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
1 /*
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved.
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
4 *
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
8 *
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
13 * accompanied this code).
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
14 *
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
18 *
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
21 * questions.
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
22 */
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
23 package com.oracle.graal.compiler.test;
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
24
22054
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents: 21933
diff changeset
25 import jdk.internal.jvmci.meta.*;
0e095e2c24e2 Rename com.oracle.jvmci to jdk.internal.jvmci
twisti
parents: 21933
diff changeset
26
21933
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
27 import org.junit.*;
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
28
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
29 import com.oracle.graal.api.directives.*;
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
30 import com.oracle.graal.graph.*;
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
31 import com.oracle.graal.graphbuilderconf.GraphBuilderConfiguration.Plugins;
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
32 import com.oracle.graal.graphbuilderconf.*;
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
33 import com.oracle.graal.graphbuilderconf.InvocationPlugins.Registration;
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
34 import com.oracle.graal.loop.*;
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
35 import com.oracle.graal.nodeinfo.*;
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
36 import com.oracle.graal.nodes.*;
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
37 import com.oracle.graal.nodes.calc.*;
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
38 import com.oracle.graal.nodes.spi.*;
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
39
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
40 public class CountedLoopTest extends GraalCompilerTest {
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
41
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
42 @FunctionalInterface
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
43 private interface IVProperty {
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
44 ValueNode get(InductionVariable iv);
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
45 }
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
46
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
47 /**
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
48 * Get a property of an induction variable.
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
49 *
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
50 * @param property
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
51 */
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
52 private static int get(IVProperty property, int iv) {
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
53 return iv;
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
54 }
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
55
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
56 private static class Result {
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
57 public int extremum;
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
58 public int exitValue;
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
59
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
60 @Override
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
61 public int hashCode() {
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
62 final int prime = 31;
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
63 int result = 1;
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
64 result = prime * result + exitValue;
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
65 result = prime * result + extremum;
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
66 return result;
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
67 }
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
68
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
69 @Override
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
70 public boolean equals(Object obj) {
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
71 if (!(obj instanceof Result)) {
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
72 return false;
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
73 }
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
74 Result other = (Result) obj;
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
75 return extremum == other.extremum && exitValue == other.exitValue;
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
76 }
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
77
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
78 @Override
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
79 public String toString() {
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
80 return String.format("extremum = %d, exitValue = %d", extremum, exitValue);
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
81 }
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
82 }
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
83
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
84 public static Result incrementSnippet(int start, int limit, int step) {
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
85 int i;
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
86 int inc = ((step - 1) & 0xFFFF) + 1; // make sure this value is always strictly positive
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
87 Result ret = new Result();
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
88 for (i = start; i < limit; i += inc) {
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
89 GraalDirectives.controlFlowAnchor();
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
90 ret.extremum = get(InductionVariable::extremumNode, i);
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
91 }
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
92 ret.exitValue = get(InductionVariable::exitValueNode, i);
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
93 return ret;
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
94 }
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
95
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
96 @Test
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
97 public void increment1() {
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
98 test("incrementSnippet", 0, 256, 1);
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
99 }
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
100
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
101 @Test
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
102 public void increment2() {
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
103 test("incrementSnippet", 0, 256, 2);
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
104 }
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
105
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
106 @Test
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
107 public void increment3() {
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
108 test("incrementSnippet", 0, 256, 3);
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
109 }
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
110
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
111 public static Result incrementEqSnippet(int start, int limit, int step) {
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
112 int i;
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
113 int inc = ((step - 1) & 0xFFFF) + 1; // make sure this value is always strictly positive
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
114 Result ret = new Result();
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
115 for (i = start; i <= limit; i += inc) {
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
116 GraalDirectives.controlFlowAnchor();
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
117 ret.extremum = get(InductionVariable::extremumNode, i);
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
118 }
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
119 ret.exitValue = get(InductionVariable::exitValueNode, i);
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
120 return ret;
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
121 }
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
122
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
123 @Test
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
124 public void incrementEq1() {
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
125 test("incrementEqSnippet", 0, 256, 1);
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
126 }
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
127
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
128 @Test
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
129 public void incrementEq2() {
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
130 test("incrementEqSnippet", 0, 256, 2);
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
131 }
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
132
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
133 @Test
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
134 public void incrementEq3() {
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
135 test("incrementEqSnippet", 0, 256, 3);
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
136 }
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
137
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
138 public static Result decrementSnippet(int start, int limit, int step) {
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
139 int i;
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
140 int dec = ((step - 1) & 0xFFFF) + 1; // make sure this value is always strictly positive
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
141 Result ret = new Result();
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
142 for (i = start; i > limit; i -= dec) {
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
143 GraalDirectives.controlFlowAnchor();
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
144 ret.extremum = get(InductionVariable::extremumNode, i);
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
145 }
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
146 ret.exitValue = get(InductionVariable::exitValueNode, i);
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
147 return ret;
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
148 }
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
149
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
150 @Test
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
151 public void decrement1() {
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
152 test("decrementSnippet", 256, 0, 1);
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
153 }
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
154
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
155 @Test
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
156 public void decrement2() {
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
157 test("decrementSnippet", 256, 0, 2);
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
158 }
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
159
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
160 @Test
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
161 public void decrement3() {
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
162 test("decrementSnippet", 256, 0, 3);
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
163 }
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
164
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
165 public static Result decrementEqSnippet(int start, int limit, int step) {
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
166 int i;
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
167 int dec = ((step - 1) & 0xFFFF) + 1; // make sure this value is always strictly positive
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
168 Result ret = new Result();
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
169 for (i = start; i >= limit; i -= dec) {
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
170 GraalDirectives.controlFlowAnchor();
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
171 ret.extremum = get(InductionVariable::extremumNode, i);
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
172 }
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
173 ret.exitValue = get(InductionVariable::exitValueNode, i);
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
174 return ret;
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
175 }
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
176
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
177 @Test
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
178 public void decrementEq1() {
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
179 test("decrementEqSnippet", 256, 0, 1);
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
180 }
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
181
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
182 @Test
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
183 public void decrementEq2() {
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
184 test("decrementEqSnippet", 256, 0, 2);
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
185 }
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
186
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
187 @Test
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
188 public void decrementEq3() {
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
189 test("decrementEqSnippet", 256, 0, 3);
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
190 }
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
191
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
192 @NodeInfo
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
193 private static class IVPropertyNode extends FloatingNode implements LIRLowerable {
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
194
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
195 public static final NodeClass<IVPropertyNode> TYPE = NodeClass.create(IVPropertyNode.class);
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
196
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
197 private final IVProperty property;
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
198 @Input private ValueNode iv;
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
199
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
200 public IVPropertyNode(IVProperty property, ValueNode iv) {
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
201 super(TYPE, iv.stamp().unrestricted());
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
202 this.property = property;
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
203 this.iv = iv;
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
204 }
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
205
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
206 public void rewrite(LoopsData loops) {
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
207 InductionVariable inductionVariable = loops.getInductionVariable(iv);
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
208 ValueNode node = property.get(inductionVariable);
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
209 graph().replaceFloating(this, node);
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
210 }
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
211
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
212 public void generate(NodeLIRBuilderTool gen) {
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
213 gen.setResult(this, gen.operand(iv));
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
214 }
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
215
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
216 @NodeIntrinsic
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
217 public static native int get(@ConstantNodeParameter IVProperty property, int iv);
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
218 }
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
219
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
220 protected static int getIntrinsic(IVProperty property, int iv) {
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
221 return IVPropertyNode.get(property, iv);
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
222 }
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
223
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
224 @Override
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
225 protected Plugins getDefaultGraphBuilderPlugins() {
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
226 Plugins plugins = super.getDefaultGraphBuilderPlugins();
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
227 Registration r = new Registration(plugins.getInvocationPlugins(), CountedLoopTest.class);
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
228
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
229 ResolvedJavaMethod intrinsic = getResolvedJavaMethod("getIntrinsic");
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
230 r.register2("get", IVProperty.class, int.class, new InvocationPlugin() {
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
231 public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode arg1, ValueNode arg2) {
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
232 b.intrinsify(targetMethod, intrinsic, new ValueNode[]{arg1, arg2});
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
233 return true;
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
234 }
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
235 });
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
236
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
237 return plugins;
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
238 }
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
239
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
240 @Override
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
241 protected boolean checkMidTierGraph(StructuredGraph graph) {
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
242 LoopsData loops = new LoopsData(graph);
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
243 loops.detectedCountedLoops();
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
244 for (IVPropertyNode node : graph.getNodes().filter(IVPropertyNode.class)) {
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
245 node.rewrite(loops);
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
246 }
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
247 assert graph.getNodes().filter(IVPropertyNode.class).isEmpty();
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
248 return true;
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
249 }
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
250
2a7f8723d5b2 Unit tests for counted loop detection.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
251 }