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-NOT:                      InvokeStaticOrDirect
25 
26   /// CHECK-START: int Main.inlineLoop() inliner (after)
27   /// CHECK-DAG:     <<Constant:i\d+>>   IntConstant 42
28   /// CHECK-DAG:                         Return [<<Constant>>]
29 
30   /// CHECK-START: int Main.inlineLoop() licm (after)
31   /// CHECK:                         Goto loop:{{B\d+}}
32 
inlineLoop()33   public static int inlineLoop() {
34     return loopMethod();
35   }
36 
37   /// CHECK-START: void Main.inlineWithinLoop() inliner (before)
38   /// CHECK:      InvokeStaticOrDirect
39 
40   /// CHECK-START: void Main.inlineWithinLoop() inliner (after)
41   /// CHECK-NOT:  InvokeStaticOrDirect
42 
43   /// CHECK-START: void Main.inlineWithinLoop() licm (after)
44   /// CHECK-DAG:  Goto loop:<<OuterLoop:B\d+>> outer_loop:none
45   /// CHECK-DAG:  Goto outer_loop:<<OuterLoop>>
46 
inlineWithinLoop()47   public static void inlineWithinLoop() {
48     while (doLoop) {
49       loopMethod();
50     }
51   }
52 
loopMethod()53   public static int loopMethod() {
54     while (doLoop) {}
55     return 42;
56   }
57 
58   public static boolean doLoop = false;
59 
main(String[] args)60   public static void main(String[] args) {
61     inlineLoop();
62     inlineWithinLoop();
63   }
64 }
65