blob: 6b4da9de276f60b115ccc6803524b3b6997a4db4 [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) {
43 while (true) {
44 System.out.println("foo");
45 while (incoming) {}
46 }
47 }
48
David Brazdila06d66a2015-05-28 11:14:54 +010049 /// CHECK-START: void Main.loop3(boolean) liveness (after)
David Brazdil29c86802015-09-23 11:24:56 +010050 /// CHECK: <<Arg:z\d+>> ParameterValue liveness:<<ArgLiv:\d+>> ranges:{[<<ArgLiv>>,<<ArgLoopUse:\d+>>)} uses:[<<ArgUse:\d+>>,<<ArgLoopUse>>]
51 /// CHECK: Goto liveness:<<GotoLiv1:\d+>>
52 /// CHECK: InvokeVirtual [{{l\d+}},<<Arg>>] method_name:java.io.PrintStream.println liveness:<<InvokeLiv:\d+>>
53 /// CHECK: Goto liveness:<<GotoLiv2:\d+>>
54 /// CHECK-EVAL: <<InvokeLiv>> == <<ArgUse>>
55 /// CHECK-EVAL: <<GotoLiv1>> < <<GotoLiv2>>
56 /// CHECK-EVAL: <<GotoLiv2>> + 2 == <<ArgLoopUse>>
Nicolas Geoffray57902602015-04-21 14:28:41 +010057
Nicolas Geoffray57902602015-04-21 14:28:41 +010058 public static void loop3(boolean incoming) {
59 // 'incoming' only needs a use at the outer loop's back edge.
60 while (System.currentTimeMillis() != 42) {
61 while (Runtime.getRuntime() != null) {}
62 System.out.println(incoming);
63 }
64 }
65
David Brazdil29c86802015-09-23 11:24:56 +010066 /// CHECK-START: void Main.loop4(boolean) liveness (after)
67 /// CHECK: <<Arg:z\d+>> ParameterValue liveness:<<ArgLiv:\d+>> ranges:{[<<ArgLiv>>,<<ArgUse:\d+>>)} uses:[<<ArgUse>>]
68 /// CHECK: InvokeVirtual [{{l\d+}},<<Arg>>] method_name:java.io.PrintStream.println liveness:<<InvokeLiv:\d+>>
69 /// CHECK-EVAL: <<InvokeLiv>> == <<ArgUse>>
Nicolas Geoffray57902602015-04-21 14:28:41 +010070
Nicolas Geoffray57902602015-04-21 14:28:41 +010071 public static void loop4(boolean incoming) {
72 // 'incoming' has no loop use, so should not have back edge uses.
73 System.out.println(incoming);
74 while (System.currentTimeMillis() != 42) {
75 while (Runtime.getRuntime() != null) {}
76 }
77 }
78
David Brazdila06d66a2015-05-28 11:14:54 +010079 /// CHECK-START: void Main.loop5(boolean) liveness (after)
David Brazdil29c86802015-09-23 11:24:56 +010080 /// CHECK: <<Arg:z\d+>> ParameterValue liveness:<<ArgLiv:\d+>> ranges:{[<<ArgLiv>>,<<ArgLoopUse2:\d+>>)} uses:[<<ArgUse:\d+>>,<<ArgLoopUse1:\d+>>,<<ArgLoopUse2>>]
81 /// CHECK: InvokeVirtual [{{l\d+}},<<Arg>>] method_name:java.io.PrintStream.println liveness:<<InvokeLiv:\d+>>
82 /// CHECK: Goto liveness:<<GotoLiv1:\d+>>
83 /// CHECK: Goto liveness:<<GotoLiv2:\d+>>
84 /// CHECK: Exit
85 /// CHECK-EVAL: <<InvokeLiv>> == <<ArgUse>>
86 /// CHECK-EVAL: <<GotoLiv1>> < <<GotoLiv2>>
87 /// CHECK-EVAL: <<GotoLiv1>> + 2 == <<ArgLoopUse1>>
88 /// CHECK-EVAL: <<GotoLiv2>> + 2 == <<ArgLoopUse2>>
89
Nicolas Geoffray57902602015-04-21 14:28:41 +010090 public static void loop5(boolean incoming) {
91 // 'incoming' must have a use at both back edges.
David Brazdil29c86802015-09-23 11:24:56 +010092 for (long i = System.nanoTime(); i < 42; ++i) {
93 for (long j = System.currentTimeMillis(); j != 42; ++j) {
Nicolas Geoffray57902602015-04-21 14:28:41 +010094 System.out.println(incoming);
95 }
96 }
97 }
98
David Brazdila06d66a2015-05-28 11:14:54 +010099 /// CHECK-START: void Main.loop6(boolean) liveness (after)
David Brazdil29c86802015-09-23 11:24:56 +0100100 /// CHECK: <<Arg:z\d+>> ParameterValue liveness:<<ArgLiv:\d+>> ranges:{[<<ArgLiv>>,<<ArgLoopUse:\d+>>)} uses:[<<ArgUse:\d+>>,<<ArgLoopUse>>]
101 /// CHECK: InvokeVirtual [{{l\d+}},<<Arg>>] method_name:java.io.PrintStream.println liveness:<<InvokeLiv:\d+>>
102 /// CHECK: Add
103 /// CHECK: Goto liveness:<<GotoLiv1:\d+>>
104 /// CHECK: Add
105 /// CHECK: Goto liveness:<<GotoLiv2:\d+>>
106 /// CHECK: Exit
107 /// CHECK-EVAL: <<InvokeLiv>> == <<ArgUse>>
108 /// CHECK-EVAL: <<GotoLiv1>> < <<GotoLiv2>>
109 /// CHECK-EVAL: <<GotoLiv2>> + 2 == <<ArgLoopUse>>
Nicolas Geoffray57902602015-04-21 14:28:41 +0100110
Nicolas Geoffray57902602015-04-21 14:28:41 +0100111 public static void loop6(boolean incoming) {
112 // 'incoming' must have a use only at the first loop's back edge.
David Brazdil29c86802015-09-23 11:24:56 +0100113 for (long i = System.nanoTime(); i < 42; ++i) {
Nicolas Geoffray57902602015-04-21 14:28:41 +0100114 System.out.println(incoming);
David Brazdil29c86802015-09-23 11:24:56 +0100115 for (long j = System.currentTimeMillis(); j != 42; ++j) {}
Nicolas Geoffray57902602015-04-21 14:28:41 +0100116 }
117 }
118
David Brazdila06d66a2015-05-28 11:14:54 +0100119 /// CHECK-START: void Main.loop7(boolean) liveness (after)
David Brazdil29c86802015-09-23 11:24:56 +0100120 /// CHECK: <<Arg:z\d+>> ParameterValue liveness:<<ArgLiv:\d+>> ranges:{[<<ArgLiv>>,<<ArgLoopUse2:\d+>>)} uses:[<<ArgUse1:\d+>>,<<ArgUse2:\d+>>,<<ArgLoopUse1:\d+>>,<<ArgLoopUse2>>]
121 /// CHECK: InvokeVirtual [{{l\d+}},<<Arg>>] method_name:java.io.PrintStream.println liveness:<<InvokeLiv:\d+>>
122 /// CHECK: If [<<Arg>>] liveness:<<IfLiv:\d+>>
123 /// CHECK: Goto liveness:<<GotoLiv1:\d+>>
124 /// CHECK: Goto liveness:<<GotoLiv2:\d+>>
125 /// CHECK: Exit
126 /// CHECK-EVAL: <<InvokeLiv>> == <<ArgUse1>>
127 /// CHECK-EVAL: <<IfLiv>> + 1 == <<ArgUse2>>
128 /// CHECK-EVAL: <<GotoLiv1>> < <<GotoLiv2>>
129 /// CHECK-EVAL: <<GotoLiv1>> + 2 == <<ArgLoopUse1>>
130 /// CHECK-EVAL: <<GotoLiv2>> + 2 == <<ArgLoopUse2>>
131
Nicolas Geoffray57902602015-04-21 14:28:41 +0100132 public static void loop7(boolean incoming) {
133 // 'incoming' must have a use at both back edges.
134 while (Runtime.getRuntime() != null) {
135 System.out.println(incoming);
136 while (incoming) {}
David Brazdil29c86802015-09-23 11:24:56 +0100137 System.nanoTime(); // beat back edge splitting
Nicolas Geoffray57902602015-04-21 14:28:41 +0100138 }
139 }
140
David Brazdila06d66a2015-05-28 11:14:54 +0100141 /// CHECK-START: void Main.loop8() liveness (after)
David Brazdil29c86802015-09-23 11:24:56 +0100142 /// CHECK: <<Arg:z\d+>> StaticFieldGet liveness:<<ArgLiv:\d+>> ranges:{[<<ArgLiv>>,<<ArgLoopUse2:\d+>>)} uses:[<<ArgUse:\d+>>,<<ArgLoopUse1:\d+>>,<<ArgLoopUse2>>]
143 /// CHECK: If [<<Arg>>] liveness:<<IfLiv:\d+>>
144 /// CHECK: Goto liveness:<<GotoLiv1:\d+>>
145 /// CHECK: Goto liveness:<<GotoLiv2:\d+>>
146 /// CHECK: Exit
147 /// CHECK-EVAL: <<IfLiv>> + 1 == <<ArgUse>>
148 /// CHECK-EVAL: <<GotoLiv1>> < <<GotoLiv2>>
149 /// CHECK-EVAL: <<GotoLiv1>> + 2 == <<ArgLoopUse1>>
150 /// CHECK-EVAL: <<GotoLiv2>> + 2 == <<ArgLoopUse2>>
151
Nicolas Geoffray57902602015-04-21 14:28:41 +0100152 public static void loop8() {
153 // 'incoming' must have a use at both back edges.
154 boolean incoming = field;
155 while (Runtime.getRuntime() != null) {
David Brazdil29c86802015-09-23 11:24:56 +0100156 System.nanoTime(); // beat pre-header creation
Nicolas Geoffray57902602015-04-21 14:28:41 +0100157 while (incoming) {}
David Brazdil29c86802015-09-23 11:24:56 +0100158 System.nanoTime(); // beat back edge splitting
Nicolas Geoffray57902602015-04-21 14:28:41 +0100159 }
160 }
161
David Brazdila06d66a2015-05-28 11:14:54 +0100162 /// CHECK-START: void Main.loop9() liveness (after)
David Brazdil29c86802015-09-23 11:24:56 +0100163 /// CHECK: <<Arg:z\d+>> StaticFieldGet liveness:<<ArgLiv:\d+>> ranges:{[<<ArgLiv>>,<<ArgLoopUse:\d+>>)} uses:[<<ArgUse:\d+>>,<<ArgLoopUse>>]
164 /// CHECK: If [<<Arg>>] liveness:<<IfLiv:\d+>>
165 /// CHECK: Goto liveness:<<GotoLiv1:\d+>>
166 /// CHECK: Goto liveness:<<GotoLiv2:\d+>>
167 /// CHECK: Exit
168 /// CHECK-EVAL: <<IfLiv>> + 1 == <<ArgUse>>
169 /// CHECK-EVAL: <<GotoLiv1>> < <<GotoLiv2>>
170 /// CHECK-EVAL: <<GotoLiv1>> + 2 == <<ArgLoopUse>>
171
Nicolas Geoffray57902602015-04-21 14:28:41 +0100172 public static void loop9() {
173 while (Runtime.getRuntime() != null) {
174 // 'incoming' must only have a use in the inner loop.
175 boolean incoming = field;
176 while (incoming) {}
177 }
178 }
179
180 public static void main(String[] args) {
181 }
182
183 static boolean field;
184}