GCC Middle and Back End API Reference
dce.c File Reference
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "hashtab.h"
#include "tm.h"
#include "rtl.h"
#include "tree.h"
#include "regs.h"
#include "hard-reg-set.h"
#include "flags.h"
#include "except.h"
#include "df.h"
#include "cselib.h"
#include "dce.h"
#include "valtrack.h"
#include "tree-pass.h"
#include "dbgcnt.h"
#include "tm_p.h"
#include "emit-rtl.h"
Include dependency graph for dce.c:

Functions

static bool find_call_stack_args (rtx, bool, bool, bitmap)
static bool deletable_insn_p_1 ()
static bool deletable_insn_p ()
static int marked_insn_p ()
static void mark_insn ()
static void mark_nonreg_stores_1 ()
static void mark_nonreg_stores_2 ()
static void mark_nonreg_stores ()
static bool check_argument_store (rtx mem, HOST_WIDE_INT off, HOST_WIDE_INT min_sp_off, HOST_WIDE_INT max_sp_off, bitmap sp_bytes)
static void remove_reg_equal_equiv_notes_for_defs ()
static void reset_unmarked_insns_debug_uses ()
static void delete_unmarked_insns ()
static void prescan_insns_for_dce ()
static void mark_artificial_uses ()
static void mark_reg_dependencies ()
static void init_dce ()
static void fini_dce ()
static unsigned int rest_of_handle_ud_dce ()
static bool gate_ud_dce ()
rtl_opt_passmake_pass_ud_rtl_dce ()
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 ()
static unsigned int rest_of_handle_fast_dce ()
void run_word_dce ()
void run_fast_df_dce ()
void run_fast_dce ()
static bool gate_fast_dce ()
rtl_opt_passmake_pass_fast_rtl_dce ()

Variables

static bool df_in_progress = false
static bool can_alter_cfg = false
static vec< rtxworklist
static sbitmap marked
static bitmap_obstack dce_blocks_bitmap_obstack
static bitmap_obstack dce_tmp_bitmap_obstack

Function Documentation

static bool check_argument_store ( rtx  mem,
HOST_WIDE_INT  off,
HOST_WIDE_INT  min_sp_off,
HOST_WIDE_INT  max_sp_off,
bitmap  sp_bytes 
)
static

Return true if store to MEM, starting OFF bytes from stack pointer, is a call argument store, and clear corresponding bits from SP_BYTES bitmap if it is.

References ACCUMULATE_OUTGOING_ARGS, bitmap_clear(), CALL_INSN_FUNCTION_USAGE, CALL_P, gcc_assert, GET_CODE, HOST_WIDE_INT, INTTYPE_MAXIMUM, MEM_P, and XEXP.

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

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.

     Need to redo the live_out set of this block if when one of
     the succs of this block has had a change in it live in
     set.   
       The insn is needed if there is someone who uses the output.   
       No matter if the instruction is needed or not, we remove
       any regno in the defs from the live set.   
       On the other hand, we do not allow the dead uses to set
       anything in local_live.   
       Insert debug temps for dead REGs used in subsequent debug
       insns.  We may have to emit a debug temp even if the insn
       was marked, in case the debug use was after the point of
       death.   
static bool deletable_insn_p ( )
static

Return true if INSN is a normal instruction that can be deleted by the DCE pass.

     We cannot delete calls inside of the recursive dce because
     this may cause basic blocks to be deleted and this messes up
     the rest of the stack of optimization passes.   
     We cannot delete pure or const sibling calls because it is
     hard to see the result.   
     We can delete dead const or pure calls as long as they do not
     infinite loop.   
 Don't delete jumps, notes and the like.   
 Don't delete insns that may throw if we cannot do so.   
 If INSN sets a global_reg, leave it untouched.   
         A CLOBBER of a dead pseudo register serves no purpose.
         That is not necessarily true for hard registers until
         after reload.   
       Because of the way that use-def chains are built, it is not
       possible to tell if the clobber is dead because it can
       never be the target of a use-def chain.   
static bool deletable_insn_p_1 ( )
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.

