blob: f8f0aa3f0abde84cea45924ee5b5ba8ac3552a22 [file] [log] [blame]
Nicolas Geoffray57902602015-04-21 14:28:41 +01001/*
Roland Levillain6a92a032015-07-23 12:15:01 +01002 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Nicolas Geoffray57902602015-04-21 14:28:41 +010016
17
18public class Main {
19
David Brazdila06d66a2015-05-28 11:14:54 +010020 /// CHECK-START: void Main.loop1(boolean) liveness (after)
David Brazdil29c86802015-09-23 11:24:56 +010021 /// CHECK: <<Arg:z\d+>> ParameterValue liveness:<<ArgLiv:\d+>> ranges:{[<<ArgLiv>>,<<ArgLoopUse:\d+>>)} uses:[<<ArgUse:\d+>>,<<ArgLoopUse>>]
22 /// CHECK: If [<<Arg>>] liveness:<<IfLiv:\d+>>
23 /// CHECK: Goto liveness:<<GotoLiv:\d+>>
24 /// CHECK: Exit
25 /// CHECK-EVAL: <<IfLiv>> + 1 == <<ArgUse>>
26 /// CHECK-EVAL: <<GotoLiv>> + 2 == <<ArgLoopUse>>
27
Nicolas Geoffray57902602015-04-21 14:28:41 +010028 public static void loop1(boolean incoming) {
29 while (incoming) {}
30 }
31
David Brazdila06d66a2015-05-28 11:14:54 +010032 /// CHECK-START: void Main.loop2(boolean) liveness (after)
David Brazdil29c86802015-09-23 11:24:56 +010033 /// CHECK: <<Arg:z\d+>> ParameterValue liveness:<<ArgLiv:\d+>> ranges:{[<<ArgLiv>>,<<ArgLoopUse2:\d+>>)} uses:[<<ArgUse:\d+>>,<<ArgLoopUse1:\d+>>,<<ArgLoopUse2>>]
34 /// CHECK: If [<<Arg>>] liveness:<<IfLiv:\d+>>
35 /// CHECK: Goto liveness:<<GotoLiv1:\d+>>
36 /// CHECK: Goto liveness:<<GotoLiv2:\d+>>
37 /// CHECK-EVAL: <<IfLiv>> + 1 == <<ArgUse>>
38 /// CHECK-EVAL: <<GotoLiv1>> < <<GotoLiv2>>
39 /// CHECK-EVAL: <<GotoLiv1>> + 2 == <<ArgLoopUse1>>
40 /// CHECK-EVAL: <<GotoLiv2>> + 2 == <<ArgLoopUse2>>
41
Nicolas Geoffray57902602015-04-21 14:28:41 +010042 public static void loop2(boolean incoming) {
Nicolas Geoffray788f2f02016-01-22 12:41:38 +000043 // Add some code at entry to avoid having the entry block be a pre header.
44 // This avoids having to create a synthesized block.
45 System.out.println("Enter");
Nicolas Geoffray57902602015-04-21 14:28:41 +010046 while (true) {
47 System.out.println("foo");
48 while (incoming) {}
49 }
50 }
51
David Brazdila06d66a2015-05-28 11:14:54 +010052 /// CHECK-START: void Main.loop3(boolean) liveness (after)
David Brazdil29c86802015-09-23 11:24:56 +010053 /// CHECK: <<Arg:z\d+>> ParameterValue liveness:<<ArgLiv:\d+>> ranges:{[<<ArgLiv>>,<<ArgLoopUse:\d+>>)} uses:[<<ArgUse:\d+>>,<<ArgLoopUse>>]
54 /// CHECK: Goto liveness:<<GotoLiv1:\d+>>
55 /// CHECK: InvokeVirtual [{{l\d+}},<<Arg>>] method_name:java.io.PrintStream.println liveness:<<InvokeLiv:\d+>>
56 /// CHECK: Goto liveness:<<GotoLiv2:\d+>>
57 /// CHECK-EVAL: <<InvokeLiv>> == <<ArgUse>>
58 /// CHECK-EVAL: <<GotoLiv1>> < <<GotoLiv2>>
59 /// CHECK-EVAL: <<GotoLiv2>> + 2 == <<ArgLoopUse>>
Nicolas Geoffray57902602015-04-21 14:28:41 +010060
Nicolas Geoffray57902602015-04-21 14:28:41 +010061 public static void loop3(boolean incoming) {
62 // 'incoming' only needs a use at the outer loop's back edge.
63 while (System.currentTimeMillis() != 42) {
64 while (Runtime.getRuntime() != null) {}
65 System.out.println(incoming);
66 }
67 }
68
David Brazdil29c86802015-09-23 11:24:56 +010069 /// CHECK-START: void Main.loop4(boolean) liveness (after)
70 /// CHECK: <<Arg:z\d+>> ParameterValue liveness:<<ArgLiv:\d+>> ranges:{[<<ArgLiv>>,<<ArgUse:\d+>>)} uses:[<<ArgUse>>]
71 /// CHECK: InvokeVirtual [{{l\d+}},<<Arg>>] method_name:java.io.PrintStream.println liveness:<<InvokeLiv:\d+>>
72 /// CHECK-EVAL: <<InvokeLiv>> == <<ArgUse>>
Nicolas Geoffray57902602015-04-21 14:28:41 +010073
Nicolas Geoffray57902602015-04-21 14:28:41 +010074 public static void loop4(boolean incoming) {
75 // 'incoming' has no loop use, so should not have back edge uses.
76 System.out.println(incoming);
77 while (System.currentTimeMillis() != 42) {
78 while (Runtime.getRuntime() != null) {}
79 }
80 }
81
David Brazdila06d66a2015-05-28 11:14:54 +010082 /// CHECK-START: void Main.loop5(boolean) liveness (after)
David Brazdil29c86802015-09-23 11:24:56 +010083 /// CHECK: <<Arg:z\d+>> ParameterValue liveness:<<ArgLiv:\d+>> ranges:{[<<ArgLiv>>,<<ArgLoopUse2:\d+>>)} uses:[<<ArgUse:\d+>>,<<ArgLoopUse1:\d+>>,<<ArgLoopUse2>>]
84 /// CHECK: InvokeVirtual [{{l\d+}},<<Arg>>] method_name:java.io.PrintStream.println liveness:<<InvokeLiv:\d+>>
85 /// CHECK: Goto liveness:<<GotoLiv1:\d+>>
86 /// CHECK: Goto liveness:<<GotoLiv2:\d+>>
87 /// CHECK: Exit
88 /// CHECK-EVAL: <<InvokeLiv>> == <<ArgUse>>
89 /// CHECK-EVAL: <<GotoLiv1>> < <<GotoLiv2>>
90 /// CHECK-EVAL: <<GotoLiv1>> + 2 == <<ArgLoopUse1>>
91 /// CHECK-EVAL: <<GotoLiv2>> + 2 == <<ArgLoopUse2>>
92
Nicolas Geoffray57902602015-04-21 14:28:41 +010093 public static void loop5(boolean incoming) {
94 // 'incoming' must have a use at both back edges.
David Brazdil29c86802015-09-23 11:24:56 +010095 for (long i = System.nanoTime(); i < 42; ++i) {
96 for (long j = System.currentTimeMillis(); j != 42; ++j) {
Nicolas Geoffray57902602015-04-21 14:28:41 +010097 System.out.println(incoming);
98 }
99 }
100 }
101
David Brazdila06d66a2015-05-28 11:14:54 +0100102 /// CHECK-START: void Main.loop6(boolean) liveness (after)
David Brazdil29c86802015-09-23 11:24:56 +0100103 /// CHECK: <<Arg:z\d+>> ParameterValue liveness:<<ArgLiv:\d+>> ranges:{[<<ArgLiv>>,<<ArgLoopUse:\d+>>)} uses:[<<ArgUse:\d+>>,<<ArgLoopUse>>]
104 /// CHECK: InvokeVirtual [{{l\d+}},<<Arg>>] method_name:java.io.PrintStream.println liveness:<<InvokeLiv:\d+>>
105 /// CHECK: Add
106 /// CHECK: Goto liveness:<<GotoLiv1:\d+>>
107 /// CHECK: Add
108 /// CHECK: Goto liveness:<<GotoLiv2:\d+>>
109 /// CHECK: Exit
110 /// CHECK-EVAL: <<InvokeLiv>> == <<ArgUse>>
111 /// CHECK-EVAL: <<GotoLiv1>> < <<GotoLiv2>>
112 /// CHECK-EVAL: <<GotoLiv2>> + 2 == <<ArgLoopUse>>
Nicolas Geoffray57902602015-04-21 14:28:41 +0100113
Nicolas Geoffray57902602015-04-21 14:28:41 +0100114 public static void loop6(boolean incoming) {
115 // 'incoming' must have a use only at the first loop's back edge.
David Brazdil29c86802015-09-23 11:24:56 +0100116 for (long i = System.nanoTime(); i < 42; ++i) {
Nicolas Geoffray57902602015-04-21 14:28:41 +0100117 System.out.println(incoming);
David Brazdil29c86802015-09-23 11:24:56 +0100118 for (long j = System.currentTimeMillis(); j != 42; ++j) {}
Nicolas Geoffray57902602015-04-21 14:28:41 +0100119 }
120 }
121
David Brazdila06d66a2015-05-28 11:14:54 +0100122 /// CHECK-START: void Main.loop7(boolean) liveness (after)
David Brazdil29c86802015-09-23 11:24:56 +0100123 /// CHECK: <<Arg:z\d+>> ParameterValue liveness:<<ArgLiv:\d+>> ranges:{[<<ArgLiv>>,<<ArgLoopUse2:\d+>>)} uses:[<<ArgUse1:\d+>>,<<ArgUse2:\d+>>,<<ArgLoopUse1:\d+>>,<<ArgLoopUse2>>]
124 /// CHECK: InvokeVirtual [{{l\d+}},<<Arg>>] method_name:java.io.PrintStream.println liveness:<<InvokeLiv:\d+>>
125 /// CHECK: If [<<Arg>>] liveness:<<IfLiv:\d+>>
126 /// CHECK: Goto liveness:<<GotoLiv1:\d+>>
127 /// CHECK: Goto liveness:<<GotoLiv2:\d+>>
128 /// CHECK: Exit
129 /// CHECK-EVAL: <<InvokeLiv>> == <<ArgUse1>>
130 /// CHECK-EVAL: <<IfLiv>> + 1 == <<ArgUse2>>
131 /// CHECK-EVAL: <<GotoLiv1>> < <<GotoLiv2>>
132 /// CHECK-EVAL: <<GotoLiv1>> + 2 == <<ArgLoopUse1>>
133 /// CHECK-EVAL: <<GotoLiv2>> + 2 == <<ArgLoopUse2>>
134
Nicolas Geoffray57902602015-04-21 14:28:41 +0100135 public static void loop7(boolean incoming) {
136 // 'incoming' must have a use at both back edges.
137 while (Runtime.getRuntime() != null) {
138 System.out.println(incoming);
139 while (incoming) {}
David Brazdil29c86802015-09-23 11:24:56 +0100140 System.nanoTime(); // beat back edge splitting
Nicolas Geoffray57902602015-04-21 14:28:41 +0100141 }
142 }
143
David Brazdila06d66a2015-05-28 11:14:54 +0100144 /// CHECK-START: void Main.loop8() liveness (after)
David Brazdil29c86802015-09-23 11:24:56 +0100145 /// CHECK: <<Arg:z\d+>> StaticFieldGet liveness:<<ArgLiv:\d+>> ranges:{[<<ArgLiv>>,<<ArgLoopUse2:\d+>>)} uses:[<<ArgUse:\d+>>,<<ArgLoopUse1:\d+>>,<<ArgLoopUse2>>]
146 /// CHECK: If [<<Arg>>] liveness:<<IfLiv:\d+>>
147 /// CHECK: Goto liveness:<<GotoLiv1:\d+>>
148 /// CHECK: Goto liveness:<<GotoLiv2:\d+>>
149 /// CHECK: Exit
150 /// CHECK-EVAL: <<IfLiv>> + 1 == <<ArgUse>>
151 /// CHECK-EVAL: <<GotoLiv1>> < <<GotoLiv2>>
152 /// CHECK-EVAL: <<GotoLiv1>> + 2 == <<ArgLoopUse1>>
153 /// CHECK-EVAL: <<GotoLiv2>> + 2 == <<ArgLoopUse2>>
154
Nicolas Geoffray57902602015-04-21 14:28:41 +0100155 public static void loop8() {
156 // 'incoming' must have a use at both back edges.
157 boolean incoming = field;
158 while (Runtime.getRuntime() != null) {
David Brazdil29c86802015-09-23 11:24:56 +0100159 System.nanoTime(); // beat pre-header creation
Nicolas Geoffray57902602015-04-21 14:28:41 +0100160 while (incoming) {}
David Brazdil29c86802015-09-23 11:24:56 +0100161 System.nanoTime(); // beat back edge splitting
Nicolas Geoffray57902602015-04-21 14:28:41 +0100162 }
163 }
164
David Brazdila06d66a2015-05-28 11:14:54 +0100165 /// CHECK-START: void Main.loop9() liveness (after)
David Brazdil29c86802015-09-23 11:24:56 +0100166 /// CHECK: <<Arg:z\d+>> StaticFieldGet liveness:<<ArgLiv:\d+>> ranges:{[<<ArgLiv>>,<<ArgLoopUse:\d+>>)} uses:[<<ArgUse:\d+>>,<<ArgLoopUse>>]
167 /// CHECK: If [<<Arg>>] liveness:<<IfLiv:\d+>>
168 /// CHECK: Goto liveness:<<GotoLiv1:\d+>>
David Brazdil29c86802015-09-23 11:24:56 +0100169 /// CHECK: Exit
David Brazdil57e863c2016-01-11 10:27:13 +0000170 /// CHECK: Goto liveness:<<GotoLiv2:\d+>>
David Brazdil29c86802015-09-23 11:24:56 +0100171 /// CHECK-EVAL: <<IfLiv>> + 1 == <<ArgUse>>
172 /// CHECK-EVAL: <<GotoLiv1>> < <<GotoLiv2>>
173 /// CHECK-EVAL: <<GotoLiv1>> + 2 == <<ArgLoopUse>>
174
Nicolas Geoffray57902602015-04-21 14:28:41 +0100175 public static void loop9() {
Nicolas Geoffray788f2f02016-01-22 12:41:38 +0000176 // Add some code at entry to avoid having the entry block be a pre header.
177 // This avoids having to create a synthesized block.
178 System.out.println("Enter");
Nicolas Geoffray57902602015-04-21 14:28:41 +0100179 while (Runtime.getRuntime() != null) {
180 // 'incoming' must only have a use in the inner loop.
181 boolean incoming = field;
182 while (incoming) {}
183 }
184 }
185
186 public static void main(String[] args) {
187 }
188
189 static boolean field;
190}