GCC Middle and Back End API Reference
dce.cc File Reference
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "backend.h"
#include "rtl.h"
#include "tree.h"
#include "predict.h"
#include "df.h"
#include "memmodel.h"
#include "tm_p.h"
#include "emit-rtl.h"
#include "cfgrtl.h"
#include "cfgbuild.h"
#include "cfgcleanup.h"
#include "dce.h"
#include "valtrack.h"
#include "tree-pass.h"
#include "dbgcnt.h"
#include "rtl-iter.h"
Include dependency graph for dce.cc:

Data Structures

struct  check_argument_load_data
 

Functions

static bool find_call_stack_args (rtx_call_insn *, bool, bool, bitmap)
 
static bool deletable_insn_p_1 (rtx body)
 
static bool can_delete_call (rtx_insn *insn)
 
static bool deletable_insn_p (rtx_insn *insn, bool fast, bitmap arg_stores)
 
static int marked_insn_p (rtx_insn *insn)
 
static void mark_insn (rtx_insn *insn, bool fast)
 
static void mark_nonreg_stores_1 (rtx dest, const_rtx pattern, void *data)
 
static void mark_nonreg_stores_2 (rtx dest, const_rtx pattern, void *data)
 
static void mark_nonreg_stores (rtx_insn *insn, bool fast)
 
static bool check_argument_store (HOST_WIDE_INT size, HOST_WIDE_INT off, HOST_WIDE_INT min_sp_off, HOST_WIDE_INT max_sp_off, bitmap sp_bytes)
 
static HOST_WIDE_INT sp_based_mem_offset (rtx_call_insn *call_insn, const_rtx mem, bool fast)
 
static void check_argument_load (rtx *loc, void *data)
 
static void remove_reg_equal_equiv_notes_for_defs (rtx_insn *insn)
 
static void reset_unmarked_insns_debug_uses (void)
 
static void delete_unmarked_insns (void)
 
static void prescan_insns_for_dce (bool fast)
 
static void mark_artificial_uses (void)
 
static void mark_reg_dependencies (rtx_insn *insn)
 
static void init_dce (bool fast)
 
static void fini_dce (bool fast)
 
static unsigned int rest_of_handle_ud_dce (void)
 
rtl_opt_passmake_pass_ud_rtl_dce (gcc::context *ctxt)
 
static bool word_dce_process_block (basic_block bb, bool redo_out, struct dead_debug_global *global_debug)
 
static bool dce_process_block (basic_block bb, bool redo_out, bitmap au, struct dead_debug_global *global_debug)
 
static void fast_dce (bool word_level)
 
static unsigned int rest_of_handle_fast_dce (void)
 
void run_word_dce (void)
 
void run_fast_df_dce (void)
 
void run_fast_dce (void)
 
rtl_opt_passmake_pass_fast_rtl_dce (gcc::context *ctxt)
 

Variables

static bool df_in_progress = false
 
static bool can_alter_cfg = false
 
static vec< rtx_insn * > worklist
 
static sbitmap marked
 
static bitmap_obstack dce_blocks_bitmap_obstack
 
static bitmap_obstack dce_tmp_bitmap_obstack
 

Function Documentation

◆ can_delete_call()

static bool can_delete_call ( rtx_insn * insn)
static
Don't delete calls that may throw if we cannot do so.   

References BB_END, BLOCK_FOR_INSN(), CALL_P, can_alter_cfg, cfun, FOR_EACH_EDGE, gcc_assert, ggc_alloc(), and insn_nothrow_p().

Referenced by deletable_insn_p(), and mark_insn().

◆ check_argument_load()

static void check_argument_load ( rtx * loc,
void * data )
static
Helper function for find_call_stack_args.  Check if there are
any loads from the argument slots in between the const/pure call
and store to the argument slot, set LOAD_FOUND if any is found.   

References bitmap_bit_p, check_argument_load_data::call_insn, check_argument_load_data::fast, FOR_EACH_SUBRTX, ggc_alloc(), INTTYPE_MINIMUM, check_argument_load_data::load_found, MAX, check_argument_load_data::max_sp_off, MEM_P, MEM_SIZE, MEM_SIZE_KNOWN_P, MIN, check_argument_load_data::min_sp_off, sp_based_mem_offset(), and check_argument_load_data::sp_bytes.

Referenced by find_call_stack_args().

◆ check_argument_store()

static bool check_argument_store ( HOST_WIDE_INT size,
HOST_WIDE_INT off,
HOST_WIDE_INT min_sp_off,
HOST_WIDE_INT max_sp_off,
bitmap sp_bytes )
static
Return true if a store to SIZE bytes, starting OFF bytes from stack pointer,
is a call argument store, and clear corresponding bits from SP_BYTES
bitmap if it is.   

