GCC Middle and Back End API Reference
|
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "backend.h"
#include "target.h"
#include "rtl.h"
#include "df.h"
#include "memmodel.h"
#include "tm_p.h"
#include "insn-config.h"
#include "regs.h"
#include "emit-rtl.h"
#include "recog.h"
#include "addresses.h"
#include "cfganal.h"
#include "tree-pass.h"
#include "function-abi.h"
#include "regrename.h"
Data Structures | |
struct | incoming_reg_info |
class | bb_rename_info |
Enumerations | |
enum | scan_actions { terminate_write , terminate_dead , mark_all_read , mark_read , mark_write , mark_access } |
Functions | |
static void | scan_rtx (rtx_insn *, rtx *, enum reg_class, enum scan_actions, enum op_type) |
static bool | build_def_use (basic_block) |
du_head_p | regrename_chain_from_id (unsigned int id) |
static void | dump_def_use_chain (int from) |
static void | free_chain_data (void) |
static void | mark_conflict (class du_head *chains, unsigned id) |
static void | record_operand_use (class du_head *head, struct du_chain *this_du) |
static du_head_p | create_new_chain (unsigned this_regno, unsigned this_nregs, rtx *loc, rtx_insn *insn, enum reg_class cl) |
static void | merge_overlapping_regs (HARD_REG_SET *pset, class du_head *head) |
static bool | call_clobbered_in_chain_p (du_head *this_head, machine_mode mode, unsigned int regno) |
static bool | check_new_reg_p (int reg, int new_reg, class du_head *this_head, HARD_REG_SET this_unavailable) |
int | find_rename_reg (du_head_p this_head, enum reg_class super_class, HARD_REG_SET *unavailable, int old_reg, bool best_rename) |
reg_class | regrename_find_superclass (du_head_p head, int *pn_uses, HARD_REG_SET *punavailable) |
static void | rename_chains (void) |
static void | init_rename_info (class bb_rename_info *p, basic_block bb) |
static void | set_incoming_from_chain (class bb_rename_info *ri, du_head_p chain) |
static void | merge_chains (du_head_p c1, du_head_p c2) |
void | regrename_analyze (bitmap bb_mask, bool include_all_block_p) |
bool | regrename_do_replace (class du_head *head, int reg) |
static bool | verify_reg_in_set (rtx op, HARD_REG_SET *pset) |
static bool | verify_reg_tracked (rtx op) |
static void | note_sets_clobbers (rtx x, const_rtx set, void *data) |
static void | scan_rtx_reg (rtx_insn *insn, rtx *loc, enum reg_class cl, enum scan_actions action, enum op_type type) |
static reg_class | base_reg_class_for_rename (rtx_insn *insn, machine_mode mode, addr_space_t as, rtx_code code, rtx_code index_code) |
static void | scan_rtx_address (rtx_insn *insn, rtx *loc, enum reg_class cl, enum scan_actions action, machine_mode mode, addr_space_t as) |
static void | hide_operands (int n_ops, rtx *old_operands, rtx *old_dups, unsigned HOST_WIDE_INT do_not_hide, bool inout_and_ec_only) |
static void | restore_operands (rtx_insn *insn, int n_ops, rtx *old_operands, rtx *old_dups) |
static void | record_out_operands (rtx_insn *insn, bool earlyclobber, insn_rr_info *insn_info) |
void | regrename_init (bool insn_info) |
void | regrename_finish (void) |
static unsigned int | regrename_optimize (void) |
rtl_opt_pass * | make_pass_regrename (gcc::context *ctxt) |
Variables | |
static const char *const | scan_actions_name [] |
static int | tick [FIRST_PSEUDO_REGISTER] |
static int | this_tick = 0 |
static struct obstack | rename_obstack |
vec< insn_rr_info > | insn_rr |
static unsigned | current_id |
static vec< du_head_p > | id_to_chain |
static class du_head * | open_chains |
static bitmap_head | open_chains_set |
static HARD_REG_SET | live_in_chains |
static HARD_REG_SET | live_hard_regs |
static operand_rr_info * | cur_operand |
static class du_head * | terminated_this_insn |
static bool | fail_current_block |
enum scan_actions |
Register renaming for the GNU compiler. Copyright (C) 2000-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/>.
This file implements the RTL register renaming pass of the compiler. It is a semi-local pass whose goal is to maximize the usage of the register file of the processor by substituting registers for others in the solution given by the register allocator. The algorithm is as follows: 1. Local def/use chains are built: within each basic block, chains are opened and closed; if a chain isn't closed at the end of the block, it is dropped. We pre-open chains if we have already examined a predecessor block and found chains live at the end which match live registers at the start of the new block. 2. We try to combine the local chains across basic block boundaries by comparing chains that were open at the start or end of a block to those in successor/predecessor blocks. 3. For each chain, the set of possible renaming registers is computed. This takes into account the renaming of previously processed chains. Optionally, a preferred class is computed for the renaming register. 4. The best renaming register is computed for the chain in the above set, using a round-robin allocation. If a preferred class exists, then the round-robin allocation is done within the class first, if possible. The round-robin allocation of renaming registers itself is global. 5. If a renaming register has been found, it is substituted in the chain. Targets can parameterize the pass by specifying a preferred class for the renaming register for a given (super)class of registers to be renamed. DEBUG_INSNs are treated specially, in particular registers occurring inside them are treated as requiring ALL_REGS as a class.
Enumerator | |
---|---|
terminate_write | |
terminate_dead | |
mark_all_read | |
mark_read | |
mark_write | |
mark_access |
|
static |
A wrapper around base_reg_class which returns ALL_REGS if INSN is a DEBUG_INSN. The arguments MODE, AS, CODE and INDEX_CODE are as for base_reg_class.
References base_reg_class(), DEBUG_INSN_P, and du_chain::insn.
Referenced by scan_rtx(), and scan_rtx_address().
|
static |
Build def/use chain.
References ADDR_SPACE_GENERIC, alternative_class(), asm_noperands(), BB_END, BB_HEAD, du_head::call_abis, du_head::call_clobber_mask, CALL_INSN_FUNCTION_USAGE, CALL_P, recog_data_d::constraints, create_new_chain(), cur_operand, DEBUG_BIND_INSN_P, recog_data_d::dup_loc, recog_data_d::dup_num, extract_constrain_insn(), fail_current_block, find_regno_note(), function_abi::full_and_partial_reg_clobbers(), function_abi::full_reg_clobbers(), GET_CODE, GET_MODE, GET_MODE_SIZE(), du_head::hard_conflicts, hide_operands(), i, function_abi::id(), IN_RANGE, insn_callee_abi(), insn_rr, INSN_UID(), INSN_VAR_LOCATION_LOC, live_hard_regs, live_in_chains, mark_access, mark_all_read, mark_read, operand_alternative::matches, recog_data_d::n_dups, recog_data_d::n_operands, du_head::next_chain, NEXT_INSN(), NONDEBUG_INSN_P, note_sets_clobbers(), note_stores(), NULL, OP_IN, insn_rr_info::op_info, OP_INOUT, OP_OUT, open_chains, recog_data_d::operand, recog_data_d::operand_loc, recog_data_d::operand_mode, recog_data_d::operand_type, ORIGINAL_REGNO, PATTERN(), preprocess_constraints(), recog_data, record_out_operands(), REG_NOTE_KIND, REG_NOTES, REG_NREGS, REG_P, REGNO, remove_from_hard_reg_set(), rename_obstack, restore_operands(), scan_rtx(), scan_rtx_address(), SET, SET_DEST, terminate_dead, terminate_write, terminated_this_insn, VAR_LOC_UNKNOWN_P, verify_reg_in_set(), verify_reg_tracked(), which_op_alt(), XEXP, and XVECEXP.
Referenced by regrename_analyze().
|
static |
Return true if (reg:MODE REGNO) would be clobbered by a call covered by THIS_HEAD.
References du_head::call_abis, du_head::call_clobber_mask, and call_clobbered_in_region_p().
Referenced by check_new_reg_p().
|
static |
Check if NEW_REG can be the candidate register to rename for REG in THIS_HEAD chain. THIS_UNAVAILABLE is a set of unavailable hard registers.
References call_clobbered_in_chain_p(), crtl, DEBUG_INSN_P, df_regs_ever_live_p(), du_head::first, fixed_regs, GET_MODE, global_regs, HARD_REGNO_RENAME_OK, i, du_chain::insn, du_chain::loc, du_chain::next_use, du_head::nregs, targetm, and TEST_HARD_REG_BIT.
Referenced by find_rename_reg().
|
static |
Create a new chain for THIS_NREGS registers starting at THIS_REGNO, and record its occurrence in *LOC, which is being written to in INSN. This access requires a register of class CL.
References bitmap_copy(), bitmap_default_obstack, bitmap_initialize(), bitmap_set_bit, du_chain::cl, CLEAR_HARD_REG_BIT, current_id, dump_file, head::first, id_to_chain, du_chain::insn, INSN_UID(), head::last, live_hard_regs, live_in_chains, du_chain::loc, mark_conflict(), du_chain::next_use, NULL, NULL_RTX, open_chains, open_chains_set, record_operand_use(), reg_names, rename_obstack, and SET_HARD_REG_BIT.
Referenced by build_def_use(), init_rename_info(), and scan_rtx_reg().
|
static |
Dump all def/use chains, starting at id FROM.
References du_chain::cl, dump_file, head::first, FOR_EACH_VEC_ELT_FROM, i, id_to_chain, du_chain::insn, INSN_UID(), du_chain::next_use, reg_class_names, and reg_names.
Referenced by regrename_analyze().
int find_rename_reg | ( | du_head_p | this_head, |
enum reg_class | super_class, | ||
HARD_REG_SET * | unavailable, | ||
int | old_reg, | ||
bool | best_rename ) |
For the chain THIS_HEAD, compute and return the best register to rename to. SUPER_CLASS is the superunion of register classes in the chain. UNAVAILABLE is a set of registers that cannot be used. OLD_REG is the register currently used for the chain. BEST_RENAME controls whether the register chosen must be better than the current one or just respect the given constraint.
References check_new_reg_p(), DEBUG_INSN_P, merge_overlapping_regs(), du_chain::next_use, noop_move_p(), reg_class_contents, targetm, TEST_HARD_REG_BIT, and tick.
Referenced by rename_chains().
|
static |
References bitmap_clear(), i, and id_to_chain.
Referenced by regrename_finish().
|
static |
Hide operands of the current insn (of which there are N_OPS) by substituting pc for them. Previous values are stored in the OLD_OPERANDS and OLD_DUPS. For every bit set in DO_NOT_HIDE, we leave the operand alone. If INOUT_AND_EC_ONLY is set, we only do this for OP_INOUT type operands and earlyclobbers.
References recog_data_d::constraints, recog_data_d::dup_loc, recog_data_d::dup_num, operand_alternative::earlyclobber, i, recog_data_d::n_dups, OP_INOUT, recog_data_d::operand, recog_data_d::operand_loc, recog_data_d::operand_type, pc_rtx, recog_data, and which_op_alt().
Referenced by build_def_use().
|
static |
Initialize a rename_info structure P for basic block BB, which starts a new scan.
References bb_rename_info::bb, bitmap_clear(), bitmap_default_obstack, bitmap_initialize(), bitmap_set_bit, CLEAR_HARD_REG_SET, create_new_chain(), df_get_live_in(), DF_REF_AT_TOP, DF_REF_FLAGS, DF_REF_REGNO, dump_file, FOR_EACH_ARTIFICIAL_DEF, i, bb_rename_info::incoming, bb_rename_info::incoming_open_chains_set, basic_block_def::index, live_hard_regs, live_in_chains, incoming_reg_info::nregs, NULL, open_chains, bb_rename_info::open_chains_set, open_chains_set, range_in_hard_reg_set_p(), REG_SET_TO_HARD_REG_SET, remove_range_from_hard_reg_set(), SET_HARD_REG_BIT, TEST_HARD_REG_BIT, and incoming_reg_info::unusable.
Referenced by regrename_analyze().
rtl_opt_pass * make_pass_regrename | ( | gcc::context * | ctxt | ) |
|
static |
Walk all chains starting with CHAINS and record that they conflict with another chain whose id is ID.
References bitmap_set_bit, du_head::conflicts, and du_head::next_chain.
Referenced by create_new_chain().
Merge the two chains C1 and C2 so that all conflict information is recorded and C1, and the id of C2 is changed to that of C1.
References bitmap_ior_into(), and NULL.
Referenced by regrename_analyze().
|
static |
For a def-use chain HEAD, find which registers overlap its lifetime and set the corresponding bits in *PSET.
References EXECUTE_IF_SET_IN_BITMAP, gcc_assert, i, regrename_chain_from_id(), and SET_HARD_REG_BIT.
Referenced by find_rename_reg().
Called through note_stores. DATA points to a rtx_code, either SET or CLOBBER, which tells us which kind of rtx to look at. If we have a match, record the set register in live_hard_regs and in the hard_conflicts bitmap of open chains.
References add_to_hard_reg_set(), gcc_assert, GET_CODE, GET_MODE, HARD_REGISTER_P, live_hard_regs, open_chains, REG_P, REGNO, and SUBREG_REG.
Referenced by build_def_use().
Examine cur_operand, and if it is nonnull, record information about the use THIS_DU which is part of the chain HEAD.
References operand_rr_info::chains, cur_operand, operand_rr_info::failed, gcc_assert, operand_rr_info::heads, operand_rr_info::n_chains, and NULL.
Referenced by create_new_chain(), and scan_rtx_reg().
|
static |
For each output operand of INSN, call scan_rtx to create a new open chain. Do this only for normal or earlyclobber outputs, depending on EARLYCLOBBER. If INSN_INFO is nonnull, use it to record information about the operands in the insn.
References alternative_class(), asm_noperands(), CALL_P, du_head::cannot_rename, du_chain::cl, cur_operand, recog_data_d::dup_loc, recog_data_d::dup_num, operand_alternative::earlyclobber, i, du_chain::loc, mark_write, recog_data_d::n_dups, recog_data_d::n_operands, NULL, insn_rr_info::op_info, OP_OUT, open_chains, recog_data_d::operand_loc, recog_data_d::operand_type, ORIGINAL_REGNO, PATTERN(), recog_data, REG_P, REGNO, scan_rtx(), terminate_write, and which_op_alt().
Referenced by build_def_use().
Analyze the current function and build chains for renaming. If INCLUDE_ALL_BLOCKS_P is set to true, process all blocks, ignoring BB_DISABLE_SCHEDULE. The default value is true.
References basic_block_def::aux, BASIC_BLOCK_FOR_FN, bb_rename_info::bb, bitmap_bit_p, bitmap_clear(), bitmap_copy(), bitmap_default_obstack, bitmap_initialize(), build_def_use(), cfun, current_id, df_get_live_in(), df_get_live_out(), dump_def_use_chain(), dump_file, EXECUTE_IF_SET_IN_BITMAP, basic_block_def::flags, FOR_BB_INSNS, FOR_EACH_BB_FN, FOR_EACH_EDGE, free(), i, du_head::id, id_to_chain, bb_rename_info::incoming_open_chains_set, basic_block_def::index, init_rename_info(), insn_rr, INSN_UID(), last_basic_block_for_fn, merge_chains(), n_basic_blocks_for_fn, du_head::nregs, NULL, insn_rr_info::op_info, open_chains, bb_rename_info::open_chains_set, open_chains_set, pre_and_rev_post_order_compute(), basic_block_def::preds, range_overlaps_hard_reg_set_p(), reg_names, REG_SET_TO_HARD_REG_SET, du_head::regno, regrename_chain_from_id(), set_incoming_from_chain(), and basic_block_def::succs.
Referenced by regrename_optimize().
du_head_p regrename_chain_from_id | ( | unsigned int | id | ) |
Return the chain corresponding to id number ID. Take into account that chains may have been merged.
References du_head::id, and id_to_chain.
Referenced by merge_overlapping_regs(), and regrename_analyze().
Attempt to replace all uses of the register in the chain beginning with HEAD with REG. Returns true on success and false if the replacement is rejected because the insns would not validate. The latter can happen e.g. if a match_parallel predicate enforces restrictions on register numbering in its subpatterns.
References apply_change_group(), DEBUG_INSN_P, head::first, gen_raw_REG(), gen_rtx_UNKNOWN_VAR_LOC, GET_MODE, hard_regno_nregs(), INSN_VAR_LOCATION_LOC, NULL_RTX, ORIGINAL_REGNO, REG_ATTRS, REG_POINTER, REGNO, and validate_change().
Referenced by rename_chains().
reg_class regrename_find_superclass | ( | du_head_p | head, |
int * | pn_uses, | ||
HARD_REG_SET * | punavailable ) |
Iterate over elements in the chain HEAD in order to: 1. Count number of uses, storing it in *PN_USES. 2. Narrow the set of registers we can use for renaming, adding unavailable registers to *PUNAVAILABLE, which must be initialized by the caller. 3. Compute the superunion of register classes in this chain and return it.
References DEBUG_INSN_P, head::first, and reg_class_superunion.
Referenced by rename_chains().
void regrename_finish | ( | void | ) |
Free all global data used by the register renamer.
References free_chain_data(), insn_rr, NULL, and rename_obstack.
Referenced by regrename_optimize().
void regrename_init | ( | bool | insn_info | ) |
Initialize the register renamer. If INSN_INFO is true, ensure that insn_rr is nonnull.
References gcc_obstack_init, get_max_uid(), insn_rr, and rename_obstack.
Referenced by regrename_optimize().
|
static |
Perform register renaming on the current function.
References df_analyze(), DF_DEFER_INSN_RESCAN, DF_LR_RUN_DCE, df_note_add_problem(), df_set_flags(), NULL, regrename_analyze(), regrename_finish(), regrename_init(), and rename_chains().
|
static |
Perform register renaming on the current function.
References add_to_hard_reg_set(), CLEAR_HARD_REG_SET, df_set_regs_ever_live(), dump_file, find_rename_reg(), fixed_regs, FOR_EACH_VEC_ELT, frame_pointer_needed, global_regs, HARD_FRAME_POINTER_IS_FRAME_POINTER, HARD_FRAME_POINTER_REGNUM, i, id_to_chain, INSN_UID(), reg_names, regrename_do_replace(), regrename_find_superclass(), this_tick, and tick.
Referenced by regrename_optimize().
|
static |
Undo the substitution performed by hide_operands. INSN is the insn we are processing; the arguments are the same as in hide_operands.
References df_insn_rescan(), recog_data_d::dup_loc, i, du_chain::insn, recog_data_d::n_dups, recog_data_d::operand_loc, and recog_data.
Referenced by build_def_use().
|
static |
References base_reg_class_for_rename(), CASE_CONST_ANY, du_chain::cl, gcc_unreachable, GET_CODE, GET_MODE, GET_RTX_FORMAT, GET_RTX_LENGTH, i, du_chain::insn, du_chain::loc, MEM_ADDR_SPACE, OP_IN, OP_INOUT, OP_OUT, PATTERN(), scan_rtx(), scan_rtx_address(), scan_rtx_reg(), SET, SET_DEST, SET_SRC, verify_reg_tracked(), XEXP, XVECEXP, and XVECLEN.
Referenced by build_def_use(), record_out_operands(), and scan_rtx().
|
static |
Adapted from find_reloads_address_1. CL is INDEX_REG_CLASS or BASE_REG_CLASS depending on how the register is being considered.
References AUTO_INC_DEC, base_reg_class_for_rename(), du_chain::cl, DEBUG_INSN_P, GET_CODE, GET_MODE, GET_RTX_FORMAT, GET_RTX_LENGTH, i, du_chain::insn, du_chain::loc, mark_access, mark_all_read, mark_write, MEM_ADDR_SPACE, NULL, OP_IN, REGNO, regno_ok_for_base_p(), RTX_CODE, scan_rtx_address(), scan_rtx_reg(), SUBREG_REG, XEXP, XVECEXP, and XVECLEN.
Referenced by build_def_use(), scan_rtx(), and scan_rtx_address().
|
static |
References bitmap_bit_p, bitmap_clear_bit(), du_chain::cl, CLEAR_HARD_REG_BIT, create_new_chain(), DEBUG_INSN_P, dump_file, fail_current_block, head::first, gcc_assert, GET_CODE, du_head::id, du_chain::insn, INSN_UID(), head::last, live_hard_regs, live_in_chains, du_chain::loc, mark_access, mark_read, mark_write, recog_data_d::n_operands, du_chain::next_use, du_head::nregs, NULL, OP_OUT, open_chains, open_chains_set, recog_data_d::operand, PATTERN(), recog_data, record_operand_use(), reg_names, REG_NREGS, REGNO, du_head::regno, rename_obstack, scan_actions_name, SET, SET_DEST, SET_HARD_REG_BIT, SET_SRC, terminate_dead, terminate_write, terminated_this_insn, and du_head::tied_chain.
Referenced by scan_rtx(), and scan_rtx_address().
|
static |
Record in RI that the block corresponding to it has an incoming live value, described by CHAIN.
References dump_file, i, bb_rename_info::incoming, incoming_reg_info::nregs, and incoming_reg_info::unusable.
Referenced by regrename_analyze().
|
static |
Return true if OP is a reg for which all bits are set in PSET, false if all bits are clear. In other cases, set fail_current_block and return false.
References fail_current_block, REG_NREGS, REG_P, REGNO, and TEST_HARD_REG_BIT.
Referenced by build_def_use(), and verify_reg_tracked().
Return true if OP is a reg that is being tracked already in some form. May set fail_current_block if it sees an unhandled case of overlap.
References live_hard_regs, live_in_chains, and verify_reg_in_set().
Referenced by build_def_use(), and scan_rtx().
|
static |
Set while scanning RTL if INSN_RR is nonnull, i.e. if the current analysis is for a caller that requires operand data. Used in record_operand_use.
Referenced by build_def_use(), record_operand_use(), and record_out_operands().
|
static |
The id to be given to the next opened chain.
Referenced by create_new_chain(), and regrename_analyze().
|
static |
True if we found a register with a size mismatch, which means that we can't track its lifetime accurately. If so, we abort the current block without renaming.
Referenced by build_def_use(), scan_rtx_reg(), and verify_reg_in_set().
A mapping of unique id numbers to chains.
Referenced by create_new_chain(), dump_def_use_chain(), free_chain_data(), regrename_analyze(), regrename_chain_from_id(), and rename_chains().
vec<insn_rr_info> insn_rr |
If nonnull, the code calling into the register renamer requested information about insn operands, and we store it here.
Referenced by build_def_use(), regrename_analyze(), regrename_finish(), and regrename_init().
|
static |
Record the registers that are live but not tracked. The intersection between this and live_in_chains is empty.
Referenced by build_def_use(), create_new_chain(), do_remat(), inherit_in_ebb(), init_rename_info(), note_sets_clobbers(), scan_rtx_reg(), and verify_reg_tracked().
|
static |
Record the registers being tracked in open_chains.
Referenced by build_def_use(), create_new_chain(), init_rename_info(), scan_rtx_reg(), and verify_reg_tracked().
|
static |
List of currently open chains.
Referenced by build_def_use(), create_new_chain(), init_rename_info(), note_sets_clobbers(), record_out_operands(), regrename_analyze(), and scan_rtx_reg().
|
static |
Bitmap of open chains. The bits set always match the list found in open_chains.
Referenced by create_new_chain(), init_rename_info(), regrename_analyze(), and scan_rtx_reg().
|
static |
Referenced by build_def_use(), create_new_chain(), regrename_finish(), regrename_init(), and scan_rtx_reg().
|
static |
Referenced by scan_rtx_reg().
|
static |
Set while scanning RTL if a register dies. Used to tie chains.
Referenced by build_def_use(), and scan_rtx_reg().
|
static |
Referenced by rename_chains().
|
static |
TICK and THIS_TICK are used to record the last time we saw each register.
Referenced by find_rename_reg(), get_last_value_validate(), graphds_dfs(), and rename_chains().