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)
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 
inlineLoop()30   public static int inlineLoop() {
31     return $inline$loopMethod();
32   }
33 
34   /// CHECK-START: void Main.inlineWithinLoop() inliner (before)
35   /// CHECK:      InvokeStaticOrDirect
36 
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 
inlineWithinLoop()41   public static void inlineWithinLoop() {
42     while (doLoop) {
43       $inline$loopMethod();
44     }
45   }
46 
$inline$loopMethod()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) {}
51     return 42;
52   }
53 
54   public static boolean doLoop = false;
55   public static boolean otherDoLoop = false;
56 
main(String[] args)57   public static void main(String[] args) {
58     inlineLoop();
59     inlineWithinLoop();
60   }
61 }
62