1 /* 2 * Copyright (C) 2015 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 18 public class Main { 19 20 /// CHECK-START: java.lang.Object Main.boundTypeForIf(java.lang.Object) builder (after) 21 /// CHECK: BoundType boundTypeForIf(Object a)22 public static Object boundTypeForIf(Object a) { 23 if (a != null) { 24 return a.toString(); 25 } else { 26 return null; 27 } 28 } 29 30 /// CHECK-START: java.lang.Object Main.boundTypeForInstanceOf(java.lang.Object) builder (after) 31 /// CHECK: BoundType boundTypeForInstanceOf(Object a)32 public static Object boundTypeForInstanceOf(Object a) { 33 if (a instanceof Main) { 34 return (Main)a; 35 } else { 36 return null; 37 } 38 } 39 40 /// CHECK-START: java.lang.Object Main.noBoundTypeForIf(java.lang.Object) builder (after) 41 /// CHECK-NOT: BoundType noBoundTypeForIf(Object a)42 public static Object noBoundTypeForIf(Object a) { 43 if (a == null) { 44 return new Object(); 45 } else { 46 return null; 47 } 48 } 49 50 /// CHECK-START: java.lang.Object Main.noBoundTypeForInstanceOf(java.lang.Object) builder (after) 51 /// CHECK-NOT: BoundType noBoundTypeForInstanceOf(Object a)52 public static Object noBoundTypeForInstanceOf(Object a) { 53 if (a instanceof Main) { 54 return new Object(); 55 } else { 56 return null; 57 } 58 } 59 60 /// CHECK-START: void Main.boundTypeInLoop(int[]) licm (before) 61 /// CHECK-DAG: <<Param:l\d+>> ParameterValue loop:none 62 /// CHECK-DAG: <<Phi:i\d+>> Phi loop:<<Loop:B\d+>> outer_loop:none 63 /// CHECK-DAG: <<BoundT:l\d+>> BoundType [<<Param>>] loop:<<Loop>> outer_loop:none 64 /// CHECK-DAG: ArrayLength [<<BoundT>>] loop:<<Loop>> outer_loop:none 65 /// CHECK-DAG: ArrayGet loop:<<Loop>> outer_loop:none 66 /// CHECK-DAG: ArraySet loop:<<Loop>> outer_loop:none 67 68 /// CHECK-START: void Main.boundTypeInLoop(int[]) licm (after) 69 /// CHECK-DAG: <<Param:l\d+>> ParameterValue loop:none 70 /// CHECK-DAG: <<Phi:i\d+>> Phi loop:<<Loop:B\d+>> outer_loop:none 71 /// CHECK-DAG: <<BoundT:l\d+>> BoundType [<<Param>>] loop:<<Loop>> outer_loop:none 72 /// CHECK-DAG: ArrayLength [<<BoundT>>] loop:<<Loop>> outer_loop:none 73 /// CHECK-DAG: ArrayGet loop:<<Loop>> outer_loop:none 74 /// CHECK-DAG: ArraySet loop:<<Loop>> outer_loop:none 75 // 76 /// CHECK-NOT: BoundType 77 78 /// CHECK-START: void Main.boundTypeInLoop(int[]) loop_optimization (after) 79 /// CHECK-DAG: <<Param:l\d+>> ParameterValue loop:none 80 /// CHECK-DAG: <<BoundTA:l\d+>> BoundType [<<Param>>] loop:none 81 /// CHECK-DAG: ArrayLength [<<BoundTA>>] loop:none 82 /// CHECK-DAG: ArrayGet loop:none 83 /// CHECK-DAG: ArraySet loop:none 84 /// CHECK-DAG: <<Phi:i\d+>> Phi loop:<<Loop:B\d+>> outer_loop:none 85 /// CHECK-DAG: <<BoundT:l\d+>> BoundType [<<Param>>] loop:<<Loop>> outer_loop:none 86 /// CHECK-DAG: ArrayLength [<<BoundT>>] loop:<<Loop>> outer_loop:none 87 /// CHECK-DAG: ArrayGet loop:<<Loop>> outer_loop:none 88 /// CHECK-DAG: ArraySet loop:<<Loop>> outer_loop:none 89 90 /// CHECK-START: void Main.boundTypeInLoop(int[]) GVN$after_arch (after) 91 /// CHECK-DAG: <<Param:l\d+>> ParameterValue loop:none 92 /// CHECK-DAG: <<BoundTA:l\d+>> BoundType [<<Param>>] loop:none 93 /// CHECK-DAG: ArrayLength [<<BoundTA>>] loop:none 94 /// CHECK-DAG: ArrayGet loop:none 95 /// CHECK-DAG: ArraySet loop:none 96 /// CHECK-DAG: <<Phi:i\d+>> Phi loop:<<Loop:B\d+>> outer_loop:none 97 /// CHECK-DAG: ArrayGet loop:<<Loop>> outer_loop:none 98 /// CHECK-DAG: ArraySet loop:<<Loop>> outer_loop:none 99 // 100 /// CHECK-NOT: BoundType 101 /// CHECK-NOT: ArrayLength boundTypeInLoop(int[] a)102 private static void boundTypeInLoop(int[] a) { 103 for (int i = 0; a != null && i < a.length; i++) { 104 a[i] += 1; 105 } 106 } 107 108 // BoundType must not be hoisted by LICM, in this example it leads to ArrayLength being 109 // hoisted as well which is invalid. 110 // 111 /// CHECK-START: void Main.BoundTypeNoLICM(java.lang.Object) licm (before) 112 /// CHECK-DAG: <<Param:l\d+>> ParameterValue loop:none 113 /// CHECK-DAG: SuspendCheck loop:<<Loop:B\d+>> outer_loop:none 114 /// CHECK-DAG: <<Bound1:l\d+>> BoundType [<<Param>>] loop:<<Loop>> outer_loop:none 115 /// CHECK-DAG: <<Bound2:l\d+>> BoundType [<<Bound1>>] loop:<<Loop>> outer_loop:none 116 /// CHECK-DAG: ArrayLength [<<Bound2>>] loop:<<Loop>> outer_loop:none 117 // 118 /// CHECK-START: void Main.BoundTypeNoLICM(java.lang.Object) licm (after) 119 /// CHECK-DAG: <<Param:l\d+>> ParameterValue loop:none 120 /// CHECK-DAG: SuspendCheck loop:<<Loop:B\d+>> outer_loop:none 121 /// CHECK-DAG: <<Bound1:l\d+>> BoundType [<<Param>>] loop:<<Loop>> outer_loop:none 122 /// CHECK-DAG: <<Bound2:l\d+>> BoundType [<<Bound1>>] loop:<<Loop>> outer_loop:none 123 /// CHECK-DAG: ArrayLength [<<Bound2>>] loop:<<Loop>> outer_loop:none 124 // 125 /// CHECK-NOT: BoundType loop:none BoundTypeNoLICM(Object obj)126 private static void BoundTypeNoLICM(Object obj) { 127 int i = 0; 128 while (obj instanceof int[]) { 129 int[] a = (int[])obj; 130 a[0] = 1; 131 } 132 } 133 main(String[] args)134 public static void main(String[] args) { } 135 } 136