/* Instruction scheduling pass. Selective scheduler and pipeliner.
- Copyright (C) 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+ Copyright (C) 2006-2014 Free Software Foundation, Inc.
This file is part of GCC.
#include "system.h"
#include "coretypes.h"
#include "tm.h"
-#include "toplev.h"
+#include "diagnostic-core.h"
#include "rtl.h"
#include "tm_p.h"
#include "hard-reg-set.h"
#include "regs.h"
+#include "hashtab.h"
+#include "hash-set.h"
+#include "vec.h"
+#include "machmode.h"
+#include "input.h"
#include "function.h"
+#include "predict.h"
+#include "dominance.h"
+#include "cfg.h"
+#include "cfgrtl.h"
+#include "cfganal.h"
+#include "cfgbuild.h"
+#include "basic-block.h"
#include "flags.h"
#include "insn-config.h"
#include "insn-attr.h"
#include "except.h"
-#include "toplev.h"
#include "recog.h"
#include "params.h"
#include "target.h"
-#include "timevar.h"
-#include "tree-pass.h"
#include "sched-int.h"
#include "ggc.h"
#include "tree.h"
-#include "vec.h"
#include "langhooks.h"
#include "rtlhooks-def.h"
+#include "emit-rtl.h" /* FIXME: Can go away once crtl is moved to rtl.h. */
#ifdef INSN_SCHEDULING
#include "sel-sched-ir.h"
#include "sel-sched-dump.h"
/* A vector holding bb info for whole scheduling pass. */
-VEC(sel_global_bb_info_def, heap) *sel_global_bb_info = NULL;
+vec<sel_global_bb_info_def>
+ sel_global_bb_info = vNULL;
/* A vector holding bb info. */
-VEC(sel_region_bb_info_def, heap) *sel_region_bb_info = NULL;
+vec<sel_region_bb_info_def>
+ sel_region_bb_info = vNULL;
/* A pool for allocating all lists. */
alloc_pool sched_lists_pool;
/* LOOP_NESTS is a vector containing the corresponding loop nest for
each region. */
-static VEC(loop_p, heap) *loop_nests = NULL;
+static vec<loop_p> loop_nests = vNULL;
/* Saves blocks already in loop regions, indexed by bb->index. */
static sbitmap bbs_in_loop_rgns = NULL;
int n;
/* Its size. */
- int s;
+ int s;
} nop_pool = { NULL, 0, 0 };
/* The pool for basic block notes. */
-static rtx_vec_t bb_note_pool;
+static vec<rtx_note *> bb_note_pool;
/* A NOP pattern used to emit placeholder insns. */
rtx nop_pattern = NULL_RTX;
/* A special instruction that resides in EXIT_BLOCK.
EXIT_INSN is successor of the insns that lead to EXIT_BLOCK. */
-rtx exit_insn = NULL_RTX;
+rtx_insn *exit_insn = NULL;
-/* TRUE if while scheduling current region, which is loop, its preheader
+/* TRUE if while scheduling current region, which is loop, its preheader
was removed. */
bool preheader_removed = false;
\f
static void cfg_preds (basic_block, insn_t **, int *);
static void prepare_insn_expr (insn_t, int);
-static void free_history_vect (VEC (expr_history_def, heap) **);
+static void free_history_vect (vec<expr_history_def> &);
static void move_bb_info (basic_block, basic_block);
static void remove_empty_bb (basic_block, bool);
+static void sel_merge_blocks (basic_block, basic_block);
static void sel_remove_loop_preheader (void);
+static bool bb_has_removable_jump_to_p (basic_block, basic_block);
static bool insn_is_the_only_one_in_bb_p (insn_t);
static void create_initial_data_sets (basic_block);
static void free_av_set (basic_block);
static void invalidate_av_set (basic_block);
static void extend_insn_data (void);
-static void sel_init_new_insn (insn_t, int);
+static void sel_init_new_insn (insn_t, int, int = -1);
static void finish_insns (void);
\f
/* Various list functions. */
/* Add new fence consisting of INSN and STATE to the list pointed to by LP. */
static void
-flist_add (flist_t *lp, insn_t insn, state_t state, deps_t dc, void *tc,
- insn_t last_scheduled_insn, VEC(rtx,gc) *executing_insns,
- int *ready_ticks, int ready_ticks_size, insn_t sched_next,
- int cycle, int cycle_issued_insns,
+flist_add (flist_t *lp, insn_t insn, state_t state, deps_t dc, void *tc,
+ insn_t last_scheduled_insn, vec<rtx_insn *, va_gc> *executing_insns,
+ int *ready_ticks, int ready_ticks_size, insn_t sched_next,
+ int cycle, int cycle_issued_insns, int issue_more,
bool starts_cycle_p, bool after_stall_p)
{
fence_t f;
FENCE_TC (f) = tc;
FENCE_LAST_SCHEDULED_INSN (f) = last_scheduled_insn;
+ FENCE_ISSUE_MORE (f) = issue_more;
FENCE_EXECUTING_INSNS (f) = executing_insns;
FENCE_READY_TICKS (f) = ready_ticks;
FENCE_READY_TICKS_SIZE (f) = ready_ticks_size;
def_list_add (def_list_t *dl, insn_t original_insn, bool crosses_call)
{
def_t d;
-
+
_list_add (dl);
d = DEF_LIST_DEF (*dl);
/* Functions to work with target contexts. */
-/* Bulk target context. It is convenient for debugging purposes to ensure
+/* Bulk target context. It is convenient for debugging purposes to ensure
that there are no uninitialized (null) target contexts. */
static tc_t bulk_tc = (tc_t) 1;
-/* Target hooks wrappers. In the future we can provide some default
+/* Target hooks wrappers. In the future we can provide some default
implementations for them. */
/* Allocate a store for the target context. */
init_target_context (tc, clean_p);
}
\f
-/* Functions to work with dependence contexts.
- Dc (aka deps context, aka deps_t, aka struct deps *) is short for dependence
+/* Functions to work with dependence contexts.
+ Dc (aka deps context, aka deps_t, aka struct deps_desc *) is short for dependence
context. It accumulates information about processed insns to decide if
current insn is dependent on the processed ones. */
static void
copy_deps_context (deps_t to, deps_t from)
{
- init_deps (to);
+ init_deps (to, false);
deps_join (to, from);
}
static deps_t
alloc_deps_context (void)
{
- return XNEW (struct deps);
+ return XNEW (struct deps_desc);
}
/* Allocate and initialize dep context. */
{
deps_t dc = alloc_deps_context ();
- init_deps (dc);
+ init_deps (dc, false);
return dc;
}
reset_deps_context (deps_t dc)
{
clear_deps_context (dc);
- init_deps (dc);
+ init_deps (dc, false);
}
-/* This structure describes the dependence analysis hooks for advancing
+/* This structure describes the dependence analysis hooks for advancing
dependence context. */
static struct sched_deps_info_def advance_deps_context_sched_deps_info =
{
gcc_assert ((s != NULL && dc != NULL && tc != NULL)
|| (s == NULL && dc == NULL && tc == NULL));
- if (s != NULL)
- free (s);
+ free (s);
if (dc != NULL)
delete_deps_context (dc);
if (tc != NULL)
delete_target_context (tc);
- VEC_free (rtx, gc, FENCE_EXECUTING_INSNS (f));
+ vec_free (FENCE_EXECUTING_INSNS (f));
free (FENCE_READY_TICKS (f));
FENCE_READY_TICKS (f) = NULL;
}
succ_iterator si;
bool first = true;
int ready_ticks_size = get_max_uid () + 1;
-
- FOR_EACH_SUCC_1 (succ, si, old_fence,
+
+ FOR_EACH_SUCC_1 (succ, si, old_fence,
SUCCS_NORMAL | SUCCS_SKIP_TO_LOOP_EXITS)
{
-
+
if (first)
first = false;
else
state_create (),
create_deps_context () /* dc */,
create_target_context (true) /* tc */,
- NULL_RTX /* last_scheduled_insn */,
+ NULL /* last_scheduled_insn */,
NULL, /* executing_insns */
XCNEWVEC (int, ready_ticks_size), /* ready_ticks */
ready_ticks_size,
- NULL_RTX /* sched_next */,
- 1 /* cycle */, 0 /* cycle_issued_insns */,
- 1 /* starts_cycle_p */, 0 /* after_stall_p */);
+ NULL /* sched_next */,
+ 1 /* cycle */, 0 /* cycle_issued_insns */,
+ issue_rate, /* issue_more */
+ 1 /* starts_cycle_p */, 0 /* after_stall_p */);
}
}
/* Merges two fences (filling fields of fence F with resulting values) by
following rules: 1) state, target context and last scheduled insn are
- propagated from fallthrough edge if it is available;
+ propagated from fallthrough edge if it is available;
2) deps context and cycle is propagated from more probable edge;
- 3) all other fields are set to corresponding constant values.
+ 3) all other fields are set to corresponding constant values.
- INSN, STATE, DC, TC, LAST_SCHEDULED_INSN, EXECUTING_INSNS,
- READY_TICKS, READY_TICKS_SIZE, SCHED_NEXT, CYCLE and AFTER_STALL_P
- are the corresponding fields of the second fence. */
+ INSN, STATE, DC, TC, LAST_SCHEDULED_INSN, EXECUTING_INSNS,
+ READY_TICKS, READY_TICKS_SIZE, SCHED_NEXT, CYCLE, ISSUE_MORE
+ and AFTER_STALL_P are the corresponding fields of the second fence. */
static void
merge_fences (fence_t f, insn_t insn,
- state_t state, deps_t dc, void *tc,
- rtx last_scheduled_insn, VEC(rtx, gc) *executing_insns,
+ state_t state, deps_t dc, void *tc,
+ rtx_insn *last_scheduled_insn,
+ vec<rtx_insn *, va_gc> *executing_insns,
int *ready_ticks, int ready_ticks_size,
- rtx sched_next, int cycle, bool after_stall_p)
+ rtx sched_next, int cycle, int issue_more, bool after_stall_p)
{
insn_t last_scheduled_insn_old = FENCE_LAST_SCHEDULED_INSN (f);
gcc_assert (sel_bb_head_p (FENCE_INSN (f))
&& !sched_next && !FENCE_SCHED_NEXT (f));
- /* Check if we can decide which path fences came.
+ /* Check if we can decide which path fences came.
If we can't (or don't want to) - reset all. */
if (last_scheduled_insn == NULL
|| last_scheduled_insn_old == NULL
- /* This is a case when INSN is reachable on several paths from
- one insn (this can happen when pipelining of outer loops is on and
- there are two edges: one going around of inner loop and the other -
+ /* This is a case when INSN is reachable on several paths from
+ one insn (this can happen when pipelining of outer loops is on and
+ there are two edges: one going around of inner loop and the other -
right through it; in such case just reset everything). */
|| last_scheduled_insn == last_scheduled_insn_old)
{
state_reset (FENCE_STATE (f));
state_free (state);
-
+
reset_deps_context (FENCE_DC (f));
delete_deps_context (dc);
-
+
reset_target_context (FENCE_TC (f), true);
delete_target_context (tc);
FENCE_CYCLE (f) = cycle;
FENCE_LAST_SCHEDULED_INSN (f) = NULL;
- VEC_free (rtx, gc, executing_insns);
+ FENCE_ISSUE_MORE (f) = issue_rate;
+ vec_free (executing_insns);
free (ready_ticks);
if (FENCE_EXECUTING_INSNS (f))
- VEC_block_remove (rtx, FENCE_EXECUTING_INSNS (f), 0,
- VEC_length (rtx, FENCE_EXECUTING_INSNS (f)));
+ FENCE_EXECUTING_INSNS (f)->block_remove (0,
+ FENCE_EXECUTING_INSNS (f)->length ());
if (FENCE_READY_TICKS (f))
memset (FENCE_READY_TICKS (f), 0, FENCE_READY_TICKS_SIZE (f));
}
edge candidate;
succ_iterator si;
insn_t succ;
-
+
/* Find fallthrough edge. */
gcc_assert (BLOCK_FOR_INSN (insn)->prev_bb);
- candidate = find_fallthru_edge (BLOCK_FOR_INSN (insn)->prev_bb);
+ candidate = find_fallthru_edge_from (BLOCK_FOR_INSN (insn)->prev_bb);
if (!candidate
|| (candidate->src != BLOCK_FOR_INSN (last_scheduled_insn)
/* No fallthrough edge leading to basic block of INSN. */
state_reset (FENCE_STATE (f));
state_free (state);
-
+
reset_target_context (FENCE_TC (f), true);
delete_target_context (tc);
-
+
FENCE_LAST_SCHEDULED_INSN (f) = NULL;
+ FENCE_ISSUE_MORE (f) = issue_rate;
}
else
if (candidate->src == BLOCK_FOR_INSN (last_scheduled_insn))
{
- /* Would be weird if same insn is successor of several fallthrough
+ /* Would be weird if same insn is successor of several fallthrough
edges. */
gcc_assert (BLOCK_FOR_INSN (insn)->prev_bb
!= BLOCK_FOR_INSN (last_scheduled_insn_old));
FENCE_TC (f) = tc;
FENCE_LAST_SCHEDULED_INSN (f) = last_scheduled_insn;
+ FENCE_ISSUE_MORE (f) = issue_more;
}
else
{
{
reset_deps_context (FENCE_DC (f));
delete_deps_context (dc);
- VEC_free (rtx, gc, executing_insns);
+ vec_free (executing_insns);
free (ready_ticks);
-
+
FENCE_CYCLE (f) = MAX (FENCE_CYCLE (f), cycle);
if (FENCE_EXECUTING_INSNS (f))
- VEC_block_remove (rtx, FENCE_EXECUTING_INSNS (f), 0,
- VEC_length (rtx, FENCE_EXECUTING_INSNS (f)));
+ FENCE_EXECUTING_INSNS (f)->block_remove (0,
+ FENCE_EXECUTING_INSNS (f)->length ());
if (FENCE_READY_TICKS (f))
memset (FENCE_READY_TICKS (f), 0, FENCE_READY_TICKS_SIZE (f));
}
{
delete_deps_context (FENCE_DC (f));
FENCE_DC (f) = dc;
- VEC_free (rtx, gc, FENCE_EXECUTING_INSNS (f));
+ vec_free (FENCE_EXECUTING_INSNS (f));
FENCE_EXECUTING_INSNS (f) = executing_insns;
free (FENCE_READY_TICKS (f));
FENCE_READY_TICKS (f) = ready_ticks;
{
/* Leave DC and CYCLE untouched. */
delete_deps_context (dc);
- VEC_free (rtx, gc, executing_insns);
+ vec_free (executing_insns);
free (ready_ticks);
}
}
FENCE_SCHED_NEXT (f) = NULL;
}
-/* Add a new fence to NEW_FENCES list, initializing it from all
+/* Add a new fence to NEW_FENCES list, initializing it from all
other parameters. */
static void
add_to_fences (flist_tail_t new_fences, insn_t insn,
- state_t state, deps_t dc, void *tc, rtx last_scheduled_insn,
- VEC(rtx, gc) *executing_insns, int *ready_ticks,
- int ready_ticks_size, rtx sched_next, int cycle,
- int cycle_issued_insns, bool starts_cycle_p, bool after_stall_p)
+ state_t state, deps_t dc, void *tc,
+ rtx_insn *last_scheduled_insn,
+ vec<rtx_insn *, va_gc> *executing_insns, int *ready_ticks,
+ int ready_ticks_size, rtx_insn *sched_next, int cycle,
+ int cycle_issued_insns, int issue_rate,
+ bool starts_cycle_p, bool after_stall_p)
{
fence_t f = flist_lookup (FLIST_TAIL_HEAD (new_fences), insn);
if (! f)
{
flist_add (FLIST_TAIL_TAILP (new_fences), insn, state, dc, tc,
- last_scheduled_insn, executing_insns, ready_ticks,
+ last_scheduled_insn, executing_insns, ready_ticks,
ready_ticks_size, sched_next, cycle, cycle_issued_insns,
- starts_cycle_p, after_stall_p);
+ issue_rate, starts_cycle_p, after_stall_p);
FLIST_TAIL_TAILP (new_fences)
= &FLIST_NEXT (*FLIST_TAIL_TAILP (new_fences));
}
else
{
- merge_fences (f, insn, state, dc, tc, last_scheduled_insn,
- executing_insns, ready_ticks, ready_ticks_size,
- sched_next, cycle, after_stall_p);
+ merge_fences (f, insn, state, dc, tc, last_scheduled_insn,
+ executing_insns, ready_ticks, ready_ticks_size,
+ sched_next, cycle, issue_rate, after_stall_p);
}
}
flist_t *tailp = FLIST_TAIL_TAILP (new_fences);
old = FLIST_FENCE (old_fences);
- f = flist_lookup (FLIST_TAIL_HEAD (new_fences),
+ f = flist_lookup (FLIST_TAIL_HEAD (new_fences),
FENCE_INSN (FLIST_FENCE (old_fences)));
if (f)
{
merge_fences (f, old->insn, old->state, old->dc, old->tc,
old->last_scheduled_insn, old->executing_insns,
old->ready_ticks, old->ready_ticks_size,
- old->sched_next, old->cycle,
+ old->sched_next, old->cycle, old->issue_more,
old->after_stall_p);
}
else
FENCE_INSN (old) = NULL;
}
-/* Add a new fence to NEW_FENCES list and initialize most of its data
+/* Add a new fence to NEW_FENCES list and initialize most of its data
as a clean one. */
void
add_clean_fence_to_fences (flist_tail_t new_fences, insn_t succ, fence_t fence)
{
int ready_ticks_size = get_max_uid () + 1;
-
+
add_to_fences (new_fences,
succ, state_create (), create_deps_context (),
create_target_context (true),
- NULL_RTX, NULL,
+ NULL, NULL,
XCNEWVEC (int, ready_ticks_size), ready_ticks_size,
- NULL_RTX, FENCE_CYCLE (fence) + 1,
- 0, 1, FENCE_AFTER_STALL_P (fence));
+ NULL, FENCE_CYCLE (fence) + 1,
+ 0, issue_rate, 1, FENCE_AFTER_STALL_P (fence));
}
-/* Add a new fence to NEW_FENCES list and initialize all of its data
+/* Add a new fence to NEW_FENCES list and initialize all of its data
from FENCE and SUCC. */
void
add_dirty_fence_to_fences (flist_tail_t new_fences, insn_t succ, fence_t fence)
{
- int * new_ready_ticks
+ int * new_ready_ticks
= XNEWVEC (int, FENCE_READY_TICKS_SIZE (fence));
-
+
memcpy (new_ready_ticks, FENCE_READY_TICKS (fence),
FENCE_READY_TICKS_SIZE (fence) * sizeof (int));
add_to_fences (new_fences,
succ, state_create_copy (FENCE_STATE (fence)),
create_copy_of_deps_context (FENCE_DC (fence)),
create_copy_of_target_context (FENCE_TC (fence)),
- FENCE_LAST_SCHEDULED_INSN (fence),
- VEC_copy (rtx, gc, FENCE_EXECUTING_INSNS (fence)),
+ FENCE_LAST_SCHEDULED_INSN (fence),
+ vec_safe_copy (FENCE_EXECUTING_INSNS (fence)),
new_ready_ticks,
FENCE_READY_TICKS_SIZE (fence),
FENCE_SCHED_NEXT (fence),
FENCE_CYCLE (fence),
FENCE_ISSUED_INSNS (fence),
+ FENCE_ISSUE_MORE (fence),
FENCE_STARTS_CYCLE_P (fence),
FENCE_AFTER_STALL_P (fence));
}
void
return_regset_to_pool (regset rs)
{
+ gcc_assert (rs);
regset_pool.diff--;
if (regset_pool.n == regset_pool.s)
static int
cmp_v_in_regset_pool (const void *x, const void *xx)
{
- return *((const regset *) x) - *((const regset *) xx);
+ uintptr_t r1 = (uintptr_t) *((const regset *) x);
+ uintptr_t r2 = (uintptr_t) *((const regset *) xx);
+ if (r1 > r2)
+ return 1;
+ else if (r1 < r2)
+ return -1;
+ gcc_unreachable ();
}
#endif
regset *v = regset_pool.v;
int i = 0;
int n = regset_pool.n;
-
+
regset *vv = regset_pool.vv;
int ii = 0;
int nn = regset_pool.nn;
-
+
int diff = 0;
-
+
gcc_assert (n <= nn);
-
+
/* Sort both vectors so it will be possible to compare them. */
qsort (v, n, sizeof (*v), cmp_v_in_regset_pool);
qsort (vv, nn, sizeof (*vv), cmp_v_in_regset_pool);
-
+
while (ii < nn)
{
if (v[i] == vv[ii])
else
/* VV[II] was lost. */
diff++;
-
+
ii++;
}
-
+
gcc_assert (diff == regset_pool.diff);
}
#endif
-
+
/* If not true - we have a memory leak. */
gcc_assert (regset_pool.diff == 0);
-
+
while (regset_pool.n)
{
--regset_pool.n;
free (regset_pool.v);
regset_pool.v = NULL;
regset_pool.s = 0;
-
+
free (regset_pool.vv);
regset_pool.vv = NULL;
regset_pool.nn = 0;
}
\f
-/* Functions to work with nop pools. NOP insns are used as temporary
- placeholders of the insns being scheduled to allow correct update of
+/* Functions to work with nop pools. NOP insns are used as temporary
+ placeholders of the insns being scheduled to allow correct update of
the data sets. When update is finished, NOPs are deleted. */
/* A vinsn that is used to represent a nop. This vinsn is shared among all
insn_t
get_nop_from_pool (insn_t insn)
{
+ rtx nop_pat;
insn_t nop;
bool old_p = nop_pool.n != 0;
int flags;
if (old_p)
- nop = nop_pool.v[--nop_pool.n];
+ nop_pat = nop_pool.v[--nop_pool.n];
else
- nop = nop_pattern;
+ nop_pat = nop_pattern;
- nop = emit_insn_before (nop, insn);
+ nop = emit_insn_before (nop_pat, insn);
if (old_p)
flags = INSN_INIT_TODO_SSID;
gcc_assert (INSN_IN_STREAM_P (nop));
sel_remove_insn (nop, false, full_tidying);
+ /* We'll recycle this nop. */
+ nop->set_undeleted ();
+
if (nop_pool.n == nop_pool.s)
- nop_pool.v = XRESIZEVEC (rtx, nop_pool.v,
+ nop_pool.v = XRESIZEVEC (rtx_insn *, nop_pool.v,
(nop_pool.s = 2 * nop_pool.s + 1));
nop_pool.v[nop_pool.n++] = nop;
}
}
\f
-/* Skip unspec to support ia64 speculation. Called from rtx_equal_p_cb.
+/* Skip unspec to support ia64 speculation. Called from rtx_equal_p_cb.
The callback is given two rtxes XX and YY and writes the new rtxes
to NX and NY in case some needs to be skipped. */
static int
{
const_rtx x = *xx;
const_rtx y = *yy;
-
+
if (GET_CODE (x) == UNSPEC
&& (targetm.sched.skip_rtx_p == NULL
|| targetm.sched.skip_rtx_p (x)))
*ny = CONST_CAST_RTX (y);
return 1;
}
-
+
if (GET_CODE (y) == UNSPEC
&& (targetm.sched.skip_rtx_p == NULL
|| targetm.sched.skip_rtx_p (y)))
*ny = XVECEXP (y, 0, 0);
return 1;
}
-
+
return 0;
}
-/* Callback, called from hash_rtx_cb. Helps to hash UNSPEC rtx X in a correct way
+/* Callback, called from hash_rtx_cb. Helps to hash UNSPEC rtx X in a correct way
to support ia64 speculation. When changes are needed, new rtx X and new mode
NMODE are written, and the callback returns true. */
static int
-hash_with_unspec_callback (const_rtx x, enum machine_mode mode ATTRIBUTE_UNUSED,
- rtx *nx, enum machine_mode* nmode)
+hash_with_unspec_callback (const_rtx x, machine_mode mode ATTRIBUTE_UNUSED,
+ rtx *nx, machine_mode* nmode)
{
- if (GET_CODE (x) == UNSPEC
+ if (GET_CODE (x) == UNSPEC
&& targetm.sched.skip_rtx_p
&& targetm.sched.skip_rtx_p (x))
{
*nmode = VOIDmode;
return 1;
}
-
+
return 0;
}
if (lhs == NULL || rhs == NULL)
return false;
- /* Do not schedule CONST, CONST_INT and CONST_DOUBLE etc as rhs: no point
- to use reg, if const can be used. Moreover, scheduling const as rhs may
- lead to mode mismatch cause consts don't have modes but they could be
- merged from branches where the same const used in different modes. */
+ /* Do not schedule constants as rhs: no point to use reg, if const
+ can be used. Moreover, scheduling const as rhs may lead to mode
+ mismatch cause consts don't have modes but they could be merged
+ from branches where the same const used in different modes. */
if (CONSTANT_P (rhs))
return false;
if (REG_P (rhs))
return false;
- /* See comment at find_used_regs_1 (*1) for explanation of this
+ /* See comment at find_used_regs_1 (*1) for explanation of this
restriction. */
/* FIXME: remove this later. */
if (MEM_P (lhs))
return true;
}
-/* Initialize vinsn VI for INSN. Only for use from vinsn_create (). When
- FORCE_UNIQUE_P is true, the resulting vinsn will not be clonable. This is
+/* Initialize vinsn VI for INSN. Only for use from vinsn_create (). When
+ FORCE_UNIQUE_P is true, the resulting vinsn will not be clonable. This is
used e.g. for insns from recovery blocks. */
static void
vinsn_init (vinsn_t vi, insn_t insn, bool force_unique_p)
VINSN_INSN_RTX (vi) = insn;
VINSN_COUNT (vi) = 0;
vi->cost = -1;
-
+
+ if (INSN_NOP_P (insn))
+ return;
+
if (DF_INSN_UID_SAFE_GET (INSN_UID (insn)) != NULL)
init_id_from_df (VINSN_ID (vi), insn, force_unique_p);
else
deps_init_id (VINSN_ID (vi), insn, force_unique_p);
-
+
/* Hash vinsn depending on whether it is separable or not. */
hrcf = targetm.sched.skip_rtx_p ? hash_with_unspec_callback : NULL;
if (VINSN_SEPARABLE_P (vi))
NULL, NULL, false, hrcf);
VINSN_HASH_RTX (vi) = VINSN_HASH (vi);
}
-
+
insn_class = haifa_classify_insn (insn);
if (insn_class >= 2
&& (!targetm.sched.get_insn_spec_ds
VINSN_COUNT (vi)++;
}
-/* Create and init VI from the INSN. Use UNIQUE_P for determining the correct
+/* Create and init VI from the INSN. Use UNIQUE_P for determining the correct
VINSN_TYPE (VI). */
static vinsn_t
vinsn_create (insn_t insn, bool force_unique_p)
/* Return a copy of VI. When REATTACH_P is true, detach VI and attach
the copy. */
-vinsn_t
+vinsn_t
vinsn_copy (vinsn_t vi, bool reattach_p)
{
- rtx copy;
+ rtx_insn *copy;
bool unique = VINSN_UNIQUE_P (vi);
vinsn_t new_vi;
-
+
copy = create_copy_of_insn_rtx (VINSN_INSN_RTX (vi));
new_vi = create_vinsn_from_insn_rtx (copy, unique);
if (reattach_p)
{
gcc_assert (VINSN_COUNT (vi) == 0);
- return_regset_to_pool (VINSN_REG_SETS (vi));
- return_regset_to_pool (VINSN_REG_USES (vi));
- return_regset_to_pool (VINSN_REG_CLOBBERS (vi));
+ if (!INSN_NOP_P (VINSN_INSN_RTX (vi)))
+ {
+ return_regset_to_pool (VINSN_REG_SETS (vi));
+ return_regset_to_pool (VINSN_REG_USES (vi));
+ return_regset_to_pool (VINSN_REG_CLOBBERS (vi));
+ }
free (vi);
}
-/* Indicate that VI is no longer a part of some rtx object.
+/* Indicate that VI is no longer a part of some rtx object.
Remove VI if it is no longer needed. */
void
vinsn_detach (vinsn_t vi)
/* Return latency of INSN. */
static int
-sel_insn_rtx_cost (rtx insn)
+sel_insn_rtx_cost (rtx_insn *insn)
{
int cost;
}
/* Emit new insn after AFTER based on EXPR and SEQNO. If VINSN is not NULL,
- take it as a new vinsn instead of EXPR's vinsn.
- We simplify insns later, after scheduling region in
+ take it as a new vinsn instead of EXPR's vinsn.
+ We simplify insns later, after scheduling region in
simplify_changed_insns. */
insn_t
-sel_gen_insn_from_expr_after (expr_t expr, vinsn_t vinsn, int seqno,
+sel_gen_insn_from_expr_after (expr_t expr, vinsn_t vinsn, int seqno,
insn_t after)
{
expr_t emit_expr;
insn_t insn;
int flags;
-
- emit_expr = set_insn_init (expr, vinsn ? vinsn : EXPR_VINSN (expr),
+
+ emit_expr = set_insn_init (expr, vinsn ? vinsn : EXPR_VINSN (expr),
seqno);
insn = EXPR_INSN_RTX (emit_expr);
- add_insn_after (insn, after, BLOCK_FOR_INSN (insn));
+
+ /* The insn may come from the transformation cache, which may hold already
+ deleted insns, so mark it as not deleted. */
+ insn->set_undeleted ();
+
+ add_insn_after (insn, after, BLOCK_FOR_INSN (insn));
flags = INSN_INIT_TODO_SSID;
if (INSN_LUID (insn) == 0)
/* Assert that in move_op we disconnected this insn properly. */
gcc_assert (EXPR_VINSN (INSN_EXPR (insn)) != NULL);
- PREV_INSN (insn) = after;
- NEXT_INSN (insn) = next;
+ SET_PREV_INSN (insn) = after;
+ SET_NEXT_INSN (insn) = next;
- NEXT_INSN (after) = insn;
- PREV_INSN (next) = insn;
+ SET_NEXT_INSN (after) = insn;
+ SET_PREV_INSN (next) = insn;
/* Update links from insn to bb and vice versa. */
df_insn_change_bb (insn, bb);
if (BB_END (bb) == after)
BB_END (bb) = insn;
-
+
prepare_insn_expr (insn, seqno);
return insn;
}
\f
/* Functions to work with right-hand sides. */
-/* Search for a hash value determined by UID/NEW_VINSN in a sorted vector
+/* Search for a hash value determined by UID/NEW_VINSN in a sorted vector
VECT and return true when found. Use NEW_VINSN for comparison only when
- COMPARE_VINSNS is true. Write to INDP the index on which
- the search has stopped, such that inserting the new element at INDP will
+ COMPARE_VINSNS is true. Write to INDP the index on which
+ the search has stopped, such that inserting the new element at INDP will
retain VECT's sort order. */
static bool
-find_in_history_vect_1 (VEC(expr_history_def, heap) *vect,
- unsigned uid, vinsn_t new_vinsn,
+find_in_history_vect_1 (vec<expr_history_def> vect,
+ unsigned uid, vinsn_t new_vinsn,
bool compare_vinsns, int *indp)
{
expr_history_def *arr;
- int i, j, len = VEC_length (expr_history_def, vect);
+ int i, j, len = vect.length ();
if (len == 0)
{
return false;
}
- arr = VEC_address (expr_history_def, vect);
+ arr = vect.address ();
i = 0, j = len - 1;
while (i <= j)
{
unsigned auid = arr[i].uid;
- vinsn_t avinsn = arr[i].new_expr_vinsn;
+ vinsn_t avinsn = arr[i].new_expr_vinsn;
if (auid == uid
- /* When undoing transformation on a bookkeeping copy, the new vinsn
- may not be exactly equal to the one that is saved in the vector.
+ /* When undoing transformation on a bookkeeping copy, the new vinsn
+ may not be exactly equal to the one that is saved in the vector.
This is because the insn whose copy we're checking was possibly
substituted itself. */
- && (! compare_vinsns
+ && (! compare_vinsns
|| vinsn_equal_p (avinsn, new_vinsn)))
{
*indp = i;
return false;
}
-/* Search for a uid of INSN and NEW_VINSN in a sorted vector VECT. Return
- the position found or -1, if no such value is in vector.
+/* Search for a uid of INSN and NEW_VINSN in a sorted vector VECT. Return
+ the position found or -1, if no such value is in vector.
Search also for UIDs of insn's originators, if ORIGINATORS_P is true. */
int
-find_in_history_vect (VEC(expr_history_def, heap) *vect, rtx insn,
+find_in_history_vect (vec<expr_history_def> vect, rtx insn,
vinsn_t new_vinsn, bool originators_p)
{
int ind;
- if (find_in_history_vect_1 (vect, INSN_UID (insn), new_vinsn,
+ if (find_in_history_vect_1 (vect, INSN_UID (insn), new_vinsn,
false, &ind))
return ind;
if (find_in_history_vect_1 (vect, uid, new_vinsn, false, &ind))
return ind;
}
-
+
return -1;
}
-/* Insert new element in a sorted history vector pointed to by PVECT,
- if it is not there already. The element is searched using
+/* Insert new element in a sorted history vector pointed to by PVECT,
+ if it is not there already. The element is searched using
UID/NEW_EXPR_VINSN pair. TYPE, OLD_EXPR_VINSN and SPEC_DS save
the history of a transformation. */
void
-insert_in_history_vect (VEC (expr_history_def, heap) **pvect,
+insert_in_history_vect (vec<expr_history_def> *pvect,
unsigned uid, enum local_trans_type type,
- vinsn_t old_expr_vinsn, vinsn_t new_expr_vinsn,
+ vinsn_t old_expr_vinsn, vinsn_t new_expr_vinsn,
ds_t spec_ds)
{
- VEC(expr_history_def, heap) *vect = *pvect;
+ vec<expr_history_def> vect = *pvect;
expr_history_def temp;
bool res;
int ind;
if (res)
{
- expr_history_def *phist = VEC_index (expr_history_def, vect, ind);
+ expr_history_def *phist = &vect[ind];
- /* It is possible that speculation types of expressions that were
+ /* It is possible that speculation types of expressions that were
propagated through different paths will be different here. In this
case, merge the status to get the correct check later. */
if (phist->spec_ds != spec_ds)
phist->spec_ds = ds_max_merge (phist->spec_ds, spec_ds);
return;
}
-
+
temp.uid = uid;
temp.old_expr_vinsn = old_expr_vinsn;
- temp.new_expr_vinsn = new_expr_vinsn;
+ temp.new_expr_vinsn = new_expr_vinsn;
temp.spec_ds = spec_ds;
temp.type = type;
vinsn_attach (old_expr_vinsn);
vinsn_attach (new_expr_vinsn);
- VEC_safe_insert (expr_history_def, heap, vect, ind, &temp);
+ vect.safe_insert (ind, temp);
*pvect = vect;
}
/* Free history vector PVECT. */
static void
-free_history_vect (VEC (expr_history_def, heap) **pvect)
+free_history_vect (vec<expr_history_def> &pvect)
{
unsigned i;
expr_history_def *phist;
- if (! *pvect)
+ if (! pvect.exists ())
return;
-
- for (i = 0;
- VEC_iterate (expr_history_def, *pvect, i, phist);
- i++)
+
+ for (i = 0; pvect.iterate (i, &phist); i++)
{
vinsn_detach (phist->old_expr_vinsn);
vinsn_detach (phist->new_expr_vinsn);
}
-
- VEC_free (expr_history_def, heap, *pvect);
- *pvect = NULL;
+
+ pvect.release ();
}
+/* Merge vector FROM to PVECT. */
+static void
+merge_history_vect (vec<expr_history_def> *pvect,
+ vec<expr_history_def> from)
+{
+ expr_history_def *phist;
+ int i;
+
+ /* We keep this vector sorted. */
+ for (i = 0; from.iterate (i, &phist); i++)
+ insert_in_history_vect (pvect, phist->uid, phist->type,
+ phist->old_expr_vinsn, phist->new_expr_vinsn,
+ phist->spec_ds);
+}
/* Compare two vinsns as rhses if possible and as vinsns otherwise. */
bool
return false;
repcf = targetm.sched.skip_rtx_p ? skip_unspecs_callback : NULL;
- if (VINSN_SEPARABLE_P (x))
+ if (VINSN_SEPARABLE_P (x))
{
/* Compare RHSes of VINSNs. */
gcc_assert (VINSN_RHS (x));
init_expr (expr_t expr, vinsn_t vi, int spec, int use, int priority,
int sched_times, int orig_bb_index, ds_t spec_done_ds,
ds_t spec_to_check_ds, int orig_sched_cycle,
- VEC(expr_history_def, heap) *history, bool target_available,
+ vec<expr_history_def> history,
+ signed char target_available,
bool was_substituted, bool was_renamed, bool needs_spec_check_p,
bool cant_move)
{
EXPR_SPEC_DONE_DS (expr) = spec_done_ds;
EXPR_SPEC_TO_CHECK_DS (expr) = spec_to_check_ds;
- if (history)
+ if (history.exists ())
EXPR_HISTORY_OF_CHANGES (expr) = history;
else
- EXPR_HISTORY_OF_CHANGES (expr) = NULL;
+ EXPR_HISTORY_OF_CHANGES (expr).create (0);
EXPR_TARGET_AVAILABLE (expr) = target_available;
EXPR_WAS_SUBSTITUTED (expr) = was_substituted;
void
copy_expr (expr_t to, expr_t from)
{
- VEC(expr_history_def, heap) *temp = NULL;
+ vec<expr_history_def> temp = vNULL;
- if (EXPR_HISTORY_OF_CHANGES (from))
+ if (EXPR_HISTORY_OF_CHANGES (from).exists ())
{
unsigned i;
expr_history_def *phist;
- temp = VEC_copy (expr_history_def, heap, EXPR_HISTORY_OF_CHANGES (from));
- for (i = 0;
- VEC_iterate (expr_history_def, temp, i, phist);
+ temp = EXPR_HISTORY_OF_CHANGES (from).copy ();
+ for (i = 0;
+ temp.iterate (i, &phist);
i++)
{
vinsn_attach (phist->old_expr_vinsn);
}
}
- init_expr (to, EXPR_VINSN (from), EXPR_SPEC (from),
+ init_expr (to, EXPR_VINSN (from), EXPR_SPEC (from),
EXPR_USEFULNESS (from), EXPR_PRIORITY (from),
EXPR_SCHED_TIMES (from), EXPR_ORIG_BB_INDEX (from),
- EXPR_SPEC_DONE_DS (from), EXPR_SPEC_TO_CHECK_DS (from),
+ EXPR_SPEC_DONE_DS (from), EXPR_SPEC_TO_CHECK_DS (from),
EXPR_ORIG_SCHED_CYCLE (from), temp,
- EXPR_TARGET_AVAILABLE (from), EXPR_WAS_SUBSTITUTED (from),
+ EXPR_TARGET_AVAILABLE (from), EXPR_WAS_SUBSTITUTED (from),
EXPR_WAS_RENAMED (from), EXPR_NEEDS_SPEC_CHECK_P (from),
EXPR_CANT_MOVE (from));
}
-/* Same, but the final expr will not ever be in av sets, so don't copy
+/* Same, but the final expr will not ever be in av sets, so don't copy
"uninteresting" data such as bitmap cache. */
void
copy_expr_onside (expr_t to, expr_t from)
{
init_expr (to, EXPR_VINSN (from), EXPR_SPEC (from), EXPR_USEFULNESS (from),
EXPR_PRIORITY (from), EXPR_SCHED_TIMES (from), 0,
- EXPR_SPEC_DONE_DS (from), EXPR_SPEC_TO_CHECK_DS (from), 0, NULL,
+ EXPR_SPEC_DONE_DS (from), EXPR_SPEC_TO_CHECK_DS (from), 0,
+ vNULL,
EXPR_TARGET_AVAILABLE (from), EXPR_WAS_SUBSTITUTED (from),
EXPR_WAS_RENAMED (from), EXPR_NEEDS_SPEC_CHECK_P (from),
EXPR_CANT_MOVE (from));
{
expr_t expr = INSN_EXPR (insn);
ds_t ds;
-
+
INSN_SEQNO (insn) = seqno;
EXPR_ORIG_BB_INDEX (expr) = BLOCK_NUM (insn);
EXPR_SPEC (expr) = 0;
if (ds)
EXPR_SPEC_DONE_DS (expr) = ds_get_max_dep_weak (ds);
- free_history_vect (&EXPR_HISTORY_OF_CHANGES (expr));
+ free_history_vect (EXPR_HISTORY_OF_CHANGES (expr));
}
/* Update target_available bits when merging exprs TO and FROM. SPLIT_POINT
- is non-null when expressions are merged from different successors at
+ is non-null when expressions are merged from different successors at
a split point. */
static void
update_target_availability (expr_t to, expr_t from, insn_t split_point)
{
- if (EXPR_TARGET_AVAILABLE (to) < 0
+ if (EXPR_TARGET_AVAILABLE (to) < 0
|| EXPR_TARGET_AVAILABLE (from) < 0)
EXPR_TARGET_AVAILABLE (to) = -1;
else
toind = EXPR_ORIG_BB_INDEX (to);
fromind = EXPR_ORIG_BB_INDEX (from);
-
+
if (toind && toind == fromind)
- /* Do nothing -- everything is done in
+ /* Do nothing -- everything is done in
merge_with_other_exprs. */
;
else
EXPR_TARGET_AVAILABLE (to) = -1;
}
+ else if (EXPR_TARGET_AVAILABLE (from) == 0
+ && EXPR_LHS (from)
+ && REG_P (EXPR_LHS (from))
+ && REGNO (EXPR_LHS (to)) != REGNO (EXPR_LHS (from)))
+ EXPR_TARGET_AVAILABLE (to) = -1;
else
EXPR_TARGET_AVAILABLE (to) &= EXPR_TARGET_AVAILABLE (from);
}
}
/* Update speculation bits when merging exprs TO and FROM. SPLIT_POINT
- is non-null when expressions are merged from different successors at
+ is non-null when expressions are merged from different successors at
a split point. */
static void
update_speculative_bits (expr_t to, expr_t from, insn_t split_point)
old_to_ds = EXPR_SPEC_DONE_DS (to);
old_from_ds = EXPR_SPEC_DONE_DS (from);
-
+
EXPR_SPEC_DONE_DS (to) = ds_max_merge (old_to_ds, old_from_ds);
EXPR_SPEC_TO_CHECK_DS (to) |= EXPR_SPEC_TO_CHECK_DS (from);
EXPR_NEEDS_SPEC_CHECK_P (to) |= EXPR_NEEDS_SPEC_CHECK_P (from);
/* When merging e.g. control & data speculative exprs, or a control
- speculative with a control&data speculative one, we really have
+ speculative with a control&data speculative one, we really have
to change vinsn too. Also, when speculative status is changed,
we also need to record this as a transformation in expr's history. */
if ((old_to_ds & SPECULATIVE) || (old_from_ds & SPECULATIVE))
{
old_to_ds = ds_get_speculation_types (old_to_ds);
old_from_ds = ds_get_speculation_types (old_from_ds);
-
+
if (old_to_ds != old_from_ds)
{
ds_t record_ds;
-
- /* When both expressions are speculative, we need to change
+
+ /* When both expressions are speculative, we need to change
the vinsn first. */
if ((old_to_ds & SPECULATIVE) && (old_from_ds & SPECULATIVE))
{
int res;
-
+
res = speculate_expr (to, EXPR_SPEC_DONE_DS (to));
gcc_assert (res >= 0);
}
record_ds = EXPR_SPEC_DONE_DS (to) & SPECULATIVE;
record_ds &= ~(old_to_ds & SPECULATIVE);
record_ds &= ~(old_from_ds & SPECULATIVE);
-
- insert_in_history_vect (&EXPR_HISTORY_OF_CHANGES (to),
- INSN_UID (split_point), TRANS_SPECULATION,
+
+ insert_in_history_vect (&EXPR_HISTORY_OF_CHANGES (to),
+ INSN_UID (split_point), TRANS_SPECULATION,
EXPR_VINSN (from), EXPR_VINSN (to),
record_ds);
}
void
merge_expr_data (expr_t to, expr_t from, insn_t split_point)
{
- int i;
- expr_history_def *phist;
-
- /* For now, we just set the spec of resulting expr to be minimum of the specs
- of merged exprs. */
- if (EXPR_SPEC (to) > EXPR_SPEC (from))
+ /* Choose the maximum of the specs of merged exprs. This is required
+ for correctness of bookkeeping. */
+ if (EXPR_SPEC (to) < EXPR_SPEC (from))
EXPR_SPEC (to) = EXPR_SPEC (from);
if (split_point)
EXPR_USEFULNESS (to) += EXPR_USEFULNESS (from);
else
- EXPR_USEFULNESS (to) = MAX (EXPR_USEFULNESS (to),
+ EXPR_USEFULNESS (to) = MAX (EXPR_USEFULNESS (to),
EXPR_USEFULNESS (from));
if (EXPR_PRIORITY (to) < EXPR_PRIORITY (from))
if (EXPR_ORIG_BB_INDEX (to) != EXPR_ORIG_BB_INDEX (from))
EXPR_ORIG_BB_INDEX (to) = 0;
- EXPR_ORIG_SCHED_CYCLE (to) = MIN (EXPR_ORIG_SCHED_CYCLE (to),
+ EXPR_ORIG_SCHED_CYCLE (to) = MIN (EXPR_ORIG_SCHED_CYCLE (to),
EXPR_ORIG_SCHED_CYCLE (from));
- /* We keep this vector sorted. */
- for (i = 0;
- VEC_iterate (expr_history_def, EXPR_HISTORY_OF_CHANGES (from),
- i, phist);
- i++)
- insert_in_history_vect (&EXPR_HISTORY_OF_CHANGES (to),
- phist->uid, phist->type,
- phist->old_expr_vinsn, phist->new_expr_vinsn,
- phist->spec_ds);
-
EXPR_WAS_SUBSTITUTED (to) |= EXPR_WAS_SUBSTITUTED (from);
EXPR_WAS_RENAMED (to) |= EXPR_WAS_RENAMED (from);
EXPR_CANT_MOVE (to) |= EXPR_CANT_MOVE (from);
+ merge_history_vect (&EXPR_HISTORY_OF_CHANGES (to),
+ EXPR_HISTORY_OF_CHANGES (from));
update_target_availability (to, from, split_point);
update_speculative_bits (to, from, split_point);
}
/* Merge bits of FROM expr to TO expr. Vinsns in the exprs should be equal
- in terms of vinsn_equal_p. SPLIT_POINT is non-null when expressions
+ in terms of vinsn_equal_p. SPLIT_POINT is non-null when expressions
are merged from different successors at a split point. */
void
merge_expr (expr_t to, expr_t from, insn_t split_point)
/* Make sure that speculative pattern is propagated into exprs that
have non-speculative one. This will provide us with consistent
speculative bits and speculative patterns inside expr. */
- if (EXPR_SPEC_DONE_DS (to) == 0
- && EXPR_SPEC_DONE_DS (from) != 0)
+ if ((EXPR_SPEC_DONE_DS (from) != 0
+ && EXPR_SPEC_DONE_DS (to) == 0)
+ /* Do likewise for volatile insns, so that we always retain
+ the may_trap_p bit on the resulting expression. */
+ || (VINSN_MAY_TRAP_P (EXPR_VINSN (from))
+ && !VINSN_MAY_TRAP_P (EXPR_VINSN (to))))
change_vinsn_in_expr (to, EXPR_VINSN (from));
merge_expr_data (to, from, split_point);
void
clear_expr (expr_t expr)
{
-
+
vinsn_detach (EXPR_VINSN (expr));
EXPR_VINSN (expr) = NULL;
- free_history_vect (&EXPR_HISTORY_OF_CHANGES (expr));
+ free_history_vect (EXPR_HISTORY_OF_CHANGES (expr));
}
/* For a given LV_SET, mark EXPR having unavailable target register. */
if (EXPR_SEPARABLE_P (expr))
{
if (REG_P (EXPR_LHS (expr))
- && bitmap_bit_p (lv_set, REGNO (EXPR_LHS (expr))))
+ && register_unavailable_p (lv_set, EXPR_LHS (expr)))
{
- /* If it's an insn like r1 = use (r1, ...), and it exists in
- different forms in each of the av_sets being merged, we can't say
- whether original destination register is available or not.
- However, this still works if destination register is not used
+ /* If it's an insn like r1 = use (r1, ...), and it exists in
+ different forms in each of the av_sets being merged, we can't say
+ whether original destination register is available or not.
+ However, this still works if destination register is not used
in the original expression: if the branch at which LV_SET we're
looking here is not actually 'other branch' in sense that same
- expression is available through it (but it can't be determined
+ expression is available through it (but it can't be determined
at computation stage because of transformations on one of the
- branches), it still won't affect the availability.
- Liveness of a register somewhere on a code motion path means
- it's either read somewhere on a codemotion path, live on
+ branches), it still won't affect the availability.
+ Liveness of a register somewhere on a code motion path means
+ it's either read somewhere on a codemotion path, live on
'other' branch, live at the point immediately following
the original operation, or is read by the original operation.
The latter case is filtered out in the condition below.
miss a unifying code motion along both branches using a renamed
register, but it won't affect a code correctness since upon
an actual code motion a bookkeeping code would be generated. */
- if (bitmap_bit_p (VINSN_REG_USES (EXPR_VINSN (expr)),
- REGNO (EXPR_LHS (expr))))
+ if (register_unavailable_p (VINSN_REG_USES (EXPR_VINSN (expr)),
+ EXPR_LHS (expr)))
EXPR_TARGET_AVAILABLE (expr) = -1;
else
EXPR_TARGET_AVAILABLE (expr) = false;
{
unsigned regno;
reg_set_iterator rsi;
-
- EXECUTE_IF_SET_IN_REG_SET (VINSN_REG_SETS (EXPR_VINSN (expr)),
+
+ EXECUTE_IF_SET_IN_REG_SET (VINSN_REG_SETS (EXPR_VINSN (expr)),
0, regno, rsi)
if (bitmap_bit_p (lv_set, regno))
{
}
}
-/* Try to make EXPR speculative. Return 1 when EXPR's pattern
+/* Try to make EXPR speculative. Return 1 when EXPR's pattern
or dependence status have changed, 2 when also the target register
became unavailable, 0 if nothing had to be changed. */
int
speculate_expr (expr_t expr, ds_t ds)
{
int res;
- rtx orig_insn_rtx;
+ rtx_insn *orig_insn_rtx;
rtx spec_pat;
ds_t target_ds, current_ds;
case 0:
EXPR_SPEC_DONE_DS (expr) = ds;
return current_ds != ds ? 1 : 0;
-
+
case 1:
{
- rtx spec_insn_rtx = create_insn_rtx_from_pattern (spec_pat, NULL_RTX);
+ rtx_insn *spec_insn_rtx =
+ create_insn_rtx_from_pattern (spec_pat, NULL_RTX);
vinsn_t spec_vinsn = create_vinsn_from_insn_rtx (spec_insn_rtx, false);
change_vinsn_in_expr (expr, spec_vinsn);
EXPR_SPEC_DONE_DS (expr) = ds;
EXPR_NEEDS_SPEC_CHECK_P (expr) = true;
- /* Do not allow clobbering the address register of speculative
+ /* Do not allow clobbering the address register of speculative
insns. */
- if (bitmap_bit_p (VINSN_REG_USES (EXPR_VINSN (expr)),
- expr_dest_regno (expr)))
+ if (register_unavailable_p (VINSN_REG_USES (EXPR_VINSN (expr)),
+ expr_dest_reg (expr)))
{
EXPR_TARGET_AVAILABLE (expr) = false;
return 2;
return REGNO (dest);
}
-/* For a given LV_SET, mark all expressions in JOIN_SET, but not present in
+/* For a given LV_SET, mark all expressions in JOIN_SET, but not present in
AV_SET having unavailable target register. */
void
mark_unavailable_targets (av_set_t join_set, av_set_t av_set, regset lv_set)
}
\f
+/* Returns true if REG (at least partially) is present in REGS. */
+bool
+register_unavailable_p (regset regs, rtx reg)
+{
+ unsigned regno, end_regno;
+
+ regno = REGNO (reg);
+ if (bitmap_bit_p (regs, regno))
+ return true;
+
+ end_regno = END_REGNO (reg);
+
+ while (++regno < end_regno)
+ if (bitmap_bit_p (regs, regno))
+ return true;
+
+ return false;
+}
+
/* Av set functions. */
/* Add a new element to av set SETP.
av_set_add (av_set_t *setp, expr_t expr)
{
av_set_t elem;
-
+
gcc_assert (!INSN_NOP_P (EXPR_INSN_RTX (expr)));
elem = av_set_add_element (setp);
copy_expr (_AV_SET_EXPR (elem), expr);
EXPR_USEFULNESS (expr2) = 0;
merge_expr (expr2, expr, NULL);
-
+
/* Fix usefulness as it should be now REG_BR_PROB_BASE. */
EXPR_USEFULNESS (expr2) = REG_BR_PROB_BASE;
-
+
av_set_iter_remove (ip);
return expr2;
}
join_distinct_sets (i.lp, fromp);
}
-/* Same as above, but also update availability of target register in
+/* Same as above, but also update availability of target register in
TOP judging by TO_LV_SET and FROM_LV_SET. */
void
av_set_union_and_live (av_set_t *top, av_set_t *fromp, regset to_lv_set,
if (expr2)
{
- /* It may be that the expressions have different destination
+ /* It may be that the expressions have different destination
registers, in which case we need to check liveness here. */
if (EXPR_SEPARABLE_P (expr1))
{
- int regno1 = (REG_P (EXPR_LHS (expr1))
+ int regno1 = (REG_P (EXPR_LHS (expr1))
? (int) expr_dest_regno (expr1) : -1);
- int regno2 = (REG_P (EXPR_LHS (expr2))
+ int regno2 = (REG_P (EXPR_LHS (expr2))
? (int) expr_dest_regno (expr2) : -1);
-
- /* ??? We don't have a way to check restrictions for
+
+ /* ??? We don't have a way to check restrictions for
*other* register on the current path, we did it only
for the current target register. Give up. */
if (regno1 != regno2)
av_set_iter_remove (&i);
}
else
- /* EXPR1 is present in TOP, but not in FROMP. Check it on
+ /* EXPR1 is present in TOP, but not in FROMP. Check it on
FROM_LV_SET. */
set_unavailable_target_for_expr (expr1, from_lv_set);
}
av_set_iterator i;
bool has_one_nonspec = false;
- /* Keep all speculative exprs, and leave one non-speculative
+ /* Keep all speculative exprs, and leave one non-speculative
(the first one). */
FOR_EACH_EXPR_1 (expr, i, setp)
{
av_set_iter_remove (&i);
}
-/* Multiplies usefulness attribute of each member of av-set *AVP by
+/* Multiplies usefulness attribute of each member of av-set *AVP by
value PROB / ALL_PROB. */
void
av_set_split_usefulness (av_set_t av, int prob, int all_prob)
expr_t expr;
FOR_EACH_EXPR (expr, i, av)
- EXPR_USEFULNESS (expr) = (all_prob
+ EXPR_USEFULNESS (expr) = (all_prob
? (EXPR_USEFULNESS (expr) * prob) / all_prob
: 0);
}
/* Leave in AVP only those expressions, which are present in AV,
- and return it. */
+ and return it, merging history expressions. */
void
-av_set_intersect (av_set_t *avp, av_set_t av)
+av_set_code_motion_filter (av_set_t *avp, av_set_t av)
{
av_set_iterator i;
- expr_t expr;
+ expr_t expr, expr2;
FOR_EACH_EXPR_1 (expr, i, avp)
- if (av_set_lookup (av, EXPR_VINSN (expr)) == NULL)
+ if ((expr2 = av_set_lookup (av, EXPR_VINSN (expr))) == NULL)
av_set_iter_remove (&i);
+ else
+ /* When updating av sets in bookkeeping blocks, we can add more insns
+ there which will be transformed but the upper av sets will not
+ reflect those transformations. We then fail to undo those
+ when searching for such insns. So merge the history saved
+ in the av set of the block we are processing. */
+ merge_history_vect (&EXPR_HISTORY_OF_CHANGES (expr),
+ EXPR_HISTORY_OF_CHANGES (expr2));
}
\f
} deps_init_id_data;
-/* Setup ID for INSN. FORCE_UNIQUE_P is true when INSN should not be
+/* Setup ID for INSN. FORCE_UNIQUE_P is true when INSN should not be
clonable. */
static void
setup_id_for_insn (idata_t id, insn_t insn, bool force_unique_p)
{
int type;
-
+
/* Determine whether INSN could be cloned and return appropriate vinsn type.
That clonable insns which can be separated into lhs and rhs have type SET.
Other clonable insns have type USE. */
type = PC;
else if (type == DEBUG_INSN)
type = !force_unique_p ? USE : INSN;
-
+
IDATA_TYPE (id) = type;
IDATA_REG_SETS (id) = get_clear_regset_from_pool ();
IDATA_REG_USES (id) = get_clear_regset_from_pool ();
SET_REGNO_REG_SET (IDATA_REG_SETS (deps_init_id_data.id), regno);
#ifdef STACK_REGS
- /* Make instructions that set stack registers to be ineligible for
+ /* Make instructions that set stack registers to be ineligible for
renaming to avoid issues with find_used_regs. */
if (IN_RANGE (regno, FIRST_STACK_REG, LAST_STACK_REG))
deps_init_id_data.force_use_p = true;
if (lhs == NULL || rhs == NULL || !lhs_and_rhs_separable_p (lhs, rhs)
|| deps_init_id_data.force_use_p)
{
- /* This should be a USE, as we don't want to schedule its RHS
+ /* This should be a USE, as we don't want to schedule its RHS
separately. However, we still want to have them recorded
- for the purposes of substitution. That's why we don't
+ for the purposes of substitution. That's why we don't
simply call downgrade_to_use () here. */
gcc_assert (IDATA_TYPE (deps_init_id_data.id) == SET);
gcc_assert (!lhs == !rhs);
setup_id_lhs_rhs (idata_t id, insn_t insn, bool force_unique_p)
{
rtx pat = PATTERN (insn);
-
+
if (NONJUMP_INSN_P (insn)
- && GET_CODE (pat) == SET
+ && GET_CODE (pat) == SET
&& !force_unique_p)
{
IDATA_RHS (id) = SET_SRC (pat);
maybe_downgrade_id_to_use (idata_t id, insn_t insn)
{
bool must_be_use = false;
- unsigned uid = INSN_UID (insn);
- df_ref *rec;
+ df_ref def;
rtx lhs = IDATA_LHS (id);
rtx rhs = IDATA_RHS (id);
-
+
/* We downgrade only SETs. */
if (IDATA_TYPE (id) != SET)
return;
IDATA_TYPE (id) = USE;
return;
}
-
- for (rec = DF_INSN_UID_DEFS (uid); *rec; rec++)
+
+ FOR_EACH_INSN_DEF (def, insn)
{
- df_ref def = *rec;
-
if (DF_REF_INSN (def)
&& DF_REF_FLAGS_IS_SET (def, DF_REF_PRE_POST_MODIFY)
&& loc_mentioned_in_p (DF_REF_LOC (def), IDATA_RHS (id)))
}
#ifdef STACK_REGS
- /* Make instructions that set stack registers to be ineligible for
+ /* Make instructions that set stack registers to be ineligible for
renaming to avoid issues with find_used_regs. */
if (IN_RANGE (DF_REF_REGNO (def), FIRST_STACK_REG, LAST_STACK_REG))
{
break;
}
#endif
- }
-
+ }
+
if (must_be_use)
IDATA_TYPE (id) = USE;
}
static void
setup_id_reg_sets (idata_t id, insn_t insn)
{
- unsigned uid = INSN_UID (insn);
- df_ref *rec;
+ struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
+ df_ref def, use;
regset tmp = get_clear_regset_from_pool ();
-
- for (rec = DF_INSN_UID_DEFS (uid); *rec; rec++)
+
+ FOR_EACH_INSN_INFO_DEF (def, insn_info)
{
- df_ref def = *rec;
unsigned int regno = DF_REF_REGNO (def);
-
+
/* Post modifies are treated like clobbers by sched-deps.c. */
if (DF_REF_FLAGS_IS_SET (def, (DF_REF_MUST_CLOBBER
| DF_REF_PRE_POST_MODIFY)))
SET_REGNO_REG_SET (IDATA_REG_SETS (id), regno);
#ifdef STACK_REGS
- /* For stack registers, treat writes to them as writes
+ /* For stack registers, treat writes to them as writes
to the first one to be consistent with sched-deps.c. */
if (IN_RANGE (regno, FIRST_STACK_REG, LAST_STACK_REG))
SET_REGNO_REG_SET (IDATA_REG_SETS (id), FIRST_STACK_REG);
|| regno == STACK_POINTER_REGNUM)
bitmap_set_bit (tmp, regno);
}
-
- for (rec = DF_INSN_UID_USES (uid); *rec; rec++)
+
+ FOR_EACH_INSN_INFO_USE (use, insn_info)
{
- df_ref use = *rec;
unsigned int regno = DF_REF_REGNO (use);
/* When these refs are met for the first time, skip them, as
SET_REGNO_REG_SET (IDATA_REG_USES (id), regno);
#ifdef STACK_REGS
- /* For stack registers, treat reads from them as reads from
+ /* For stack registers, treat reads from them as reads from
the first one to be consistent with sched-deps.c. */
if (IN_RANGE (regno, FIRST_STACK_REG, LAST_STACK_REG))
SET_REGNO_REG_SET (IDATA_REG_USES (id), FIRST_STACK_REG);
static void
deps_init_id (idata_t id, insn_t insn, bool force_unique_p)
{
- struct deps _dc, *dc = &_dc;
+ struct deps_desc _dc, *dc = &_dc;
deps_init_id_data.where = DEPS_IN_NOWHERE;
deps_init_id_data.id = id;
deps_init_id_data.force_unique_p = force_unique_p;
deps_init_id_data.force_use_p = false;
- init_deps (dc);
+ init_deps (dc, false);
memcpy (&deps_init_id_sched_deps_info,
&const_deps_init_id_sched_deps_info,
}
\f
+struct sched_scan_info_def
+{
+ /* This hook notifies scheduler frontend to extend its internal per basic
+ block data structures. This hook should be called once before a series of
+ calls to bb_init (). */
+ void (*extend_bb) (void);
+
+ /* This hook makes scheduler frontend to initialize its internal data
+ structures for the passed basic block. */
+ void (*init_bb) (basic_block);
+
+ /* This hook notifies scheduler frontend to extend its internal per insn data
+ structures. This hook should be called once before a series of calls to
+ insn_init (). */
+ void (*extend_insn) (void);
+
+ /* This hook makes scheduler frontend to initialize its internal data
+ structures for the passed insn. */
+ void (*init_insn) (insn_t);
+};
+
+/* A driver function to add a set of basic blocks (BBS) to the
+ scheduling region. */
+static void
+sched_scan (const struct sched_scan_info_def *ssi, bb_vec_t bbs)
+{
+ unsigned i;
+ basic_block bb;
+
+ if (ssi->extend_bb)
+ ssi->extend_bb ();
+
+ if (ssi->init_bb)
+ FOR_EACH_VEC_ELT (bbs, i, bb)
+ ssi->init_bb (bb);
+
+ if (ssi->extend_insn)
+ ssi->extend_insn ();
+
+ if (ssi->init_insn)
+ FOR_EACH_VEC_ELT (bbs, i, bb)
+ {
+ rtx_insn *insn;
+
+ FOR_BB_INSNS (bb, insn)
+ ssi->init_insn (insn);
+ }
+}
/* Implement hooks for collecting fundamental insn properties like if insn is
an ASM or is within a SCHED_GROUP. */
static int
eq_transformed_insns (const void *p, const void *q)
{
- rtx i1 = VINSN_INSN_RTX (((const struct transformed_insns *) p)->vinsn_old);
- rtx i2 = VINSN_INSN_RTX (((const struct transformed_insns *) q)->vinsn_old);
+ rtx_insn *i1 =
+ VINSN_INSN_RTX (((const struct transformed_insns *) p)->vinsn_old);
+ rtx_insn *i2 =
+ VINSN_INSN_RTX (((const struct transformed_insns *) q)->vinsn_old);
if (INSN_UID (i1) == INSN_UID (i2))
return 1;
free (pti);
}
-/* Init the s_i_d data for INSN which should be inited just once, when
+/* Init the s_i_d data for INSN which should be inited just once, when
we first see the insn. */
static void
init_first_time_insn_data (insn_t insn)
/* This should not be set if this is the first time we init data for
insn. */
gcc_assert (first_time_insn_init (insn));
-
+
/* These are needed for nops too. */
INSN_LIVE (insn) = get_regset_from_pool ();
INSN_LIVE_VALID_P (insn) = false;
-
+
if (!INSN_NOP_P (insn))
{
INSN_ANALYZED_DEPS (insn) = BITMAP_ALLOC (NULL);
INSN_FOUND_DEPS (insn) = BITMAP_ALLOC (NULL);
- INSN_TRANSFORMED_INSNS (insn)
+ INSN_TRANSFORMED_INSNS (insn)
= htab_create (16, hash_transformed_insns,
eq_transformed_insns, free_transformed_insns);
- init_deps (&INSN_DEPS_CONTEXT (insn));
+ init_deps (&INSN_DEPS_CONTEXT (insn), true);
}
}
-/* Free the same data as above for INSN. */
-static void
-free_first_time_insn_data (insn_t insn)
+/* Free almost all above data for INSN that is scheduled already.
+ Used for extra-large basic blocks. */
+void
+free_data_for_scheduled_insn (insn_t insn)
{
gcc_assert (! first_time_insn_init (insn));
+ if (! INSN_ANALYZED_DEPS (insn))
+ return;
+
BITMAP_FREE (INSN_ANALYZED_DEPS (insn));
BITMAP_FREE (INSN_FOUND_DEPS (insn));
htab_delete (INSN_TRANSFORMED_INSNS (insn));
- return_regset_to_pool (INSN_LIVE (insn));
- INSN_LIVE (insn) = NULL;
- INSN_LIVE_VALID_P (insn) = false;
/* This is allocated only for bookkeeping insns. */
if (INSN_ORIGINATORS (insn))
BITMAP_FREE (INSN_ORIGINATORS (insn));
free_deps (&INSN_DEPS_CONTEXT (insn));
+
+ INSN_ANALYZED_DEPS (insn) = NULL;
+
+ /* Clear the readonly flag so we would ICE when trying to recalculate
+ the deps context (as we believe that it should not happen). */
+ (&INSN_DEPS_CONTEXT (insn))->readonly = 0;
+}
+
+/* Free the same data as above for INSN. */
+static void
+free_first_time_insn_data (insn_t insn)
+{
+ gcc_assert (! first_time_insn_init (insn));
+
+ free_data_for_scheduled_insn (insn);
+ return_regset_to_pool (INSN_LIVE (insn));
+ INSN_LIVE (insn) = NULL;
+ INSN_LIVE_VALID_P (insn) = false;
}
/* Initialize region-scope data structures for basic blocks. */
if (NOTE_INSN_BASIC_BLOCK_P (insn))
{
- init_global_data.prev_insn = NULL_RTX;
+ init_global_data.prev_insn = NULL;
return;
}
init_global_data.prev_insn = insn;
}
else
- init_global_data.prev_insn = NULL_RTX;
+ init_global_data.prev_insn = NULL;
if (GET_CODE (PATTERN (insn)) == ASM_INPUT
|| asm_noperands (PATTERN (insn)) >= 0)
bool force_unique_p;
ds_t spec_done_ds;
- /* Certain instructions cannot be cloned. */
- if (CANT_MOVE (insn)
- || INSN_ASM_P (insn)
- || SCHED_GROUP_P (insn)
- || prologue_epilogue_contains (insn)
- /* Exception handling insns are always unique. */
- || (flag_non_call_exceptions && can_throw_internal (insn))
- /* TRAP_IF though have an INSN code is control_flow_insn_p (). */
- || control_flow_insn_p (insn))
- force_unique_p = true;
+ /* Certain instructions cannot be cloned, and frame related insns and
+ the insn adjacent to NOTE_INSN_EPILOGUE_BEG cannot be moved out of
+ their block. */
+ if (prologue_epilogue_contains (insn))
+ {
+ if (RTX_FRAME_RELATED_P (insn))
+ CANT_MOVE (insn) = 1;
+ else
+ {
+ rtx note;
+ for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
+ if (REG_NOTE_KIND (note) == REG_SAVE_NOTE
+ && ((enum insn_note) INTVAL (XEXP (note, 0))
+ == NOTE_INSN_EPILOGUE_BEG))
+ {
+ CANT_MOVE (insn) = 1;
+ break;
+ }
+ }
+ force_unique_p = true;
+ }
else
- force_unique_p = false;
+ if (CANT_MOVE (insn)
+ || INSN_ASM_P (insn)
+ || SCHED_GROUP_P (insn)
+ || CALL_P (insn)
+ /* Exception handling insns are always unique. */
+ || (cfun->can_throw_non_call_exceptions && can_throw_internal (insn))
+ /* TRAP_IF though have an INSN code is control_flow_insn_p (). */
+ || control_flow_insn_p (insn)
+ || volatile_insn_p (PATTERN (insn))
+ || (targetm.cannot_copy_insn_p
+ && targetm.cannot_copy_insn_p (insn)))
+ force_unique_p = true;
+ else
+ force_unique_p = false;
if (targetm.sched.get_insn_spec_ds)
{
/* Initialize INSN's expr. */
init_expr (INSN_EXPR (insn), vinsn_create (insn, force_unique_p), 0,
REG_BR_PROB_BASE, INSN_PRIORITY (insn), 0, BLOCK_NUM (insn),
- spec_done_ds, 0, 0, NULL, true, false, false, false,
- CANT_MOVE (insn));
+ spec_done_ds, 0, 0, vNULL, true,
+ false, false, false, CANT_MOVE (insn));
}
init_first_time_insn_data (insn);
extend_insn_data, /* extend_insn */
init_global_and_expr_for_insn /* init_insn */
};
-
- sched_scan (&ssi, bbs, NULL, NULL, NULL);
+
+ sched_scan (&ssi, bbs);
}
/* Finalize region-scope data structures for basic blocks. */
free_first_time_insn_data (insn);
INSN_WS_LEVEL (insn) = 0;
CANT_MOVE (insn) = 0;
-
- /* We can no longer assert this, as vinsns of this insn could be
- easily live in other insn's caches. This should be changed to
+
+ /* We can no longer assert this, as vinsns of this insn could be
+ easily live in other insn's caches. This should be changed to
a counter-like approach among all vinsns. */
gcc_assert (true || VINSN_COUNT (INSN_VINSN (insn)) == 1);
clear_expr (INSN_EXPR (insn));
bb_vec_t bbs;
int i;
- bbs = VEC_alloc (basic_block, heap, current_nr_blocks);
+ bbs.create (current_nr_blocks);
for (i = 0; i < current_nr_blocks; i++)
- VEC_quick_push (basic_block, bbs, BASIC_BLOCK (BB_TO_BLOCK (i)));
+ bbs.quick_push (BASIC_BLOCK_FOR_FN (cfun, BB_TO_BLOCK (i)));
/* Clear AV_SETs and INSN_EXPRs. */
{
finish_global_and_expr_insn /* init_insn */
};
- sched_scan (&ssi, bbs, NULL, NULL, NULL);
+ sched_scan (&ssi, bbs);
}
- VEC_free (basic_block, heap, bbs);
+ bbs.release ();
}
finish_insns ();
}
\f
-/* In the below hooks, we merely calculate whether or not a dependence
- exists, and in what part of insn. However, we will need more data
+/* In the below hooks, we merely calculate whether or not a dependence
+ exists, and in what part of insn. However, we will need more data
when we'll start caching dependence requests. */
/* Container to hold information for dependency analysis. */
|| reg_last->clobbers != NULL)
*dsp = (*dsp & ~SPECULATIVE) | DEP_OUTPUT;
- if (reg_last->uses)
+ if (reg_last->uses || reg_last->implicit_sets)
*dsp = (*dsp & ~SPECULATIVE) | DEP_ANTI;
}
}
if (reg_last->sets)
*dsp = (*dsp & ~SPECULATIVE) | DEP_OUTPUT;
-
- if (reg_last->uses)
+
+ if (reg_last->uses || reg_last->implicit_sets)
*dsp = (*dsp & ~SPECULATIVE) | DEP_ANTI;
}
}
if (reg_last->sets)
*dsp = (*dsp & ~SPECULATIVE) | DEP_TRUE;
- if (reg_last->clobbers)
+ if (reg_last->clobbers || reg_last->implicit_sets)
*dsp = (*dsp & ~SPECULATIVE) | DEP_ANTI;
- /* Handle BE_IN_SPEC. */
+ /* Merge BE_IN_SPEC bits into *DSP when the dependency producer
+ is actually a check insn. We need to do this for any register
+ read-read dependency with the check unless we track properly
+ all registers written by BE_IN_SPEC-speculated insns, as
+ we don't have explicit dependence lists. See PR 53975. */
if (reg_last->uses)
{
ds_t pro_spec_checked_ds;
pro_spec_checked_ds = ds_get_max_dep_weak (pro_spec_checked_ds);
if (pro_spec_checked_ds != 0)
- /* Merge BE_IN_SPEC bits into *DSP. */
*dsp = ds_full_merge (*dsp, pro_spec_checked_ds,
NULL_RTX, NULL_RTX);
}
{
int i;
ds_t ds;
- struct deps *dc;
+ struct deps_desc *dc;
if (INSN_SIMPLEJUMP_P (pred))
/* Unconditional jump is just a transfer of control flow.
return false;
dc = &INSN_DEPS_CONTEXT (pred);
+
+ /* We init this field lazily. */
+ if (dc->reg_last == NULL)
+ init_deps_reg_last (dc);
+
if (!dc->readonly)
{
has_dependence_data.pro = NULL;
/* Do not allow stores to memory to move through checks. Currently
we don't move this to sched-deps.c as the check doesn't have
- obvious places to which this dependence can be attached.
+ obvious places to which this dependence can be attached.
FIMXE: this should go to a hook. */
if (EXPR_LHS (expr)
&& MEM_P (EXPR_LHS (expr))
&& sel_insn_is_speculation_check (pred))
has_dependence_data.has_dep_p[DEPS_IN_INSN] = DEP_ANTI;
-
+
*has_dep_pp = has_dependence_data.has_dep_p;
ds = 0;
for (i = 0; i < DEPS_IN_NOWHERE; i++)
}
\f
-/* Dependence hooks implementation that checks dependence latency constraints
- on the insns being scheduled. The entry point for these routines is
- tick_check_p predicate. */
+/* Dependence hooks implementation that checks dependence latency constraints
+ on the insns being scheduled. The entry point for these routines is
+ tick_check_p predicate. */
static struct
{
tick_check_data.cycle = 0;
tick_check_data.seen_true_dep_p = false;
sched_deps_info = &tick_check_sched_deps_info;
-
+
gcc_assert (!dc->readonly);
dc->readonly = 1;
deps_analyze_insn (dc, EXPR_INSN_RTX (expr));
if (lhs == NULL || dest == NULL)
return false;
-
+
return rtx_equal_p (lhs, dest);
}
bool
sel_insn_is_speculation_check (rtx insn)
{
- return s_i_d && !! INSN_SPEC_CHECKED_DS (insn);
+ return s_i_d.exists () && !! INSN_SPEC_CHECKED_DS (insn);
}
-/* Extracts machine mode MODE and destination location DST_LOC
+/* Extracts machine mode MODE and destination location DST_LOC
for given INSN. */
void
-get_dest_and_mode (rtx insn, rtx *dst_loc, enum machine_mode *mode)
+get_dest_and_mode (rtx insn, rtx *dst_loc, machine_mode *mode)
{
rtx pat = PATTERN (insn);
*mode = GET_MODE (*dst_loc);
}
-/* Returns true when moving through JUMP will result in bookkeeping
+/* Returns true when moving through JUMP will result in bookkeeping
creation. */
bool
bookkeeping_can_be_created_if_moved_through_p (insn_t jump)
}
#ifdef ENABLE_CHECKING
-/* Check that the region we're scheduling still has at most one
+/* Check that the region we're scheduling still has at most one
backedge. */
static void
verify_backedges (void)
int i, n = 0;
edge e;
edge_iterator ei;
-
+
for (i = 0; i < current_nr_blocks; i++)
- FOR_EACH_EDGE (e, ei, BASIC_BLOCK (BB_TO_BLOCK (i))->succs)
+ FOR_EACH_EDGE (e, ei, BASIC_BLOCK_FOR_FN (cfun, BB_TO_BLOCK (i))->succs)
if (in_current_region_p (e->dest)
&& BLOCK_TO_BB (e->dest->index) < i)
n++;
-
+
gcc_assert (n <= 1);
}
}
/* Functions to work with control flow. */
+/* Recompute BLOCK_TO_BB and BB_FOR_BLOCK for current region so that blocks
+ are sorted in topological order (it might have been invalidated by
+ redirecting an edge). */
+static void
+sel_recompute_toporder (void)
+{
+ int i, n, rgn;
+ int *postorder, n_blocks;
+
+ postorder = XALLOCAVEC (int, n_basic_blocks_for_fn (cfun));
+ n_blocks = post_order_compute (postorder, false, false);
+
+ rgn = CONTAINING_RGN (BB_TO_BLOCK (0));
+ for (n = 0, i = n_blocks - 1; i >= 0; i--)
+ if (CONTAINING_RGN (postorder[i]) == rgn)
+ {
+ BLOCK_TO_BB (postorder[i]) = n;
+ BB_TO_BLOCK (n) = postorder[i];
+ n++;
+ }
+
+ /* Assert that we updated info for all blocks. We may miss some blocks if
+ this function is called when redirecting an edge made a block
+ unreachable, but that block is not deleted yet. */
+ gcc_assert (n == RGN_NR_BLOCKS (rgn));
+}
+
/* Tidy the possibly empty block BB. */
-bool
+static bool
maybe_tidy_empty_bb (basic_block bb)
{
- basic_block succ_bb, pred_bb;
+ basic_block succ_bb, pred_bb, note_bb;
+ vec<basic_block> dom_bbs;
edge e;
edge_iterator ei;
bool rescan_p;
/* Keep empty bb only if this block immediately precedes EXIT and
- has incoming non-fallthrough edge. Otherwise remove it. */
+ has incoming non-fallthrough edge, or it has no predecessors or
+ successors. Otherwise remove it. */
if (!sel_bb_empty_p (bb)
- || (single_succ_p (bb)
- && single_succ (bb) == EXIT_BLOCK_PTR
- && (!single_pred_p (bb)
- || !(single_pred_edge (bb)->flags & EDGE_FALLTHRU))))
+ || (single_succ_p (bb)
+ && single_succ (bb) == EXIT_BLOCK_PTR_FOR_FN (cfun)
+ && (!single_pred_p (bb)
+ || !(single_pred_edge (bb)->flags & EDGE_FALLTHRU)))
+ || EDGE_COUNT (bb->preds) == 0
+ || EDGE_COUNT (bb->succs) == 0)
return false;
/* Do not attempt to redirect complex edges. */
FOR_EACH_EDGE (e, ei, bb->preds)
if (e->flags & EDGE_COMPLEX)
return false;
+ else if (e->flags & EDGE_FALLTHRU)
+ {
+ rtx note;
+ /* If prev bb ends with asm goto, see if any of the
+ ASM_OPERANDS_LABELs don't point to the fallthru
+ label. Do not attempt to redirect it in that case. */
+ if (JUMP_P (BB_END (e->src))
+ && (note = extract_asm_operands (PATTERN (BB_END (e->src)))))
+ {
+ int i, n = ASM_OPERANDS_LABEL_LENGTH (note);
+
+ for (i = 0; i < n; ++i)
+ if (XEXP (ASM_OPERANDS_LABEL (note, i), 0) == BB_HEAD (bb))
+ return false;
+ }
+ }
free_data_sets (bb);
succ_bb = single_succ (bb);
rescan_p = true;
pred_bb = NULL;
+ dom_bbs.create (0);
+
+ /* Save a pred/succ from the current region to attach the notes to. */
+ note_bb = NULL;
+ FOR_EACH_EDGE (e, ei, bb->preds)
+ if (in_current_region_p (e->src))
+ {
+ note_bb = e->src;
+ break;
+ }
+ if (note_bb == NULL)
+ note_bb = succ_bb;
/* Redirect all non-fallthru edges to the next bb. */
while (rescan_p)
if (!(e->flags & EDGE_FALLTHRU))
{
+ /* We can not invalidate computed topological order by moving
+ the edge destination block (E->SUCC) along a fallthru edge.
+
+ We will update dominators here only when we'll get
+ an unreachable block when redirecting, otherwise
+ sel_redirect_edge_and_branch will take care of it. */
+ if (e->dest != bb
+ && single_pred_p (e->dest))
+ dom_bbs.safe_push (e->dest);
sel_redirect_edge_and_branch (e, succ_bb);
rescan_p = true;
break;
}
+ /* If the edge is fallthru, but PRED_BB ends in a conditional jump
+ to BB (so there is no non-fallthru edge from PRED_BB to BB), we
+ still have to adjust it. */
+ else if (single_succ_p (pred_bb) && any_condjump_p (BB_END (pred_bb)))
+ {
+ /* If possible, try to remove the unneeded conditional jump. */
+ if (INSN_SCHED_TIMES (BB_END (pred_bb)) == 0
+ && !IN_CURRENT_FENCE_P (BB_END (pred_bb)))
+ {
+ if (!sel_remove_insn (BB_END (pred_bb), false, false))
+ tidy_fallthru_edge (e);
+ }
+ else
+ sel_redirect_edge_and_branch (e, succ_bb);
+ rescan_p = true;
+ break;
+ }
}
}
- /* If it is possible - merge BB with its predecessor. */
if (can_merge_blocks_p (bb->prev_bb, bb))
sel_merge_blocks (bb->prev_bb, bb);
else
- /* Otherwise this is a block without fallthru predecessor.
- Just delete it. */
{
- gcc_assert (pred_bb != NULL);
-
- move_bb_info (pred_bb, bb);
+ /* This is a block without fallthru predecessor. Just delete it. */
+ gcc_assert (note_bb);
+ move_bb_info (note_bb, bb);
remove_empty_bb (bb, true);
}
-#ifdef ENABLE_CHECKING
- verify_backedges ();
-#endif
+ if (!dom_bbs.is_empty ())
+ {
+ dom_bbs.safe_push (succ_bb);
+ iterate_fix_dominators (CDI_DOMINATORS, dom_bbs, false);
+ dom_bbs.release ();
+ }
return true;
}
-/* Tidy the control flow after we have removed original insn from
+/* Tidy the control flow after we have removed original insn from
XBB. Return true if we have removed some blocks. When FULL_TIDYING
is true, also try to optimize control flow on non-empty blocks. */
bool
{
bool changed = true;
insn_t first, last;
-
+
/* First check whether XBB is empty. */
changed = maybe_tidy_empty_bb (xbb);
if (changed || !full_tidying)
return changed;
-
+
/* Check if there is a unnecessary jump after insn left. */
- if (jump_leads_only_to_bb_p (BB_END (xbb), xbb->next_bb)
+ if (bb_has_removable_jump_to_p (xbb, xbb->next_bb)
&& INSN_SCHED_TIMES (BB_END (xbb)) == 0
&& !IN_CURRENT_FENCE_P (BB_END (xbb)))
{
while (first != last && (DEBUG_INSN_P (last) || NOTE_P (last)));
}
/* Check if there is an unnecessary jump in previous basic block leading
- to next basic block left after removing INSN from stream.
- If it is so, remove that jump and redirect edge to current
- basic block (where there was INSN before deletion). This way
- when NOP will be deleted several instructions later with its
- basic block we will not get a jump to next instruction, which
+ to next basic block left after removing INSN from stream.
+ If it is so, remove that jump and redirect edge to current
+ basic block (where there was INSN before deletion). This way
+ when NOP will be deleted several instructions later with its
+ basic block we will not get a jump to next instruction, which
can be harmful. */
if (first == last
&& !sel_bb_empty_p (xbb)
&& EDGE_COUNT (xbb->succs) == 1
&& (EDGE_SUCC (xbb, 0)->flags & EDGE_FALLTHRU)
/* When successor is an EXIT block, it may not be the next block. */
- && single_succ (xbb) != EXIT_BLOCK_PTR
+ && single_succ (xbb) != EXIT_BLOCK_PTR_FOR_FN (cfun)
/* And unconditional jump in previous basic block leads to
next basic block of XBB and this jump can be safely removed. */
&& in_current_region_p (xbb->prev_bb)
- && jump_leads_only_to_bb_p (BB_END (xbb->prev_bb), xbb->next_bb)
+ && bb_has_removable_jump_to_p (xbb->prev_bb, xbb->next_bb)
&& INSN_SCHED_TIMES (BB_END (xbb->prev_bb)) == 0
/* Also this jump is not at the scheduling boundary. */
&& !IN_CURRENT_FENCE_P (BB_END (xbb->prev_bb)))
{
+ bool recompute_toporder_p;
/* Clear data structures of jump - jump itself will be removed
by sel_redirect_edge_and_branch. */
clear_expr (INSN_EXPR (BB_END (xbb->prev_bb)));
- sel_redirect_edge_and_branch (EDGE_SUCC (xbb->prev_bb, 0), xbb);
+ recompute_toporder_p
+ = sel_redirect_edge_and_branch (EDGE_SUCC (xbb->prev_bb, 0), xbb);
+
gcc_assert (EDGE_SUCC (xbb->prev_bb, 0)->flags & EDGE_FALLTHRU);
/* It can turn out that after removing unused jump, basic block
remove it too. */
if (sel_bb_empty_p (xbb->prev_bb))
changed = maybe_tidy_empty_bb (xbb->prev_bb);
+ if (recompute_toporder_p)
+ sel_recompute_toporder ();
}
+#ifdef ENABLE_CHECKING
+ verify_backedges ();
+ verify_dominators (CDI_DOMINATORS);
+#endif
+
return changed;
}
-/* Rip-off INSN from the insn stream. When ONLY_DISCONNECT is true,
- do not delete insn's data, because it will be later re-emitted.
+/* Purge meaningless empty blocks in the middle of a region. */
+void
+purge_empty_blocks (void)
+{
+ int i;
+
+ /* Do not attempt to delete the first basic block in the region. */
+ for (i = 1; i < current_nr_blocks; )
+ {
+ basic_block b = BASIC_BLOCK_FOR_FN (cfun, BB_TO_BLOCK (i));
+
+ if (maybe_tidy_empty_bb (b))
+ continue;
+
+ i++;
+ }
+}
+
+/* Rip-off INSN from the insn stream. When ONLY_DISCONNECT is true,
+ do not delete insn's data, because it will be later re-emitted.
Return true if we have removed some blocks afterwards. */
bool
sel_remove_insn (insn_t insn, bool only_disconnect, bool full_tidying)
}
if (only_disconnect)
- {
- insn_t prev = PREV_INSN (insn);
- insn_t next = NEXT_INSN (insn);
- basic_block bb = BLOCK_FOR_INSN (insn);
-
- NEXT_INSN (prev) = next;
- PREV_INSN (next) = prev;
-
- if (BB_HEAD (bb) == insn)
- {
- gcc_assert (BLOCK_FOR_INSN (prev) == bb);
- BB_HEAD (bb) = prev;
- }
- if (BB_END (bb) == insn)
- BB_END (bb) = prev;
- }
+ remove_insn (insn);
else
{
- remove_insn (insn);
+ delete_insn (insn);
clear_expr (INSN_EXPR (insn));
}
- /* It is necessary to null this fields before calling add_insn (). */
- PREV_INSN (insn) = NULL_RTX;
- NEXT_INSN (insn) = NULL_RTX;
+ /* It is necessary to NULL these fields in case we are going to re-insert
+ INSN into the insns stream, as will usually happen in the ONLY_DISCONNECT
+ case, but also for NOPs that we will return to the nop pool. */
+ SET_PREV_INSN (insn) = NULL_RTX;
+ SET_NEXT_INSN (insn) = NULL_RTX;
+ set_block_for_insn (insn, NULL);
return tidy_control_flow (bb, full_tidying);
}
return -1;
}
-/* Return seqno of the only predecessor of INSN. */
+/* Find the proper seqno for inserting at INSN by successors.
+ Return -1 if no successors with positive seqno exist. */
+static int
+get_seqno_by_succs (rtx_insn *insn)
+{
+ basic_block bb = BLOCK_FOR_INSN (insn);
+ rtx_insn *tmp = insn, *end = BB_END (bb);
+ int seqno;
+ insn_t succ = NULL;
+ succ_iterator si;
+
+ while (tmp != end)
+ {
+ tmp = NEXT_INSN (tmp);
+ if (INSN_P (tmp))
+ return INSN_SEQNO (tmp);
+ }
+
+ seqno = INT_MAX;
+
+ FOR_EACH_SUCC_1 (succ, si, end, SUCCS_NORMAL)
+ if (INSN_SEQNO (succ) > 0)
+ seqno = MIN (seqno, INSN_SEQNO (succ));
+
+ if (seqno == INT_MAX)
+ return -1;
+
+ return seqno;
+}
+
+/* Compute seqno for INSN by its preds or succs. Use OLD_SEQNO to compute
+ seqno in corner cases. */
static int
-get_seqno_of_a_pred (insn_t insn)
+get_seqno_for_a_jump (insn_t insn, int old_seqno)
{
int seqno;
&& !in_current_region_p (single_pred (bb)))
{
/* We can have preds outside a region when splitting edges
- for pipelining of an outer loop. Use succ instead.
+ for pipelining of an outer loop. Use succ instead.
There should be only one of them. */
insn_t succ = NULL;
succ_iterator si;
bool first = true;
-
+
gcc_assert (flag_sel_sched_pipelining_outer_loops
&& current_loop_nest);
- FOR_EACH_SUCC_1 (succ, si, insn,
+ FOR_EACH_SUCC_1 (succ, si, insn,
SUCCS_NORMAL | SUCCS_SKIP_TO_LOOP_EXITS)
{
gcc_assert (first);
int n;
cfg_preds (BLOCK_FOR_INSN (insn), &preds, &n);
- gcc_assert (n == 1);
- seqno = INSN_SEQNO (preds[0]);
-
+ gcc_assert (n > 0);
+ /* For one predecessor, use simple method. */
+ if (n == 1)
+ seqno = INSN_SEQNO (preds[0]);
+ else
+ seqno = get_seqno_by_preds (insn);
+
free (preds);
}
}
+ /* We were unable to find a good seqno among preds. */
+ if (seqno < 0)
+ seqno = get_seqno_by_succs (insn);
+
+ if (seqno < 0)
+ {
+ /* The only case where this could be here legally is that the only
+ unscheduled insn was a conditional jump that got removed and turned
+ into this unconditional one. Initialize from the old seqno
+ of that jump passed down to here. */
+ seqno = old_seqno;
+ }
+
+ gcc_assert (seqno >= 0);
return seqno;
}
/* Find the proper seqno for inserting at INSN. Returns -1 if no predecessors
with positive seqno exist. */
int
-get_seqno_by_preds (rtx insn)
+get_seqno_by_preds (rtx_insn *insn)
{
basic_block bb = BLOCK_FOR_INSN (insn);
- rtx tmp = insn, head = BB_HEAD (bb);
+ rtx_insn *tmp = insn, *head = BB_HEAD (bb);
insn_t *preds;
int n, i, seqno;
while (tmp != head)
- if (INSN_P (tmp))
- return INSN_SEQNO (tmp);
- else
+ {
tmp = PREV_INSN (tmp);
-
+ if (INSN_P (tmp))
+ return INSN_SEQNO (tmp);
+ }
+
cfg_preds (bb, &preds, &n);
for (i = 0, seqno = -1; i < n; i++)
seqno = MAX (seqno, INSN_SEQNO (preds[i]));
void
sel_extend_global_bb_info (void)
{
- VEC_safe_grow_cleared (sel_global_bb_info_def, heap, sel_global_bb_info,
- last_basic_block);
+ sel_global_bb_info.safe_grow_cleared (last_basic_block_for_fn (cfun));
}
/* Extend region-scope data structures for basic blocks. */
static void
extend_region_bb_info (void)
{
- VEC_safe_grow_cleared (sel_region_bb_info_def, heap, sel_region_bb_info,
- last_basic_block);
+ sel_region_bb_info.safe_grow_cleared (last_basic_block_for_fn (cfun));
}
/* Extend all data structures to fit for all basic blocks. */
void
sel_finish_global_bb_info (void)
{
- VEC_free (sel_global_bb_info_def, heap, sel_global_bb_info);
+ sel_global_bb_info.release ();
}
/* Finalize region-scope data structures for basic blocks. */
static void
finish_region_bb_info (void)
{
- VEC_free (sel_region_bb_info_def, heap, sel_region_bb_info);
+ sel_region_bb_info.release ();
}
\f
/* Data for each insn in current region. */
-VEC (sel_insn_data_def, heap) *s_i_d = NULL;
-
-/* A vector for the insns we've emitted. */
-static insn_vec_t new_insns = NULL;
+vec<sel_insn_data_def> s_i_d = vNULL;
/* Extend data structures for insns from current region. */
static void
extend_insn_data (void)
{
int reserve;
-
+
sched_extend_target ();
sched_deps_init (false);
/* Extend data structures for insns from current region. */
- reserve = (sched_max_luid + 1
- - VEC_length (sel_insn_data_def, s_i_d));
- if (reserve > 0
- && ! VEC_space (sel_insn_data_def, s_i_d, reserve))
- VEC_safe_grow_cleared (sel_insn_data_def, heap, s_i_d,
- 3 * sched_max_luid / 2);
+ reserve = (sched_max_luid + 1 - s_i_d.length ());
+ if (reserve > 0 && ! s_i_d.space (reserve))
+ {
+ int size;
+
+ if (sched_max_luid / 2 > 1024)
+ size = sched_max_luid + 1024;
+ else
+ size = 3 * sched_max_luid / 2;
+
+
+ s_i_d.safe_grow_cleared (size);
+ }
}
/* Finalize data structures for insns from current region. */
/* Clear here all dependence contexts that may have left from insns that were
removed during the scheduling. */
- for (i = 0; i < VEC_length (sel_insn_data_def, s_i_d); i++)
+ for (i = 0; i < s_i_d.length (); i++)
{
- sel_insn_data_def *sid_entry = VEC_index (sel_insn_data_def, s_i_d, i);
-
+ sel_insn_data_def *sid_entry = &s_i_d[i];
+
if (sid_entry->live)
return_regset_to_pool (sid_entry->live);
if (sid_entry->analyzed_deps)
if (EXPR_VINSN (&sid_entry->expr))
{
clear_expr (&sid_entry->expr);
-
+
/* Also, clear CANT_MOVE bit here, because we really don't want it
to be passed to the next region. */
CANT_MOVE_BY_LUID (i) = 0;
}
}
-
- VEC_free (sel_insn_data_def, heap, s_i_d);
+
+ s_i_d.release ();
}
/* A proxy to pass initialization data to init_insn (). */
if (insn_init_create_new_vinsn_p)
change_vinsn_in_expr (expr, vinsn_create (insn, init_insn_force_unique_p));
-
+
if (first_time_insn_init (insn))
init_first_time_insn_data (insn);
}
/* This is used to initialize spurious jumps generated by
- sel_redirect_edge (). */
+ sel_redirect_edge (). OLD_SEQNO is used for initializing seqnos
+ in corner cases within get_seqno_for_a_jump. */
static void
-init_simplejump_data (insn_t insn)
+init_simplejump_data (insn_t insn, int old_seqno)
{
init_expr (INSN_EXPR (insn), vinsn_create (insn, false), 0,
- REG_BR_PROB_BASE, 0, 0, 0, 0, 0, 0, NULL, true, false, false,
+ REG_BR_PROB_BASE, 0, 0, 0, 0, 0, 0,
+ vNULL, true, false, false,
false, true);
- INSN_SEQNO (insn) = get_seqno_of_a_pred (insn);
+ INSN_SEQNO (insn) = get_seqno_for_a_jump (insn, old_seqno);
init_first_time_insn_data (insn);
}
-/* Perform deferred initialization of insns. This is used to process
- a new jump that may be created by redirect_edge. */
-void
-sel_init_new_insn (insn_t insn, int flags)
+/* Perform deferred initialization of insns. This is used to process
+ a new jump that may be created by redirect_edge. OLD_SEQNO is used
+ for initializing simplejumps in init_simplejump_data. */
+static void
+sel_init_new_insn (insn_t insn, int flags, int old_seqno)
{
/* We create data structures for bb when the first insn is emitted in it. */
if (INSN_P (insn)
extend_bb_info ();
create_initial_data_sets (BLOCK_FOR_INSN (insn));
}
-
+
if (flags & INSN_INIT_TODO_LUID)
- sched_init_luids (NULL, NULL, NULL, insn);
+ {
+ sched_extend_luids ();
+ sched_init_insn_luid (insn);
+ }
if (flags & INSN_INIT_TODO_SSID)
{
if (flags & INSN_INIT_TODO_SIMPLEJUMP)
{
extend_insn_data ();
- init_simplejump_data (insn);
+ init_simplejump_data (insn, old_seqno);
}
-
+
gcc_assert (CONTAINING_RGN (BLOCK_NUM (insn))
== CONTAINING_RGN (BB_TO_BLOCK (0)));
}
gcc_assert (!BB_LV_SET_VALID_P (bb));
BB_LV_SET (bb) = get_regset_from_pool ();
- COPY_REG_SET (BB_LV_SET (bb), DF_LR_IN (bb));
+ COPY_REG_SET (BB_LV_SET (bb), DF_LR_IN (bb));
BB_LV_SET_VALID_P (bb) = true;
}
copy_lv_set_from (basic_block bb, basic_block from_bb)
{
gcc_assert (!BB_LV_SET_VALID_P (bb));
-
+
COPY_REG_SET (BB_LV_SET (bb), BB_LV_SET (from_bb));
BB_LV_SET_VALID_P (bb) = true;
-}
+}
/* Initialize lv set of all bb headers. */
void
basic_block bb;
/* Initialize of LV sets. */
- FOR_EACH_BB (bb)
+ FOR_EACH_BB_FN (bb, cfun)
init_lv_set (bb);
/* Don't forget EXIT_BLOCK. */
- init_lv_set (EXIT_BLOCK_PTR);
+ init_lv_set (EXIT_BLOCK_PTR_FOR_FN (cfun));
}
/* Release lv set of HEAD. */
basic_block bb;
/* Don't forget EXIT_BLOCK. */
- free_lv_set (EXIT_BLOCK_PTR);
+ free_lv_set (EXIT_BLOCK_PTR_FOR_FN (cfun));
/* Free LV sets. */
- FOR_EACH_BB (bb)
+ FOR_EACH_BB_FN (bb, cfun)
if (BB_LV_SET (bb))
free_lv_set (bb);
}
-/* Initialize an invalid AV_SET for BB.
- This set will be updated next time compute_av () process BB. */
+/* Mark AV_SET for BB as invalid, so this set will be updated the next time
+ compute_av() processes BB. This function is called when creating new basic
+ blocks, as well as for blocks (either new or existing) where new jumps are
+ created when the control flow is being updated. */
static void
invalidate_av_set (basic_block bb)
{
- gcc_assert (BB_AV_LEVEL (bb) <= 0
- && BB_AV_SET (bb) == NULL);
-
BB_AV_LEVEL (bb) = -1;
}
/* The basic block that already has been processed by the sched_data_update (),
but hasn't been in sel_add_bb () yet. */
-static VEC (basic_block, heap) *last_added_blocks = NULL;
+static vec<basic_block>
+ last_added_blocks = vNULL;
/* A pool for allocating successor infos. */
static struct
/* Functions to work with control-flow graph. */
/* Return basic block note of BB. */
-insn_t
+rtx_insn *
sel_bb_head (basic_block bb)
{
- insn_t head;
+ rtx_insn *head;
- if (bb == EXIT_BLOCK_PTR)
+ if (bb == EXIT_BLOCK_PTR_FOR_FN (cfun))
{
gcc_assert (exit_insn != NULL_RTX);
head = exit_insn;
note = bb_note (bb);
head = next_nonnote_insn (note);
- if (head && BLOCK_FOR_INSN (head) != bb)
- head = NULL_RTX;
+ if (head && (BARRIER_P (head) || BLOCK_FOR_INSN (head) != bb))
+ head = NULL;
}
return head;
}
/* Return last insn of BB. */
-insn_t
+rtx_insn *
sel_bb_end (basic_block bb)
{
if (sel_bb_empty_p (bb))
- return NULL_RTX;
+ return NULL;
- gcc_assert (bb != EXIT_BLOCK_PTR);
+ gcc_assert (bb != EXIT_BLOCK_PTR_FOR_FN (cfun));
return BB_END (bb);
}
/* Return the block which is a fallthru bb of a conditional jump JUMP. */
basic_block
-fallthru_bb_of_jump (rtx jump)
+fallthru_bb_of_jump (const rtx_insn *jump)
{
if (!JUMP_P (jump))
return NULL;
- if (any_uncondjump_p (jump))
- return single_succ (BLOCK_FOR_INSN (jump));
-
if (!any_condjump_p (jump))
return NULL;
+ /* A basic block that ends with a conditional jump may still have one successor
+ (and be followed by a barrier), we are not interested. */
+ if (single_succ_p (BLOCK_FOR_INSN (jump)))
+ return NULL;
+
return FALLTHRU_EDGE (BLOCK_FOR_INSN (jump))->dest;
}
}
void
-sel_init_bbs (bb_vec_t bbs, basic_block bb)
+sel_init_bbs (bb_vec_t bbs)
{
const struct sched_scan_info_def ssi =
{
NULL /* init_insn */
};
- sched_scan (&ssi, bbs, bb, new_insns, NULL);
+ sched_scan (&ssi, bbs);
}
-/* Restore other notes for the whole region. */
+/* Restore notes for the whole region. */
static void
-sel_restore_other_notes (void)
+sel_restore_notes (void)
{
int bb;
+ insn_t insn;
for (bb = 0; bb < current_nr_blocks; bb++)
{
{
note_list = BB_NOTE_LIST (first);
restore_other_notes (NULL, first);
- BB_NOTE_LIST (first) = NULL_RTX;
+ BB_NOTE_LIST (first) = NULL;
+
+ FOR_BB_INSNS (first, insn)
+ if (NONDEBUG_INSN_P (insn))
+ reemit_notes (insn);
first = first->next_bb;
}
void
sel_finish_bbs (void)
{
- sel_restore_other_notes ();
+ sel_restore_notes ();
/* Remove current loop preheader from this loop. */
if (current_loop_nest)
if (succs_info_pool.top == succs_info_pool.max_top)
{
int i;
-
+
if (++succs_info_pool.max_top >= succs_info_pool.size)
gcc_unreachable ();
i = ++succs_info_pool.top;
- succs_info_pool.stack[i].succs_ok = VEC_alloc (rtx, heap, 10);
- succs_info_pool.stack[i].succs_other = VEC_alloc (rtx, heap, 10);
- succs_info_pool.stack[i].probs_ok = VEC_alloc (int, heap, 10);
+ succs_info_pool.stack[i].succs_ok.create (10);
+ succs_info_pool.stack[i].succs_other.create (10);
+ succs_info_pool.stack[i].probs_ok.create (10);
}
else
succs_info_pool.top++;
void
free_succs_info (struct succs_info * sinfo)
{
- gcc_assert (succs_info_pool.top >= 0
+ gcc_assert (succs_info_pool.top >= 0
&& &succs_info_pool.stack[succs_info_pool.top] == sinfo);
succs_info_pool.top--;
/* Clear stale info. */
- VEC_block_remove (rtx, sinfo->succs_ok,
- 0, VEC_length (rtx, sinfo->succs_ok));
- VEC_block_remove (rtx, sinfo->succs_other,
- 0, VEC_length (rtx, sinfo->succs_other));
- VEC_block_remove (int, sinfo->probs_ok,
- 0, VEC_length (int, sinfo->probs_ok));
+ sinfo->succs_ok.block_remove (0, sinfo->succs_ok.length ());
+ sinfo->succs_other.block_remove (0, sinfo->succs_other.length ());
+ sinfo->probs_ok.block_remove (0, sinfo->probs_ok.length ());
sinfo->all_prob = 0;
sinfo->succs_ok_n = 0;
sinfo->all_succs_n = 0;
}
-/* Compute successor info for INSN. FLAGS are the flags passed
+/* Compute successor info for INSN. FLAGS are the flags passed
to the FOR_EACH_SUCC_1 iterator. */
struct succs_info *
compute_succs_info (insn_t insn, short flags)
if (current_flags & flags)
{
- VEC_safe_push (rtx, heap, sinfo->succs_ok, succ);
- VEC_safe_push (int, heap, sinfo->probs_ok,
- /* FIXME: Improve calculation when skipping
- inner loop to exits. */
- (si.bb_end
- ? si.e1->probability
- : REG_BR_PROB_BASE));
+ sinfo->succs_ok.safe_push (succ);
+ sinfo->probs_ok.safe_push (
+ /* FIXME: Improve calculation when skipping
+ inner loop to exits. */
+ si.bb_end ? si.e1->probability : REG_BR_PROB_BASE);
sinfo->succs_ok_n++;
}
else
- VEC_safe_push (rtx, heap, sinfo->succs_other, succ);
+ sinfo->succs_other.safe_push (succ);
/* Compute all_prob. */
if (!si.bb_end)
return sinfo;
}
-/* Return the predecessors of BB in PREDS and their number in N.
+/* Return the predecessors of BB in PREDS and their number in N.
Empty blocks are skipped. SIZE is used to allocate PREDS. */
static void
cfg_preds_1 (basic_block bb, insn_t **preds, int *n, int *size)
basic_block pred_bb = e->src;
insn_t bb_end = BB_END (pred_bb);
- /* ??? This code is not supposed to walk out of a region. */
- gcc_assert (in_current_region_p (pred_bb));
+ if (!in_current_region_p (pred_bb))
+ {
+ gcc_assert (flag_sel_sched_pipelining_outer_loops
+ && current_loop_nest);
+ continue;
+ }
if (sel_bb_empty_p (pred_bb))
cfg_preds_1 (pred_bb, preds, n, size);
else
{
if (*n == *size)
- *preds = XRESIZEVEC (insn_t, *preds,
+ *preds = XRESIZEVEC (insn_t, *preds,
(*size = 2 * *size + 1));
(*preds)[(*n)++] = bb_end;
}
}
- gcc_assert (*n != 0);
+ gcc_assert (*n != 0
+ || (flag_sel_sched_pipelining_outer_loops
+ && current_loop_nest));
}
-/* Find all predecessors of BB and record them in PREDS and their number
- in N. Empty blocks are skipped, and only normal (forward in-region)
+/* Find all predecessors of BB and record them in PREDS and their number
+ in N. Empty blocks are skipped, and only normal (forward in-region)
edges are processed. */
static void
cfg_preds (basic_block bb, insn_t **preds, int *n)
return false;
}
-/* Returns true when BB should be the end of an ebb. Adapted from the
+/* Returns true when BB should be the end of an ebb. Adapted from the
code in sched-ebb.c. */
bool
bb_ends_ebb_p (basic_block bb)
{
basic_block next_bb = bb_next_bb (bb);
edge e;
- edge_iterator ei;
-
- if (next_bb == EXIT_BLOCK_PTR
+
+ if (next_bb == EXIT_BLOCK_PTR_FOR_FN (cfun)
|| bitmap_bit_p (forced_ebb_heads, next_bb->index)
|| (LABEL_P (BB_HEAD (next_bb))
/* NB: LABEL_NUSES () is not maintained outside of jump.c.
if (!in_current_region_p (next_bb))
return true;
- FOR_EACH_EDGE (e, ei, bb->succs)
- if ((e->flags & EDGE_FALLTHRU) != 0)
- {
- gcc_assert (e->dest == next_bb);
-
- return false;
- }
+ e = find_fallthru_edge (bb->succs);
+ if (e)
+ {
+ gcc_assert (e->dest == next_bb);
+
+ return false;
+ }
return true;
}
{
basic_block ptr = BLOCK_FOR_INSN (insn);
- for(;;)
+ for (;;)
{
if (ptr == BLOCK_FOR_INSN (succ))
return true;
-
+
if (bb_ends_ebb_p (ptr))
return false;
int *postorder;
int n_blocks, i;
- if (!rev_top_order_index || rev_top_order_index_len < last_basic_block)
+ if (!rev_top_order_index
+ || rev_top_order_index_len < last_basic_block_for_fn (cfun))
{
- rev_top_order_index_len = last_basic_block;
+ rev_top_order_index_len = last_basic_block_for_fn (cfun);
rev_top_order_index = XRESIZEVEC (int, rev_top_order_index,
rev_top_order_index_len);
}
- postorder = XNEWVEC (int, n_basic_blocks);
+ postorder = XNEWVEC (int, n_basic_blocks_for_fn (cfun));
n_blocks = post_order_compute (postorder, true, false);
- gcc_assert (n_basic_blocks == n_blocks);
+ gcc_assert (n_basic_blocks_for_fn (cfun) == n_blocks);
/* Build reverse function: for each basic block with BB->INDEX == K
rev_top_order_index[K] is it's reverse topological sort number. */
void
clear_outdated_rtx_info (basic_block bb)
{
- rtx insn;
+ rtx_insn *insn;
FOR_BB_INSNS (bb, insn)
if (INSN_P (insn))
EXPR_PRIORITY_ADJ (INSN_EXPR (insn)) = 0;
/* We cannot use the changed caches, as previously we could ignore
- the LHS dependence due to enabled renaming and transform
+ the LHS dependence due to enabled renaming and transform
the expression, and currently we'll be unable to do this. */
htab_empty (INSN_TRANSFORMED_INSNS (insn));
}
/* It turns out that current cfg infrastructure does not support
reuse of basic blocks. Don't bother for now. */
- /*VEC_safe_push (rtx, heap, bb_note_pool, note);*/
+ /*bb_note_pool.safe_push (note);*/
}
/* Get a bb_note from pool or return NULL_RTX if pool is empty. */
-static rtx
+static rtx_note *
get_bb_note_from_pool (void)
{
- if (VEC_empty (rtx, bb_note_pool))
- return NULL_RTX;
+ if (bb_note_pool.is_empty ())
+ return NULL;
else
{
- rtx note = VEC_pop (rtx, bb_note_pool);
+ rtx_note *note = bb_note_pool.pop ();
- PREV_INSN (note) = NULL_RTX;
- NEXT_INSN (note) = NULL_RTX;
+ SET_PREV_INSN (note) = NULL_RTX;
+ SET_NEXT_INSN (note) = NULL_RTX;
return note;
}
void
free_bb_note_pool (void)
{
- VEC_free (rtx, heap, bb_note_pool);
+ bb_note_pool.release ();
}
/* Setup scheduler pool and successor structure. */
int succs_size;
succs_size = MAX_WS + 1;
- succs_info_pool.stack = XCNEWVEC (struct succs_info, succs_size);
+ succs_info_pool.stack = XCNEWVEC (struct succs_info, succs_size);
succs_info_pool.size = succs_size;
succs_info_pool.top = -1;
succs_info_pool.max_top = -1;
- sched_lists_pool = create_alloc_pool ("sel-sched-lists",
+ sched_lists_pool = create_alloc_pool ("sel-sched-lists",
sizeof (struct _list_node), 500);
}
free_sched_pools (void)
{
int i;
-
+
free_alloc_pool (sched_lists_pool);
gcc_assert (succs_info_pool.top == -1);
- for (i = 0; i < succs_info_pool.max_top; i++)
+ for (i = 0; i <= succs_info_pool.max_top; i++)
{
- VEC_free (rtx, heap, succs_info_pool.stack[i].succs_ok);
- VEC_free (rtx, heap, succs_info_pool.stack[i].succs_other);
- VEC_free (int, heap, succs_info_pool.stack[i].probs_ok);
+ succs_info_pool.stack[i].succs_ok.release ();
+ succs_info_pool.stack[i].succs_other.release ();
+ succs_info_pool.stack[i].probs_ok.release ();
}
free (succs_info_pool.stack);
}
\f
-/* Returns a position in RGN where BB can be inserted retaining
+/* Returns a position in RGN where BB can be inserted retaining
topological order. */
static int
find_place_to_insert_bb (basic_block bb, int rgn)
bool has_preds_outside_rgn = false;
edge e;
edge_iterator ei;
-
+
/* Find whether we have preds outside the region. */
FOR_EACH_EDGE (e, ei, bb->preds)
if (!in_current_region_p (e->src))
has_preds_outside_rgn = true;
break;
}
-
+
/* Recompute the top order -- needed when we have > 1 pred
and in case we don't have preds outside. */
if (flag_sel_sched_pipelining_outer_loops
for (i = RGN_NR_BLOCKS (rgn) - 1; i >= 0; i--)
{
cur_bbi = BB_TO_BLOCK (i);
- if (rev_top_order_index[bbi]
+ if (rev_top_order_index[bbi]
< rev_top_order_index[cur_bbi])
break;
}
-
- /* We skipped the right block, so we increase i. We accomodate
+
+ /* We skipped the right block, so we increase i. We accommodate
it for increasing by step later, so we decrease i. */
return (i + 1) - 1;
}
if (EDGE_COUNT (bb->succs) > 0)
{
int pred_bbi;
-
+
gcc_assert (EDGE_COUNT (bb->preds) == 1);
-
+
pred_bbi = EDGE_PRED (bb, 0)->src->index;
return BLOCK_TO_BB (pred_bbi);
}
bitmap_clear_bit (blocks_to_reschedule, bb->index);
- /* Can't assert av_set properties because we use sel_aremove_bb
- when removing loop preheader from the region. At the point of
+ /* Can't assert av_set properties because we use sel_aremove_bb
+ when removing loop preheader from the region. At the point of
removing the preheader we already have deallocated sel_region_bb_info. */
gcc_assert (BB_LV_SET (bb) == NULL
&& !BB_LV_SET_VALID_P (bb)
&& BB_AV_LEVEL (bb) == 0
&& BB_AV_SET (bb) == NULL);
-
+
delete_basic_block (bb);
}
gcc_assert (RGN_HAS_REAL_EBB (rgn) == 0
&& ebb_head[bbi] == pos);
-
+
/* Make a place for the new block. */
extend_regions ();
for (i = RGN_BLOCKS (rgn + 1) - 1; i >= pos; i--)
BLOCK_TO_BB (rgn_bb_table[i])++;
-
+
memmove (rgn_bb_table + pos + 1,
rgn_bb_table + pos,
(RGN_BLOCKS (nr_regions) - pos) * sizeof (*rgn_bb_table));
CONTAINING_RGN (bb->index) = rgn;
RGN_NR_BLOCKS (rgn)++;
-
+
for (i = rgn + 1; i <= nr_regions; i++)
RGN_BLOCKS (i)++;
}
RGN_BLOCKS (i)--;
}
-/* Add BB to the current region and update all data. If BB is NULL, add all
+/* Add BB to the current region and update all data. If BB is NULL, add all
blocks from last_added_blocks vector. */
static void
sel_add_bb (basic_block bb)
{
/* Extend luids so that new notes will receive zero luids. */
- sched_init_luids (NULL, NULL, NULL, NULL);
+ sched_extend_luids ();
sched_init_bbs ();
- sel_init_bbs (last_added_blocks, NULL);
+ sel_init_bbs (last_added_blocks);
- /* When bb is passed explicitly, the vector should contain
+ /* When bb is passed explicitly, the vector should contain
the only element that equals to bb; otherwise, the vector
should not be NULL. */
- gcc_assert (last_added_blocks != NULL);
-
+ gcc_assert (last_added_blocks.exists ());
+
if (bb != NULL)
{
- gcc_assert (VEC_length (basic_block, last_added_blocks) == 1
- && VEC_index (basic_block,
- last_added_blocks, 0) == bb);
+ gcc_assert (last_added_blocks.length () == 1
+ && last_added_blocks[0] == bb);
add_block_to_current_region (bb);
/* We associate creating/deleting data sets with the first insn
appearing / disappearing in the bb. */
if (!sel_bb_empty_p (bb) && BB_LV_SET (bb) == NULL)
create_initial_data_sets (bb);
-
- VEC_free (basic_block, heap, last_added_blocks);
+
+ last_added_blocks.release ();
}
else
/* BB is NULL - process LAST_ADDED_BLOCKS instead. */
int i;
basic_block temp_bb = NULL;
- for (i = 0;
- VEC_iterate (basic_block, last_added_blocks, i, bb); i++)
+ for (i = 0;
+ last_added_blocks.iterate (i, &bb); i++)
{
add_block_to_current_region (bb);
temp_bb = bb;
}
- /* We need to fetch at least one bb so we know the region
+ /* We need to fetch at least one bb so we know the region
to update. */
gcc_assert (temp_bb != NULL);
bb = temp_bb;
- VEC_free (basic_block, heap, last_added_blocks);
+ last_added_blocks.release ();
}
rgn_setup_region (CONTAINING_RGN (bb->index));
}
-/* Remove BB from the current region and update all data.
+/* Remove BB from the current region and update all data.
If REMOVE_FROM_CFG_PBB is true, also remove the block cfom cfg. */
static void
sel_remove_bb (basic_block bb, bool remove_from_cfg_p)
{
+ unsigned idx = bb->index;
+
gcc_assert (bb != NULL && BB_NOTE_LIST (bb) == NULL_RTX);
-
+
remove_bb_from_region (bb);
return_bb_to_pool (bb);
- bitmap_clear_bit (blocks_to_reschedule, bb->index);
-
+ bitmap_clear_bit (blocks_to_reschedule, idx);
+
if (remove_from_cfg_p)
- delete_and_free_basic_block (bb);
+ {
+ basic_block succ = single_succ (bb);
+ delete_and_free_basic_block (bb);
+ set_immediate_dominator (CDI_DOMINATORS, succ,
+ recompute_dominator (CDI_DOMINATORS, succ));
+ }
- rgn_setup_region (CONTAINING_RGN (bb->index));
+ rgn_setup_region (CONTAINING_RGN (idx));
}
/* Concatenate info of EMPTY_BB to info of MERGE_BB. */
static void
move_bb_info (basic_block merge_bb, basic_block empty_bb)
{
- gcc_assert (in_current_region_p (merge_bb));
-
- concat_note_lists (BB_NOTE_LIST (empty_bb),
- &BB_NOTE_LIST (merge_bb));
- BB_NOTE_LIST (empty_bb) = NULL_RTX;
+ if (in_current_region_p (merge_bb))
+ concat_note_lists (BB_NOTE_LIST (empty_bb),
+ &BB_NOTE_LIST (merge_bb));
+ BB_NOTE_LIST (empty_bb) = NULL;
}
-/* Remove an empty basic block EMPTY_BB. When MERGE_UP_P is true, we put
- EMPTY_BB's note lists into its predecessor instead of putting them
- into the successor. When REMOVE_FROM_CFG_P is true, also remove
- the empty block. */
-void
-sel_remove_empty_bb (basic_block empty_bb, bool merge_up_p,
- bool remove_from_cfg_p)
-{
- basic_block merge_bb;
-
- gcc_assert (sel_bb_empty_p (empty_bb));
-
- if (merge_up_p)
- {
- merge_bb = empty_bb->prev_bb;
- gcc_assert (EDGE_COUNT (empty_bb->preds) == 1
- && EDGE_PRED (empty_bb, 0)->src == merge_bb);
- }
- else
- {
- edge e;
- edge_iterator ei;
-
- merge_bb = bb_next_bb (empty_bb);
-
- /* Redirect incoming edges (except fallthrough one) of EMPTY_BB to its
- successor block. */
- for (ei = ei_start (empty_bb->preds);
- (e = ei_safe_edge (ei)); )
- {
- if (! (e->flags & EDGE_FALLTHRU))
- sel_redirect_edge_and_branch (e, merge_bb);
- else
- ei_next (&ei);
- }
-
- gcc_assert (EDGE_COUNT (empty_bb->succs) == 1
- && EDGE_SUCC (empty_bb, 0)->dest == merge_bb);
- }
-
- move_bb_info (merge_bb, empty_bb);
- remove_empty_bb (empty_bb, remove_from_cfg_p);
-}
-
/* Remove EMPTY_BB. If REMOVE_FROM_CFG_P is false, remove EMPTY_BB from
region, but keep it in CFG. */
static void
sel_remove_bb (empty_bb, remove_from_cfg_p);
}
-/* An implementation of create_basic_block hook, which additionally updates
+/* An implementation of create_basic_block hook, which additionally updates
per-bb data structures. */
static basic_block
sel_create_basic_block (void *headp, void *endp, basic_block after)
{
basic_block new_bb;
- insn_t new_bb_note;
-
- gcc_assert (flag_sel_sched_pipelining_outer_loops
- || last_added_blocks == NULL);
+ rtx_note *new_bb_note;
+
+ gcc_assert (flag_sel_sched_pipelining_outer_loops
+ || !last_added_blocks.exists ());
new_bb_note = get_bb_note_from_pool ();
new_bb = orig_cfg_hooks.create_basic_block (headp, endp, after);
else
{
- new_bb = create_basic_block_structure ((rtx) headp, (rtx) endp,
+ new_bb = create_basic_block_structure ((rtx_insn *) headp,
+ (rtx_insn *) endp,
new_bb_note, after);
new_bb->aux = NULL;
}
- VEC_safe_push (basic_block, heap, last_added_blocks, new_bb);
+ last_added_blocks.safe_push (new_bb);
return new_bb;
}
}
}
-/* Splits BB on two basic blocks, adding it to the region and extending
+/* Splits BB on two basic blocks, adding it to the region and extending
per-bb data structures. Returns the newly created bb. */
static basic_block
sel_split_block (basic_block bb, rtx after)
sel_add_bb (new_bb);
/* This should be called after sel_add_bb, because this uses
- CONTAINING_RGN for the new block, which is not yet initialized.
+ CONTAINING_RGN for the new block, which is not yet initialized.
FIXME: this function may be a no-op now. */
change_loops_latches (bb, new_bb);
/* If BB ends with a jump insn whose ID is bigger then PREV_MAX_UID, return it.
Otherwise returns NULL. */
-static rtx
+static rtx_insn *
check_for_new_jump (basic_block bb, int prev_max_uid)
{
- rtx end;
+ rtx_insn *end;
end = sel_bb_end (bb);
if (end && INSN_UID (end) >= prev_max_uid)
return NULL;
}
-/* Look for a new jump either in FROM_BB block or in newly created JUMP_BB block.
+/* Look for a new jump either in FROM_BB block or in newly created JUMP_BB block.
New means having UID at least equal to PREV_MAX_UID. */
-static rtx
+static rtx_insn *
find_new_jump (basic_block from, basic_block jump_bb, int prev_max_uid)
{
- rtx jump;
+ rtx_insn *jump;
/* Return immediately if no new insns were emitted. */
if (get_max_uid () == prev_max_uid)
return NULL;
-
+
/* Now check both blocks for new jumps. It will ever be only one. */
if ((jump = check_for_new_jump (from, prev_max_uid)))
return jump;
{
basic_block new_bb, src, other_bb = NULL;
int prev_max_uid;
- rtx jump;
+ rtx_insn *jump;
src = e->src;
prev_max_uid = get_max_uid ();
new_bb = split_edge (e);
- if (flag_sel_sched_pipelining_outer_loops
+ if (flag_sel_sched_pipelining_outer_loops
&& current_loop_nest)
{
int i;
basic_block bb;
- /* Some of the basic blocks might not have been added to the loop.
+ /* Some of the basic blocks might not have been added to the loop.
Add them here, until this is fixed in force_fallthru. */
- for (i = 0;
- VEC_iterate (basic_block, last_added_blocks, i, bb); i++)
+ for (i = 0;
+ last_added_blocks.iterate (i, &bb); i++)
if (!bb->loop_father)
{
add_bb_to_loop (bb, e->dest->loop_father);
/* We'll explicitly initialize NEW_BB via sel_init_only_bb () a bit
later. */
- gcc_assert (VEC_length (basic_block, last_added_blocks) == 1
- && VEC_index (basic_block, last_added_blocks, 0) == new_bb);
+ gcc_assert (last_added_blocks.length () == 1
+ && last_added_blocks[0] == new_bb);
- VEC_free (basic_block, heap, last_added_blocks);
+ last_added_blocks.release ();
return new_bb;
}
{
basic_block first_bb, second_bb, recovery_block;
basic_block before_recovery = NULL;
- rtx jump;
+ rtx_insn *jump;
first_bb = BLOCK_FOR_INSN (orig_insn);
if (sel_bb_end_p (orig_insn))
recovery_block = sched_create_recovery_block (&before_recovery);
if (before_recovery)
- copy_lv_set_from (before_recovery, EXIT_BLOCK_PTR);
+ copy_lv_set_from (before_recovery, EXIT_BLOCK_PTR_FOR_FN (cfun));
gcc_assert (sel_bb_empty_p (recovery_block));
sched_create_recovery_edges (first_bb, recovery_block, second_bb);
if (current_loops != NULL)
add_bb_to_loop (recovery_block, first_bb->loop_father);
-
+
sel_add_bb (recovery_block);
-
+
jump = BB_END (recovery_block);
gcc_assert (sel_bb_head (recovery_block) == jump);
sel_init_new_insn (jump, INSN_INIT_TODO_LUID | INSN_INIT_TODO_SIMPLEJUMP);
}
/* Merge basic block B into basic block A. */
-void
+static void
sel_merge_blocks (basic_block a, basic_block b)
{
- sel_remove_empty_bb (b, true, false);
- merge_blocks (a, b);
+ gcc_assert (sel_bb_empty_p (b)
+ && EDGE_COUNT (b->preds) == 1
+ && EDGE_PRED (b, 0)->src == b->prev_bb);
+ move_bb_info (b->prev_bb, b);
+ remove_empty_bb (b, false);
+ merge_blocks (a, b);
change_loops_latches (b, a);
}
/* A wrapper for redirect_edge_and_branch_force, which also initializes
- data structures for possibly created bb and insns. Returns the newly
- added bb or NULL, when a bb was not needed. */
+ data structures for possibly created bb and insns. */
void
sel_redirect_edge_and_branch_force (edge e, basic_block to)
{
- basic_block jump_bb, src;
+ basic_block jump_bb, src, orig_dest = e->dest;
int prev_max_uid;
- rtx jump;
-
- gcc_assert (!sel_bb_empty_p (e->src));
-
+ rtx_insn *jump;
+ int old_seqno = -1;
+
+ /* This function is now used only for bookkeeping code creation, where
+ we'll never get the single pred of orig_dest block and thus will not
+ hit unreachable blocks when updating dominator info. */
+ gcc_assert (!sel_bb_empty_p (e->src)
+ && !single_pred_p (orig_dest));
src = e->src;
prev_max_uid = get_max_uid ();
- jump_bb = redirect_edge_and_branch_force (e, to);
+ /* Compute and pass old_seqno down to sel_init_new_insn only for the case
+ when the conditional jump being redirected may become unconditional. */
+ if (any_condjump_p (BB_END (src))
+ && INSN_SEQNO (BB_END (src)) >= 0)
+ old_seqno = INSN_SEQNO (BB_END (src));
+ jump_bb = redirect_edge_and_branch_force (e, to);
if (jump_bb != NULL)
sel_add_bb (jump_bb);
if (current_loop_nest
&& pipelining_p)
gcc_assert (loop_latch_edge (current_loop_nest));
-
+
jump = find_new_jump (src, jump_bb, prev_max_uid);
if (jump)
- sel_init_new_insn (jump, INSN_INIT_TODO_LUID | INSN_INIT_TODO_SIMPLEJUMP);
+ sel_init_new_insn (jump, INSN_INIT_TODO_LUID | INSN_INIT_TODO_SIMPLEJUMP,
+ old_seqno);
+ set_immediate_dominator (CDI_DOMINATORS, to,
+ recompute_dominator (CDI_DOMINATORS, to));
+ set_immediate_dominator (CDI_DOMINATORS, orig_dest,
+ recompute_dominator (CDI_DOMINATORS, orig_dest));
}
-/* A wrapper for redirect_edge_and_branch. */
-void
+/* A wrapper for redirect_edge_and_branch. Return TRUE if blocks connected by
+ redirected edge are in reverse topological order. */
+bool
sel_redirect_edge_and_branch (edge e, basic_block to)
{
bool latch_edge_p;
- basic_block src;
+ basic_block src, orig_dest = e->dest;
int prev_max_uid;
- rtx jump;
+ rtx_insn *jump;
edge redirected;
+ bool recompute_toporder_p = false;
+ bool maybe_unreachable = single_pred_p (orig_dest);
+ int old_seqno = -1;
latch_edge_p = (pipelining_p
&& current_loop_nest
src = e->src;
prev_max_uid = get_max_uid ();
+ /* Compute and pass old_seqno down to sel_init_new_insn only for the case
+ when the conditional jump being redirected may become unconditional. */
+ if (any_condjump_p (BB_END (src))
+ && INSN_SEQNO (BB_END (src)) >= 0)
+ old_seqno = INSN_SEQNO (BB_END (src));
+
redirected = redirect_edge_and_branch (e, to);
- gcc_assert (redirected && last_added_blocks == NULL);
+ gcc_assert (redirected && !last_added_blocks.exists ());
/* When we've redirected a latch edge, update the header. */
if (latch_edge_p)
gcc_assert (loop_latch_edge (current_loop_nest));
}
+ /* In rare situations, the topological relation between the blocks connected
+ by the redirected edge can change (see PR42245 for an example). Update
+ block_to_bb/bb_to_block. */
+ if (CONTAINING_RGN (e->src->index) == CONTAINING_RGN (to->index)
+ && BLOCK_TO_BB (e->src->index) > BLOCK_TO_BB (to->index))
+ recompute_toporder_p = true;
+
jump = find_new_jump (src, NULL, prev_max_uid);
if (jump)
- sel_init_new_insn (jump, INSN_INIT_TODO_LUID | INSN_INIT_TODO_SIMPLEJUMP);
+ sel_init_new_insn (jump, INSN_INIT_TODO_LUID | INSN_INIT_TODO_SIMPLEJUMP, old_seqno);
+
+ /* Only update dominator info when we don't have unreachable blocks.
+ Otherwise we'll update in maybe_tidy_empty_bb. */
+ if (!maybe_unreachable)
+ {
+ set_immediate_dominator (CDI_DOMINATORS, to,
+ recompute_dominator (CDI_DOMINATORS, to));
+ set_immediate_dominator (CDI_DOMINATORS, orig_dest,
+ recompute_dominator (CDI_DOMINATORS, orig_dest));
+ }
+ return recompute_toporder_p;
}
/* This variable holds the cfg hooks used by the selective scheduler. */
/* Emit an insn rtx based on PATTERN. If a jump insn is wanted,
LABEL is where this jump should be directed. */
-rtx
+rtx_insn *
create_insn_rtx_from_pattern (rtx pattern, rtx label)
{
- rtx insn_rtx;
+ rtx_insn *insn_rtx;
gcc_assert (!INSN_P (pattern));
end_sequence ();
- sched_init_luids (NULL, NULL, NULL, NULL);
+ sched_extend_luids ();
sched_extend_target ();
sched_deps_init (false);
/* Create a new vinsn for INSN_RTX. FORCE_UNIQUE_P is true when the vinsn
must not be clonable. */
vinsn_t
-create_vinsn_from_insn_rtx (rtx insn_rtx, bool force_unique_p)
+create_vinsn_from_insn_rtx (rtx_insn *insn_rtx, bool force_unique_p)
{
gcc_assert (INSN_P (insn_rtx) && !INSN_IN_STREAM_P (insn_rtx));
}
/* Create a copy of INSN_RTX. */
-rtx
+rtx_insn *
create_copy_of_insn_rtx (rtx insn_rtx)
{
- rtx res;
+ rtx_insn *res;
+ rtx link;
if (DEBUG_INSN_P (insn_rtx))
return create_insn_rtx_from_pattern (copy_rtx (PATTERN (insn_rtx)),
res = create_insn_rtx_from_pattern (copy_rtx (PATTERN (insn_rtx)),
NULL_RTX);
+
+ /* Copy all REG_NOTES except REG_EQUAL/REG_EQUIV and REG_LABEL_OPERAND
+ since mark_jump_label will make them. REG_LABEL_TARGETs are created
+ there too, but are supposed to be sticky, so we copy them. */
+ for (link = REG_NOTES (insn_rtx); link; link = XEXP (link, 1))
+ if (REG_NOTE_KIND (link) != REG_LABEL_OPERAND
+ && REG_NOTE_KIND (link) != REG_EQUAL
+ && REG_NOTE_KIND (link) != REG_EQUIV)
+ {
+ if (GET_CODE (link) == EXPR_LIST)
+ add_reg_note (res, REG_NOTE_KIND (link),
+ copy_insn_1 (XEXP (link, 0)));
+ else
+ add_reg_note (res, REG_NOTE_KIND (link), XEXP (link, 0));
+ }
+
return res;
}
/* Helpers for global init. */
/* This structure is used to be able to call existing bundling mechanism
and calculate insn priorities. */
-static struct haifa_sched_info sched_sel_haifa_sched_info =
+static struct haifa_sched_info sched_sel_haifa_sched_info =
{
NULL, /* init_ready_list */
NULL, /* can_schedule_ready_p */
NULL, /* add_remove_insn */
NULL, /* begin_schedule_ready */
+ NULL, /* begin_move_insn */
NULL, /* advance_target_bb */
+
+ NULL,
+ NULL,
+
SEL_SCHED | NEW_BBS
};
/* Setup special insns used in the scheduler. */
-void
+void
setup_nop_and_exit_insns (void)
{
gcc_assert (nop_pattern == NULL_RTX
&& exit_insn == NULL_RTX);
- nop_pattern = gen_nop ();
+ nop_pattern = constm1_rtx;
start_sequence ();
emit_insn (nop_pattern);
exit_insn = get_insns ();
end_sequence ();
- set_block_for_insn (exit_insn, EXIT_BLOCK_PTR);
+ set_block_for_insn (exit_insn, EXIT_BLOCK_PTR_FOR_FN (cfun));
}
/* Free special insns used in the scheduler. */
void
free_nop_and_exit_insns (void)
{
- exit_insn = NULL_RTX;
+ exit_insn = NULL;
nop_pattern = NULL_RTX;
}
void
sel_set_sched_flags (void)
{
- /* ??? This means that set_sched_flags were called, and we decided to
+ /* ??? This means that set_sched_flags were called, and we decided to
support speculation. However, set_sched_flags also modifies flags
- on current_sched_info, doing this only at global init. And we
+ on current_sched_info, doing this only at global init. And we
sometimes change c_s_i later. So put the correct flags again. */
if (spec_info && targetm.sched.set_sched_flags)
targetm.sched.set_sched_flags (spec_info);
common_sched_info = &sel_common_sched_info;
current_sched_info = &sched_sel_haifa_sched_info;
- current_sched_info->sched_max_insns_priority =
+ current_sched_info->sched_max_insns_priority =
get_rgn_sched_max_insns_priority ();
-
+
sel_set_sched_flags ();
}
\f
/* FIXME: This will work only when EBBs are not created. */
if (new_rgn_number != 0)
- RGN_BLOCKS (new_rgn_number) = RGN_BLOCKS (new_rgn_number - 1) +
+ RGN_BLOCKS (new_rgn_number) = RGN_BLOCKS (new_rgn_number - 1) +
RGN_NR_BLOCKS (new_rgn_number - 1);
else
RGN_BLOCKS (new_rgn_number) = 0;
/* Set the blocks of the next region so the other functions may
calculate the number of blocks in the region. */
- RGN_BLOCKS (new_rgn_number + 1) = RGN_BLOCKS (new_rgn_number) +
+ RGN_BLOCKS (new_rgn_number + 1) = RGN_BLOCKS (new_rgn_number) +
RGN_NR_BLOCKS (new_rgn_number);
nr_regions++;
basic_block bb1 = *(const basic_block *) x;
basic_block bb2 = *(const basic_block *) y;
- gcc_assert (bb1 == bb2
- || rev_top_order_index[bb1->index]
+ gcc_assert (bb1 == bb2
+ || rev_top_order_index[bb1->index]
!= rev_top_order_index[bb2->index]);
/* It's a reverse topological order in REV_TOP_ORDER_INDEX, so
return 1;
}
-/* Create a region for LOOP and return its number. If we don't want
+/* Create a region for LOOP and return its number. If we don't want
to pipeline LOOP, return -1. */
static int
make_region_from_loop (struct loop *loop)
basic_block *loop_blocks;
basic_block preheader_block;
- if (loop->num_nodes
+ if (loop->num_nodes
> (unsigned) PARAM_VALUE (PARAM_MAX_PIPELINE_REGION_BLOCKS))
return -1;
-
+
/* Don't pipeline loops whose latch belongs to some of its inner loops. */
for (inner = loop->inner; inner; inner = inner->inner)
if (flow_bb_inside_loop_p (inner, loop->latch))
new_rgn_number = sel_create_new_region ();
sel_add_block_to_region (preheader_block, &bb_ord_index, new_rgn_number);
- SET_BIT (bbs_in_loop_rgns, preheader_block->index);
+ bitmap_set_bit (bbs_in_loop_rgns, preheader_block->index);
for (i = 0; i < loop->num_nodes; i++)
{
/* Add only those blocks that haven't been scheduled in the inner loop.
The exception is the basic blocks with bookkeeping code - they should
- be added to the region (and they actually don't belong to the loop
+ be added to the region (and they actually don't belong to the loop
body, but to the region containing that loop body). */
gcc_assert (new_rgn_number >= 0);
- if (! TEST_BIT (bbs_in_loop_rgns, loop_blocks[i]->index))
+ if (! bitmap_bit_p (bbs_in_loop_rgns, loop_blocks[i]->index))
{
- sel_add_block_to_region (loop_blocks[i], &bb_ord_index,
+ sel_add_block_to_region (loop_blocks[i], &bb_ord_index,
new_rgn_number);
- SET_BIT (bbs_in_loop_rgns, loop_blocks[i]->index);
+ bitmap_set_bit (bbs_in_loop_rgns, loop_blocks[i]->index);
}
}
/* Create a new region from preheader blocks LOOP_BLOCKS. */
void
-make_region_from_loop_preheader (VEC(basic_block, heap) **loop_blocks)
+make_region_from_loop_preheader (vec<basic_block> *&loop_blocks)
{
unsigned int i;
int new_rgn_number = -1;
new_rgn_number = sel_create_new_region ();
- for (i = 0; VEC_iterate (basic_block, *loop_blocks, i, bb); i++)
+ FOR_EACH_VEC_ELT (*loop_blocks, i, bb)
{
gcc_assert (new_rgn_number >= 0);
sel_add_block_to_region (bb, &bb_ord_index, new_rgn_number);
}
- VEC_free (basic_block, heap, *loop_blocks);
- gcc_assert (*loop_blocks == NULL);
+ vec_free (loop_blocks);
}
/* Create region(s) from loop nest LOOP, such that inner loops will be
- pipelined before outer loops. Returns true when a region for LOOP
+ pipelined before outer loops. Returns true when a region for LOOP
is created. */
static bool
make_regions_from_loop_nest (struct loop *loop)
-{
+{
struct loop *cur_loop;
int rgn_number;
/* Traverse all inner nodes of the loop. */
for (cur_loop = loop->inner; cur_loop; cur_loop = cur_loop->next)
- if (! TEST_BIT (bbs_in_loop_rgns, cur_loop->header->index))
+ if (! bitmap_bit_p (bbs_in_loop_rgns, cur_loop->header->index))
return false;
/* At this moment all regular inner loops should have been pipelined.
if (rgn_number < 0)
return false;
- VEC_safe_push (loop_p, heap, loop_nests, loop);
+ loop_nests.safe_push (loop);
return true;
}
| LOOPS_HAVE_MARKED_IRREDUCIBLE_REGIONS);
current_loop_nest = NULL;
- bbs_in_loop_rgns = sbitmap_alloc (last_basic_block);
- sbitmap_zero (bbs_in_loop_rgns);
+ bbs_in_loop_rgns = sbitmap_alloc (last_basic_block_for_fn (cfun));
+ bitmap_clear (bbs_in_loop_rgns);
recompute_rev_top_order ();
}
{
/* Regions created with extend_rgns don't have corresponding loop nests,
because they don't represent loops. */
- if (rgn < VEC_length (loop_p, loop_nests))
- return VEC_index (loop_p, loop_nests, rgn);
+ if (rgn < loop_nests.length ())
+ return loop_nests[rgn];
else
return NULL;
}
if (loop_depth (loop) == 0)
return false;
- /* Now, the loop could be too large or irreducible. Check whether its
- region is in LOOP_NESTS.
- We determine the region number of LOOP as the region number of its
- latch. We can't use header here, because this header could be
+ /* Now, the loop could be too large or irreducible. Check whether its
+ region is in LOOP_NESTS.
+ We determine the region number of LOOP as the region number of its
+ latch. We can't use header here, because this header could be
just removed preheader and it will give us the wrong region number.
Latch can't be used because it could be in the inner loop too. */
- if (LOOP_MARKED_FOR_PIPELINING_P (loop) && pipelining_p)
+ if (LOOP_MARKED_FOR_PIPELINING_P (loop))
{
int rgn = CONTAINING_RGN (loop->latch->index);
- gcc_assert ((unsigned) rgn < VEC_length (loop_p, loop_nests));
+ gcc_assert ((unsigned) rgn < loop_nests.length ());
return true;
}
-
+
return false;
}
-/* Makes regions from the rest of the blocks, after loops are chosen
+/* Makes regions from the rest of the blocks, after loops are chosen
for pipelining. */
static void
make_regions_from_the_rest (void)
edge e;
edge_iterator ei;
int *degree;
- int new_regions;
/* Index in rgn_bb_table where to start allocating new regions. */
cur_rgn_blocks = nr_regions ? RGN_BLOCKS (nr_regions) : 0;
- new_regions = nr_regions;
- /* Make regions from all the rest basic blocks - those that don't belong to
+ /* Make regions from all the rest basic blocks - those that don't belong to
any loop or belong to irreducible loops. Prepare the data structures
for extend_rgns. */
/* LOOP_HDR[I] == -1 if I-th bb doesn't belong to any loop,
LOOP_HDR[I] == LOOP_HDR[J] iff basic blocks I and J reside within the same
loop. */
- loop_hdr = XNEWVEC (int, last_basic_block);
- degree = XCNEWVEC (int, last_basic_block);
+ loop_hdr = XNEWVEC (int, last_basic_block_for_fn (cfun));
+ degree = XCNEWVEC (int, last_basic_block_for_fn (cfun));
/* For each basic block that belongs to some loop assign the number
of innermost loop it belongs to. */
- for (i = 0; i < last_basic_block; i++)
+ for (i = 0; i < last_basic_block_for_fn (cfun); i++)
loop_hdr[i] = -1;
- FOR_EACH_BB (bb)
+ FOR_EACH_BB_FN (bb, cfun)
{
- if (bb->loop_father && !bb->loop_father->num == 0
+ if (bb->loop_father && bb->loop_father->num != 0
&& !(bb->flags & BB_IRREDUCIBLE_LOOP))
loop_hdr[bb->index] = bb->loop_father->num;
}
- /* For each basic block degree is calculated as the number of incoming
+ /* For each basic block degree is calculated as the number of incoming
edges, that are going out of bbs that are not yet scheduled.
The basic blocks that are scheduled have degree value of zero. */
- FOR_EACH_BB (bb)
+ FOR_EACH_BB_FN (bb, cfun)
{
degree[bb->index] = 0;
- if (!TEST_BIT (bbs_in_loop_rgns, bb->index))
+ if (!bitmap_bit_p (bbs_in_loop_rgns, bb->index))
{
FOR_EACH_EDGE (e, ei, bb->preds)
- if (!TEST_BIT (bbs_in_loop_rgns, e->src->index))
+ if (!bitmap_bit_p (bbs_in_loop_rgns, e->src->index))
degree[bb->index]++;
}
else
/* Any block that did not end up in a region is placed into a region
by itself. */
- FOR_EACH_BB (bb)
+ FOR_EACH_BB_FN (bb, cfun)
if (degree[bb->index] >= 0)
{
rgn_bb_table[cur_rgn_blocks] = bb->index;
/* Free data structures used in pipelining of loops. */
void sel_finish_pipelining (void)
{
- loop_iterator li;
struct loop *loop;
/* Release aux fields so we don't free them later by mistake. */
- FOR_EACH_LOOP (li, loop, 0)
+ FOR_EACH_LOOP (loop, 0)
loop->aux = NULL;
loop_optimizer_finalize ();
- VEC_free (loop_p, heap, loop_nests);
+ loop_nests.release ();
free (rev_top_order_index);
rev_top_order_index = NULL;
}
-/* This function replaces the find_rgns when
+/* This function replaces the find_rgns when
FLAG_SEL_SCHED_PIPELINING_OUTER_LOOPS is set. */
-void
+void
sel_find_rgns (void)
{
sel_init_pipelining ();
if (current_loops)
{
loop_p loop;
- loop_iterator li;
- FOR_EACH_LOOP (li, loop, (flag_sel_sched_pipelining_outer_loops
- ? LI_FROM_INNERMOST
- : LI_ONLY_INNERMOST))
+ FOR_EACH_LOOP (loop, (flag_sel_sched_pipelining_outer_loops
+ ? LI_FROM_INNERMOST
+ : LI_ONLY_INNERMOST))
make_regions_from_loop_nest (loop);
}
/* Make regions from all the rest basic blocks and schedule them.
- These blocks include blocks that don't belong to any loop or belong
+ These blocks include blocks that don't belong to any loop or belong
to irreducible loops. */
make_regions_from_the_rest ();
bbs_in_loop_rgns = NULL;
}
-/* Adds the preheader blocks from previous loop to current region taking
- it from LOOP_PREHEADER_BLOCKS (current_loop_nest).
+/* Add the preheader blocks from previous loop to current region taking
+ it from LOOP_PREHEADER_BLOCKS (current_loop_nest) and record them in *BBS.
This function is only used with -fsel-sched-pipelining-outer-loops. */
void
-sel_add_loop_preheaders (void)
+sel_add_loop_preheaders (bb_vec_t *bbs)
{
int i;
basic_block bb;
- VEC(basic_block, heap) *preheader_blocks
+ vec<basic_block> *preheader_blocks
= LOOP_PREHEADER_BLOCKS (current_loop_nest);
- for (i = 0;
- VEC_iterate (basic_block, preheader_blocks, i, bb);
- i++)
+ if (!preheader_blocks)
+ return;
+
+ for (i = 0; preheader_blocks->iterate (i, &bb); i++)
+ {
+ bbs->safe_push (bb);
+ last_added_blocks.safe_push (bb);
sel_add_bb (bb);
+ }
- VEC_free (basic_block, heap, preheader_blocks);
+ vec_free (preheader_blocks);
}
-/* While pipelining outer loops, returns TRUE if BB is a loop preheader.
- Please note that the function should also work when pipelining_p is
- false, because it is used when deciding whether we should or should
+/* While pipelining outer loops, returns TRUE if BB is a loop preheader.
+ Please note that the function should also work when pipelining_p is
+ false, because it is used when deciding whether we should or should
not reschedule pipelined code. */
bool
sel_is_loop_preheader_p (basic_block bb)
Check that the above code is equivalent to what we did before. */
if (in_current_region_p (current_loop_nest->header))
- gcc_assert (!(BLOCK_TO_BB (bb->index)
+ gcc_assert (!(BLOCK_TO_BB (bb->index)
< BLOCK_TO_BB (current_loop_nest->header->index)));
/* Support the situation when the latch block of outer loop
return false;
}
-/* Checks whether JUMP leads to basic block DEST_BB and no other blocks. */
-bool
-jump_leads_only_to_bb_p (insn_t jump, basic_block dest_bb)
+/* Check whether JUMP_BB ends with a jump insn that leads only to DEST_BB and
+ can be removed, making the corresponding edge fallthrough (assuming that
+ all basic blocks between JUMP_BB and DEST_BB are empty). */
+static bool
+bb_has_removable_jump_to_p (basic_block jump_bb, basic_block dest_bb)
{
- basic_block jump_bb = BLOCK_FOR_INSN (jump);
-
- /* It is not jump, jump with side-effects or jump can lead to several
- basic blocks. */
- if (!onlyjump_p (jump)
- || !any_uncondjump_p (jump))
+ if (!onlyjump_p (BB_END (jump_bb))
+ || tablejump_p (BB_END (jump_bb), NULL, NULL))
return false;
- /* Several outgoing edges, abnormal edge or destination of jump is
+ /* Several outgoing edges, abnormal edge or destination of jump is
not DEST_BB. */
if (EDGE_COUNT (jump_bb->succs) != 1
- || EDGE_SUCC (jump_bb, 0)->flags & EDGE_ABNORMAL
+ || EDGE_SUCC (jump_bb, 0)->flags & (EDGE_ABNORMAL | EDGE_CROSSING)
|| EDGE_SUCC (jump_bb, 0)->dest != dest_bb)
return false;
}
/* Removes the loop preheader from the current region and saves it in
- PREHEADER_BLOCKS of the father loop, so they will be added later to
+ PREHEADER_BLOCKS of the father loop, so they will be added later to
region that represents an outer loop. */
static void
sel_remove_loop_preheader (void)
int cur_rgn = CONTAINING_RGN (BB_TO_BLOCK (0));
basic_block bb;
bool all_empty_p = true;
- VEC(basic_block, heap) *preheader_blocks
+ vec<basic_block> *preheader_blocks
= LOOP_PREHEADER_BLOCKS (loop_outer (current_loop_nest));
+ vec_check_alloc (preheader_blocks, 0);
+
gcc_assert (current_loop_nest);
- old_len = VEC_length (basic_block, preheader_blocks);
+ old_len = preheader_blocks->length ();
/* Add blocks that aren't within the current loop to PREHEADER_BLOCKS. */
for (i = 0; i < RGN_NR_BLOCKS (cur_rgn); i++)
{
- bb = BASIC_BLOCK (BB_TO_BLOCK (i));
+ bb = BASIC_BLOCK_FOR_FN (cfun, BB_TO_BLOCK (i));
- /* If the basic block belongs to region, but doesn't belong to
+ /* If the basic block belongs to region, but doesn't belong to
corresponding loop, then it should be a preheader. */
if (sel_is_loop_preheader_p (bb))
{
- VEC_safe_push (basic_block, heap, preheader_blocks, bb);
+ preheader_blocks->safe_push (bb);
if (BB_END (bb) != bb_note (bb))
all_empty_p = false;
}
}
-
+
/* Remove these blocks only after iterating over the whole region. */
- for (i = VEC_length (basic_block, preheader_blocks) - 1;
- i >= old_len;
- i--)
+ for (i = preheader_blocks->length () - 1; i >= old_len; i--)
{
- bb = VEC_index (basic_block, preheader_blocks, i);
+ bb = (*preheader_blocks)[i];
sel_remove_bb (bb, false);
}
{
if (!all_empty_p)
/* Immediately create new region from preheader. */
- make_region_from_loop_preheader (&preheader_blocks);
+ make_region_from_loop_preheader (preheader_blocks);
else
{
/* If all preheader blocks are empty - dont create new empty region.
Instead, remove them completely. */
- for (i = 0; VEC_iterate (basic_block, preheader_blocks, i, bb); i++)
+ FOR_EACH_VEC_ELT (*preheader_blocks, i, bb)
{
edge e;
edge_iterator ei;
gcc_assert (BB_NOTE_LIST (bb) == NULL);
delete_and_free_basic_block (bb);
- /* Check if after deleting preheader there is a nonconditional
- jump in PREV_BB that leads to the next basic block NEXT_BB.
- If it is so - delete this jump and clear data sets of its
+ /* Check if after deleting preheader there is a nonconditional
+ jump in PREV_BB that leads to the next basic block NEXT_BB.
+ If it is so - delete this jump and clear data sets of its
basic block if it becomes empty. */
if (next_bb->prev_bb == prev_bb
- && prev_bb != ENTRY_BLOCK_PTR
- && jump_leads_only_to_bb_p (BB_END (prev_bb), next_bb))
+ && prev_bb != ENTRY_BLOCK_PTR_FOR_FN (cfun)
+ && bb_has_removable_jump_to_p (prev_bb, next_bb))
{
redirect_edge_and_branch (EDGE_SUCC (prev_bb, 0), next_bb);
if (BB_END (prev_bb) == bb_note (prev_bb))
free_data_sets (prev_bb);
}
+
+ set_immediate_dominator (CDI_DOMINATORS, next_bb,
+ recompute_dominator (CDI_DOMINATORS,
+ next_bb));
}
}
- VEC_free (basic_block, heap, preheader_blocks);
+ vec_free (preheader_blocks);
}
else
/* Store preheader within the father's loop structure. */
SET_LOOP_PREHEADER_BLOCKS (loop_outer (current_loop_nest),
preheader_blocks);
}
+
#endif