HELLO·Android
系统源代码
IT资讯
技术文章
我的收藏
注册
登录
-
我收藏的文章
创建代码块
我的代码块
我的账号
Nougat 7.0
|
7.0.0_r31
下载
查看原文件
收藏
根目录
art
test
463-checker-boolean-simplifier
src
Main.java
/* * Copyright (C) 2015 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. */ public class Main { // Note #1: `javac` flips the conditions of If statements. // Note #2: In the optimizing compiler, the first input of Phi is always // the fall-through path, i.e. the false branch. public static void assertBoolEquals(boolean expected, boolean result) { if (expected != result) { throw new Error("Expected: " + expected + ", found: " + result); } } public static void assertIntEquals(int expected, int result) { if (expected != result) { throw new Error("Expected: " + expected + ", found: " + result); } } /* * Elementary test negating a boolean. Verifies that blocks are merged and * empty branches removed. */ /// CHECK-START: boolean Main.BooleanNot(boolean) select_generator (before) /// CHECK-DAG: <
> ParameterValue /// CHECK-DAG: <
> IntConstant 0 /// CHECK-DAG: <
> IntConstant 1 /// CHECK-DAG: If [<
>] /// CHECK-DAG: <
> Phi [<
>,<
>] /// CHECK-DAG: Return [<
>] /// CHECK-START: boolean Main.BooleanNot(boolean) select_generator (before) /// CHECK: Goto /// CHECK: Goto /// CHECK: Goto /// CHECK-NOT: Goto /// CHECK-START: boolean Main.BooleanNot(boolean) select_generator (after) /// CHECK-DAG: <
> ParameterValue /// CHECK-DAG: <
> IntConstant 0 /// CHECK-DAG: <
> IntConstant 1 /// CHECK-DAG: <
> Select [<
>,<
>,<
>] /// CHECK-DAG: Return [<
>] /// CHECK-START: boolean Main.BooleanNot(boolean) select_generator (after) /// CHECK-NOT: If /// CHECK-NOT: Phi /// CHECK-START: boolean Main.BooleanNot(boolean) select_generator (after) /// CHECK: Goto /// CHECK-NOT: Goto public static boolean BooleanNot(boolean x) { return !x; } /* * Program which only delegates the condition, i.e. returns 1 when True * and 0 when False. */ /// CHECK-START: boolean Main.GreaterThan(int, int) select_generator (before) /// CHECK-DAG: <
> ParameterValue /// CHECK-DAG: <
> ParameterValue /// CHECK-DAG: <
> IntConstant 0 /// CHECK-DAG: <
> IntConstant 1 /// CHECK-DAG: <
> GreaterThan [<
>,<
>] /// CHECK-DAG: If [<
>] /// CHECK-DAG: <
> Phi [<
>,<
>] /// CHECK-DAG: Return [<
>] /// CHECK-START: boolean Main.GreaterThan(int, int) select_generator (after) /// CHECK-DAG: <
> ParameterValue /// CHECK-DAG: <
> ParameterValue /// CHECK-DAG: <
> IntConstant 0 /// CHECK-DAG: <
> IntConstant 1 /// CHECK-DAG: <
> GreaterThan [<
>,<
>] /// CHECK-DAG: <
> Select [<
>,<
>,<
>] /// CHECK-DAG: Return [<
>] public static boolean GreaterThan(int x, int y) { return (x <= y) ? false : true; } /* * Program which negates a condition, i.e. returns 0 when True * and 1 when False. */ /// CHECK-START: boolean Main.LessThan(int, int) select_generator (before) /// CHECK-DAG: <
> ParameterValue /// CHECK-DAG: <
> ParameterValue /// CHECK-DAG: <
> IntConstant 0 /// CHECK-DAG: <
> IntConstant 1 /// CHECK-DAG: <
> GreaterThanOrEqual [<
>,<
>] /// CHECK-DAG: If [<
>] /// CHECK-DAG: <
> Phi [<
>,<
>] /// CHECK-DAG: Return [<
>] /// CHECK-START: boolean Main.LessThan(int, int) select_generator (after) /// CHECK-DAG: <
> ParameterValue /// CHECK-DAG: <
> ParameterValue /// CHECK-DAG: <
> IntConstant 0 /// CHECK-DAG: <
> IntConstant 1 /// CHECK-DAG: <
> GreaterThanOrEqual [<
>,<
>] /// CHECK-DAG: <
> Select [<
>,<
>,<
>] /// CHECK-DAG: Return [<
>] public static boolean LessThan(int x, int y) { return (x < y) ? true : false; } /* * Program which further uses negated conditions. * Note that Phis are discovered retrospectively. */ /// CHECK-START: boolean Main.ValuesOrdered(int, int, int) select_generator (before) /// CHECK-DAG: <
> ParameterValue /// CHECK-DAG: <
> ParameterValue /// CHECK-DAG: <
> ParameterValue /// CHECK-DAG: <
> IntConstant 0 /// CHECK-DAG: <
> IntConstant 1 /// CHECK-DAG: <
> GreaterThan [<
>,<
>] /// CHECK-DAG: If [<
>] /// CHECK-DAG: <
> GreaterThan [<
>,<
>] /// CHECK-DAG: If [<
>] /// CHECK-DAG: <
> NotEqual [<
>,<
>] /// CHECK-DAG: If [<
>] /// CHECK-DAG: Return [<
>] /// CHECK-DAG: <
> Phi [<
>,<
>] /// CHECK-DAG: <
> Phi [<
>,<
>] /// CHECK-DAG: <
> Phi [<
>,<
>] /// CHECK-START: boolean Main.ValuesOrdered(int, int, int) select_generator (after) /// CHECK-DAG: <
> ParameterValue /// CHECK-DAG: <
> ParameterValue /// CHECK-DAG: <
> ParameterValue /// CHECK-DAG: <
> IntConstant 0 /// CHECK-DAG: <
> IntConstant 1 /// CHECK-DAG: <
> GreaterThan [<
>,<
>] /// CHECK-DAG: <
> Select [<
>,<
>,<
>] /// CHECK-DAG: <
> GreaterThan [<
>,<
>] /// CHECK-DAG: <
> Select [<
>,<
>,<
>] /// CHECK-DAG: <
> NotEqual [<
>,<
>] /// CHECK-DAG: <
> Select [<
>,<
>,<
>] /// CHECK-DAG: Return [<
>] public static boolean ValuesOrdered(int x, int y, int z) { return (x <= y) == (y <= z); } /// CHECK-START: int Main.NegatedCondition(boolean) select_generator (before) /// CHECK-DAG: <
> ParameterValue /// CHECK-DAG: <
> IntConstant 42 /// CHECK-DAG: <
> IntConstant 43 /// CHECK-DAG: If [<
>] /// CHECK-DAG: <
> Phi [<
>,<
>] /// CHECK-DAG: Return [<
>] /// CHECK-START: int Main.NegatedCondition(boolean) select_generator (after) /// CHECK-DAG: <
> ParameterValue /// CHECK-DAG: <
> IntConstant 42 /// CHECK-DAG: <
> IntConstant 43 /// CHECK-DAG: <
> Select [<
>,<
>,<
>] /// CHECK-DAG: Return [<
>] /// CHECK-START: int Main.NegatedCondition(boolean) select_generator (after) /// CHECK-NOT: BooleanNot public static int NegatedCondition(boolean x) { return (x != false) ? 42 : 43; } /// CHECK-START: int Main.SimpleTrueBlock(boolean, int) select_generator (after) /// CHECK-DAG: <
> ParameterValue /// CHECK-DAG: <
> ParameterValue /// CHECK-DAG: <
> IntConstant 42 /// CHECK-DAG: <
> IntConstant 43 /// CHECK-DAG: <
> Add [<
>,<
>] /// CHECK-DAG: <
> Select [<
>,<
>,<
>] /// CHECK-DAG: Return [<
>] /// CHECK-START: int Main.SimpleTrueBlock(boolean, int) select_generator (after) /// CHECK-NOT: If public static int SimpleTrueBlock(boolean x, int y) { return x ? y + 42 : 43; } /// CHECK-START: int Main.SimpleFalseBlock(boolean, int) select_generator (after) /// CHECK-DAG: <
> ParameterValue /// CHECK-DAG: <
> ParameterValue /// CHECK-DAG: <
> IntConstant 42 /// CHECK-DAG: <
> IntConstant 43 /// CHECK-DAG: <
> Add [<
>,<
>] /// CHECK-DAG: <
> Select [<
>,<
>,<
>] /// CHECK-DAG: Return [<
>] /// CHECK-START: int Main.SimpleFalseBlock(boolean, int) select_generator (after) /// CHECK-NOT: If public static int SimpleFalseBlock(boolean x, int y) { return x ? 42 : y + 43; } /// CHECK-START: int Main.SimpleBothBlocks(boolean, int, int) select_generator (after) /// CHECK-DAG: <
> ParameterValue /// CHECK-DAG: <
> ParameterValue /// CHECK-DAG: <
> ParameterValue /// CHECK-DAG: <
> IntConstant 42 /// CHECK-DAG: <
> IntConstant 43 /// CHECK-DAG: <
> Add [<
>,<
>] /// CHECK-DAG: <
> Add [<
>,<
>] /// CHECK-DAG: <
> Select [<
>,<
>,<
>] /// CHECK-DAG: Return [<
>] /// CHECK-START: int Main.SimpleBothBlocks(boolean, int, int) select_generator (after) /// CHECK-NOT: If public static int SimpleBothBlocks(boolean x, int y, int z) { return x ? y + 42 : z + 43; } /// CHECK-START: int Main.ThreeBlocks(boolean, boolean) select_generator (after) /// CHECK-DAG: <
> ParameterValue /// CHECK-DAG: <
> ParameterValue /// CHECK-DAG: <
> IntConstant 1 /// CHECK-DAG: <
> IntConstant 2 /// CHECK-DAG: <
> IntConstant 3 /// CHECK-DAG: <
> Select [<
>,<
>,<
>] /// CHECK-DAG: <
> Select [<
>,<
>,<
>] /// CHECK-DAG: Return [<
>] public static int ThreeBlocks(boolean x, boolean y) { return x ? 1 : (y ? 2 : 3); } /// CHECK-START: int Main.MultiplePhis() select_generator (before) /// CHECK-DAG: <
> IntConstant 0 /// CHECK-DAG: <
> IntConstant 1 /// CHECK-DAG: <
> IntConstant 13 /// CHECK-DAG: <
> IntConstant 42 /// CHECK-DAG: <
> Phi [<
>,<
>,<
>] /// CHECK-DAG: <
> Phi [<
>,<
>,<
>] /// CHECK-DAG: <
> Add [<
>,<
>] /// CHECK-DAG: <
> LessThanOrEqual [<
>,<
>] /// CHECK-DAG: If [<
>] /// CHECK-DAG: Return [<
>] /// CHECK-START: int Main.MultiplePhis() select_generator (after) /// CHECK-DAG: <
> IntConstant 0 /// CHECK-DAG: <
> IntConstant 1 /// CHECK-DAG: <
> IntConstant 13 /// CHECK-DAG: <
> IntConstant 42 /// CHECK-DAG: <
> Phi [<
>,<
>] /// CHECK-DAG: <
> Phi [<
>,<
>] /// CHECK-DAG: <
> Add [<
>,<
>] /// CHECK-DAG: <
> LessThanOrEqual [<
>,<
>] /// CHECK-DAG: <
> Select [<
>,<
>,<
>] /// CHECK-DAG: Return [<
>] public static int MultiplePhis() { int x = 0; int y = 1; while (y++ < 10) { if (y > 1) { x = 13; continue; } else { x = 42; continue; } } return x; } /// CHECK-START: int Main.TrueBlockWithTooManyInstructions(boolean) select_generator (before) /// CHECK-DAG: <
> ParameterValue /// CHECK-DAG: <
> ParameterValue /// CHECK-DAG: <
> IntConstant 2 /// CHECK-DAG: <
> IntConstant 43 /// CHECK-DAG: If [<
>] /// CHECK-DAG: <
> InstanceFieldGet [<
>] /// CHECK-DAG: <
> Add [<
>,<
>] /// CHECK-DAG: Phi [<
>,<
>] /// CHECK-START: int Main.TrueBlockWithTooManyInstructions(boolean) select_generator (after) /// CHECK-NOT: Select public int TrueBlockWithTooManyInstructions(boolean x) { return x ? (read_field + 2) : 43; } /// CHECK-START: int Main.FalseBlockWithTooManyInstructions(boolean) select_generator (before) /// CHECK-DAG: <
> ParameterValue /// CHECK-DAG: <
> ParameterValue /// CHECK-DAG: <
> IntConstant 3 /// CHECK-DAG: <
> IntConstant 42 /// CHECK-DAG: If [<
>] /// CHECK-DAG: <
> InstanceFieldGet [<
>] /// CHECK-DAG: <
> Add [<
>,<
>] /// CHECK-DAG: Phi [<
>,<
>] /// CHECK-START: int Main.FalseBlockWithTooManyInstructions(boolean) select_generator (after) /// CHECK-NOT: Select public int FalseBlockWithTooManyInstructions(boolean x) { return x ? 42 : (read_field + 3); } /// CHECK-START: int Main.TrueBlockWithSideEffects(boolean) select_generator (before) /// CHECK-DAG: <
> ParameterValue /// CHECK-DAG: <
> ParameterValue /// CHECK-DAG: <
> IntConstant 42 /// CHECK-DAG: <
> IntConstant 43 /// CHECK-DAG: If [<