References bitmap_clear_bit(), and ggc_alloc().

Referenced by find_call_stack_args().

◆ dce_process_block()

static bool dce_process_block ( basic_block bb,
bool redo_out,
bitmap au,
struct dead_debug_global * global_debug )
static

◆ deletable_insn_p()

◆ deletable_insn_p_1()

static bool deletable_insn_p_1 ( rtx body)
static
A subroutine for which BODY is part of the instruction being tested;
either the top-level pattern, or an element of a PARALLEL.  The
instruction is known not to be a bare USE or CLOBBER.   

References GET_CODE, ggc_alloc(), and volatile_refs_p().

Referenced by deletable_insn_p().

◆ delete_unmarked_insns()

◆ fast_dce()

◆ find_call_stack_args()

static bool find_call_stack_args ( rtx_call_insn * call_insn,
bool do_mark,
bool fast,
bitmap arg_stores )
static
Try to find all stack stores of CALL_INSN arguments if
ACCUMULATE_OUTGOING_ARGS.  If all stack stores have been found
and it is therefore safe to eliminate the call, return true,
otherwise return false.  This function should be first called
with DO_MARK false, and only when the CALL_INSN is actually
going to be marked called again with DO_MARK true.   

References ACCUMULATE_OUTGOING_ARGS, BB_HEAD, BITMAP_ALLOC, bitmap_clear(), bitmap_empty_p(), BITMAP_FREE, bitmap_set_bit, BLOCK_FOR_INSN(), check_argument_load_data::call_insn, CALL_INSN_FUNCTION_USAGE, CALL_P, check_argument_load(), check_argument_store(), deletable_insn_p(), check_argument_load_data::fast, gcc_assert, gcc_checking_assert, gcc_unreachable, GET_CODE, ggc_alloc(), INSN_UID(), INTTYPE_MAXIMUM, INTTYPE_MINIMUM, mark_insn(), MAX, check_argument_load_data::max_sp_off, MEM_P, MEM_SIZE, MEM_SIZE_KNOWN_P, MIN, check_argument_load_data::min_sp_off, NONDEBUG_INSN_P, note_uses(), NULL, PATTERN(), PREV_INSN(), SET_DEST, single_set(), sp_based_mem_offset(), check_argument_load_data::sp_bytes, stack_pointer_rtx, and XEXP.

Referenced by deletable_insn_p(), and mark_insn().

◆ fini_dce()

static void fini_dce ( bool fast)
static

◆ init_dce()

◆ make_pass_fast_rtl_dce()

rtl_opt_pass * make_pass_fast_rtl_dce ( gcc::context * ctxt)

References ggc_alloc().

◆ make_pass_ud_rtl_dce()

rtl_opt_pass * make_pass_ud_rtl_dce ( gcc::context * ctxt)

References ggc_alloc().

◆ mark_artificial_uses()

static void mark_artificial_uses ( void )
static
UD-based DSE routines.  
Mark instructions that define artificially-used registers, such as
the frame pointer and the stack pointer.   

References cfun, defs, DF_REF_CHAIN, DF_REF_INSN, DF_REF_IS_ARTIFICIAL, FOR_ALL_BB_FN, FOR_EACH_ARTIFICIAL_USE, basic_block_def::index, mark_insn(), and insn_def::next.

Referenced by rest_of_handle_ud_dce().

◆ mark_insn()

◆ mark_nonreg_stores()

static void mark_nonreg_stores ( rtx_insn * insn,
bool fast )
static
Mark INSN if it stores to a non-register destination.   

References mark_nonreg_stores_1(), mark_nonreg_stores_2(), and note_stores().

Referenced by prescan_insns_for_dce().

◆ mark_nonreg_stores_1()

static void mark_nonreg_stores_1 ( rtx dest,
const_rtx pattern,
void * data )
static
A note_stores callback used by mark_nonreg_stores.  DATA is the
instruction containing DEST.   

References GET_CODE, ggc_alloc(), mark_insn(), and REG_P.

Referenced by mark_nonreg_stores().

◆ mark_nonreg_stores_2()

static void mark_nonreg_stores_2 ( rtx dest,
const_rtx pattern,
void * data )
static
A note_stores callback used by mark_nonreg_stores.  DATA is the
instruction containing DEST.   

References GET_CODE, ggc_alloc(), mark_insn(), and REG_P.

Referenced by mark_nonreg_stores().

◆ mark_reg_dependencies()

static void mark_reg_dependencies ( rtx_insn * insn)
static
Mark every instruction that defines a register value that INSN uses.   

