GCC Middle and Back End API Reference
|
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "backend.h"
#include "rtl.h"
#include "rtlanal.h"
#include "cfghooks.h"
#include "df.h"
#include "insn-config.h"
#include "memmodel.h"
#include "emit-rtl.h"
#include "recog.h"
#include "diagnostic-core.h"
#include "toplev.h"
#include "cfgrtl.h"
#include "cfganal.h"
#include "lcm.h"
#include "cfgcleanup.h"
#include "cselib.h"
#include "intl.h"
#include "tree-pass.h"
#include "dbgcnt.h"
#include "cfgloop.h"
#include "gcse.h"
Data Structures | |
struct | cprop_occr |
struct | cprop_expr |
struct | hash_table_d |
Macros | |
#define | GOBNEW(T) |
#define | GOBNEWVAR(T, S) |
#define | MAX_USES 8 |
Variables | |
static struct obstack | cprop_obstack |
static struct hash_table_d | set_hash_table |
static rtx * | implicit_sets |
static int * | implicit_set_indexes |
static regset | reg_set_bitmap |
static int | bytes_used |
static int | local_const_prop_count |
static int | local_copy_prop_count |
static int | global_const_prop_count |
static int | global_copy_prop_count |
static sbitmap * | cprop_avloc |
static sbitmap * | cprop_kill |
static sbitmap * | cprop_avin |
static sbitmap * | cprop_avout |
static rtx | reg_use_table [MAX_USES] |
static unsigned | reg_use_count |
static int | bypass_last_basic_block |
#define GOBNEW | ( | T | ) |
Referenced by insert_set_in_table().
#define MAX_USES 8 |
Copy/constant propagation.
Maximum number of register uses in an insn that we handle.
Referenced by find_used_regs().
|
static |
Allocate vars used for copy/const propagation. N_BLOCKS is the number of basic blocks. N_SETS is the number of sets.
References cprop_avin, cprop_avloc, cprop_avout, cprop_kill, and sbitmap_vector_alloc().
Referenced by one_cprop_pass().
|
static |
Allocate space for the set/expr hash TABLE. It is used to determine the number of buckets to use.
References get_max_insn_count(), and table.
Referenced by one_cprop_pass().
|
static |
Subroutine of bypass_conditional_jumps that attempts to bypass the given basic block BB which has more than one predecessor. If not NULL, SETCC is the first instruction of BB, which is immediately followed by JUMP_INSN JUMP. Otherwise, SETCC is NULL, and JUMP is the first insn of BB. Returns true if a change was made. During the jump bypassing pass, we may place copies of SETCC instructions on CFG edges. The following routine must be careful to pay attention to these inserted insns when performing its transformations.
References BLOCK_FOR_INSN(), bypass_last_basic_block, cfun, copy_insn(), current_loops, cprop_expr::dest, dump_file, EDGE_COMPLEX, ei_next(), ei_safe_edge(), ei_start, EXIT_BLOCK_PTR_FOR_FN, FALLTHRU_EDGE, find_bypass_set(), find_edge(), find_reg_equal_equiv_note(), find_used_regs(), FOR_EACH_EDGE, GET_CODE, loop::header, i, basic_block_def::index, insert_insn_on_edge(), INSN_UID(), basic_block_def::loop_father, note_uses(), NULL, PATTERN(), pc_rtx, pc_set(), basic_block_def::preds, print_rtl(), redirect_edge_and_branch_force(), reg_killed_on_edge(), reg_use_count, reg_use_table, REGNO, SET_DEST, SET_SRC, simplify_replace_rtx(), cprop_expr::src, set::src, and XEXP.
Referenced by bypass_conditional_jumps().
|
static |
Find basic blocks with more than one predecessor that only contain a single conditional jump. If the result of the comparison is known at compile-time from any incoming edge, redirect that edge to the appropriate target. Return nonzero if a change was made. This function is now mis-named, because we also handle indirect jumps.
References any_condjump_p(), bypass_block(), cfun, changed, commit_edge_insertions(), computed_jump_p(), DEBUG_INSN_P, cprop_expr::dest, ENTRY_BLOCK_PTR_FOR_FN, EXIT_BLOCK_PTR_FOR_FN, FOR_BB_BETWEEN, FOR_BB_INSNS, GET_CODE, INSN_P, JUMP_P, mark_dfs_back_edges(), basic_block_def::next_bb, NONJUMP_INSN_P, NULL, onlyjump_p(), PATTERN(), REG_P, SET, SET_DEST, and single_pred_p().
Referenced by one_cprop_pass().
|
static |
Hash table support.
Top level routine to do the dataflow analysis needed by copy/const propagation.
References bitmap_set_bit, cfun, compute_available(), compute_local_properties(), cprop_avin, cprop_avloc, cprop_avout, cprop_kill, FOR_EACH_BB_FN, implicit_set_indexes, basic_block_def::index, and set_hash_table.
Referenced by one_cprop_pass().
|
static |
Compute the hash TABLE for doing copy/const propagation or expression hash table.
References compute_hash_table_work(), and table.
|
static |
Top level function to create an assignment hash table. Assignment entries are placed in the hash table if - they are of the form (set (pseudo-reg) src), - src is something we want to perform const/copy propagation on, - none of the operands or target are subsequently modified in the block Currently src must be a pseudo-reg or a const_int. TABLE is the table computed.
References ALLOC_REG_SET, BB_HEAD, cfun, CLEAR_REG_SET, FOR_BB_INSNS_REVERSE, FOR_EACH_BB_FN, FREE_REG_SET, hash_scan_insn(), hash_scan_set(), implicit_sets, basic_block_def::index, make_set_regs_unavailable(), NONDEBUG_INSN_P, NULL, NULL_RTX, reg_set_bitmap, and table.
Referenced by compute_hash_table().
|
static |
Compute the local properties of each recorded expression. Local properties are those that are defined by the block, irrespective of other blocks. An expression is killed in a block if its operands, either DEST or SRC, are modified in the block. An expression is computed (locally available) in a block if it is computed at least once and expression would contain the same value if the computation was moved to the end of the block. KILL and COMP are destination sbitmaps for recording local properties.
References expr::avail_occr, expr::bitmap_index, bitmap_set_bit, bitmap_vector_clear(), BLOCK_FOR_INSN(), cfun, comp, DF_REF_BB, DF_REF_NEXT_REG, DF_REG_DEF_CHAIN, expr, i, basic_block_def::index, occr::insn, kill, last_basic_block_for_fn, occr::next, NULL, REG_P, REGNO, and table.
Referenced by compute_cprop_data().
Subroutine of cprop_insn that tries to propagate constants. FROM is what we will try to replace, SRC is the constant we will try to substitute for it and INSN is the instruction where this will be happening.
References any_condjump_p(), BLOCK_FOR_INSN(), cprop_jump(), cprop_expr::dest, next_insn(), next_nondebug_insn(), NONJUMP_INSN_P, NULL, onlyjump_p(), REG_P, SET_DEST, single_set(), cprop_expr::src, and try_replace_reg().
Referenced by cprop_insn(), and do_local_cprop().
|
static |
Cover function to obstack_alloc.
References bytes_used, cprop_obstack, and hash_table_d::size.
Determine whether the rtx X should be treated as a constant for CPROP. Since X might be inserted more than once we have to take care that it is sharable.
References CONSTANT_P, GET_CODE, and shared_const_p().
Referenced by cprop_insn(), do_local_cprop(), find_avail_set(), find_bypass_set(), hash_scan_set(), and implicit_set_cond_p().
Perform constant and copy propagation on INSN. Return true if a change was made.
References changed, constprop_register(), cprop_constant_p(), cprop_reg_p(), DEBUG_INSN_P, rtx_insn::deleted(), dump_file, find_avail_set(), find_reg_equal_equiv_note(), find_used_regs(), global_const_prop_count, global_copy_prop_count, i, INSN_UID(), note_uses(), NULL, PATTERN(), print_rtl(), reg_not_set_p(), reg_use_count, reg_use_table, REGNO, set::src, try_replace_reg(), and XEXP.
Referenced by one_cprop_pass().
|
static |
Subroutine of cprop_insn that tries to propagate constants into JUMP_INSNS. JUMP must be a conditional jump. If SETCC is non-NULL it is the instruction that immediately precedes JUMP, and must be a single SET of a register. FROM is what we will try to replace, SRC is the constant we will try to substitute for it. Return true if a change was made.
References BB_HEAD, cfun, copy_rtx(), delete_insn(), dump_file, EXIT_BLOCK_PTR_FOR_FN, find_reg_equal_equiv_note(), FOR_EACH_EDGE, GET_CODE, global_const_prop_count, INSN_UID(), JUMP_LABEL, modified_between_p(), modified_in_p(), NULL, NULL_RTX, pc_rtx, pc_set(), print_rtl(), purge_dead_edges(), REGNO, remove_note(), rtx_equal_p(), SET_DEST, SET_SRC, set_unique_reg_note(), simplejump_p(), simplify_replace_rtx(), single_set(), cprop_expr::src, basic_block_def::succs, validate_unshare_change(), and XEXP.
Referenced by constprop_register().
Determine whether the rtx X should be treated as a register that can be propagated. Any pseudo-register is fine.
References HARD_REGISTER_P, and REG_P.
Referenced by cprop_insn(), do_local_cprop(), hash_scan_set(), and implicit_set_cond_p().
Try to perform local const/copy propagation on X in INSN.
References asm_noperands(), constprop_register(), cprop_constant_p(), cprop_reg_p(), cselib_lookup(), dump_file, find_reg_note(), GET_CODE, GET_MODE, INSN_UID(), elt_loc_list::loc, local_const_prop_count, local_copy_prop_count, cselib_val::locs, MEM_P, elt_loc_list::next, NULL, NULL_RTX, PATTERN(), print_rtl(), REG_P, REGNO, elt_loc_list::setting_insn, try_replace_reg(), and XEXP.
Referenced by local_cprop_pass().
|
static |
Dump the hash table TABLE to file FILE under the name NAME.
References expr::bitmap_index, expr, free(), i, NULL, print_rtl(), and table.
Referenced by one_cprop_pass().
|
static |
All the passes implemented in this file. Each pass has its own gate and execute function, and at the end of the file a pass definition for passes.cc. We do not construct an accurate cfg in functions which call setjmp, so none of these passes runs if the function calls setjmp. FIXME: Should just handle setjmp via REG_SETJMP notes.
References changed, cleanup_cfg(), CLEANUP_CFG_CHANGED, delete_unreachable_blocks(), df_analyze(), DF_LR_RUN_DCE, df_set_flags(), flag_rerun_cse_after_global_opts, and one_cprop_pass().
|
static |
Find a set of REGNOs that are available on entry to INSN's block. If found, SET_RET[0] will be assigned a set with a register source and SET_RET[1] a set with a constant source. If not found the corresponding entry is set to NULL.
References bitmap_bit_p, BLOCK_FOR_INSN(), cprop_avin, cprop_constant_p(), lookup_set(), next_set(), NULL, reg_not_set_p(), REG_P, REGNO, set_hash_table, cprop_expr::src, and set::src.
Referenced by cprop_insn().
|
static |
Find a set of REGNO to a constant that is available at the end of basic block BB. Return NULL if no such set is found. Based heavily upon find_avail_set.
References bitmap_bit_p, cprop_avout, cprop_constant_p(), lookup_set(), next_set(), REG_P, REGNO, set_hash_table, cprop_expr::src, and set::src.
Referenced by bypass_block().
|
static |
Find the implicit sets of a function. An "implicit set" is a constraint on the value of a variable, implied by a conditional jump. For example, following "if (x == 2)", the then branch may be optimized as though the conditional performed an "explicit set", in this example, "x = 2". This function records the set patterns that are implicit at the start of each basic block. If an implicit set is found but the set is implicit on a critical edge, this critical edge is split. Return true if the CFG was modified, false otherwise.
References BB_END, BRANCH_EDGE, cfun, count, dump_file, EDGE_COUNT, EXIT_BLOCK_PTR_FOR_FN, FALLTHRU_EDGE, find_edge(), fis_get_condition(), FOR_EACH_BB_FN, GET_CODE, implicit_set_cond_p(), implicit_sets, basic_block_def::index, last_basic_block_for_fn, REGNO, single_pred_p(), split_edge(), basic_block_def::succs, and XEXP.
Referenced by one_cprop_pass().
|
static |
Set up a list of register numbers used in INSN. The found uses are stored in `reg_use_table'. `reg_use_count' is initialized to zero before entry, and contains the number of uses in the table upon exit. ??? If a register appears multiple times we will record it multiple times. This doesn't hurt anything but it will slow things down.
References find_used_regs(), GET_CODE, GET_RTX_FORMAT, GET_RTX_LENGTH, i, MAX_USES, REG_P, reg_use_count, reg_use_table, XEXP, XVECEXP, and XVECLEN.
Referenced by bypass_block(), cprop_insn(), find_used_regs(), and local_cprop_find_used_regs().
Similar to get_condition, only the resulting condition must be valid at JUMP, instead of at EARLIEST. This differs from noce_get_condition in ifcvt.cc in that we prefer not to settle for the condition variable in the jump instruction being integral. We prefer to be able to record the value of a user variable, rather than the value of a temporary used in a condition. This could be solved by recording the value of *every* register scanned by canonicalize_condition, but this would require some code reorganization.
References get_condition(), and NULL.
Referenced by find_implicit_sets(), and reload_cse_move2add_invalidate().
|
static |
Free vars used by copy/const propagation.
References cprop_avin, cprop_avloc, cprop_avout, cprop_kill, and sbitmap_vector_free().
Referenced by one_cprop_pass().
|
static |
Free things allocated by alloc_hash_table.
Referenced by one_cprop_pass().
|
static |
Hash a set of register REGNO. Sets are hashed on the register that is set. This simplifies the PRE copy propagation code. ??? May need to make things more elaborate. Later, as necessary.
Referenced by insert_set_in_table(), and lookup_set().
|
static |
Process INSN and add hash table entries as appropriate.
References GET_CODE, hash_scan_set(), i, cprop_occr::insn, PATTERN(), SET, table, XVECEXP, and XVECLEN.
Referenced by compute_hash_table_work().
|
static |
Scan SET present in INSN and add an entry to the hash TABLE. IMPLICIT is true if it's an implicit set, false otherwise.
References can_copy_p(), cprop_constant_p(), cprop_reg_p(), find_reg_equal_equiv_note(), GET_MODE, insert_set_in_table(), cprop_occr::insn, reg_available_p(), REG_NOTE_KIND, REG_P, SET_DEST, SET_SRC, table, and XEXP.
Referenced by compute_hash_table_work(), and hash_scan_insn().
Check the comparison COND to see if we can safely form an implicit set from it.
References CONST_DOUBLE_AS_FLOAT_P, CONST_DOUBLE_REAL_VALUE, cprop_constant_p(), cprop_reg_p(), dconst0, GET_CODE, GET_MODE, HONOR_SIGNED_ZEROS(), real_equal(), and XEXP.
Referenced by find_implicit_sets().
|
static |
Insert assignment DEST:=SET from INSN in the hash table. DEST is a register and SET is a register or a suitable constant. If the assignment is already present in the table, record it as the last occurrence in INSN's basic block. IMPLICIT is true if it's an implicit set, false otherwise.
References cprop_expr::avail_occr, cprop_expr::bitmap_index, BLOCK_FOR_INSN(), bytes_used, copy_rtx(), cprop_expr::dest, GOBNEW, hash_mod(), implicit_set_indexes, basic_block_def::index, cprop_occr::insn, cprop_occr::next, cprop_expr::next_same_hash, NULL, REGNO, cprop_expr::src, and table.
Referenced by hash_scan_set().
|
static |
Like find_used_regs, but avoid recording uses that appear in input-output contexts such as zero_extract or pre_dec. This restricts the cases we consider to those for which local cprop can legitimately make replacements.
References find_used_regs(), GET_CODE, and read_modify_subreg_p().
Referenced by local_cprop_pass().
|
static |
Do local const/copy propagation (i.e. within each basic block).
References BLOCK_FOR_INSN(), cfun, changed, const1_rtx, cselib_clear_table(), cselib_finish(), cselib_init(), cselib_process_insn(), DEBUG_INSN_P, rtx_insn::deleted(), do_local_cprop(), emit_barrier_after_bb(), find_reg_equal_equiv_note(), FOR_BB_INSNS, FOR_EACH_BB_FN, GET_CODE, i, INSN_P, local_cprop_find_used_regs(), note_uses(), NULL, PATTERN(), reg_use_count, reg_use_table, remove_edge(), split_block(), and XEXP.
Referenced by one_cprop_pass().
|
static |
Expression tracking support.
Lookup REGNO in the set TABLE. The result is a pointer to the table entry, or NULL if not found.
References expr, hash_mod(), REGNO, and table.
Referenced by find_avail_set(), and find_bypass_set().
rtl_opt_pass * make_pass_rtl_cprop | ( | gcc::context * | ctxt | ) |
|
static |
Record as unavailable all registers that are DEF operands of INSN.
References DF_REF_REGNO, FOR_EACH_INSN_DEF, reg_set_bitmap, and SET_REGNO_REG_SET.
Referenced by compute_hash_table_work().
|
static |
Record things set by INSN. This data is used by reg_not_set_p.
References DF_REF_REGNO, FOR_EACH_INSN_DEF, reg_set_bitmap, and SET_REGNO_REG_SET.
Referenced by one_cprop_pass().
|
static |
Return the next entry for REGNO in list EXPR.
Referenced by find_avail_set(), and find_bypass_set().
|
static |
Main function for the CPROP pass.
References _, alloc_cprop_mem(), alloc_hash_table(), ALLOC_REG_SET, BLOCK_FOR_INSN(), bypass_conditional_jumps(), bypass_last_basic_block, bytes_used, cfun, changed, compute_cprop_data(), compute_hash_table(), const1_rtx, cprop_insn(), cprop_obstack, current_function_name(), delete_unreachable_blocks(), rtx_insn::deleted(), df_analyze(), dump_file, dump_hash_table(), emit_barrier_after_bb(), ENTRY_BLOCK_PTR_FOR_FN, EXIT_BLOCK_PTR_FOR_FN, find_implicit_sets(), FOR_BB_BETWEEN, FOR_BB_INSNS, free(), free_cprop_mem(), free_hash_table(), FREE_REG_SET, gcc_obstack_init, gcse_or_cprop_is_too_expensive(), GET_CODE, global_const_prop_count, global_copy_prop_count, i, implicit_set_indexes, implicit_sets, INSN_P, last_basic_block_for_fn, local_const_prop_count, local_copy_prop_count, local_cprop_pass(), mark_oprs_set(), n_basic_blocks_for_fn, hash_table_d::n_elems, basic_block_def::next_bb, NOTE_P, NULL, NUM_FIXED_BLOCKS, PATTERN(), reg_set_bitmap, remove_edge(), reset_opr_set_tables(), set_hash_table, set_insn_deleted(), split_block(), and XEXP.
Referenced by execute_rtl_cprop().
Return true if register X is unchanged from INSN to the end of INSN's basic block.
References reg_set_bitmap, REGNO, and REGNO_REG_SET_P.
Referenced by hash_scan_set().
|
static |
Subroutine of bypass_block that checks whether a pseudo is killed by any of the instructions inserted on an edge. Jump bypassing places condition code setters on CFG edges using insert_insn_on_edge. This function is required to check that our data flow analysis is still valid prior to commit_edge_insertions.
References INSN_P, NEXT_INSN(), and reg_set_p().
Referenced by bypass_block().
Return true if the register X has not been set yet [since the start of the basic block containing INSN].
References reg_set_bitmap, REGNO, and REGNO_REG_SET_P.
Referenced by cprop_insn(), and find_avail_set().
|
static |
Reset tables used to keep track of what's still available [since the start of the block].
References CLEAR_REG_SET, and reg_set_bitmap.
Referenced by one_cprop_pass().
Try to replace all uses of FROM in INSN with TO. Return true if successful.
References apply_change_group(), BLOCK_FOR_INSN(), cancel_changes(), CONSTANT_P, contains_paradoxical_subreg_p(), copy_rtx(), find_reg_equal_equiv_note(), GET_CODE, cprop_occr::insn, MEM_P, num_changes_pending(), optimize_bb_for_speed_p(), reg_mentioned_p(), REG_NOTE_KIND, REG_P, remove_note(), rtx_equal_p(), SET_DEST, set_rtx_cost(), SET_SRC, set_unique_reg_note(), simplify_replace_rtx(), simplify_rtx(), single_set(), validate_change(), validate_replace_src_group(), and XEXP.
Referenced by constprop_register(), cprop_insn(), and do_local_cprop().
|
static |
Bypass conditional jumps.
The value of last_basic_block at the beginning of the jump_bypass pass. The use of redirect_edge_and_branch_force may introduce new basic blocks, but the data flow analysis is only valid for basic block indices less than bypass_last_basic_block.
Referenced by bypass_block(), and one_cprop_pass().
|
static |
Various variables for statistics gathering.
Memory used in a pass. This isn't intended to be absolutely precise. Its intent is only to keep an eye on memory usage.
Referenced by cprop_alloc(), insert_set_in_table(), and one_cprop_pass().
|
static |
Global properties of assignments (computed from the local properties).
Referenced by alloc_cprop_mem(), compute_cprop_data(), find_avail_set(), and free_cprop_mem().
|
static |
Compute copy/constant propagation working variables.
Local properties of assignments.
Referenced by alloc_cprop_mem(), compute_cprop_data(), and free_cprop_mem().
|
static |
Referenced by alloc_cprop_mem(), compute_cprop_data(), find_bypass_set(), and free_cprop_mem().
|
static |
Referenced by alloc_cprop_mem(), compute_cprop_data(), and free_cprop_mem().
|
static |
Global constant/copy propagation for RTL. Copyright (C) 1997-2024 Free Software Foundation, Inc. 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/>.
An obstack for our working variables.
Referenced by cprop_alloc(), and one_cprop_pass().
|
static |
Number of global constants propagated.
Referenced by cprop_insn(), cprop_jump(), and one_cprop_pass().
|
static |
Number of global copies propagated.
Referenced by cprop_insn(), and one_cprop_pass().
|
static |
Array of indexes of expressions for implicit set patterns indexed by basic block index. In other words, implicit_set_indexes[i] is the bitmap_index of the expression whose RTX is implicit_sets[i].
Referenced by compute_cprop_data(), insert_set_in_table(), and one_cprop_pass().
|
static |
Array of implicit set patterns indexed by basic block index.
Referenced by compute_hash_table_work(), find_implicit_sets(), and one_cprop_pass().
|
static |
Number of local constants propagated.
Referenced by do_local_cprop(), and one_cprop_pass().
|
static |
Number of local copies propagated.
Referenced by do_local_cprop(), and one_cprop_pass().
|
static |
Bitmap containing one bit for each register in the program. Used when performing GCSE to track which registers have been set since the start or end of the basic block while traversing that block.
Referenced by compute_hash_table_work(), make_set_regs_unavailable(), mark_oprs_set(), one_cprop_pass(), reg_available_p(), reg_not_set_p(), and reset_opr_set_tables().
|
static |
Index into `reg_use_table' while building it.
Referenced by bypass_block(), cprop_insn(), find_used_regs(), and local_cprop_pass().
Table of uses (registers, both hard and pseudo) found in an insn. Allocated statically to avoid alloc/free complexity and overhead.
Referenced by bypass_block(), cprop_insn(), find_used_regs(), and local_cprop_pass().
|
static |
Copy propagation hash table.
Referenced by compute_cprop_data(), find_avail_set(), find_bypass_set(), and one_cprop_pass().