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) { |
| 43 | while (true) { |
| 44 | System.out.println("foo"); |
| 45 | while (incoming) {} |
| 46 | } |
| 47 | } |
| 48 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 49 | /// CHECK-START: void Main.loop3(boolean) liveness (after) |
David Brazdil | 29c8680 | 2015-09-23 11:24:56 +0100 | [diff] [blame] | 50 | /// 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 Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 57 | |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 58 | 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 Brazdil | 29c8680 | 2015-09-23 11:24:56 +0100 | [diff] [blame] | 66 | /// 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 Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 70 | |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 71 | 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 Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 79 | /// CHECK-START: void Main.loop5(boolean) liveness (after) |
David Brazdil | 29c8680 | 2015-09-23 11:24:56 +0100 | [diff] [blame] | 80 | /// 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 Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 90 | public static void loop5(boolean incoming) { |
| 91 | // 'incoming' must have a use at both back edges. |
David Brazdil | 29c8680 | 2015-09-23 11:24:56 +0100 | [diff] [blame] | 92 | for (long i = System.nanoTime(); i < 42; ++i) { |
| 93 | for (long j = System.currentTimeMillis(); j != 42; ++j) { |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 94 | System.out.println(incoming); |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 99 | /// CHECK-START: void Main.loop6(boolean) liveness (after) |
David Brazdil | 29c8680 | 2015-09-23 11:24:56 +0100 | [diff] [blame] | 100 | /// 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 Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 110 | |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 111 | public static void loop6(boolean incoming) { |
| 112 | // '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] | 113 | for (long i = System.nanoTime(); i < 42; ++i) { |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 114 | System.out.println(incoming); |
David Brazdil | 29c8680 | 2015-09-23 11:24:56 +0100 | [diff] [blame] | 115 | for (long j = System.currentTimeMillis(); j != 42; ++j) {} |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 116 | } |
| 117 | } |
| 118 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 119 | /// CHECK-START: void Main.loop7(boolean) liveness (after) |
David Brazdil | 29c8680 | 2015-09-23 11:24:56 +0100 | [diff] [blame] | 120 | /// 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 Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 132 | 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 Brazdil | 29c8680 | 2015-09-23 11:24:56 +0100 | [diff] [blame] | 137 | System.nanoTime(); // beat back edge splitting |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 138 | } |
| 139 | } |
| 140 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 141 | /// CHECK-START: void Main.loop8() liveness (after) |
David Brazdil | 29c8680 | 2015-09-23 11:24:56 +0100 | [diff] [blame] | 142 | /// 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 Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 152 | public static void loop8() { |
| 153 | // 'incoming' must have a use at both back edges. |
| 154 | boolean incoming = field; |
| 155 | while (Runtime.getRuntime() != null) { |
David Brazdil | 29c8680 | 2015-09-23 11:24:56 +0100 | [diff] [blame] | 156 | System.nanoTime(); // beat pre-header creation |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 157 | while (incoming) {} |
David Brazdil | 29c8680 | 2015-09-23 11:24:56 +0100 | [diff] [blame] | 158 | System.nanoTime(); // beat back edge splitting |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 159 | } |
| 160 | } |
| 161 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 162 | /// CHECK-START: void Main.loop9() liveness (after) |
David Brazdil | 29c8680 | 2015-09-23 11:24:56 +0100 | [diff] [blame] | 163 | /// 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 Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 172 | 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 | } |