GCC Middle and Back End API Reference
|
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "backend.h"
#include "rtl.h"
#include "df.h"
#include "insn-config.h"
#include "regs.h"
#include "memmodel.h"
#include "ira.h"
#include "recog.h"
#include "lra.h"
#include "lra-int.h"
#include "function-abi.h"
Data Structures | |
struct | cand |
class | remat_bb_data |
Typedefs | |
typedef struct cand * | cand_t |
typedef const struct cand * | const_cand_t |
typedef class remat_bb_data * | remat_bb_data_t |
Variables | |
static unsigned int | cands_num |
static bitmap_head | temp_bitmap |
static bitmap_head | subreg_regs |
static vec< cand_t > | all_cands |
static cand_t * | insn_to_cand |
static cand_t * | insn_to_cand_activation |
static cand_t * | regno_cands |
static bitmap_head | all_blocks |
static remat_bb_data_t | remat_bb_data |
static htab_t | cand_table |
int | lra_rematerialization_iter |
typedef const struct cand* const_cand_t |
typedef class remat_bb_data* remat_bb_data_t |
Array for all BB data. Indexed by the corresponding BB index.
Return true if X contains memory or some UNSPEC. We cannot just check insn operands as memory or unspec might be not an operand itself but contain an operand. Insn with memory access is not profitable for rematerialization. Rematerialization of UNSPEC might result in wrong code generation as the UNPEC effect is unknown (e.g. generating a label).
References bad_for_rematerialization_p(), GET_CODE, GET_RTX_FORMAT, GET_RTX_LENGTH, i, MEM_P, XEXP, XVECEXP, and XVECLEN.
Referenced by bad_for_rematerialization_p(), and operand_to_remat().
|
static |
Calculate gen_cands for each BB.
References bitmap_and_compl_into(), bitmap_clear(), bitmap_clear_bit(), bitmap_set_bit, CALL_P, call_used_input_regno_present_p(), cfun, EXECUTE_IF_SET_IN_BITMAP, find_regno_note(), FOR_BB_INSNS, FOR_EACH_BB_FN, gcc_assert, get_remat_bb_data(), lra_static_insn_data::hard_regs, cand::index, lra_insn_recog_data::insn, insn_callee_abi(), INSN_P, insn_to_cand, INSN_UID(), lra_get_insn_recog_data(), lra_insn_reg::next, NULL, OP_IN, reg_obstack, reg_overlap_for_remat_p(), REG_P, REGNO, cand::regno, lra_insn_reg::regno, cand::reload_regno, SET_DEST, SET_SRC, single_set(), temp_bitmap, and lra_insn_reg::type.
Referenced by lra_remat().
|
static |
Calculate available candidates for each BB.
References all_blocks, bitmap_copy(), cand_av_con_fun_0(), cand_av_con_fun_n(), cand_av_trans_fun(), cand_pav_con_fun_0(), cand_pav_con_fun_n(), cand_pav_trans_fun(), cfun, DF_FORWARD, df_get_n_blocks(), df_get_postorder(), df_simple_dataflow(), FOR_EACH_BB_FN, get_remat_bb_data(), and NULL.
Referenced by lra_remat().
|
static |
Calculate livein_cands for each BB.
References all_cands, bitmap_bit_p, bitmap_set_bit, cands_num, cfun, df_get_live_in(), FOR_EACH_BB_FN, get_remat_bb_data(), i, cand::insn, lra_get_insn_recog_data(), lra_insn_reg::next, NULL, OP_IN, lra_insn_reg::regno, and lra_insn_reg::type.
Referenced by lra_remat().
|
static |
Calculate changed_regs and dead_regs for each BB.
References cfun, FOR_BB_INSNS, FOR_EACH_BB_FN, NONDEBUG_INSN_P, and set_bb_regs().
Referenced by lra_remat().
|
static |
Return true if a call used register is an input operand of INSN.
References lra_insn_reg::biggest_mode, function_abi::clobbers_reg_p(), lra_static_insn_data::hard_regs, lra_get_insn_recog_data(), lra_insn_reg::next, NULL, OP_IN, lra_insn_reg::regno, and lra_insn_reg::type.
Referenced by calculate_gen_cands(), and do_remat().
|
static |
The confluence function used by the DF equation solver to set up cand_av info for a block BB without predecessor.
References bitmap_clear(), and get_remat_bb_data().
Referenced by calculate_global_remat_bb_data().
The confluence function used by the DF equation solver to propagate cand_av info from predecessor to successor on edge E (pred->bb) according to the following equation: bb.avin_cands = 0 for entry block | AND (avout_cands of predecessors)
References bitmap_and_into(), and get_remat_bb_data().
Referenced by calculate_global_remat_bb_data().
|
static |
The transfer function used by the DF equation solver to propagate candidate availability info through block with BB_INDEX according to the following equation: bb.avout = ((bb.avin & bb.livein) - bb.killed) OR bb.gen
References cand_trans_fun(), and get_remat_bb_data_by_index().
Referenced by calculate_global_remat_bb_data().
|
static |
Equal function for candidates CAND1 and CAND2. They are equal if the corresponding candidate insns have the same code, the same regno for rematerialization, the same input operands.
References gcc_assert, i, cand::insn, INSN_CODE, lra_get_insn_recog_data(), lra_static_insn_data::n_operands, cand::nop, OP_IN, lra_static_insn_data::operand, cand::regno, and lra_operand_data::type.
Referenced by initiate_cand_table().
|
static |
Hash function for candidate CAND.
References i, cand::insn, lra_get_insn_recog_data(), lra_static_insn_data::n_operands, cand::nop, OP_IN, lra_static_insn_data::operand, cand::regno, and lra_operand_data::type.
Referenced by initiate_cand_table().
|
static |
The confluence function used by the DF equation solver to set up cand_pav info for a block BB without predecessor.
References bitmap_clear(), and get_remat_bb_data().
Referenced by calculate_global_remat_bb_data().
The confluence function used by the DF equation solver to propagate partial candidate availability info from predecessor to successor on edge E (pred->bb) according to the following equation: bb.pavin_cands = 0 for entry block | OR (pavout_cands of predecessors)
References bitmap_ior_into(), and get_remat_bb_data().
Referenced by calculate_global_remat_bb_data().
|
static |
The transfer function used by the DF equation solver to propagate partial candidate availability info through block with BB_INDEX according to the following equation: bb.pavout = ((bb.pavin & bb.livein) - bb.killed) OR bb.gen
References cand_trans_fun(), and get_remat_bb_data_by_index().
Referenced by calculate_global_remat_bb_data().
The common transfer function used by the DF equation solver to propagate (partial) availability info BB_IN to BB_OUT through block with BB_INDEX according to the following equation: bb.out = ((bb.in & bb.livein) - bb.killed) OR bb.gen
References all_cands, bitmap_bit_p, bitmap_clear(), bitmap_ior_and_compl(), bitmap_set_bit, EXECUTE_IF_SET_IN_BITMAP, get_remat_bb_data_by_index(), cand::insn, lra_get_insn_recog_data(), lra_insn_reg::next, NULL, OP_OUT, cand::regno, lra_insn_reg::regno, temp_bitmap, and lra_insn_reg::type.
Referenced by cand_av_trans_fun(), and cand_pav_trans_fun().
|
static |
Setup sp offset attribute to SP_OFFSET for all INSNS.
References eliminate_regs_in_insn(), insns, NEXT_INSN(), and NULL.
Referenced by do_remat().
|
static |
Create candidate for INSN with rematerialization operand NOP and REGNO. Insert the candidate into the table and set up the corresponding INSN_TO_CAND element.
References all_cands, free(), gcc_assert, cand::index, insert_cand(), cand::insn, insn_to_cand, insn_to_cand_activation, INSN_UID(), lra_get_insn_recog_data(), cand::next_regno_cand, cand::nop, NULL, REG_P, REGNO, cand::regno, lra_insn_reg::regno, regno_cands, and cand::reload_regno.
Referenced by create_cands().
|
static |
Create rematerialization candidates (inserting them into the table).
References all_cands, BLOCK_FOR_INSN(), cands_num, create_cand(), free(), gcc_assert, get_insns(), lra_constraint_new_regno_start, lra_get_insn_recog_data(), max_reg_num(), NEXT_INSN(), NONDEBUG_INSN_P, NULL, OP_IN, operand_to_remat(), prev_nonnote_insn(), REG_P, reg_renumber, REGNO, SET_DEST, SET_SRC, and single_set().
Referenced by lra_remat().
|
static |
Create and initialize BB data.
References bitmap_initialize(), cfun, FOR_ALL_BB_FN, gcc_checking_assert, get_remat_bb_data(), basic_block_def::index, last_basic_block_for_fn, and reg_obstack.
Referenced by lra_remat().
|
static |
Insert rematerialization insns using the data-flow data calculated earlier.
References all_cands, bitmap_and(), bitmap_and_compl_into(), bitmap_bit_p, bitmap_clear(), bitmap_clear_bit(), bitmap_copy(), bitmap_set_bit, CALL_P, call_used_input_regno_present_p(), cfun, change_sp_offset(), CLEAR_HARD_REG_BIT, CLEAR_HARD_REG_SET, copy_insn(), df_get_live_in(), emit_insn(), end_sequence(), EXECUTE_IF_SET_IN_BITMAP, find_regno_note(), FOR_BB_INSNS, FOR_EACH_BB_FN, gcc_assert, get_hard_regs(), get_insns(), GET_MODE, get_remat_bb_data(), hard_regno_nregs(), lra_static_insn_data::hard_regs, i, cand::index, cand::insn, insn_callee_abi(), insn_to_cand, insn_to_cand_activation, INSN_UID(), live_hard_regs, lra_constrain_insn(), lra_get_insn_recog_data(), lra_process_new_insns(), lra_set_insn_deleted(), lra_update_insn_regno_info(), lra_insn_reg::next, cand::next_regno_cand, NONDEBUG_INSN_P, cand::nop, NULL, OP_IN, PATTERN(), recog_memoized(), reg_obstack, reg_overlap_for_remat_p(), REG_P, reg_renumber, REGNO, cand::regno, lra_insn_reg::regno, regno_cands, cand::reload_regno, SET_DEST, SET_HARD_REG_BIT, SET_SRC, single_set(), start_sequence(), temp_bitmap, TEST_HARD_REG_BIT, lra_insn_reg::type, and update_scratch_ops().
Referenced by lra_remat().
|
static |
Dump all candidates and BB data.
References cfun, df_get_live_in(), df_get_live_out(), dump_cands(), dump_regset(), FOR_EACH_BB_FN, get_remat_bb_data(), basic_block_def::index, lra_dump_bitmap_with_title(), lra_dump_file, NULL, and subreg_regs.
Referenced by lra_remat().
|
static |
Dump all candidates to DUMP_FILE.
References all_cands, cands_num, dump_file, i, cand::insn, cand::nop, print_inline_rtx(), cand::regno, and cand::reload_regno.
Referenced by dump_candidates_and_remat_bb_data().
|
static |
|
static |
Free all BB data.
References bitmap_clear(), cfun, FOR_EACH_BB_FN, free(), and get_remat_bb_data().
Referenced by lra_remat().
|
static |
|
static |
Return start hard register of REG (can be a hard or a pseudo reg) or -1 (if it is a spilled pseudo). Return number of hard registers occupied by REG through parameter NREGS if the start hard reg is not negative.
References lra_insn_reg::biggest_mode, hard_regno_nregs(), reg_renumber, and lra_insn_reg::regno.
Referenced by do_remat().
|
inlinestatic |
Two small functions for access to the bb data.
References remat_bb_data::bb.
Referenced by calculate_gen_cands(), calculate_global_remat_bb_data(), calculate_livein_cands(), cand_av_con_fun_0(), cand_av_con_fun_n(), cand_pav_con_fun_0(), cand_pav_con_fun_n(), create_remat_bb_data(), do_remat(), dump_candidates_and_remat_bb_data(), finish_remat_bb_data(), and set_bb_regs().
|
inlinestatic |
Referenced by cand_av_trans_fun(), cand_pav_trans_fun(), and cand_trans_fun().
|
static |
Initiate the candidate table.
References cand_eq_p(), cand_hash(), cand_table, and free_cand().
Referenced by lra_remat().
Insert candidate CAND into the table if it is not there yet. Return candidate which is in the table.
References cand_table, and NULL.
Referenced by create_cand().
bool lra_remat | ( | void | ) |
Entry point of the rematerialization sub-pass. Return true if we did any rematerialization.
References all_blocks, all_cands, bitmap_clear(), bitmap_initialize(), bitmap_set_bit, calculate_gen_cands(), calculate_global_remat_bb_data(), calculate_livein_cands(), calculate_local_reg_remat_bb_data(), cfun, create_cands(), create_remat_bb_data(), do_remat(), dump_candidates_and_remat_bb_data(), finish_cand_table(), finish_remat_bb_data(), FOR_ALL_BB_FN, free(), get_max_uid(), basic_block_def::index, initiate_cand_table(), insn_to_cand, insn_to_cand_activation, lra_dump_file, lra_dump_insns_if_possible(), LRA_MAX_REMATERIALIZATION_PASSES, lra_rematerialization_iter, max_reg_num(), max_regno, NULL, reg_obstack, regno_cands, subreg_regs, temp_bitmap, timevar_pop(), and timevar_push().
Referenced by lra().
|
static |
If INSN cannot be used for rematerialization, return negative value. If INSN can be considered as a candidate for rematerialization, return value which is the operand number of the pseudo for which the insn can be used for rematerialization. Here we consider the insns without any memory, spilled pseudo (except for the rematerialization pseudo), or dying or unused regs.
References bad_for_rematerialization_p(), lra_insn_reg::biggest_mode, bitmap_bit_p, CALL_P, end_hard_regno(), find_regno_note(), frame_pointer_needed, lra_static_insn_data::hard_regs, i, JUMP_P, lra_get_insn_recog_data(), lra_static_insn_data::n_operands, lra_insn_reg::next, NULL, OP_IN, OP_INOUT, OP_OUT, PATTERN(), REG_P, reg_renumber, REGNO, lra_insn_reg::regno, lra_insn_reg::subreg_p, subreg_regs, and lra_insn_reg::type.
Referenced by create_cands().
|
static |
Return true if REG overlaps an input operand or non-input hard register of INSN. Basically the function returns false if we can move rematerialization candidate INSN through another insn with output REG or dead input REG (we consider it to avoid extending reg live range) with possible output pseudo renaming in INSN.
References lra_insn_reg::biggest_mode, hard_regno_nregs(), lra_static_insn_data::hard_regs, lra_get_insn_recog_data(), lra_insn_reg::next, NULL, OP_IN, reg_renumber, lra_insn_reg::regno, and lra_insn_reg::type.
Referenced by calculate_gen_cands(), and do_remat().
|
static |
Update changed_regs, dead_regs, subreg_regs of BB from INSN.
References bitmap_ior_into(), bitmap_set_bit, CALL_P, find_regno_note(), function_abi::full_reg_clobbers(), get_remat_bb_data(), insn_callee_abi(), lra_get_insn_recog_data(), lra_insn_reg::next, NULL, OP_IN, lra_insn_reg::regno, lra_insn_reg::subreg_p, subreg_regs, and lra_insn_reg::type.
Referenced by calculate_local_reg_remat_bb_data().
|
static |
Make copy of and register scratch pseudos in rematerialized insn REMAT_INSN.
References GET_MODE, i, ira_former_scratch_p(), ira_register_new_scratch_op(), lra_create_new_reg(), lra_get_allocno_class(), lra_get_insn_recog_data(), lra_static_insn_data::n_operands, NULL, REG_P, and REGNO.
Referenced by do_remat().
|
static |
Basic blocks for data flow problems -- all bocks except the special ones.
Vector containing all candidates.
Referenced by calculate_livein_cands(), cand_trans_fun(), create_cand(), create_cands(), do_remat(), dump_cands(), and lra_remat().
|
static |
Hash table for the candidates. Different insns (e.g. structurally the same insns or even insns with different unused output regs) can be represented by the same candidate in the table.
Referenced by finish_cand_table(), initiate_cand_table(), and insert_cand().
|
static |
Rematerialize pseudos values. Copyright (C) 2014-2025 Free Software Foundation, Inc. Contributed by Vladimir Makarov <vmakarov@redhat.com>. 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 code objective is to rematerialize spilled pseudo values. To do this we calculate available insn candidates. The candidate is available at some point if there is dominated set of insns with the same pattern, the insn inputs are not dying or modified on any path from the set, the outputs are not modified. The insns containing memory or spilled pseudos (except for the rematerialized pseudo) are not considered as such insns are not profitable in comparison with regular loads of spilled pseudo values. That simplifies the implementation as we don't need to deal with memory aliasing. To speed up available candidate calculation, we calculate partially available candidates first and use them for initialization of the availability. That is because (partial) availability sets are sparse. The rematerialization sub-pass could be improved further in the following ways: o We could make longer live ranges of inputs in the rematerialization candidates if their hard registers are not used for other purposes. This could be complicated if we need to update BB live info information as LRA does not use DF-infrastructure for compile-time reasons. This problem could be overcome if constrain making live ranges longer only in BB/EBB scope. o We could use cost-based decision to choose rematerialization insn (currently all insns without memory is can be used). o We could use other free hard regs for unused output pseudos in rematerialization candidates although such cases probably will be very rare.
Number of candidates for rematerialization.
Referenced by calculate_livein_cands(), create_cands(), and dump_cands().
|
static |
Map: insn -> candidate representing it. It is null if the insn cannot be used for rematerialization.
Referenced by calculate_gen_cands(), create_cand(), do_remat(), and lra_remat().
|
static |
A secondary map, for candidates that involve two insns, where the second one makes the equivalence. The candidate must not be used before seeing this activation insn.
Referenced by create_cand(), do_remat(), and lra_remat().
int lra_rematerialization_iter |
Current number of rematerialization iteration.
Referenced by lra(), and lra_remat().
|
static |
Map regno -> candidates can be used for the regno rematerialization.
Referenced by create_cand(), do_remat(), and lra_remat().
|
static |
All basic block data are referred through the following array.
|
static |
Registers accessed via subreg_p.
Referenced by dump_candidates_and_remat_bb_data(), lra_remat(), operand_to_remat(), and set_bb_regs().
|
static |
Bitmap used for different calculations.