blob: 41eca3531dc467cbd0bd3af444614cd59a4f7cf6 [file] [log] [blame]
Nicolas Geoffray788f2f02016-01-22 12:41:38 +00001/*
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
17public 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 Geoffray788f2f02016-01-22 12:41:38 +000024 /// 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 Solanes8c3b58a2022-08-15 13:21:59 +000031 return $inline$loopMethod();
Nicolas Geoffray788f2f02016-01-22 12:41:38 +000032 }
33
34 /// CHECK-START: void Main.inlineWithinLoop() inliner (before)
35 /// CHECK: InvokeStaticOrDirect
36
Nicolas Geoffray788f2f02016-01-22 12:41:38 +000037 /// 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 Solanes8c3b58a2022-08-15 13:21:59 +000043 $inline$loopMethod();
Nicolas Geoffray788f2f02016-01-22 12:41:38 +000044 }
45 }
46
Santiago Aboy Solanes8c3b58a2022-08-15 13:21:59 +000047 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 Geoffray788f2f02016-01-22 12:41:38 +000051 return 42;
52 }
53
54 public static boolean doLoop = false;
Santiago Aboy Solanes8c3b58a2022-08-15 13:21:59 +000055 public static boolean otherDoLoop = false;
Nicolas Geoffray788f2f02016-01-22 12:41:38 +000056
57 public static void main(String[] args) {
58 inlineLoop();
59 inlineWithinLoop();
60 }
61}