summaryrefslogtreecommitdiffstats
path: root/contrib/gcc/flow.c
diff options
context:
space:
mode:
authorobrien <obrien@FreeBSD.org>2002-02-01 18:16:02 +0000
committerobrien <obrien@FreeBSD.org>2002-02-01 18:16:02 +0000
commitc9ab9ae440a8066b2c2b85b157b1fdadcf09916a (patch)
tree086d9d6c8fbd4fc8fe4495059332f66bc0f8d12b /contrib/gcc/flow.c
parent2ecfd8bd04b63f335c1ec6295740a4bfd97a4fa6 (diff)
downloadFreeBSD-src-c9ab9ae440a8066b2c2b85b157b1fdadcf09916a.zip
FreeBSD-src-c9ab9ae440a8066b2c2b85b157b1fdadcf09916a.tar.gz
Enlist the FreeBSD-CURRENT users as testers of what is to become Gcc 3.1.0.
These bits are taken from the FSF anoncvs repo on 1-Feb-2002 08:20 PST.
Diffstat (limited to 'contrib/gcc/flow.c')
-rw-r--r--contrib/gcc/flow.c7163
1 files changed, 3062 insertions, 4101 deletions
diff --git a/contrib/gcc/flow.c b/contrib/gcc/flow.c
index 432a990..315cb2d 100644
--- a/contrib/gcc/flow.c
+++ b/contrib/gcc/flow.c
@@ -1,24 +1,23 @@
/* Data flow analysis for GNU compiler.
Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
- 1999, 2000 Free Software Foundation, Inc.
+ 1999, 2000, 2001 Free Software Foundation, Inc.
-This file is part of GNU CC.
+This file is part of GCC.
-GNU CC 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 2, or (at your option)
-any later version.
+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 2, or (at your option) any later
+version.
-GNU CC 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.
+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 GNU CC; see the file COPYING. If not, write to
-the Free Software Foundation, 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA. */
-
+along with GCC; see the file COPYING. If not, write to the Free
+Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+02111-1307, USA. */
/* This file contains the data flow analysis pass of the compiler. It
computes data flow information which tells combine_instructions
@@ -57,7 +56,7 @@ Boston, MA 02111-1307, USA. */
pseudo register. The bit is 1 if the register is live at the
beginning of the basic block.
- Two types of elements can be added to an insn's REG_NOTES.
+ Two types of elements can be added to an insn's REG_NOTES.
A REG_DEAD note is added to an insn's REG_NOTES for any register
that meets both of two conditions: The value in the register is not
needed in subsequent insns and the insn does not replace the value in
@@ -104,13 +103,13 @@ Boston, MA 02111-1307, USA. */
a REG_INC element is added to the insn's REG_NOTES list.
life_analysis fills in certain vectors containing information about
- register usage: reg_n_refs, reg_n_deaths, reg_n_sets, reg_live_length,
- reg_n_calls_crosses and reg_basic_block.
+ register usage: REG_N_REFS, REG_N_DEATHS, REG_N_SETS, REG_LIVE_LENGTH,
+ REG_N_CALLS_CROSSED and REG_BASIC_BLOCK.
life_analysis sets current_function_sp_is_unchanging if the function
doesn't modify the stack pointer. */
-/* TODO:
+/* TODO:
Split out from life_analysis:
- local property discovery (bb->local_live, bb->local_set)
@@ -121,23 +120,29 @@ Boston, MA 02111-1307, USA. */
#include "config.h"
#include "system.h"
+#include "tree.h"
#include "rtl.h"
+#include "tm_p.h"
+#include "hard-reg-set.h"
#include "basic-block.h"
#include "insn-config.h"
#include "regs.h"
-#include "hard-reg-set.h"
#include "flags.h"
#include "output.h"
+#include "function.h"
#include "except.h"
#include "toplev.h"
#include "recog.h"
-#include "insn-flags.h"
+#include "expr.h"
+#include "ssa.h"
+#include "timevar.h"
#include "obstack.h"
+#include "splay-tree.h"
+
#define obstack_chunk_alloc xmalloc
#define obstack_chunk_free free
-
/* EXIT_IGNORE_STACK should be nonzero if, when returning from a function,
the stack pointer does not matter. The value is tested only in
functions that have frame pointers.
@@ -146,54 +151,28 @@ Boston, MA 02111-1307, USA. */
#define EXIT_IGNORE_STACK 0
#endif
+#ifndef HAVE_epilogue
+#define HAVE_epilogue 0
+#endif
+#ifndef HAVE_prologue
+#define HAVE_prologue 0
+#endif
+#ifndef HAVE_sibcall_epilogue
+#define HAVE_sibcall_epilogue 0
+#endif
-/* The contents of the current function definition are allocated
- in this obstack, and all are freed at the end of the function.
- For top-level functions, this is temporary_obstack.
- Separate obstacks are made for nested functions. */
-
-extern struct obstack *function_obstack;
-
-/* List of labels that must never be deleted. */
-extern rtx forced_labels;
-
-/* Number of basic blocks in the current function. */
-
-int n_basic_blocks;
-
-/* The basic block array. */
-
-varray_type basic_block_info;
-
-/* The special entry and exit blocks. */
+#ifndef LOCAL_REGNO
+#define LOCAL_REGNO(REGNO) 0
+#endif
+#ifndef EPILOGUE_USES
+#define EPILOGUE_USES(REGNO) 0
+#endif
-struct basic_block_def entry_exit_blocks[2] =
-{
- {
- NULL, /* head */
- NULL, /* end */
- NULL, /* pred */
- NULL, /* succ */
- NULL, /* local_set */
- NULL, /* global_live_at_start */
- NULL, /* global_live_at_end */
- NULL, /* aux */
- ENTRY_BLOCK, /* index */
- 0 /* loop_depth */
- },
- {
- NULL, /* head */
- NULL, /* end */
- NULL, /* pred */
- NULL, /* succ */
- NULL, /* local_set */
- NULL, /* global_live_at_start */
- NULL, /* global_live_at_end */
- NULL, /* aux */
- EXIT_BLOCK, /* index */
- 0 /* loop_depth */
- }
-};
+#ifdef HAVE_conditional_execution
+#ifndef REVERSE_CONDEXEC_PREDICATES_P
+#define REVERSE_CONDEXEC_PREDICATES_P(x, y) ((x) == reverse_condition (y))
+#endif
+#endif
/* Nonzero if the second flow pass has completed. */
int flow2_completed;
@@ -206,16 +185,6 @@ int max_regno;
varray_type reg_n_info;
-/* Size of the reg_n_info table. */
-
-unsigned int reg_n_max;
-
-/* Element N is the next insn that uses (hard or pseudo) register number N
- within the current basic block; or zero, if there is no such insn.
- This is valid only during the final backward scan in propagate_block. */
-
-static rtx *reg_next_use;
-
/* Size of a regset for the current function,
in (1) bytes and (2) elements. */
@@ -233,2710 +202,1795 @@ regset regs_live_at_setjmp;
are another pair, etc. */
rtx regs_may_share;
-/* Depth within loops of basic block being scanned for lifetime analysis,
- plus one. This is the weight attached to references to registers. */
-
-static int loop_depth;
-
-/* During propagate_block, this is non-zero if the value of CC0 is live. */
-
-static int cc0_live;
-
-/* During propagate_block, this contains a list of all the MEMs we are
- tracking for dead store elimination.
-
- ?!? Note we leak memory by not free-ing items on this list. We need to
- write some generic routines to operate on memory lists since cse, gcse,
- loop, sched, flow and possibly other passes all need to do basically the
- same operations on these lists. */
-
-static rtx mem_set_list;
+/* Callback that determines if it's ok for a function to have no
+ noreturn attribute. */
+int (*lang_missing_noreturn_ok_p) PARAMS ((tree));
/* Set of registers that may be eliminable. These are handled specially
in updating regs_ever_live. */
static HARD_REG_SET elim_reg_set;
-/* The basic block structure for every insn, indexed by uid. */
-
-varray_type basic_block_for_insn;
-
-/* The labels mentioned in non-jump rtl. Valid during find_basic_blocks. */
-/* ??? Should probably be using LABEL_NUSES instead. It would take a
- bit of surgery to be able to use or co-opt the routines in jump. */
+/* Holds information for tracking conditional register life information. */
+struct reg_cond_life_info
+{
+ /* A boolean expression of conditions under which a register is dead. */
+ rtx condition;
+ /* Conditions under which a register is dead at the basic block end. */
+ rtx orig_condition;
-static rtx label_value_list;
+ /* A boolean expression of conditions under which a register has been
+ stored into. */
+ rtx stores;
-/* INSN_VOLATILE (insn) is 1 if the insn refers to anything volatile. */
+ /* ??? Could store mask of bytes that are dead, so that we could finally
+ track lifetimes of multi-word registers accessed via subregs. */
+};
-#define INSN_VOLATILE(INSN) bitmap_bit_p (uid_volatile, INSN_UID (INSN))
-#define SET_INSN_VOLATILE(INSN) bitmap_set_bit (uid_volatile, INSN_UID (INSN))
-static bitmap uid_volatile;
+/* For use in communicating between propagate_block and its subroutines.
+ Holds all information needed to compute life and def-use information. */
-/* Forward declarations */
-static int count_basic_blocks PROTO((rtx));
-static rtx find_basic_blocks_1 PROTO((rtx, rtx*));
-static void create_basic_block PROTO((int, rtx, rtx, rtx));
-static void compute_bb_for_insn PROTO((varray_type, int));
-static void clear_edges PROTO((void));
-static void make_edges PROTO((rtx, rtx*));
-static void make_edge PROTO((basic_block, basic_block, int));
-static void make_label_edge PROTO((basic_block, rtx, int));
-static void mark_critical_edges PROTO((void));
-
-static void commit_one_edge_insertion PROTO((edge));
-
-static void delete_unreachable_blocks PROTO((void));
-static void delete_eh_regions PROTO((void));
-static int can_delete_note_p PROTO((rtx));
-static void delete_insn_chain PROTO((rtx, rtx));
-static int delete_block PROTO((basic_block));
-static void expunge_block PROTO((basic_block));
-static rtx flow_delete_insn PROTO((rtx));
-static int can_delete_label_p PROTO((rtx));
-static void merge_blocks_nomove PROTO((basic_block, basic_block));
-static int merge_blocks PROTO((edge,basic_block,basic_block));
-static void tidy_fallthru_edge PROTO((edge,basic_block,basic_block));
-static void calculate_loop_depth PROTO((rtx));
-
-static int set_noop_p PROTO((rtx));
-static int noop_move_p PROTO((rtx));
-static void notice_stack_pointer_modification PROTO ((rtx, rtx));
-static void record_volatile_insns PROTO((rtx));
-static void mark_regs_live_at_end PROTO((regset));
-static void life_analysis_1 PROTO((rtx, int, int));
-static void init_regset_vector PROTO ((regset *, int,
- struct obstack *));
-static void propagate_block PROTO((regset, rtx, rtx, int,
- regset, int, int));
-static int insn_dead_p PROTO((rtx, regset, int, rtx));
-static int libcall_dead_p PROTO((rtx, regset, rtx, rtx));
-static void mark_set_regs PROTO((regset, regset, rtx,
- rtx, regset));
-static void mark_set_1 PROTO((regset, regset, rtx,
- rtx, regset));
-#ifdef AUTO_INC_DEC
-static void find_auto_inc PROTO((regset, rtx, rtx));
-static int try_pre_increment_1 PROTO((rtx));
-static int try_pre_increment PROTO((rtx, rtx, HOST_WIDE_INT));
-#endif
-static void mark_used_regs PROTO((regset, regset, rtx, int, rtx));
-void dump_flow_info PROTO((FILE *));
-static void dump_edge_info PROTO((FILE *, edge, int));
-
-static int_list_ptr alloc_int_list_node PROTO ((int_list_block **));
-static int_list_ptr add_int_list_node PROTO ((int_list_block **,
- int_list **, int));
-
-static void add_pred_succ PROTO ((int, int, int_list_ptr *,
- int_list_ptr *, int *, int *));
-
-static void count_reg_sets_1 PROTO ((rtx));
-static void count_reg_sets PROTO ((rtx));
-static void count_reg_references PROTO ((rtx));
-static void notice_stack_pointer_modification PROTO ((rtx, rtx));
-static void invalidate_mems_from_autoinc PROTO ((rtx));
-void verify_flow_info PROTO ((void));
-
-/* Find basic blocks of the current function.
- F is the first insn of the function and NREGS the number of register
- numbers in use. */
-
-void
-find_basic_blocks (f, nregs, file, do_cleanup)
- rtx f;
- int nregs ATTRIBUTE_UNUSED;
- FILE *file ATTRIBUTE_UNUSED;
- int do_cleanup;
+struct propagate_block_info
{
- rtx *bb_eh_end;
- int max_uid;
-
- /* Flush out existing data. */
- if (basic_block_info != NULL)
- {
- int i;
-
- clear_edges ();
+ /* The basic block we're considering. */
+ basic_block bb;
- /* Clear bb->aux on all extant basic blocks. We'll use this as a
- tag for reuse during create_basic_block, just in case some pass
- copies around basic block notes improperly. */
- for (i = 0; i < n_basic_blocks; ++i)
- BASIC_BLOCK (i)->aux = NULL;
+ /* Bit N is set if register N is conditionally or unconditionally live. */
+ regset reg_live;
- VARRAY_FREE (basic_block_info);
- }
+ /* Bit N is set if register N is set this insn. */
+ regset new_set;
- n_basic_blocks = count_basic_blocks (f);
+ /* Element N is the next insn that uses (hard or pseudo) register N
+ within the current basic block; or zero, if there is no such insn. */
+ rtx *reg_next_use;
- /* Size the basic block table. The actual structures will be allocated
- by find_basic_blocks_1, since we want to keep the structure pointers
- stable across calls to find_basic_blocks. */
- /* ??? This whole issue would be much simpler if we called find_basic_blocks
- exactly once, and thereafter we don't have a single long chain of
- instructions at all until close to the end of compilation when we
- actually lay them out. */
+ /* Contains a list of all the MEMs we are tracking for dead store
+ elimination. */
+ rtx mem_set_list;
- VARRAY_BB_INIT (basic_block_info, n_basic_blocks, "basic_block_info");
+ /* If non-null, record the set of registers set unconditionally in the
+ basic block. */
+ regset local_set;
- /* An array to record the active exception region at the end of each
- basic block. It is filled in by find_basic_blocks_1 for make_edges. */
- bb_eh_end = (rtx *) alloca (n_basic_blocks * sizeof (rtx));
+ /* If non-null, record the set of registers set conditionally in the
+ basic block. */
+ regset cond_local_set;
- label_value_list = find_basic_blocks_1 (f, bb_eh_end);
-
- /* Record the block to which an insn belongs. */
- /* ??? This should be done another way, by which (perhaps) a label is
- tagged directly with the basic block that it starts. It is used for
- more than that currently, but IMO that is the only valid use. */
+#ifdef HAVE_conditional_execution
+ /* Indexed by register number, holds a reg_cond_life_info for each
+ register that is not unconditionally live or dead. */
+ splay_tree reg_cond_dead;
- max_uid = get_max_uid ();
-#ifdef AUTO_INC_DEC
- /* Leave space for insns life_analysis makes in some cases for auto-inc.
- These cases are rare, so we don't need too much space. */
- max_uid += max_uid / 10;
+ /* Bit N is set if register N is in an expression in reg_cond_dead. */
+ regset reg_cond_reg;
#endif
- VARRAY_BB_INIT (basic_block_for_insn, max_uid, "basic_block_for_insn");
- compute_bb_for_insn (basic_block_for_insn, max_uid);
+ /* The length of mem_set_list. */
+ int mem_set_list_len;
- /* Discover the edges of our cfg. */
+ /* Non-zero if the value of CC0 is live. */
+ int cc0_live;
- make_edges (label_value_list, bb_eh_end);
-
- /* Delete unreachable blocks. */
-
- if (do_cleanup)
- delete_unreachable_blocks ();
-
- /* Mark critical edges. */
-
- mark_critical_edges ();
-
- /* Discover the loop depth at the start of each basic block to aid
- register allocation. */
- calculate_loop_depth (f);
+ /* Flags controling the set of information propagate_block collects. */
+ int flags;
+};
- /* Kill the data we won't maintain. */
- label_value_list = 0;
+/* Maximum length of pbi->mem_set_list before we start dropping
+ new elements on the floor. */
+#define MAX_MEM_SET_LIST_LEN 100
-#ifdef ENABLE_CHECKING
- verify_flow_info ();
+/* Forward declarations */
+static int verify_wide_reg_1 PARAMS ((rtx *, void *));
+static void verify_wide_reg PARAMS ((int, basic_block));
+static void verify_local_live_at_start PARAMS ((regset, basic_block));
+static void notice_stack_pointer_modification_1 PARAMS ((rtx, rtx, void *));
+static void notice_stack_pointer_modification PARAMS ((rtx));
+static void mark_reg PARAMS ((rtx, void *));
+static void mark_regs_live_at_end PARAMS ((regset));
+static int set_phi_alternative_reg PARAMS ((rtx, int, int, void *));
+static void calculate_global_regs_live PARAMS ((sbitmap, sbitmap, int));
+static void propagate_block_delete_insn PARAMS ((basic_block, rtx));
+static rtx propagate_block_delete_libcall PARAMS ((rtx, rtx));
+static int insn_dead_p PARAMS ((struct propagate_block_info *,
+ rtx, int, rtx));
+static int libcall_dead_p PARAMS ((struct propagate_block_info *,
+ rtx, rtx));
+static void mark_set_regs PARAMS ((struct propagate_block_info *,
+ rtx, rtx));
+static void mark_set_1 PARAMS ((struct propagate_block_info *,
+ enum rtx_code, rtx, rtx,
+ rtx, int));
+static int find_regno_partial PARAMS ((rtx *, void *));
+
+#ifdef HAVE_conditional_execution
+static int mark_regno_cond_dead PARAMS ((struct propagate_block_info *,
+ int, rtx));
+static void free_reg_cond_life_info PARAMS ((splay_tree_value));
+static int flush_reg_cond_reg_1 PARAMS ((splay_tree_node, void *));
+static void flush_reg_cond_reg PARAMS ((struct propagate_block_info *,
+ int));
+static rtx elim_reg_cond PARAMS ((rtx, unsigned int));
+static rtx ior_reg_cond PARAMS ((rtx, rtx, int));
+static rtx not_reg_cond PARAMS ((rtx));
+static rtx and_reg_cond PARAMS ((rtx, rtx, int));
#endif
-}
-
-/* Count the basic blocks of the function. */
+#ifdef AUTO_INC_DEC
+static void attempt_auto_inc PARAMS ((struct propagate_block_info *,
+ rtx, rtx, rtx, rtx, rtx));
+static void find_auto_inc PARAMS ((struct propagate_block_info *,
+ rtx, rtx));
+static int try_pre_increment_1 PARAMS ((struct propagate_block_info *,
+ rtx));
+static int try_pre_increment PARAMS ((rtx, rtx, HOST_WIDE_INT));
+#endif
+static void mark_used_reg PARAMS ((struct propagate_block_info *,
+ rtx, rtx, rtx));
+static void mark_used_regs PARAMS ((struct propagate_block_info *,
+ rtx, rtx, rtx));
+void dump_flow_info PARAMS ((FILE *));
+void debug_flow_info PARAMS ((void));
+static void add_to_mem_set_list PARAMS ((struct propagate_block_info *,
+ rtx));
+static void invalidate_mems_from_autoinc PARAMS ((struct propagate_block_info *,
+ rtx));
+static void invalidate_mems_from_set PARAMS ((struct propagate_block_info *,
+ rtx));
+static void delete_dead_jumptables PARAMS ((void));
+static void clear_log_links PARAMS ((sbitmap));
+
-static int
-count_basic_blocks (f)
- rtx f;
+void
+check_function_return_warnings ()
{
- register rtx insn;
- register RTX_CODE prev_code;
- register int count = 0;
- int eh_region = 0;
- int call_had_abnormal_edge = 0;
- rtx prev_call = NULL_RTX;
-
- prev_code = JUMP_INSN;
- for (insn = f; insn; insn = NEXT_INSN (insn))
+ if (warn_missing_noreturn
+ && !TREE_THIS_VOLATILE (cfun->decl)
+ && EXIT_BLOCK_PTR->pred == NULL
+ && (lang_missing_noreturn_ok_p
+ && !lang_missing_noreturn_ok_p (cfun->decl)))
+ warning ("function might be possible candidate for attribute `noreturn'");
+
+ /* If we have a path to EXIT, then we do return. */
+ if (TREE_THIS_VOLATILE (cfun->decl)
+ && EXIT_BLOCK_PTR->pred != NULL)
+ warning ("`noreturn' function does return");
+
+ /* If the clobber_return_insn appears in some basic block, then we
+ do reach the end without returning a value. */
+ else if (warn_return_type
+ && cfun->x_clobber_return_insn != NULL
+ && EXIT_BLOCK_PTR->pred != NULL)
{
- register RTX_CODE code = GET_CODE (insn);
-
- if (code == CODE_LABEL
- || (GET_RTX_CLASS (code) == 'i'
- && (prev_code == JUMP_INSN
- || prev_code == BARRIER
- || (prev_code == CALL_INSN && call_had_abnormal_edge))))
- {
- count++;
-
- /* If the previous insn was a call that did not create an
- abnormal edge, we want to add a nop so that the CALL_INSN
- itself is not at basic_block_end. This allows us to
- easily distinguish between normal calls and those which
- create abnormal edges in the flow graph. */
-
- if (count > 0 && prev_call != 0 && !call_had_abnormal_edge)
- {
- rtx nop = gen_rtx_USE (VOIDmode, const0_rtx);
- emit_insn_after (nop, prev_call);
- }
- }
+ int max_uid = get_max_uid ();
- /* Record whether this call created an edge. */
- if (code == CALL_INSN)
+ /* If clobber_return_insn was excised by jump1, then renumber_insns
+ can make max_uid smaller than the number still recorded in our rtx.
+ That's fine, since this is a quick way of verifying that the insn
+ is no longer in the chain. */
+ if (INSN_UID (cfun->x_clobber_return_insn) < max_uid)
{
- rtx note = find_reg_note (insn, REG_EH_REGION, NULL_RTX);
- int region = (note ? XINT (XEXP (note, 0), 0) : 1);
- prev_call = insn;
- call_had_abnormal_edge = 0;
-
- /* If there is a specified EH region, we have an edge. */
- if (eh_region && region > 0)
- call_had_abnormal_edge = 1;
- else
- {
- /* If there is a nonlocal goto label and the specified
- region number isn't -1, we have an edge. (0 means
- no throw, but might have a nonlocal goto). */
- if (nonlocal_goto_handler_labels && region >= 0)
- call_had_abnormal_edge = 1;
- }
+ /* Recompute insn->block mapping, since the initial mapping is
+ set before we delete unreachable blocks. */
+ if (BLOCK_FOR_INSN (cfun->x_clobber_return_insn) != NULL)
+ warning ("control reaches end of non-void function");
}
- else if (code != NOTE)
- prev_call = NULL_RTX;
-
- if (code != NOTE)
- prev_code = code;
- else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_BEG)
- ++eh_region;
- else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_END)
- --eh_region;
-
}
-
- /* The rest of the compiler works a bit smoother when we don't have to
- check for the edge case of do-nothing functions with no basic blocks. */
- if (count == 0)
- {
- emit_insn (gen_rtx_USE (VOIDmode, const0_rtx));
- count = 1;
- }
-
- return count;
}
+
+/* Return the INSN immediately following the NOTE_INSN_BASIC_BLOCK
+ note associated with the BLOCK. */
-/* Find all basic blocks of the function whose first insn is F.
- Store the correct data in the tables that describe the basic blocks,
- set up the chains of references for each CODE_LABEL, and
- delete any entire basic blocks that cannot be reached.
-
- NONLOCAL_LABEL_LIST is a list of non-local labels in the function. Blocks
- that are otherwise unreachable may be reachable with a non-local goto.
-
- BB_EH_END is an array in which we record the list of exception regions
- active at the end of every basic block. */
-
-static rtx
-find_basic_blocks_1 (f, bb_eh_end)
- rtx f;
- rtx *bb_eh_end;
+rtx
+first_insn_after_basic_block_note (block)
+ basic_block block;
{
- register rtx insn, next;
- int call_has_abnormal_edge = 0;
- int i = 0;
- rtx bb_note = NULL_RTX;
- rtx eh_list = NULL_RTX;
- rtx label_value_list = NULL_RTX;
- rtx head = NULL_RTX;
- rtx end = NULL_RTX;
-
- /* We process the instructions in a slightly different way than we did
- previously. This is so that we see a NOTE_BASIC_BLOCK after we have
- closed out the previous block, so that it gets attached at the proper
- place. Since this form should be equivalent to the previous,
- find_basic_blocks_0 continues to use the old form as a check. */
-
- for (insn = f; insn; insn = next)
- {
- enum rtx_code code = GET_CODE (insn);
+ rtx insn;
- next = NEXT_INSN (insn);
+ /* Get the first instruction in the block. */
+ insn = block->head;
- if (code == CALL_INSN)
- {
- /* Record whether this call created an edge. */
- rtx note = find_reg_note (insn, REG_EH_REGION, NULL_RTX);
- int region = (note ? XINT (XEXP (note, 0), 0) : 1);
- call_has_abnormal_edge = 0;
-
- /* If there is an EH region, we have an edge. */
- if (eh_list && region > 0)
- call_has_abnormal_edge = 1;
- else
- {
- /* If there is a nonlocal goto label and the specified
- region number isn't -1, we have an edge. (0 means
- no throw, but might have a nonlocal goto). */
- if (nonlocal_goto_handler_labels && region >= 0)
- call_has_abnormal_edge = 1;
- }
- }
+ if (insn == NULL_RTX)
+ return NULL_RTX;
+ if (GET_CODE (insn) == CODE_LABEL)
+ insn = NEXT_INSN (insn);
+ if (!NOTE_INSN_BASIC_BLOCK_P (insn))
+ abort ();
- switch (code)
- {
- case NOTE:
- {
- int kind = NOTE_LINE_NUMBER (insn);
-
- /* Keep a LIFO list of the currently active exception notes. */
- if (kind == NOTE_INSN_EH_REGION_BEG)
- eh_list = gen_rtx_INSN_LIST (VOIDmode, insn, eh_list);
- else if (kind == NOTE_INSN_EH_REGION_END)
- eh_list = XEXP (eh_list, 1);
-
- /* Look for basic block notes with which to keep the
- basic_block_info pointers stable. Unthread the note now;
- we'll put it back at the right place in create_basic_block.
- Or not at all if we've already found a note in this block. */
- else if (kind == NOTE_INSN_BASIC_BLOCK)
- {
- if (bb_note == NULL_RTX)
- bb_note = insn;
- next = flow_delete_insn (insn);
- }
+ return NEXT_INSN (insn);
+}
+
+/* Perform data flow analysis.
+ F is the first insn of the function; FLAGS is a set of PROP_* flags
+ to be used in accumulating flow info. */
- break;
- }
+void
+life_analysis (f, file, flags)
+ rtx f;
+ FILE *file;
+ int flags;
+{
+#ifdef ELIMINABLE_REGS
+ int i;
+ static const struct {const int from, to; } eliminables[] = ELIMINABLE_REGS;
+#endif
- case CODE_LABEL:
- /* A basic block starts at a label. If we've closed one off due
- to a barrier or some such, no need to do it again. */
- if (head != NULL_RTX)
- {
- /* While we now have edge lists with which other portions of
- the compiler might determine a call ending a basic block
- does not imply an abnormal edge, it will be a bit before
- everything can be updated. So continue to emit a noop at
- the end of such a block. */
- if (GET_CODE (end) == CALL_INSN)
- {
- rtx nop = gen_rtx_USE (VOIDmode, const0_rtx);
- end = emit_insn_after (nop, end);
- }
+ /* Record which registers will be eliminated. We use this in
+ mark_used_regs. */
- bb_eh_end[i] = eh_list;
- create_basic_block (i++, head, end, bb_note);
- bb_note = NULL_RTX;
- }
- head = end = insn;
- break;
+ CLEAR_HARD_REG_SET (elim_reg_set);
- case JUMP_INSN:
- /* A basic block ends at a jump. */
- if (head == NULL_RTX)
- head = insn;
- else
- {
- /* ??? Make a special check for table jumps. The way this
- happens is truely and amazingly gross. We are about to
- create a basic block that contains just a code label and
- an addr*vec jump insn. Worse, an addr_diff_vec creates
- its own natural loop.
+#ifdef ELIMINABLE_REGS
+ for (i = 0; i < (int) ARRAY_SIZE (eliminables); i++)
+ SET_HARD_REG_BIT (elim_reg_set, eliminables[i].from);
+#else
+ SET_HARD_REG_BIT (elim_reg_set, FRAME_POINTER_REGNUM);
+#endif
- Prevent this bit of brain damage, pasting things together
- correctly in make_edges.
+ if (! optimize)
+ flags &= ~(PROP_LOG_LINKS | PROP_AUTOINC | PROP_ALLOW_CFG_CHANGES);
- The correct solution involves emitting the table directly
- on the tablejump instruction as a note, or JUMP_LABEL. */
+ /* The post-reload life analysis have (on a global basis) the same
+ registers live as was computed by reload itself. elimination
+ Otherwise offsets and such may be incorrect.
- if (GET_CODE (PATTERN (insn)) == ADDR_VEC
- || GET_CODE (PATTERN (insn)) == ADDR_DIFF_VEC)
- {
- head = end = NULL;
- n_basic_blocks--;
- break;
- }
- }
- end = insn;
- goto new_bb_inclusive;
+ Reload will make some registers as live even though they do not
+ appear in the rtl.
- case BARRIER:
- /* A basic block ends at a barrier. It may be that an unconditional
- jump already closed the basic block -- no need to do it again. */
- if (head == NULL_RTX)
- break;
+ We don't want to create new auto-incs after reload, since they
+ are unlikely to be useful and can cause problems with shared
+ stack slots. */
+ if (reload_completed)
+ flags &= ~(PROP_REG_INFO | PROP_AUTOINC);
- /* While we now have edge lists with which other portions of the
- compiler might determine a call ending a basic block does not
- imply an abnormal edge, it will be a bit before everything can
- be updated. So continue to emit a noop at the end of such a
- block. */
- if (GET_CODE (end) == CALL_INSN)
- {
- rtx nop = gen_rtx_USE (VOIDmode, const0_rtx);
- end = emit_insn_after (nop, end);
- }
- goto new_bb_exclusive;
+ /* We want alias analysis information for local dead store elimination. */
+ if (optimize && (flags & PROP_SCAN_DEAD_CODE))
+ init_alias_analysis ();
+
+ /* Always remove no-op moves. Do this before other processing so
+ that we don't have to keep re-scanning them. */
+ delete_noop_moves (f);
+ purge_all_dead_edges (false);
+
+ /* Some targets can emit simpler epilogues if they know that sp was
+ not ever modified during the function. After reload, of course,
+ we've already emitted the epilogue so there's no sense searching. */
+ if (! reload_completed)
+ notice_stack_pointer_modification (f);
+
+ /* Allocate and zero out data structures that will record the
+ data from lifetime analysis. */
+ allocate_reg_life_data ();
+ allocate_bb_life_data ();
- case CALL_INSN:
- /* A basic block ends at a call that can either throw or
- do a non-local goto. */
- if (call_has_abnormal_edge)
- {
- new_bb_inclusive:
- if (head == NULL_RTX)
- head = insn;
- end = insn;
-
- new_bb_exclusive:
- bb_eh_end[i] = eh_list;
- create_basic_block (i++, head, end, bb_note);
- head = end = NULL_RTX;
- bb_note = NULL_RTX;
- break;
- }
- /* FALLTHRU */
+ /* Find the set of registers live on function exit. */
+ mark_regs_live_at_end (EXIT_BLOCK_PTR->global_live_at_start);
- default:
- if (GET_RTX_CLASS (code) == 'i')
- {
- if (head == NULL_RTX)
- head = insn;
- end = insn;
- }
- break;
- }
+ /* "Update" life info from zero. It'd be nice to begin the
+ relaxation with just the exit and noreturn blocks, but that set
+ is not immediately handy. */
- if (GET_RTX_CLASS (code) == 'i')
- {
- rtx note;
+ if (flags & PROP_REG_INFO)
+ memset (regs_ever_live, 0, sizeof (regs_ever_live));
+ update_life_info (NULL, UPDATE_LIFE_GLOBAL, flags);
- /* Make a list of all labels referred to other than by jumps
- (which just don't have the REG_LABEL notes).
+ /* Clean up. */
+ if (optimize && (flags & PROP_SCAN_DEAD_CODE))
+ end_alias_analysis ();
- Make a special exception for labels followed by an ADDR*VEC,
- as this would be a part of the tablejump setup code.
+ if (file)
+ dump_flow_info (file);
- Make a special exception for the eh_return_stub_label, which
- we know isn't part of any otherwise visible control flow. */
-
- for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
- if (REG_NOTE_KIND (note) == REG_LABEL)
- {
- rtx lab = XEXP (note, 0), next;
-
- if (lab == eh_return_stub_label)
- ;
- else if ((next = next_nonnote_insn (lab)) != NULL
- && GET_CODE (next) == JUMP_INSN
- && (GET_CODE (PATTERN (next)) == ADDR_VEC
- || GET_CODE (PATTERN (next)) == ADDR_DIFF_VEC))
- ;
- else
- label_value_list
- = gen_rtx_EXPR_LIST (VOIDmode, XEXP (note, 0),
- label_value_list);
- }
- }
- }
+ free_basic_block_vars (1);
- if (head != NULL_RTX)
- {
- bb_eh_end[i] = eh_list;
- create_basic_block (i++, head, end, bb_note);
- }
+#ifdef ENABLE_CHECKING
+ {
+ rtx insn;
- if (i != n_basic_blocks)
- abort ();
+ /* Search for any REG_LABEL notes which reference deleted labels. */
+ for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
+ {
+ rtx inote = find_reg_note (insn, REG_LABEL, NULL_RTX);
- return label_value_list;
+ if (inote && GET_CODE (inote) == NOTE_INSN_DELETED_LABEL)
+ abort ();
+ }
+ }
+#endif
+ /* Removing dead insns should've made jumptables really dead. */
+ delete_dead_jumptables ();
}
-/* Create a new basic block consisting of the instructions between
- HEAD and END inclusive. Reuses the note and basic block struct
- in BB_NOTE, if any. */
-
-static void
-create_basic_block (index, head, end, bb_note)
- int index;
- rtx head, end, bb_note;
-{
- basic_block bb;
-
- if (bb_note
- && ! RTX_INTEGRATED_P (bb_note)
- && (bb = NOTE_BASIC_BLOCK (bb_note)) != NULL
- && bb->aux == NULL)
- {
- /* If we found an existing note, thread it back onto the chain. */
-
- if (GET_CODE (head) == CODE_LABEL)
- add_insn_after (bb_note, head);
- else
- {
- add_insn_before (bb_note, head);
- head = bb_note;
- }
- }
- else
- {
- /* Otherwise we must create a note and a basic block structure.
- Since we allow basic block structs in rtl, give the struct
- the same lifetime by allocating it off the function obstack
- rather than using malloc. */
-
- bb = (basic_block) obstack_alloc (function_obstack, sizeof (*bb));
- memset (bb, 0, sizeof (*bb));
-
- if (GET_CODE (head) == CODE_LABEL)
- bb_note = emit_note_after (NOTE_INSN_BASIC_BLOCK, head);
- else
- {
- bb_note = emit_note_before (NOTE_INSN_BASIC_BLOCK, head);
- head = bb_note;
- }
- NOTE_BASIC_BLOCK (bb_note) = bb;
- }
-
- /* Always include the bb note in the block. */
- if (NEXT_INSN (end) == bb_note)
- end = bb_note;
+/* A subroutine of verify_wide_reg, called through for_each_rtx.
+ Search for REGNO. If found, return 2 if it is not wider than
+ word_mode. */
- bb->head = head;
- bb->end = end;
- bb->index = index;
- BASIC_BLOCK (index) = bb;
-
- /* Tag the block so that we know it has been used when considering
- other basic block notes. */
- bb->aux = bb;
-}
-
-/* Records the basic block struct in BB_FOR_INSN, for every instruction
- indexed by INSN_UID. MAX is the size of the array. */
-
-static void
-compute_bb_for_insn (bb_for_insn, max)
- varray_type bb_for_insn;
- int max;
+static int
+verify_wide_reg_1 (px, pregno)
+ rtx *px;
+ void *pregno;
{
- int i;
+ rtx x = *px;
+ unsigned int regno = *(int *) pregno;
- for (i = 0; i < n_basic_blocks; ++i)
+ if (GET_CODE (x) == REG && REGNO (x) == regno)
{
- basic_block bb = BASIC_BLOCK (i);
- rtx insn, end;
-
- end = bb->end;
- insn = bb->head;
- while (1)
- {
- int uid = INSN_UID (insn);
- if (uid < max)
- VARRAY_BB (bb_for_insn, uid) = bb;
- if (insn == end)
- break;
- insn = NEXT_INSN (insn);
- }
+ if (GET_MODE_BITSIZE (GET_MODE (x)) <= BITS_PER_WORD)
+ return 2;
+ return 1;
}
+ return 0;
}
-/* Free the memory associated with the edge structures. */
+/* A subroutine of verify_local_live_at_start. Search through insns
+ of BB looking for register REGNO. */
static void
-clear_edges ()
+verify_wide_reg (regno, bb)
+ int regno;
+ basic_block bb;
{
- int i;
- edge n, e;
+ rtx head = bb->head, end = bb->end;
- for (i = 0; i < n_basic_blocks; ++i)
+ while (1)
{
- basic_block bb = BASIC_BLOCK (i);
-
- for (e = bb->succ; e ; e = n)
+ if (INSN_P (head))
{
- n = e->succ_next;
- free (e);
+ int r = for_each_rtx (&PATTERN (head), verify_wide_reg_1, &regno);
+ if (r == 1)
+ return;
+ if (r == 2)
+ break;
}
-
- bb->succ = 0;
- bb->pred = 0;
+ if (head == end)
+ break;
+ head = NEXT_INSN (head);
}
- for (e = ENTRY_BLOCK_PTR->succ; e ; e = n)
+ if (rtl_dump_file)
{
- n = e->succ_next;
- free (e);
+ fprintf (rtl_dump_file, "Register %d died unexpectedly.\n", regno);
+ dump_bb (bb, rtl_dump_file);
}
-
- ENTRY_BLOCK_PTR->succ = 0;
- EXIT_BLOCK_PTR->pred = 0;
+ abort ();
}
-/* Identify the edges between basic blocks.
-
- NONLOCAL_LABEL_LIST is a list of non-local labels in the function. Blocks
- that are otherwise unreachable may be reachable with a non-local goto.
-
- BB_EH_END is an array indexed by basic block number in which we record
- the list of exception regions active at the end of the basic block. */
+/* A subroutine of update_life_info. Verify that there are no untoward
+ changes in live_at_start during a local update. */
static void
-make_edges (label_value_list, bb_eh_end)
- rtx label_value_list;
- rtx *bb_eh_end;
+verify_local_live_at_start (new_live_at_start, bb)
+ regset new_live_at_start;
+ basic_block bb;
{
- int i;
-
- /* Assume no computed jump; revise as we create edges. */
- current_function_has_computed_jump = 0;
-
- /* By nature of the way these get numbered, block 0 is always the entry. */
- make_edge (ENTRY_BLOCK_PTR, BASIC_BLOCK (0), EDGE_FALLTHRU);
-
- for (i = 0; i < n_basic_blocks; ++i)
+ if (reload_completed)
{
- basic_block bb = BASIC_BLOCK (i);
- rtx insn, x, eh_list;
- enum rtx_code code;
- int force_fallthru = 0;
-
- /* If we have asynchronous exceptions, scan the notes for all exception
- regions active in the block. In the normal case, we only need the
- one active at the end of the block, which is bb_eh_end[i]. */
-
- eh_list = bb_eh_end[i];
- if (asynchronous_exceptions)
- {
- for (insn = bb->end; insn != bb->head; insn = PREV_INSN (insn))
- {
- if (GET_CODE (insn) == NOTE
- && NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_END)
- eh_list = gen_rtx_INSN_LIST (VOIDmode, insn, eh_list);
- }
- }
-
- /* Now examine the last instruction of the block, and discover the
- ways we can leave the block. */
-
- insn = bb->end;
- code = GET_CODE (insn);
-
- /* A branch. */
- if (code == JUMP_INSN)
+ /* After reload, there are no pseudos, nor subregs of multi-word
+ registers. The regsets should exactly match. */
+ if (! REG_SET_EQUAL_P (new_live_at_start, bb->global_live_at_start))
{
- rtx tmp;
-
- /* ??? Recognize a tablejump and do the right thing. */
- if ((tmp = JUMP_LABEL (insn)) != NULL_RTX
- && (tmp = NEXT_INSN (tmp)) != NULL_RTX
- && GET_CODE (tmp) == JUMP_INSN
- && (GET_CODE (PATTERN (tmp)) == ADDR_VEC
- || GET_CODE (PATTERN (tmp)) == ADDR_DIFF_VEC))
+ if (rtl_dump_file)
{
- rtvec vec;
- int j;
-
- if (GET_CODE (PATTERN (tmp)) == ADDR_VEC)
- vec = XVEC (PATTERN (tmp), 0);
- else
- vec = XVEC (PATTERN (tmp), 1);
-
- for (j = GET_NUM_ELEM (vec) - 1; j >= 0; --j)
- make_label_edge (bb, XEXP (RTVEC_ELT (vec, j), 0), 0);
-
- /* Some targets (eg, ARM) emit a conditional jump that also
- contains the out-of-range target. Scan for these and
- add an edge if necessary. */
- if ((tmp = single_set (insn)) != NULL
- && SET_DEST (tmp) == pc_rtx
- && GET_CODE (SET_SRC (tmp)) == IF_THEN_ELSE
- && GET_CODE (XEXP (SET_SRC (tmp), 2)) == LABEL_REF)
- make_label_edge (bb, XEXP (XEXP (SET_SRC (tmp), 2), 0), 0);
-
-#ifdef CASE_DROPS_THROUGH
- /* Silly VAXen. The ADDR_VEC is going to be in the way of
- us naturally detecting fallthru into the next block. */
- force_fallthru = 1;
-#endif
- }
-
- /* If this is a computed jump, then mark it as reaching
- everything on the label_value_list and forced_labels list. */
- else if (computed_jump_p (insn))
- {
- current_function_has_computed_jump = 1;
-
- for (x = label_value_list; x; x = XEXP (x, 1))
- make_label_edge (bb, XEXP (x, 0), EDGE_ABNORMAL);
-
- for (x = forced_labels; x; x = XEXP (x, 1))
- make_label_edge (bb, XEXP (x, 0), EDGE_ABNORMAL);
- }
-
- /* Returns create an exit out. */
- else if (returnjump_p (insn))
- make_edge (bb, EXIT_BLOCK_PTR, 0);
-
- /* Otherwise, we have a plain conditional or unconditional jump. */
- else
- {
- if (! JUMP_LABEL (insn))
- abort ();
- make_label_edge (bb, JUMP_LABEL (insn), 0);
+ fprintf (rtl_dump_file,
+ "live_at_start mismatch in bb %d, aborting\nNew:\n",
+ bb->index);
+ debug_bitmap_file (rtl_dump_file, new_live_at_start);
+ fputs ("Old:\n", rtl_dump_file);
+ dump_bb (bb, rtl_dump_file);
}
+ abort ();
}
+ }
+ else
+ {
+ int i;
- /* If this is a CALL_INSN, then mark it as reaching the active EH
- handler for this CALL_INSN. If we're handling asynchronous
- exceptions then any insn can reach any of the active handlers.
-
- Also mark the CALL_INSN as reaching any nonlocal goto handler. */
+ /* Find the set of changed registers. */
+ XOR_REG_SET (new_live_at_start, bb->global_live_at_start);
- if (code == CALL_INSN || asynchronous_exceptions)
+ EXECUTE_IF_SET_IN_REG_SET (new_live_at_start, 0, i,
{
- int is_call = (code == CALL_INSN ? EDGE_ABNORMAL_CALL : 0);
- handler_info *ptr;
-
- /* Use REG_EH_RETHROW and REG_EH_REGION if available. */
- /* ??? REG_EH_REGION is not generated presently. Is it
- inteded that there be multiple notes for the regions?
- or is my eh_list collection redundant with handler linking? */
-
- x = find_reg_note (insn, REG_EH_RETHROW, 0);
- if (!x)
- x = find_reg_note (insn, REG_EH_REGION, 0);
- if (x)
+ /* No registers should die. */
+ if (REGNO_REG_SET_P (bb->global_live_at_start, i))
{
- if (XINT (XEXP (x, 0), 0) > 0)
+ if (rtl_dump_file)
{
- ptr = get_first_handler (XINT (XEXP (x, 0), 0));
- while (ptr)
- {
- make_label_edge (bb, ptr->handler_label,
- EDGE_ABNORMAL | EDGE_EH | is_call);
- ptr = ptr->next;
- }
+ fprintf (rtl_dump_file,
+ "Register %d died unexpectedly.\n", i);
+ dump_bb (bb, rtl_dump_file);
}
+ abort ();
}
- else
- {
- for (x = eh_list; x; x = XEXP (x, 1))
- {
- ptr = get_first_handler (NOTE_BLOCK_NUMBER (XEXP (x, 0)));
- while (ptr)
- {
- make_label_edge (bb, ptr->handler_label,
- EDGE_ABNORMAL | EDGE_EH | is_call);
- ptr = ptr->next;
- }
- }
- }
-
- if (code == CALL_INSN && nonlocal_goto_handler_labels)
- {
- /* ??? This could be made smarter: in some cases it's possible
- to tell that certain calls will not do a nonlocal goto.
-
- For example, if the nested functions that do the nonlocal
- gotos do not have their addresses taken, then only calls to
- those functions or to other nested functions that use them
- could possibly do nonlocal gotos. */
-
- for (x = nonlocal_goto_handler_labels; x ; x = XEXP (x, 1))
- make_label_edge (bb, XEXP (x, 0),
- EDGE_ABNORMAL | EDGE_ABNORMAL_CALL);
- }
- }
- /* We know something about the structure of the function __throw in
- libgcc2.c. It is the only function that ever contains eh_stub
- labels. It modifies its return address so that the last block
- returns to one of the eh_stub labels within it. So we have to
- make additional edges in the flow graph. */
- if (i + 1 == n_basic_blocks && eh_return_stub_label != 0)
- make_label_edge (bb, eh_return_stub_label, EDGE_EH);
-
- /* Find out if we can drop through to the next block. */
- insn = next_nonnote_insn (insn);
- if (!insn || (i + 1 == n_basic_blocks && force_fallthru))
- make_edge (bb, EXIT_BLOCK_PTR, EDGE_FALLTHRU);
- else if (i + 1 < n_basic_blocks)
- {
- rtx tmp = BLOCK_HEAD (i + 1);
- if (GET_CODE (tmp) == NOTE)
- tmp = next_nonnote_insn (tmp);
- if (force_fallthru || insn == tmp)
- make_edge (bb, BASIC_BLOCK (i + 1), EDGE_FALLTHRU);
- }
+ /* Verify that the now-live register is wider than word_mode. */
+ verify_wide_reg (i, bb);
+ });
}
}
-/* Create an edge between two basic blocks. FLAGS are auxiliary information
- about the edge that is accumulated between calls. */
+/* Updates life information starting with the basic blocks set in BLOCKS.
+ If BLOCKS is null, consider it to be the universal set.
-static void
-make_edge (src, dst, flags)
- basic_block src, dst;
- int flags;
-{
- edge e;
+ If EXTENT is UPDATE_LIFE_LOCAL, such as after splitting or peepholeing,
+ we are only expecting local modifications to basic blocks. If we find
+ extra registers live at the beginning of a block, then we either killed
+ useful data, or we have a broken split that wants data not provided.
+ If we find registers removed from live_at_start, that means we have
+ a broken peephole that is killing a register it shouldn't.
- /* Make sure we don't add duplicate edges. */
+ ??? This is not true in one situation -- when a pre-reload splitter
+ generates subregs of a multi-word pseudo, current life analysis will
+ lose the kill. So we _can_ have a pseudo go live. How irritating.
- for (e = src->succ; e ; e = e->succ_next)
- if (e->dest == dst)
- {
- e->flags |= flags;
- return;
- }
+ Including PROP_REG_INFO does not properly refresh regs_ever_live
+ unless the caller resets it to zero. */
- e = (edge) xcalloc (1, sizeof (*e));
-
- e->succ_next = src->succ;
- e->pred_next = dst->pred;
- e->src = src;
- e->dest = dst;
- e->flags = flags;
+void
+update_life_info (blocks, extent, prop_flags)
+ sbitmap blocks;
+ enum update_life_extent extent;
+ int prop_flags;
+{
+ regset tmp;
+ regset_head tmp_head;
+ int i;
- src->succ = e;
- dst->pred = e;
-}
+ tmp = INITIALIZE_REG_SET (tmp_head);
-/* Create an edge from a basic block to a label. */
+ timevar_push ((extent == UPDATE_LIFE_LOCAL || blocks)
+ ? TV_LIFE_UPDATE : TV_LIFE);
-static void
-make_label_edge (src, label, flags)
- basic_block src;
- rtx label;
- int flags;
-{
- if (GET_CODE (label) != CODE_LABEL)
+ /* Changes to the CFG are only allowed when
+ doing a global update for the entire CFG. */
+ if ((prop_flags & PROP_ALLOW_CFG_CHANGES)
+ && (extent == UPDATE_LIFE_LOCAL || blocks))
abort ();
- /* If the label was never emitted, this insn is junk, but avoid a
- crash trying to refer to BLOCK_FOR_INSN (label). This can happen
- as a result of a syntax error and a diagnostic has already been
- printed. */
-
- if (INSN_UID (label) == 0)
- return;
+ /* Clear log links in case we are asked to (re)compute them. */
+ if (prop_flags & PROP_LOG_LINKS)
+ clear_log_links (blocks);
- make_edge (src, BLOCK_FOR_INSN (label), flags);
-}
-
-/* Identify critical edges and set the bits appropriately. */
-static void
-mark_critical_edges ()
-{
- int i, n = n_basic_blocks;
- basic_block bb;
+ /* For a global update, we go through the relaxation process again. */
+ if (extent != UPDATE_LIFE_LOCAL)
+ {
+ for ( ; ; )
+ {
+ int changed = 0;
- /* We begin with the entry block. This is not terribly important now,
- but could be if a front end (Fortran) implemented alternate entry
- points. */
- bb = ENTRY_BLOCK_PTR;
- i = -1;
+ calculate_global_regs_live (blocks, blocks,
+ prop_flags & (PROP_SCAN_DEAD_CODE
+ | PROP_ALLOW_CFG_CHANGES));
- while (1)
- {
- edge e;
+ if ((prop_flags & (PROP_KILL_DEAD_CODE | PROP_ALLOW_CFG_CHANGES))
+ != (PROP_KILL_DEAD_CODE | PROP_ALLOW_CFG_CHANGES))
+ break;
- /* (1) Critical edges must have a source with multiple successors. */
- if (bb->succ && bb->succ->succ_next)
- {
- for (e = bb->succ; e ; e = e->succ_next)
+ /* Removing dead code may allow the CFG to be simplified which
+ in turn may allow for further dead code detection / removal. */
+ for (i = n_basic_blocks - 1; i >= 0; --i)
{
- /* (2) Critical edges must have a destination with multiple
- predecessors. Note that we know there is at least one
- predecessor -- the edge we followed to get here. */
- if (e->dest->pred->pred_next)
- e->flags |= EDGE_CRITICAL;
- else
- e->flags &= ~EDGE_CRITICAL;
+ basic_block bb = BASIC_BLOCK (i);
+
+ COPY_REG_SET (tmp, bb->global_live_at_end);
+ changed |= propagate_block (bb, tmp, NULL, NULL,
+ prop_flags & (PROP_SCAN_DEAD_CODE
+ | PROP_KILL_DEAD_CODE));
}
- }
- else
- {
- for (e = bb->succ; e ; e = e->succ_next)
- e->flags &= ~EDGE_CRITICAL;
+
+ if (! changed || ! cleanup_cfg (CLEANUP_EXPENSIVE))
+ break;
}
- if (++i >= n)
- break;
- bb = BASIC_BLOCK (i);
+ /* If asked, remove notes from the blocks we'll update. */
+ if (extent == UPDATE_LIFE_GLOBAL_RM_NOTES)
+ count_or_remove_death_notes (blocks, 1);
}
-}
-
-/* Split a (typically critical) edge. Return the new block.
- Abort on abnormal edges.
-
- ??? The code generally expects to be called on critical edges.
- The case of a block ending in an unconditional jump to a
- block with multiple predecessors is not handled optimally. */
-
-basic_block
-split_edge (edge_in)
- edge edge_in;
-{
- basic_block old_pred, bb, old_succ;
- edge edge_out;
- rtx bb_note;
- int i;
-
- /* Abnormal edges cannot be split. */
- if ((edge_in->flags & EDGE_ABNORMAL) != 0)
- abort ();
-
- old_pred = edge_in->src;
- old_succ = edge_in->dest;
-
- /* Remove the existing edge from the destination's pred list. */
- {
- edge *pp;
- for (pp = &old_succ->pred; *pp != edge_in; pp = &(*pp)->pred_next)
- continue;
- *pp = edge_in->pred_next;
- edge_in->pred_next = NULL;
- }
- /* Create the new structures. */
- bb = (basic_block) obstack_alloc (function_obstack, sizeof (*bb));
- edge_out = (edge) xcalloc (1, sizeof (*edge_out));
+ if (blocks)
+ {
+ EXECUTE_IF_SET_IN_SBITMAP (blocks, 0, i,
+ {
+ basic_block bb = BASIC_BLOCK (i);
- memset (bb, 0, sizeof (*bb));
- bb->local_set = OBSTACK_ALLOC_REG_SET (function_obstack);
- bb->global_live_at_start = OBSTACK_ALLOC_REG_SET (function_obstack);
- bb->global_live_at_end = OBSTACK_ALLOC_REG_SET (function_obstack);
+ COPY_REG_SET (tmp, bb->global_live_at_end);
+ propagate_block (bb, tmp, NULL, NULL, prop_flags);
- /* ??? This info is likely going to be out of date very soon. */
- CLEAR_REG_SET (bb->local_set);
- if (old_succ->global_live_at_start)
- {
- COPY_REG_SET (bb->global_live_at_start, old_succ->global_live_at_start);
- COPY_REG_SET (bb->global_live_at_end, old_succ->global_live_at_start);
+ if (extent == UPDATE_LIFE_LOCAL)
+ verify_local_live_at_start (tmp, bb);
+ });
}
else
{
- CLEAR_REG_SET (bb->global_live_at_start);
- CLEAR_REG_SET (bb->global_live_at_end);
- }
-
- /* Wire them up. */
- bb->pred = edge_in;
- bb->succ = edge_out;
-
- edge_in->dest = bb;
- edge_in->flags &= ~EDGE_CRITICAL;
-
- edge_out->pred_next = old_succ->pred;
- edge_out->succ_next = NULL;
- edge_out->src = bb;
- edge_out->dest = old_succ;
- edge_out->flags = EDGE_FALLTHRU;
- edge_out->probability = REG_BR_PROB_BASE;
-
- old_succ->pred = edge_out;
-
- /* Tricky case -- if there existed a fallthru into the successor
- (and we're not it) we must add a new unconditional jump around
- the new block we're actually interested in.
-
- Further, if that edge is critical, this means a second new basic
- block must be created to hold it. In order to simplify correct
- insn placement, do this before we touch the existing basic block
- ordering for the block we were really wanting. */
- if ((edge_in->flags & EDGE_FALLTHRU) == 0)
- {
- edge e;
- for (e = edge_out->pred_next; e ; e = e->pred_next)
- if (e->flags & EDGE_FALLTHRU)
- break;
-
- if (e)
+ for (i = n_basic_blocks - 1; i >= 0; --i)
{
- basic_block jump_block;
- rtx pos;
-
- if ((e->flags & EDGE_CRITICAL) == 0)
- {
- /* Non critical -- we can simply add a jump to the end
- of the existing predecessor. */
- jump_block = e->src;
- }
- else
- {
- /* We need a new block to hold the jump. The simplest
- way to do the bulk of the work here is to recursively
- call ourselves. */
- jump_block = split_edge (e);
- e = jump_block->succ;
- }
-
- /* Now add the jump insn ... */
- pos = emit_jump_insn_after (gen_jump (old_succ->head),
- jump_block->end);
- jump_block->end = pos;
- emit_barrier_after (pos);
+ basic_block bb = BASIC_BLOCK (i);
- /* ... let jump know that label is in use, ... */
- ++LABEL_NUSES (old_succ->head);
-
- /* ... and clear fallthru on the outgoing edge. */
- e->flags &= ~EDGE_FALLTHRU;
+ COPY_REG_SET (tmp, bb->global_live_at_end);
+ propagate_block (bb, tmp, NULL, NULL, prop_flags);
- /* Continue splitting the interesting edge. */
+ if (extent == UPDATE_LIFE_LOCAL)
+ verify_local_live_at_start (tmp, bb);
}
}
- /* Place the new block just in front of the successor. */
- VARRAY_GROW (basic_block_info, ++n_basic_blocks);
- for (i = n_basic_blocks - 1; i > old_succ->index; --i)
+ FREE_REG_SET (tmp);
+
+ if (prop_flags & PROP_REG_INFO)
{
- basic_block tmp = BASIC_BLOCK (i - 1);
- BASIC_BLOCK (i) = tmp;
- tmp->index = i;
+ /* The only pseudos that are live at the beginning of the function
+ are those that were not set anywhere in the function. local-alloc
+ doesn't know how to handle these correctly, so mark them as not
+ local to any one basic block. */
+ EXECUTE_IF_SET_IN_REG_SET (ENTRY_BLOCK_PTR->global_live_at_end,
+ FIRST_PSEUDO_REGISTER, i,
+ { REG_BASIC_BLOCK (i) = REG_BLOCK_GLOBAL; });
+
+ /* We have a problem with any pseudoreg that lives across the setjmp.
+ ANSI says that if a user variable does not change in value between
+ the setjmp and the longjmp, then the longjmp preserves it. This
+ includes longjmp from a place where the pseudo appears dead.
+ (In principle, the value still exists if it is in scope.)
+ If the pseudo goes in a hard reg, some other value may occupy
+ that hard reg where this pseudo is dead, thus clobbering the pseudo.
+ Conclusion: such a pseudo must not go in a hard reg. */
+ EXECUTE_IF_SET_IN_REG_SET (regs_live_at_setjmp,
+ FIRST_PSEUDO_REGISTER, i,
+ {
+ if (regno_reg_rtx[i] != 0)
+ {
+ REG_LIVE_LENGTH (i) = -1;
+ REG_BASIC_BLOCK (i) = REG_BLOCK_UNKNOWN;
+ }
+ });
}
- BASIC_BLOCK (i) = bb;
- bb->index = i;
-
- /* Create the basic block note. */
- bb_note = emit_note_before (NOTE_INSN_BASIC_BLOCK, old_succ->head);
- NOTE_BASIC_BLOCK (bb_note) = bb;
- bb->head = bb->end = bb_note;
+ timevar_pop ((extent == UPDATE_LIFE_LOCAL || blocks)
+ ? TV_LIFE_UPDATE : TV_LIFE);
+}
- /* Not quite simple -- for non-fallthru edges, we must adjust the
- predecessor's jump instruction to target our new block. */
- if ((edge_in->flags & EDGE_FALLTHRU) == 0)
- {
- rtx tmp, insn = old_pred->end;
- rtx old_label = old_succ->head;
- rtx new_label = gen_label_rtx ();
+/* Free the variables allocated by find_basic_blocks.
- if (GET_CODE (insn) != JUMP_INSN)
- abort ();
+ KEEP_HEAD_END_P is non-zero if basic_block_info is not to be freed. */
- /* ??? Recognize a tablejump and adjust all matching cases. */
- if ((tmp = JUMP_LABEL (insn)) != NULL_RTX
- && (tmp = NEXT_INSN (tmp)) != NULL_RTX
- && GET_CODE (tmp) == JUMP_INSN
- && (GET_CODE (PATTERN (tmp)) == ADDR_VEC
- || GET_CODE (PATTERN (tmp)) == ADDR_DIFF_VEC))
+void
+free_basic_block_vars (keep_head_end_p)
+ int keep_head_end_p;
+{
+ if (! keep_head_end_p)
+ {
+ if (basic_block_info)
{
- rtvec vec;
- int j;
-
- if (GET_CODE (PATTERN (tmp)) == ADDR_VEC)
- vec = XVEC (PATTERN (tmp), 0);
- else
- vec = XVEC (PATTERN (tmp), 1);
-
- for (j = GET_NUM_ELEM (vec) - 1; j >= 0; --j)
- if (XEXP (RTVEC_ELT (vec, j), 0) == old_label)
- {
- RTVEC_ELT (vec, j) = gen_rtx_LABEL_REF (VOIDmode, new_label);
- --LABEL_NUSES (old_label);
- ++LABEL_NUSES (new_label);
- }
- }
- else
- {
- /* This would have indicated an abnormal edge. */
- if (computed_jump_p (insn))
- abort ();
-
- /* A return instruction can't be redirected. */
- if (returnjump_p (insn))
- abort ();
-
- /* If the insn doesn't go where we think, we're confused. */
- if (JUMP_LABEL (insn) != old_label)
- abort ();
-
- redirect_jump (insn, new_label);
+ clear_edges ();
+ VARRAY_FREE (basic_block_info);
}
+ n_basic_blocks = 0;
- emit_label_before (new_label, bb_note);
- bb->head = new_label;
+ ENTRY_BLOCK_PTR->aux = NULL;
+ ENTRY_BLOCK_PTR->global_live_at_end = NULL;
+ EXIT_BLOCK_PTR->aux = NULL;
+ EXIT_BLOCK_PTR->global_live_at_start = NULL;
}
-
- return bb;
}
-/* Queue instructions for insertion on an edge between two basic blocks.
- The new instructions and basic blocks (if any) will not appear in the
- CFG until commit_edge_insertions is called. */
+/* Delete any insns that copy a register to itself. */
void
-insert_insn_on_edge (pattern, e)
- rtx pattern;
- edge e;
+delete_noop_moves (f)
+ rtx f ATTRIBUTE_UNUSED;
{
- /* We cannot insert instructions on an abnormal critical edge.
- It will be easier to find the culprit if we die now. */
- if ((e->flags & (EDGE_ABNORMAL|EDGE_CRITICAL))
- == (EDGE_ABNORMAL|EDGE_CRITICAL))
- abort ();
+ int i;
+ rtx insn, next;
+ basic_block bb;
- if (e->insns == NULL_RTX)
- start_sequence ();
- else
- push_to_sequence (e->insns);
+ for (i = 0; i < n_basic_blocks; i++)
+ {
+ bb = BASIC_BLOCK (i);
+ for (insn = bb->head; insn != NEXT_INSN (bb->end); insn = next)
+ {
+ next = NEXT_INSN (insn);
+ if (INSN_P (insn) && noop_move_p (insn))
+ {
+ rtx note;
- emit_insn (pattern);
+ /* If we're about to remove the first insn of a libcall
+ then move the libcall note to the next real insn and
+ update the retval note. */
+ if ((note = find_reg_note (insn, REG_LIBCALL, NULL_RTX))
+ && XEXP (note, 0) != insn)
+ {
+ rtx new_libcall_insn = next_real_insn (insn);
+ rtx retval_note = find_reg_note (XEXP (note, 0),
+ REG_RETVAL, NULL_RTX);
+ REG_NOTES (new_libcall_insn)
+ = gen_rtx_INSN_LIST (REG_LIBCALL, XEXP (note, 0),
+ REG_NOTES (new_libcall_insn));
+ XEXP (retval_note, 0) = new_libcall_insn;
+ }
- e->insns = get_insns ();
- end_sequence();
+ /* Do not call delete_insn here since that may change
+ the basic block boundaries which upsets some callers. */
+ PUT_CODE (insn, NOTE);
+ NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
+ NOTE_SOURCE_FILE (insn) = 0;
+ }
+ }
+ }
}
-/* Update the CFG for the instructions queued on edge E. */
-
+/* Delete any jump tables never referenced. We can't delete them at the
+ time of removing tablejump insn as they are referenced by the preceding
+ insns computing the destination, so we delay deleting and garbagecollect
+ them once life information is computed. */
static void
-commit_one_edge_insertion (e)
- edge e;
+delete_dead_jumptables ()
{
- rtx before = NULL_RTX, after = NULL_RTX, tmp;
- basic_block bb;
-
- /* Figure out where to put these things. If the destination has
- one predecessor, insert there. Except for the exit block. */
- if (e->dest->pred->pred_next == NULL
- && e->dest != EXIT_BLOCK_PTR)
- {
- bb = e->dest;
-
- /* Get the location correct wrt a code label, and "nice" wrt
- a basic block note, and before everything else. */
- tmp = bb->head;
- if (GET_CODE (tmp) == CODE_LABEL)
- tmp = NEXT_INSN (tmp);
- if (GET_CODE (tmp) == NOTE
- && NOTE_LINE_NUMBER (tmp) == NOTE_INSN_BASIC_BLOCK)
- tmp = NEXT_INSN (tmp);
- if (tmp == bb->head)
- before = tmp;
- else
- after = PREV_INSN (tmp);
- }
-
- /* If the source has one successor and the edge is not abnormal,
- insert there. Except for the entry block. */
- else if ((e->flags & EDGE_ABNORMAL) == 0
- && e->src->succ->succ_next == NULL
- && e->src != ENTRY_BLOCK_PTR)
+ rtx insn, next;
+ for (insn = get_insns (); insn; insn = next)
{
- bb = e->src;
- if (GET_CODE (bb->end) == JUMP_INSN)
- {
- /* ??? Is it possible to wind up with non-simple jumps? Perhaps
- a jump with delay slots already filled? */
- if (! simplejump_p (bb->end))
- abort ();
-
- before = bb->end;
- }
- else
+ next = NEXT_INSN (insn);
+ if (GET_CODE (insn) == CODE_LABEL
+ && LABEL_NUSES (insn) == LABEL_PRESERVE_P (insn)
+ && GET_CODE (next) == JUMP_INSN
+ && (GET_CODE (PATTERN (next)) == ADDR_VEC
+ || GET_CODE (PATTERN (next)) == ADDR_DIFF_VEC))
{
- /* We'd better be fallthru, or we've lost track of what's what. */
- if ((e->flags & EDGE_FALLTHRU) == 0)
- abort ();
-
- after = bb->end;
+ if (rtl_dump_file)
+ fprintf (rtl_dump_file, "Dead jumptable %i removed\n", INSN_UID (insn));
+ delete_insn (NEXT_INSN (insn));
+ delete_insn (insn);
+ next = NEXT_INSN (next);
}
}
+}
- /* Otherwise we must split the edge. */
- else
- {
- bb = split_edge (e);
- after = bb->end;
- }
+/* Determine if the stack pointer is constant over the life of the function.
+ Only useful before prologues have been emitted. */
- /* Now that we've found the spot, do the insertion. */
- tmp = e->insns;
- e->insns = NULL_RTX;
- if (before)
- {
- emit_insns_before (tmp, before);
- if (before == bb->head)
- bb->head = before;
- }
- else
- {
- tmp = emit_insns_after (tmp, after);
- if (after == bb->end)
- bb->end = tmp;
- }
+static void
+notice_stack_pointer_modification_1 (x, pat, data)
+ rtx x;
+ rtx pat ATTRIBUTE_UNUSED;
+ void *data ATTRIBUTE_UNUSED;
+{
+ if (x == stack_pointer_rtx
+ /* The stack pointer is only modified indirectly as the result
+ of a push until later in flow. See the comments in rtl.texi
+ regarding Embedded Side-Effects on Addresses. */
+ || (GET_CODE (x) == MEM
+ && GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) == 'a'
+ && XEXP (XEXP (x, 0), 0) == stack_pointer_rtx))
+ current_function_sp_is_unchanging = 0;
}
-/* Update the CFG for all queued instructions. */
-
-void
-commit_edge_insertions ()
+static void
+notice_stack_pointer_modification (f)
+ rtx f;
{
- int i;
- basic_block bb;
+ rtx insn;
- i = -1;
- bb = ENTRY_BLOCK_PTR;
- while (1)
- {
- edge e, next;
+ /* Assume that the stack pointer is unchanging if alloca hasn't
+ been used. */
+ current_function_sp_is_unchanging = !current_function_calls_alloca;
+ if (! current_function_sp_is_unchanging)
+ return;
- for (e = bb->succ; e ; e = next)
+ for (insn = f; insn; insn = NEXT_INSN (insn))
+ {
+ if (INSN_P (insn))
{
- next = e->succ_next;
- if (e->insns)
- commit_one_edge_insertion (e);
+ /* Check if insn modifies the stack pointer. */
+ note_stores (PATTERN (insn), notice_stack_pointer_modification_1,
+ NULL);
+ if (! current_function_sp_is_unchanging)
+ return;
}
-
- if (++i >= n_basic_blocks)
- break;
- bb = BASIC_BLOCK (i);
}
}
-
-/* Delete all unreachable basic blocks. */
+
+/* Mark a register in SET. Hard registers in large modes get all
+ of their component registers set as well. */
static void
-delete_unreachable_blocks ()
+mark_reg (reg, xset)
+ rtx reg;
+ void *xset;
{
- basic_block *worklist, *tos;
- int deleted_handler;
- edge e;
- int i, n;
+ regset set = (regset) xset;
+ int regno = REGNO (reg);
- n = n_basic_blocks;
- tos = worklist = (basic_block *) alloca (sizeof (basic_block) * n);
+ if (GET_MODE (reg) == BLKmode)
+ abort ();
- /* Use basic_block->aux as a marker. Clear them all. */
+ SET_REGNO_REG_SET (set, regno);
+ if (regno < FIRST_PSEUDO_REGISTER)
+ {
+ int n = HARD_REGNO_NREGS (regno, GET_MODE (reg));
+ while (--n > 0)
+ SET_REGNO_REG_SET (set, regno + n);
+ }
+}
- for (i = 0; i < n; ++i)
- BASIC_BLOCK (i)->aux = NULL;
+/* Mark those regs which are needed at the end of the function as live
+ at the end of the last basic block. */
- /* Add our starting points to the worklist. Almost always there will
- be only one. It isn't inconcievable that we might one day directly
- support Fortran alternate entry points. */
+static void
+mark_regs_live_at_end (set)
+ regset set;
+{
+ unsigned int i;
- for (e = ENTRY_BLOCK_PTR->succ; e ; e = e->succ_next)
+ /* If exiting needs the right stack value, consider the stack pointer
+ live at the end of the function. */
+ if ((HAVE_epilogue && reload_completed)
+ || ! EXIT_IGNORE_STACK
+ || (! FRAME_POINTER_REQUIRED
+ && ! current_function_calls_alloca
+ && flag_omit_frame_pointer)
+ || current_function_sp_is_unchanging)
{
- *tos++ = e->dest;
-
- /* Mark the block with a handy non-null value. */
- e->dest->aux = e;
+ SET_REGNO_REG_SET (set, STACK_POINTER_REGNUM);
}
-
- /* Iterate: find everything reachable from what we've already seen. */
- while (tos != worklist)
- {
- basic_block b = *--tos;
+ /* Mark the frame pointer if needed at the end of the function. If
+ we end up eliminating it, it will be removed from the live list
+ of each basic block by reload. */
- for (e = b->succ; e ; e = e->succ_next)
- if (!e->dest->aux)
- {
- *tos++ = e->dest;
- e->dest->aux = e;
- }
+ if (! reload_completed || frame_pointer_needed)
+ {
+ SET_REGNO_REG_SET (set, FRAME_POINTER_REGNUM);
+#if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
+ /* If they are different, also mark the hard frame pointer as live. */
+ if (! LOCAL_REGNO (HARD_FRAME_POINTER_REGNUM))
+ SET_REGNO_REG_SET (set, HARD_FRAME_POINTER_REGNUM);
+#endif
}
- /* Delete all unreachable basic blocks. Count down so that we don't
- interfere with the block renumbering that happens in delete_block. */
+#ifndef PIC_OFFSET_TABLE_REG_CALL_CLOBBERED
+ /* Many architectures have a GP register even without flag_pic.
+ Assume the pic register is not in use, or will be handled by
+ other means, if it is not fixed. */
+ if (PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
+ && fixed_regs[PIC_OFFSET_TABLE_REGNUM])
+ SET_REGNO_REG_SET (set, PIC_OFFSET_TABLE_REGNUM);
+#endif
- deleted_handler = 0;
+ /* Mark all global registers, and all registers used by the epilogue
+ as being live at the end of the function since they may be
+ referenced by our caller. */
+ for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
+ if (global_regs[i] || EPILOGUE_USES (i))
+ SET_REGNO_REG_SET (set, i);
- for (i = n - 1; i >= 0; --i)
+ if (HAVE_epilogue && reload_completed)
{
- basic_block b = BASIC_BLOCK (i);
-
- if (b->aux != NULL)
- /* This block was found. Tidy up the mark. */
- b->aux = NULL;
- else
- deleted_handler |= delete_block (b);
+ /* Mark all call-saved registers that we actually used. */
+ for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
+ if (regs_ever_live[i] && ! LOCAL_REGNO (i)
+ && ! TEST_HARD_REG_BIT (regs_invalidated_by_call, i))
+ SET_REGNO_REG_SET (set, i);
}
- /* Fix up edges that now fall through, or rather should now fall through
- but previously required a jump around now deleted blocks. Simplify
- the search by only examining blocks numerically adjacent, since this
- is how find_basic_blocks created them. */
-
- for (i = 1; i < n_basic_blocks; ++i)
+#ifdef EH_RETURN_DATA_REGNO
+ /* Mark the registers that will contain data for the handler. */
+ if (reload_completed && current_function_calls_eh_return)
+ for (i = 0; ; ++i)
+ {
+ unsigned regno = EH_RETURN_DATA_REGNO(i);
+ if (regno == INVALID_REGNUM)
+ break;
+ SET_REGNO_REG_SET (set, regno);
+ }
+#endif
+#ifdef EH_RETURN_STACKADJ_RTX
+ if ((! HAVE_epilogue || ! reload_completed)
+ && current_function_calls_eh_return)
{
- basic_block b = BASIC_BLOCK (i - 1);
- basic_block c = BASIC_BLOCK (i);
- edge s;
-
- /* We care about simple conditional or unconditional jumps with
- a single successor.
-
- If we had a conditional branch to the next instruction when
- find_basic_blocks was called, then there will only be one
- out edge for the block which ended with the conditional
- branch (since we do not create duplicate edges).
-
- Furthermore, the edge will be marked as a fallthru because we
- merge the flags for the duplicate edges. So we do not want to
- check that the edge is not a FALLTHRU edge. */
- if ((s = b->succ) != NULL
- && s->succ_next == NULL
- && s->dest == c
- /* If the last insn is not a normal conditional jump
- (or an unconditional jump), then we can not tidy the
- fallthru edge because we can not delete the jump. */
- && GET_CODE (b->end) == JUMP_INSN
- && condjump_p (b->end))
- tidy_fallthru_edge (s, b, c);
+ rtx tmp = EH_RETURN_STACKADJ_RTX;
+ if (tmp && REG_P (tmp))
+ mark_reg (tmp, set);
}
-
- /* Attempt to merge blocks as made possible by edge removal. If a block
- has only one successor, and the successor has only one predecessor,
- they may be combined. */
-
- for (i = 0; i < n_basic_blocks; )
+#endif
+#ifdef EH_RETURN_HANDLER_RTX
+ if ((! HAVE_epilogue || ! reload_completed)
+ && current_function_calls_eh_return)
{
- basic_block c, b = BASIC_BLOCK (i);
- edge s;
-
- /* A loop because chains of blocks might be combineable. */
- while ((s = b->succ) != NULL
- && s->succ_next == NULL
- && (s->flags & EDGE_EH) == 0
- && (c = s->dest) != EXIT_BLOCK_PTR
- && c->pred->pred_next == NULL
- /* If the last insn is not a normal conditional jump
- (or an unconditional jump), then we can not merge
- the blocks because we can not delete the jump. */
- && GET_CODE (b->end) == JUMP_INSN
- && condjump_p (b->end)
- && merge_blocks (s, b, c))
- continue;
-
- /* Don't get confused by the index shift caused by deleting blocks. */
- i = b->index + 1;
+ rtx tmp = EH_RETURN_HANDLER_RTX;
+ if (tmp && REG_P (tmp))
+ mark_reg (tmp, set);
}
+#endif
- /* If we deleted an exception handler, we may have EH region begin/end
- blocks to remove as well. */
- if (deleted_handler)
- delete_eh_regions ();
-}
-
-/* Find EH regions for which there is no longer a handler, and delete them. */
-
-static void
-delete_eh_regions ()
-{
- rtx insn;
-
- for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
- if (GET_CODE (insn) == NOTE)
- {
- if ((NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_BEG) ||
- (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_END))
- {
- int num = CODE_LABEL_NUMBER (insn);
- /* A NULL handler indicates a region is no longer needed */
- if (get_first_handler (num) == NULL)
- {
- NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
- NOTE_SOURCE_FILE (insn) = 0;
- }
- }
- }
+ /* Mark function return value. */
+ diddle_return_value (mark_reg, set);
}
-/* Return true if NOTE is not one of the ones that must be kept paired,
- so that we may simply delete them. */
+/* Callback function for for_each_successor_phi. DATA is a regset.
+ Sets the SRC_REGNO, the regno of the phi alternative for phi node
+ INSN, in the regset. */
static int
-can_delete_note_p (note)
- rtx note;
+set_phi_alternative_reg (insn, dest_regno, src_regno, data)
+ rtx insn ATTRIBUTE_UNUSED;
+ int dest_regno ATTRIBUTE_UNUSED;
+ int src_regno;
+ void *data;
{
- return (NOTE_LINE_NUMBER (note) == NOTE_INSN_DELETED
- || NOTE_LINE_NUMBER (note) == NOTE_INSN_BASIC_BLOCK);
+ regset live = (regset) data;
+ SET_REGNO_REG_SET (live, src_regno);
+ return 0;
}
-/* Unlink a chain of insns between START and FINISH, leaving notes
- that must be paired. */
+/* Propagate global life info around the graph of basic blocks. Begin
+ considering blocks with their corresponding bit set in BLOCKS_IN.
+ If BLOCKS_IN is null, consider it the universal set.
+
+ BLOCKS_OUT is set for every block that was changed. */
static void
-delete_insn_chain (start, finish)
- rtx start, finish;
+calculate_global_regs_live (blocks_in, blocks_out, flags)
+ sbitmap blocks_in, blocks_out;
+ int flags;
{
- /* Unchain the insns one by one. It would be quicker to delete all
- of these with a single unchaining, rather than one at a time, but
- we need to keep the NOTE's. */
-
- rtx next;
+ basic_block *queue, *qhead, *qtail, *qend;
+ regset tmp, new_live_at_end, call_used;
+ regset_head tmp_head, call_used_head;
+ regset_head new_live_at_end_head;
+ int i;
- while (1)
+ tmp = INITIALIZE_REG_SET (tmp_head);
+ new_live_at_end = INITIALIZE_REG_SET (new_live_at_end_head);
+ call_used = INITIALIZE_REG_SET (call_used_head);
+
+ /* Inconveniently, this is only readily available in hard reg set form. */
+ for (i = 0; i < FIRST_PSEUDO_REGISTER; ++i)
+ if (call_used_regs[i])
+ SET_REGNO_REG_SET (call_used, i);
+
+ /* Create a worklist. Allocate an extra slot for ENTRY_BLOCK, and one
+ because the `head == tail' style test for an empty queue doesn't
+ work with a full queue. */
+ queue = (basic_block *) xmalloc ((n_basic_blocks + 2) * sizeof (*queue));
+ qtail = queue;
+ qhead = qend = queue + n_basic_blocks + 2;
+
+ /* Queue the blocks set in the initial mask. Do this in reverse block
+ number order so that we are more likely for the first round to do
+ useful work. We use AUX non-null to flag that the block is queued. */
+ if (blocks_in)
{
- next = NEXT_INSN (start);
- if (GET_CODE (start) == NOTE && !can_delete_note_p (start))
- ;
- else if (GET_CODE (start) == CODE_LABEL && !can_delete_label_p (start))
- ;
- else
- next = flow_delete_insn (start);
+ /* Clear out the garbage that might be hanging out in bb->aux. */
+ for (i = n_basic_blocks - 1; i >= 0; --i)
+ BASIC_BLOCK (i)->aux = NULL;
- if (start == finish)
- break;
- start = next;
+ EXECUTE_IF_SET_IN_SBITMAP (blocks_in, 0, i,
+ {
+ basic_block bb = BASIC_BLOCK (i);
+ *--qhead = bb;
+ bb->aux = bb;
+ });
}
-}
-
-/* Delete the insns in a (non-live) block. We physically delete every
- non-deleted-note insn, and update the flow graph appropriately.
-
- Return nonzero if we deleted an exception handler. */
-
-/* ??? Preserving all such notes strikes me as wrong. It would be nice
- to post-process the stream to remove empty blocks, loops, ranges, etc. */
-
-static int
-delete_block (b)
- basic_block b;
-{
- int deleted_handler = 0;
- rtx insn, end, tmp;
-
- /* If the head of this block is a CODE_LABEL, then it might be the
- label for an exception handler which can't be reached.
-
- We need to remove the label from the exception_handler_label list
- and remove the associated NOTE_EH_REGION_BEG and NOTE_EH_REGION_END
- notes. */
-
- insn = b->head;
-
- if (GET_CODE (insn) == CODE_LABEL)
+ else
{
- rtx x, *prev = &exception_handler_labels;
-
- for (x = exception_handler_labels; x; x = XEXP (x, 1))
- {
- if (XEXP (x, 0) == insn)
- {
- /* Found a match, splice this label out of the EH label list. */
- *prev = XEXP (x, 1);
- XEXP (x, 1) = NULL_RTX;
- XEXP (x, 0) = NULL_RTX;
-
- /* Remove the handler from all regions */
- remove_handler (insn);
- deleted_handler = 1;
- break;
- }
- prev = &XEXP (x, 1);
- }
-
- /* This label may be referenced by code solely for its value, or
- referenced by static data, or something. We have determined
- that it is not reachable, but cannot delete the label itself.
- Save code space and continue to delete the balance of the block,
- along with properly updating the cfg. */
- if (!can_delete_label_p (insn))
+ for (i = 0; i < n_basic_blocks; ++i)
{
- /* If we've only got one of these, skip the whole deleting
- insns thing. */
- if (insn == b->end)
- goto no_delete_insns;
- insn = NEXT_INSN (insn);
+ basic_block bb = BASIC_BLOCK (i);
+ *--qhead = bb;
+ bb->aux = bb;
}
}
- /* Include any jump table following the basic block. */
- end = b->end;
- if (GET_CODE (end) == JUMP_INSN
- && (tmp = JUMP_LABEL (end)) != NULL_RTX
- && (tmp = NEXT_INSN (tmp)) != NULL_RTX
- && GET_CODE (tmp) == JUMP_INSN
- && (GET_CODE (PATTERN (tmp)) == ADDR_VEC
- || GET_CODE (PATTERN (tmp)) == ADDR_DIFF_VEC))
- end = tmp;
-
- /* Include any barrier that may follow the basic block. */
- tmp = next_nonnote_insn (b->end);
- if (tmp && GET_CODE (tmp) == BARRIER)
- end = tmp;
-
- delete_insn_chain (insn, end);
-
-no_delete_insns:
-
- /* Remove the edges into and out of this block. Note that there may
- indeed be edges in, if we are removing an unreachable loop. */
- {
- edge e, next, *q;
-
- for (e = b->pred; e ; e = next)
- {
- for (q = &e->src->succ; *q != e; q = &(*q)->succ_next)
- continue;
- *q = e->succ_next;
- next = e->pred_next;
- free (e);
- }
- for (e = b->succ; e ; e = next)
- {
- for (q = &e->dest->pred; *q != e; q = &(*q)->pred_next)
- continue;
- *q = e->pred_next;
- next = e->succ_next;
- free (e);
- }
-
- b->pred = NULL;
- b->succ = NULL;
- }
-
- /* Remove the basic block from the array, and compact behind it. */
- expunge_block (b);
-
- return deleted_handler;
-}
-
-/* Remove block B from the basic block array and compact behind it. */
-
-static void
-expunge_block (b)
- basic_block b;
-{
- int i, n = n_basic_blocks;
-
- for (i = b->index; i + 1 < n; ++i)
+ if (blocks_out)
+ sbitmap_zero (blocks_out);
+
+ /* We work through the queue until there are no more blocks. What
+ is live at the end of this block is precisely the union of what
+ is live at the beginning of all its successors. So, we set its
+ GLOBAL_LIVE_AT_END field based on the GLOBAL_LIVE_AT_START field
+ for its successors. Then, we compute GLOBAL_LIVE_AT_START for
+ this block by walking through the instructions in this block in
+ reverse order and updating as we go. If that changed
+ GLOBAL_LIVE_AT_START, we add the predecessors of the block to the
+ queue; they will now need to recalculate GLOBAL_LIVE_AT_END.
+
+ We are guaranteed to terminate, because GLOBAL_LIVE_AT_START
+ never shrinks. If a register appears in GLOBAL_LIVE_AT_START, it
+ must either be live at the end of the block, or used within the
+ block. In the latter case, it will certainly never disappear
+ from GLOBAL_LIVE_AT_START. In the former case, the register
+ could go away only if it disappeared from GLOBAL_LIVE_AT_START
+ for one of the successor blocks. By induction, that cannot
+ occur. */
+ while (qhead != qtail)
{
- basic_block x = BASIC_BLOCK (i + 1);
- BASIC_BLOCK (i) = x;
- x->index = i;
- }
+ int rescan, changed;
+ basic_block bb;
+ edge e;
- basic_block_info->num_elements--;
- n_basic_blocks--;
-}
+ bb = *qhead++;
+ if (qhead == qend)
+ qhead = queue;
+ bb->aux = NULL;
-/* Delete INSN by patching it out. Return the next insn. */
+ /* Begin by propagating live_at_start from the successor blocks. */
+ CLEAR_REG_SET (new_live_at_end);
+ for (e = bb->succ; e; e = e->succ_next)
+ {
+ basic_block sb = e->dest;
-static rtx
-flow_delete_insn (insn)
- rtx insn;
-{
- rtx prev = PREV_INSN (insn);
- rtx next = NEXT_INSN (insn);
- rtx note;
+ /* Call-clobbered registers die across exception and call edges. */
+ /* ??? Abnormal call edges ignored for the moment, as this gets
+ confused by sibling call edges, which crashes reg-stack. */
+ if (e->flags & EDGE_EH)
+ {
+ bitmap_operation (tmp, sb->global_live_at_start,
+ call_used, BITMAP_AND_COMPL);
+ IOR_REG_SET (new_live_at_end, tmp);
+ }
+ else
+ IOR_REG_SET (new_live_at_end, sb->global_live_at_start);
+ }
- PREV_INSN (insn) = NULL_RTX;
- NEXT_INSN (insn) = NULL_RTX;
+ /* The all-important stack pointer must always be live. */
+ SET_REGNO_REG_SET (new_live_at_end, STACK_POINTER_REGNUM);
- if (prev)
- NEXT_INSN (prev) = next;
- if (next)
- PREV_INSN (next) = prev;
- else
- set_last_insn (prev);
+ /* Before reload, there are a few registers that must be forced
+ live everywhere -- which might not already be the case for
+ blocks within infinite loops. */
+ if (! reload_completed)
+ {
+ /* Any reference to any pseudo before reload is a potential
+ reference of the frame pointer. */
+ SET_REGNO_REG_SET (new_live_at_end, FRAME_POINTER_REGNUM);
- if (GET_CODE (insn) == CODE_LABEL)
- remove_node_from_expr_list (insn, &nonlocal_goto_handler_labels);
+#if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
+ /* Pseudos with argument area equivalences may require
+ reloading via the argument pointer. */
+ if (fixed_regs[ARG_POINTER_REGNUM])
+ SET_REGNO_REG_SET (new_live_at_end, ARG_POINTER_REGNUM);
+#endif
- /* If deleting a jump, decrement the use count of the label. Deleting
- the label itself should happen in the normal course of block merging. */
- if (GET_CODE (insn) == JUMP_INSN && JUMP_LABEL (insn))
- LABEL_NUSES (JUMP_LABEL (insn))--;
+ /* Any constant, or pseudo with constant equivalences, may
+ require reloading from memory using the pic register. */
+ if (PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
+ && fixed_regs[PIC_OFFSET_TABLE_REGNUM])
+ SET_REGNO_REG_SET (new_live_at_end, PIC_OFFSET_TABLE_REGNUM);
+ }
- /* Also if deleting an insn that references a label. */
- else if ((note = find_reg_note (insn, REG_LABEL, NULL_RTX)) != NULL_RTX)
- LABEL_NUSES (XEXP (note, 0))--;
+ /* Regs used in phi nodes are not included in
+ global_live_at_start, since they are live only along a
+ particular edge. Set those regs that are live because of a
+ phi node alternative corresponding to this particular block. */
+ if (in_ssa_form)
+ for_each_successor_phi (bb, &set_phi_alternative_reg,
+ new_live_at_end);
- return next;
-}
+ if (bb == ENTRY_BLOCK_PTR)
+ {
+ COPY_REG_SET (bb->global_live_at_end, new_live_at_end);
+ continue;
+ }
-/* True if a given label can be deleted. */
+ /* On our first pass through this block, we'll go ahead and continue.
+ Recognize first pass by local_set NULL. On subsequent passes, we
+ get to skip out early if live_at_end wouldn't have changed. */
-static int
-can_delete_label_p (label)
- rtx label;
-{
- rtx x;
+ if (bb->local_set == NULL)
+ {
+ bb->local_set = OBSTACK_ALLOC_REG_SET (&flow_obstack);
+ bb->cond_local_set = OBSTACK_ALLOC_REG_SET (&flow_obstack);
+ rescan = 1;
+ }
+ else
+ {
+ /* If any bits were removed from live_at_end, we'll have to
+ rescan the block. This wouldn't be necessary if we had
+ precalculated local_live, however with PROP_SCAN_DEAD_CODE
+ local_live is really dependent on live_at_end. */
+ CLEAR_REG_SET (tmp);
+ rescan = bitmap_operation (tmp, bb->global_live_at_end,
+ new_live_at_end, BITMAP_AND_COMPL);
+
+ if (! rescan)
+ {
+ /* If any of the registers in the new live_at_end set are
+ conditionally set in this basic block, we must rescan.
+ This is because conditional lifetimes at the end of the
+ block do not just take the live_at_end set into account,
+ but also the liveness at the start of each successor
+ block. We can miss changes in those sets if we only
+ compare the new live_at_end against the previous one. */
+ CLEAR_REG_SET (tmp);
+ rescan = bitmap_operation (tmp, new_live_at_end,
+ bb->cond_local_set, BITMAP_AND);
+ }
- if (LABEL_PRESERVE_P (label))
- return 0;
+ if (! rescan)
+ {
+ /* Find the set of changed bits. Take this opportunity
+ to notice that this set is empty and early out. */
+ CLEAR_REG_SET (tmp);
+ changed = bitmap_operation (tmp, bb->global_live_at_end,
+ new_live_at_end, BITMAP_XOR);
+ if (! changed)
+ continue;
- for (x = forced_labels; x ; x = XEXP (x, 1))
- if (label == XEXP (x, 0))
- return 0;
- for (x = label_value_list; x ; x = XEXP (x, 1))
- if (label == XEXP (x, 0))
- return 0;
- for (x = exception_handler_labels; x ; x = XEXP (x, 1))
- if (label == XEXP (x, 0))
- return 0;
-
- /* User declared labels must be preserved. */
- if (LABEL_NAME (label) != 0)
- return 0;
-
- return 1;
-}
+ /* If any of the changed bits overlap with local_set,
+ we'll have to rescan the block. Detect overlap by
+ the AND with ~local_set turning off bits. */
+ rescan = bitmap_operation (tmp, tmp, bb->local_set,
+ BITMAP_AND_COMPL);
+ }
+ }
-/* Blocks A and B are to be merged into a single block. The insns
- are already contiguous, hence `nomove'. */
+ /* Let our caller know that BB changed enough to require its
+ death notes updated. */
+ if (blocks_out)
+ SET_BIT (blocks_out, bb->index);
-static void
-merge_blocks_nomove (a, b)
- basic_block a, b;
-{
- edge e;
- rtx b_head, b_end, a_end;
- int b_empty = 0;
+ if (! rescan)
+ {
+ /* Add to live_at_start the set of all registers in
+ new_live_at_end that aren't in the old live_at_end. */
- /* If there was a CODE_LABEL beginning B, delete it. */
- b_head = b->head;
- b_end = b->end;
- if (GET_CODE (b_head) == CODE_LABEL)
- {
- /* Detect basic blocks with nothing but a label. This can happen
- in particular at the end of a function. */
- if (b_head == b_end)
- b_empty = 1;
- b_head = flow_delete_insn (b_head);
- }
+ bitmap_operation (tmp, new_live_at_end, bb->global_live_at_end,
+ BITMAP_AND_COMPL);
+ COPY_REG_SET (bb->global_live_at_end, new_live_at_end);
- /* Delete the basic block note. */
- if (GET_CODE (b_head) == NOTE
- && NOTE_LINE_NUMBER (b_head) == NOTE_INSN_BASIC_BLOCK)
- {
- if (b_head == b_end)
- b_empty = 1;
- b_head = flow_delete_insn (b_head);
- }
+ changed = bitmap_operation (bb->global_live_at_start,
+ bb->global_live_at_start,
+ tmp, BITMAP_IOR);
+ if (! changed)
+ continue;
+ }
+ else
+ {
+ COPY_REG_SET (bb->global_live_at_end, new_live_at_end);
- /* If there was a jump out of A, delete it. */
- a_end = a->end;
- if (GET_CODE (a_end) == JUMP_INSN)
- {
- rtx prev;
+ /* Rescan the block insn by insn to turn (a copy of) live_at_end
+ into live_at_start. */
+ propagate_block (bb, new_live_at_end, bb->local_set,
+ bb->cond_local_set, flags);
- prev = prev_nonnote_insn (a_end);
- if (!prev)
- prev = a->head;
+ /* If live_at start didn't change, no need to go farther. */
+ if (REG_SET_EQUAL_P (bb->global_live_at_start, new_live_at_end))
+ continue;
-#ifdef HAVE_cc0
- /* If this was a conditional jump, we need to also delete
- the insn that set cc0. */
+ COPY_REG_SET (bb->global_live_at_start, new_live_at_end);
+ }
- if (prev && sets_cc0_p (prev))
+ /* Queue all predecessors of BB so that we may re-examine
+ their live_at_end. */
+ for (e = bb->pred; e; e = e->pred_next)
{
- rtx tmp = prev;
- prev = prev_nonnote_insn (prev);
- if (!prev)
- prev = a->head;
- flow_delete_insn (tmp);
+ basic_block pb = e->src;
+ if (pb->aux == NULL)
+ {
+ *qtail++ = pb;
+ if (qtail == qend)
+ qtail = queue;
+ pb->aux = pb;
+ }
}
-#endif
-
- /* Note that a->head != a->end, since we should have at least a
- bb note plus the jump, so prev != insn. */
- flow_delete_insn (a_end);
- a_end = prev;
}
- /* By definition, there should only be one successor of A, and that is
- B. Free that edge struct. */
- free (a->succ);
-
- /* Adjust the edges out of B for the new owner. */
- for (e = b->succ; e ; e = e->succ_next)
- e->src = a;
- a->succ = b->succ;
+ FREE_REG_SET (tmp);
+ FREE_REG_SET (new_live_at_end);
+ FREE_REG_SET (call_used);
- /* Reassociate the insns of B with A. */
- if (!b_empty)
+ if (blocks_out)
{
- BLOCK_FOR_INSN (b_head) = a;
- while (b_head != b_end)
+ EXECUTE_IF_SET_IN_SBITMAP (blocks_out, 0, i,
{
- b_head = NEXT_INSN (b_head);
- BLOCK_FOR_INSN (b_head) = a;
- }
- a_end = b_head;
+ basic_block bb = BASIC_BLOCK (i);
+ FREE_REG_SET (bb->local_set);
+ FREE_REG_SET (bb->cond_local_set);
+ });
}
- a->end = a_end;
-
- /* Compact the basic block array. */
- expunge_block (b);
-}
-
-/* Attempt to merge basic blocks that are potentially non-adjacent.
- Return true iff the attempt succeeded. */
-
-static int
-merge_blocks (e, b, c)
- edge e;
- basic_block b, c;
-{
- /* If B has a fallthru edge to C, no need to move anything. */
- if (!(e->flags & EDGE_FALLTHRU))
+ else
{
- /* ??? From here on out we must make sure to not munge nesting
- of exception regions and lexical blocks. Need to think about
- these cases before this gets implemented. */
- return 0;
-
- /* If C has an outgoing fallthru, and B does not have an incoming
- fallthru, move B before C. The later clause is somewhat arbitrary,
- but avoids modifying blocks other than the two we've been given. */
-
- /* Otherwise, move C after B. If C had a fallthru, which doesn't
- happen to be the physical successor to B, insert an unconditional
- branch. If C already ended with a conditional branch, the new
- jump must go in a new basic block D. */
+ for (i = n_basic_blocks - 1; i >= 0; --i)
+ {
+ basic_block bb = BASIC_BLOCK (i);
+ FREE_REG_SET (bb->local_set);
+ FREE_REG_SET (bb->cond_local_set);
+ }
}
- /* If a label still appears somewhere and we cannot delete the label,
- then we cannot merge the blocks. The edge was tidied already. */
- {
- rtx insn, stop = NEXT_INSN (c->head);
- for (insn = NEXT_INSN (b->end); insn != stop; insn = NEXT_INSN (insn))
- if (GET_CODE (insn) == CODE_LABEL && !can_delete_label_p (insn))
- return 0;
- }
-
- merge_blocks_nomove (b, c);
- return 1;
+ free (queue);
}
-/* The given edge should potentially a fallthru edge. If that is in
- fact true, delete the unconditional jump and barriers that are in
- the way. */
-
-static void
-tidy_fallthru_edge (e, b, c)
- edge e;
- basic_block b, c;
-{
- rtx q;
+
+/* This structure is used to pass parameters to an from the
+ the function find_regno_partial(). It is used to pass in the
+ register number we are looking, as well as to return any rtx
+ we find. */
- /* ??? In a late-running flow pass, other folks may have deleted basic
- blocks by nopping out blocks, leaving multiple BARRIERs between here
- and the target label. They ought to be chastized and fixed.
+typedef struct {
+ unsigned regno_to_find;
+ rtx retval;
+} find_regno_partial_param;
- We can also wind up with a sequence of undeletable labels between
- one block and the next.
- So search through a sequence of barriers, labels, and notes for
- the head of block C and assert that we really do fall through. */
+/* Find the rtx for the reg numbers specified in 'data' if it is
+ part of an expression which only uses part of the register. Return
+ it in the structure passed in. */
+static int
+find_regno_partial (ptr, data)
+ rtx *ptr;
+ void *data;
+{
+ find_regno_partial_param *param = (find_regno_partial_param *)data;
+ unsigned reg = param->regno_to_find;
+ param->retval = NULL_RTX;
- if (next_real_insn (b->end) != next_real_insn (PREV_INSN (c->head)))
- return;
+ if (*ptr == NULL_RTX)
+ return 0;
- /* Remove what will soon cease being the jump insn from the source block.
- If block B consisted only of this single jump, turn it into a deleted
- note. */
- q = b->end;
- if (GET_CODE (q) == JUMP_INSN)
+ switch (GET_CODE (*ptr))
{
-#ifdef HAVE_cc0
- /* If this was a conditional jump, we need to also delete
- the insn that set cc0. */
- if (! simplejump_p (q) && condjump_p (q))
- q = PREV_INSN (q);
-#endif
+ case ZERO_EXTRACT:
+ case SIGN_EXTRACT:
+ case STRICT_LOW_PART:
+ if (GET_CODE (XEXP (*ptr, 0)) == REG && REGNO (XEXP (*ptr, 0)) == reg)
+ {
+ param->retval = XEXP (*ptr, 0);
+ return 1;
+ }
+ break;
- if (b->head == q)
+ case SUBREG:
+ if (GET_CODE (SUBREG_REG (*ptr)) == REG
+ && REGNO (SUBREG_REG (*ptr)) == reg)
{
- PUT_CODE (q, NOTE);
- NOTE_LINE_NUMBER (q) = NOTE_INSN_DELETED;
- NOTE_SOURCE_FILE (q) = 0;
+ param->retval = SUBREG_REG (*ptr);
+ return 1;
}
- else
- b->end = q = PREV_INSN (q);
- }
+ break;
- /* Selectively unlink the sequence. */
- if (q != PREV_INSN (c->head))
- delete_insn_chain (NEXT_INSN (q), PREV_INSN (c->head));
+ default:
+ break;
+ }
- e->flags |= EDGE_FALLTHRU;
+ return 0;
}
-/* Discover and record the loop depth at the head of each basic block. */
+/* Process all immediate successors of the entry block looking for pseudo
+ registers which are live on entry. Find all of those whose first
+ instance is a partial register reference of some kind, and initialize
+ them to 0 after the entry block. This will prevent bit sets within
+ registers whose value is unknown, and may contain some kind of sticky
+ bits we don't want. */
-static void
-calculate_loop_depth (insns)
- rtx insns;
+int
+initialize_uninitialized_subregs ()
{
- basic_block bb;
rtx insn;
- int i = 0, depth = 1;
+ edge e;
+ int reg, did_something = 0;
+ find_regno_partial_param param;
- bb = BASIC_BLOCK (i);
- for (insn = insns; insn ; insn = NEXT_INSN (insn))
+ for (e = ENTRY_BLOCK_PTR->succ; e; e = e->succ_next)
{
- if (insn == bb->head)
- {
- bb->loop_depth = depth;
- if (++i >= n_basic_blocks)
- break;
- bb = BASIC_BLOCK (i);
- }
-
- if (GET_CODE (insn) == NOTE)
+ basic_block bb = e->dest;
+ regset map = bb->global_live_at_start;
+ EXECUTE_IF_SET_IN_REG_SET (map,
+ FIRST_PSEUDO_REGISTER, reg,
{
- if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG)
- depth++;
- else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END)
- depth--;
-
- /* If we have LOOP_DEPTH == 0, there has been a bookkeeping error. */
- if (depth == 0)
- abort ();
- }
+ int uid = REGNO_FIRST_UID (reg);
+ rtx i;
+
+ /* Find an insn which mentions the register we are looking for.
+ Its preferable to have an instance of the register's rtl since
+ there may be various flags set which we need to duplicate.
+ If we can't find it, its probably an automatic whose initial
+ value doesn't matter, or hopefully something we don't care about. */
+ for (i = get_insns (); i && INSN_UID (i) != uid; i = NEXT_INSN (i))
+ ;
+ if (i != NULL_RTX)
+ {
+ /* Found the insn, now get the REG rtx, if we can. */
+ param.regno_to_find = reg;
+ for_each_rtx (&i, find_regno_partial, &param);
+ if (param.retval != NULL_RTX)
+ {
+ insn = gen_move_insn (param.retval,
+ CONST0_RTX (GET_MODE (param.retval)));
+ insert_insn_on_edge (insn, e);
+ did_something = 1;
+ }
+ }
+ });
}
+
+ if (did_something)
+ commit_edge_insertions ();
+ return did_something;
}
+
-/* Perform data flow analysis.
- F is the first insn of the function and NREGS the number of register numbers
- in use. */
+/* Subroutines of life analysis. */
+
+/* Allocate the permanent data structures that represent the results
+ of life analysis. Not static since used also for stupid life analysis. */
void
-life_analysis (f, nregs, file, remove_dead_code)
- rtx f;
- int nregs;
- FILE *file;
- int remove_dead_code;
+allocate_bb_life_data ()
{
-#ifdef ELIMINABLE_REGS
- register size_t i;
- static struct {int from, to; } eliminables[] = ELIMINABLE_REGS;
-#endif
-
- /* Record which registers will be eliminated. We use this in
- mark_used_regs. */
-
- CLEAR_HARD_REG_SET (elim_reg_set);
-
-#ifdef ELIMINABLE_REGS
- for (i = 0; i < sizeof eliminables / sizeof eliminables[0]; i++)
- SET_HARD_REG_BIT (elim_reg_set, eliminables[i].from);
-#else
- SET_HARD_REG_BIT (elim_reg_set, FRAME_POINTER_REGNUM);
-#endif
+ int i;
- /* Allocate a bitmap to be filled in by record_volatile_insns. */
- uid_volatile = BITMAP_ALLOCA ();
+ for (i = 0; i < n_basic_blocks; i++)
+ {
+ basic_block bb = BASIC_BLOCK (i);
- /* We want alias analysis information for local dead store elimination. */
- init_alias_analysis ();
- life_analysis_1 (f, nregs, remove_dead_code);
- end_alias_analysis ();
+ bb->global_live_at_start = OBSTACK_ALLOC_REG_SET (&flow_obstack);
+ bb->global_live_at_end = OBSTACK_ALLOC_REG_SET (&flow_obstack);
+ }
- if (file)
- dump_flow_info (file);
+ ENTRY_BLOCK_PTR->global_live_at_end
+ = OBSTACK_ALLOC_REG_SET (&flow_obstack);
+ EXIT_BLOCK_PTR->global_live_at_start
+ = OBSTACK_ALLOC_REG_SET (&flow_obstack);
- BITMAP_FREE (uid_volatile);
- free_basic_block_vars (1);
+ regs_live_at_setjmp = OBSTACK_ALLOC_REG_SET (&flow_obstack);
}
-/* Free the variables allocated by find_basic_blocks.
-
- KEEP_HEAD_END_P is non-zero if basic_block_info is not to be freed. */
-
void
-free_basic_block_vars (keep_head_end_p)
- int keep_head_end_p;
+allocate_reg_life_data ()
{
- if (basic_block_for_insn)
- {
- VARRAY_FREE (basic_block_for_insn);
- basic_block_for_insn = NULL;
- }
+ int i;
- if (! keep_head_end_p)
- {
- clear_edges ();
- VARRAY_FREE (basic_block_info);
- n_basic_blocks = 0;
+ max_regno = max_reg_num ();
- ENTRY_BLOCK_PTR->aux = NULL;
- ENTRY_BLOCK_PTR->global_live_at_end = NULL;
- EXIT_BLOCK_PTR->aux = NULL;
- EXIT_BLOCK_PTR->global_live_at_start = NULL;
+ /* Recalculate the register space, in case it has grown. Old style
+ vector oriented regsets would set regset_{size,bytes} here also. */
+ allocate_reg_info (max_regno, FALSE, FALSE);
+
+ /* Reset all the data we'll collect in propagate_block and its
+ subroutines. */
+ for (i = 0; i < max_regno; i++)
+ {
+ REG_N_SETS (i) = 0;
+ REG_N_REFS (i) = 0;
+ REG_N_DEATHS (i) = 0;
+ REG_N_CALLS_CROSSED (i) = 0;
+ REG_LIVE_LENGTH (i) = 0;
+ REG_BASIC_BLOCK (i) = REG_BLOCK_UNKNOWN;
}
}
-/* Return nonzero if the destination of SET equals the source. */
-static int
-set_noop_p (set)
- rtx set;
-{
- rtx src = SET_SRC (set);
- rtx dst = SET_DEST (set);
- if (GET_CODE (src) == REG && GET_CODE (dst) == REG
- && REGNO (src) == REGNO (dst))
- return 1;
- if (GET_CODE (src) != SUBREG || GET_CODE (dst) != SUBREG
- || SUBREG_WORD (src) != SUBREG_WORD (dst))
- return 0;
- src = SUBREG_REG (src);
- dst = SUBREG_REG (dst);
- if (GET_CODE (src) == REG && GET_CODE (dst) == REG
- && REGNO (src) == REGNO (dst))
- return 1;
- return 0;
-}
+/* Delete dead instructions for propagate_block. */
-/* Return nonzero if an insn consists only of SETs, each of which only sets a
- value to itself. */
-static int
-noop_move_p (insn)
+static void
+propagate_block_delete_insn (bb, insn)
+ basic_block bb;
rtx insn;
{
- rtx pat = PATTERN (insn);
+ rtx inote = find_reg_note (insn, REG_LABEL, NULL_RTX);
+ bool purge = false;
- /* Insns carrying these notes are useful later on. */
- if (find_reg_note (insn, REG_EQUAL, NULL_RTX))
- return 0;
+ /* If the insn referred to a label, and that label was attached to
+ an ADDR_VEC, it's safe to delete the ADDR_VEC. In fact, it's
+ pretty much mandatory to delete it, because the ADDR_VEC may be
+ referencing labels that no longer exist.
- if (GET_CODE (pat) == SET && set_noop_p (pat))
- return 1;
+ INSN may reference a deleted label, particularly when a jump
+ table has been optimized into a direct jump. There's no
+ real good way to fix up the reference to the deleted label
+ when the label is deleted, so we just allow it here.
- if (GET_CODE (pat) == PARALLEL)
+ After dead code elimination is complete, we do search for
+ any REG_LABEL notes which reference deleted labels as a
+ sanity check. */
+
+ if (inote && GET_CODE (inote) == CODE_LABEL)
{
- int i;
- /* If nothing but SETs of registers to themselves,
- this insn can also be deleted. */
- for (i = 0; i < XVECLEN (pat, 0); i++)
+ rtx label = XEXP (inote, 0);
+ rtx next;
+
+ /* The label may be forced if it has been put in the constant
+ pool. If that is the only use we must discard the table
+ jump following it, but not the label itself. */
+ if (LABEL_NUSES (label) == 1 + LABEL_PRESERVE_P (label)
+ && (next = next_nonnote_insn (label)) != NULL
+ && GET_CODE (next) == JUMP_INSN
+ && (GET_CODE (PATTERN (next)) == ADDR_VEC
+ || GET_CODE (PATTERN (next)) == ADDR_DIFF_VEC))
{
- rtx tem = XVECEXP (pat, 0, i);
+ rtx pat = PATTERN (next);
+ int diff_vec_p = GET_CODE (pat) == ADDR_DIFF_VEC;
+ int len = XVECLEN (pat, diff_vec_p);
+ int i;
- if (GET_CODE (tem) == USE
- || GET_CODE (tem) == CLOBBER)
- continue;
+ for (i = 0; i < len; i++)
+ LABEL_NUSES (XEXP (XVECEXP (pat, diff_vec_p, i), 0))--;
- if (GET_CODE (tem) != SET || ! set_noop_p (tem))
- return 0;
+ delete_insn (next);
}
-
- return 1;
}
- return 0;
-}
-static void
-notice_stack_pointer_modification (x, pat)
- rtx x;
- rtx pat ATTRIBUTE_UNUSED;
-{
- if (x == stack_pointer_rtx
- /* The stack pointer is only modified indirectly as the result
- of a push until later in flow. See the comments in rtl.texi
- regarding Embedded Side-Effects on Addresses. */
- || (GET_CODE (x) == MEM
- && (GET_CODE (XEXP (x, 0)) == PRE_DEC
- || GET_CODE (XEXP (x, 0)) == PRE_INC
- || GET_CODE (XEXP (x, 0)) == POST_DEC
- || GET_CODE (XEXP (x, 0)) == POST_INC)
- && XEXP (XEXP (x, 0), 0) == stack_pointer_rtx))
- current_function_sp_is_unchanging = 0;
+ if (bb->end == insn)
+ purge = true;
+ delete_insn (insn);
+ if (purge)
+ purge_dead_edges (bb);
}
-/* Record which insns refer to any volatile memory
- or for any reason can't be deleted just because they are dead stores.
- Also, delete any insns that copy a register to itself.
- And see if the stack pointer is modified. */
-static void
-record_volatile_insns (f)
- rtx f;
-{
- rtx insn;
- for (insn = f; insn; insn = NEXT_INSN (insn))
- {
- enum rtx_code code1 = GET_CODE (insn);
- if (code1 == CALL_INSN)
- SET_INSN_VOLATILE (insn);
- else if (code1 == INSN || code1 == JUMP_INSN)
- {
- if (GET_CODE (PATTERN (insn)) != USE
- && volatile_refs_p (PATTERN (insn)))
- SET_INSN_VOLATILE (insn);
-
- /* A SET that makes space on the stack cannot be dead.
- (Such SETs occur only for allocating variable-size data,
- so they will always have a PLUS or MINUS according to the
- direction of stack growth.)
- Even if this function never uses this stack pointer value,
- signal handlers do! */
- else if (code1 == INSN && GET_CODE (PATTERN (insn)) == SET
- && SET_DEST (PATTERN (insn)) == stack_pointer_rtx
-#ifdef STACK_GROWS_DOWNWARD
- && GET_CODE (SET_SRC (PATTERN (insn))) == MINUS
-#else
- && GET_CODE (SET_SRC (PATTERN (insn))) == PLUS
-#endif
- && XEXP (SET_SRC (PATTERN (insn)), 0) == stack_pointer_rtx)
- SET_INSN_VOLATILE (insn);
+/* Delete dead libcalls for propagate_block. Return the insn
+ before the libcall. */
- /* Delete (in effect) any obvious no-op moves. */
- else if (noop_move_p (insn))
- {
- PUT_CODE (insn, NOTE);
- NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
- NOTE_SOURCE_FILE (insn) = 0;
- }
- }
+static rtx
+propagate_block_delete_libcall ( insn, note)
+ rtx insn, note;
+{
+ rtx first = XEXP (note, 0);
+ rtx before = PREV_INSN (first);
- /* Check if insn modifies the stack pointer. */
- if ( current_function_sp_is_unchanging
- && GET_RTX_CLASS (GET_CODE (insn)) == 'i')
- note_stores (PATTERN (insn), notice_stack_pointer_modification);
- }
+ delete_insn_chain (first, insn);
+ return before;
}
-/* Mark those regs which are needed at the end of the function as live
- at the end of the last basic block. */
-static void
-mark_regs_live_at_end (set)
- regset set;
+/* Update the life-status of regs for one insn. Return the previous insn. */
+
+rtx
+propagate_one_insn (pbi, insn)
+ struct propagate_block_info *pbi;
+ rtx insn;
{
+ rtx prev = PREV_INSN (insn);
+ int flags = pbi->flags;
+ int insn_is_dead = 0;
+ int libcall_is_dead = 0;
+ rtx note;
int i;
-
- /* If exiting needs the right stack value, consider the stack pointer
- live at the end of the function. */
- if (! EXIT_IGNORE_STACK
- || (! FRAME_POINTER_REQUIRED
- && ! current_function_calls_alloca
- && flag_omit_frame_pointer)
- || current_function_sp_is_unchanging)
- {
- SET_REGNO_REG_SET (set, STACK_POINTER_REGNUM);
- }
- /* Mark the frame pointer if needed at the end of the function. If
- we end up eliminating it, it will be removed from the live list
- of each basic block by reload. */
+ if (! INSN_P (insn))
+ return prev;
- if (! reload_completed || frame_pointer_needed)
+ note = find_reg_note (insn, REG_RETVAL, NULL_RTX);
+ if (flags & PROP_SCAN_DEAD_CODE)
{
- SET_REGNO_REG_SET (set, FRAME_POINTER_REGNUM);
-#if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
- /* If they are different, also mark the hard frame pointer as live */
- SET_REGNO_REG_SET (set, HARD_FRAME_POINTER_REGNUM);
-#endif
+ insn_is_dead = insn_dead_p (pbi, PATTERN (insn), 0, REG_NOTES (insn));
+ libcall_is_dead = (insn_is_dead && note != 0
+ && libcall_dead_p (pbi, note, insn));
}
- /* Mark all global registers, and all registers used by the epilogue
- as being live at the end of the function since they may be
- referenced by our caller. */
- for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
- if (global_regs[i]
-#ifdef EPILOGUE_USES
- || EPILOGUE_USES (i)
-#endif
- )
- SET_REGNO_REG_SET (set, i);
-
- /* ??? Mark function return value here rather than as uses. */
-}
-
-/* Determine which registers are live at the start of each
- basic block of the function whose first insn is F.
- NREGS is the number of registers used in F.
- We allocate the vector basic_block_live_at_start
- and the regsets that it points to, and fill them with the data.
- regset_size and regset_bytes are also set here. */
-
-static void
-life_analysis_1 (f, nregs, remove_dead_code)
- rtx f;
- int nregs;
- int remove_dead_code;
-{
- int first_pass;
- int changed;
- register int i;
- char save_regs_ever_live[FIRST_PSEUDO_REGISTER];
- regset *new_live_at_end;
-
- struct obstack flow_obstack;
-
- gcc_obstack_init (&flow_obstack);
-
- max_regno = nregs;
-
- /* Allocate and zero out many data structures
- that will record the data from lifetime analysis. */
-
- allocate_reg_life_data ();
- allocate_bb_life_data ();
-
- reg_next_use = (rtx *) alloca (nregs * sizeof (rtx));
- memset (reg_next_use, 0, nregs * sizeof (rtx));
-
- /* Set up regset-vectors used internally within this function.
- Their meanings are documented above, with their declarations. */
-
- new_live_at_end = (regset *) alloca ((n_basic_blocks + 1) * sizeof (regset));
- init_regset_vector (new_live_at_end, n_basic_blocks + 1, &flow_obstack);
-
- /* Stick these vectors into the AUX field of the basic block, so that
- we don't have to keep going through the index. */
+ /* If an instruction consists of just dead store(s) on final pass,
+ delete it. */
+ if ((flags & PROP_KILL_DEAD_CODE) && insn_is_dead)
+ {
+ /* If we're trying to delete a prologue or epilogue instruction
+ that isn't flagged as possibly being dead, something is wrong.
+ But if we are keeping the stack pointer depressed, we might well
+ be deleting insns that are used to compute the amount to update
+ it by, so they are fine. */
+ if (reload_completed
+ && !(TREE_CODE (TREE_TYPE (current_function_decl)) == FUNCTION_TYPE
+ && (TYPE_RETURNS_STACK_DEPRESSED
+ (TREE_TYPE (current_function_decl))))
+ && (((HAVE_epilogue || HAVE_prologue)
+ && prologue_epilogue_contains (insn))
+ || (HAVE_sibcall_epilogue
+ && sibcall_epilogue_contains (insn)))
+ && find_reg_note (insn, REG_MAYBE_DEAD, NULL_RTX) == 0)
+ fatal_insn ("Attempt to delete prologue/epilogue insn:", insn);
+
+ /* Record sets. Do this even for dead instructions, since they
+ would have killed the values if they hadn't been deleted. */
+ mark_set_regs (pbi, PATTERN (insn), insn);
+
+ /* CC0 is now known to be dead. Either this insn used it,
+ in which case it doesn't anymore, or clobbered it,
+ so the next insn can't use it. */
+ pbi->cc0_live = 0;
+
+ if (libcall_is_dead)
+ prev = propagate_block_delete_libcall ( insn, note);
+ else
+ propagate_block_delete_insn (pbi->bb, insn);
- for (i = 0; i < n_basic_blocks; ++i)
- BASIC_BLOCK (i)->aux = new_live_at_end[i];
- ENTRY_BLOCK_PTR->aux = new_live_at_end[i];
+ return prev;
+ }
- /* Assume that the stack pointer is unchanging if alloca hasn't been used.
- This will be cleared by record_volatile_insns if it encounters an insn
- which modifies the stack pointer. */
- current_function_sp_is_unchanging = !current_function_calls_alloca;
+ /* See if this is an increment or decrement that can be merged into
+ a following memory address. */
+#ifdef AUTO_INC_DEC
+ {
+ rtx x = single_set (insn);
+
+ /* Does this instruction increment or decrement a register? */
+ if ((flags & PROP_AUTOINC)
+ && x != 0
+ && GET_CODE (SET_DEST (x)) == REG
+ && (GET_CODE (SET_SRC (x)) == PLUS
+ || GET_CODE (SET_SRC (x)) == MINUS)
+ && XEXP (SET_SRC (x), 0) == SET_DEST (x)
+ && GET_CODE (XEXP (SET_SRC (x), 1)) == CONST_INT
+ /* Ok, look for a following memory ref we can combine with.
+ If one is found, change the memory ref to a PRE_INC
+ or PRE_DEC, cancel this insn, and return 1.
+ Return 0 if nothing has been done. */
+ && try_pre_increment_1 (pbi, insn))
+ return prev;
+ }
+#endif /* AUTO_INC_DEC */
- record_volatile_insns (f);
+ CLEAR_REG_SET (pbi->new_set);
- if (n_basic_blocks > 0)
+ /* If this is not the final pass, and this insn is copying the value of
+ a library call and it's dead, don't scan the insns that perform the
+ library call, so that the call's arguments are not marked live. */
+ if (libcall_is_dead)
{
- regset theend;
- register edge e;
+ /* Record the death of the dest reg. */
+ mark_set_regs (pbi, PATTERN (insn), insn);
- theend = EXIT_BLOCK_PTR->global_live_at_start;
- mark_regs_live_at_end (theend);
-
- /* Propogate this exit data to each of EXIT's predecessors. */
- for (e = EXIT_BLOCK_PTR->pred; e ; e = e->pred_next)
- {
- COPY_REG_SET (e->src->global_live_at_end, theend);
- COPY_REG_SET ((regset) e->src->aux, theend);
- }
+ insn = XEXP (note, 0);
+ return PREV_INSN (insn);
}
+ else if (GET_CODE (PATTERN (insn)) == SET
+ && SET_DEST (PATTERN (insn)) == stack_pointer_rtx
+ && GET_CODE (SET_SRC (PATTERN (insn))) == PLUS
+ && XEXP (SET_SRC (PATTERN (insn)), 0) == stack_pointer_rtx
+ && GET_CODE (XEXP (SET_SRC (PATTERN (insn)), 1)) == CONST_INT)
+ /* We have an insn to pop a constant amount off the stack.
+ (Such insns use PLUS regardless of the direction of the stack,
+ and any insn to adjust the stack by a constant is always a pop.)
+ These insns, if not dead stores, have no effect on life. */
+ ;
+ else
+ {
+ rtx note;
+ /* Any regs live at the time of a call instruction must not go
+ in a register clobbered by calls. Find all regs now live and
+ record this for them. */
- /* The post-reload life analysis have (on a global basis) the same registers
- live as was computed by reload itself.
+ if (GET_CODE (insn) == CALL_INSN && (flags & PROP_REG_INFO))
+ EXECUTE_IF_SET_IN_REG_SET (pbi->reg_live, 0, i,
+ { REG_N_CALLS_CROSSED (i)++; });
- Otherwise elimination offsets and such may be incorrect.
+ /* Record sets. Do this even for dead instructions, since they
+ would have killed the values if they hadn't been deleted. */
+ mark_set_regs (pbi, PATTERN (insn), insn);
- Reload will make some registers as live even though they do not appear
- in the rtl. */
- if (reload_completed)
- memcpy (save_regs_ever_live, regs_ever_live, sizeof (regs_ever_live));
- memset (regs_ever_live, 0, sizeof regs_ever_live);
-
- /* Propagate life info through the basic blocks
- around the graph of basic blocks.
-
- This is a relaxation process: each time a new register
- is live at the end of the basic block, we must scan the block
- to determine which registers are, as a consequence, live at the beginning
- of that block. These registers must then be marked live at the ends
- of all the blocks that can transfer control to that block.
- The process continues until it reaches a fixed point. */
-
- first_pass = 1;
- changed = 1;
- while (changed)
- {
- changed = 0;
- for (i = n_basic_blocks - 1; i >= 0; i--)
+ if (GET_CODE (insn) == CALL_INSN)
{
- basic_block bb = BASIC_BLOCK (i);
- int consider = first_pass;
- int must_rescan = first_pass;
- register int j;
-
- if (!first_pass)
- {
- /* Set CONSIDER if this block needs thinking about at all
- (that is, if the regs live now at the end of it
- are not the same as were live at the end of it when
- we last thought about it).
- Set must_rescan if it needs to be thought about
- instruction by instruction (that is, if any additional
- reg that is live at the end now but was not live there before
- is one of the significant regs of this basic block). */
-
- EXECUTE_IF_AND_COMPL_IN_REG_SET
- ((regset) bb->aux, bb->global_live_at_end, 0, j,
- {
- consider = 1;
- if (REGNO_REG_SET_P (bb->local_set, j))
- {
- must_rescan = 1;
- goto done;
- }
- });
- done:
- if (! consider)
- continue;
- }
+ int i;
+ rtx note, cond;
- /* The live_at_start of this block may be changing,
- so another pass will be required after this one. */
- changed = 1;
+ cond = NULL_RTX;
+ if (GET_CODE (PATTERN (insn)) == COND_EXEC)
+ cond = COND_EXEC_TEST (PATTERN (insn));
- if (! must_rescan)
- {
- /* No complete rescan needed;
- just record those variables newly known live at end
- as live at start as well. */
- IOR_AND_COMPL_REG_SET (bb->global_live_at_start,
- (regset) bb->aux,
- bb->global_live_at_end);
-
- IOR_AND_COMPL_REG_SET (bb->global_live_at_end,
- (regset) bb->aux,
- bb->global_live_at_end);
- }
- else
+ /* Non-constant calls clobber memory. */
+ if (! CONST_OR_PURE_CALL_P (insn))
{
- /* Update the basic_block_live_at_start
- by propagation backwards through the block. */
- COPY_REG_SET (bb->global_live_at_end, (regset) bb->aux);
- COPY_REG_SET (bb->global_live_at_start,
- bb->global_live_at_end);
- propagate_block (bb->global_live_at_start,
- bb->head, bb->end, 0,
- first_pass ? bb->local_set : (regset) 0,
- i, remove_dead_code);
+ free_EXPR_LIST_list (&pbi->mem_set_list);
+ pbi->mem_set_list_len = 0;
}
- /* Update the new_live_at_end's of the block's predecessors. */
- {
- register edge e;
-
- for (e = bb->pred; e ; e = e->pred_next)
- IOR_REG_SET ((regset) e->src->aux, bb->global_live_at_start);
- }
+ /* There may be extra registers to be clobbered. */
+ for (note = CALL_INSN_FUNCTION_USAGE (insn);
+ note;
+ note = XEXP (note, 1))
+ if (GET_CODE (XEXP (note, 0)) == CLOBBER)
+ mark_set_1 (pbi, CLOBBER, XEXP (XEXP (note, 0), 0),
+ cond, insn, pbi->flags);
+
+ /* Calls change all call-used and global registers. */
+ for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
+ if (TEST_HARD_REG_BIT (regs_invalidated_by_call, i))
+ {
+ /* We do not want REG_UNUSED notes for these registers. */
+ mark_set_1 (pbi, CLOBBER, gen_rtx_REG (reg_raw_mode[i], i),
+ cond, insn,
+ pbi->flags & ~(PROP_DEATH_NOTES | PROP_REG_INFO));
+ }
+ }
-#ifdef USE_C_ALLOCA
- alloca (0);
+ /* If an insn doesn't use CC0, it becomes dead since we assume
+ that every insn clobbers it. So show it dead here;
+ mark_used_regs will set it live if it is referenced. */
+ pbi->cc0_live = 0;
+
+ /* Record uses. */
+ if (! insn_is_dead)
+ mark_used_regs (pbi, PATTERN (insn), NULL_RTX, insn);
+ if ((flags & PROP_EQUAL_NOTES)
+ && ((note = find_reg_note (insn, REG_EQUAL, NULL_RTX))
+ || (note = find_reg_note (insn, REG_EQUIV, NULL_RTX))))
+ mark_used_regs (pbi, XEXP (note, 0), NULL_RTX, insn);
+
+ /* Sometimes we may have inserted something before INSN (such as a move)
+ when we make an auto-inc. So ensure we will scan those insns. */
+#ifdef AUTO_INC_DEC
+ prev = PREV_INSN (insn);
#endif
+
+ if (! insn_is_dead && GET_CODE (insn) == CALL_INSN)
+ {
+ int i;
+ rtx note, cond;
+
+ cond = NULL_RTX;
+ if (GET_CODE (PATTERN (insn)) == COND_EXEC)
+ cond = COND_EXEC_TEST (PATTERN (insn));
+
+ /* Calls use their arguments. */
+ for (note = CALL_INSN_FUNCTION_USAGE (insn);
+ note;
+ note = XEXP (note, 1))
+ if (GET_CODE (XEXP (note, 0)) == USE)
+ mark_used_regs (pbi, XEXP (XEXP (note, 0), 0),
+ cond, insn);
+
+ /* The stack ptr is used (honorarily) by a CALL insn. */
+ SET_REGNO_REG_SET (pbi->reg_live, STACK_POINTER_REGNUM);
+
+ /* Calls may also reference any of the global registers,
+ so they are made live. */
+ for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
+ if (global_regs[i])
+ mark_used_reg (pbi, gen_rtx_REG (reg_raw_mode[i], i),
+ cond, insn);
}
- first_pass = 0;
}
- /* The only pseudos that are live at the beginning of the function are
- those that were not set anywhere in the function. local-alloc doesn't
- know how to handle these correctly, so mark them as not local to any
- one basic block. */
+ /* On final pass, update counts of how many insns in which each reg
+ is live. */
+ if (flags & PROP_REG_INFO)
+ EXECUTE_IF_SET_IN_REG_SET (pbi->reg_live, 0, i,
+ { REG_LIVE_LENGTH (i)++; });
- if (n_basic_blocks > 0)
- EXECUTE_IF_SET_IN_REG_SET (BASIC_BLOCK (0)->global_live_at_start,
- FIRST_PSEUDO_REGISTER, i,
- {
- REG_BASIC_BLOCK (i) = REG_BLOCK_GLOBAL;
- });
+ return prev;
+}
- /* Now the life information is accurate. Make one more pass over each
- basic block to delete dead stores, create autoincrement addressing
- and record how many times each register is used, is set, or dies. */
+/* Initialize a propagate_block_info struct for public consumption.
+ Note that the structure itself is opaque to this file, but that
+ the user can use the regsets provided here. */
- for (i = 0; i < n_basic_blocks; i++)
- {
- basic_block bb = BASIC_BLOCK (i);
+struct propagate_block_info *
+init_propagate_block_info (bb, live, local_set, cond_local_set, flags)
+ basic_block bb;
+ regset live, local_set, cond_local_set;
+ int flags;
+{
+ struct propagate_block_info *pbi = xmalloc (sizeof (*pbi));
+
+ pbi->bb = bb;
+ pbi->reg_live = live;
+ pbi->mem_set_list = NULL_RTX;
+ pbi->mem_set_list_len = 0;
+ pbi->local_set = local_set;
+ pbi->cond_local_set = cond_local_set;
+ pbi->cc0_live = 0;
+ pbi->flags = flags;
+
+ if (flags & (PROP_LOG_LINKS | PROP_AUTOINC))
+ pbi->reg_next_use = (rtx *) xcalloc (max_reg_num (), sizeof (rtx));
+ else
+ pbi->reg_next_use = NULL;
- /* We start with global_live_at_end to determine which stores are
- dead. This process is destructive, and we wish to preserve the
- contents of global_live_at_end for posterity. Fortunately,
- new_live_at_end, due to the way we converged on a solution,
- contains a duplicate of global_live_at_end that we can kill. */
- propagate_block ((regset) bb->aux, bb->head, bb->end, 1, (regset) 0, i, remove_dead_code);
+ pbi->new_set = BITMAP_XMALLOC ();
-#ifdef USE_C_ALLOCA
- alloca (0);
-#endif
- }
-
- /* We have a problem with any pseudoreg that lives across the setjmp.
- ANSI says that if a user variable does not change in value between
- the setjmp and the longjmp, then the longjmp preserves it. This
- includes longjmp from a place where the pseudo appears dead.
- (In principle, the value still exists if it is in scope.)
- If the pseudo goes in a hard reg, some other value may occupy
- that hard reg where this pseudo is dead, thus clobbering the pseudo.
- Conclusion: such a pseudo must not go in a hard reg. */
- EXECUTE_IF_SET_IN_REG_SET (regs_live_at_setjmp,
- FIRST_PSEUDO_REGISTER, i,
- {
- if (regno_reg_rtx[i] != 0)
- {
- REG_LIVE_LENGTH (i) = -1;
- REG_BASIC_BLOCK (i) = -1;
- }
- });
+#ifdef HAVE_conditional_execution
+ pbi->reg_cond_dead = splay_tree_new (splay_tree_compare_ints, NULL,
+ free_reg_cond_life_info);
+ pbi->reg_cond_reg = BITMAP_XMALLOC ();
- /* Restore regs_ever_live that was provided by reload. */
- if (reload_completed)
- memcpy (regs_ever_live, save_regs_ever_live, sizeof (regs_ever_live));
+ /* If this block ends in a conditional branch, for each register live
+ from one side of the branch and not the other, record the register
+ as conditionally dead. */
+ if (GET_CODE (bb->end) == JUMP_INSN
+ && any_condjump_p (bb->end))
+ {
+ regset_head diff_head;
+ regset diff = INITIALIZE_REG_SET (diff_head);
+ basic_block bb_true, bb_false;
+ rtx cond_true, cond_false, set_src;
+ int i;
- free_regset_vector (new_live_at_end, n_basic_blocks);
- obstack_free (&flow_obstack, NULL_PTR);
+ /* Identify the successor blocks. */
+ bb_true = bb->succ->dest;
+ if (bb->succ->succ_next != NULL)
+ {
+ bb_false = bb->succ->succ_next->dest;
- for (i = 0; i < n_basic_blocks; ++i)
- BASIC_BLOCK (i)->aux = NULL;
- ENTRY_BLOCK_PTR->aux = NULL;
-}
-
-/* Subroutines of life analysis. */
+ if (bb->succ->flags & EDGE_FALLTHRU)
+ {
+ basic_block t = bb_false;
+ bb_false = bb_true;
+ bb_true = t;
+ }
+ else if (! (bb->succ->succ_next->flags & EDGE_FALLTHRU))
+ abort ();
+ }
+ else
+ {
+ /* This can happen with a conditional jump to the next insn. */
+ if (JUMP_LABEL (bb->end) != bb_true->head)
+ abort ();
-/* Allocate the permanent data structures that represent the results
- of life analysis. Not static since used also for stupid life analysis. */
+ /* Simplest way to do nothing. */
+ bb_false = bb_true;
+ }
-void
-allocate_bb_life_data ()
-{
- register int i;
+ /* Extract the condition from the branch. */
+ set_src = SET_SRC (pc_set (bb->end));
+ cond_true = XEXP (set_src, 0);
+ cond_false = gen_rtx_fmt_ee (reverse_condition (GET_CODE (cond_true)),
+ GET_MODE (cond_true), XEXP (cond_true, 0),
+ XEXP (cond_true, 1));
+ if (GET_CODE (XEXP (set_src, 1)) == PC)
+ {
+ rtx t = cond_false;
+ cond_false = cond_true;
+ cond_true = t;
+ }
- for (i = 0; i < n_basic_blocks; i++)
- {
- basic_block bb = BASIC_BLOCK (i);
+ /* Compute which register lead different lives in the successors. */
+ if (bitmap_operation (diff, bb_true->global_live_at_start,
+ bb_false->global_live_at_start, BITMAP_XOR))
+ {
+ rtx reg = XEXP (cond_true, 0);
- bb->local_set = OBSTACK_ALLOC_REG_SET (function_obstack);
- bb->global_live_at_start = OBSTACK_ALLOC_REG_SET (function_obstack);
- bb->global_live_at_end = OBSTACK_ALLOC_REG_SET (function_obstack);
- }
+ if (GET_CODE (reg) == SUBREG)
+ reg = SUBREG_REG (reg);
- ENTRY_BLOCK_PTR->global_live_at_end
- = OBSTACK_ALLOC_REG_SET (function_obstack);
- EXIT_BLOCK_PTR->global_live_at_start
- = OBSTACK_ALLOC_REG_SET (function_obstack);
+ if (GET_CODE (reg) != REG)
+ abort ();
- regs_live_at_setjmp = OBSTACK_ALLOC_REG_SET (function_obstack);
-}
+ SET_REGNO_REG_SET (pbi->reg_cond_reg, REGNO (reg));
-void
-allocate_reg_life_data ()
-{
- int i;
+ /* For each such register, mark it conditionally dead. */
+ EXECUTE_IF_SET_IN_REG_SET
+ (diff, 0, i,
+ {
+ struct reg_cond_life_info *rcli;
+ rtx cond;
- /* Recalculate the register space, in case it has grown. Old style
- vector oriented regsets would set regset_{size,bytes} here also. */
- allocate_reg_info (max_regno, FALSE, FALSE);
+ rcli = (struct reg_cond_life_info *) xmalloc (sizeof (*rcli));
- /* Because both reg_scan and flow_analysis want to set up the REG_N_SETS
- information, explicitly reset it here. The allocation should have
- already happened on the previous reg_scan pass. Make sure in case
- some more registers were allocated. */
- for (i = 0; i < max_regno; i++)
- REG_N_SETS (i) = 0;
-}
+ if (REGNO_REG_SET_P (bb_true->global_live_at_start, i))
+ cond = cond_false;
+ else
+ cond = cond_true;
+ rcli->condition = cond;
+ rcli->stores = const0_rtx;
+ rcli->orig_condition = cond;
-/* Make each element of VECTOR point at a regset. The vector has
- NELTS elements, and space is allocated from the ALLOC_OBSTACK
- obstack. */
+ splay_tree_insert (pbi->reg_cond_dead, i,
+ (splay_tree_value) rcli);
+ });
+ }
-static void
-init_regset_vector (vector, nelts, alloc_obstack)
- regset *vector;
- int nelts;
- struct obstack *alloc_obstack;
-{
- register int i;
+ FREE_REG_SET (diff);
+ }
+#endif
- for (i = 0; i < nelts; i++)
+ /* If this block has no successors, any stores to the frame that aren't
+ used later in the block are dead. So make a pass over the block
+ recording any such that are made and show them dead at the end. We do
+ a very conservative and simple job here. */
+ if (optimize
+ && ! (TREE_CODE (TREE_TYPE (current_function_decl)) == FUNCTION_TYPE
+ && (TYPE_RETURNS_STACK_DEPRESSED
+ (TREE_TYPE (current_function_decl))))
+ && (flags & PROP_SCAN_DEAD_CODE)
+ && (bb->succ == NULL
+ || (bb->succ->succ_next == NULL
+ && bb->succ->dest == EXIT_BLOCK_PTR
+ && ! current_function_calls_eh_return)))
{
- vector[i] = OBSTACK_ALLOC_REG_SET (alloc_obstack);
- CLEAR_REG_SET (vector[i]);
+ rtx insn, set;
+ for (insn = bb->end; insn != bb->head; insn = PREV_INSN (insn))
+ if (GET_CODE (insn) == INSN
+ && (set = single_set (insn))
+ && GET_CODE (SET_DEST (set)) == MEM)
+ {
+ rtx mem = SET_DEST (set);
+ rtx canon_mem = canon_rtx (mem);
+
+ /* This optimization is performed by faking a store to the
+ memory at the end of the block. This doesn't work for
+ unchanging memories because multiple stores to unchanging
+ memory is illegal and alias analysis doesn't consider it. */
+ if (RTX_UNCHANGING_P (canon_mem))
+ continue;
+
+ if (XEXP (canon_mem, 0) == frame_pointer_rtx
+ || (GET_CODE (XEXP (canon_mem, 0)) == PLUS
+ && XEXP (XEXP (canon_mem, 0), 0) == frame_pointer_rtx
+ && GET_CODE (XEXP (XEXP (canon_mem, 0), 1)) == CONST_INT))
+ add_to_mem_set_list (pbi, canon_mem);
+ }
}
+
+ return pbi;
}
-/* Release any additional space allocated for each element of VECTOR point
- other than the regset header itself. The vector has NELTS elements. */
+/* Release a propagate_block_info struct. */
void
-free_regset_vector (vector, nelts)
- regset *vector;
- int nelts;
+free_propagate_block_info (pbi)
+ struct propagate_block_info *pbi;
{
- register int i;
+ free_EXPR_LIST_list (&pbi->mem_set_list);
- for (i = 0; i < nelts; i++)
- FREE_REG_SET (vector[i]);
-}
+ BITMAP_XFREE (pbi->new_set);
-/* Compute the registers live at the beginning of a basic block
- from those live at the end.
+#ifdef HAVE_conditional_execution
+ splay_tree_delete (pbi->reg_cond_dead);
+ BITMAP_XFREE (pbi->reg_cond_reg);
+#endif
- When called, OLD contains those live at the end.
- On return, it contains those live at the beginning.
- FIRST and LAST are the first and last insns of the basic block.
+ if (pbi->reg_next_use)
+ free (pbi->reg_next_use);
- FINAL is nonzero if we are doing the final pass which is not
- for computing the life info (since that has already been done)
- but for acting on it. On this pass, we delete dead stores,
- set up the logical links and dead-variables lists of instructions,
- and merge instructions for autoincrement and autodecrement addresses.
+ free (pbi);
+}
- SIGNIFICANT is nonzero only the first time for each basic block.
- If it is nonzero, it points to a regset in which we store
- a 1 for each register that is set within the block.
+/* Compute the registers live at the beginning of a basic block BB from
+ those live at the end.
- BNUM is the number of the basic block. */
+ When called, REG_LIVE contains those live at the end. On return, it
+ contains those live at the beginning.
-static void
-propagate_block (old, first, last, final, significant, bnum, remove_dead_code)
- register regset old;
- rtx first;
- rtx last;
- int final;
- regset significant;
- int bnum;
- int remove_dead_code;
-{
- register rtx insn;
- rtx prev;
- regset live;
- regset dead;
+ LOCAL_SET, if non-null, will be set with all registers killed
+ unconditionally by this basic block.
+ Likewise, COND_LOCAL_SET, if non-null, will be set with all registers
+ killed conditionally by this basic block. If there is any unconditional
+ set of a register, then the corresponding bit will be set in LOCAL_SET
+ and cleared in COND_LOCAL_SET.
+ It is valid for LOCAL_SET and COND_LOCAL_SET to be the same set. In this
+ case, the resulting set will be equal to the union of the two sets that
+ would otherwise be computed.
- /* Find the loop depth for this block. Ignore loop level changes in the
- middle of the basic block -- for register allocation purposes, the
- important uses will be in the blocks wholely contained within the loop
- not in the loop pre-header or post-trailer. */
- loop_depth = BASIC_BLOCK (bnum)->loop_depth;
+ Return non-zero if an INSN is deleted (i.e. by dead code removal). */
- dead = ALLOCA_REG_SET ();
- live = ALLOCA_REG_SET ();
+int
+propagate_block (bb, live, local_set, cond_local_set, flags)
+ basic_block bb;
+ regset live;
+ regset local_set;
+ regset cond_local_set;
+ int flags;
+{
+ struct propagate_block_info *pbi;
+ rtx insn, prev;
+ int changed;
- cc0_live = 0;
- mem_set_list = NULL_RTX;
+ pbi = init_propagate_block_info (bb, live, local_set, cond_local_set, flags);
- if (final)
+ if (flags & PROP_REG_INFO)
{
- register int i;
+ int i;
/* Process the regs live at the end of the block.
- Mark them as not local to any one basic block. */
- EXECUTE_IF_SET_IN_REG_SET (old, 0, i,
- {
- REG_BASIC_BLOCK (i) = REG_BLOCK_GLOBAL;
- });
+ Mark them as not local to any one basic block. */
+ EXECUTE_IF_SET_IN_REG_SET (live, 0, i,
+ { REG_BASIC_BLOCK (i) = REG_BLOCK_GLOBAL; });
}
/* Scan the block an insn at a time from end to beginning. */
- for (insn = last; ; insn = prev)
+ changed = 0;
+ for (insn = bb->end;; insn = prev)
{
- prev = PREV_INSN (insn);
-
- if (GET_CODE (insn) == NOTE)
- {
- /* If this is a call to `setjmp' et al,
- warn if any non-volatile datum is live. */
-
- if (final && NOTE_LINE_NUMBER (insn) == NOTE_INSN_SETJMP)
- IOR_REG_SET (regs_live_at_setjmp, old);
- }
-
- /* Update the life-status of regs for this insn.
- First DEAD gets which regs are set in this insn
- then LIVE gets which regs are used in this insn.
- Then the regs live before the insn
- are those live after, with DEAD regs turned off,
- and then LIVE regs turned on. */
-
- else if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
- {
- register int i;
- rtx note = find_reg_note (insn, REG_RETVAL, NULL_RTX);
- int insn_is_dead = 0;
- int libcall_is_dead = 0;
-
- if (remove_dead_code)
- {
- insn_is_dead = (insn_dead_p (PATTERN (insn), old, 0, REG_NOTES (insn))
- /* Don't delete something that refers to volatile storage! */
- && ! INSN_VOLATILE (insn));
- libcall_is_dead = (insn_is_dead && note != 0
- && libcall_dead_p (PATTERN (insn), old, note, insn));
- }
-
- /* If an instruction consists of just dead store(s) on final pass,
- "delete" it by turning it into a NOTE of type NOTE_INSN_DELETED.
- We could really delete it with delete_insn, but that
- can cause trouble for first or last insn in a basic block. */
- if (final && insn_is_dead)
- {
- rtx inote;
- /* If the insn referred to a label, note that the label is
- now less used. */
- for (inote = REG_NOTES (insn); inote; inote = XEXP (inote, 1))
- {
- if (REG_NOTE_KIND (inote) == REG_LABEL)
- {
- rtx label = XEXP (inote, 0);
- rtx next;
- LABEL_NUSES (label)--;
-
- /* If this label was attached to an ADDR_VEC, it's
- safe to delete the ADDR_VEC. In fact, it's pretty much
- mandatory to delete it, because the ADDR_VEC may
- be referencing labels that no longer exist. */
- if (LABEL_NUSES (label) == 0
- && (next = next_nonnote_insn (label)) != NULL
- && GET_CODE (next) == JUMP_INSN
- && (GET_CODE (PATTERN (next)) == ADDR_VEC
- || GET_CODE (PATTERN (next)) == ADDR_DIFF_VEC))
- {
- rtx pat = PATTERN (next);
- int diff_vec_p = GET_CODE (pat) == ADDR_DIFF_VEC;
- int len = XVECLEN (pat, diff_vec_p);
- int i;
- for (i = 0; i < len; i++)
- LABEL_NUSES (XEXP (XVECEXP (pat, diff_vec_p, i), 0))--;
-
- flow_delete_insn (next);
- }
- }
- }
-
- PUT_CODE (insn, NOTE);
- NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
- NOTE_SOURCE_FILE (insn) = 0;
-
- /* CC0 is now known to be dead. Either this insn used it,
- in which case it doesn't anymore, or clobbered it,
- so the next insn can't use it. */
- cc0_live = 0;
-
- /* If this insn is copying the return value from a library call,
- delete the entire library call. */
- if (libcall_is_dead)
- {
- rtx first = XEXP (note, 0);
- rtx p = insn;
- while (INSN_DELETED_P (first))
- first = NEXT_INSN (first);
- while (p != first)
- {
- p = PREV_INSN (p);
- PUT_CODE (p, NOTE);
- NOTE_LINE_NUMBER (p) = NOTE_INSN_DELETED;
- NOTE_SOURCE_FILE (p) = 0;
- }
- }
- goto flushed;
- }
-
- CLEAR_REG_SET (dead);
- CLEAR_REG_SET (live);
-
- /* See if this is an increment or decrement that can be
- merged into a following memory address. */
-#ifdef AUTO_INC_DEC
- {
- register rtx x = single_set (insn);
-
- /* Does this instruction increment or decrement a register? */
- if (!reload_completed
- && final && x != 0
- && GET_CODE (SET_DEST (x)) == REG
- && (GET_CODE (SET_SRC (x)) == PLUS
- || GET_CODE (SET_SRC (x)) == MINUS)
- && XEXP (SET_SRC (x), 0) == SET_DEST (x)
- && GET_CODE (XEXP (SET_SRC (x), 1)) == CONST_INT
- /* Ok, look for a following memory ref we can combine with.
- If one is found, change the memory ref to a PRE_INC
- or PRE_DEC, cancel this insn, and return 1.
- Return 0 if nothing has been done. */
- && try_pre_increment_1 (insn))
- goto flushed;
- }
-#endif /* AUTO_INC_DEC */
+ /* If this is a call to `setjmp' et al, warn if any
+ non-volatile datum is live. */
+ if ((flags & PROP_REG_INFO)
+ && GET_CODE (insn) == CALL_INSN
+ && find_reg_note (insn, REG_SETJMP, NULL))
+ IOR_REG_SET (regs_live_at_setjmp, pbi->reg_live);
- /* If this is not the final pass, and this insn is copying the
- value of a library call and it's dead, don't scan the
- insns that perform the library call, so that the call's
- arguments are not marked live. */
- if (libcall_is_dead)
- {
- /* Mark the dest reg as `significant'. */
- mark_set_regs (old, dead, PATTERN (insn), NULL_RTX, significant);
+ prev = propagate_one_insn (pbi, insn);
+ changed |= NEXT_INSN (prev) != insn;
- insn = XEXP (note, 0);
- prev = PREV_INSN (insn);
- }
- else if (GET_CODE (PATTERN (insn)) == SET
- && SET_DEST (PATTERN (insn)) == stack_pointer_rtx
- && GET_CODE (SET_SRC (PATTERN (insn))) == PLUS
- && XEXP (SET_SRC (PATTERN (insn)), 0) == stack_pointer_rtx
- && GET_CODE (XEXP (SET_SRC (PATTERN (insn)), 1)) == CONST_INT)
- /* We have an insn to pop a constant amount off the stack.
- (Such insns use PLUS regardless of the direction of the stack,
- and any insn to adjust the stack by a constant is always a pop.)
- These insns, if not dead stores, have no effect on life. */
- ;
- else
- {
- /* Any regs live at the time of a call instruction
- must not go in a register clobbered by calls.
- Find all regs now live and record this for them. */
-
- if (GET_CODE (insn) == CALL_INSN && final)
- EXECUTE_IF_SET_IN_REG_SET (old, 0, i,
- {
- REG_N_CALLS_CROSSED (i)++;
- });
-
- /* LIVE gets the regs used in INSN;
- DEAD gets those set by it. Dead insns don't make anything
- live. */
-
- mark_set_regs (old, dead, PATTERN (insn),
- final ? insn : NULL_RTX, significant);
-
- /* If an insn doesn't use CC0, it becomes dead since we
- assume that every insn clobbers it. So show it dead here;
- mark_used_regs will set it live if it is referenced. */
- cc0_live = 0;
-
- if (! insn_is_dead)
- mark_used_regs (old, live, PATTERN (insn), final, insn);
-
- /* Sometimes we may have inserted something before INSN (such as
- a move) when we make an auto-inc. So ensure we will scan
- those insns. */
-#ifdef AUTO_INC_DEC
- prev = PREV_INSN (insn);
-#endif
-
- if (! insn_is_dead && GET_CODE (insn) == CALL_INSN)
- {
- register int i;
-
- rtx note;
-
- for (note = CALL_INSN_FUNCTION_USAGE (insn);
- note;
- note = XEXP (note, 1))
- if (GET_CODE (XEXP (note, 0)) == USE)
- mark_used_regs (old, live, SET_DEST (XEXP (note, 0)),
- final, insn);
-
- /* Each call clobbers all call-clobbered regs that are not
- global or fixed. Note that the function-value reg is a
- call-clobbered reg, and mark_set_regs has already had
- a chance to handle it. */
-
- for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
- if (call_used_regs[i] && ! global_regs[i]
- && ! fixed_regs[i])
- SET_REGNO_REG_SET (dead, i);
-
- /* The stack ptr is used (honorarily) by a CALL insn. */
- SET_REGNO_REG_SET (live, STACK_POINTER_REGNUM);
-
- /* Calls may also reference any of the global registers,
- so they are made live. */
- for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
- if (global_regs[i])
- mark_used_regs (old, live,
- gen_rtx_REG (reg_raw_mode[i], i),
- final, insn);
-
- /* Calls also clobber memory. */
- mem_set_list = NULL_RTX;
- }
-
- /* Update OLD for the registers used or set. */
- AND_COMPL_REG_SET (old, dead);
- IOR_REG_SET (old, live);
-
- }
-
- /* On final pass, update counts of how many insns each reg is live
- at. */
- if (final)
- EXECUTE_IF_SET_IN_REG_SET (old, 0, i,
- { REG_LIVE_LENGTH (i)++; });
- }
- flushed: ;
- if (insn == first)
+ if (insn == bb->head)
break;
}
- FREE_REG_SET (dead);
- FREE_REG_SET (live);
+ free_propagate_block_info (pbi);
+
+ return changed;
}
/* Return 1 if X (the body of an insn, or part of it) is just dead stores
@@ -2949,30 +2003,27 @@ propagate_block (old, first, last, final, significant, bnum, remove_dead_code)
pertaining to the insn. */
static int
-insn_dead_p (x, needed, call_ok, notes)
+insn_dead_p (pbi, x, call_ok, notes)
+ struct propagate_block_info *pbi;
rtx x;
- regset needed;
int call_ok;
rtx notes ATTRIBUTE_UNUSED;
{
enum rtx_code code = GET_CODE (x);
#ifdef AUTO_INC_DEC
- /* If flow is invoked after reload, we must take existing AUTO_INC
- expresions into account. */
- if (reload_completed)
+ /* As flow is invoked after combine, we must take existing AUTO_INC
+ expressions into account. */
+ for (; notes; notes = XEXP (notes, 1))
{
- for ( ; notes; notes = XEXP (notes, 1))
+ if (REG_NOTE_KIND (notes) == REG_INC)
{
- if (REG_NOTE_KIND (notes) == REG_INC)
- {
- int regno = REGNO (XEXP (notes, 0));
+ int regno = REGNO (XEXP (notes, 0));
- /* Don't delete insns to set global regs. */
- if ((regno < FIRST_PSEUDO_REGISTER && global_regs[regno])
- || REGNO_REG_SET_P (needed, regno))
- return 0;
- }
+ /* Don't delete insns to set global regs. */
+ if ((regno < FIRST_PSEUDO_REGISTER && global_regs[regno])
+ || REGNO_REG_SET_P (pbi->reg_live, regno))
+ return 0;
}
}
#endif
@@ -2984,76 +2035,126 @@ insn_dead_p (x, needed, call_ok, notes)
{
rtx r = SET_DEST (x);
- /* A SET that is a subroutine call cannot be dead. */
- if (! call_ok && GET_CODE (SET_SRC (x)) == CALL)
- return 0;
-
#ifdef HAVE_cc0
if (GET_CODE (r) == CC0)
- return ! cc0_live;
+ return ! pbi->cc0_live;
#endif
-
- if (GET_CODE (r) == MEM && ! MEM_VOLATILE_P (r))
+
+ /* A SET that is a subroutine call cannot be dead. */
+ if (GET_CODE (SET_SRC (x)) == CALL)
+ {
+ if (! call_ok)
+ return 0;
+ }
+
+ /* Don't eliminate loads from volatile memory or volatile asms. */
+ else if (volatile_refs_p (SET_SRC (x)))
+ return 0;
+
+ if (GET_CODE (r) == MEM)
{
- rtx temp;
+ rtx temp, canon_r;
+
+ if (MEM_VOLATILE_P (r) || GET_MODE (r) == BLKmode)
+ return 0;
+
+ canon_r = canon_rtx (r);
+
/* Walk the set of memory locations we are currently tracking
and see if one is an identical match to this memory location.
If so, this memory write is dead (remember, we're walking
- backwards from the end of the block to the start. */
- temp = mem_set_list;
- while (temp)
- {
- if (rtx_equal_p (XEXP (temp, 0), r))
- return 1;
- temp = XEXP (temp, 1);
- }
- }
+ backwards from the end of the block to the start). Since
+ rtx_equal_p does not check the alias set or flags, we also
+ must have the potential for them to conflict (anti_dependence). */
+ for (temp = pbi->mem_set_list; temp != 0; temp = XEXP (temp, 1))
+ if (anti_dependence (r, XEXP (temp, 0)))
+ {
+ rtx mem = XEXP (temp, 0);
- while (GET_CODE (r) == SUBREG || GET_CODE (r) == STRICT_LOW_PART
- || GET_CODE (r) == ZERO_EXTRACT)
- r = SUBREG_REG (r);
+ if (rtx_equal_p (XEXP (canon_r, 0), XEXP (mem, 0))
+ && (GET_MODE_SIZE (GET_MODE (canon_r))
+ <= GET_MODE_SIZE (GET_MODE (mem))))
+ return 1;
- if (GET_CODE (r) == REG)
+#ifdef AUTO_INC_DEC
+ /* Check if memory reference matches an auto increment. Only
+ post increment/decrement or modify are valid. */
+ if (GET_MODE (mem) == GET_MODE (r)
+ && (GET_CODE (XEXP (mem, 0)) == POST_DEC
+ || GET_CODE (XEXP (mem, 0)) == POST_INC
+ || GET_CODE (XEXP (mem, 0)) == POST_MODIFY)
+ && GET_MODE (XEXP (mem, 0)) == GET_MODE (r)
+ && rtx_equal_p (XEXP (XEXP (mem, 0), 0), XEXP (r, 0)))
+ return 1;
+#endif
+ }
+ }
+ else
{
- int regno = REGNO (r);
+ while (GET_CODE (r) == SUBREG
+ || GET_CODE (r) == STRICT_LOW_PART
+ || GET_CODE (r) == ZERO_EXTRACT)
+ r = XEXP (r, 0);
- /* Don't delete insns to set global regs. */
- if ((regno < FIRST_PSEUDO_REGISTER && global_regs[regno])
- /* Make sure insns to set frame pointer aren't deleted. */
- || (regno == FRAME_POINTER_REGNUM
+ if (GET_CODE (r) == REG)
+ {
+ int regno = REGNO (r);
+
+ /* Obvious. */
+ if (REGNO_REG_SET_P (pbi->reg_live, regno))
+ return 0;
+
+ /* If this is a hard register, verify that subsequent
+ words are not needed. */
+ if (regno < FIRST_PSEUDO_REGISTER)
+ {
+ int n = HARD_REGNO_NREGS (regno, GET_MODE (r));
+
+ while (--n > 0)
+ if (REGNO_REG_SET_P (pbi->reg_live, regno+n))
+ return 0;
+ }
+
+ /* Don't delete insns to set global regs. */
+ if (regno < FIRST_PSEUDO_REGISTER && global_regs[regno])
+ return 0;
+
+ /* Make sure insns to set the stack pointer aren't deleted. */
+ if (regno == STACK_POINTER_REGNUM)
+ return 0;
+
+ /* ??? These bits might be redundant with the force live bits
+ in calculate_global_regs_live. We would delete from
+ sequential sets; whether this actually affects real code
+ for anything but the stack pointer I don't know. */
+ /* Make sure insns to set the frame pointer aren't deleted. */
+ if (regno == FRAME_POINTER_REGNUM
&& (! reload_completed || frame_pointer_needed))
+ return 0;
#if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
- || (regno == HARD_FRAME_POINTER_REGNUM
+ if (regno == HARD_FRAME_POINTER_REGNUM
&& (! reload_completed || frame_pointer_needed))
+ return 0;
#endif
+
#if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
/* Make sure insns to set arg pointer are never deleted
- (if the arg pointer isn't fixed, there will be a USE for
- it, so we can treat it normally). */
- || (regno == ARG_POINTER_REGNUM && fixed_regs[regno])
+ (if the arg pointer isn't fixed, there will be a USE
+ for it, so we can treat it normally). */
+ if (regno == ARG_POINTER_REGNUM && fixed_regs[regno])
+ return 0;
#endif
- || REGNO_REG_SET_P (needed, regno))
- return 0;
- /* If this is a hard register, verify that subsequent words are
- not needed. */
- if (regno < FIRST_PSEUDO_REGISTER)
- {
- int n = HARD_REGNO_NREGS (regno, GET_MODE (r));
-
- while (--n > 0)
- if (REGNO_REG_SET_P (needed, regno+n))
- return 0;
+ /* Otherwise, the set is dead. */
+ return 1;
}
-
- return 1;
}
}
- /* If performing several activities,
- insn is dead if each activity is individually dead.
- Also, CLOBBERs and USEs can be ignored; a CLOBBER or USE
- that's inside a PARALLEL doesn't make the insn worth keeping. */
+ /* If performing several activities, insn is dead if each activity
+ is individually dead. Also, CLOBBERs and USEs can be ignored; a
+ CLOBBER or USE that's inside a PARALLEL doesn't make the insn
+ worth keeping. */
else if (code == PARALLEL)
{
int i = XVECLEN (x, 0);
@@ -3061,7 +2162,7 @@ insn_dead_p (x, needed, call_ok, notes)
for (i--; i >= 0; i--)
if (GET_CODE (XVECEXP (x, 0, i)) != CLOBBER
&& GET_CODE (XVECEXP (x, 0, i)) != USE
- && ! insn_dead_p (XVECEXP (x, 0, i), needed, call_ok, NULL_RTX))
+ && ! insn_dead_p (pbi, XVECEXP (x, 0, i), call_ok, NULL_RTX))
return 0;
return 1;
@@ -3071,7 +2172,7 @@ insn_dead_p (x, needed, call_ok, notes)
is not necessarily true for hard registers. */
else if (code == CLOBBER && GET_CODE (XEXP (x, 0)) == REG
&& REGNO (XEXP (x, 0)) >= FIRST_PSEUDO_REGISTER
- && ! REGNO_REG_SET_P (needed, REGNO (XEXP (x, 0))))
+ && ! REGNO_REG_SET_P (pbi->reg_live, REGNO (XEXP (x, 0))))
return 1;
/* We do not check other CLOBBER or USE here. An insn consisting of just
@@ -3079,37 +2180,38 @@ insn_dead_p (x, needed, call_ok, notes)
return 0;
}
-/* If X is the pattern of the last insn in a libcall, and assuming X is dead,
+/* If INSN is the last insn in a libcall, and assuming INSN is dead,
return 1 if the entire library call is dead.
- This is true if X copies a register (hard or pseudo)
- and if the hard return reg of the call insn is dead.
- (The caller should have tested the destination of X already for death.)
+ This is true if INSN copies a register (hard or pseudo)
+ and if the hard return reg of the call insn is dead.
+ (The caller should have tested the destination of the SET inside
+ INSN already for death.)
If this insn doesn't just copy a register, then we don't
have an ordinary libcall. In that case, cse could not have
managed to substitute the source for the dest later on,
so we can assume the libcall is dead.
- NEEDED is the bit vector of pseudoregs live before this insn.
- NOTE is the REG_RETVAL note of the insn. INSN is the insn itself. */
+ PBI is the block info giving pseudoregs live before this insn.
+ NOTE is the REG_RETVAL note of the insn. */
static int
-libcall_dead_p (x, needed, note, insn)
- rtx x;
- regset needed;
+libcall_dead_p (pbi, note, insn)
+ struct propagate_block_info *pbi;
rtx note;
rtx insn;
{
- register RTX_CODE code = GET_CODE (x);
+ rtx x = single_set (insn);
- if (code == SET)
+ if (x)
{
- register rtx r = SET_SRC (x);
+ rtx r = SET_SRC (x);
+
if (GET_CODE (r) == REG)
{
rtx call = XEXP (note, 0);
rtx call_pat;
- register int i;
+ int i;
/* Find the call insn. */
while (call != insn && GET_CODE (call) != CALL_INSN)
@@ -3139,7 +2241,7 @@ libcall_dead_p (x, needed, note, insn)
call_pat = XVECEXP (call_pat, 0, i);
}
- return insn_dead_p (call_pat, needed, 1, REG_NOTES (call));
+ return insn_dead_p (pbi, call_pat, 1, REG_NOTES (call));
}
}
return 1;
@@ -3152,7 +2254,7 @@ libcall_dead_p (x, needed, note, insn)
int
regno_uninitialized (regno)
- int regno;
+ unsigned int regno;
{
if (n_basic_blocks == 0
|| (regno < FIRST_PSEUDO_REGISTER
@@ -3180,328 +2282,1079 @@ regno_clobbered_at_setjmp (regno)
&& REGNO_REG_SET_P (regs_live_at_setjmp, regno));
}
-/* INSN references memory, possibly using autoincrement addressing modes.
- Find any entries on the mem_set_list that need to be invalidated due
- to an address change. */
+/* Add MEM to PBI->MEM_SET_LIST. MEM should be canonical. Respect the
+ maximal list size; look for overlaps in mode and select the largest. */
static void
-invalidate_mems_from_autoinc (insn)
- rtx insn;
+add_to_mem_set_list (pbi, mem)
+ struct propagate_block_info *pbi;
+ rtx mem;
{
- rtx note = REG_NOTES (insn);
- for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
- {
- if (REG_NOTE_KIND (note) == REG_INC)
- {
- rtx temp = mem_set_list;
- rtx prev = NULL_RTX;
+ rtx i;
+
+ /* We don't know how large a BLKmode store is, so we must not
+ take them into consideration. */
+ if (GET_MODE (mem) == BLKmode)
+ return;
- while (temp)
+ for (i = pbi->mem_set_list; i ; i = XEXP (i, 1))
+ {
+ rtx e = XEXP (i, 0);
+ if (rtx_equal_p (XEXP (mem, 0), XEXP (e, 0)))
+ {
+ if (GET_MODE_SIZE (GET_MODE (mem)) > GET_MODE_SIZE (GET_MODE (e)))
{
- if (reg_overlap_mentioned_p (XEXP (note, 0), XEXP (temp, 0)))
- {
- /* Splice temp out of list. */
- if (prev)
- XEXP (prev, 1) = XEXP (temp, 1);
- else
- mem_set_list = XEXP (temp, 1);
- }
+#ifdef AUTO_INC_DEC
+ /* If we must store a copy of the mem, we can just modify
+ the mode of the stored copy. */
+ if (pbi->flags & PROP_AUTOINC)
+ PUT_MODE (e, GET_MODE (mem));
else
- prev = temp;
- temp = XEXP (temp, 1);
+#endif
+ XEXP (i, 0) = mem;
}
+ return;
}
}
-}
-/* Process the registers that are set within X.
- Their bits are set to 1 in the regset DEAD,
- because they are dead prior to this insn.
+ if (pbi->mem_set_list_len < MAX_MEM_SET_LIST_LEN)
+ {
+#ifdef AUTO_INC_DEC
+ /* Store a copy of mem, otherwise the address may be
+ scrogged by find_auto_inc. */
+ if (pbi->flags & PROP_AUTOINC)
+ mem = shallow_copy_rtx (mem);
+#endif
+ pbi->mem_set_list = alloc_EXPR_LIST (0, mem, pbi->mem_set_list);
+ pbi->mem_set_list_len++;
+ }
+}
- If INSN is nonzero, it is the insn being processed
- and the fact that it is nonzero implies this is the FINAL pass
- in propagate_block. In this case, various info about register
- usage is stored, LOG_LINKS fields of insns are set up. */
+/* INSN references memory, possibly using autoincrement addressing modes.
+ Find any entries on the mem_set_list that need to be invalidated due
+ to an address change. */
static void
-mark_set_regs (needed, dead, x, insn, significant)
- regset needed;
- regset dead;
- rtx x;
+invalidate_mems_from_autoinc (pbi, insn)
+ struct propagate_block_info *pbi;
rtx insn;
- regset significant;
{
- register RTX_CODE code = GET_CODE (x);
+ rtx note = REG_NOTES (insn);
+ for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
+ if (REG_NOTE_KIND (note) == REG_INC)
+ invalidate_mems_from_set (pbi, XEXP (note, 0));
+}
- if (code == SET || code == CLOBBER)
- mark_set_1 (needed, dead, x, insn, significant);
- else if (code == PARALLEL)
+/* EXP is a REG. Remove any dependent entries from pbi->mem_set_list. */
+
+static void
+invalidate_mems_from_set (pbi, exp)
+ struct propagate_block_info *pbi;
+ rtx exp;
+{
+ rtx temp = pbi->mem_set_list;
+ rtx prev = NULL_RTX;
+ rtx next;
+
+ while (temp)
{
- register int i;
- for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
+ next = XEXP (temp, 1);
+ if (reg_overlap_mentioned_p (exp, XEXP (temp, 0)))
{
- code = GET_CODE (XVECEXP (x, 0, i));
- if (code == SET || code == CLOBBER)
- mark_set_1 (needed, dead, XVECEXP (x, 0, i), insn, significant);
+ /* Splice this entry out of the list. */
+ if (prev)
+ XEXP (prev, 1) = next;
+ else
+ pbi->mem_set_list = next;
+ free_EXPR_LIST_node (temp);
+ pbi->mem_set_list_len--;
}
+ else
+ prev = temp;
+ temp = next;
}
}
-/* Process a single SET rtx, X. */
+/* Process the registers that are set within X. Their bits are set to
+ 1 in the regset DEAD, because they are dead prior to this insn.
+
+ If INSN is nonzero, it is the insn being processed.
+
+ FLAGS is the set of operations to perform. */
static void
-mark_set_1 (needed, dead, x, insn, significant)
- regset needed;
- regset dead;
- rtx x;
- rtx insn;
- regset significant;
+mark_set_regs (pbi, x, insn)
+ struct propagate_block_info *pbi;
+ rtx x, insn;
{
- register int regno;
- register rtx reg = SET_DEST (x);
-
- /* Some targets place small structures in registers for
- return values of functions. We have to detect this
- case specially here to get correct flow information. */
- if (GET_CODE (reg) == PARALLEL
- && GET_MODE (reg) == BLKmode)
- {
- register int i;
+ rtx cond = NULL_RTX;
+ rtx link;
+ enum rtx_code code;
- for (i = XVECLEN (reg, 0) - 1; i >= 0; i--)
- mark_set_1 (needed, dead, XVECEXP (reg, 0, i), insn, significant);
+ if (insn)
+ for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
+ {
+ if (REG_NOTE_KIND (link) == REG_INC)
+ mark_set_1 (pbi, SET, XEXP (link, 0),
+ (GET_CODE (x) == COND_EXEC
+ ? COND_EXEC_TEST (x) : NULL_RTX),
+ insn, pbi->flags);
+ }
+ retry:
+ switch (code = GET_CODE (x))
+ {
+ case SET:
+ case CLOBBER:
+ mark_set_1 (pbi, code, SET_DEST (x), cond, insn, pbi->flags);
return;
+
+ case COND_EXEC:
+ cond = COND_EXEC_TEST (x);
+ x = COND_EXEC_CODE (x);
+ goto retry;
+
+ case PARALLEL:
+ {
+ int i;
+
+ for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
+ {
+ rtx sub = XVECEXP (x, 0, i);
+ switch (code = GET_CODE (sub))
+ {
+ case COND_EXEC:
+ if (cond != NULL_RTX)
+ abort ();
+
+ cond = COND_EXEC_TEST (sub);
+ sub = COND_EXEC_CODE (sub);
+ if (GET_CODE (sub) != SET && GET_CODE (sub) != CLOBBER)
+ break;
+ /* Fall through. */
+
+ case SET:
+ case CLOBBER:
+ mark_set_1 (pbi, code, SET_DEST (sub), cond, insn, pbi->flags);
+ break;
+
+ default:
+ break;
+ }
+ }
+ break;
+ }
+
+ default:
+ break;
}
+}
- /* Modifying just one hardware register of a multi-reg value
- or just a byte field of a register
- does not mean the value from before this insn is now dead.
- But it does mean liveness of that register at the end of the block
- is significant.
+/* Process a single set, which appears in INSN. REG (which may not
+ actually be a REG, it may also be a SUBREG, PARALLEL, etc.) is
+ being set using the CODE (which may be SET, CLOBBER, or COND_EXEC).
+ If the set is conditional (because it appear in a COND_EXEC), COND
+ will be the condition. */
- Within mark_set_1, however, we treat it as if the register is
- indeed modified. mark_used_regs will, however, also treat this
- register as being used. Thus, we treat these insns as setting a
- new value for the register as a function of its old value. This
- cases LOG_LINKS to be made appropriately and this will help combine. */
+static void
+mark_set_1 (pbi, code, reg, cond, insn, flags)
+ struct propagate_block_info *pbi;
+ enum rtx_code code;
+ rtx reg, cond, insn;
+ int flags;
+{
+ int regno_first = -1, regno_last = -1;
+ unsigned long not_dead = 0;
+ int i;
- while (GET_CODE (reg) == SUBREG || GET_CODE (reg) == ZERO_EXTRACT
- || GET_CODE (reg) == SIGN_EXTRACT
- || GET_CODE (reg) == STRICT_LOW_PART)
- reg = XEXP (reg, 0);
+ /* Modifying just one hardware register of a multi-reg value or just a
+ byte field of a register does not mean the value from before this insn
+ is now dead. Of course, if it was dead after it's unused now. */
- /* If this set is a MEM, then it kills any aliased writes.
- If this set is a REG, then it kills any MEMs which use the reg. */
- if (GET_CODE (reg) == MEM
- || GET_CODE (reg) == REG)
+ switch (GET_CODE (reg))
{
- rtx temp = mem_set_list;
- rtx prev = NULL_RTX;
+ case PARALLEL:
+ /* Some targets place small structures in registers for return values of
+ functions. We have to detect this case specially here to get correct
+ flow information. */
+ for (i = XVECLEN (reg, 0) - 1; i >= 0; i--)
+ if (XEXP (XVECEXP (reg, 0, i), 0) != 0)
+ mark_set_1 (pbi, code, XEXP (XVECEXP (reg, 0, i), 0), cond, insn,
+ flags);
+ return;
+
+ case ZERO_EXTRACT:
+ case SIGN_EXTRACT:
+ case STRICT_LOW_PART:
+ /* ??? Assumes STRICT_LOW_PART not used on multi-word registers. */
+ do
+ reg = XEXP (reg, 0);
+ while (GET_CODE (reg) == SUBREG
+ || GET_CODE (reg) == ZERO_EXTRACT
+ || GET_CODE (reg) == SIGN_EXTRACT
+ || GET_CODE (reg) == STRICT_LOW_PART);
+ if (GET_CODE (reg) == MEM)
+ break;
+ not_dead = (unsigned long) REGNO_REG_SET_P (pbi->reg_live, REGNO (reg));
+ /* Fall through. */
+
+ case REG:
+ regno_last = regno_first = REGNO (reg);
+ if (regno_first < FIRST_PSEUDO_REGISTER)
+ regno_last += HARD_REGNO_NREGS (regno_first, GET_MODE (reg)) - 1;
+ break;
- while (temp)
+ case SUBREG:
+ if (GET_CODE (SUBREG_REG (reg)) == REG)
{
- if ((GET_CODE (reg) == MEM
- && output_dependence (XEXP (temp, 0), reg))
- || (GET_CODE (reg) == REG
- && reg_overlap_mentioned_p (reg, XEXP (temp, 0))))
+ enum machine_mode outer_mode = GET_MODE (reg);
+ enum machine_mode inner_mode = GET_MODE (SUBREG_REG (reg));
+
+ /* Identify the range of registers affected. This is moderately
+ tricky for hard registers. See alter_subreg. */
+
+ regno_last = regno_first = REGNO (SUBREG_REG (reg));
+ if (regno_first < FIRST_PSEUDO_REGISTER)
{
- /* Splice this entry out of the list. */
- if (prev)
- XEXP (prev, 1) = XEXP (temp, 1);
- else
- mem_set_list = XEXP (temp, 1);
+ regno_first += subreg_regno_offset (regno_first, inner_mode,
+ SUBREG_BYTE (reg),
+ outer_mode);
+ regno_last = (regno_first
+ + HARD_REGNO_NREGS (regno_first, outer_mode) - 1);
+
+ /* Since we've just adjusted the register number ranges, make
+ sure REG matches. Otherwise some_was_live will be clear
+ when it shouldn't have been, and we'll create incorrect
+ REG_UNUSED notes. */
+ reg = gen_rtx_REG (outer_mode, regno_first);
}
else
- prev = temp;
- temp = XEXP (temp, 1);
+ {
+ /* If the number of words in the subreg is less than the number
+ of words in the full register, we have a well-defined partial
+ set. Otherwise the high bits are undefined.
+
+ This is only really applicable to pseudos, since we just took
+ care of multi-word hard registers. */
+ if (((GET_MODE_SIZE (outer_mode)
+ + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
+ < ((GET_MODE_SIZE (inner_mode)
+ + UNITS_PER_WORD - 1) / UNITS_PER_WORD))
+ not_dead = (unsigned long) REGNO_REG_SET_P (pbi->reg_live,
+ regno_first);
+
+ reg = SUBREG_REG (reg);
+ }
}
+ else
+ reg = SUBREG_REG (reg);
+ break;
+
+ default:
+ break;
}
- /* If the memory reference had embedded side effects (autoincrement
- address modes. Then we may need to kill some entries on the
- memory set list. */
- if (insn && GET_CODE (reg) == MEM)
- invalidate_mems_from_autoinc (insn);
-
- if (GET_CODE (reg) == MEM && ! side_effects_p (reg)
- /* We do not know the size of a BLKmode store, so we do not track
- them for redundant store elimination. */
- && GET_MODE (reg) != BLKmode
- /* There are no REG_INC notes for SP, so we can't assume we'll see
- everything that invalidates it. To be safe, don't eliminate any
- stores though SP; none of them should be redundant anyway. */
- && ! reg_mentioned_p (stack_pointer_rtx, reg))
- mem_set_list = gen_rtx_EXPR_LIST (VOIDmode, reg, mem_set_list);
+ /* If this set is a MEM, then it kills any aliased writes.
+ If this set is a REG, then it kills any MEMs which use the reg. */
+ if (optimize && (flags & PROP_SCAN_DEAD_CODE))
+ {
+ if (GET_CODE (reg) == REG)
+ invalidate_mems_from_set (pbi, reg);
+
+ /* If the memory reference had embedded side effects (autoincrement
+ address modes. Then we may need to kill some entries on the
+ memory set list. */
+ if (insn && GET_CODE (reg) == MEM)
+ invalidate_mems_from_autoinc (pbi, insn);
+
+ if (GET_CODE (reg) == MEM && ! side_effects_p (reg)
+ /* ??? With more effort we could track conditional memory life. */
+ && ! cond
+ /* There are no REG_INC notes for SP, so we can't assume we'll see
+ everything that invalidates it. To be safe, don't eliminate any
+ stores though SP; none of them should be redundant anyway. */
+ && ! reg_mentioned_p (stack_pointer_rtx, reg))
+ add_to_mem_set_list (pbi, canon_rtx (reg));
+ }
if (GET_CODE (reg) == REG
- && (regno = REGNO (reg), ! (regno == FRAME_POINTER_REGNUM
- && (! reload_completed || frame_pointer_needed)))
+ && ! (regno_first == FRAME_POINTER_REGNUM
+ && (! reload_completed || frame_pointer_needed))
#if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
- && ! (regno == HARD_FRAME_POINTER_REGNUM
+ && ! (regno_first == HARD_FRAME_POINTER_REGNUM
&& (! reload_completed || frame_pointer_needed))
#endif
#if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
- && ! (regno == ARG_POINTER_REGNUM && fixed_regs[regno])
+ && ! (regno_first == ARG_POINTER_REGNUM && fixed_regs[regno_first])
#endif
- && ! (regno < FIRST_PSEUDO_REGISTER && global_regs[regno]))
- /* && regno != STACK_POINTER_REGNUM) -- let's try without this. */
+ )
{
- int some_needed = REGNO_REG_SET_P (needed, regno);
- int some_not_needed = ! some_needed;
-
- /* Mark it as a significant register for this basic block. */
- if (significant)
- SET_REGNO_REG_SET (significant, regno);
+ int some_was_live = 0, some_was_dead = 0;
- /* Mark it as dead before this insn. */
- SET_REGNO_REG_SET (dead, regno);
-
- /* A hard reg in a wide mode may really be multiple registers.
- If so, mark all of them just like the first. */
- if (regno < FIRST_PSEUDO_REGISTER)
+ for (i = regno_first; i <= regno_last; ++i)
{
- int n;
-
- /* Nothing below is needed for the stack pointer; get out asap.
- Eg, log links aren't needed, since combine won't use them. */
- if (regno == STACK_POINTER_REGNUM)
- return;
-
- n = HARD_REGNO_NREGS (regno, GET_MODE (reg));
- while (--n > 0)
+ int needed_regno = REGNO_REG_SET_P (pbi->reg_live, i);
+ if (pbi->local_set)
{
- int regno_n = regno + n;
- int needed_regno = REGNO_REG_SET_P (needed, regno_n);
- if (significant)
- SET_REGNO_REG_SET (significant, regno_n);
-
- SET_REGNO_REG_SET (dead, regno_n);
- some_needed |= needed_regno;
- some_not_needed |= ! needed_regno;
+ /* Order of the set operation matters here since both
+ sets may be the same. */
+ CLEAR_REGNO_REG_SET (pbi->cond_local_set, i);
+ if (cond != NULL_RTX
+ && ! REGNO_REG_SET_P (pbi->local_set, i))
+ SET_REGNO_REG_SET (pbi->cond_local_set, i);
+ else
+ SET_REGNO_REG_SET (pbi->local_set, i);
}
+ if (code != CLOBBER)
+ SET_REGNO_REG_SET (pbi->new_set, i);
+
+ some_was_live |= needed_regno;
+ some_was_dead |= ! needed_regno;
}
- /* Additional data to record if this is the final pass. */
- if (insn)
+
+#ifdef HAVE_conditional_execution
+ /* Consider conditional death in deciding that the register needs
+ a death note. */
+ if (some_was_live && ! not_dead
+ /* The stack pointer is never dead. Well, not strictly true,
+ but it's very difficult to tell from here. Hopefully
+ combine_stack_adjustments will fix up the most egregious
+ errors. */
+ && regno_first != STACK_POINTER_REGNUM)
{
- register rtx y = reg_next_use[regno];
- register int blocknum = BLOCK_NUM (insn);
+ for (i = regno_first; i <= regno_last; ++i)
+ if (! mark_regno_cond_dead (pbi, i, cond))
+ not_dead |= ((unsigned long) 1) << (i - regno_first);
+ }
+#endif
- /* If this is a hard reg, record this function uses the reg. */
+ /* Additional data to record if this is the final pass. */
+ if (flags & (PROP_LOG_LINKS | PROP_REG_INFO
+ | PROP_DEATH_NOTES | PROP_AUTOINC))
+ {
+ rtx y;
+ int blocknum = pbi->bb->index;
- if (regno < FIRST_PSEUDO_REGISTER)
+ y = NULL_RTX;
+ if (flags & (PROP_LOG_LINKS | PROP_AUTOINC))
{
- register int i;
- int endregno = regno + HARD_REGNO_NREGS (regno, GET_MODE (reg));
+ y = pbi->reg_next_use[regno_first];
+
+ /* The next use is no longer next, since a store intervenes. */
+ for (i = regno_first; i <= regno_last; ++i)
+ pbi->reg_next_use[i] = 0;
+ }
- for (i = regno; i < endregno; i++)
+ if (flags & PROP_REG_INFO)
+ {
+ for (i = regno_first; i <= regno_last; ++i)
{
- /* The next use is no longer "next", since a store
- intervenes. */
- reg_next_use[i] = 0;
+ /* Count (weighted) references, stores, etc. This counts a
+ register twice if it is modified, but that is correct. */
+ REG_N_SETS (i) += 1;
+ REG_N_REFS (i) += 1;
+ REG_FREQ (i) += REG_FREQ_FROM_BB (pbi->bb);
+
+ /* The insns where a reg is live are normally counted
+ elsewhere, but we want the count to include the insn
+ where the reg is set, and the normal counting mechanism
+ would not count it. */
+ REG_LIVE_LENGTH (i) += 1;
+ }
- regs_ever_live[i] = 1;
- REG_N_SETS (i)++;
+ /* If this is a hard reg, record this function uses the reg. */
+ if (regno_first < FIRST_PSEUDO_REGISTER)
+ {
+ for (i = regno_first; i <= regno_last; i++)
+ regs_ever_live[i] = 1;
+ }
+ else
+ {
+ /* Keep track of which basic blocks each reg appears in. */
+ if (REG_BASIC_BLOCK (regno_first) == REG_BLOCK_UNKNOWN)
+ REG_BASIC_BLOCK (regno_first) = blocknum;
+ else if (REG_BASIC_BLOCK (regno_first) != blocknum)
+ REG_BASIC_BLOCK (regno_first) = REG_BLOCK_GLOBAL;
}
- }
- else
- {
- /* The next use is no longer "next", since a store
- intervenes. */
- reg_next_use[regno] = 0;
-
- /* Keep track of which basic blocks each reg appears in. */
-
- if (REG_BASIC_BLOCK (regno) == REG_BLOCK_UNKNOWN)
- REG_BASIC_BLOCK (regno) = blocknum;
- else if (REG_BASIC_BLOCK (regno) != blocknum)
- REG_BASIC_BLOCK (regno) = REG_BLOCK_GLOBAL;
-
- /* Count (weighted) references, stores, etc. This counts a
- register twice if it is modified, but that is correct. */
- REG_N_SETS (regno)++;
-
- REG_N_REFS (regno) += loop_depth;
-
- /* The insns where a reg is live are normally counted
- elsewhere, but we want the count to include the insn
- where the reg is set, and the normal counting mechanism
- would not count it. */
- REG_LIVE_LENGTH (regno)++;
}
- if (! some_not_needed)
+ if (! some_was_dead)
{
- /* Make a logical link from the next following insn
- that uses this register, back to this insn.
- The following insns have already been processed.
-
- We don't build a LOG_LINK for hard registers containing
- in ASM_OPERANDs. If these registers get replaced,
- we might wind up changing the semantics of the insn,
- even if reload can make what appear to be valid assignments
- later. */
- if (y && (BLOCK_NUM (y) == blocknum)
- && (regno >= FIRST_PSEUDO_REGISTER
- || asm_noperands (PATTERN (y)) < 0))
- LOG_LINKS (y)
- = gen_rtx_INSN_LIST (VOIDmode, insn, LOG_LINKS (y));
+ if (flags & PROP_LOG_LINKS)
+ {
+ /* Make a logical link from the next following insn
+ that uses this register, back to this insn.
+ The following insns have already been processed.
+
+ We don't build a LOG_LINK for hard registers containing
+ in ASM_OPERANDs. If these registers get replaced,
+ we might wind up changing the semantics of the insn,
+ even if reload can make what appear to be valid
+ assignments later. */
+ if (y && (BLOCK_NUM (y) == blocknum)
+ && (regno_first >= FIRST_PSEUDO_REGISTER
+ || asm_noperands (PATTERN (y)) < 0))
+ LOG_LINKS (y) = alloc_INSN_LIST (insn, LOG_LINKS (y));
+ }
}
- else if (! some_needed)
+ else if (not_dead)
+ ;
+ else if (! some_was_live)
{
- /* Note that dead stores have already been deleted when possible
- If we get here, we have found a dead store that cannot
- be eliminated (because the same insn does something useful).
- Indicate this by marking the reg being set as dying here. */
- REG_NOTES (insn)
- = gen_rtx_EXPR_LIST (REG_UNUSED, reg, REG_NOTES (insn));
- REG_N_DEATHS (REGNO (reg))++;
+ if (flags & PROP_REG_INFO)
+ REG_N_DEATHS (regno_first) += 1;
+
+ if (flags & PROP_DEATH_NOTES)
+ {
+ /* Note that dead stores have already been deleted
+ when possible. If we get here, we have found a
+ dead store that cannot be eliminated (because the
+ same insn does something useful). Indicate this
+ by marking the reg being set as dying here. */
+ REG_NOTES (insn)
+ = alloc_EXPR_LIST (REG_UNUSED, reg, REG_NOTES (insn));
+ }
}
else
{
- /* This is a case where we have a multi-word hard register
- and some, but not all, of the words of the register are
- needed in subsequent insns. Write REG_UNUSED notes
- for those parts that were not needed. This case should
- be rare. */
-
- int i;
-
- for (i = HARD_REGNO_NREGS (regno, GET_MODE (reg)) - 1;
- i >= 0; i--)
- if (!REGNO_REG_SET_P (needed, regno + i))
- REG_NOTES (insn)
- = gen_rtx_EXPR_LIST (REG_UNUSED,
- gen_rtx_REG (reg_raw_mode[regno + i],
- regno + i),
- REG_NOTES (insn));
+ if (flags & PROP_DEATH_NOTES)
+ {
+ /* This is a case where we have a multi-word hard register
+ and some, but not all, of the words of the register are
+ needed in subsequent insns. Write REG_UNUSED notes
+ for those parts that were not needed. This case should
+ be rare. */
+
+ for (i = regno_first; i <= regno_last; ++i)
+ if (! REGNO_REG_SET_P (pbi->reg_live, i))
+ REG_NOTES (insn)
+ = alloc_EXPR_LIST (REG_UNUSED,
+ gen_rtx_REG (reg_raw_mode[i], i),
+ REG_NOTES (insn));
+ }
}
}
+
+ /* Mark the register as being dead. */
+ if (some_was_live
+ /* The stack pointer is never dead. Well, not strictly true,
+ but it's very difficult to tell from here. Hopefully
+ combine_stack_adjustments will fix up the most egregious
+ errors. */
+ && regno_first != STACK_POINTER_REGNUM)
+ {
+ for (i = regno_first; i <= regno_last; ++i)
+ if (!(not_dead & (((unsigned long) 1) << (i - regno_first))))
+ CLEAR_REGNO_REG_SET (pbi->reg_live, i);
+ }
}
else if (GET_CODE (reg) == REG)
- reg_next_use[regno] = 0;
+ {
+ if (flags & (PROP_LOG_LINKS | PROP_AUTOINC))
+ pbi->reg_next_use[regno_first] = 0;
+ }
/* If this is the last pass and this is a SCRATCH, show it will be dying
here and count it. */
- else if (GET_CODE (reg) == SCRATCH && insn != 0)
+ else if (GET_CODE (reg) == SCRATCH)
{
- REG_NOTES (insn)
- = gen_rtx_EXPR_LIST (REG_UNUSED, reg, REG_NOTES (insn));
+ if (flags & PROP_DEATH_NOTES)
+ REG_NOTES (insn)
+ = alloc_EXPR_LIST (REG_UNUSED, reg, REG_NOTES (insn));
}
}
+#ifdef HAVE_conditional_execution
+/* Mark REGNO conditionally dead.
+ Return true if the register is now unconditionally dead. */
+
+static int
+mark_regno_cond_dead (pbi, regno, cond)
+ struct propagate_block_info *pbi;
+ int regno;
+ rtx cond;
+{
+ /* If this is a store to a predicate register, the value of the
+ predicate is changing, we don't know that the predicate as seen
+ before is the same as that seen after. Flush all dependent
+ conditions from reg_cond_dead. This will make all such
+ conditionally live registers unconditionally live. */
+ if (REGNO_REG_SET_P (pbi->reg_cond_reg, regno))
+ flush_reg_cond_reg (pbi, regno);
+
+ /* If this is an unconditional store, remove any conditional
+ life that may have existed. */
+ if (cond == NULL_RTX)
+ splay_tree_remove (pbi->reg_cond_dead, regno);
+ else
+ {
+ splay_tree_node node;
+ struct reg_cond_life_info *rcli;
+ rtx ncond;
+
+ /* Otherwise this is a conditional set. Record that fact.
+ It may have been conditionally used, or there may be a
+ subsequent set with a complimentary condition. */
+
+ node = splay_tree_lookup (pbi->reg_cond_dead, regno);
+ if (node == NULL)
+ {
+ /* The register was unconditionally live previously.
+ Record the current condition as the condition under
+ which it is dead. */
+ rcli = (struct reg_cond_life_info *) xmalloc (sizeof (*rcli));
+ rcli->condition = cond;
+ rcli->stores = cond;
+ rcli->orig_condition = const0_rtx;
+ splay_tree_insert (pbi->reg_cond_dead, regno,
+ (splay_tree_value) rcli);
+
+ SET_REGNO_REG_SET (pbi->reg_cond_reg, REGNO (XEXP (cond, 0)));
+
+ /* Not unconditionally dead. */
+ return 0;
+ }
+ else
+ {
+ /* The register was conditionally live previously.
+ Add the new condition to the old. */
+ rcli = (struct reg_cond_life_info *) node->value;
+ ncond = rcli->condition;
+ ncond = ior_reg_cond (ncond, cond, 1);
+ if (rcli->stores == const0_rtx)
+ rcli->stores = cond;
+ else if (rcli->stores != const1_rtx)
+ rcli->stores = ior_reg_cond (rcli->stores, cond, 1);
+
+ /* If the register is now unconditionally dead, remove the entry
+ in the splay_tree. A register is unconditionally dead if the
+ dead condition ncond is true. A register is also unconditionally
+ dead if the sum of all conditional stores is an unconditional
+ store (stores is true), and the dead condition is identically the
+ same as the original dead condition initialized at the end of
+ the block. This is a pointer compare, not an rtx_equal_p
+ compare. */
+ if (ncond == const1_rtx
+ || (ncond == rcli->orig_condition && rcli->stores == const1_rtx))
+ splay_tree_remove (pbi->reg_cond_dead, regno);
+ else
+ {
+ rcli->condition = ncond;
+
+ SET_REGNO_REG_SET (pbi->reg_cond_reg, REGNO (XEXP (cond, 0)));
+
+ /* Not unconditionally dead. */
+ return 0;
+ }
+ }
+ }
+
+ return 1;
+}
+
+/* Called from splay_tree_delete for pbi->reg_cond_life. */
+
+static void
+free_reg_cond_life_info (value)
+ splay_tree_value value;
+{
+ struct reg_cond_life_info *rcli = (struct reg_cond_life_info *) value;
+ free (rcli);
+}
+
+/* Helper function for flush_reg_cond_reg. */
+
+static int
+flush_reg_cond_reg_1 (node, data)
+ splay_tree_node node;
+ void *data;
+{
+ struct reg_cond_life_info *rcli;
+ int *xdata = (int *) data;
+ unsigned int regno = xdata[0];
+
+ /* Don't need to search if last flushed value was farther on in
+ the in-order traversal. */
+ if (xdata[1] >= (int) node->key)
+ return 0;
+
+ /* Splice out portions of the expression that refer to regno. */
+ rcli = (struct reg_cond_life_info *) node->value;
+ rcli->condition = elim_reg_cond (rcli->condition, regno);
+ if (rcli->stores != const0_rtx && rcli->stores != const1_rtx)
+ rcli->stores = elim_reg_cond (rcli->stores, regno);
+
+ /* If the entire condition is now false, signal the node to be removed. */
+ if (rcli->condition == const0_rtx)
+ {
+ xdata[1] = node->key;
+ return -1;
+ }
+ else if (rcli->condition == const1_rtx)
+ abort ();
+
+ return 0;
+}
+
+/* Flush all (sub) expressions referring to REGNO from REG_COND_LIVE. */
+
+static void
+flush_reg_cond_reg (pbi, regno)
+ struct propagate_block_info *pbi;
+ int regno;
+{
+ int pair[2];
+
+ pair[0] = regno;
+ pair[1] = -1;
+ while (splay_tree_foreach (pbi->reg_cond_dead,
+ flush_reg_cond_reg_1, pair) == -1)
+ splay_tree_remove (pbi->reg_cond_dead, pair[1]);
+
+ CLEAR_REGNO_REG_SET (pbi->reg_cond_reg, regno);
+}
+
+/* Logical arithmetic on predicate conditions. IOR, NOT and AND.
+ For ior/and, the ADD flag determines whether we want to add the new
+ condition X to the old one unconditionally. If it is zero, we will
+ only return a new expression if X allows us to simplify part of
+ OLD, otherwise we return NULL to the caller.
+ If ADD is nonzero, we will return a new condition in all cases. The
+ toplevel caller of one of these functions should always pass 1 for
+ ADD. */
+
+static rtx
+ior_reg_cond (old, x, add)
+ rtx old, x;
+ int add;
+{
+ rtx op0, op1;
+
+ if (GET_RTX_CLASS (GET_CODE (old)) == '<')
+ {
+ if (GET_RTX_CLASS (GET_CODE (x)) == '<'
+ && REVERSE_CONDEXEC_PREDICATES_P (GET_CODE (x), GET_CODE (old))
+ && REGNO (XEXP (x, 0)) == REGNO (XEXP (old, 0)))
+ return const1_rtx;
+ if (GET_CODE (x) == GET_CODE (old)
+ && REGNO (XEXP (x, 0)) == REGNO (XEXP (old, 0)))
+ return old;
+ if (! add)
+ return NULL;
+ return gen_rtx_IOR (0, old, x);
+ }
+
+ switch (GET_CODE (old))
+ {
+ case IOR:
+ op0 = ior_reg_cond (XEXP (old, 0), x, 0);
+ op1 = ior_reg_cond (XEXP (old, 1), x, 0);
+ if (op0 != NULL || op1 != NULL)
+ {
+ if (op0 == const0_rtx)
+ return op1 ? op1 : gen_rtx_IOR (0, XEXP (old, 1), x);
+ if (op1 == const0_rtx)
+ return op0 ? op0 : gen_rtx_IOR (0, XEXP (old, 0), x);
+ if (op0 == const1_rtx || op1 == const1_rtx)
+ return const1_rtx;
+ if (op0 == NULL)
+ op0 = gen_rtx_IOR (0, XEXP (old, 0), x);
+ else if (rtx_equal_p (x, op0))
+ /* (x | A) | x ~ (x | A). */
+ return old;
+ if (op1 == NULL)
+ op1 = gen_rtx_IOR (0, XEXP (old, 1), x);
+ else if (rtx_equal_p (x, op1))
+ /* (A | x) | x ~ (A | x). */
+ return old;
+ return gen_rtx_IOR (0, op0, op1);
+ }
+ if (! add)
+ return NULL;
+ return gen_rtx_IOR (0, old, x);
+
+ case AND:
+ op0 = ior_reg_cond (XEXP (old, 0), x, 0);
+ op1 = ior_reg_cond (XEXP (old, 1), x, 0);
+ if (op0 != NULL || op1 != NULL)
+ {
+ if (op0 == const1_rtx)
+ return op1 ? op1 : gen_rtx_IOR (0, XEXP (old, 1), x);
+ if (op1 == const1_rtx)
+ return op0 ? op0 : gen_rtx_IOR (0, XEXP (old, 0), x);
+ if (op0 == const0_rtx || op1 == const0_rtx)
+ return const0_rtx;
+ if (op0 == NULL)
+ op0 = gen_rtx_IOR (0, XEXP (old, 0), x);
+ else if (rtx_equal_p (x, op0))
+ /* (x & A) | x ~ x. */
+ return op0;
+ if (op1 == NULL)
+ op1 = gen_rtx_IOR (0, XEXP (old, 1), x);
+ else if (rtx_equal_p (x, op1))
+ /* (A & x) | x ~ x. */
+ return op1;
+ return gen_rtx_AND (0, op0, op1);
+ }
+ if (! add)
+ return NULL;
+ return gen_rtx_IOR (0, old, x);
+
+ case NOT:
+ op0 = and_reg_cond (XEXP (old, 0), not_reg_cond (x), 0);
+ if (op0 != NULL)
+ return not_reg_cond (op0);
+ if (! add)
+ return NULL;
+ return gen_rtx_IOR (0, old, x);
+
+ default:
+ abort ();
+ }
+}
+
+static rtx
+not_reg_cond (x)
+ rtx x;
+{
+ enum rtx_code x_code;
+
+ if (x == const0_rtx)
+ return const1_rtx;
+ else if (x == const1_rtx)
+ return const0_rtx;
+ x_code = GET_CODE (x);
+ if (x_code == NOT)
+ return XEXP (x, 0);
+ if (GET_RTX_CLASS (x_code) == '<'
+ && GET_CODE (XEXP (x, 0)) == REG)
+ {
+ if (XEXP (x, 1) != const0_rtx)
+ abort ();
+
+ return gen_rtx_fmt_ee (reverse_condition (x_code),
+ VOIDmode, XEXP (x, 0), const0_rtx);
+ }
+ return gen_rtx_NOT (0, x);
+}
+
+static rtx
+and_reg_cond (old, x, add)
+ rtx old, x;
+ int add;
+{
+ rtx op0, op1;
+
+ if (GET_RTX_CLASS (GET_CODE (old)) == '<')
+ {
+ if (GET_RTX_CLASS (GET_CODE (x)) == '<'
+ && GET_CODE (x) == reverse_condition (GET_CODE (old))
+ && REGNO (XEXP (x, 0)) == REGNO (XEXP (old, 0)))
+ return const0_rtx;
+ if (GET_CODE (x) == GET_CODE (old)
+ && REGNO (XEXP (x, 0)) == REGNO (XEXP (old, 0)))
+ return old;
+ if (! add)
+ return NULL;
+ return gen_rtx_AND (0, old, x);
+ }
+
+ switch (GET_CODE (old))
+ {
+ case IOR:
+ op0 = and_reg_cond (XEXP (old, 0), x, 0);
+ op1 = and_reg_cond (XEXP (old, 1), x, 0);
+ if (op0 != NULL || op1 != NULL)
+ {
+ if (op0 == const0_rtx)
+ return op1 ? op1 : gen_rtx_AND (0, XEXP (old, 1), x);
+ if (op1 == const0_rtx)
+ return op0 ? op0 : gen_rtx_AND (0, XEXP (old, 0), x);
+ if (op0 == const1_rtx || op1 == const1_rtx)
+ return const1_rtx;
+ if (op0 == NULL)
+ op0 = gen_rtx_AND (0, XEXP (old, 0), x);
+ else if (rtx_equal_p (x, op0))
+ /* (x | A) & x ~ x. */
+ return op0;
+ if (op1 == NULL)
+ op1 = gen_rtx_AND (0, XEXP (old, 1), x);
+ else if (rtx_equal_p (x, op1))
+ /* (A | x) & x ~ x. */
+ return op1;
+ return gen_rtx_IOR (0, op0, op1);
+ }
+ if (! add)
+ return NULL;
+ return gen_rtx_AND (0, old, x);
+
+ case AND:
+ op0 = and_reg_cond (XEXP (old, 0), x, 0);
+ op1 = and_reg_cond (XEXP (old, 1), x, 0);
+ if (op0 != NULL || op1 != NULL)
+ {
+ if (op0 == const1_rtx)
+ return op1 ? op1 : gen_rtx_AND (0, XEXP (old, 1), x);
+ if (op1 == const1_rtx)
+ return op0 ? op0 : gen_rtx_AND (0, XEXP (old, 0), x);
+ if (op0 == const0_rtx || op1 == const0_rtx)
+ return const0_rtx;
+ if (op0 == NULL)
+ op0 = gen_rtx_AND (0, XEXP (old, 0), x);
+ else if (rtx_equal_p (x, op0))
+ /* (x & A) & x ~ (x & A). */
+ return old;
+ if (op1 == NULL)
+ op1 = gen_rtx_AND (0, XEXP (old, 1), x);
+ else if (rtx_equal_p (x, op1))
+ /* (A & x) & x ~ (A & x). */
+ return old;
+ return gen_rtx_AND (0, op0, op1);
+ }
+ if (! add)
+ return NULL;
+ return gen_rtx_AND (0, old, x);
+
+ case NOT:
+ op0 = ior_reg_cond (XEXP (old, 0), not_reg_cond (x), 0);
+ if (op0 != NULL)
+ return not_reg_cond (op0);
+ if (! add)
+ return NULL;
+ return gen_rtx_AND (0, old, x);
+
+ default:
+ abort ();
+ }
+}
+
+/* Given a condition X, remove references to reg REGNO and return the
+ new condition. The removal will be done so that all conditions
+ involving REGNO are considered to evaluate to false. This function
+ is used when the value of REGNO changes. */
+
+static rtx
+elim_reg_cond (x, regno)
+ rtx x;
+ unsigned int regno;
+{
+ rtx op0, op1;
+
+ if (GET_RTX_CLASS (GET_CODE (x)) == '<')
+ {
+ if (REGNO (XEXP (x, 0)) == regno)
+ return const0_rtx;
+ return x;
+ }
+
+ switch (GET_CODE (x))
+ {
+ case AND:
+ op0 = elim_reg_cond (XEXP (x, 0), regno);
+ op1 = elim_reg_cond (XEXP (x, 1), regno);
+ if (op0 == const0_rtx || op1 == const0_rtx)
+ return const0_rtx;
+ if (op0 == const1_rtx)
+ return op1;
+ if (op1 == const1_rtx)
+ return op0;
+ if (op0 == XEXP (x, 0) && op1 == XEXP (x, 1))
+ return x;
+ return gen_rtx_AND (0, op0, op1);
+
+ case IOR:
+ op0 = elim_reg_cond (XEXP (x, 0), regno);
+ op1 = elim_reg_cond (XEXP (x, 1), regno);
+ if (op0 == const1_rtx || op1 == const1_rtx)
+ return const1_rtx;
+ if (op0 == const0_rtx)
+ return op1;
+ if (op1 == const0_rtx)
+ return op0;
+ if (op0 == XEXP (x, 0) && op1 == XEXP (x, 1))
+ return x;
+ return gen_rtx_IOR (0, op0, op1);
+
+ case NOT:
+ op0 = elim_reg_cond (XEXP (x, 0), regno);
+ if (op0 == const0_rtx)
+ return const1_rtx;
+ if (op0 == const1_rtx)
+ return const0_rtx;
+ if (op0 != XEXP (x, 0))
+ return not_reg_cond (op0);
+ return x;
+
+ default:
+ abort ();
+ }
+}
+#endif /* HAVE_conditional_execution */
+
#ifdef AUTO_INC_DEC
+/* Try to substitute the auto-inc expression INC as the address inside
+ MEM which occurs in INSN. Currently, the address of MEM is an expression
+ involving INCR_REG, and INCR is the next use of INCR_REG; it is an insn
+ that has a single set whose source is a PLUS of INCR_REG and something
+ else. */
+
+static void
+attempt_auto_inc (pbi, inc, insn, mem, incr, incr_reg)
+ struct propagate_block_info *pbi;
+ rtx inc, insn, mem, incr, incr_reg;
+{
+ int regno = REGNO (incr_reg);
+ rtx set = single_set (incr);
+ rtx q = SET_DEST (set);
+ rtx y = SET_SRC (set);
+ int opnum = XEXP (y, 0) == incr_reg ? 0 : 1;
+
+ /* Make sure this reg appears only once in this insn. */
+ if (count_occurrences (PATTERN (insn), incr_reg, 1) != 1)
+ return;
+
+ if (dead_or_set_p (incr, incr_reg)
+ /* Mustn't autoinc an eliminable register. */
+ && (regno >= FIRST_PSEUDO_REGISTER
+ || ! TEST_HARD_REG_BIT (elim_reg_set, regno)))
+ {
+ /* This is the simple case. Try to make the auto-inc. If
+ we can't, we are done. Otherwise, we will do any
+ needed updates below. */
+ if (! validate_change (insn, &XEXP (mem, 0), inc, 0))
+ return;
+ }
+ else if (GET_CODE (q) == REG
+ /* PREV_INSN used here to check the semi-open interval
+ [insn,incr). */
+ && ! reg_used_between_p (q, PREV_INSN (insn), incr)
+ /* We must also check for sets of q as q may be
+ a call clobbered hard register and there may
+ be a call between PREV_INSN (insn) and incr. */
+ && ! reg_set_between_p (q, PREV_INSN (insn), incr))
+ {
+ /* We have *p followed sometime later by q = p+size.
+ Both p and q must be live afterward,
+ and q is not used between INSN and its assignment.
+ Change it to q = p, ...*q..., q = q+size.
+ Then fall into the usual case. */
+ rtx insns, temp;
+
+ start_sequence ();
+ emit_move_insn (q, incr_reg);
+ insns = get_insns ();
+ end_sequence ();
+
+ /* If we can't make the auto-inc, or can't make the
+ replacement into Y, exit. There's no point in making
+ the change below if we can't do the auto-inc and doing
+ so is not correct in the pre-inc case. */
+
+ XEXP (inc, 0) = q;
+ validate_change (insn, &XEXP (mem, 0), inc, 1);
+ validate_change (incr, &XEXP (y, opnum), q, 1);
+ if (! apply_change_group ())
+ return;
+
+ /* We now know we'll be doing this change, so emit the
+ new insn(s) and do the updates. */
+ emit_insns_before (insns, insn);
+
+ if (pbi->bb->head == insn)
+ pbi->bb->head = insns;
+
+ /* INCR will become a NOTE and INSN won't contain a
+ use of INCR_REG. If a use of INCR_REG was just placed in
+ the insn before INSN, make that the next use.
+ Otherwise, invalidate it. */
+ if (GET_CODE (PREV_INSN (insn)) == INSN
+ && GET_CODE (PATTERN (PREV_INSN (insn))) == SET
+ && SET_SRC (PATTERN (PREV_INSN (insn))) == incr_reg)
+ pbi->reg_next_use[regno] = PREV_INSN (insn);
+ else
+ pbi->reg_next_use[regno] = 0;
+
+ incr_reg = q;
+ regno = REGNO (q);
+
+ /* REGNO is now used in INCR which is below INSN, but
+ it previously wasn't live here. If we don't mark
+ it as live, we'll put a REG_DEAD note for it
+ on this insn, which is incorrect. */
+ SET_REGNO_REG_SET (pbi->reg_live, regno);
+
+ /* If there are any calls between INSN and INCR, show
+ that REGNO now crosses them. */
+ for (temp = insn; temp != incr; temp = NEXT_INSN (temp))
+ if (GET_CODE (temp) == CALL_INSN)
+ REG_N_CALLS_CROSSED (regno)++;
+
+ /* Invalidate alias info for Q since we just changed its value. */
+ clear_reg_alias_info (q);
+ }
+ else
+ return;
+
+ /* If we haven't returned, it means we were able to make the
+ auto-inc, so update the status. First, record that this insn
+ has an implicit side effect. */
+
+ REG_NOTES (insn) = alloc_EXPR_LIST (REG_INC, incr_reg, REG_NOTES (insn));
+
+ /* Modify the old increment-insn to simply copy
+ the already-incremented value of our register. */
+ if (! validate_change (incr, &SET_SRC (set), incr_reg, 0))
+ abort ();
+
+ /* If that makes it a no-op (copying the register into itself) delete
+ it so it won't appear to be a "use" and a "set" of this
+ register. */
+ if (REGNO (SET_DEST (set)) == REGNO (incr_reg))
+ {
+ /* If the original source was dead, it's dead now. */
+ rtx note;
+
+ while ((note = find_reg_note (incr, REG_DEAD, NULL_RTX)) != NULL_RTX)
+ {
+ remove_note (incr, note);
+ if (XEXP (note, 0) != incr_reg)
+ CLEAR_REGNO_REG_SET (pbi->reg_live, REGNO (XEXP (note, 0)));
+ }
+
+ PUT_CODE (incr, NOTE);
+ NOTE_LINE_NUMBER (incr) = NOTE_INSN_DELETED;
+ NOTE_SOURCE_FILE (incr) = 0;
+ }
+
+ if (regno >= FIRST_PSEUDO_REGISTER)
+ {
+ /* Count an extra reference to the reg. When a reg is
+ incremented, spilling it is worse, so we want to make
+ that less likely. */
+ REG_FREQ (regno) += REG_FREQ_FROM_BB (pbi->bb);
+
+ /* Count the increment as a setting of the register,
+ even though it isn't a SET in rtl. */
+ REG_N_SETS (regno)++;
+ }
+}
+
/* X is a MEM found in INSN. See if we can convert it into an auto-increment
reference. */
static void
-find_auto_inc (needed, x, insn)
- regset needed;
+find_auto_inc (pbi, x, insn)
+ struct propagate_block_info *pbi;
rtx x;
rtx insn;
{
rtx addr = XEXP (x, 0);
HOST_WIDE_INT offset = 0;
- rtx set;
+ rtx set, y, incr, inc_val;
+ int regno;
+ int size = GET_MODE_SIZE (GET_MODE (x));
+
+ if (GET_CODE (insn) == JUMP_INSN)
+ return;
/* Here we detect use of an index register which might be good for
postincrement, postdecrement, preincrement, or predecrement. */
@@ -3509,187 +3362,271 @@ find_auto_inc (needed, x, insn)
if (GET_CODE (addr) == PLUS && GET_CODE (XEXP (addr, 1)) == CONST_INT)
offset = INTVAL (XEXP (addr, 1)), addr = XEXP (addr, 0);
- if (GET_CODE (addr) == REG)
+ if (GET_CODE (addr) != REG)
+ return;
+
+ regno = REGNO (addr);
+
+ /* Is the next use an increment that might make auto-increment? */
+ incr = pbi->reg_next_use[regno];
+ if (incr == 0 || BLOCK_NUM (incr) != BLOCK_NUM (insn))
+ return;
+ set = single_set (incr);
+ if (set == 0 || GET_CODE (set) != SET)
+ return;
+ y = SET_SRC (set);
+
+ if (GET_CODE (y) != PLUS)
+ return;
+
+ if (REG_P (XEXP (y, 0)) && REGNO (XEXP (y, 0)) == REGNO (addr))
+ inc_val = XEXP (y, 1);
+ else if (REG_P (XEXP (y, 1)) && REGNO (XEXP (y, 1)) == REGNO (addr))
+ inc_val = XEXP (y, 0);
+ else
+ return;
+
+ if (GET_CODE (inc_val) == CONST_INT)
{
- register rtx y;
- register int size = GET_MODE_SIZE (GET_MODE (x));
- rtx use;
- rtx incr;
- int regno = REGNO (addr);
-
- /* Is the next use an increment that might make auto-increment? */
- if ((incr = reg_next_use[regno]) != 0
- && (set = single_set (incr)) != 0
- && GET_CODE (set) == SET
- && BLOCK_NUM (incr) == BLOCK_NUM (insn)
- /* Can't add side effects to jumps; if reg is spilled and
- reloaded, there's no way to store back the altered value. */
- && GET_CODE (insn) != JUMP_INSN
- && (y = SET_SRC (set), GET_CODE (y) == PLUS)
- && XEXP (y, 0) == addr
- && GET_CODE (XEXP (y, 1)) == CONST_INT
- && ((HAVE_POST_INCREMENT
- && (INTVAL (XEXP (y, 1)) == size && offset == 0))
- || (HAVE_POST_DECREMENT
- && (INTVAL (XEXP (y, 1)) == - size && offset == 0))
- || (HAVE_PRE_INCREMENT
- && (INTVAL (XEXP (y, 1)) == size && offset == size))
- || (HAVE_PRE_DECREMENT
- && (INTVAL (XEXP (y, 1)) == - size && offset == - size)))
- /* Make sure this reg appears only once in this insn. */
- && (use = find_use_as_address (PATTERN (insn), addr, offset),
- use != 0 && use != (rtx) 1))
+ if (HAVE_POST_INCREMENT
+ && (INTVAL (inc_val) == size && offset == 0))
+ attempt_auto_inc (pbi, gen_rtx_POST_INC (Pmode, addr), insn, x,
+ incr, addr);
+ else if (HAVE_POST_DECREMENT
+ && (INTVAL (inc_val) == -size && offset == 0))
+ attempt_auto_inc (pbi, gen_rtx_POST_DEC (Pmode, addr), insn, x,
+ incr, addr);
+ else if (HAVE_PRE_INCREMENT
+ && (INTVAL (inc_val) == size && offset == size))
+ attempt_auto_inc (pbi, gen_rtx_PRE_INC (Pmode, addr), insn, x,
+ incr, addr);
+ else if (HAVE_PRE_DECREMENT
+ && (INTVAL (inc_val) == -size && offset == -size))
+ attempt_auto_inc (pbi, gen_rtx_PRE_DEC (Pmode, addr), insn, x,
+ incr, addr);
+ else if (HAVE_POST_MODIFY_DISP && offset == 0)
+ attempt_auto_inc (pbi, gen_rtx_POST_MODIFY (Pmode, addr,
+ gen_rtx_PLUS (Pmode,
+ addr,
+ inc_val)),
+ insn, x, incr, addr);
+ }
+ else if (GET_CODE (inc_val) == REG
+ && ! reg_set_between_p (inc_val, PREV_INSN (insn),
+ NEXT_INSN (incr)))
+
+ {
+ if (HAVE_POST_MODIFY_REG && offset == 0)
+ attempt_auto_inc (pbi, gen_rtx_POST_MODIFY (Pmode, addr,
+ gen_rtx_PLUS (Pmode,
+ addr,
+ inc_val)),
+ insn, x, incr, addr);
+ }
+}
+
+#endif /* AUTO_INC_DEC */
+
+static void
+mark_used_reg (pbi, reg, cond, insn)
+ struct propagate_block_info *pbi;
+ rtx reg;
+ rtx cond ATTRIBUTE_UNUSED;
+ rtx insn;
+{
+ unsigned int regno_first, regno_last, i;
+ int some_was_live, some_was_dead, some_not_set;
+
+ regno_last = regno_first = REGNO (reg);
+ if (regno_first < FIRST_PSEUDO_REGISTER)
+ regno_last += HARD_REGNO_NREGS (regno_first, GET_MODE (reg)) - 1;
+
+ /* Find out if any of this register is live after this instruction. */
+ some_was_live = some_was_dead = 0;
+ for (i = regno_first; i <= regno_last; ++i)
+ {
+ int needed_regno = REGNO_REG_SET_P (pbi->reg_live, i);
+ some_was_live |= needed_regno;
+ some_was_dead |= ! needed_regno;
+ }
+
+ /* Find out if any of the register was set this insn. */
+ some_not_set = 0;
+ for (i = regno_first; i <= regno_last; ++i)
+ some_not_set |= ! REGNO_REG_SET_P (pbi->new_set, i);
+
+ if (pbi->flags & (PROP_LOG_LINKS | PROP_AUTOINC))
+ {
+ /* Record where each reg is used, so when the reg is set we know
+ the next insn that uses it. */
+ pbi->reg_next_use[regno_first] = insn;
+ }
+
+ if (pbi->flags & PROP_REG_INFO)
+ {
+ if (regno_first < FIRST_PSEUDO_REGISTER)
{
- rtx q = SET_DEST (set);
- enum rtx_code inc_code = (INTVAL (XEXP (y, 1)) == size
- ? (offset ? PRE_INC : POST_INC)
- : (offset ? PRE_DEC : POST_DEC));
+ /* If this is a register we are going to try to eliminate,
+ don't mark it live here. If we are successful in
+ eliminating it, it need not be live unless it is used for
+ pseudos, in which case it will have been set live when it
+ was allocated to the pseudos. If the register will not
+ be eliminated, reload will set it live at that point.
+
+ Otherwise, record that this function uses this register. */
+ /* ??? The PPC backend tries to "eliminate" on the pic
+ register to itself. This should be fixed. In the mean
+ time, hack around it. */
+
+ if (! (TEST_HARD_REG_BIT (elim_reg_set, regno_first)
+ && (regno_first == FRAME_POINTER_REGNUM
+ || regno_first == ARG_POINTER_REGNUM)))
+ for (i = regno_first; i <= regno_last; ++i)
+ regs_ever_live[i] = 1;
+ }
+ else
+ {
+ /* Keep track of which basic block each reg appears in. */
- if (dead_or_set_p (incr, addr))
- {
- /* This is the simple case. Try to make the auto-inc. If
- we can't, we are done. Otherwise, we will do any
- needed updates below. */
- if (! validate_change (insn, &XEXP (x, 0),
- gen_rtx_fmt_e (inc_code, Pmode, addr),
- 0))
- return;
- }
- else if (GET_CODE (q) == REG
- /* PREV_INSN used here to check the semi-open interval
- [insn,incr). */
- && ! reg_used_between_p (q, PREV_INSN (insn), incr)
- /* We must also check for sets of q as q may be
- a call clobbered hard register and there may
- be a call between PREV_INSN (insn) and incr. */
- && ! reg_set_between_p (q, PREV_INSN (insn), incr))
- {
- /* We have *p followed sometime later by q = p+size.
- Both p and q must be live afterward,
- and q is not used between INSN and its assignment.
- Change it to q = p, ...*q..., q = q+size.
- Then fall into the usual case. */
- rtx insns, temp;
- basic_block bb;
-
- start_sequence ();
- emit_move_insn (q, addr);
- insns = get_insns ();
- end_sequence ();
-
- bb = BLOCK_FOR_INSN (insn);
- for (temp = insns; temp; temp = NEXT_INSN (temp))
- set_block_for_insn (temp, bb);
-
- /* If we can't make the auto-inc, or can't make the
- replacement into Y, exit. There's no point in making
- the change below if we can't do the auto-inc and doing
- so is not correct in the pre-inc case. */
-
- validate_change (insn, &XEXP (x, 0),
- gen_rtx_fmt_e (inc_code, Pmode, q),
- 1);
- validate_change (incr, &XEXP (y, 0), q, 1);
- if (! apply_change_group ())
- return;
-
- /* We now know we'll be doing this change, so emit the
- new insn(s) and do the updates. */
- emit_insns_before (insns, insn);
-
- if (BLOCK_FOR_INSN (insn)->head == insn)
- BLOCK_FOR_INSN (insn)->head = insns;
-
- /* INCR will become a NOTE and INSN won't contain a
- use of ADDR. If a use of ADDR was just placed in
- the insn before INSN, make that the next use.
- Otherwise, invalidate it. */
- if (GET_CODE (PREV_INSN (insn)) == INSN
- && GET_CODE (PATTERN (PREV_INSN (insn))) == SET
- && SET_SRC (PATTERN (PREV_INSN (insn))) == addr)
- reg_next_use[regno] = PREV_INSN (insn);
- else
- reg_next_use[regno] = 0;
-
- addr = q;
- regno = REGNO (q);
-
- /* REGNO is now used in INCR which is below INSN, but
- it previously wasn't live here. If we don't mark
- it as needed, we'll put a REG_DEAD note for it
- on this insn, which is incorrect. */
- SET_REGNO_REG_SET (needed, regno);
-
- /* If there are any calls between INSN and INCR, show
- that REGNO now crosses them. */
- for (temp = insn; temp != incr; temp = NEXT_INSN (temp))
- if (GET_CODE (temp) == CALL_INSN)
- REG_N_CALLS_CROSSED (regno)++;
- }
- else
- return;
+ int blocknum = pbi->bb->index;
+ if (REG_BASIC_BLOCK (regno_first) == REG_BLOCK_UNKNOWN)
+ REG_BASIC_BLOCK (regno_first) = blocknum;
+ else if (REG_BASIC_BLOCK (regno_first) != blocknum)
+ REG_BASIC_BLOCK (regno_first) = REG_BLOCK_GLOBAL;
- /* If we haven't returned, it means we were able to make the
- auto-inc, so update the status. First, record that this insn
- has an implicit side effect. */
+ /* Count (weighted) number of uses of each reg. */
+ REG_FREQ (regno_first) += REG_FREQ_FROM_BB (pbi->bb);
+ REG_N_REFS (regno_first)++;
+ }
+ }
- REG_NOTES (insn)
- = gen_rtx_EXPR_LIST (REG_INC, addr, REG_NOTES (insn));
+ /* Record and count the insns in which a reg dies. If it is used in
+ this insn and was dead below the insn then it dies in this insn.
+ If it was set in this insn, we do not make a REG_DEAD note;
+ likewise if we already made such a note. */
+ if ((pbi->flags & (PROP_DEATH_NOTES | PROP_REG_INFO))
+ && some_was_dead
+ && some_not_set)
+ {
+ /* Check for the case where the register dying partially
+ overlaps the register set by this insn. */
+ if (regno_first != regno_last)
+ for (i = regno_first; i <= regno_last; ++i)
+ some_was_live |= REGNO_REG_SET_P (pbi->new_set, i);
+
+ /* If none of the words in X is needed, make a REG_DEAD note.
+ Otherwise, we must make partial REG_DEAD notes. */
+ if (! some_was_live)
+ {
+ if ((pbi->flags & PROP_DEATH_NOTES)
+ && ! find_regno_note (insn, REG_DEAD, regno_first))
+ REG_NOTES (insn)
+ = alloc_EXPR_LIST (REG_DEAD, reg, REG_NOTES (insn));
- /* Modify the old increment-insn to simply copy
- the already-incremented value of our register. */
- if (! validate_change (incr, &SET_SRC (set), addr, 0))
- abort ();
+ if (pbi->flags & PROP_REG_INFO)
+ REG_N_DEATHS (regno_first)++;
+ }
+ else
+ {
+ /* Don't make a REG_DEAD note for a part of a register
+ that is set in the insn. */
+ for (i = regno_first; i <= regno_last; ++i)
+ if (! REGNO_REG_SET_P (pbi->reg_live, i)
+ && ! dead_or_set_regno_p (insn, i))
+ REG_NOTES (insn)
+ = alloc_EXPR_LIST (REG_DEAD,
+ gen_rtx_REG (reg_raw_mode[i], i),
+ REG_NOTES (insn));
+ }
+ }
+
+ /* Mark the register as being live. */
+ for (i = regno_first; i <= regno_last; ++i)
+ {
+ SET_REGNO_REG_SET (pbi->reg_live, i);
- /* If that makes it a no-op (copying the register into itself) delete
- it so it won't appear to be a "use" and a "set" of this
- register. */
- if (SET_DEST (set) == addr)
+#ifdef HAVE_conditional_execution
+ /* If this is a conditional use, record that fact. If it is later
+ conditionally set, we'll know to kill the register. */
+ if (cond != NULL_RTX)
+ {
+ splay_tree_node node;
+ struct reg_cond_life_info *rcli;
+ rtx ncond;
+
+ if (some_was_live)
{
- PUT_CODE (incr, NOTE);
- NOTE_LINE_NUMBER (incr) = NOTE_INSN_DELETED;
- NOTE_SOURCE_FILE (incr) = 0;
+ node = splay_tree_lookup (pbi->reg_cond_dead, i);
+ if (node == NULL)
+ {
+ /* The register was unconditionally live previously.
+ No need to do anything. */
+ }
+ else
+ {
+ /* The register was conditionally live previously.
+ Subtract the new life cond from the old death cond. */
+ rcli = (struct reg_cond_life_info *) node->value;
+ ncond = rcli->condition;
+ ncond = and_reg_cond (ncond, not_reg_cond (cond), 1);
+
+ /* If the register is now unconditionally live,
+ remove the entry in the splay_tree. */
+ if (ncond == const0_rtx)
+ splay_tree_remove (pbi->reg_cond_dead, i);
+ else
+ {
+ rcli->condition = ncond;
+ SET_REGNO_REG_SET (pbi->reg_cond_reg,
+ REGNO (XEXP (cond, 0)));
+ }
+ }
}
-
- if (regno >= FIRST_PSEUDO_REGISTER)
+ else
{
- /* Count an extra reference to the reg. When a reg is
- incremented, spilling it is worse, so we want to make
- that less likely. */
- REG_N_REFS (regno) += loop_depth;
-
- /* Count the increment as a setting of the register,
- even though it isn't a SET in rtl. */
- REG_N_SETS (regno)++;
+ /* The register was not previously live at all. Record
+ the condition under which it is still dead. */
+ rcli = (struct reg_cond_life_info *) xmalloc (sizeof (*rcli));
+ rcli->condition = not_reg_cond (cond);
+ rcli->stores = const0_rtx;
+ rcli->orig_condition = const0_rtx;
+ splay_tree_insert (pbi->reg_cond_dead, i,
+ (splay_tree_value) rcli);
+
+ SET_REGNO_REG_SET (pbi->reg_cond_reg, REGNO (XEXP (cond, 0)));
}
}
+ else if (some_was_live)
+ {
+ /* The register may have been conditionally live previously, but
+ is now unconditionally live. Remove it from the conditionally
+ dead list, so that a conditional set won't cause us to think
+ it dead. */
+ splay_tree_remove (pbi->reg_cond_dead, i);
+ }
+#endif
}
}
-#endif /* AUTO_INC_DEC */
-
-/* Scan expression X and store a 1-bit in LIVE for each reg it uses.
- This is done assuming the registers needed from X
- are those that have 1-bits in NEEDED.
- On the final pass, FINAL is 1. This means try for autoincrement
- and count the uses and deaths of each pseudo-reg.
+/* Scan expression X and store a 1-bit in NEW_LIVE for each reg it uses.
+ This is done assuming the registers needed from X are those that
+ have 1-bits in PBI->REG_LIVE.
- INSN is the containing instruction. If INSN is dead, this function is not
- called. */
+ INSN is the containing instruction. If INSN is dead, this function
+ is not called. */
static void
-mark_used_regs (needed, live, x, final, insn)
- regset needed;
- regset live;
- rtx x;
- int final;
- rtx insn;
+mark_used_regs (pbi, x, cond, insn)
+ struct propagate_block_info *pbi;
+ rtx x, cond, insn;
{
- register RTX_CODE code;
- register int regno;
- int i;
+ RTX_CODE code;
+ int regno;
+ int flags = pbi->flags;
retry:
+ if (!x)
+ return;
code = GET_CODE (x);
switch (code)
{
@@ -3705,7 +3642,7 @@ mark_used_regs (needed, live, x, final, insn)
#ifdef HAVE_cc0
case CC0:
- cc0_live = 1;
+ pbi->cc0_live = 1;
return;
#endif
@@ -3713,219 +3650,81 @@ mark_used_regs (needed, live, x, final, insn)
/* If we are clobbering a MEM, mark any registers inside the address
as being used. */
if (GET_CODE (XEXP (x, 0)) == MEM)
- mark_used_regs (needed, live, XEXP (XEXP (x, 0), 0), final, insn);
+ mark_used_regs (pbi, XEXP (XEXP (x, 0), 0), cond, insn);
return;
case MEM:
- /* Invalidate the data for the last MEM stored, but only if MEM is
- something that can be stored into. */
- if (GET_CODE (XEXP (x, 0)) == SYMBOL_REF
- && CONSTANT_POOL_ADDRESS_P (XEXP (x, 0)))
- ; /* needn't clear the memory set list */
- else
+ /* Don't bother watching stores to mems if this is not the
+ final pass. We'll not be deleting dead stores this round. */
+ if (optimize && (flags & PROP_SCAN_DEAD_CODE))
{
- rtx temp = mem_set_list;
- rtx prev = NULL_RTX;
-
- while (temp)
+ /* Invalidate the data for the last MEM stored, but only if MEM is
+ something that can be stored into. */
+ if (GET_CODE (XEXP (x, 0)) == SYMBOL_REF
+ && CONSTANT_POOL_ADDRESS_P (XEXP (x, 0)))
+ /* Needn't clear the memory set list. */
+ ;
+ else
{
- if (anti_dependence (XEXP (temp, 0), x))
+ rtx temp = pbi->mem_set_list;
+ rtx prev = NULL_RTX;
+ rtx next;
+
+ while (temp)
{
- /* Splice temp out of the list. */
- if (prev)
- XEXP (prev, 1) = XEXP (temp, 1);
+ next = XEXP (temp, 1);
+ if (anti_dependence (XEXP (temp, 0), x))
+ {
+ /* Splice temp out of the list. */
+ if (prev)
+ XEXP (prev, 1) = next;
+ else
+ pbi->mem_set_list = next;
+ free_EXPR_LIST_node (temp);
+ pbi->mem_set_list_len--;
+ }
else
- mem_set_list = XEXP (temp, 1);
+ prev = temp;
+ temp = next;
}
- else
- prev = temp;
- temp = XEXP (temp, 1);
}
- }
- /* If the memory reference had embedded side effects (autoincrement
- address modes. Then we may need to kill some entries on the
- memory set list. */
- if (insn)
- invalidate_mems_from_autoinc (insn);
+ /* If the memory reference had embedded side effects (autoincrement
+ address modes. Then we may need to kill some entries on the
+ memory set list. */
+ if (insn)
+ invalidate_mems_from_autoinc (pbi, insn);
+ }
#ifdef AUTO_INC_DEC
- if (final)
- find_auto_inc (needed, x, insn);
+ if (flags & PROP_AUTOINC)
+ find_auto_inc (pbi, x, insn);
#endif
break;
case SUBREG:
+#ifdef CLASS_CANNOT_CHANGE_MODE
if (GET_CODE (SUBREG_REG (x)) == REG
&& REGNO (SUBREG_REG (x)) >= FIRST_PSEUDO_REGISTER
- && (GET_MODE_SIZE (GET_MODE (x))
- != GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))))
- REG_CHANGES_SIZE (REGNO (SUBREG_REG (x))) = 1;
+ && CLASS_CANNOT_CHANGE_MODE_P (GET_MODE (x),
+ GET_MODE (SUBREG_REG (x))))
+ REG_CHANGES_MODE (REGNO (SUBREG_REG (x))) = 1;
+#endif
/* While we're here, optimize this case. */
x = SUBREG_REG (x);
-
- /* In case the SUBREG is not of a register, don't optimize */
if (GET_CODE (x) != REG)
- {
- mark_used_regs (needed, live, x, final, insn);
- return;
- }
-
- /* ... fall through ... */
+ goto retry;
+ /* Fall through. */
case REG:
- /* See a register other than being set
- => mark it as needed. */
-
- regno = REGNO (x);
- {
- int some_needed = REGNO_REG_SET_P (needed, regno);
- int some_not_needed = ! some_needed;
-
- SET_REGNO_REG_SET (live, regno);
-
- /* A hard reg in a wide mode may really be multiple registers.
- If so, mark all of them just like the first. */
- if (regno < FIRST_PSEUDO_REGISTER)
- {
- int n;
-
- /* For stack ptr or fixed arg pointer,
- nothing below can be necessary, so waste no more time. */
- if (regno == STACK_POINTER_REGNUM
-#if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
- || (regno == HARD_FRAME_POINTER_REGNUM
- && (! reload_completed || frame_pointer_needed))
-#endif
-#if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
- || (regno == ARG_POINTER_REGNUM && fixed_regs[regno])
-#endif
- || (regno == FRAME_POINTER_REGNUM
- && (! reload_completed || frame_pointer_needed)))
- {
- /* If this is a register we are going to try to eliminate,
- don't mark it live here. If we are successful in
- eliminating it, it need not be live unless it is used for
- pseudos, in which case it will have been set live when
- it was allocated to the pseudos. If the register will not
- be eliminated, reload will set it live at that point. */
-
- if (! TEST_HARD_REG_BIT (elim_reg_set, regno))
- regs_ever_live[regno] = 1;
- return;
- }
- /* No death notes for global register variables;
- their values are live after this function exits. */
- if (global_regs[regno])
- {
- if (final)
- reg_next_use[regno] = insn;
- return;
- }
-
- n = HARD_REGNO_NREGS (regno, GET_MODE (x));
- while (--n > 0)
- {
- int regno_n = regno + n;
- int needed_regno = REGNO_REG_SET_P (needed, regno_n);
-
- SET_REGNO_REG_SET (live, regno_n);
- some_needed |= needed_regno;
- some_not_needed |= ! needed_regno;
- }
- }
- if (final)
- {
- /* Record where each reg is used, so when the reg
- is set we know the next insn that uses it. */
-
- reg_next_use[regno] = insn;
-
- if (regno < FIRST_PSEUDO_REGISTER)
- {
- /* If a hard reg is being used,
- record that this function does use it. */
-
- i = HARD_REGNO_NREGS (regno, GET_MODE (x));
- if (i == 0)
- i = 1;
- do
- regs_ever_live[regno + --i] = 1;
- while (i > 0);
- }
- else
- {
- /* Keep track of which basic block each reg appears in. */
-
- register int blocknum = BLOCK_NUM (insn);
-
- if (REG_BASIC_BLOCK (regno) == REG_BLOCK_UNKNOWN)
- REG_BASIC_BLOCK (regno) = blocknum;
- else if (REG_BASIC_BLOCK (regno) != blocknum)
- REG_BASIC_BLOCK (regno) = REG_BLOCK_GLOBAL;
-
- /* Count (weighted) number of uses of each reg. */
-
- REG_N_REFS (regno) += loop_depth;
- }
-
- /* Record and count the insns in which a reg dies.
- If it is used in this insn and was dead below the insn
- then it dies in this insn. If it was set in this insn,
- we do not make a REG_DEAD note; likewise if we already
- made such a note. */
-
- if (some_not_needed
- && ! dead_or_set_p (insn, x)
-#if 0
- && (regno >= FIRST_PSEUDO_REGISTER || ! fixed_regs[regno])
-#endif
- )
- {
- /* Check for the case where the register dying partially
- overlaps the register set by this insn. */
- if (regno < FIRST_PSEUDO_REGISTER
- && HARD_REGNO_NREGS (regno, GET_MODE (x)) > 1)
- {
- int n = HARD_REGNO_NREGS (regno, GET_MODE (x));
- while (--n >= 0)
- some_needed |= dead_or_set_regno_p (insn, regno + n);
- }
-
- /* If none of the words in X is needed, make a REG_DEAD
- note. Otherwise, we must make partial REG_DEAD notes. */
- if (! some_needed)
- {
- REG_NOTES (insn)
- = gen_rtx_EXPR_LIST (REG_DEAD, x, REG_NOTES (insn));
- REG_N_DEATHS (regno)++;
- }
- else
- {
- int i;
-
- /* Don't make a REG_DEAD note for a part of a register
- that is set in the insn. */
-
- for (i = HARD_REGNO_NREGS (regno, GET_MODE (x)) - 1;
- i >= 0; i--)
- if (!REGNO_REG_SET_P (needed, regno + i)
- && ! dead_or_set_regno_p (insn, regno + i))
- REG_NOTES (insn)
- = gen_rtx_EXPR_LIST (REG_DEAD,
- gen_rtx_REG (reg_raw_mode[regno + i],
- regno + i),
- REG_NOTES (insn));
- }
- }
- }
- }
+ /* See a register other than being set => mark it as needed. */
+ mark_used_reg (pbi, x, cond, insn);
return;
case SET:
{
- register rtx testreg = SET_DEST (x);
+ rtx testreg = SET_DEST (x);
int mark_dest = 0;
/* If storing into MEM, don't show it as being used. But do
@@ -3933,14 +3732,14 @@ mark_used_regs (needed, live, x, final, insn)
if (GET_CODE (testreg) == MEM)
{
#ifdef AUTO_INC_DEC
- if (final)
- find_auto_inc (needed, testreg, insn);
+ if (flags & PROP_AUTOINC)
+ find_auto_inc (pbi, testreg, insn);
#endif
- mark_used_regs (needed, live, XEXP (testreg, 0), final, insn);
- mark_used_regs (needed, live, SET_SRC (x), final, insn);
+ mark_used_regs (pbi, XEXP (testreg, 0), cond, insn);
+ mark_used_regs (pbi, SET_SRC (x), cond, insn);
return;
}
-
+
/* Storing in STRICT_LOW_PART is like storing in a reg
in that this SET might be dead, so ignore it in TESTREG.
but in some other ways it is like using the reg.
@@ -3953,18 +3752,23 @@ mark_used_regs (needed, live, x, final, insn)
|| GET_CODE (testreg) == SIGN_EXTRACT
|| GET_CODE (testreg) == SUBREG)
{
+#ifdef CLASS_CANNOT_CHANGE_MODE
if (GET_CODE (testreg) == SUBREG
&& GET_CODE (SUBREG_REG (testreg)) == REG
&& REGNO (SUBREG_REG (testreg)) >= FIRST_PSEUDO_REGISTER
- && (GET_MODE_SIZE (GET_MODE (testreg))
- != GET_MODE_SIZE (GET_MODE (SUBREG_REG (testreg)))))
- REG_CHANGES_SIZE (REGNO (SUBREG_REG (testreg))) = 1;
+ && CLASS_CANNOT_CHANGE_MODE_P (GET_MODE (SUBREG_REG (testreg)),
+ GET_MODE (testreg)))
+ REG_CHANGES_MODE (REGNO (SUBREG_REG (testreg))) = 1;
+#endif
/* Modifying a single register in an alternate mode
does not use any of the old value. But these other
ways of storing in a register do use the old value. */
if (GET_CODE (testreg) == SUBREG
- && !(REG_SIZE (SUBREG_REG (testreg)) > REG_SIZE (testreg)))
+ && !((REG_BYTES (SUBREG_REG (testreg))
+ + UNITS_PER_WORD - 1) / UNITS_PER_WORD
+ > (REG_BYTES (testreg)
+ + UNITS_PER_WORD - 1) / UNITS_PER_WORD))
;
else
mark_dest = 1;
@@ -3972,14 +3776,15 @@ mark_used_regs (needed, live, x, final, insn)
testreg = XEXP (testreg, 0);
}
- /* If this is a store into a register,
+ /* If this is a store into a register or group of registers,
recursively scan the value being stored. */
if ((GET_CODE (testreg) == PARALLEL
&& GET_MODE (testreg) == BLKmode)
|| (GET_CODE (testreg) == REG
- && (regno = REGNO (testreg), ! (regno == FRAME_POINTER_REGNUM
- && (! reload_completed || frame_pointer_needed)))
+ && (regno = REGNO (testreg),
+ ! (regno == FRAME_POINTER_REGNUM
+ && (! reload_completed || frame_pointer_needed)))
#if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
&& ! (regno == HARD_FRAME_POINTER_REGNUM
&& (! reload_completed || frame_pointer_needed))
@@ -3988,37 +3793,15 @@ mark_used_regs (needed, live, x, final, insn)
&& ! (regno == ARG_POINTER_REGNUM && fixed_regs[regno])
#endif
))
- /* We used to exclude global_regs here, but that seems wrong.
- Storing in them is like storing in mem. */
{
- mark_used_regs (needed, live, SET_SRC (x), final, insn);
if (mark_dest)
- mark_used_regs (needed, live, SET_DEST (x), final, insn);
+ mark_used_regs (pbi, SET_DEST (x), cond, insn);
+ mark_used_regs (pbi, SET_SRC (x), cond, insn);
return;
}
}
break;
- case RETURN:
- /* If exiting needs the right stack value, consider this insn as
- using the stack pointer. In any event, consider it as using
- all global registers and all registers used by return. */
- if (! EXIT_IGNORE_STACK
- || (! FRAME_POINTER_REQUIRED
- && ! current_function_calls_alloca
- && flag_omit_frame_pointer)
- || current_function_sp_is_unchanging)
- SET_REGNO_REG_SET (live, STACK_POINTER_REGNUM);
-
- for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
- if (global_regs[i]
-#ifdef EPILOGUE_USES
- || EPILOGUE_USES (i)
-#endif
- )
- SET_REGNO_REG_SET (live, i);
- break;
-
case ASM_OPERANDS:
case UNSPEC_VOLATILE:
case TRAP_IF:
@@ -4030,7 +3813,7 @@ mark_used_regs (needed, live, x, final, insn)
Consider for instance a volatile asm that changes the fpu rounding
mode. An insn should not be moved across this even if it only uses
- pseudo-regs because it might give an incorrectly rounded result.
+ pseudo-regs because it might give an incorrectly rounded result.
?!? Unfortunately, marking all hard registers as live causes massive
problems for the register allocator and marking all pseudos as live
@@ -4039,9 +3822,12 @@ mark_used_regs (needed, live, x, final, insn)
So for now, just clear the memory set list and mark any regs
we can find in ASM_OPERANDS as used. */
if (code != ASM_OPERANDS || MEM_VOLATILE_P (x))
- mem_set_list = NULL_RTX;
+ {
+ free_EXPR_LIST_list (&pbi->mem_set_list);
+ pbi->mem_set_list_len = 0;
+ }
- /* For all ASM_OPERANDS, we must traverse the vector of input operands.
+ /* For all ASM_OPERANDS, we must traverse the vector of input operands.
We can not just fall through here since then we would be confused
by the ASM_INPUT rtx inside ASM_OPERANDS, which do not indicate
traditional asms unlike their normal usage. */
@@ -4050,12 +3836,28 @@ mark_used_regs (needed, live, x, final, insn)
int j;
for (j = 0; j < ASM_OPERANDS_INPUT_LENGTH (x); j++)
- mark_used_regs (needed, live, ASM_OPERANDS_INPUT (x, j),
- final, insn);
+ mark_used_regs (pbi, ASM_OPERANDS_INPUT (x, j), cond, insn);
}
break;
}
+ case COND_EXEC:
+ if (cond != NULL_RTX)
+ abort ();
+
+ mark_used_regs (pbi, COND_EXEC_TEST (x), NULL_RTX, insn);
+
+ cond = COND_EXEC_TEST (x);
+ x = COND_EXEC_CODE (x);
+ goto retry;
+
+ case PHI:
+ /* We _do_not_ want to scan operands of phi nodes. Operands of
+ a phi function are evaluated only when control reaches this
+ block along a particular edge. Therefore, regs that appear
+ as arguments to phi should not be added to the global live at
+ start. */
+ return;
default:
break;
@@ -4064,9 +3866,9 @@ mark_used_regs (needed, live, x, final, insn)
/* Recursively scan the operands of this expression. */
{
- register char *fmt = GET_RTX_FORMAT (code);
- register int i;
-
+ const char * const fmt = GET_RTX_FORMAT (code);
+ int i;
+
for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
{
if (fmt[i] == 'e')
@@ -4077,13 +3879,13 @@ mark_used_regs (needed, live, x, final, insn)
x = XEXP (x, 0);
goto retry;
}
- mark_used_regs (needed, live, XEXP (x, i), final, insn);
+ mark_used_regs (pbi, XEXP (x, i), cond, insn);
}
else if (fmt[i] == 'E')
{
- register int j;
+ int j;
for (j = 0; j < XVECLEN (x, i); j++)
- mark_used_regs (needed, live, XVECEXP (x, i, j), final, insn);
+ mark_used_regs (pbi, XVECEXP (x, i, j), cond, insn);
}
}
}
@@ -4092,38 +3894,42 @@ mark_used_regs (needed, live, x, final, insn)
#ifdef AUTO_INC_DEC
static int
-try_pre_increment_1 (insn)
+try_pre_increment_1 (pbi, insn)
+ struct propagate_block_info *pbi;
rtx insn;
{
/* Find the next use of this reg. If in same basic block,
make it do pre-increment or pre-decrement if appropriate. */
rtx x = single_set (insn);
HOST_WIDE_INT amount = ((GET_CODE (SET_SRC (x)) == PLUS ? 1 : -1)
- * INTVAL (XEXP (SET_SRC (x), 1)));
+ * INTVAL (XEXP (SET_SRC (x), 1)));
int regno = REGNO (SET_DEST (x));
- rtx y = reg_next_use[regno];
+ rtx y = pbi->reg_next_use[regno];
if (y != 0
+ && SET_DEST (x) != stack_pointer_rtx
&& BLOCK_NUM (y) == BLOCK_NUM (insn)
/* Don't do this if the reg dies, or gets set in y; a standard addressing
mode would be better. */
&& ! dead_or_set_p (y, SET_DEST (x))
&& try_pre_increment (y, SET_DEST (x), amount))
{
- /* We have found a suitable auto-increment
- and already changed insn Y to do it.
- So flush this increment-instruction. */
- PUT_CODE (insn, NOTE);
- NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
- NOTE_SOURCE_FILE (insn) = 0;
- /* Count a reference to this reg for the increment
- insn we are deleting. When a reg is incremented.
- spilling it is worse, so we want to make that
- less likely. */
+ /* We have found a suitable auto-increment and already changed
+ insn Y to do it. So flush this increment instruction. */
+ propagate_block_delete_insn (pbi->bb, insn);
+
+ /* Count a reference to this reg for the increment insn we are
+ deleting. When a reg is incremented, spilling it is worse,
+ so we want to make that less likely. */
if (regno >= FIRST_PSEUDO_REGISTER)
{
- REG_N_REFS (regno) += loop_depth;
+ REG_FREQ (regno) += REG_FREQ_FROM_BB (pbi->bb);
REG_N_SETS (regno)++;
}
+
+ /* Flush any remembered memories depending on the value of
+ the incremented register. */
+ invalidate_mems_from_set (pbi, SET_DEST (x));
+
return 1;
}
return 0;
@@ -4140,7 +3946,7 @@ try_pre_increment (insn, reg, amount)
rtx insn, reg;
HOST_WIDE_INT amount;
{
- register rtx use;
+ rtx use;
/* Nonzero if we can try to make a pre-increment or pre-decrement.
For example, addl $4,r1; movl (r1),... can become movl +(r1),... */
@@ -4179,13 +3985,13 @@ try_pre_increment (insn, reg, amount)
use = 0;
if (pre_ok)
use = find_use_as_address (PATTERN (insn), reg, 0);
- if (post_ok && (use == 0 || use == (rtx) 1))
+ if (post_ok && (use == 0 || use == (rtx) (size_t) 1))
{
use = find_use_as_address (PATTERN (insn), reg, -amount);
do_post = 1;
}
- if (use == 0 || use == (rtx) 1)
+ if (use == 0 || use == (rtx) (size_t) 1)
return 0;
if (GET_MODE_SIZE (GET_MODE (use)) != (amount > 0 ? amount : - amount))
@@ -4200,7 +4006,7 @@ try_pre_increment (insn, reg, amount)
return 0;
/* Record that this insn now has an implicit side effect on X. */
- REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_INC, reg, REG_NOTES (insn));
+ REG_NOTES (insn) = alloc_EXPR_LIST (REG_INC, reg, REG_NOTES (insn));
return 1;
}
@@ -4213,19 +4019,19 @@ try_pre_increment (insn, reg, amount)
If such an address does not appear, return 0.
If REG appears more than once, or is used other than in such an address,
- return (rtx)1. */
+ return (rtx) 1. */
rtx
find_use_as_address (x, reg, plusconst)
- register rtx x;
+ rtx x;
rtx reg;
HOST_WIDE_INT plusconst;
{
enum rtx_code code = GET_CODE (x);
- char *fmt = GET_RTX_FORMAT (code);
- register int i;
- register rtx value = 0;
- register rtx tem;
+ const char * const fmt = GET_RTX_FORMAT (code);
+ int i;
+ rtx value = 0;
+ rtx tem;
if (code == MEM && XEXP (x, 0) == reg && plusconst == 0)
return x;
@@ -4241,11 +4047,11 @@ find_use_as_address (x, reg, plusconst)
/* If REG occurs inside a MEM used in a bit-field reference,
that is unacceptable. */
if (find_use_as_address (XEXP (x, 0), reg, 0) != 0)
- return (rtx) (HOST_WIDE_INT) 1;
+ return (rtx) (size_t) 1;
}
if (x == reg)
- return (rtx) (HOST_WIDE_INT) 1;
+ return (rtx) (size_t) 1;
for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
{
@@ -4255,18 +4061,18 @@ find_use_as_address (x, reg, plusconst)
if (value == 0)
value = tem;
else if (tem != 0)
- return (rtx) (HOST_WIDE_INT) 1;
+ return (rtx) (size_t) 1;
}
- if (fmt[i] == 'E')
+ else if (fmt[i] == 'E')
{
- register int j;
+ int j;
for (j = XVECLEN (x, i) - 1; j >= 0; j--)
{
tem = find_use_as_address (XVECEXP (x, i, j), reg, plusconst);
if (value == 0)
value = tem;
else if (tem != 0)
- return (rtx) (HOST_WIDE_INT) 1;
+ return (rtx) (size_t) 1;
}
}
}
@@ -4278,688 +4084,36 @@ find_use_as_address (x, reg, plusconst)
This is part of making a debugging dump. */
void
-dump_flow_info (file)
- FILE *file;
-{
- register int i;
- static char *reg_class_names[] = REG_CLASS_NAMES;
-
- fprintf (file, "%d registers.\n", max_regno);
- for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
- if (REG_N_REFS (i))
- {
- enum reg_class class, altclass;
- fprintf (file, "\nRegister %d used %d times across %d insns",
- i, REG_N_REFS (i), REG_LIVE_LENGTH (i));
- if (REG_BASIC_BLOCK (i) >= 0)
- fprintf (file, " in block %d", REG_BASIC_BLOCK (i));
- if (REG_N_SETS (i))
- fprintf (file, "; set %d time%s", REG_N_SETS (i),
- (REG_N_SETS (i) == 1) ? "" : "s");
- if (REG_USERVAR_P (regno_reg_rtx[i]))
- fprintf (file, "; user var");
- if (REG_N_DEATHS (i) != 1)
- fprintf (file, "; dies in %d places", REG_N_DEATHS (i));
- if (REG_N_CALLS_CROSSED (i) == 1)
- fprintf (file, "; crosses 1 call");
- else if (REG_N_CALLS_CROSSED (i))
- fprintf (file, "; crosses %d calls", REG_N_CALLS_CROSSED (i));
- if (PSEUDO_REGNO_BYTES (i) != UNITS_PER_WORD)
- fprintf (file, "; %d bytes", PSEUDO_REGNO_BYTES (i));
- class = reg_preferred_class (i);
- altclass = reg_alternate_class (i);
- if (class != GENERAL_REGS || altclass != ALL_REGS)
- {
- if (altclass == ALL_REGS || class == ALL_REGS)
- fprintf (file, "; pref %s", reg_class_names[(int) class]);
- else if (altclass == NO_REGS)
- fprintf (file, "; %s or none", reg_class_names[(int) class]);
- else
- fprintf (file, "; pref %s, else %s",
- reg_class_names[(int) class],
- reg_class_names[(int) altclass]);
- }
- if (REGNO_POINTER_FLAG (i))
- fprintf (file, "; pointer");
- fprintf (file, ".\n");
- }
-
- fprintf (file, "\n%d basic blocks.\n", n_basic_blocks);
- for (i = 0; i < n_basic_blocks; i++)
- {
- register basic_block bb = BASIC_BLOCK (i);
- register int regno;
- register edge e;
-
- fprintf (file, "\nBasic block %d: first insn %d, last %d.\n",
- i, INSN_UID (bb->head), INSN_UID (bb->end));
-
- fprintf (file, "Predecessors: ");
- for (e = bb->pred; e ; e = e->pred_next)
- dump_edge_info (file, e, 0);
-
- fprintf (file, "\nSuccessors: ");
- for (e = bb->succ; e ; e = e->succ_next)
- dump_edge_info (file, e, 1);
-
- fprintf (file, "\nRegisters live at start:");
- if (bb->global_live_at_start)
- {
- for (regno = 0; regno < max_regno; regno++)
- if (REGNO_REG_SET_P (bb->global_live_at_start, regno))
- fprintf (file, " %d", regno);
- }
- else
- fprintf (file, " n/a");
-
- fprintf (file, "\nRegisters live at end:");
- if (bb->global_live_at_end)
- {
- for (regno = 0; regno < max_regno; regno++)
- if (REGNO_REG_SET_P (bb->global_live_at_end, regno))
- fprintf (file, " %d", regno);
- }
- else
- fprintf (file, " n/a");
-
- putc('\n', file);
- }
-
- putc('\n', file);
-}
-
-static void
-dump_edge_info (file, e, do_succ)
- FILE *file;
- edge e;
- int do_succ;
-{
- basic_block side = (do_succ ? e->dest : e->src);
-
- if (side == ENTRY_BLOCK_PTR)
- fputs (" ENTRY", file);
- else if (side == EXIT_BLOCK_PTR)
- fputs (" EXIT", file);
- else
- fprintf (file, " %d", side->index);
-
- if (e->flags)
- {
- static char * bitnames[] = {
- "fallthru", "crit", "ab", "abcall", "eh", "fake"
- };
- int comma = 0;
- int i, flags = e->flags;
-
- fputc (' ', file);
- fputc ('(', file);
- for (i = 0; flags; i++)
- if (flags & (1 << i))
- {
- flags &= ~(1 << i);
-
- if (comma)
- fputc (',', file);
- if (i < (int)(sizeof (bitnames) / sizeof (*bitnames)))
- fputs (bitnames[i], file);
- else
- fprintf (file, "%d", i);
- comma = 1;
- }
- fputc (')', file);
- }
-}
-
-
-/* Like print_rtl, but also print out live information for the start of each
- basic block. */
-
-void
-print_rtl_with_bb (outf, rtx_first)
+dump_regset (r, outf)
+ regset r;
FILE *outf;
- rtx rtx_first;
{
- register rtx tmp_rtx;
-
- if (rtx_first == 0)
- fprintf (outf, "(nil)\n");
- else
- {
- int i;
- enum bb_state { NOT_IN_BB, IN_ONE_BB, IN_MULTIPLE_BB };
- int max_uid = get_max_uid ();
- basic_block *start = (basic_block *)
- alloca (max_uid * sizeof (basic_block));
- basic_block *end = (basic_block *)
- alloca (max_uid * sizeof (basic_block));
- enum bb_state *in_bb_p = (enum bb_state *)
- alloca (max_uid * sizeof (enum bb_state));
-
- memset (start, 0, max_uid * sizeof (basic_block));
- memset (end, 0, max_uid * sizeof (basic_block));
- memset (in_bb_p, 0, max_uid * sizeof (enum bb_state));
-
- for (i = n_basic_blocks - 1; i >= 0; i--)
- {
- basic_block bb = BASIC_BLOCK (i);
- rtx x;
-
- start[INSN_UID (bb->head)] = bb;
- end[INSN_UID (bb->end)] = bb;
- for (x = bb->head; x != NULL_RTX; x = NEXT_INSN (x))
- {
- enum bb_state state = IN_MULTIPLE_BB;
- if (in_bb_p[INSN_UID(x)] == NOT_IN_BB)
- state = IN_ONE_BB;
- in_bb_p[INSN_UID(x)] = state;
-
- if (x == bb->end)
- break;
- }
- }
-
- for (tmp_rtx = rtx_first; NULL != tmp_rtx; tmp_rtx = NEXT_INSN (tmp_rtx))
- {
- int did_output;
- basic_block bb;
-
- if ((bb = start[INSN_UID (tmp_rtx)]) != NULL)
- {
- fprintf (outf, ";; Start of basic block %d, registers live:",
- bb->index);
-
- EXECUTE_IF_SET_IN_REG_SET (bb->global_live_at_start, 0, i,
- {
- fprintf (outf, " %d", i);
- if (i < FIRST_PSEUDO_REGISTER)
- fprintf (outf, " [%s]",
- reg_names[i]);
- });
- putc ('\n', outf);
- }
-
- if (in_bb_p[INSN_UID(tmp_rtx)] == NOT_IN_BB
- && GET_CODE (tmp_rtx) != NOTE
- && GET_CODE (tmp_rtx) != BARRIER
- && ! obey_regdecls)
- fprintf (outf, ";; Insn is not within a basic block\n");
- else if (in_bb_p[INSN_UID(tmp_rtx)] == IN_MULTIPLE_BB)
- fprintf (outf, ";; Insn is in multiple basic blocks\n");
-
- did_output = print_rtl_single (outf, tmp_rtx);
-
- if ((bb = end[INSN_UID (tmp_rtx)]) != NULL)
- fprintf (outf, ";; End of basic block %d\n", bb->index);
-
- if (did_output)
- putc ('\n', outf);
- }
- }
-}
-
-
-/* Integer list support. */
-
-/* Allocate a node from list *HEAD_PTR. */
-
-static int_list_ptr
-alloc_int_list_node (head_ptr)
- int_list_block **head_ptr;
-{
- struct int_list_block *first_blk = *head_ptr;
-
- if (first_blk == NULL || first_blk->nodes_left <= 0)
- {
- first_blk = (struct int_list_block *) xmalloc (sizeof (struct int_list_block));
- first_blk->nodes_left = INT_LIST_NODES_IN_BLK;
- first_blk->next = *head_ptr;
- *head_ptr = first_blk;
- }
-
- first_blk->nodes_left--;
- return &first_blk->nodes[first_blk->nodes_left];
-}
-
-/* Pointer to head of predecessor/successor block list. */
-static int_list_block *pred_int_list_blocks;
-
-/* Add a new node to integer list LIST with value VAL.
- LIST is a pointer to a list object to allow for different implementations.
- If *LIST is initially NULL, the list is empty.
- The caller must not care whether the element is added to the front or
- to the end of the list (to allow for different implementations). */
-
-static int_list_ptr
-add_int_list_node (blk_list, list, val)
- int_list_block **blk_list;
- int_list **list;
- int val;
-{
- int_list_ptr p = alloc_int_list_node (blk_list);
-
- p->val = val;
- p->next = *list;
- *list = p;
- return p;
-}
-
-/* Free the blocks of lists at BLK_LIST. */
-
-void
-free_int_list (blk_list)
- int_list_block **blk_list;
-{
- int_list_block *p, *next;
-
- for (p = *blk_list; p != NULL; p = next)
- {
- next = p->next;
- free (p);
- }
-
- /* Mark list as empty for the next function we compile. */
- *blk_list = NULL;
-}
-
-/* Predecessor/successor computation. */
-
-/* Mark PRED_BB a precessor of SUCC_BB,
- and conversely SUCC_BB a successor of PRED_BB. */
-
-static void
-add_pred_succ (pred_bb, succ_bb, s_preds, s_succs, num_preds, num_succs)
- int pred_bb;
- int succ_bb;
- int_list_ptr *s_preds;
- int_list_ptr *s_succs;
- int *num_preds;
- int *num_succs;
-{
- if (succ_bb != EXIT_BLOCK)
- {
- add_int_list_node (&pred_int_list_blocks, &s_preds[succ_bb], pred_bb);
- num_preds[succ_bb]++;
- }
- if (pred_bb != ENTRY_BLOCK)
- {
- add_int_list_node (&pred_int_list_blocks, &s_succs[pred_bb], succ_bb);
- num_succs[pred_bb]++;
- }
-}
-
-/* Convert edge lists into pred/succ lists for backward compatibility. */
-
-void
-compute_preds_succs (s_preds, s_succs, num_preds, num_succs)
- int_list_ptr *s_preds;
- int_list_ptr *s_succs;
- int *num_preds;
- int *num_succs;
-{
- int i, n = n_basic_blocks;
- edge e;
-
- memset (s_preds, 0, n_basic_blocks * sizeof (int_list_ptr));
- memset (s_succs, 0, n_basic_blocks * sizeof (int_list_ptr));
- memset (num_preds, 0, n_basic_blocks * sizeof (int));
- memset (num_succs, 0, n_basic_blocks * sizeof (int));
-
- for (i = 0; i < n; ++i)
- {
- basic_block bb = BASIC_BLOCK (i);
-
- for (e = bb->succ; e ; e = e->succ_next)
- add_pred_succ (i, e->dest->index, s_preds, s_succs,
- num_preds, num_succs);
- }
-
- for (e = ENTRY_BLOCK_PTR->succ; e ; e = e->succ_next)
- add_pred_succ (ENTRY_BLOCK, e->dest->index, s_preds, s_succs,
- num_preds, num_succs);
-}
-
-void
-dump_bb_data (file, preds, succs, live_info)
- FILE *file;
- int_list_ptr *preds;
- int_list_ptr *succs;
- int live_info;
-{
- int bb;
- int_list_ptr p;
-
- fprintf (file, "BB data\n\n");
- for (bb = 0; bb < n_basic_blocks; bb++)
- {
- fprintf (file, "BB %d, start %d, end %d\n", bb,
- INSN_UID (BLOCK_HEAD (bb)), INSN_UID (BLOCK_END (bb)));
- fprintf (file, " preds:");
- for (p = preds[bb]; p != NULL; p = p->next)
- {
- int pred_bb = INT_LIST_VAL (p);
- if (pred_bb == ENTRY_BLOCK)
- fprintf (file, " entry");
- else
- fprintf (file, " %d", pred_bb);
- }
- fprintf (file, "\n");
- fprintf (file, " succs:");
- for (p = succs[bb]; p != NULL; p = p->next)
- {
- int succ_bb = INT_LIST_VAL (p);
- if (succ_bb == EXIT_BLOCK)
- fprintf (file, " exit");
- else
- fprintf (file, " %d", succ_bb);
- }
- if (live_info)
- {
- int regno;
- fprintf (file, "\nRegisters live at start:");
- for (regno = 0; regno < max_regno; regno++)
- if (REGNO_REG_SET_P (BASIC_BLOCK (bb)->global_live_at_start, regno))
- fprintf (file, " %d", regno);
- fprintf (file, "\n");
- }
- fprintf (file, "\n");
- }
- fprintf (file, "\n");
-}
-
-/* Free basic block data storage. */
-
-void
-free_bb_mem ()
-{
- free_int_list (&pred_int_list_blocks);
-}
-
-/* Compute dominator relationships. */
-void
-compute_dominators (dominators, post_dominators, s_preds, s_succs)
- sbitmap *dominators;
- sbitmap *post_dominators;
- int_list_ptr *s_preds;
- int_list_ptr *s_succs;
-{
- int bb, changed, passes;
- sbitmap *temp_bitmap;
-
- temp_bitmap = sbitmap_vector_alloc (n_basic_blocks, n_basic_blocks);
- sbitmap_vector_ones (dominators, n_basic_blocks);
- sbitmap_vector_ones (post_dominators, n_basic_blocks);
- sbitmap_vector_zero (temp_bitmap, n_basic_blocks);
-
- sbitmap_zero (dominators[0]);
- SET_BIT (dominators[0], 0);
-
- sbitmap_zero (post_dominators[n_basic_blocks - 1]);
- SET_BIT (post_dominators[n_basic_blocks - 1], 0);
-
- passes = 0;
- changed = 1;
- while (changed)
- {
- changed = 0;
- for (bb = 1; bb < n_basic_blocks; bb++)
- {
- sbitmap_intersect_of_predecessors (temp_bitmap[bb], dominators,
- bb, s_preds);
- SET_BIT (temp_bitmap[bb], bb);
- changed |= sbitmap_a_and_b (dominators[bb],
- dominators[bb],
- temp_bitmap[bb]);
- sbitmap_intersect_of_successors (temp_bitmap[bb], post_dominators,
- bb, s_succs);
- SET_BIT (temp_bitmap[bb], bb);
- changed |= sbitmap_a_and_b (post_dominators[bb],
- post_dominators[bb],
- temp_bitmap[bb]);
- }
- passes++;
- }
-
- free (temp_bitmap);
-}
-
-/* Given DOMINATORS, compute the immediate dominators into IDOM. */
-
-void
-compute_immediate_dominators (idom, dominators)
- int *idom;
- sbitmap *dominators;
-{
- sbitmap *tmp;
- int b;
-
- tmp = sbitmap_vector_alloc (n_basic_blocks, n_basic_blocks);
-
- /* Begin with tmp(n) = dom(n) - { n }. */
- for (b = n_basic_blocks; --b >= 0; )
- {
- sbitmap_copy (tmp[b], dominators[b]);
- RESET_BIT (tmp[b], b);
- }
-
- /* Subtract out all of our dominator's dominators. */
- for (b = n_basic_blocks; --b >= 0; )
- {
- sbitmap tmp_b = tmp[b];
- int s;
-
- for (s = n_basic_blocks; --s >= 0; )
- if (TEST_BIT (tmp_b, s))
- sbitmap_difference (tmp_b, tmp_b, tmp[s]);
- }
-
- /* Find the one bit set in the bitmap and put it in the output array. */
- for (b = n_basic_blocks; --b >= 0; )
- {
- int t;
- EXECUTE_IF_SET_IN_SBITMAP (tmp[b], 0, t, { idom[b] = t; });
- }
-
- sbitmap_vector_free (tmp);
-}
-
-/* Count for a single SET rtx, X. */
-
-static void
-count_reg_sets_1 (x)
- rtx x;
-{
- register int regno;
- register rtx reg = SET_DEST (x);
-
- /* Find the register that's set/clobbered. */
- while (GET_CODE (reg) == SUBREG || GET_CODE (reg) == ZERO_EXTRACT
- || GET_CODE (reg) == SIGN_EXTRACT
- || GET_CODE (reg) == STRICT_LOW_PART)
- reg = XEXP (reg, 0);
-
- if (GET_CODE (reg) == PARALLEL
- && GET_MODE (reg) == BLKmode)
+ int i;
+ if (r == NULL)
{
- register int i;
- for (i = XVECLEN (reg, 0) - 1; i >= 0; i--)
- count_reg_sets_1 (XVECEXP (reg, 0, i));
+ fputs (" (nil)", outf);
return;
}
- if (GET_CODE (reg) == REG)
- {
- regno = REGNO (reg);
- if (regno >= FIRST_PSEUDO_REGISTER)
- {
- /* Count (weighted) references, stores, etc. This counts a
- register twice if it is modified, but that is correct. */
- REG_N_SETS (regno)++;
-
- REG_N_REFS (regno) += loop_depth;
- }
- }
-}
-
-/* Increment REG_N_SETS for each SET or CLOBBER found in X; also increment
- REG_N_REFS by the current loop depth for each SET or CLOBBER found. */
-
-static void
-count_reg_sets (x)
- rtx x;
-{
- register RTX_CODE code = GET_CODE (x);
-
- if (code == SET || code == CLOBBER)
- count_reg_sets_1 (x);
- else if (code == PARALLEL)
+ EXECUTE_IF_SET_IN_REG_SET (r, 0, i,
{
- register int i;
- for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
- {
- code = GET_CODE (XVECEXP (x, 0, i));
- if (code == SET || code == CLOBBER)
- count_reg_sets_1 (XVECEXP (x, 0, i));
- }
- }
+ fprintf (outf, " %d", i);
+ if (i < FIRST_PSEUDO_REGISTER)
+ fprintf (outf, " [%s]",
+ reg_names[i]);
+ });
}
-/* Increment REG_N_REFS by the current loop depth each register reference
- found in X. */
+/* Print a human-reaable representation of R on the standard error
+ stream. This function is designed to be used from within the
+ debugger. */
-static void
-count_reg_references (x)
- rtx x;
+void
+debug_regset (r)
+ regset r;
{
- register RTX_CODE code;
-
- retry:
- code = GET_CODE (x);
- switch (code)
- {
- case LABEL_REF:
- case SYMBOL_REF:
- case CONST_INT:
- case CONST:
- case CONST_DOUBLE:
- case PC:
- case ADDR_VEC:
- case ADDR_DIFF_VEC:
- case ASM_INPUT:
- return;
-
-#ifdef HAVE_cc0
- case CC0:
- return;
-#endif
-
- case CLOBBER:
- /* If we are clobbering a MEM, mark any registers inside the address
- as being used. */
- if (GET_CODE (XEXP (x, 0)) == MEM)
- count_reg_references (XEXP (XEXP (x, 0), 0));
- return;
-
- case SUBREG:
- /* While we're here, optimize this case. */
- x = SUBREG_REG (x);
-
- /* In case the SUBREG is not of a register, don't optimize */
- if (GET_CODE (x) != REG)
- {
- count_reg_references (x);
- return;
- }
-
- /* ... fall through ... */
-
- case REG:
- if (REGNO (x) >= FIRST_PSEUDO_REGISTER)
- REG_N_REFS (REGNO (x)) += loop_depth;
- return;
-
- case SET:
- {
- register rtx testreg = SET_DEST (x);
- int mark_dest = 0;
-
- /* If storing into MEM, don't show it as being used. But do
- show the address as being used. */
- if (GET_CODE (testreg) == MEM)
- {
- count_reg_references (XEXP (testreg, 0));
- count_reg_references (SET_SRC (x));
- return;
- }
-
- /* Storing in STRICT_LOW_PART is like storing in a reg
- in that this SET might be dead, so ignore it in TESTREG.
- but in some other ways it is like using the reg.
-
- Storing in a SUBREG or a bit field is like storing the entire
- register in that if the register's value is not used
- then this SET is not needed. */
- while (GET_CODE (testreg) == STRICT_LOW_PART
- || GET_CODE (testreg) == ZERO_EXTRACT
- || GET_CODE (testreg) == SIGN_EXTRACT
- || GET_CODE (testreg) == SUBREG)
- {
- /* Modifying a single register in an alternate mode
- does not use any of the old value. But these other
- ways of storing in a register do use the old value. */
- if (GET_CODE (testreg) == SUBREG
- && !(REG_SIZE (SUBREG_REG (testreg)) > REG_SIZE (testreg)))
- ;
- else
- mark_dest = 1;
-
- testreg = XEXP (testreg, 0);
- }
-
- /* If this is a store into a register,
- recursively scan the value being stored. */
-
- if ((GET_CODE (testreg) == PARALLEL
- && GET_MODE (testreg) == BLKmode)
- || GET_CODE (testreg) == REG)
- {
- count_reg_references (SET_SRC (x));
- if (mark_dest)
- count_reg_references (SET_DEST (x));
- return;
- }
- }
- break;
-
- default:
- break;
- }
-
- /* Recursively scan the operands of this expression. */
-
- {
- register char *fmt = GET_RTX_FORMAT (code);
- register int i;
-
- for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
- {
- if (fmt[i] == 'e')
- {
- /* Tail recursive case: save a function call level. */
- if (i == 0)
- {
- x = XEXP (x, 0);
- goto retry;
- }
- count_reg_references (XEXP (x, i));
- }
- else if (fmt[i] == 'E')
- {
- register int j;
- for (j = 0; j < XVECLEN (x, i); j++)
- count_reg_references (XVECEXP (x, i, j));
- }
- }
- }
+ dump_regset (r, stderr);
+ putc ('\n', stderr);
}
/* Recompute register set/reference counts immediately prior to register
@@ -4973,332 +4127,139 @@ count_reg_references (x)
More accurate reference counts generally lead to better register allocation.
F is the first insn to be scanned.
+
LOOP_STEP denotes how much loop_depth should be incremented per
- loop nesting level in order to increase the ref count more for references
- in a loop.
+ loop nesting level in order to increase the ref count more for
+ references in a loop.
It might be worthwhile to update REG_LIVE_LENGTH, REG_BASIC_BLOCK and
possibly other information which is used by the register allocators. */
void
recompute_reg_usage (f, loop_step)
- rtx f;
- int loop_step;
+ rtx f ATTRIBUTE_UNUSED;
+ int loop_step ATTRIBUTE_UNUSED;
{
- rtx insn;
- int i, max_reg;
-
- /* Clear out the old data. */
- max_reg = max_reg_num ();
- for (i = FIRST_PSEUDO_REGISTER; i < max_reg; i++)
- {
- REG_N_SETS (i) = 0;
- REG_N_REFS (i) = 0;
- }
-
- /* Scan each insn in the chain and count how many times each register is
- set/used. */
- loop_depth = 1;
- for (insn = f; insn; insn = NEXT_INSN (insn))
- {
- /* Keep track of loop depth. */
- if (GET_CODE (insn) == NOTE)
- {
- /* Look for loop boundaries. */
- if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END)
- loop_depth -= loop_step;
- else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG)
- loop_depth += loop_step;
-
- /* If we have LOOP_DEPTH == 0, there has been a bookkeeping error.
- Abort now rather than setting register status incorrectly. */
- if (loop_depth == 0)
- abort ();
- }
- else if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
- {
- rtx links;
-
- /* This call will increment REG_N_SETS for each SET or CLOBBER
- of a register in INSN. It will also increment REG_N_REFS
- by the loop depth for each set of a register in INSN. */
- count_reg_sets (PATTERN (insn));
-
- /* count_reg_sets does not detect autoincrement address modes, so
- detect them here by looking at the notes attached to INSN. */
- for (links = REG_NOTES (insn); links; links = XEXP (links, 1))
- {
- if (REG_NOTE_KIND (links) == REG_INC)
- /* Count (weighted) references, stores, etc. This counts a
- register twice if it is modified, but that is correct. */
- REG_N_SETS (REGNO (XEXP (links, 0)))++;
- }
-
- /* This call will increment REG_N_REFS by the current loop depth for
- each reference to a register in INSN. */
- count_reg_references (PATTERN (insn));
-
- /* count_reg_references will not include counts for arguments to
- function calls, so detect them here by examining the
- CALL_INSN_FUNCTION_USAGE data. */
- if (GET_CODE (insn) == CALL_INSN)
- {
- rtx note;
-
- for (note = CALL_INSN_FUNCTION_USAGE (insn);
- note;
- note = XEXP (note, 1))
- if (GET_CODE (XEXP (note, 0)) == USE)
- count_reg_references (SET_DEST (XEXP (note, 0)));
- }
- }
- }
-}
-
-/* Record INSN's block as BB. */
-
-void
-set_block_for_insn (insn, bb)
- rtx insn;
- basic_block bb;
-{
- size_t uid = INSN_UID (insn);
- if (uid >= basic_block_for_insn->num_elements)
- {
- int new_size;
-
- /* Add one-eighth the size so we don't keep calling xrealloc. */
- new_size = uid + (uid + 7) / 8;
-
- VARRAY_GROW (basic_block_for_insn, new_size);
- }
- VARRAY_BB (basic_block_for_insn, uid) = bb;
+ allocate_reg_life_data ();
+ update_life_info (NULL, UPDATE_LIFE_LOCAL, PROP_REG_INFO);
}
-/* Record INSN's block number as BB. */
-/* ??? This has got to go. */
-
-void
-set_block_num (insn, bb)
- rtx insn;
- int bb;
-{
- set_block_for_insn (insn, BASIC_BLOCK (bb));
-}
-
-/* Verify the CFG consistency. This function check some CFG invariants and
- aborts when something is wrong. Hope that this function will help to
- convert many optimization passes to preserve CFG consistent.
+/* Optionally removes all the REG_DEAD and REG_UNUSED notes from a set of
+ blocks. If BLOCKS is NULL, assume the universal set. Returns a count
+ of the number of registers that died. */
- Currently it does following checks:
-
- - test head/end pointers
- - overlapping of basic blocks
- - edge list corectness
- - headers of basic blocks (the NOTE_INSN_BASIC_BLOCK note)
- - tails of basic blocks (ensure that boundary is necesary)
- - scans body of the basic block for JUMP_INSN, CODE_LABEL
- and NOTE_INSN_BASIC_BLOCK
- - check that all insns are in the basic blocks
- (except the switch handling code, barriers and notes)
-
- In future it can be extended check a lot of other stuff as well
- (reachability of basic blocks, life information, etc. etc.). */
-
-void
-verify_flow_info ()
+int
+count_or_remove_death_notes (blocks, kill)
+ sbitmap blocks;
+ int kill;
{
- const int max_uid = get_max_uid ();
- const rtx rtx_first = get_insns ();
- basic_block *bb_info;
- rtx x;
- int i;
+ int i, count = 0;
- bb_info = (basic_block *) alloca (max_uid * sizeof (basic_block));
- memset (bb_info, 0, max_uid * sizeof (basic_block));
-
- /* First pass check head/end pointers and set bb_info array used by
- later passes. */
- for (i = n_basic_blocks - 1; i >= 0; i--)
+ for (i = n_basic_blocks - 1; i >= 0; --i)
{
- basic_block bb = BASIC_BLOCK (i);
-
- /* Check the head pointer and make sure that it is pointing into
- insn list. */
- for (x = rtx_first; x != NULL_RTX; x = NEXT_INSN (x))
- if (x == bb->head)
- break;
- if (!x)
- {
- fatal ("verify_flow_info: Head insn %d for block %d not found in the insn stream.\n",
- INSN_UID (bb->head), bb->index);
- }
-
- /* Check the end pointer and make sure that it is pointing into
- insn list. */
- for (x = bb->head; x != NULL_RTX; x = NEXT_INSN (x))
- {
- if (bb_info[INSN_UID (x)] != NULL)
- {
- fatal ("verify_flow_info: Insn %d is in multiple basic blocks (%d and %d)",
- INSN_UID (x), bb->index, bb_info[INSN_UID (x)]->index);
- }
- bb_info[INSN_UID (x)] = bb;
+ basic_block bb;
+ rtx insn;
- if (x == bb->end)
- break;
- }
- if (!x)
- {
- fatal ("verify_flow_info: End insn %d for block %d not found in the insn stream.\n",
- INSN_UID (bb->end), bb->index);
- }
- }
+ if (blocks && ! TEST_BIT (blocks, i))
+ continue;
- /* Now check the basic blocks (boundaries etc.) */
- for (i = n_basic_blocks - 1; i >= 0; i--)
- {
- basic_block bb = BASIC_BLOCK (i);
- /* Check corectness of edge lists */
- edge e;
+ bb = BASIC_BLOCK (i);
- e = bb->succ;
- while (e)
+ for (insn = bb->head;; insn = NEXT_INSN (insn))
{
- if (e->src != bb)
- {
- fprintf (stderr, "verify_flow_info: Basic block %d succ edge is corrupted\n",
- bb->index);
- fprintf (stderr, "Predecessor: ");
- dump_edge_info (stderr, e, 0);
- fprintf (stderr, "\nSuccessor: ");
- dump_edge_info (stderr, e, 1);
- fflush (stderr);
- abort ();
- }
- if (e->dest != EXIT_BLOCK_PTR)
+ if (INSN_P (insn))
{
- edge e2 = e->dest->pred;
- while (e2 && e2 != e)
- e2 = e2->pred_next;
- if (!e2)
- {
- fatal ("verify_flow_info: Basic block %i edge lists are corrupted\n",
- bb->index);
- }
- }
- e = e->succ_next;
- }
+ rtx *pprev = &REG_NOTES (insn);
+ rtx link = *pprev;
- e = bb->pred;
- while (e)
- {
- if (e->dest != bb)
- {
- fprintf (stderr, "verify_flow_info: Basic block %d pred edge is corrupted\n",
- bb->index);
- fprintf (stderr, "Predecessor: ");
- dump_edge_info (stderr, e, 0);
- fprintf (stderr, "\nSuccessor: ");
- dump_edge_info (stderr, e, 1);
- fflush (stderr);
- abort ();
- }
- if (e->src != ENTRY_BLOCK_PTR)
- {
- edge e2 = e->src->succ;
- while (e2 && e2 != e)
- e2 = e2->succ_next;
- if (!e2)
+ while (link)
{
- fatal ("verify_flow_info: Basic block %i edge lists are corrupted\n",
- bb->index);
- }
- }
- e = e->pred_next;
- }
+ switch (REG_NOTE_KIND (link))
+ {
+ case REG_DEAD:
+ if (GET_CODE (XEXP (link, 0)) == REG)
+ {
+ rtx reg = XEXP (link, 0);
+ int n;
+
+ if (REGNO (reg) >= FIRST_PSEUDO_REGISTER)
+ n = 1;
+ else
+ n = HARD_REGNO_NREGS (REGNO (reg), GET_MODE (reg));
+ count += n;
+ }
+ /* Fall through. */
- /* OK pointers are correct. Now check the header of basic
- block. It ought to contain optional CODE_LABEL followed
- by NOTE_BASIC_BLOCK. */
- x = bb->head;
- if (GET_CODE (x) == CODE_LABEL)
- {
- if (bb->end == x)
- {
- fatal ("verify_flow_info: Basic block contains only CODE_LABEL and no NOTE_INSN_BASIC_BLOCK note\n");
+ case REG_UNUSED:
+ if (kill)
+ {
+ rtx next = XEXP (link, 1);
+ free_EXPR_LIST_node (link);
+ *pprev = link = next;
+ break;
+ }
+ /* Fall through. */
+
+ default:
+ pprev = &XEXP (link, 1);
+ link = *pprev;
+ break;
+ }
+ }
}
- x = NEXT_INSN (x);
- }
- if (GET_CODE (x) != NOTE
- || NOTE_LINE_NUMBER (x) != NOTE_INSN_BASIC_BLOCK
- || NOTE_BASIC_BLOCK (x) != bb)
- {
- fatal ("verify_flow_info: NOTE_INSN_BASIC_BLOCK is missing for block %d\n",
- bb->index);
- }
- if (bb->end == x)
- {
- /* Do checks for empty blocks here */
+ if (insn == bb->end)
+ break;
}
- else
- {
- x = NEXT_INSN (x);
- while (x)
- {
- if (GET_CODE (x) == NOTE
- && NOTE_LINE_NUMBER (x) == NOTE_INSN_BASIC_BLOCK)
- {
- fatal ("verify_flow_info: NOTE_INSN_BASIC_BLOCK %d in the middle of basic block %d\n",
- INSN_UID (x), bb->index);
- }
+ }
- if (x == bb->end)
- break;
+ return count;
+}
+/* Clear LOG_LINKS fields of insns in a selected blocks or whole chain
+ if blocks is NULL. */
- if (GET_CODE (x) == JUMP_INSN
- || GET_CODE (x) == CODE_LABEL
- || GET_CODE (x) == BARRIER)
- {
- fatal_insn ("verify_flow_info: Incorrect insn in the middle of basic block %d\n",
- x, bb->index);
- }
+static void
+clear_log_links (blocks)
+ sbitmap blocks;
+{
+ rtx insn;
+ int i;
- x = NEXT_INSN (x);
- }
- }
+ if (!blocks)
+ {
+ for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
+ if (INSN_P (insn))
+ free_INSN_LIST_list (&LOG_LINKS (insn));
}
+ else
+ EXECUTE_IF_SET_IN_SBITMAP (blocks, 0, i,
+ {
+ basic_block bb = BASIC_BLOCK (i);
- x = rtx_first;
- while (x)
- {
- if (!bb_info[INSN_UID (x)])
- {
- switch (GET_CODE (x))
- {
- case BARRIER:
- case NOTE:
- break;
-
- case CODE_LABEL:
- /* An addr_vec is placed outside any block block. */
- if (NEXT_INSN (x)
- && GET_CODE (NEXT_INSN (x)) == JUMP_INSN
- && (GET_CODE (PATTERN (NEXT_INSN (x))) == ADDR_DIFF_VEC
- || GET_CODE (PATTERN (NEXT_INSN (x))) == ADDR_VEC))
- {
- x = NEXT_INSN (x);
- }
+ for (insn = bb->head; insn != NEXT_INSN (bb->end);
+ insn = NEXT_INSN (insn))
+ if (INSN_P (insn))
+ free_INSN_LIST_list (&LOG_LINKS (insn));
+ });
+}
- /* But in any case, non-deletable labels can appear anywhere. */
- break;
+/* Given a register bitmap, turn on the bits in a HARD_REG_SET that
+ correspond to the hard registers, if any, set in that map. This
+ could be done far more efficiently by having all sorts of special-cases
+ with moving single words, but probably isn't worth the trouble. */
- default:
- fatal_insn ("verify_flow_info: Insn outside basic block\n", x);
- }
- }
+void
+reg_set_to_hard_reg_set (to, from)
+ HARD_REG_SET *to;
+ bitmap from;
+{
+ int i;
- x = NEXT_INSN (x);
- }
+ EXECUTE_IF_SET_IN_BITMAP
+ (from, 0, i,
+ {
+ if (i >= FIRST_PSEUDO_REGISTER)
+ return;
+ SET_HARD_REG_BIT (*to, i);
+ });
}
OpenPOWER on IntegriCloud