The UNSPEC case was added here because the ia-64 claims that USEs do not work after reload and generates UNSPECS rather than USEs. Since dce is run after reload we need to avoid deleting these even if they are dead. If it turns out that USEs really do work after reload, the ia-64 should be changed, and the UNSPEC case can be removed.

static void delete_unmarked_insns ( )
static

Delete every instruction that hasn't been marked.

         Always delete no-op moves.   
         Otherwise rely only on the DCE algorithm.   
         Beware that reaching a dbg counter limit here can result
         in miscompiled file.  This occurs when a group of insns
         must be deleted together, typically because the kept insn
         depends on the output from the deleted insn.  Deleting
         this insns in reverse order (both at the bb level and
         when looking at the blocks) minimizes this, but does not
         eliminate it, since it is possible for the using insn to
         be top of a block and the producer to be at the bottom of
         the block.  However, in most cases this will only result
         in an uninitialized use of an insn that is dead anyway.

         However, there is one rare case that will cause a
         miscompile: deletion of non-looping pure and constant
         calls on a machine where ACCUMULATE_OUTGOING_ARGS is true.
         In this case it is possible to remove the call, but leave
         the argument pushes to the stack.  Because of the changes
         to the stack pointer, this will almost always lead to a
         miscompile.   
         Before we delete the insn we have to remove the REG_EQUAL notes
         for the destination regs in order to avoid dangling notes.   
         If a pure or const call is deleted, this may make the cfg
         have unreachable blocks.  We rememeber this and call
         delete_unreachable_blocks at the end.   
         Now delete the insn.   
 Deleted a pure or const call.   

Referenced by fast_dce(), and init_dce().

static void fast_dce ( )
static

Perform fast DCE once initialization is done. If WORD_LEVEL is true, use the word level dce, otherwise do it at the pseudo level.

 The set of blocks that have been seen on this iteration.   
 The set of blocks that need to have the out vectors reset because
 the in of one of their successors has changed.   
 These regs are considered always live so if they end up dying
 because of some def, we need to bring the back again.  Calling
 df_simulate_fixup_sets has the disadvantage of calling
 bb_has_eh_pred once per insn, so we cache the information
 here.   
                 Be tricky about when we need to iterate the
                 analysis.  We only have redo the analysis if the
                 bitmaps change at the top of a block that is the
                 entry to a loop.   
         Turn off the RUN_DCE flag to prevent recursive calls to
         dce.   
         So something was deleted that requires a redo.  Do it on
         the cheap.   
         We do not need to rescan any instructions.  We only need
         to redo the dataflow equations for the blocks that had a
         change at the top of the block.  Then we need to redo the
         iteration.   

References bitmap_clear(), delete_unmarked_insns(), df_analyze_problem(), df_clear_flags(), df_lr, DF_LR_RUN_DCE, df_set_flags(), df_word_lr, and prescan_insns_for_dce().

