GCC Middle and Back End API Reference
|
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "rtl.h"
#include "tm_p.h"
#include "tree.h"
#include "basic-block.h"
#include "tree-pretty-print.h"
#include "gimple.h"
#include "gimple-ssa.h"
#include "tree-cfg.h"
#include "tree-phinodes.h"
#include "ssa-iterators.h"
#include "tree-pass.h"
Macros | |
#define | LOGICAL_OP_NON_SHORT_CIRCUIT |
Functions | |
static bool | recognize_if_then_else (basic_block cond_bb, basic_block *then_bb, basic_block *else_bb) |
static bool | bb_no_side_effects_p () |
static bool | same_phi_args_p () |
static tree | get_name_for_bit_test () |
static bool | recognize_single_bit_test () |
static bool | recognize_bits_test () |
static bool | ifcombine_ifandif (basic_block inner_cond_bb, bool inner_inv, basic_block outer_cond_bb, bool outer_inv, bool result_inv) |
static bool | tree_ssa_ifcombine_bb () |
static unsigned int | tree_ssa_ifcombine () |
static bool | gate_ifcombine () |
gimple_opt_pass * | make_pass_tree_ifcombine () |
#define LOGICAL_OP_NON_SHORT_CIRCUIT |
Combining of if-expressions on trees. Copyright (C) 2007-2013 Free Software Foundation, Inc. Contributed by Richard Guenther rguen ther @suse .de
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
GCC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with GCC; see the file COPYING3. If not see http://www.gnu.org/licenses/. rtl is needed only because arm back-end requires it for BRANCH_COST.
|
static |
Verify if the basic block BB does not have side-effects. Return true in this case, else false.
|
static |
|
static |
Return the best representative SSA name for CANDIDATE which is used in a bit test.
Skip single-use names in favor of using the name from a non-widening conversion definition.
References gimple_assign_rhs1(), TREE_TYPE, and TYPE_PRECISION.
Referenced by recognize_single_bit_test().
|
static |
If-convert on a and pattern with a common else block. The inner if is specified by its INNER_COND_BB, the outer by OUTER_COND_BB. inner_inv, outer_inv and result_inv indicate whether the conditions are inverted. Returns true if the edges to the common else basic-block were merged.
See if we test a single bit of the same name in both tests. In that case remove the outer test, merging both else edges, and change the inner one to test for name & (bit1 | bit2) == (bit1 | bit2).
Do it.
Leave CFG optimization to cfg_cleanup.
See if we have two bit tests of the same name in both tests. In that case remove the outer test and change the inner one to test for name & (bits1 | bits2) != 0.
Find the common name which is bit-tested.
As we strip non-widening conversions in finding a common name that is tested make sure to end up with an integral type for building the bit operations.
Do it.
Leave CFG optimization to cfg_cleanup.
See if we have two comparisons that we can merge into one.
Invert comparisons if necessary (and possible).
Don't return false so fast, try maybe_fold_or_comparisons?
Only do this optimization if the inner bb contains only the conditional.
Leave CFG optimization to cfg_cleanup.
References boolean_false_node, boolean_true_node, boolean_type_node, build_int_cst(), canonicalize_cond_expr_cond(), dump_file, fold_build2, force_gimple_operand_gsi(), gimple_cond_set_condition_from_tree(), gsi_for_stmt(), GSI_SAME_STMT, NULL_TREE, print_generic_expr(), TREE_TYPE, and update_stmt().
gimple_opt_pass* make_pass_tree_ifcombine | ( | ) |
|
static |
Recognize a bit test pattern in a GIMPLE_COND and its defining statements. Store the name being tested in *NAME and the bits in *BITS. The COND_EXPR computes *NAME & *BITS. Returns true if the pattern matched, false otherwise.
Get at the definition of the result of the bit test.
References last_stmt(), and recognize_single_bit_test().
|
static |
This pass combines COND_EXPRs to simplify control flow. It currently recognizes bit tests and comparisons in chains that represent logical and or logical or of two COND_EXPRs.
It does so by walking basic blocks in a approximate reverse post-dominator order and trying to match CFG patterns that represent logical and or logical or of two COND_EXPRs. Transformations are done if the COND_EXPR conditions match either
To simplify this pass, removing basic blocks and dead code is left to CFG cleanup and DCE. Recognize a if-then-else CFG pattern starting to match with the COND_BB basic-block containing the COND_EXPR. The recognized then end else blocks are stored to *THEN_BB and *ELSE_BB. If *THEN_BB and/or *ELSE_BB are already set, they are required to match the then and else basic-blocks to make the pattern match. Returns true if the pattern matched, false otherwise.
Find the then/else edges.
Check if the edge destinations point to the required block.
|
static |
Recognize a single bit test pattern in GIMPLE_COND and its defining statements. Store the name being tested in *NAME and the bit in *BIT. The GIMPLE_COND computes *NAME & (1 << *BIT). Returns true if the pattern matched, false otherwise.
Get at the definition of the result of the bit test.
Look at which bit is tested. One form to recognize is D.1985_5 = state_3(D) >> control1_4(D); D.1986_6 = (int) D.1985_5; D.1987_7 = op0 & 1; if (D.1987_7 != 0)
Look through copies and conversions to eventually find the stmt that computes the shift.
If we found such, decompose it.
op0 & (1 << op1)
t & 1
Another form is D.1987_7 = op0 & (1 << CST) if (D.1987_7 != 0)
Another form is D.1986_6 = 1 << control1_4(D) D.1987_7 = op0 & D.1986_6 if (D.1987_7 != 0)
Both arguments of the BIT_AND_EXPR can be the single-bit specifying expression.
References CONVERT_EXPR_CODE_P, get_name_for_bit_test(), gimple_assign_lhs(), gimple_assign_rhs1(), gimple_assign_rhs2(), gimple_assign_rhs_code(), gimple_assign_ssa_name_copy_p(), integer_zero_node, is_gimple_assign(), SSA_NAME_DEF_STMT, TREE_TYPE, and TYPE_PRECISION.
Referenced by recognize_bits_test().
|
static |
Verify if all PHI node arguments in DEST for edges from BB1 or BB2 to DEST are the same. This makes the CFG merge point free from side-effects. Return true in this case, else false.
References gsi_stmt(), operand_equal_p(), and PHI_ARG_DEF_FROM_EDGE.
|
static |
Main entry for the tree if-conversion pass.
Search every basic block for COND_EXPR we may be able to optimize.
We walk the blocks in order that guarantees that a block with a single predecessor is processed after the predecessor. This ensures that we collapse outter ifs before visiting the inner ones, and also that we do not try to visit a removed block. This is opposite of PHI-OPT, because we cascade the combining rather than cascading PHIs.
|
static |
Recognize a CFG pattern and dispatch to the appropriate if-conversion helper. We start with BB as the innermost worker basic-block. Returns true if a transformation was done.
Recognize && and || of two conditions with a common then/else block which entry edges we can merge. That is: if (a || b) ; and if (a && b) ; This requires a single predecessor of the inner cond_bb.
The && form is characterized by a common else_bb with the two edges leading to it mergable. The latter is guaranteed by matching PHI arguments in the else_bb and the inner cond_bb having no side-effects.
We have <outer_cond_bb> if (q) goto inner_cond_bb; else goto else_bb; <inner_cond_bb> if (p) goto ...; else goto else_bb; ... <else_bb> ...
And a version where the outer condition is negated.
We have <outer_cond_bb> if (q) goto else_bb; else goto inner_cond_bb; <inner_cond_bb> if (p) goto ...; else goto else_bb; ... <else_bb> ...
The || form is characterized by a common then_bb with the two edges leading to it mergable. The latter is guaranteed by matching PHI arguments in the then_bb and the inner cond_bb having no side-effects.
We have <outer_cond_bb> if (q) goto then_bb; else goto inner_cond_bb; <inner_cond_bb> if (q) goto then_bb; else goto ...; <then_bb> ...
And a version where the outer condition is negated.
We have <outer_cond_bb> if (q) goto inner_cond_bb; else goto then_bb; <inner_cond_bb> if (q) goto then_bb; else goto ...; <then_bb> ...