Commit f8305d18 by Richard Sandiford Committed by Richard Sandiford

combine-stack-adj.c: Include rtl-iter.h.

gcc/
	* combine-stack-adj.c: Include rtl-iter.h.
	(record_stack_refs_data): Delete.
	(record_stack_refs): Turn from being a for_each_rtx callback
	to being a function that examines each subrtx itself.
	Take a pointer to the reflist.  Invert sense of return value
	so that true means success and false means failure.  Don't
	handle null rtxes.
	(combine_stack_adjustments_for_block): Update accordingly.

From-SVN: r214625
parent 46bbda03
2014-08-28 Richard Sandiford <rdsandiford@googlemail.com> 2014-08-28 Richard Sandiford <rdsandiford@googlemail.com>
* combine-stack-adj.c: Include rtl-iter.h.
(record_stack_refs_data): Delete.
(record_stack_refs): Turn from being a for_each_rtx callback
to being a function that examines each subrtx itself.
Take a pointer to the reflist. Invert sense of return value
so that true means success and false means failure. Don't
handle null rtxes.
(combine_stack_adjustments_for_block): Update accordingly.
2014-08-28 Richard Sandiford <rdsandiford@googlemail.com>
* combine.c (record_truncated_value): Turn from being a for_each_rtx * combine.c (record_truncated_value): Turn from being a for_each_rtx
callback to a function that takes an rtx and returns a bool callback to a function that takes an rtx and returns a bool
(record_truncated_values): Use FOR_EACH_SUBRTX_VAR instead of (record_truncated_values): Use FOR_EACH_SUBRTX_VAR instead of
......
...@@ -56,6 +56,7 @@ along with GCC; see the file COPYING3. If not see ...@@ -56,6 +56,7 @@ along with GCC; see the file COPYING3. If not see
#include "except.h" #include "except.h"
#include "reload.h" #include "reload.h"
#include "tree-pass.h" #include "tree-pass.h"
#include "rtl-iter.h"
/* Turn STACK_GROWS_DOWNWARD into a boolean. */ /* Turn STACK_GROWS_DOWNWARD into a boolean. */
...@@ -86,7 +87,6 @@ static struct csa_reflist *record_one_stack_ref (rtx_insn *, rtx *, ...@@ -86,7 +87,6 @@ static struct csa_reflist *record_one_stack_ref (rtx_insn *, rtx *,
static int try_apply_stack_adjustment (rtx_insn *, struct csa_reflist *, static int try_apply_stack_adjustment (rtx_insn *, struct csa_reflist *,
HOST_WIDE_INT, HOST_WIDE_INT); HOST_WIDE_INT, HOST_WIDE_INT);
static void combine_stack_adjustments_for_block (basic_block); static void combine_stack_adjustments_for_block (basic_block);
static int record_stack_refs (rtx *, void *);
/* Main entry point for stack adjustment combination. */ /* Main entry point for stack adjustment combination. */
...@@ -237,61 +237,63 @@ try_apply_stack_adjustment (rtx_insn *insn, struct csa_reflist *reflist, ...@@ -237,61 +237,63 @@ try_apply_stack_adjustment (rtx_insn *insn, struct csa_reflist *reflist,
return 0; return 0;
} }
/* Called via for_each_rtx and used to record all stack memory and other /* For non-debug insns, record all stack memory references in INSN
references in the insn and discard all other stack pointer references. */ and return true if there were no other (unrecorded) references to the
struct record_stack_refs_data stack pointer. For debug insns, record all stack references regardless
{ of context and unconditionally return true. */
rtx_insn *insn;
struct csa_reflist *reflist;
};
static int static bool
record_stack_refs (rtx *xp, void *data) record_stack_refs (rtx_insn *insn, struct csa_reflist **reflist)
{ {
rtx x = *xp; subrtx_ptr_iterator::array_type array;
struct record_stack_refs_data *d = FOR_EACH_SUBRTX_PTR (iter, array, &PATTERN (insn), NONCONST)
(struct record_stack_refs_data *) data;
if (!x)
return 0;
switch (GET_CODE (x))
{ {
case MEM: rtx *loc = *iter;
if (!reg_mentioned_p (stack_pointer_rtx, x)) rtx x = *loc;
return -1; switch (GET_CODE (x))
/* We are not able to handle correctly all possible memrefs containing
stack pointer, so this check is necessary. */
if (stack_memref_p (x))
{
d->reflist = record_one_stack_ref (d->insn, xp, d->reflist);
return -1;
}
/* Try harder for DEBUG_INSNs, handle e.g. (mem (mem (sp + 16) + 4). */
return !DEBUG_INSN_P (d->insn);
case REG:
/* ??? We want be able to handle non-memory stack pointer
references later. For now just discard all insns referring to
stack pointer outside mem expressions. We would probably
want to teach validate_replace to simplify expressions first.
We can't just compare with STACK_POINTER_RTX because the
reference to the stack pointer might be in some other mode.
In particular, an explicit clobber in an asm statement will
result in a QImode clobber.
In DEBUG_INSNs, we want to replace all occurrences, otherwise
they will cause -fcompare-debug failures. */
if (REGNO (x) == STACK_POINTER_REGNUM)
{ {
if (!DEBUG_INSN_P (d->insn)) case MEM:
return 1; if (!reg_mentioned_p (stack_pointer_rtx, x))
d->reflist = record_one_stack_ref (d->insn, xp, d->reflist); iter.skip_subrtxes ();
return -1; /* We are not able to handle correctly all possible memrefs
containing stack pointer, so this check is necessary. */
else if (stack_memref_p (x))
{
*reflist = record_one_stack_ref (insn, loc, *reflist);
iter.skip_subrtxes ();
}
/* Try harder for DEBUG_INSNs, handle e.g.
(mem (mem (sp + 16) + 4). */
else if (!DEBUG_INSN_P (insn))
return false;
break;
case REG:
/* ??? We want be able to handle non-memory stack pointer
references later. For now just discard all insns referring to
stack pointer outside mem expressions. We would probably
want to teach validate_replace to simplify expressions first.
We can't just compare with STACK_POINTER_RTX because the
reference to the stack pointer might be in some other mode.
In particular, an explicit clobber in an asm statement will
result in a QImode clobber.
In DEBUG_INSNs, we want to replace all occurrences, otherwise
they will cause -fcompare-debug failures. */
if (REGNO (x) == STACK_POINTER_REGNUM)
{
if (!DEBUG_INSN_P (insn))
return false;
*reflist = record_one_stack_ref (insn, loc, *reflist);
}
break;
default:
break;
} }
break;
default:
break;
} }
return 0; return true;
} }
/* If INSN has a REG_ARGS_SIZE note, move it to LAST. /* If INSN has a REG_ARGS_SIZE note, move it to LAST.
...@@ -432,7 +434,6 @@ combine_stack_adjustments_for_block (basic_block bb) ...@@ -432,7 +434,6 @@ combine_stack_adjustments_for_block (basic_block bb)
struct csa_reflist *reflist = NULL; struct csa_reflist *reflist = NULL;
rtx_insn *insn, *next; rtx_insn *insn, *next;
rtx set; rtx set;
struct record_stack_refs_data data;
bool end_of_block = false; bool end_of_block = false;
for (insn = BB_HEAD (bb); !end_of_block ; insn = next) for (insn = BB_HEAD (bb); !end_of_block ; insn = next)
...@@ -583,15 +584,9 @@ combine_stack_adjustments_for_block (basic_block bb) ...@@ -583,15 +584,9 @@ combine_stack_adjustments_for_block (basic_block bb)
} }
} }
data.insn = insn;
data.reflist = reflist;
if (!CALL_P (insn) && last_sp_set if (!CALL_P (insn) && last_sp_set
&& !for_each_rtx (&PATTERN (insn), record_stack_refs, &data)) && record_stack_refs (insn, &reflist))
{ continue;
reflist = data.reflist;
continue;
}
reflist = data.reflist;
/* Otherwise, we were not able to process the instruction. /* Otherwise, we were not able to process the instruction.
Do not continue collecting data across such a one. */ Do not continue collecting data across such a one. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment