/* Try to unroll loops, and split induction variables.
- Copyright (C) 1992, 1993, 1994, 1995, 1997, 1998, 1999, 2000, 2001, 2002
+ Copyright (C) 1992, 1993, 1994, 1995, 1997, 1998, 1999, 2000, 2001,
+ 2002, 2003, 2004
Free Software Foundation, Inc.
Contributed by James E. Wilson, Cygnus Support/UC Berkeley.
/* Forward declarations. */
-static rtx simplify_cmp_and_jump_insns PARAMS ((enum rtx_code,
- enum machine_mode,
- rtx, rtx, rtx));
-static void init_reg_map PARAMS ((struct inline_remap *, int));
-static rtx calculate_giv_inc PARAMS ((rtx, rtx, unsigned int));
-static rtx initial_reg_note_copy PARAMS ((rtx, struct inline_remap *));
-static void final_reg_note_copy PARAMS ((rtx *, struct inline_remap *));
-static void copy_loop_body PARAMS ((struct loop *, rtx, rtx,
- struct inline_remap *, rtx, int,
- enum unroll_types, rtx, rtx, rtx, rtx));
-static int find_splittable_regs PARAMS ((const struct loop *,
- enum unroll_types, int));
-static int find_splittable_givs PARAMS ((const struct loop *,
- struct iv_class *, enum unroll_types,
- rtx, int));
-static int reg_dead_after_loop PARAMS ((const struct loop *, rtx));
-static rtx fold_rtx_mult_add PARAMS ((rtx, rtx, rtx, enum machine_mode));
-static rtx remap_split_bivs PARAMS ((struct loop *, rtx));
-static rtx find_common_reg_term PARAMS ((rtx, rtx));
-static rtx subtract_reg_term PARAMS ((rtx, rtx));
-static rtx loop_find_equiv_value PARAMS ((const struct loop *, rtx));
-static rtx ujump_to_loop_cont PARAMS ((rtx, rtx));
+static rtx simplify_cmp_and_jump_insns (enum rtx_code, enum machine_mode,
+ rtx, rtx, rtx);
+static void init_reg_map (struct inline_remap *, int);
+static rtx calculate_giv_inc (rtx, rtx, unsigned int);
+static rtx initial_reg_note_copy (rtx, struct inline_remap *);
+static void final_reg_note_copy (rtx *, struct inline_remap *);
+static void copy_loop_body (struct loop *, rtx, rtx,
+ struct inline_remap *, rtx, int,
+ enum unroll_types, rtx, rtx, rtx, rtx);
+static int find_splittable_regs (const struct loop *, enum unroll_types,
+ int);
+static int find_splittable_givs (const struct loop *, struct iv_class *,
+ enum unroll_types, rtx, int);
+static int reg_dead_after_loop (const struct loop *, rtx);
+static rtx fold_rtx_mult_add (rtx, rtx, rtx, enum machine_mode);
+static rtx remap_split_bivs (struct loop *, rtx);
+static rtx find_common_reg_term (rtx, rtx);
+static rtx subtract_reg_term (rtx, rtx);
+static rtx loop_find_equiv_value (const struct loop *, rtx);
+static rtx ujump_to_loop_cont (rtx, rtx);
/* Try to unroll one loop and split induction variables in the loop.
in loop.c. */
void
-unroll_loop (loop, insn_count, strength_reduce_p)
- struct loop *loop;
- int insn_count;
- int strength_reduce_p;
+unroll_loop (struct loop *loop, int insn_count, int strength_reduce_p)
{
struct loop_info *loop_info = LOOP_INFO (loop);
struct loop_ivs *ivs = LOOP_IVS (loop);
/* If the last instruction is not a BARRIER or a JUMP_INSN, then
don't do anything. */
- if (GET_CODE (last_loop_insn) == BARRIER)
+ if (BARRIER_P (last_loop_insn))
{
/* Delete the jump insn. This will delete the barrier also. */
last_loop_insn = PREV_INSN (last_loop_insn);
}
- if (ujump && GET_CODE (last_loop_insn) == JUMP_INSN)
+ if (ujump && JUMP_P (last_loop_insn))
{
#ifdef HAVE_cc0
rtx prev = PREV_INSN (last_loop_insn);
Just return without unrolling the loop in such cases. */
insn = loop_start;
- while (GET_CODE (insn) != CODE_LABEL && GET_CODE (insn) != JUMP_INSN)
+ while (!LABEL_P (insn) && !JUMP_P (insn))
insn = NEXT_INSN (insn);
- if (GET_CODE (insn) == JUMP_INSN)
+ if (JUMP_P (insn))
return;
}
insert_before = NEXT_INSN (last_loop_insn);
/* Set copy_end to the insn before the jump at the end of the loop. */
- if (GET_CODE (last_loop_insn) == BARRIER)
+ if (BARRIER_P (last_loop_insn))
copy_end = PREV_INSN (PREV_INSN (last_loop_insn));
- else if (GET_CODE (last_loop_insn) == JUMP_INSN)
+ else if (JUMP_P (last_loop_insn))
{
copy_end = PREV_INSN (last_loop_insn);
#ifdef HAVE_cc0
/* Set insert_before to the jump insn at the end of the loop.
Set copy_end to before the jump insn at the end of the loop. */
- if (GET_CODE (last_loop_insn) == BARRIER)
+ if (BARRIER_P (last_loop_insn))
{
insert_before = PREV_INSN (last_loop_insn);
copy_end = PREV_INSN (insert_before);
}
- else if (GET_CODE (last_loop_insn) == JUMP_INSN)
+ else if (JUMP_P (last_loop_insn))
{
insert_before = last_loop_insn;
#ifdef HAVE_cc0
/* Normal case: Must copy the compare and branch instructions at the
end of the loop. */
- if (GET_CODE (last_loop_insn) == BARRIER)
+ if (BARRIER_P (last_loop_insn))
{
/* Loop ends with an unconditional jump and a barrier.
Handle this like above, don't copy jump and barrier.
insert_before = PREV_INSN (last_loop_insn);
copy_end = PREV_INSN (insert_before);
}
- else if (GET_CODE (last_loop_insn) == JUMP_INSN)
+ else if (JUMP_P (last_loop_insn))
{
/* Set insert_before to immediately after the JUMP_INSN, so that
NOTEs at the end of the loop will be correctly handled by
exit_label = gen_label_rtx ();
insn = loop_start;
- while (GET_CODE (insn) != CODE_LABEL && GET_CODE (insn) != JUMP_INSN)
+ while (!LABEL_P (insn) && !JUMP_P (insn))
insn = NEXT_INSN (insn);
- if (GET_CODE (insn) == JUMP_INSN)
+ if (JUMP_P (insn))
{
/* The loop starts with a jump down to the exit condition test.
Start copying the loop after the barrier following this
/* This should always be the first label in the loop. */
start_label = NEXT_INSN (copy_start);
/* There may be a line number note and/or a loop continue note here. */
- while (GET_CODE (start_label) == NOTE)
+ while (NOTE_P (start_label))
start_label = NEXT_INSN (start_label);
- if (GET_CODE (start_label) != CODE_LABEL)
+ if (!LABEL_P (start_label))
{
/* This can happen as a result of jump threading. If the first insns in
the loop test the same condition as the loop's backward jump, or the
}
if (unroll_type == UNROLL_NAIVE
- && GET_CODE (last_loop_insn) == BARRIER
- && GET_CODE (PREV_INSN (last_loop_insn)) == JUMP_INSN
+ && BARRIER_P (last_loop_insn)
+ && JUMP_P (PREV_INSN (last_loop_insn))
&& start_label != JUMP_LABEL (PREV_INSN (last_loop_insn)))
{
/* In this case, we must copy the jump and barrier, because they will
}
if (unroll_type == UNROLL_NAIVE
- && GET_CODE (last_loop_insn) == JUMP_INSN
+ && JUMP_P (last_loop_insn)
&& start_label != JUMP_LABEL (last_loop_insn))
{
/* ??? The loop ends with a conditional branch that does not branch back
without initializing fields within the map structure.
To be safe, we use xcalloc to zero the memory. */
- map = (struct inline_remap *) xcalloc (1, sizeof (struct inline_remap));
+ map = xcalloc (1, sizeof (struct inline_remap));
/* Allocate the label map. */
if (max_labelno > 0)
{
- map->label_map = (rtx *) xcalloc (max_labelno, sizeof (rtx));
- local_label = (char *) xcalloc (max_labelno, sizeof (char));
+ map->label_map = xcalloc (max_labelno, sizeof (rtx));
+ local_label = xcalloc (max_labelno, sizeof (char));
}
/* Search the loop and mark all local labels, i.e. the ones which have to
{
rtx note;
- if (GET_CODE (insn) == CODE_LABEL)
+ if (LABEL_P (insn))
local_label[CODE_LABEL_NUMBER (insn)] = 1;
- else if (GET_CODE (insn) == JUMP_INSN)
+ else if (JUMP_P (insn))
{
if (JUMP_LABEL (insn))
set_label_in_map (map,
/* Allocate space for the insn map. */
- map->insn_map = (rtx *) xmalloc (max_insnno * sizeof (rtx));
-
- /* Set this to zero, to indicate that we are doing loop unrolling,
- not function inlining. */
- map->inline_target = 0;
+ map->insn_map = xmalloc (max_insnno * sizeof (rtx));
/* The register and constant maps depend on the number of registers
present, so the final maps can't be created until after
preconditioning code and find_splittable_regs will never be used
to access the splittable_regs[] and addr_combined_regs[] arrays. */
- splittable_regs = (rtx *) xcalloc (maxregnum, sizeof (rtx));
- splittable_regs_updates = (int *) xcalloc (maxregnum, sizeof (int));
- addr_combined_regs
- = (struct induction **) xcalloc (maxregnum, sizeof (struct induction *));
- local_regno = (char *) xcalloc (maxregnum, sizeof (char));
+ splittable_regs = xcalloc (maxregnum, sizeof (rtx));
+ splittable_regs_updates = xcalloc (maxregnum, sizeof (int));
+ addr_combined_regs = xcalloc (maxregnum, sizeof (struct induction *));
+ local_regno = xcalloc (maxregnum, sizeof (char));
/* Mark all local registers, i.e. the ones which are referenced only
inside the loop. */
/* If a register is used in the jump insn, we must not duplicate it
since it will also be used outside the loop. */
- if (GET_CODE (copy_end) == JUMP_INSN)
+ if (JUMP_P (copy_end))
copy_end_luid--;
/* If we have a target that uses cc0, then we also must not duplicate
the insn that sets cc0 before the jump insn, if one is present. */
#ifdef HAVE_cc0
- if (GET_CODE (copy_end) == JUMP_INSN
+ if (JUMP_P (copy_end)
&& sets_cc0_p (PREV_INSN (copy_end)))
copy_end_luid--;
#endif
int less_p = (cc == LE || cc == LEU || cc == LT || cc == LTU);
int unsigned_p = (cc == LEU || cc == GEU || cc == LTU || cc == GTU);
- map->reg_map = (rtx *) xmalloc (maxregnum * sizeof (rtx));
+ map->reg_map = xmalloc (maxregnum * sizeof (rtx));
VARRAY_CONST_EQUIV_INIT (map->const_equiv_varray, maxregnum,
"unroll_loop_precondition");
/* Now emit a sequence of branches to jump to the proper precond
loop entry point. */
- labels = (rtx *) xmalloc (sizeof (rtx) * unroll_number);
+ labels = xmalloc (sizeof (rtx) * unroll_number);
for (i = 0; i < unroll_number; i++)
labels[i] = gen_label_rtx ();
and then reset it inside the loop when get to the last
copy. */
- if (GET_CODE (last_loop_insn) == BARRIER)
+ if (BARRIER_P (last_loop_insn))
copy_end = PREV_INSN (PREV_INSN (last_loop_insn));
- else if (GET_CODE (last_loop_insn) == JUMP_INSN)
+ else if (JUMP_P (last_loop_insn))
{
copy_end = PREV_INSN (last_loop_insn);
#ifdef HAVE_cc0
emit_label_after (labels[unroll_number - i],
PREV_INSN (loop_start));
- memset ((char *) map->insn_map, 0, max_insnno * sizeof (rtx));
- memset ((char *) &VARRAY_CONST_EQUIV (map->const_equiv_varray, 0),
+ memset (map->insn_map, 0, max_insnno * sizeof (rtx));
+ memset (&VARRAY_CONST_EQUIV (map->const_equiv_varray, 0),
0, (VARRAY_SIZE (map->const_equiv_varray)
* sizeof (struct const_equiv_data)));
map->const_age = 0;
if (i == unroll_number - 1)
{
- if (GET_CODE (last_loop_insn) == BARRIER)
+ if (BARRIER_P (last_loop_insn))
copy_end = PREV_INSN (PREV_INSN (last_loop_insn));
else
copy_end = last_loop_insn;
}
emit_label_after (labels[0], PREV_INSN (loop_start));
- if (GET_CODE (last_loop_insn) == BARRIER)
+ if (BARRIER_P (last_loop_insn))
{
insert_before = PREV_INSN (last_loop_insn);
copy_end = PREV_INSN (insert_before);
the constant maps also. */
maxregnum = max_reg_num ();
- map->reg_map = (rtx *) xmalloc (maxregnum * sizeof (rtx));
+ map->reg_map = xmalloc (maxregnum * sizeof (rtx));
init_reg_map (map, maxregnum);
if (unroll_type == UNROLL_MODULO)
{
insn = NEXT_INSN (copy_end);
- if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN)
+ if (NONJUMP_INSN_P (insn) || JUMP_P (insn))
PATTERN (insn) = remap_split_bivs (loop, PATTERN (insn));
}
for (i = 0; i < unroll_number; i++)
{
- memset ((char *) map->insn_map, 0, max_insnno * sizeof (rtx));
- memset ((char *) &VARRAY_CONST_EQUIV (map->const_equiv_varray, 0), 0,
+ memset (map->insn_map, 0, max_insnno * sizeof (rtx));
+ memset (&VARRAY_CONST_EQUIV (map->const_equiv_varray, 0), 0,
VARRAY_SIZE (map->const_equiv_varray) * sizeof (struct const_equiv_data));
map->const_age = 0;
associated LABEL_DECL to point to one of the new label instances. */
/* ??? Likewise, we can't delete a NOTE_INSN_DELETED_LABEL note. */
if (insn != start_label
- && ! (GET_CODE (insn) == CODE_LABEL && LABEL_NAME (insn))
- && ! (GET_CODE (insn) == NOTE
+ && ! (LABEL_P (insn) && LABEL_NAME (insn))
+ && ! (NOTE_P (insn)
&& NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL))
insn = delete_related_insns (insn);
else
free (map);
}
-/* A helper function for unroll_loop. Emit a compare and branch to
+/* A helper function for unroll_loop. Emit a compare and branch to
satisfy (CMP OP1 OP2), but pass this through the simplifier first.
If the branch turned out to be conditional, return it, otherwise
return NULL. */
static rtx
-simplify_cmp_and_jump_insns (code, mode, op0, op1, label)
- enum rtx_code code;
- enum machine_mode mode;
- rtx op0, op1, label;
+simplify_cmp_and_jump_insns (enum rtx_code code, enum machine_mode mode,
+ rtx op0, rtx op1, rtx label)
{
rtx t, insn;
- t = simplify_relational_operation (code, mode, op0, op1);
+ t = simplify_const_relational_operation (code, mode, op0, op1);
if (!t)
{
enum rtx_code scode = signed_condition (code);
reflected in RTX_COST. */
int
-precondition_loop_p (loop, initial_value, final_value, increment, mode)
- const struct loop *loop;
- rtx *initial_value, *final_value, *increment;
- enum machine_mode *mode;
+precondition_loop_p (const struct loop *loop, rtx *initial_value,
+ rtx *final_value, rtx *increment,
+ enum machine_mode *mode)
{
rtx loop_start = loop->start;
struct loop_info *loop_info = LOOP_INFO (loop);
against max_reg_before_loop to make sure that the register is in
the range covered by loop_invariant_p. If it isn't, then it is
most likely a biv/giv which by definition are not invariant. */
- if ((GET_CODE (loop_info->final_value) == REG
+ if ((REG_P (loop_info->final_value)
&& REGNO (loop_info->final_value) >= max_reg_before_loop)
|| (GET_CODE (loop_info->final_value) == PLUS
&& REGNO (XEXP (loop_info->final_value, 0)) >= max_reg_before_loop)
modes. */
static void
-init_reg_map (map, maxregnum)
- struct inline_remap *map;
- int maxregnum;
+init_reg_map (struct inline_remap *map, int maxregnum)
{
int i;
The return value is the amount that the giv is incremented by. */
static rtx
-calculate_giv_inc (pattern, src_insn, regno)
- rtx pattern, src_insn;
- unsigned int regno;
+calculate_giv_inc (rtx pattern, rtx src_insn, unsigned int regno)
{
rtx increment;
rtx increment_total = 0;
/* Some ports store large constants in memory and add a REG_EQUAL
note to the store insn. */
- else if (GET_CODE (increment) == MEM)
+ else if (MEM_P (increment))
{
rtx note = find_reg_note (src_insn, REG_EQUAL, 0);
if (note)
/* Check that the source register is the same as the register we expected
to see as the source. If not, something is seriously wrong. */
- if (GET_CODE (XEXP (SET_SRC (pattern), 0)) != REG
+ if (!REG_P (XEXP (SET_SRC (pattern), 0))
|| REGNO (XEXP (SET_SRC (pattern), 0)) != regno)
{
/* Some machines (e.g. the romp), may emit two add instructions for
the reg_map entries can change during copying. */
static rtx
-initial_reg_note_copy (notes, map)
- rtx notes;
- struct inline_remap *map;
+initial_reg_note_copy (rtx notes, struct inline_remap *map)
{
rtx copy;
/* Fixup insn references in copied REG_NOTES. */
static void
-final_reg_note_copy (notesp, map)
- rtx *notesp;
- struct inline_remap *map;
+final_reg_note_copy (rtx *notesp, struct inline_remap *map)
{
while (*notesp)
{
if (GET_CODE (note) == INSN_LIST)
{
- /* Sometimes, we have a REG_WAS_0 note that points to a
- deleted instruction. In that case, we can just delete the
- note. */
- if (REG_NOTE_KIND (note) == REG_WAS_0)
+ rtx insn = map->insn_map[INSN_UID (XEXP (note, 0))];
+
+ /* If we failed to remap the note, something is awry.
+ Allow REG_LABEL as it may reference label outside
+ the unrolled loop. */
+ if (!insn)
{
- *notesp = XEXP (note, 1);
- continue;
+ if (REG_NOTE_KIND (note) != REG_LABEL)
+ abort ();
}
else
- {
- rtx insn = map->insn_map[INSN_UID (XEXP (note, 0))];
-
- /* If we failed to remap the note, something is awry.
- Allow REG_LABEL as it may reference label outside
- the unrolled loop. */
- if (!insn)
- {
- if (REG_NOTE_KIND (note) != REG_LABEL)
- abort ();
- }
- else
- XEXP (note, 0) = insn;
- }
+ XEXP (note, 0) = insn;
}
notesp = &XEXP (note, 1);
This is very similar to a loop in expand_inline_function. */
static void
-copy_loop_body (loop, copy_start, copy_end, map, exit_label, last_iteration,
- unroll_type, start_label, loop_end, insert_before,
- copy_notes_from)
- struct loop *loop;
- rtx copy_start, copy_end;
- struct inline_remap *map;
- rtx exit_label;
- int last_iteration;
- enum unroll_types unroll_type;
- rtx start_label, loop_end, insert_before, copy_notes_from;
+copy_loop_body (struct loop *loop, rtx copy_start, rtx copy_end,
+ struct inline_remap *map, rtx exit_label,
+ int last_iteration, enum unroll_types unroll_type,
+ rtx start_label, rtx loop_end, rtx insert_before,
+ rtx copy_notes_from)
{
struct loop_ivs *ivs = LOOP_IVS (loop);
rtx insn, pattern;
SET_DEST to a new register. */
if ((set = single_set (insn))
- && GET_CODE (SET_DEST (set)) == REG
+ && REG_P (SET_DEST (set))
&& addr_combined_regs[REGNO (SET_DEST (set))])
{
struct iv_class *bl;
/* tv->dest_reg will be either a bare register,
or else a register plus a constant. */
- if (GET_CODE (tv->dest_reg) == REG)
+ if (REG_P (tv->dest_reg))
dest_reg = tv->dest_reg;
else
dest_reg = XEXP (tv->dest_reg, 0);
dest_reg_was_split = 0;
if ((set = single_set (insn))
- && GET_CODE (SET_DEST (set)) == REG
+ && REG_P (SET_DEST (set))
&& splittable_regs[REGNO (SET_DEST (set))])
{
unsigned int regno = REGNO (SET_DEST (set));
}
}
- if (label && GET_CODE (label) == CODE_LABEL)
+ if (label && LABEL_P (label))
JUMP_LABEL (copy) = label;
else
{
the associated rtl. We do not want to share the structure in
this new block. */
- if (NOTE_LINE_NUMBER (insn) > 0)
- copy = emit_line_note (NOTE_SOURCE_FILE (insn),
- NOTE_LINE_NUMBER (insn));
- else if (NOTE_LINE_NUMBER (insn) != NOTE_INSN_DELETED
+ if (NOTE_LINE_NUMBER (insn) != NOTE_INSN_DELETED
&& NOTE_LINE_NUMBER (insn) != NOTE_INSN_DELETED_LABEL
&& NOTE_LINE_NUMBER (insn) != NOTE_INSN_BASIC_BLOCK
&& ((NOTE_LINE_NUMBER (insn) != NOTE_INSN_LOOP_VTOP
&& NOTE_LINE_NUMBER (insn) != NOTE_INSN_LOOP_CONT)
|| (last_iteration
&& unroll_type != UNROLL_COMPLETELY)))
- {
- copy = emit_note (NULL, NOTE_LINE_NUMBER (insn));
- NOTE_DATA (copy) = NOTE_DATA (insn);
- }
+ copy = emit_note_copy (insn);
else
copy = 0;
break;
do
{
insn = NEXT_INSN (insn);
- if ((GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
- || GET_CODE (insn) == CALL_INSN)
+ if (INSN_P (insn)
&& map->insn_map[INSN_UID (insn)])
final_reg_note_copy (®_NOTES (map->insn_map[INSN_UID (insn)]), map);
}
instructions before the last insn in the loop, COPY_NOTES_FROM
can be a NOTE_INSN_LOOP_CONT note if there is no VTOP note,
as in a do .. while loop. */
- if (GET_CODE (insn) != NOTE)
- /*NOP*/;
- else if (NOTE_LINE_NUMBER (insn) > 0)
- emit_line_note (NOTE_SOURCE_FILE (insn), NOTE_LINE_NUMBER (insn));
- else if (NOTE_LINE_NUMBER (insn) != NOTE_INSN_DELETED
+ if (NOTE_P (insn)
+ && ((NOTE_LINE_NUMBER (insn) != NOTE_INSN_DELETED
&& NOTE_LINE_NUMBER (insn) != NOTE_INSN_BASIC_BLOCK
&& NOTE_LINE_NUMBER (insn) != NOTE_INSN_LOOP_VTOP
- && NOTE_LINE_NUMBER (insn) != NOTE_INSN_LOOP_CONT)
- {
- rtx copy = emit_note (NULL, NOTE_LINE_NUMBER (insn));
- NOTE_DATA (copy) = NOTE_DATA (insn);
- }
+ && NOTE_LINE_NUMBER (insn) != NOTE_INSN_LOOP_CONT)))
+ emit_note_copy (insn);
}
}
won't fit in the immediate field of a PLUS insns. */
void
-emit_unrolled_add (dest_reg, src_reg, increment)
- rtx dest_reg, src_reg, increment;
+emit_unrolled_add (rtx dest_reg, rtx src_reg, rtx increment)
{
rtx result;
and uses a negligible amount of CPU time on average. */
int
-back_branch_in_range_p (loop, insn)
- const struct loop *loop;
- rtx insn;
+back_branch_in_range_p (const struct loop *loop, rtx insn)
{
rtx p, q, target_insn;
rtx loop_start = loop->start;
/* Stop before we get to the backward branch at the end of the loop. */
loop_end = prev_nonnote_insn (loop_end);
- if (GET_CODE (loop_end) == BARRIER)
+ if (BARRIER_P (loop_end))
loop_end = PREV_INSN (loop_end);
/* Check in case insn has been deleted, search forward for first non
for (p = NEXT_INSN (insn); p != loop_end; p = NEXT_INSN (p))
{
- if (GET_CODE (p) == JUMP_INSN)
+ if (JUMP_P (p))
{
target_insn = JUMP_LABEL (p);
value of giv's. */
static rtx
-fold_rtx_mult_add (mult1, mult2, add1, mode)
- rtx mult1, mult2, add1;
- enum machine_mode mode;
+fold_rtx_mult_add (rtx mult1, rtx mult2, rtx add1, enum machine_mode mode)
{
rtx temp, mult_res;
rtx result;
if it can be calculated. Otherwise, returns 0. */
rtx
-biv_total_increment (bl)
- const struct iv_class *bl;
+biv_total_increment (const struct iv_class *bl)
{
struct induction *v;
rtx result;
if (v->always_computable && v->mult_val == const1_rtx
&& ! v->maybe_multiple
&& SCALAR_INT_MODE_P (v->mode))
- result = fold_rtx_mult_add (result, const1_rtx, v->add_val, v->mode);
+ {
+ /* If we have already counted it, skip it. */
+ if (v->same)
+ continue;
+
+ result = fold_rtx_mult_add (result, const1_rtx, v->add_val, v->mode);
+ }
else
return 0;
}
times, since multiplies by small integers (1,2,3,4) are very cheap. */
static int
-find_splittable_regs (loop, unroll_type, unroll_number)
- const struct loop *loop;
- enum unroll_types unroll_type;
- int unroll_number;
+find_splittable_regs (const struct loop *loop,
+ enum unroll_types unroll_type, int unroll_number)
{
struct loop_ivs *ivs = LOOP_IVS (loop);
struct iv_class *bl;
PLUS, we don't know how to split it. */
for (v = bl->biv; biv_splittable && v; v = v->next_iv)
if ((tem = single_set (v->insn)) == 0
- || GET_CODE (SET_DEST (tem)) != REG
+ || !REG_P (SET_DEST (tem))
|| REGNO (SET_DEST (tem)) != bl->regno
|| GET_CODE (SET_SRC (tem)) != PLUS)
biv_splittable = 0;
register, or it isn't invariant, then we must create a new
pseudo reg to hold the initial value of the biv. */
- if (GET_CODE (bl->initial_value) == REG
+ if (REG_P (bl->initial_value)
&& (REGNO (bl->initial_value) == bl->regno
|| REGNO (bl->initial_value) < FIRST_PSEUDO_REGISTER
|| ! loop_invariant_p (loop, bl->initial_value)))
Return the number of instructions that set splittable registers. */
static int
-find_splittable_givs (loop, bl, unroll_type, increment, unroll_number)
- const struct loop *loop;
- struct iv_class *bl;
- enum unroll_types unroll_type;
- rtx increment;
- int unroll_number ATTRIBUTE_UNUSED;
+find_splittable_givs (const struct loop *loop, struct iv_class *bl,
+ enum unroll_types unroll_type, rtx increment,
+ int unroll_number ATTRIBUTE_UNUSED)
{
struct loop_ivs *ivs = LOOP_IVS (loop);
struct induction *v, *v2;
if (splittable_regs[bl->regno])
biv_initial_value = splittable_regs[bl->regno];
- else if (GET_CODE (bl->initial_value) != REG
+ else if (!REG_P (bl->initial_value)
|| (REGNO (bl->initial_value) != bl->regno
&& REGNO (bl->initial_value) >= FIRST_PSEUDO_REGISTER))
biv_initial_value = bl->initial_value;
is going before the loop start. */
if (unroll_type == UNROLL_COMPLETELY
&& GET_CODE (value) != CONST_INT
- && GET_CODE (value) != REG
+ && !REG_P (value)
&& (GET_CODE (value) != PLUS
- || GET_CODE (XEXP (value, 0)) != REG
+ || !REG_P (XEXP (value, 0))
|| GET_CODE (XEXP (value, 1)) != CONST_INT))
{
rtx tem = gen_reg_rtx (v->mode);
record_base_value (REGNO (tem), v->add_val, 0);
- loop_iv_add_mult_hoist (loop, bl->initial_value, v->mult_val,
- v->add_val, tem);
+ loop_iv_add_mult_hoist (loop,
+ extend_value_for_giv (v, bl->initial_value),
+ v->mult_val, v->add_val, tem);
value = tem;
}
a splittable register. Don't need to do anything for address givs
where this may not be a register. */
- if (GET_CODE (v->new_reg) == REG)
+ if (REG_P (v->new_reg))
{
int count = 1;
if (! v->ignore)
if (GET_CODE (v->dest_reg) == CONST_INT)
regnum = -1;
- else if (GET_CODE (v->dest_reg) != REG)
+ else if (!REG_P (v->dest_reg))
regnum = REGNO (XEXP (v->dest_reg, 0));
else
regnum = REGNO (v->dest_reg);
it can search past if statements and other similar structures. */
static int
-reg_dead_after_loop (loop, reg)
- const struct loop *loop;
- rtx reg;
+reg_dead_after_loop (const struct loop *loop, rtx reg)
{
rtx insn, label;
- enum rtx_code code;
int jump_count = 0;
int label_count = 0;
insn = NEXT_INSN (XEXP (label, 0));
while (insn)
{
- code = GET_CODE (insn);
- if (GET_RTX_CLASS (code) == 'i')
+ if (INSN_P (insn))
{
- rtx set;
+ rtx set, note;
if (reg_referenced_p (reg, PATTERN (insn)))
return 0;
+ note = find_reg_equal_equiv_note (insn);
+ if (note && reg_overlap_mentioned_p (reg, XEXP (note, 0)))
+ return 0;
+
set = single_set (insn);
if (set && rtx_equal_p (SET_DEST (set), reg))
break;
- }
- if (code == JUMP_INSN)
- {
- if (GET_CODE (PATTERN (insn)) == RETURN)
- break;
- else if (!any_uncondjump_p (insn)
- /* Prevent infinite loop following infinite loops. */
- || jump_count++ > 20)
- return 0;
- else
- insn = JUMP_LABEL (insn);
+ if (JUMP_P (insn))
+ {
+ if (GET_CODE (PATTERN (insn)) == RETURN)
+ break;
+ else if (!any_uncondjump_p (insn)
+ /* Prevent infinite loop following infinite loops. */
+ || jump_count++ > 20)
+ return 0;
+ else
+ insn = JUMP_LABEL (insn);
+ }
}
insn = NEXT_INSN (insn);
the end of the loop. If we can do it, return that value. */
rtx
-final_biv_value (loop, bl)
- const struct loop *loop;
- struct iv_class *bl;
+final_biv_value (const struct loop *loop, struct iv_class *bl)
{
unsigned HOST_WIDE_INT n_iterations = LOOP_INFO (loop)->n_iterations;
rtx increment, tem;
the end of the loop. If we can do it, return that value. */
rtx
-final_giv_value (loop, v)
- const struct loop *loop;
- struct induction *v;
+final_giv_value (const struct loop *loop, struct induction *v)
{
struct loop_ivs *ivs = LOOP_IVS (loop);
struct iv_class *bl;
the SET_SRC of REG. */
static rtx
-loop_find_equiv_value (loop, reg)
- const struct loop *loop;
- rtx reg;
+loop_find_equiv_value (const struct loop *loop, rtx reg)
{
rtx loop_start = loop->start;
rtx insn, set;
ret = reg;
for (insn = PREV_INSN (loop_start); insn; insn = PREV_INSN (insn))
{
- if (GET_CODE (insn) == CODE_LABEL)
+ if (LABEL_P (insn))
break;
else if (INSN_P (insn) && reg_set_p (reg, insn))
the proper form. */
static rtx
-subtract_reg_term (op, reg)
- rtx op, reg;
+subtract_reg_term (rtx op, rtx reg)
{
if (op == reg)
return const0_rtx;
REG or a PLUS of a REG. */
static rtx
-find_common_reg_term (op0, op1)
- rtx op0, op1;
+find_common_reg_term (rtx op0, rtx op1)
{
- if ((GET_CODE (op0) == REG || GET_CODE (op0) == PLUS)
- && (GET_CODE (op1) == REG || GET_CODE (op1) == PLUS))
+ if ((REG_P (op0) || GET_CODE (op0) == PLUS)
+ && (REG_P (op1) || GET_CODE (op1) == PLUS))
{
rtx op00;
rtx op01;
be calculated, otherwise returns zero. */
unsigned HOST_WIDE_INT
-loop_iterations (loop)
- struct loop *loop;
+loop_iterations (struct loop *loop)
{
struct loop_info *loop_info = LOOP_INFO (loop);
struct loop_ivs *ivs = LOOP_IVS (loop);
/* ??? We should probably try harder to find the jump insn
at the end of the loop. The following code assumes that
the last loop insn is a jump to the top of the loop. */
- if (GET_CODE (last_loop_insn) != JUMP_INSN)
+ if (!JUMP_P (last_loop_insn))
{
if (loop_dump_stream)
fprintf (loop_dump_stream,
do
{
- if (GET_CODE (temp) == JUMP_INSN)
+ if (JUMP_P (temp))
{
/* There are some kinds of jumps we can't deal with easily. */
if (JUMP_LABEL (temp) == 0)
iteration_var = XEXP (comparison, 0);
comparison_value = XEXP (comparison, 1);
- if (GET_CODE (iteration_var) != REG)
+ if (!REG_P (iteration_var))
{
if (loop_dump_stream)
fprintf (loop_dump_stream,
"Loop iterations: Iteration var not an integer.\n");
return 0;
}
- else if (REG_IV_TYPE (ivs, REGNO (iteration_var)) == BASIC_INDUCT)
+
+ /* Try swapping the comparison to identify a suitable iv. */
+ if (REG_IV_TYPE (ivs, REGNO (iteration_var)) != BASIC_INDUCT
+ && REG_IV_TYPE (ivs, REGNO (iteration_var)) != GENERAL_INDUCT
+ && REG_P (comparison_value)
+ && REGNO (comparison_value) < ivs->n_regs)
+ {
+ rtx temp = comparison_value;
+ comparison_code = swap_condition (comparison_code);
+ comparison_value = iteration_var;
+ iteration_var = temp;
+ }
+
+ if (REG_IV_TYPE (ivs, REGNO (iteration_var)) == BASIC_INDUCT)
{
if (REGNO (iteration_var) >= ivs->n_regs)
abort ();
return 0;
}
+ /* If we have already counted it, skip it. */
+ if (biv_inc->same)
+ continue;
+
offset -= INTVAL (biv_inc->add_val);
}
}
unsigned_p = 1;
case GT:
compare_dir = -1;
+ break;
case NE:
compare_dir = 0;
break;
its value from the insns before the start of the loop. */
final_value = comparison_value;
- if (GET_CODE (comparison_value) == REG
+ if (REG_P (comparison_value)
&& loop_invariant_p (loop, comparison_value))
{
final_value = loop_find_equiv_value (loop, comparison_value);
if (find_common_reg_term (temp, reg2))
initial_value = temp;
- else
+ else if (loop_invariant_p (loop, reg2))
{
/* Find what reg2 is equivalent to. Hopefully it will
either be reg1 or reg1 plus a constant. Let's ignore
/* If we have a REG, check to see if REG holds a constant value. */
/* ??? Other RTL, such as (neg (reg)) is possible here, but it isn't
clear if it is worthwhile to try to handle such RTL. */
- if (GET_CODE (increment) == REG || GET_CODE (increment) == SUBREG)
+ if (REG_P (increment) || GET_CODE (increment) == SUBREG)
increment = loop_find_equiv_value (loop, increment);
if (GET_CODE (increment) != CONST_INT)
copying. */
static rtx
-remap_split_bivs (loop, x)
- struct loop *loop;
- rtx x;
+remap_split_bivs (struct loop *loop, rtx x)
{
struct loop_ivs *ivs = LOOP_IVS (loop);
enum rtx_code code;
must dominate LAST_UID. */
int
-set_dominates_use (regno, first_uid, last_uid, copy_start, copy_end)
- int regno;
- int first_uid;
- int last_uid;
- rtx copy_start;
- rtx copy_end;
+set_dominates_use (int regno, int first_uid, int last_uid, rtx copy_start,
+ rtx copy_end)
{
int passed_jump = 0;
rtx p = NEXT_INSN (copy_start);
while (INSN_UID (p) != first_uid)
{
- if (GET_CODE (p) == JUMP_INSN)
+ if (JUMP_P (p))
passed_jump = 1;
/* Could not find FIRST_UID. */
if (p == copy_end)
{
/* If we see a CODE_LABEL between FIRST_UID and LAST_UID, then we
can not be sure that FIRST_UID dominates LAST_UID. */
- if (GET_CODE (p) == CODE_LABEL)
+ if (LABEL_P (p))
return 0;
/* Could not find LAST_UID, but we reached the end of the loop, so
it must be safe. */
deleted so that we execute the single iteration. */
static rtx
-ujump_to_loop_cont (loop_start, loop_cont)
- rtx loop_start;
- rtx loop_cont;
+ujump_to_loop_cont (rtx loop_start, rtx loop_cont)
{
rtx x, label, label_ref;
/* Examine insn after loop continuation note. Return if not a label. */
label = next_nonnote_insn (loop_cont);
- if (label == 0 || GET_CODE (label) != CODE_LABEL)
+ if (label == 0 || !LABEL_P (label))
return NULL_RTX;
/* Return the loop start if the branch label matches the code label. */