static bool find_call_stack_args ( rtx  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.

 First determine the minimum and maximum offset from sp for
 stored arguments.   
           If not fast, use chains to see if addr wasn't set to
           sp + offset.   
 Set bits in SP_BYTES bitmap for bytes relative to sp + min_sp_off
 which contain arguments.  Checking has been done in the previous
 loop.   
 Walk backwards, looking for argument stores.  The search stops
 when seeing another call, sp adjustment or memory store other than
 argument store.   

References CONST_INT_P, defs, DF_INSN_USES, DF_REF_CHAIN, DF_REF_INSN, DF_REF_IS_ARTIFICIAL, DF_REF_REG, GET_CODE, HOST_WIDE_INT, INTVAL, MAX, MEM_SIZE, MEM_SIZE_KNOWN_P, MIN, df_link::next, NULL, df_link::ref, REG_P, rtx_equal_p(), SET_SRC, single_set, stack_pointer_rtx, and XEXP.

static void fini_dce ( )
static

Free the data allocated by init_dce.

References OPTGROUP_NONE, RTL_PASS, TODO_df_finish, and TODO_verify_rtl_sharing.

Referenced by init_dce().

static bool gate_fast_dce ( )
static

Referenced by run_word_dce().

rtl_opt_pass* make_pass_fast_rtl_dce ( )
rtl_opt_pass* make_pass_ud_rtl_dce ( )
static void mark_artificial_uses ( )
static

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

References bitmap_obstack_initialize(), can_alter_cfg, df_analyze(), df_chain_add_problem(), df_dump(), df_in_progress, DF_RD_PRUNE_DEAD_DEFS, df_set_flags(), DF_UD_CHAIN, and dump_file.

Referenced by init_dce().

static void mark_insn ( )
static

If INSN has not yet been marked as needed, mark it now, and add it to the worklist.

References GET_CODE, and REG_P.

Referenced by prescan_insns_for_dce().

static void mark_nonreg_stores ( )
static

Mark INSN if BODY stores to a non-register destination.

static void mark_nonreg_stores_1 ( )
static

A note_stores callback used by mark_nonreg_stores. DATA is the instruction containing DEST.

References mark_nonreg_stores_2(), and note_stores().

static void mark_nonreg_stores_2 ( )
static

A note_stores callback used by mark_nonreg_stores. DATA is the instruction containing DEST.

References bitmap_clear_bit(), GET_MODE, GET_MODE_SIZE, and HOST_WIDE_INT.

Referenced by mark_nonreg_stores_1().

static void mark_reg_dependencies ( )
static

Mark every instruction that defines a register value that INSN uses.

Referenced by init_dce().

static int marked_insn_p ( )
inlinestatic

Return true if INSN has been marked as needed.

Artificial defs are always needed and they do not have an insn. We should never see them here.

static void prescan_insns_for_dce ( )
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.

  Don't mark argument stores now.  They will be marked
  if needed when the associated CALL is marked.   

find_call_stack_args only looks at argument stores in the same bb.

References defs, df_get_artificial_uses(), DF_REF_CHAIN, DF_REF_INSN, DF_REF_IS_ARTIFICIAL, FOR_ALL_BB, basic_block_def::index, mark_insn(), df_link::next, and df_link::ref.

Referenced by fast_dce(), and init_dce().

static void remove_reg_equal_equiv_notes_for_defs ( )
static

Remove all REG_EQUAL and REG_EQUIV notes referring to the registers INSN writes to.

static void reset_unmarked_insns_debug_uses ( )
static

Scan all BBs for debug insns and reset those that reference values defined in unmarked insns.

??? FIXME could we propagate the values assigned to each of the DEFs?

Referenced by init_dce().

static unsigned int rest_of_handle_fast_dce ( )
static

Fast register level DCE.

Referenced by run_word_dce().

static unsigned int rest_of_handle_ud_dce ( )
static

UD-chain based DCE.

Before any insns are deleted, we must remove the chains since they are not bidirectional.

References execute(), and gate_ud_dce().

void run_fast_dce ( void  )

Run a fast DCE pass.

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.

If dce is able to delete something, it has to happen immediately. Otherwise there will be problems handling the eq_notes.

Referenced by df_lr_init().

void run_word_dce ( void  )

Fast byte level DCE.

References execute(), gate_fast_dce(), and rest_of_handle_fast_dce().

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.

     Need to redo the live_out set of this block if when one of
     the succs of this block has had a change in it live in
     set.   
       No matter if the instruction is needed or not, we remove
       any regno in the defs from the live set.   
       On the other hand, we do not allow the dead uses to set
       anything in local_live.   
       Insert debug temps for dead REGs used in subsequent debug
       insns.  We may have to emit a debug temp even if the insn
       was marked, in case the debug use was after the point of
       death.   

Variable Documentation

bool can_alter_cfg = false
static

True if we are allowed to alter the CFG in this pass.

Referenced by mark_artificial_uses().

bitmap_obstack dce_blocks_bitmap_obstack
static

Bitmap obstacks used for block processing by the fast algorithm.

bitmap_obstack dce_tmp_bitmap_obstack
static
bool df_in_progress = false
static

RTL dead code elimination. Copyright (C) 2005-2013 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 mark_artificial_uses().

sbitmap marked
static

Bitmap of instructions marked as needed indexed by INSN_UID.

vec<rtx> worklist
static

Instructions that have been marked but whose dependencies have not yet been processed.

Referenced by compute_available(), do_partial_partial_insertion(), dump_split_point(), find_src_set_src(), replace_pseudos_in(), and tm_memopt_accumulate_memops().