Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1 | /* |
Roland Levillain | 6a92a03 | 2015-07-23 12:15:01 +0100 | [diff] [blame^] | 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 | */ |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 16 | |
| 17 | public class Main { |
| 18 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 19 | /// CHECK-START: int Main.inlineIfThenElse() inliner (before) |
| 20 | /// CHECK-DAG: <<Invoke:i\d+>> InvokeStaticOrDirect |
| 21 | /// CHECK-DAG: Return [<<Invoke>>] |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 22 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 23 | /// CHECK-START: int Main.inlineIfThenElse() inliner (after) |
| 24 | /// CHECK-NOT: InvokeStaticOrDirect |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 25 | |
| 26 | public static int inlineIfThenElse() { |
| 27 | return foo(true); |
| 28 | } |
| 29 | |
| 30 | private static int foo(boolean value) { |
| 31 | if (value) { |
| 32 | return 1; |
| 33 | } else { |
| 34 | return 0; |
| 35 | } |
| 36 | } |
| 37 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 38 | /// CHECK-START: int Main.inlineInLoop() inliner (before) |
| 39 | /// CHECK-DAG: InvokeStaticOrDirect |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 40 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 41 | /// CHECK-START: int Main.inlineInLoop() inliner (after) |
| 42 | /// CHECK-NOT: InvokeStaticOrDirect |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 43 | |
| 44 | public static int inlineInLoop() { |
| 45 | int result = 0; |
| 46 | for (int i = 0; i < 32; ++i) { |
| 47 | result += foo(i % 2 == 0); |
| 48 | } |
| 49 | return result; |
| 50 | } |
| 51 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 52 | /// CHECK-START: int Main.inlineInLoopHeader() inliner (before) |
| 53 | /// CHECK-DAG: InvokeStaticOrDirect |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 54 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 55 | /// CHECK-START: int Main.inlineInLoopHeader() inliner (after) |
| 56 | /// CHECK-NOT: InvokeStaticOrDirect |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 57 | |
| 58 | public static int inlineInLoopHeader() { |
| 59 | int result = 0; |
| 60 | for (int i = 0; i < foo(i % 2 == 0); ++i) { |
| 61 | result += 42; |
| 62 | } |
| 63 | return result; |
| 64 | } |
| 65 | |
| 66 | public static void main(String[] args) { |
| 67 | if (inlineIfThenElse() != 1) { |
| 68 | throw new Error("Expected 1"); |
| 69 | } |
| 70 | if (inlineInLoop() != 16) { |
| 71 | throw new Error("Expected 16"); |
| 72 | } |
| 73 | if (inlineInLoopHeader() != 42) { |
| 74 | throw new Error("Expected 16"); |
| 75 | } |
| 76 | } |
| 77 | } |