Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 1 | /* |
Roland Levillain | 6a92a03 | 2015-07-23 12:15:01 +0100 | [diff] [blame] | 2 | * 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 Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 16 | |
| 17 | |
| 18 | public class Main { |
| 19 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 20 | /// CHECK-START: void Main.loop1(boolean) liveness (after) |
David Brazdil | 29c8680 | 2015-09-23 11:24:56 +0100 | [diff] [blame] | 21 | /// 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 Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 28 | public static void loop1(boolean incoming) { |
| 29 | while (incoming) {} |
| 30 | } |
| 31 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 32 | /// CHECK-START: void Main.loop2(boolean) liveness (after) |
David Brazdil | 29c8680 | 2015-09-23 11:24:56 +0100 | [diff] [blame] | 33 | /// 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 Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 42 | public static void loop2(boolean incoming) { |
Nicolas Geoffray | 788f2f0 | 2016-01-22 12:41:38 +0000 | [diff] [blame] | 43 | // 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 Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 46 | while (true) { |
| 47 | System.out.println("foo"); |
| 48 | while (incoming) {} |
| 49 | } |
| 50 | } |
| 51 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 52 | /// CHECK-START: void Main.loop3(boolean) liveness (after) |
David Brazdil | 29c8680 | 2015-09-23 11:24:56 +0100 | [diff] [blame] | 53 | /// 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 Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 60 | |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 61 | 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 Brazdil | 29c8680 | 2015-09-23 11:24:56 +0100 | [diff] [blame] | 69 | /// 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 Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 73 | |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 74 | 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 Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 82 | /// CHECK-START: void Main.loop5(boolean) liveness (after) |
David Brazdil | 29c8680 | 2015-09-23 11:24:56 +0100 | [diff] [blame] | 83 | /// 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 Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 93 | public static void loop5(boolean incoming) { |
| 94 | // 'incoming' must have a use at both back edges. |
David Brazdil | 29c8680 | 2015-09-23 11:24:56 +0100 | [diff] [blame] | 95 | for (long i = System.nanoTime(); i < 42; ++i) { |
| 96 | for (long j = System.currentTimeMillis(); j != 42; ++j) { |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 97 | System.out.println(incoming); |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 102 | /// CHECK-START: void Main.loop6(boolean) liveness (after) |
David Brazdil | 29c8680 | 2015-09-23 11:24:56 +0100 | [diff] [blame] | 103 | /// 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 Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 113 | |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 114 | public static void loop6(boolean incoming) { |
| 115 | // 'incoming' must have a use only at the first loop's back edge. |
David Brazdil | 29c8680 | 2015-09-23 11:24:56 +0100 | [diff] [blame] | 116 | for (long i = System.nanoTime(); i < 42; ++i) { |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 117 | System.out.println(incoming); |
Aart Bik | 281c681 | 2016-08-26 11:31:48 -0700 | [diff] [blame^] | 118 | for (long j = System.currentTimeMillis(); j != 42; ++j) { |
| 119 | System.out.print(j); // non-empty body |
| 120 | } |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 121 | } |
| 122 | } |
| 123 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 124 | /// CHECK-START: void Main.loop7(boolean) liveness (after) |
David Brazdil | 29c8680 | 2015-09-23 11:24:56 +0100 | [diff] [blame] | 125 | /// CHECK: <<Arg:z\d+>> ParameterValue liveness:<<ArgLiv:\d+>> ranges:{[<<ArgLiv>>,<<ArgLoopUse2:\d+>>)} uses:[<<ArgUse1:\d+>>,<<ArgUse2:\d+>>,<<ArgLoopUse1:\d+>>,<<ArgLoopUse2>>] |
| 126 | /// CHECK: InvokeVirtual [{{l\d+}},<<Arg>>] method_name:java.io.PrintStream.println liveness:<<InvokeLiv:\d+>> |
| 127 | /// CHECK: If [<<Arg>>] liveness:<<IfLiv:\d+>> |
| 128 | /// CHECK: Goto liveness:<<GotoLiv1:\d+>> |
| 129 | /// CHECK: Goto liveness:<<GotoLiv2:\d+>> |
| 130 | /// CHECK: Exit |
| 131 | /// CHECK-EVAL: <<InvokeLiv>> == <<ArgUse1>> |
| 132 | /// CHECK-EVAL: <<IfLiv>> + 1 == <<ArgUse2>> |
| 133 | /// CHECK-EVAL: <<GotoLiv1>> < <<GotoLiv2>> |
| 134 | /// CHECK-EVAL: <<GotoLiv1>> + 2 == <<ArgLoopUse1>> |
| 135 | /// CHECK-EVAL: <<GotoLiv2>> + 2 == <<ArgLoopUse2>> |
| 136 | |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 137 | public static void loop7(boolean incoming) { |
| 138 | // 'incoming' must have a use at both back edges. |
| 139 | while (Runtime.getRuntime() != null) { |
| 140 | System.out.println(incoming); |
| 141 | while (incoming) {} |
David Brazdil | 29c8680 | 2015-09-23 11:24:56 +0100 | [diff] [blame] | 142 | System.nanoTime(); // beat back edge splitting |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 143 | } |
| 144 | } |
| 145 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 146 | /// CHECK-START: void Main.loop8() liveness (after) |
David Brazdil | 29c8680 | 2015-09-23 11:24:56 +0100 | [diff] [blame] | 147 | /// CHECK: <<Arg:z\d+>> StaticFieldGet liveness:<<ArgLiv:\d+>> ranges:{[<<ArgLiv>>,<<ArgLoopUse2:\d+>>)} uses:[<<ArgUse:\d+>>,<<ArgLoopUse1:\d+>>,<<ArgLoopUse2>>] |
| 148 | /// CHECK: If [<<Arg>>] liveness:<<IfLiv:\d+>> |
| 149 | /// CHECK: Goto liveness:<<GotoLiv1:\d+>> |
| 150 | /// CHECK: Goto liveness:<<GotoLiv2:\d+>> |
| 151 | /// CHECK: Exit |
| 152 | /// CHECK-EVAL: <<IfLiv>> + 1 == <<ArgUse>> |
| 153 | /// CHECK-EVAL: <<GotoLiv1>> < <<GotoLiv2>> |
| 154 | /// CHECK-EVAL: <<GotoLiv1>> + 2 == <<ArgLoopUse1>> |
| 155 | /// CHECK-EVAL: <<GotoLiv2>> + 2 == <<ArgLoopUse2>> |
| 156 | |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 157 | public static void loop8() { |
| 158 | // 'incoming' must have a use at both back edges. |
| 159 | boolean incoming = field; |
| 160 | while (Runtime.getRuntime() != null) { |
David Brazdil | 29c8680 | 2015-09-23 11:24:56 +0100 | [diff] [blame] | 161 | System.nanoTime(); // beat pre-header creation |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 162 | while (incoming) {} |
David Brazdil | 29c8680 | 2015-09-23 11:24:56 +0100 | [diff] [blame] | 163 | System.nanoTime(); // beat back edge splitting |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 164 | } |
| 165 | } |
| 166 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 167 | /// CHECK-START: void Main.loop9() liveness (after) |
David Brazdil | 29c8680 | 2015-09-23 11:24:56 +0100 | [diff] [blame] | 168 | /// CHECK: <<Arg:z\d+>> StaticFieldGet liveness:<<ArgLiv:\d+>> ranges:{[<<ArgLiv>>,<<ArgLoopUse:\d+>>)} uses:[<<ArgUse:\d+>>,<<ArgLoopUse>>] |
| 169 | /// CHECK: If [<<Arg>>] liveness:<<IfLiv:\d+>> |
| 170 | /// CHECK: Goto liveness:<<GotoLiv1:\d+>> |
David Brazdil | 29c8680 | 2015-09-23 11:24:56 +0100 | [diff] [blame] | 171 | /// CHECK: Exit |
David Brazdil | 57e863c | 2016-01-11 10:27:13 +0000 | [diff] [blame] | 172 | /// CHECK: Goto liveness:<<GotoLiv2:\d+>> |
David Brazdil | 29c8680 | 2015-09-23 11:24:56 +0100 | [diff] [blame] | 173 | /// CHECK-EVAL: <<IfLiv>> + 1 == <<ArgUse>> |
| 174 | /// CHECK-EVAL: <<GotoLiv1>> < <<GotoLiv2>> |
| 175 | /// CHECK-EVAL: <<GotoLiv1>> + 2 == <<ArgLoopUse>> |
| 176 | |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 177 | public static void loop9() { |
Nicolas Geoffray | 788f2f0 | 2016-01-22 12:41:38 +0000 | [diff] [blame] | 178 | // Add some code at entry to avoid having the entry block be a pre header. |
| 179 | // This avoids having to create a synthesized block. |
| 180 | System.out.println("Enter"); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 181 | while (Runtime.getRuntime() != null) { |
| 182 | // 'incoming' must only have a use in the inner loop. |
| 183 | boolean incoming = field; |
| 184 | while (incoming) {} |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | public static void main(String[] args) { |
| 189 | } |
| 190 | |
| 191 | static boolean field; |
| 192 | } |