Combine_stack_adjustments improvement
Jan Hubicka
hubicka@atrey.karlin.mff.cuni.cz
Fri Apr 28 03:14:00 GMT 2000
Hi
This patch allows arbitary references to stack in between of stack
adjustments - not only the loads/stores.
In future it would be nice to merge this with related register elimination
code in reload, but this don't seems to be easy task.
Honza
Thu Apr 27 21:50:56 CEST 2000 Jan Hubicka <jh@suse.cz>
* regmove.c (struct record_stack_memrefs_data): New.
(record_stack_memrefs): New function.
(combine_stack_adjustments_for_block): Use it.
*** regmove.c.old Thu Apr 27 21:32:02 2000
--- regmove.c Thu Apr 27 22:08:12 2000
*************** static struct csa_memlist *record_one_st
*** 2100,2105 ****
--- 2100,2106 ----
static int try_apply_stack_adjustment
PARAMS ((rtx, struct csa_memlist *, HOST_WIDE_INT, HOST_WIDE_INT));
static void combine_stack_adjustments_for_block PARAMS ((basic_block));
+ static int record_stack_memrefs PARAMS ((rtx *, void *));
/* Main entry point for stack adjustment combination. */
*************** try_apply_stack_adjustment (insn, memlis
*** 2258,2263 ****
--- 2259,2309 ----
return 0;
}
+ /* Called via for_each_rtx and used to record all stack memory references in
+ the insn and discard all other stack pointer references. */
+ struct record_stack_memrefs_data
+ {
+ rtx insn;
+ struct csa_memlist *memlist;
+ };
+
+ static int
+ record_stack_memrefs (xp, data)
+ rtx *xp;
+ void *data;
+ {
+ rtx x = *xp;
+ struct record_stack_memrefs_data *d =
+ (struct record_stack_memrefs_data *) data;
+ if (!x)
+ return 0;
+ switch (GET_CODE (x))
+ {
+ case MEM:
+ if (!reg_mentioned_p (stack_pointer_rtx, x))
+ return -1;
+ /* We are not able to handle correctly all possible memrefs containing
+ stack pointer, so this check is neccesary. */
+ if (stack_memref_p (x))
+ {
+ d->memlist = record_one_stack_memref (d->insn, xp, d->memlist);
+ return -1;
+ }
+ return 1;
+ case REG:
+ /* ??? We want be able to handle non-memory stack pointer references
+ later. For now just discard all insns refering to stack pointer
+ outside mem expressions. We would probably want to teach
+ validate_replace to simplify expressions first. */
+ if (x == stack_pointer_rtx)
+ return 1;
+ break;
+ default:
+ break;
+ }
+ return 0;
+ }
+
/* Subroutine of combine_stack_adjustments, called for each basic block. */
static void
*************** combine_stack_adjustments_for_block (bb)
*** 2269,2274 ****
--- 2315,2321 ----
struct csa_memlist *memlist = NULL;
rtx pending_delete;
rtx insn, next;
+ struct record_stack_memrefs_data data;
for (insn = bb->head; ; insn = next)
{
*************** combine_stack_adjustments_for_block (bb)
*** 2277,2283 ****
pending_delete = NULL_RTX;
next = NEXT_INSN (insn);
! if (GET_RTX_CLASS (GET_CODE (insn)) != 'i')
goto processed;
set = single_set_for_csa (insn);
--- 2324,2330 ----
pending_delete = NULL_RTX;
next = NEXT_INSN (insn);
! if (! INSN_P (insn))
goto processed;
set = single_set_for_csa (insn);
*************** combine_stack_adjustments_for_block (bb)
*** 2337,2359 ****
goto processed;
}
- /* Find loads from stack memory and record them. */
- if (last_sp_set && stack_memref_p (src)
- && ! reg_mentioned_p (stack_pointer_rtx, dest))
- {
- memlist = record_one_stack_memref (insn, &SET_SRC (set), memlist);
- goto processed;
- }
-
- /* Find stores to stack memory and record them. */
- if (last_sp_set && stack_memref_p (dest)
- && ! reg_mentioned_p (stack_pointer_rtx, src))
- {
- memlist = record_one_stack_memref (insn, &SET_DEST (set),
- memlist);
- goto processed;
- }
-
/* Find a predecrement of exactly the previous adjustment and
turn it into a direct store. Obviously we can't do this if
there were any intervening uses of the stack pointer. */
--- 2384,2389 ----
*************** combine_stack_adjustments_for_block (bb)
*** 2379,2384 ****
--- 2409,2424 ----
goto processed;
}
}
+
+ data.insn = insn;
+ data.memlist = memlist;
+ if (GET_CODE (insn) != CALL_INSN && last_sp_set
+ && !for_each_rtx (&PATTERN (insn), record_stack_memrefs, &data))
+ {
+ memlist = data.memlist;
+ goto processed;
+ }
+ memlist = data.memlist;
/* Otherwise, we were not able to process the instruction.
Do not continue collecting data across such a one. */
More information about the Gcc-patches
mailing list