References DEBUG_INSN_P, defs, DF_REF_CHAIN, DF_REF_INSN, DF_REF_IS_ARTIFICIAL, DF_REF_REG, dump_file, FOR_EACH_INSN_USE, ggc_alloc(), INSN_UID(), mark_insn(), insn_def::next, and print_simple_rtl().

Referenced by rest_of_handle_ud_dce().

◆ marked_insn_p()

static int marked_insn_p ( rtx_insn * insn)
inlinestatic
Return true if INSN has been marked as needed.   

References bitmap_bit_p, gcc_assert, INSN_UID(), and marked.

Referenced by dce_process_block(), delete_unmarked_insns(), mark_insn(), reset_unmarked_insns_debug_uses(), and word_dce_process_block().

◆ prescan_insns_for_dce()

static void prescan_insns_for_dce ( bool fast)
static
Go through the instructions and mark those whose necessity is not
dependent on inter-instruction information.  Make sure all other
instructions are not marked.   

References ACCUMULATE_OUTGOING_ARGS, BITMAP_ALLOC, bitmap_bit_p, bitmap_clear(), BITMAP_FREE, cfun, deletable_insn_p(), df_in_progress, dump_file, FOR_BB_INSNS_REVERSE_SAFE, FOR_EACH_BB_FN, ggc_alloc(), INSN_UID(), mark_insn(), mark_nonreg_stores(), NONDEBUG_INSN_P, and NULL.

Referenced by fast_dce(), and rest_of_handle_ud_dce().

◆ remove_reg_equal_equiv_notes_for_defs()

static void remove_reg_equal_equiv_notes_for_defs ( rtx_insn * insn)
static
Remove all REG_EQUAL and REG_EQUIV notes referring to the registers INSN
writes to.   

References DF_REF_REGNO, FOR_EACH_INSN_DEF, and remove_reg_equal_equiv_notes_for_regno().

Referenced by delete_unmarked_insns().

◆ reset_unmarked_insns_debug_uses()

static void reset_unmarked_insns_debug_uses ( void )
static

◆ rest_of_handle_fast_dce()

static unsigned int rest_of_handle_fast_dce ( void )
static
Fast register level DCE.   

References fast_dce(), fini_dce(), and init_dce().

Referenced by run_fast_dce(), and run_fast_df_dce().

◆ rest_of_handle_ud_dce()

◆ run_fast_dce()

void run_fast_dce ( void )
Run a fast DCE pass.   

References ggc_alloc(), and rest_of_handle_fast_dce().

Referenced by cleanup_cfg(), and do_reload().

◆ run_fast_df_dce()

void run_fast_df_dce ( void )
This is an internal call that is used by the df live register
problem to run fast dce as a side effect of creating the live
information.  The stack is organized so that the lr problem is run,
this pass is run, which updates the live info and the df scanning
info, and then returns to allow the rest of the problems to be run.

This can be called by elsewhere but it will not update the bit
vectors for any other problems than LR.   

References df_clear_flags(), DF_DEFER_INSN_RESCAN, df_in_progress, DF_NO_INSN_RESCAN, df_set_flags(), ggc_alloc(), and rest_of_handle_fast_dce().

Referenced by df_lr_finalize().

◆ run_word_dce()

◆ sp_based_mem_offset()

static HOST_WIDE_INT sp_based_mem_offset ( rtx_call_insn * call_insn,
const_rtx mem,
bool fast )
static
If MEM has sp address, return 0, if it has sp + const address,
return that const, if it has reg address where reg is set to sp + const
and FAST is false, return const, otherwise return
INTTYPE_MINUMUM (HOST_WIDE_INT).   

References CONST_INT_P, defs, DF_REF_CHAIN, DF_REF_INSN, DF_REF_IS_ARTIFICIAL, DF_REF_REG, FOR_EACH_INSN_USE, GET_CODE, ggc_alloc(), INTTYPE_MINIMUM, INTVAL, insn_def::next, NULL, REG_P, rtx_equal_p(), SET_SRC, single_set(), stack_pointer_rtx, and XEXP.

Referenced by check_argument_load(), and find_call_stack_args().

◆ word_dce_process_block()

static bool word_dce_process_block ( basic_block bb,
bool redo_out,
struct dead_debug_global * global_debug )
static
-------------------------------------------------------------------------
Fast DCE functions
-------------------------------------------------------------------------  
Process basic block BB.  Return true if the live_in set has
changed. REDO_OUT is true if the info at the bottom of the block
needs to be recalculated before starting.  AU is the proper set of
artificial uses.  Track global substitution of uses of dead pseudos
in debug insns using GLOBAL_DEBUG.   

