HELLO·Android
系统源代码
IT资讯
技术文章
我的收藏
注册
登录
-
我收藏的文章
创建代码块
我的代码块
我的账号
Android 10
|
10.0.0_r6
下载
查看原文件
收藏
根目录
art
test
530-checker-peel-unroll
src
Main.java
/* * Copyright (C) 2018 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.lang.reflect.Method; // // Test loop optimizations, in particular scalar loop peeling and unrolling. public class Main { static final int LENGTH = 4 * 1024; int[] a = new int[LENGTH]; int[] b = new int[LENGTH]; private static final int LENGTH_A = LENGTH; private static final int LENGTH_B = 16; private static final int RESULT_POS = 4; double[][] mA; double[][] mB; double[][] mC; public Main() { mA = new double[LENGTH_A][]; mB = new double[LENGTH_B][]; mC = new double[LENGTH_B][]; for (int i = 0; i < LENGTH_A; i++) { mA[i] = new double[LENGTH_B]; } for (int i = 0; i < LENGTH_B; i++) { mB[i] = new double[LENGTH_A]; mC[i] = new double[LENGTH_B]; } } private static final void initMatrix(double[][] m) { for (int i = 0; i < m.length; i++) { for (int j = 0; j < m[i].length; j++) { m[i][j] = (double) (i * LENGTH / (j + 1)); } } } private static final void initIntArray(int[] a) { for (int i = 0; i < a.length; i++) { a[i] = i % 4; } } private static final void initDoubleArray(double[] a) { for (int i = 0; i < a.length; i++) { a[i] = (double)(i % 4); } } /// CHECK-START: void Main.unrollingLoadStoreElimination(int[]) loop_optimization (before) /// CHECK-DAG: <
> ParameterValue loop:none /// CHECK-DAG: <
> IntConstant 1 loop:none /// CHECK-DAG: <
> IntConstant 4094 loop:none /// CHECK-DAG: <
> Phi loop:<
> outer_loop:none /// CHECK-DAG: <
> GreaterThanOrEqual [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> If [<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> ArrayGet [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> Add [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> ArrayGet [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> Add [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: ArraySet [<
>,<
>,<
>] loop:<
> outer_loop:none // /// CHECK-NOT: ArrayGet loop:<
> outer_loop:none /// CHECK-NOT: ArraySet loop:<
> outer_loop:none /// CHECK-START: void Main.unrollingLoadStoreElimination(int[]) loop_optimization (after) /// CHECK-DAG: <
> ParameterValue loop:none /// CHECK-DAG: <
> IntConstant 0 loop:none /// CHECK-DAG: <
> IntConstant 1 loop:none /// CHECK-DAG: <
> IntConstant 4094 loop:none /// CHECK-DAG: <
> Phi loop:<
> outer_loop:none /// CHECK-DAG: <
> GreaterThanOrEqual [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> If [<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> ArrayGet [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> Add [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> ArrayGet [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> Add [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: ArraySet [<
>,<
>,<
>] loop:<
> outer_loop:none // /// CHECK-DAG: <
> GreaterThanOrEqual [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> If [<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> ArrayGet [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> Add [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> ArrayGet [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> Add [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: ArraySet [<
>,<
>,<
>] loop:<
> outer_loop:none // /// CHECK-NOT: ArrayGet loop:<
> outer_loop:none /// CHECK-NOT: ArraySet loop:<
> outer_loop:none private static final void unrollingLoadStoreElimination(int[] a) { for (int i = 0; i < LENGTH - 2; i++) { a[i] += a[i + 1]; } } // Simple check that loop unrolling has happened. // /// CHECK-START: void Main.unrollingSwitch(int[]) loop_optimization (before) /// CHECK-DAG: <
> IntConstant 0 loop:none /// CHECK-DAG: <
> IntConstant 1 loop:none /// CHECK-DAG: <
> IntConstant 4096 loop:none /// CHECK-DAG: <
> Phi [<
>,{{i\d+}}] loop:<
> outer_loop:none /// CHECK-DAG: <
> GreaterThanOrEqual [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> If [<
>] loop:<
> outer_loop:none /// CHECK-DAG: ArrayGet loop:<
> outer_loop:none /// CHECK-DAG: ArraySet loop:<
> outer_loop:none /// CHECK-DAG: Add [<
>,<
>] loop:<
> outer_loop:none // /// CHECK-NOT: ArrayGet loop:<
> outer_loop:none /// CHECK-NOT: ArraySet loop:<
> outer_loop:none /// CHECK-START: void Main.unrollingSwitch(int[]) loop_optimization (after) /// CHECK-DAG: <
> IntConstant 0 loop:none /// CHECK-DAG: <
> IntConstant 1 loop:none /// CHECK-DAG: <
> IntConstant 4096 loop:none /// CHECK-DAG: <
> Phi [<
>,{{i\d+}}] loop:<
> outer_loop:none /// CHECK-DAG: <
> GreaterThanOrEqual [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> If [<
>] loop:<
> outer_loop:none /// CHECK-DAG: ArrayGet loop:<
> outer_loop:none /// CHECK-DAG: ArraySet loop:<
> outer_loop:none /// CHECK-DAG: <
> Add [<
>,<
>] loop:<
> outer_loop:none // /// CHECK-DAG: <
> GreaterThanOrEqual [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> If [<
>] loop:<
> outer_loop:none /// CHECK-DAG: ArrayGet loop:<
> outer_loop:none /// CHECK-DAG: ArraySet loop:<
> outer_loop:none /// CHECK-DAG: Add [<
>,<
>] loop:<
> outer_loop:none // /// CHECK-NOT: ArrayGet loop:<
> outer_loop:none /// CHECK-NOT: ArraySet loop:<
> outer_loop:none private static final void unrollingSwitch(int[] a) { for (int i = 0; i < LENGTH; i++) { switch (i % 3) { case 2: a[i]++; break; default: break; } } } // Simple check that loop unrolling has happened. // /// CHECK-START: void Main.unrollingSwapElements(int[]) loop_optimization (before) /// CHECK-DAG: <
> IntConstant 0 loop:none /// CHECK-DAG: <
> IntConstant 1 loop:none /// CHECK-DAG: <
> IntConstant 4094 loop:none /// CHECK-DAG: <
> Phi [<
>,{{i\d+}}] loop:<
> outer_loop:none /// CHECK-DAG: <
> GreaterThanOrEqual [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> If [<
>] loop:<
> outer_loop:none /// CHECK-DAG: ArrayGet loop:<
> outer_loop:none /// CHECK-DAG: ArrayGet loop:<
> outer_loop:none /// CHECK-DAG: ArraySet loop:<
> outer_loop:none /// CHECK-DAG: ArraySet loop:<
> outer_loop:none /// CHECK-DAG: Add [<
>,<
>] loop:<
> outer_loop:none // /// CHECK-NOT: ArrayGet loop:<
> outer_loop:none /// CHECK-NOT: ArraySet loop:<
> outer_loop:none /// CHECK-START: void Main.unrollingSwapElements(int[]) loop_optimization (after) /// CHECK-DAG: <
> IntConstant 0 loop:none /// CHECK-DAG: <
> IntConstant 1 loop:none /// CHECK-DAG: <
> IntConstant 4094 loop:none /// CHECK-DAG: <
> Phi [<
>,{{i\d+}}] loop:<
> outer_loop:none /// CHECK-DAG: <
> GreaterThanOrEqual [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> If [<
>] loop:<
> outer_loop:none /// CHECK-DAG: ArrayGet loop:<
> outer_loop:none /// CHECK-DAG: ArrayGet loop:<
> outer_loop:none /// CHECK-DAG: ArraySet loop:<
> outer_loop:none /// CHECK-DAG: ArraySet loop:<
> outer_loop:none /// CHECK-DAG: <
> Add [<
>,<
>] loop:<
> outer_loop:none // /// CHECK-DAG: <
> GreaterThanOrEqual [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> If [<
>] loop:<
> outer_loop:none /// CHECK-DAG: ArrayGet loop:<
> outer_loop:none /// CHECK-DAG: ArrayGet loop:<
> outer_loop:none /// CHECK-DAG: ArraySet loop:<
> outer_loop:none /// CHECK-DAG: ArraySet loop:<
> outer_loop:none /// CHECK-DAG: Add [<
>,<
>] loop:<
> outer_loop:none // /// CHECK-NOT: ArrayGet loop:<
> outer_loop:none /// CHECK-NOT: ArraySet loop:<
> outer_loop:none private static final void unrollingSwapElements(int[] array) { for (int i = 0; i < LENGTH - 2; i++) { if (array[i] > array[i + 1]) { int temp = array[i + 1]; array[i + 1] = array[i]; array[i] = temp; } } } // Simple check that loop unrolling has happened. // /// CHECK-START: void Main.unrollingRInnerproduct(double[][], double[][], double[][], int, int) loop_optimization (before) /// CHECK-DAG: <
> IntConstant 0 loop:none /// CHECK-DAG: <
> IntConstant 1 loop:none /// CHECK-DAG: <
> IntConstant 16 loop:none /// CHECK-DAG: <
> Phi [<
>,{{i\d+}}] loop:<
> outer_loop:none /// CHECK-DAG: <
> GreaterThanOrEqual [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> If [<
>] loop:<
> outer_loop:none /// CHECK-DAG: ArrayGet loop:<
> outer_loop:none /// CHECK-DAG: ArrayGet loop:<
> outer_loop:none /// CHECK-DAG: ArrayGet loop:<
> outer_loop:none /// CHECK-DAG: ArrayGet loop:<
> outer_loop:none /// CHECK-DAG: ArraySet loop:<
> outer_loop:none /// CHECK-DAG: Add [<
>,<
>] loop:<
> outer_loop:none // /// CHECK-NOT: ArrayGet loop:<
> outer_loop:none /// CHECK-NOT: ArraySet loop:<
> outer_loop:none /// CHECK-START: void Main.unrollingRInnerproduct(double[][], double[][], double[][], int, int) loop_optimization (after) /// CHECK-DAG: <
> IntConstant 0 loop:none /// CHECK-DAG: <
> IntConstant 1 loop:none /// CHECK-DAG: <
> IntConstant 16 loop:none /// CHECK-DAG: <
> Phi [<
>,{{i\d+}}] loop:<
> outer_loop:none /// CHECK-DAG: <
> GreaterThanOrEqual [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> If [<
>] loop:<
> outer_loop:none /// CHECK-DAG: ArrayGet loop:<
> outer_loop:none /// CHECK-DAG: ArrayGet loop:<
> outer_loop:none /// CHECK-DAG: ArrayGet loop:<
> outer_loop:none /// CHECK-DAG: ArrayGet loop:<
> outer_loop:none /// CHECK-DAG: ArraySet loop:<
> outer_loop:none /// CHECK-DAG: <
> Add [<
>,<
>] loop:<
> outer_loop:none // /// CHECK-DAG: <