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 public class ExampleObj { 20 int n1; 21 int n2; 22 ExampleObj(int n1, int n2)23 public ExampleObj(int n1, int n2) { 24 this.n1 = n1; 25 this.n2 = n2; 26 } 27 } 28 29 static int static_variable = 0; 30 31 public ExampleObj my_obj; 32 public static int number1; 33 public static int number2; 34 35 /// CHECK-START-ARM64: int Main.arrayAccess() scheduler (before) 36 /// CHECK: <<Const1:i\d+>> IntConstant 1 37 /// CHECK: <<i0:i\d+>> Phi 38 /// CHECK: <<res0:i\d+>> Phi 39 /// CHECK: <<Array:i\d+>> IntermediateAddress 40 /// CHECK: <<ArrayGet1:i\d+>> ArrayGet [<<Array>>,<<i0>>] 41 /// CHECK: <<res1:i\d+>> Add [<<res0>>,<<ArrayGet1>>] 42 /// CHECK: <<i1:i\d+>> Add [<<i0>>,<<Const1>>] 43 /// CHECK: <<ArrayGet2:i\d+>> ArrayGet [<<Array>>,<<i1>>] 44 /// CHECK: Add [<<res1>>,<<ArrayGet2>>] 45 46 /// CHECK-START-ARM64: int Main.arrayAccess() scheduler (after) 47 /// CHECK: <<Const1:i\d+>> IntConstant 1 48 /// CHECK: <<i0:i\d+>> Phi 49 /// CHECK: <<res0:i\d+>> Phi 50 /// CHECK: <<Array:i\d+>> IntermediateAddress 51 /// CHECK: <<ArrayGet1:i\d+>> ArrayGet [<<Array>>,<<i0>>] 52 /// CHECK: <<i1:i\d+>> Add [<<i0>>,<<Const1>>] 53 /// CHECK: <<ArrayGet2:i\d+>> ArrayGet [<<Array>>,<<i1>>] 54 /// CHECK: <<res1:i\d+>> Add [<<res0>>,<<ArrayGet1>>] 55 /// CHECK: Add [<<res1>>,<<ArrayGet2>>] 56 arrayAccess()57 public static int arrayAccess() { 58 int res = 0; 59 int [] array = new int[10]; 60 for (int i = 0; i < 9; i++) { 61 res += array[i]; 62 res += array[i + 1]; 63 } 64 return res; 65 } 66 67 /// CHECK-START-ARM: void Main.arrayAccessVariable(int) scheduler (before) 68 /// CHECK: <<Param:i\d+>> ParameterValue 69 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 70 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2 71 /// CHECK-DAG: <<Const3:i\d+>> IntConstant -1 72 /// CHECK: <<Add1:i\d+>> Add [<<Param>>,<<Const1>>] 73 /// CHECK: <<Add2:i\d+>> Add [<<Param>>,<<Const2>>] 74 /// CHECK: <<Add3:i\d+>> Add [<<Param>>,<<Const3>>] 75 /// CHECK: <<Array:i\d+>> IntermediateAddress 76 /// CHECK: <<ArrayGet1:i\d+>> ArrayGet [<<Array>>,<<Add1>>] 77 /// CHECK: <<AddArray1:i\d+>> Add [<<ArrayGet1>>,<<Const1>>] 78 /// CHECK: <<ArraySet1:v\d+>> ArraySet [<<Array>>,<<Add1>>,<<AddArray1>>] 79 /// CHECK: <<ArrayGet2:i\d+>> ArrayGet [<<Array>>,<<Add2>>] 80 /// CHECK: <<AddArray2:i\d+>> Add [<<ArrayGet2>>,<<Const1>>] 81 /// CHECK: <<ArraySet2:v\d+>> ArraySet [<<Array>>,<<Add2>>,<<AddArray2>>] 82 /// CHECK: <<ArrayGet3:i\d+>> ArrayGet [<<Array>>,<<Add3>>] 83 /// CHECK: <<AddArray3:i\d+>> Add [<<ArrayGet3>>,<<Const1>>] 84 /// CHECK: <<ArraySet3:v\d+>> ArraySet [<<Array>>,<<Add3>>,<<AddArray3>>] 85 86 /// CHECK-START-ARM: void Main.arrayAccessVariable(int) scheduler (after) 87 /// CHECK: <<Param:i\d+>> ParameterValue 88 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 89 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2 90 /// CHECK-DAG: <<Const3:i\d+>> IntConstant -1 91 /// CHECK: <<Add1:i\d+>> Add [<<Param>>,<<Const1>>] 92 /// CHECK: <<Add2:i\d+>> Add [<<Param>>,<<Const2>>] 93 /// CHECK: <<Add3:i\d+>> Add [<<Param>>,<<Const3>>] 94 /// CHECK: <<Array:i\d+>> IntermediateAddress 95 /// CHECK: ArrayGet [<<Array>>,{{i\d+}}] 96 /// CHECK: ArrayGet [<<Array>>,{{i\d+}}] 97 /// CHECK: ArrayGet [<<Array>>,{{i\d+}}] 98 /// CHECK: Add 99 /// CHECK: Add 100 /// CHECK: Add 101 /// CHECK: ArraySet 102 /// CHECK: ArraySet 103 /// CHECK: ArraySet 104 105 /// CHECK-START-ARM64: void Main.arrayAccessVariable(int) scheduler (before) 106 /// CHECK: <<Param:i\d+>> ParameterValue 107 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 108 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2 109 /// CHECK-DAG: <<Const3:i\d+>> IntConstant -1 110 /// CHECK: <<Add1:i\d+>> Add [<<Param>>,<<Const1>>] 111 /// CHECK: <<Add2:i\d+>> Add [<<Param>>,<<Const2>>] 112 /// CHECK: <<Add3:i\d+>> Add [<<Param>>,<<Const3>>] 113 /// CHECK: <<Array:i\d+>> IntermediateAddress 114 /// CHECK: <<ArrayGet1:i\d+>> ArrayGet [<<Array>>,<<Add1>>] 115 /// CHECK: <<AddArray1:i\d+>> Add [<<ArrayGet1>>,<<Const1>>] 116 /// CHECK: <<ArraySet1:v\d+>> ArraySet [<<Array>>,<<Add1>>,<<AddArray1>>] 117 /// CHECK: <<ArrayGet2:i\d+>> ArrayGet [<<Array>>,<<Add2>>] 118 /// CHECK: <<AddArray2:i\d+>> Add [<<ArrayGet2>>,<<Const1>>] 119 /// CHECK: <<ArraySet2:v\d+>> ArraySet [<<Array>>,<<Add2>>,<<AddArray2>>] 120 /// CHECK: <<ArrayGet3:i\d+>> ArrayGet [<<Array>>,<<Add3>>] 121 /// CHECK: <<AddArray3:i\d+>> Add [<<ArrayGet3>>,<<Const1>>] 122 /// CHECK: <<ArraySet3:v\d+>> ArraySet [<<Array>>,<<Add3>>,<<AddArray3>>] 123 124 /// CHECK-START-ARM64: void Main.arrayAccessVariable(int) scheduler (after) 125 /// CHECK: <<Param:i\d+>> ParameterValue 126 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 127 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2 128 /// CHECK-DAG: <<Const3:i\d+>> IntConstant -1 129 /// CHECK: <<Add1:i\d+>> Add [<<Param>>,<<Const1>>] 130 /// CHECK: <<Add2:i\d+>> Add [<<Param>>,<<Const2>>] 131 /// CHECK: <<Add3:i\d+>> Add [<<Param>>,<<Const3>>] 132 /// CHECK: <<Array:i\d+>> IntermediateAddress 133 /// CHECK: ArrayGet [<<Array>>,{{i\d+}}] 134 /// CHECK: ArrayGet [<<Array>>,{{i\d+}}] 135 /// CHECK: ArrayGet [<<Array>>,{{i\d+}}] 136 /// CHECK: Add 137 /// CHECK: Add 138 /// CHECK: Add 139 /// CHECK: ArraySet 140 /// CHECK: ArraySet 141 /// CHECK: ArraySet arrayAccessVariable(int i)142 public static void arrayAccessVariable(int i) { 143 int [] array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; 144 for (int j = 0; j < 100; j++) { 145 array[i + 1]++; 146 array[i + 2]++; 147 array[i - 1]++; 148 } 149 } 150 151 /// CHECK-START-ARM: void Main.arrayAccessSub(int) scheduler (before) 152 /// CHECK: <<Param:i\d+>> ParameterValue 153 /// CHECK-DAG: <<Const1:i\d+>> IntConstant -1 154 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 9 155 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 1 156 /// CHECK: <<Add1:i\d+>> Add [<<Param>>,<<Const1>>] 157 /// CHECK: <<Sub2:i\d+>> Sub [<<Const2>>,<<Param>>] 158 /// CHECK: <<Array:i\d+>> IntermediateAddress 159 /// CHECK: <<ArrayGet1:i\d+>> ArrayGet [<<Array>>,<<Add1>>] 160 /// CHECK: <<AddArray1:i\d+>> Add [<<ArrayGet1>>,<<Const3>>] 161 /// CHECK: <<ArraySet1:v\d+>> ArraySet [<<Array>>,<<Add1>>,<<AddArray1>>] 162 /// CHECK: <<ArrayGet2:i\d+>> ArrayGet [<<Array>>,<<Sub2>>] 163 /// CHECK: <<AddArray2:i\d+>> Add [<<ArrayGet2>>,<<Const3>>] 164 /// CHECK: <<ArraySet2:v\d+>> ArraySet [<<Array>>,<<Sub2>>,<<AddArray2>>] 165 166 /// CHECK-START-ARM: void Main.arrayAccessSub(int) scheduler (after) 167 /// CHECK: <<Param:i\d+>> ParameterValue 168 /// CHECK-DAG: <<Const1:i\d+>> IntConstant -1 169 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 9 170 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 1 171 /// CHECK: <<Add1:i\d+>> Add [<<Param>>,<<Const1>>] 172 /// CHECK: <<Sub2:i\d+>> Sub [<<Const2>>,<<Param>>] 173 /// CHECK: <<Array:i\d+>> IntermediateAddress 174 /// CHECK: <<ArrayGet1:i\d+>> ArrayGet [<<Array>>,<<Add1>>] 175 /// CHECK: <<AddArray1:i\d+>> Add [<<ArrayGet1>>,<<Const3>>] 176 /// CHECK: <<ArraySet1:v\d+>> ArraySet [<<Array>>,<<Add1>>,<<AddArray1>>] 177 /// CHECK: <<ArrayGet2:i\d+>> ArrayGet [<<Array>>,<<Sub2>>] 178 /// CHECK: <<AddArray2:i\d+>> Add [<<ArrayGet2>>,<<Const3>>] 179 /// CHECK: <<ArraySet2:v\d+>> ArraySet [<<Array>>,<<Sub2>>,<<AddArray2>>] 180 181 /// CHECK-START-ARM64: void Main.arrayAccessSub(int) scheduler (before) 182 /// CHECK: <<Param:i\d+>> ParameterValue 183 /// CHECK-DAG: <<Const1:i\d+>> IntConstant -1 184 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 9 185 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 1 186 /// CHECK: <<Add1:i\d+>> Add [<<Param>>,<<Const1>>] 187 /// CHECK: <<Sub2:i\d+>> Sub [<<Const2>>,<<Param>>] 188 /// CHECK: <<Array:i\d+>> IntermediateAddress 189 /// CHECK: <<ArrayGet1:i\d+>> ArrayGet [<<Array>>,<<Add1>>] 190 /// CHECK: <<AddArray1:i\d+>> Add [<<ArrayGet1>>,<<Const3>>] 191 /// CHECK: <<ArraySet1:v\d+>> ArraySet [<<Array>>,<<Add1>>,<<AddArray1>>] 192 /// CHECK: <<ArrayGet2:i\d+>> ArrayGet [<<Array>>,<<Sub2>>] 193 /// CHECK: <<AddArray2:i\d+>> Add [<<ArrayGet2>>,<<Const3>>] 194 /// CHECK: <<ArraySet2:v\d+>> ArraySet [<<Array>>,<<Sub2>>,<<AddArray2>>] 195 196 /// CHECK-START-ARM64: void Main.arrayAccessSub(int) scheduler (after) 197 /// CHECK: <<Param:i\d+>> ParameterValue 198 /// CHECK-DAG: <<Const1:i\d+>> IntConstant -1 199 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 9 200 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 1 201 /// CHECK: <<Add1:i\d+>> Add [<<Param>>,<<Const1>>] 202 /// CHECK: <<Sub2:i\d+>> Sub [<<Const2>>,<<Param>>] 203 /// CHECK: <<Array:i\d+>> IntermediateAddress 204 /// CHECK: <<ArrayGet1:i\d+>> ArrayGet [<<Array>>,<<Add1>>] 205 /// CHECK: <<AddArray1:i\d+>> Add [<<ArrayGet1>>,<<Const3>>] 206 /// CHECK: <<ArraySet1:v\d+>> ArraySet [<<Array>>,<<Add1>>,<<AddArray1>>] 207 /// CHECK: <<ArrayGet2:i\d+>> ArrayGet [<<Array>>,<<Sub2>>] 208 /// CHECK: <<AddArray2:i\d+>> Add [<<ArrayGet2>>,<<Const3>>] 209 /// CHECK: <<ArraySet2:v\d+>> ArraySet [<<Array>>,<<Sub2>>,<<AddArray2>>] arrayAccessSub(int i)210 public static void arrayAccessSub(int i) { 211 int [] array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; 212 for (int j = 0; j < 100; j++) { 213 // These two accesses MAY ALIAS 214 array[i - 1]++; 215 array[9 - i]++; 216 } 217 } 218 219 /// CHECK-START-ARM: void Main.arrayAccessLoopVariable() scheduler (before) 220 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 221 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 222 /// CHECK: <<Phi:i\d+>> Phi 223 /// CHECK: <<Array:i\d+>> IntermediateAddress 224 /// CHECK: <<ArrayGet1:i\d+>> ArrayGet 225 /// CHECK: <<AddArray1:i\d+>> Add 226 /// CHECK: <<ArraySet1:v\d+>> ArraySet 227 /// CHECK: <<AddVar:i\d+>> Add 228 /// CHECK: <<ArrayGet2:i\d+>> ArrayGet 229 /// CHECK: <<AddArray2:i\d+>> Add 230 /// CHECK: <<ArraySet2:v\d+>> ArraySet 231 232 /// CHECK-START-ARM: void Main.arrayAccessLoopVariable() scheduler (after) 233 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 234 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 235 /// CHECK: <<Phi:i\d+>> Phi 236 /// CHECK: <<Array:i\d+>> IntermediateAddress 237 /// CHECK: <<AddVar:i\d+>> Add 238 /// CHECK: <<ArrayGet1:i\d+>> ArrayGet 239 /// CHECK: <<ArrayGet2:i\d+>> ArrayGet 240 /// CHECK: <<AddArray1:i\d+>> Add 241 /// CHECK: <<AddArray2:i\d+>> Add 242 /// CHECK: <<ArraySet1:v\d+>> ArraySet 243 /// CHECK: <<ArraySet2:v\d+>> ArraySet 244 245 /// CHECK-START-ARM64: void Main.arrayAccessLoopVariable() scheduler (before) 246 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 247 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 248 /// CHECK: <<Phi:i\d+>> Phi 249 /// CHECK: <<Array:i\d+>> IntermediateAddress 250 /// CHECK: <<ArrayGet1:i\d+>> ArrayGet 251 /// CHECK: <<AddArray1:i\d+>> Add 252 /// CHECK: <<ArraySet1:v\d+>> ArraySet 253 /// CHECK: <<AddVar:i\d+>> Add 254 /// CHECK: <<ArrayGet2:i\d+>> ArrayGet 255 /// CHECK: <<AddArray2:i\d+>> Add 256 /// CHECK: <<ArraySet2:v\d+>> ArraySet 257 258 /// CHECK-START-ARM64: void Main.arrayAccessLoopVariable() scheduler (after) 259 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 260 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 261 /// CHECK: <<Phi:i\d+>> Phi 262 /// CHECK: <<Array:i\d+>> IntermediateAddress 263 /// CHECK: <<AddVar:i\d+>> Add 264 /// CHECK: <<ArrayGet1:i\d+>> ArrayGet 265 /// CHECK: <<ArrayGet2:i\d+>> ArrayGet 266 /// CHECK: <<AddArray1:i\d+>> Add 267 /// CHECK: <<AddArray2:i\d+>> Add 268 /// CHECK: <<ArraySet1:v\d+>> ArraySet 269 /// CHECK: <<ArraySet2:v\d+>> ArraySet arrayAccessLoopVariable()270 public static void arrayAccessLoopVariable() { 271 int [] array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; 272 for (int j = 0; j < 9; j++) { 273 array[j]++; 274 array[j + 1]++; 275 } 276 } 277 278 /// CHECK-START-ARM: void Main.accessFields() scheduler (before) 279 /// CHECK: InstanceFieldGet 280 /// CHECK: Add 281 /// CHECK: InstanceFieldSet 282 /// CHECK: InstanceFieldGet 283 /// CHECK: Add 284 /// CHECK: InstanceFieldSet 285 /// CHECK: StaticFieldGet 286 /// CHECK: Add 287 /// CHECK: StaticFieldSet 288 /// CHECK: StaticFieldGet 289 /// CHECK: Add 290 /// CHECK: StaticFieldSet 291 292 /// CHECK-START-ARM: void Main.accessFields() scheduler (after) 293 /// CHECK-DAG: InstanceFieldGet 294 /// CHECK-DAG: InstanceFieldGet 295 /// CHECK-DAG: StaticFieldGet 296 /// CHECK-DAG: StaticFieldGet 297 /// CHECK: Add 298 /// CHECK: Add 299 /// CHECK: Add 300 /// CHECK: Add 301 /// CHECK-DAG: InstanceFieldSet 302 /// CHECK-DAG: InstanceFieldSet 303 /// CHECK-DAG: StaticFieldSet 304 /// CHECK-DAG: StaticFieldSet 305 306 /// CHECK-START-ARM64: void Main.accessFields() scheduler (before) 307 /// CHECK: InstanceFieldGet 308 /// CHECK: Add 309 /// CHECK: InstanceFieldSet 310 /// CHECK: InstanceFieldGet 311 /// CHECK: Add 312 /// CHECK: InstanceFieldSet 313 /// CHECK: StaticFieldGet 314 /// CHECK: Add 315 /// CHECK: StaticFieldSet 316 /// CHECK: StaticFieldGet 317 /// CHECK: Add 318 /// CHECK: StaticFieldSet 319 320 /// CHECK-START-ARM64: void Main.accessFields() scheduler (after) 321 /// CHECK-DAG: InstanceFieldGet 322 /// CHECK-DAG: InstanceFieldGet 323 /// CHECK-DAG: StaticFieldGet 324 /// CHECK-DAG: StaticFieldGet 325 /// CHECK: Add 326 /// CHECK: Add 327 /// CHECK: Add 328 /// CHECK: Add 329 /// CHECK-DAG: InstanceFieldSet 330 /// CHECK-DAG: InstanceFieldSet 331 /// CHECK-DAG: StaticFieldSet 332 /// CHECK-DAG: StaticFieldSet accessFields()333 public void accessFields() { 334 my_obj = new ExampleObj(1, 2); 335 for (int i = 0; i < 10; i++) { 336 my_obj.n1++; 337 my_obj.n2++; 338 number1++; 339 number2++; 340 } 341 } 342 343 /// CHECK-START-ARM64: int Main.intDiv(int) scheduler (before) 344 /// CHECK: Sub 345 /// CHECK: DivZeroCheck 346 /// CHECK: Div 347 /// CHECK: StaticFieldSet 348 349 /// CHECK-START-ARM64: int Main.intDiv(int) scheduler (after) 350 /// CHECK: Sub 351 /// CHECK-NOT: StaticFieldSet 352 /// CHECK: DivZeroCheck 353 /// CHECK-NOT: Sub 354 /// CHECK: Div intDiv(int arg)355 public static int intDiv(int arg) { 356 int res = 0; 357 int tmp = arg; 358 for (int i = 1; i < arg; i++) { 359 tmp -= i; 360 res = res / i; // div-zero check barrier. 361 static_variable++; 362 } 363 res += tmp; 364 return res; 365 } 366 main(String[] args)367 public static void main(String[] args) { 368 if ((arrayAccess() + intDiv(10)) != -35) { 369 System.out.println("FAIL"); 370 } 371 } 372 } 373