References BITMAP_ALLOC, bitmap_bit_p, bitmap_clear(), bitmap_copy(), bitmap_empty_p(), bitmap_equal_p(), BITMAP_FREE, control_flow_insn_p(), dce_tmp_bitmap_obstack, dead_debug_add(), dead_debug_insert_temp(), dead_debug_local_finish(), dead_debug_local_init(), debug, DEBUG_INSN_P, DEBUG_TEMP_AFTER_WITH_REG_FORCE, DEBUG_TEMP_BEFORE_WITH_VALUE, df_print_word_regset(), DF_REF_REAL_REG, DF_REF_REGNO, df_word_lr, DF_WORD_LR_IN, DF_WORD_LR_OUT, df_word_lr_simulate_defs(), df_word_lr_simulate_uses(), dump_file, FOR_BB_INSNS_REVERSE, FOR_EACH_EDGE, FOR_EACH_INSN_DEF, FOR_EACH_INSN_USE, GET_MODE, GET_MODE_SIZE(), ggc_alloc(), basic_block_def::index, INSN_P, INSN_UID(), known_eq, mark_insn(), marked_insn_p(), NULL, and basic_block_def::succs.

Referenced by fast_dce().

Variable Documentation

◆ can_alter_cfg

bool can_alter_cfg = false
static
True if we are allowed to alter the CFG in this pass.   

Referenced by can_delete_call(), deletable_insn_p(), delete_unmarked_insns(), and init_dce().

◆ dce_blocks_bitmap_obstack

bitmap_obstack dce_blocks_bitmap_obstack
static
Bitmap obstacks used for block processing by the fast algorithm.   

Referenced by fast_dce(), fini_dce(), and init_dce().

◆ dce_tmp_bitmap_obstack

bitmap_obstack dce_tmp_bitmap_obstack
static

◆ df_in_progress

bool df_in_progress = false
static
RTL dead code elimination.
   Copyright (C) 2005-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/>.   
-------------------------------------------------------------------------
Core mark/delete routines
-------------------------------------------------------------------------  
True if we are invoked while the df engine is running; in this case,
we don't want to reenter it.   

Referenced by deletable_insn_p(), init_dce(), mark_insn(), prescan_insns_for_dce(), and run_fast_df_dce().

◆ marked

sbitmap marked
static
Bitmap of instructions marked as needed indexed by INSN_UID.   

Referenced by check_regexp_units_distribution(), const_ok_for_output_1(), fast_dce(), fini_dce(), init_dce(), mark_insn(), and marked_insn_p().

◆ worklist

vec<rtx_insn *> worklist
static
Instructions that have been marked but whose dependencies have not
yet been processed.   

Referenced by build_bitint_stmt_ssa_conflicts(), compute_added_num_insns(), compute_antic(), compute_antic_aux(), compute_antinout_edge(), compute_avail(), compute_available(), path_range_query::compute_exit_dependencies(), compute_laterin(), compute_live_loop_exits(), compute_nearerout(), compute_partial_antic_aux(), determine_unlikely_bbs(), df_worklist_dataflow_doublequeue(), df_worklist_propagate_backward(), df_worklist_propagate_forward(), do_rpo_vn_1(), dse_classify_store(), evaluate_bbs(), fill_always_executed_in_1(), find_always_executed_bbs(), find_bbs_reachable_by_hot_paths(), find_deps_in_bb_for_stmt(), back_threader::find_paths_to_names(), ana::exploded_graph::find_previous_entry_to(), find_unreachable_blocks(), find_vdef_in_loop(), fwprop(), handle_missing_profiles(), has_nonexceptional_receiver(), has_nonexceptional_receiver(), ifcvt_local_dce(), is_maybe_undefined(), lower_for(), mark_insn(), match_pattern_2(), maybe_push_to_hybrid_worklist(), omp_discover_implicit_declare_target(), omp_sese_split_blocks(), optimize_mask_stores(), optimize_vector_load(), prepare_block_for_update(), process_use(), propagate_unlikely_bbs_forward(), prune_unused_phi_nodes(), purge_all_uses(), ana::reachability< GraphTraits >::reachability(), rest_of_handle_ud_dce(), rewrite_blocks(), scale_dominated_blocks_in_loop(), scale_strictly_dominated_blocks(), sccopy_propagate(), tm_memopt_compute_antic(), tm_memopt_compute_available(), pcom_worker::try_combine_chains(), vect_analyze_scalar_cycles_1(), vect_bb_slp_mark_live_stmts(), vect_bb_slp_scalar_cost(), vect_build_slp_tree_2(), vect_detect_hybrid_slp(), vect_mark_relevant(), vect_mark_stmts_to_be_vectorized(), vect_slp_check_for_roots(), vect_slp_linearize_chain(), verify_non_ssa_vars(), vt_find_locations(), and dom_walker::walk().