/* * Copyright (C) 2015 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { /// CHECK-START: void Main.loop1(boolean) liveness (after) /// CHECK-DAG: <> ParameterValue liveness:<> ranges:{[<>,<>)} uses:[<>] /// CHECK-DAG: If [<>] liveness:<> loop:none /// CHECK-DAG: Goto loop:B{{\d+}} /// CHECK-DAG: Exit /// CHECK-EVAL: <> + 1 == <> // // Loop invariant exit check is hoisted from the loop by peeling. public static void loop1(boolean incoming) { while (incoming) {} } /// CHECK-START: void Main.loop2(boolean) liveness (after) /// CHECK-DAG: <> ParameterValue liveness:<> ranges:{[<>,<>)} uses:[<>,<>] /// CHECK-DAG: If [<>] liveness:<> loop:<> /// CHECK-DAG: Goto liveness:<> loop:<> /// CHECK-DAG: Goto liveness:<> loop:<> /// CHECK-EVAL: <> + 1 == <> /// CHECK-EVAL: <> < <> /// CHECK-EVAL: <> + 2 == <> // // Loop invariant exit check is hoisted from the loop by peeling. public static void loop2(boolean incoming) { // Add some code at entry to avoid having the entry block be a pre header. // This avoids having to create a synthesized block. System.out.println("Enter"); while (true) { System.out.println("foo"); while (incoming) {} } } /// CHECK-START: void Main.loop3(boolean) liveness (after) /// CHECK: <> ParameterValue liveness:<> ranges:{[<>,<>)} uses:[<>,<>] /// CHECK: Goto liveness:<> /// CHECK: InvokeVirtual [{{l\d+}},<>] method_name:java.io.PrintStream.println liveness:<> /// CHECK: Goto liveness:<> /// CHECK-EVAL: <> == <> /// CHECK-EVAL: <> < <> /// CHECK-EVAL: <> + 2 == <> public static void loop3(boolean incoming) { // 'incoming' only needs a use at the outer loop's back edge. while (System.currentTimeMillis() != 42) { while (Runtime.getRuntime() != null) {} System.out.println(incoming); } } /// CHECK-START: void Main.loop4(boolean) liveness (after) /// CHECK: <> ParameterValue liveness:<> ranges:{[<>,<>)} uses:[<>] /// CHECK: InvokeVirtual [{{l\d+}},<>] method_name:java.io.PrintStream.println liveness:<> /// CHECK-EVAL: <> == <> public static void loop4(boolean incoming) { // 'incoming' has no loop use, so should not have back edge uses. System.out.println(incoming); while (System.currentTimeMillis() != 42) { while (Runtime.getRuntime() != null) {} } } /// CHECK-START: void Main.loop5(boolean) liveness (after) /// CHECK: <> ParameterValue liveness:<> ranges:{[<>,<>)} uses:[<>,<>,<>] /// CHECK: InvokeVirtual [{{l\d+}},<>] method_name:java.io.PrintStream.println liveness:<> /// CHECK: Goto liveness:<> /// CHECK: Goto liveness:<> /// CHECK: Exit /// CHECK-EVAL: <> == <> /// CHECK-EVAL: <> < <> /// CHECK-EVAL: <> + 2 == <> /// CHECK-EVAL: <> + 2 == <> public static void loop5(boolean incoming) { // 'incoming' must have a use at both back edges. for (long i = System.nanoTime(); i < 42; ++i) { for (long j = System.currentTimeMillis(); j != 42; ++j) { System.out.println(incoming); } } } /// CHECK-START: void Main.loop6(boolean) liveness (after) /// CHECK: <> ParameterValue liveness:<> ranges:{[<>,<>)} uses:[<>,<>] /// CHECK: InvokeVirtual [{{l\d+}},<>] method_name:java.io.PrintStream.println liveness:<> /// CHECK: Add /// CHECK: Goto liveness:<> /// CHECK: Add /// CHECK: Goto liveness:<> /// CHECK: Exit /// CHECK-EVAL: <> == <> /// CHECK-EVAL: <> < <> /// CHECK-EVAL: <> + 2 == <> public static void loop6(boolean incoming) { // 'incoming' must have a use only at the first loop's back edge. for (long i = System.nanoTime(); i < 42; ++i) { System.out.println(incoming); for (long j = System.currentTimeMillis(); j != 42; ++j) { System.out.print(j); // non-empty body } } } /// CHECK-START: void Main.loop7(boolean) liveness (after) /// CHECK-DAG: <> ParameterValue liveness:<> ranges:{[<>,<>)} uses:[<>,<>,<>] /// CHECK-DAG: InvokeVirtual [{{l\d+}},<>] method_name:java.io.PrintStream.println liveness:<> /// CHECK-DAG: If [<>] liveness:<> loop:<> /// CHECK-DAG: Goto liveness:<> loop:<> /// CHECK-DAG: Goto liveness:<> loop:<> /// CHECK-DAG: Exit /// CHECK-EVAL: <> == <> /// CHECK-EVAL: <> + 1 == <> /// CHECK-EVAL: <> < <> /// CHECK-EVAL: <> + 2 == <> // // Loop invariant exit check is hoisted from the loop by peeling. public static void loop7(boolean incoming) { // 'incoming' must have a use at both back edges. while (Runtime.getRuntime() != null) { System.out.println(incoming); while (incoming) {} System.nanoTime(); // beat back edge splitting } } /// CHECK-START: void Main.loop8() liveness (after) /// CHECK-DAG: <> StaticFieldGet liveness:<> ranges:{[<>,<>)} uses:[<>,<>] /// CHECK-DAG: If [<>] liveness:<> loop:<> /// CHECK-DAG: Goto liveness:<> loop:<> /// CHECK-DAG: Goto liveness:<> loop:<> /// CHECK-DAG: Exit /// CHECK-EVAL: <> + 1 == <> /// CHECK-EVAL: <> < <> /// CHECK-EVAL: <> + 2 == <> // // Loop invariant exit check is hoisted from the loop by peeling. public static void loop8() { // 'incoming' must have a use at both back edges. boolean incoming = field; while (Runtime.getRuntime() != null) { System.nanoTime(); // beat pre-header creation while (incoming) {} System.nanoTime(); // beat back edge splitting } } static boolean $opt$noinline$ensureSideEffects() { if (doThrow) throw new Error(""); return true; } /// CHECK-START: void Main.loop9() liveness (after) /// CHECK-DAG: <> StaticFieldGet liveness:<> ranges:{[<>,<>)} uses:[<>] /// CHECK-DAG: If [<>] liveness:<> loop:<> /// CHECK-DAG: Goto liveness:<> loop:<> /// CHECK-DAG: Goto liveness:<> loop:<> /// CHECK-DAG: Exit /// CHECK-EVAL: <> + 1 == <> /// CHECK-EVAL: <> < <> // // Loop invariant exit check is hoisted from the loop by peeling. public static void loop9() { // Add some code at entry to avoid having the entry block be a pre header. // This avoids having to create a synthesized block. System.out.println("Enter"); while ($opt$noinline$ensureSideEffects()) { // 'incoming' must only have a use in the inner loop. boolean incoming = field; while (incoming) {} } } public static void main(String[] args) { } static boolean field; static boolean doThrow = false; }