Nicolas Geoffray | ef87c5d | 2015-01-30 12:41:14 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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.inlineInstanceCall(Main) inliner (before) |
David Brazdil | c2c48ff | 2015-05-15 14:24:31 +0100 | [diff] [blame] | 20 | // CHECK-DAG: <<Invoke:i\d+>> InvokeStaticOrDirect |
David Brazdil | c57397b | 2015-05-15 16:01:59 +0100 | [diff] [blame] | 21 | // CHECK-DAG: Return [<<Invoke>>] |
Nicolas Geoffray | ef87c5d | 2015-01-30 12:41:14 +0000 | [diff] [blame] | 22 | |
| 23 | // CHECK-START: int Main.inlineInstanceCall(Main) inliner (after) |
| 24 | // CHECK-NOT: InvokeStaticOrDirect |
| 25 | |
| 26 | // CHECK-START: int Main.inlineInstanceCall(Main) inliner (after) |
David Brazdil | c2c48ff | 2015-05-15 14:24:31 +0100 | [diff] [blame] | 27 | // CHECK-DAG: <<Field:i\d+>> InstanceFieldGet |
David Brazdil | c57397b | 2015-05-15 16:01:59 +0100 | [diff] [blame] | 28 | // CHECK-DAG: Return [<<Field>>] |
Nicolas Geoffray | ef87c5d | 2015-01-30 12:41:14 +0000 | [diff] [blame] | 29 | |
| 30 | public static int inlineInstanceCall(Main m) { |
| 31 | return m.foo(); |
| 32 | } |
| 33 | |
| 34 | private int foo() { |
| 35 | return field; |
| 36 | } |
| 37 | |
| 38 | int field = 42; |
| 39 | |
| 40 | // CHECK-START: int Main.inlineNestedCall() inliner (before) |
David Brazdil | c2c48ff | 2015-05-15 14:24:31 +0100 | [diff] [blame] | 41 | // CHECK-DAG: <<Invoke:i\d+>> InvokeStaticOrDirect |
David Brazdil | c57397b | 2015-05-15 16:01:59 +0100 | [diff] [blame] | 42 | // CHECK-DAG: Return [<<Invoke>>] |
Nicolas Geoffray | ef87c5d | 2015-01-30 12:41:14 +0000 | [diff] [blame] | 43 | |
| 44 | // CHECK-START: int Main.inlineNestedCall() inliner (after) |
| 45 | // CHECK-NOT: InvokeStaticOrDirect |
| 46 | |
| 47 | // CHECK-START: int Main.inlineNestedCall() inliner (after) |
David Brazdil | c2c48ff | 2015-05-15 14:24:31 +0100 | [diff] [blame] | 48 | // CHECK-DAG: <<Const38:i\d+>> IntConstant 38 |
David Brazdil | c57397b | 2015-05-15 16:01:59 +0100 | [diff] [blame] | 49 | // CHECK-DAG: Return [<<Const38>>] |
Nicolas Geoffray | ef87c5d | 2015-01-30 12:41:14 +0000 | [diff] [blame] | 50 | |
| 51 | public static int inlineNestedCall() { |
| 52 | return nestedCall(); |
| 53 | } |
| 54 | |
| 55 | public static int nestedCall() { |
| 56 | return bar(); |
| 57 | } |
| 58 | |
| 59 | public static int bar() { |
| 60 | return 38; |
| 61 | } |
| 62 | |
| 63 | public static void main(String[] args) { |
| 64 | if (inlineInstanceCall(new Main()) != 42) { |
| 65 | throw new Error("Expected 42"); |
| 66 | } |
| 67 | |
| 68 | if (inlineNestedCall() != 38) { |
| 69 | throw new Error("Expected 38"); |
| 70 | } |
| 71 | } |
| 72 | } |