Nicolas Geoffray | 788f2f0 | 2016-01-22 12:41:38 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | */ |
| 16 | |
| 17 | public class Main { |
| 18 | |
| 19 | /// CHECK-START: int Main.inlineLoop() inliner (before) |
| 20 | /// CHECK-DAG: <<Invoke:i\d+>> InvokeStaticOrDirect |
| 21 | /// CHECK-DAG: Return [<<Invoke>>] |
| 22 | |
| 23 | /// CHECK-START: int Main.inlineLoop() inliner (after) |
Nicolas Geoffray | 788f2f0 | 2016-01-22 12:41:38 +0000 | [diff] [blame] | 24 | /// CHECK-DAG: <<Constant:i\d+>> IntConstant 42 |
| 25 | /// CHECK-DAG: Return [<<Constant>>] |
| 26 | |
| 27 | /// CHECK-START: int Main.inlineLoop() licm (after) |
| 28 | /// CHECK: Goto loop:{{B\d+}} |
| 29 | |
| 30 | public static int inlineLoop() { |
Santiago Aboy Solanes | 8c3b58a | 2022-08-15 13:21:59 +0000 | [diff] [blame] | 31 | return $inline$loopMethod(); |
Nicolas Geoffray | 788f2f0 | 2016-01-22 12:41:38 +0000 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | /// CHECK-START: void Main.inlineWithinLoop() inliner (before) |
| 35 | /// CHECK: InvokeStaticOrDirect |
| 36 | |
Nicolas Geoffray | 788f2f0 | 2016-01-22 12:41:38 +0000 | [diff] [blame] | 37 | /// CHECK-START: void Main.inlineWithinLoop() licm (after) |
| 38 | /// CHECK-DAG: Goto loop:<<OuterLoop:B\d+>> outer_loop:none |
| 39 | /// CHECK-DAG: Goto outer_loop:<<OuterLoop>> |
| 40 | |
| 41 | public static void inlineWithinLoop() { |
| 42 | while (doLoop) { |
Santiago Aboy Solanes | 8c3b58a | 2022-08-15 13:21:59 +0000 | [diff] [blame] | 43 | $inline$loopMethod(); |
Nicolas Geoffray | 788f2f0 | 2016-01-22 12:41:38 +0000 | [diff] [blame] | 44 | } |
| 45 | } |
| 46 | |
Santiago Aboy Solanes | 8c3b58a | 2022-08-15 13:21:59 +0000 | [diff] [blame] | 47 | public static int $inline$loopMethod() { |
| 48 | // We use `otherDoLoop` here so we don't propagate the knowledge that `doLoop` is true when |
| 49 | // inlining from `inlineWithinLoop`. |
| 50 | while (otherDoLoop) {} |
Nicolas Geoffray | 788f2f0 | 2016-01-22 12:41:38 +0000 | [diff] [blame] | 51 | return 42; |
| 52 | } |
| 53 | |
| 54 | public static boolean doLoop = false; |
Santiago Aboy Solanes | 8c3b58a | 2022-08-15 13:21:59 +0000 | [diff] [blame] | 55 | public static boolean otherDoLoop = false; |
Nicolas Geoffray | 788f2f0 | 2016-01-22 12:41:38 +0000 | [diff] [blame] | 56 | |
| 57 | public static void main(String[] args) { |
| 58 | inlineLoop(); |
| 59 | inlineWithinLoop(); |
| 60 | } |
| 61 | } |