config.gcc: Handle --enable-fdpic.
[gcc.git] / gcc / combine-stack-adj.c
1 /* Combine stack adjustments.
2 Copyright (C) 1987-2015 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
10
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
19
20 /* Track stack adjustments and stack memory references. Attempt to
21 reduce the number of stack adjustments by back-propagating across
22 the memory references.
23
24 This is intended primarily for use with targets that do not define
25 ACCUMULATE_OUTGOING_ARGS. It is of significantly more value to
26 targets that define PREFERRED_STACK_BOUNDARY more aligned than
27 STACK_BOUNDARY (e.g. x86), or if not all registers can be pushed
28 (e.g. x86 fp regs) which would ordinarily have to be implemented
29 as a sub/mov pair due to restrictions in calls.c.
30
31 Propagation stops when any of the insns that need adjusting are
32 (a) no longer valid because we've exceeded their range, (b) a
33 non-trivial push instruction, or (c) a call instruction.
34
35 Restriction B is based on the assumption that push instructions
36 are smaller or faster. If a port really wants to remove all
37 pushes, it should have defined ACCUMULATE_OUTGOING_ARGS. The
38 one exception that is made is for an add immediately followed
39 by a push. */
40
41 #include "config.h"
42 #include "system.h"
43 #include "coretypes.h"
44 #include "backend.h"
45 #include "tree.h"
46 #include "rtl.h"
47 #include "df.h"
48 #include "tm_p.h"
49 #include "insn-config.h"
50 #include "recog.h"
51 #include "regs.h"
52 #include "flags.h"
53 #include "alias.h"
54 #include "expmed.h"
55 #include "dojump.h"
56 #include "explow.h"
57 #include "calls.h"
58 #include "emit-rtl.h"
59 #include "varasm.h"
60 #include "stmt.h"
61 #include "expr.h"
62 #include "cfgrtl.h"
63 #include "except.h"
64 #include "reload.h"
65 #include "tree-pass.h"
66 #include "rtl-iter.h"
67
68 \f
69 /* This structure records two kinds of stack references between stack
70 adjusting instructions: stack references in memory addresses for
71 regular insns and all stack references for debug insns. */
72
73 struct csa_reflist
74 {
75 HOST_WIDE_INT sp_offset;
76 rtx_insn *insn;
77 rtx *ref;
78 struct csa_reflist *next;
79 };
80
81 static int stack_memref_p (rtx);
82 static rtx single_set_for_csa (rtx_insn *);
83 static void free_csa_reflist (struct csa_reflist *);
84 static struct csa_reflist *record_one_stack_ref (rtx_insn *, rtx *,
85 struct csa_reflist *);
86 static int try_apply_stack_adjustment (rtx_insn *, struct csa_reflist *,
87 HOST_WIDE_INT, HOST_WIDE_INT);
88 static void combine_stack_adjustments_for_block (basic_block);
89
90
91 /* Main entry point for stack adjustment combination. */
92
93 static void
94 combine_stack_adjustments (void)
95 {
96 basic_block bb;
97
98 FOR_EACH_BB_FN (bb, cfun)
99 combine_stack_adjustments_for_block (bb);
100 }
101
102 /* Recognize a MEM of the form (sp) or (plus sp const). */
103
104 static int
105 stack_memref_p (rtx x)
106 {
107 if (!MEM_P (x))
108 return 0;
109 x = XEXP (x, 0);
110
111 if (x == stack_pointer_rtx)
112 return 1;
113 if (GET_CODE (x) == PLUS
114 && XEXP (x, 0) == stack_pointer_rtx
115 && CONST_INT_P (XEXP (x, 1)))
116 return 1;
117
118 return 0;
119 }
120
121 /* Recognize either normal single_set or the hack in i386.md for
122 tying fp and sp adjustments. */
123
124 static rtx
125 single_set_for_csa (rtx_insn *insn)
126 {
127 int i;
128 rtx tmp = single_set (insn);
129 if (tmp)
130 return tmp;
131
132 if (!NONJUMP_INSN_P (insn)
133 || GET_CODE (PATTERN (insn)) != PARALLEL)
134 return NULL_RTX;
135
136 tmp = PATTERN (insn);
137 if (GET_CODE (XVECEXP (tmp, 0, 0)) != SET)
138 return NULL_RTX;
139
140 for (i = 1; i < XVECLEN (tmp, 0); ++i)
141 {
142 rtx this_rtx = XVECEXP (tmp, 0, i);
143
144 /* The special case is allowing a no-op set. */
145 if (GET_CODE (this_rtx) == SET
146 && SET_SRC (this_rtx) == SET_DEST (this_rtx))
147 ;
148 else if (GET_CODE (this_rtx) != CLOBBER
149 && GET_CODE (this_rtx) != USE)
150 return NULL_RTX;
151 }
152
153 return XVECEXP (tmp, 0, 0);
154 }
155
156 /* Free the list of csa_reflist nodes. */
157
158 static void
159 free_csa_reflist (struct csa_reflist *reflist)
160 {
161 struct csa_reflist *next;
162 for (; reflist ; reflist = next)
163 {
164 next = reflist->next;
165 free (reflist);
166 }
167 }
168
169 /* Create a new csa_reflist node from the given stack reference.
170 It is already known that the reference is either a MEM satisfying the
171 predicate stack_memref_p or a REG representing the stack pointer. */
172
173 static struct csa_reflist *
174 record_one_stack_ref (rtx_insn *insn, rtx *ref, struct csa_reflist *next_reflist)
175 {
176 struct csa_reflist *ml;
177
178 ml = XNEW (struct csa_reflist);
179
180 if (REG_P (*ref) || XEXP (*ref, 0) == stack_pointer_rtx)
181 ml->sp_offset = 0;
182 else
183 ml->sp_offset = INTVAL (XEXP (XEXP (*ref, 0), 1));
184
185 ml->insn = insn;
186 ml->ref = ref;
187 ml->next = next_reflist;
188
189 return ml;
190 }
191
192 /* We only know how to adjust the CFA; no other frame-related changes
193 may appear in any insn to be deleted. */
194
195 static bool
196 no_unhandled_cfa (rtx_insn *insn)
197 {
198 if (!RTX_FRAME_RELATED_P (insn))
199 return true;
200
201 /* No CFA notes at all is a legacy interpretation like
202 FRAME_RELATED_EXPR, and is context sensitive within
203 the prologue state machine. We can't handle that here. */
204 bool has_cfa_adjust = false;
205
206 for (rtx link = REG_NOTES (insn); link; link = XEXP (link, 1))
207 switch (REG_NOTE_KIND (link))
208 {
209 default:
210 break;
211 case REG_CFA_ADJUST_CFA:
212 has_cfa_adjust = true;
213 break;
214
215 case REG_FRAME_RELATED_EXPR:
216 case REG_CFA_DEF_CFA:
217 case REG_CFA_OFFSET:
218 case REG_CFA_REGISTER:
219 case REG_CFA_EXPRESSION:
220 case REG_CFA_RESTORE:
221 case REG_CFA_SET_VDRAP:
222 case REG_CFA_WINDOW_SAVE:
223 case REG_CFA_FLUSH_QUEUE:
224 return false;
225 }
226
227 return has_cfa_adjust;
228 }
229
230 /* Attempt to apply ADJUST to the stack adjusting insn INSN, as well
231 as each of the memories and stack references in REFLIST. Return true
232 on success. */
233
234 static int
235 try_apply_stack_adjustment (rtx_insn *insn, struct csa_reflist *reflist,
236 HOST_WIDE_INT new_adjust, HOST_WIDE_INT delta)
237 {
238 struct csa_reflist *ml;
239 rtx set;
240
241 set = single_set_for_csa (insn);
242 if (MEM_P (SET_DEST (set)))
243 validate_change (insn, &SET_DEST (set),
244 replace_equiv_address (SET_DEST (set), stack_pointer_rtx),
245 1);
246 else
247 validate_change (insn, &XEXP (SET_SRC (set), 1), GEN_INT (new_adjust), 1);
248
249 for (ml = reflist; ml ; ml = ml->next)
250 {
251 rtx new_addr = plus_constant (Pmode, stack_pointer_rtx,
252 ml->sp_offset - delta);
253 rtx new_val;
254
255 if (MEM_P (*ml->ref))
256 new_val = replace_equiv_address_nv (*ml->ref, new_addr);
257 else if (GET_MODE (*ml->ref) == GET_MODE (stack_pointer_rtx))
258 new_val = new_addr;
259 else
260 new_val = lowpart_subreg (GET_MODE (*ml->ref), new_addr,
261 GET_MODE (new_addr));
262 validate_change (ml->insn, ml->ref, new_val, 1);
263 }
264
265 if (apply_change_group ())
266 {
267 /* Succeeded. Update our knowledge of the stack references. */
268 for (ml = reflist; ml ; ml = ml->next)
269 ml->sp_offset -= delta;
270
271 return 1;
272 }
273 else
274 return 0;
275 }
276
277 /* For non-debug insns, record all stack memory references in INSN
278 and return true if there were no other (unrecorded) references to the
279 stack pointer. For debug insns, record all stack references regardless
280 of context and unconditionally return true. */
281
282 static bool
283 record_stack_refs (rtx_insn *insn, struct csa_reflist **reflist)
284 {
285 subrtx_ptr_iterator::array_type array;
286 FOR_EACH_SUBRTX_PTR (iter, array, &PATTERN (insn), NONCONST)
287 {
288 rtx *loc = *iter;
289 rtx x = *loc;
290 switch (GET_CODE (x))
291 {
292 case MEM:
293 if (!reg_mentioned_p (stack_pointer_rtx, x))
294 iter.skip_subrtxes ();
295 /* We are not able to handle correctly all possible memrefs
296 containing stack pointer, so this check is necessary. */
297 else if (stack_memref_p (x))
298 {
299 *reflist = record_one_stack_ref (insn, loc, *reflist);
300 iter.skip_subrtxes ();
301 }
302 /* Try harder for DEBUG_INSNs, handle e.g.
303 (mem (mem (sp + 16) + 4). */
304 else if (!DEBUG_INSN_P (insn))
305 return false;
306 break;
307
308 case REG:
309 /* ??? We want be able to handle non-memory stack pointer
310 references later. For now just discard all insns referring to
311 stack pointer outside mem expressions. We would probably
312 want to teach validate_replace to simplify expressions first.
313
314 We can't just compare with STACK_POINTER_RTX because the
315 reference to the stack pointer might be in some other mode.
316 In particular, an explicit clobber in an asm statement will
317 result in a QImode clobber.
318
319 In DEBUG_INSNs, we want to replace all occurrences, otherwise
320 they will cause -fcompare-debug failures. */
321 if (REGNO (x) == STACK_POINTER_REGNUM)
322 {
323 if (!DEBUG_INSN_P (insn))
324 return false;
325 *reflist = record_one_stack_ref (insn, loc, *reflist);
326 }
327 break;
328
329 default:
330 break;
331 }
332 }
333 return true;
334 }
335
336 /* If INSN has a REG_ARGS_SIZE note, move it to LAST.
337 AFTER is true iff LAST follows INSN in the instruction stream. */
338
339 static void
340 maybe_move_args_size_note (rtx_insn *last, rtx_insn *insn, bool after)
341 {
342 rtx note, last_note;
343
344 note = find_reg_note (insn, REG_ARGS_SIZE, NULL_RTX);
345 if (note == NULL)
346 return;
347
348 last_note = find_reg_note (last, REG_ARGS_SIZE, NULL_RTX);
349 if (last_note)
350 {
351 /* The ARGS_SIZE notes are *not* cumulative. They represent an
352 absolute value, and the "most recent" note wins. */
353 if (!after)
354 XEXP (last_note, 0) = XEXP (note, 0);
355 }
356 else
357 add_reg_note (last, REG_ARGS_SIZE, XEXP (note, 0));
358 }
359
360 /* Merge any REG_CFA_ADJUST_CFA note from SRC into DST.
361 AFTER is true iff DST follows SRC in the instruction stream. */
362
363 static void
364 maybe_merge_cfa_adjust (rtx_insn *dst, rtx_insn *src, bool after)
365 {
366 rtx snote = NULL, dnote = NULL;
367 rtx sexp, dexp;
368 rtx exp1, exp2;
369
370 if (RTX_FRAME_RELATED_P (src))
371 snote = find_reg_note (src, REG_CFA_ADJUST_CFA, NULL_RTX);
372 if (snote == NULL)
373 return;
374 sexp = XEXP (snote, 0);
375
376 if (RTX_FRAME_RELATED_P (dst))
377 dnote = find_reg_note (dst, REG_CFA_ADJUST_CFA, NULL_RTX);
378 if (dnote == NULL)
379 {
380 add_reg_note (dst, REG_CFA_ADJUST_CFA, sexp);
381 return;
382 }
383 dexp = XEXP (dnote, 0);
384
385 gcc_assert (GET_CODE (sexp) == SET);
386 gcc_assert (GET_CODE (dexp) == SET);
387
388 if (after)
389 exp1 = dexp, exp2 = sexp;
390 else
391 exp1 = sexp, exp2 = dexp;
392
393 SET_SRC (exp1) = simplify_replace_rtx (SET_SRC (exp1), SET_DEST (exp2),
394 SET_SRC (exp2));
395 XEXP (dnote, 0) = exp1;
396 }
397
398 /* Return the next (or previous) active insn within BB. */
399
400 static rtx_insn *
401 prev_active_insn_bb (basic_block bb, rtx_insn *insn)
402 {
403 for (insn = PREV_INSN (insn);
404 insn != PREV_INSN (BB_HEAD (bb));
405 insn = PREV_INSN (insn))
406 if (active_insn_p (insn))
407 return insn;
408 return NULL;
409 }
410
411 static rtx_insn *
412 next_active_insn_bb (basic_block bb, rtx_insn *insn)
413 {
414 for (insn = NEXT_INSN (insn);
415 insn != NEXT_INSN (BB_END (bb));
416 insn = NEXT_INSN (insn))
417 if (active_insn_p (insn))
418 return insn;
419 return NULL;
420 }
421
422 /* If INSN has a REG_ARGS_SIZE note, if possible move it to PREV. Otherwise
423 search for a nearby candidate within BB where we can stick the note. */
424
425 static void
426 force_move_args_size_note (basic_block bb, rtx_insn *prev, rtx_insn *insn)
427 {
428 rtx note;
429 rtx_insn *test, *next_candidate, *prev_candidate;
430
431 /* If PREV exists, tail-call to the logic in the other function. */
432 if (prev)
433 {
434 maybe_move_args_size_note (prev, insn, false);
435 return;
436 }
437
438 /* First, make sure there's anything that needs doing. */
439 note = find_reg_note (insn, REG_ARGS_SIZE, NULL_RTX);
440 if (note == NULL)
441 return;
442
443 /* We need to find a spot between the previous and next exception points
444 where we can place the note and "properly" deallocate the arguments. */
445 next_candidate = prev_candidate = NULL;
446
447 /* It is often the case that we have insns in the order:
448 call
449 add sp (previous deallocation)
450 sub sp (align for next arglist)
451 push arg
452 and the add/sub cancel. Therefore we begin by searching forward. */
453
454 test = insn;
455 while ((test = next_active_insn_bb (bb, test)) != NULL)
456 {
457 /* Found an existing note: nothing to do. */
458 if (find_reg_note (test, REG_ARGS_SIZE, NULL_RTX))
459 return;
460 /* Found something that affects unwinding. Stop searching. */
461 if (CALL_P (test) || !insn_nothrow_p (test))
462 break;
463 if (next_candidate == NULL)
464 next_candidate = test;
465 }
466
467 test = insn;
468 while ((test = prev_active_insn_bb (bb, test)) != NULL)
469 {
470 rtx tnote;
471 /* Found a place that seems logical to adjust the stack. */
472 tnote = find_reg_note (test, REG_ARGS_SIZE, NULL_RTX);
473 if (tnote)
474 {
475 XEXP (tnote, 0) = XEXP (note, 0);
476 return;
477 }
478 if (prev_candidate == NULL)
479 prev_candidate = test;
480 /* Found something that affects unwinding. Stop searching. */
481 if (CALL_P (test) || !insn_nothrow_p (test))
482 break;
483 }
484
485 if (prev_candidate)
486 test = prev_candidate;
487 else if (next_candidate)
488 test = next_candidate;
489 else
490 {
491 /* ??? We *must* have a place, lest we ICE on the lost adjustment.
492 Options are: dummy clobber insn, nop, or prevent the removal of
493 the sp += 0 insn. */
494 /* TODO: Find another way to indicate to the dwarf2 code that we
495 have not in fact lost an adjustment. */
496 test = emit_insn_before (gen_rtx_CLOBBER (VOIDmode, const0_rtx), insn);
497 }
498 add_reg_note (test, REG_ARGS_SIZE, XEXP (note, 0));
499 }
500
501 /* Subroutine of combine_stack_adjustments, called for each basic block. */
502
503 static void
504 combine_stack_adjustments_for_block (basic_block bb)
505 {
506 HOST_WIDE_INT last_sp_adjust = 0;
507 rtx_insn *last_sp_set = NULL;
508 rtx_insn *last2_sp_set = NULL;
509 struct csa_reflist *reflist = NULL;
510 rtx_insn *insn, *next;
511 rtx set;
512 bool end_of_block = false;
513
514 for (insn = BB_HEAD (bb); !end_of_block ; insn = next)
515 {
516 end_of_block = insn == BB_END (bb);
517 next = NEXT_INSN (insn);
518
519 if (! INSN_P (insn))
520 continue;
521
522 set = single_set_for_csa (insn);
523 if (set)
524 {
525 rtx dest = SET_DEST (set);
526 rtx src = SET_SRC (set);
527
528 /* Find constant additions to the stack pointer. */
529 if (dest == stack_pointer_rtx
530 && GET_CODE (src) == PLUS
531 && XEXP (src, 0) == stack_pointer_rtx
532 && CONST_INT_P (XEXP (src, 1)))
533 {
534 HOST_WIDE_INT this_adjust = INTVAL (XEXP (src, 1));
535
536 /* If we've not seen an adjustment previously, record
537 it now and continue. */
538 if (! last_sp_set)
539 {
540 last_sp_set = insn;
541 last_sp_adjust = this_adjust;
542 continue;
543 }
544
545 /* If not all recorded refs can be adjusted, or the
546 adjustment is now too large for a constant addition,
547 we cannot merge the two stack adjustments.
548
549 Also we need to be careful to not move stack pointer
550 such that we create stack accesses outside the allocated
551 area. We can combine an allocation into the first insn,
552 or a deallocation into the second insn. We can not
553 combine an allocation followed by a deallocation.
554
555 The only somewhat frequent occurrence of the later is when
556 a function allocates a stack frame but does not use it.
557 For this case, we would need to analyze rtl stream to be
558 sure that allocated area is really unused. This means not
559 only checking the memory references, but also all registers
560 or global memory references possibly containing a stack
561 frame address.
562
563 Perhaps the best way to address this problem is to teach
564 gcc not to allocate stack for objects never used. */
565
566 /* Combine an allocation into the first instruction. */
567 if (STACK_GROWS_DOWNWARD ? this_adjust <= 0 : this_adjust >= 0)
568 {
569 if (no_unhandled_cfa (insn)
570 && try_apply_stack_adjustment (last_sp_set, reflist,
571 last_sp_adjust
572 + this_adjust,
573 this_adjust))
574 {
575 /* It worked! */
576 maybe_move_args_size_note (last_sp_set, insn, false);
577 maybe_merge_cfa_adjust (last_sp_set, insn, false);
578 delete_insn (insn);
579 last_sp_adjust += this_adjust;
580 continue;
581 }
582 }
583
584 /* Otherwise we have a deallocation. Do not combine with
585 a previous allocation. Combine into the second insn. */
586 else if (STACK_GROWS_DOWNWARD
587 ? last_sp_adjust >= 0 : last_sp_adjust <= 0)
588 {
589 if (no_unhandled_cfa (last_sp_set)
590 && try_apply_stack_adjustment (insn, reflist,
591 last_sp_adjust
592 + this_adjust,
593 -last_sp_adjust))
594 {
595 /* It worked! */
596 maybe_move_args_size_note (insn, last_sp_set, true);
597 maybe_merge_cfa_adjust (insn, last_sp_set, true);
598 delete_insn (last_sp_set);
599 last_sp_set = insn;
600 last_sp_adjust += this_adjust;
601 free_csa_reflist (reflist);
602 reflist = NULL;
603 continue;
604 }
605 }
606
607 /* Combination failed. Restart processing from here. If
608 deallocation+allocation conspired to cancel, we can
609 delete the old deallocation insn. */
610 if (last_sp_set)
611 {
612 if (last_sp_adjust == 0 && no_unhandled_cfa (last_sp_set))
613 {
614 maybe_move_args_size_note (insn, last_sp_set, true);
615 maybe_merge_cfa_adjust (insn, last_sp_set, true);
616 delete_insn (last_sp_set);
617 }
618 else
619 last2_sp_set = last_sp_set;
620 }
621 free_csa_reflist (reflist);
622 reflist = NULL;
623 last_sp_set = insn;
624 last_sp_adjust = this_adjust;
625 continue;
626 }
627
628 /* Find a store with pre-(dec|inc)rement or pre-modify of exactly
629 the previous adjustment and turn it into a simple store. This
630 is equivalent to anticipating the stack adjustment so this must
631 be an allocation. */
632 if (MEM_P (dest)
633 && ((STACK_GROWS_DOWNWARD
634 ? (GET_CODE (XEXP (dest, 0)) == PRE_DEC
635 && last_sp_adjust
636 == (HOST_WIDE_INT) GET_MODE_SIZE (GET_MODE (dest)))
637 : (GET_CODE (XEXP (dest, 0)) == PRE_INC
638 && last_sp_adjust
639 == -(HOST_WIDE_INT) GET_MODE_SIZE (GET_MODE (dest))))
640 || ((STACK_GROWS_DOWNWARD
641 ? last_sp_adjust >= 0 : last_sp_adjust <= 0)
642 && GET_CODE (XEXP (dest, 0)) == PRE_MODIFY
643 && GET_CODE (XEXP (XEXP (dest, 0), 1)) == PLUS
644 && XEXP (XEXP (XEXP (dest, 0), 1), 0)
645 == stack_pointer_rtx
646 && GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
647 == CONST_INT
648 && INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1))
649 == -last_sp_adjust))
650 && XEXP (XEXP (dest, 0), 0) == stack_pointer_rtx
651 && !reg_mentioned_p (stack_pointer_rtx, src)
652 && memory_address_p (GET_MODE (dest), stack_pointer_rtx)
653 && try_apply_stack_adjustment (insn, reflist, 0,
654 -last_sp_adjust))
655 {
656 if (last2_sp_set)
657 maybe_move_args_size_note (last2_sp_set, last_sp_set, false);
658 else
659 maybe_move_args_size_note (insn, last_sp_set, true);
660 delete_insn (last_sp_set);
661 free_csa_reflist (reflist);
662 reflist = NULL;
663 last_sp_set = NULL;
664 last_sp_adjust = 0;
665 continue;
666 }
667 }
668
669 if (!CALL_P (insn) && last_sp_set
670 && record_stack_refs (insn, &reflist))
671 continue;
672
673 /* Otherwise, we were not able to process the instruction.
674 Do not continue collecting data across such a one. */
675 if (last_sp_set
676 && (CALL_P (insn)
677 || reg_mentioned_p (stack_pointer_rtx, PATTERN (insn))))
678 {
679 if (last_sp_set && last_sp_adjust == 0)
680 {
681 force_move_args_size_note (bb, last2_sp_set, last_sp_set);
682 delete_insn (last_sp_set);
683 }
684 free_csa_reflist (reflist);
685 reflist = NULL;
686 last2_sp_set = NULL;
687 last_sp_set = NULL;
688 last_sp_adjust = 0;
689 }
690 }
691
692 if (last_sp_set && last_sp_adjust == 0)
693 {
694 force_move_args_size_note (bb, last2_sp_set, last_sp_set);
695 delete_insn (last_sp_set);
696 }
697
698 if (reflist)
699 free_csa_reflist (reflist);
700 }
701 \f
702 static unsigned int
703 rest_of_handle_stack_adjustments (void)
704 {
705 df_note_add_problem ();
706 df_analyze ();
707 combine_stack_adjustments ();
708 return 0;
709 }
710
711 namespace {
712
713 const pass_data pass_data_stack_adjustments =
714 {
715 RTL_PASS, /* type */
716 "csa", /* name */
717 OPTGROUP_NONE, /* optinfo_flags */
718 TV_COMBINE_STACK_ADJUST, /* tv_id */
719 0, /* properties_required */
720 0, /* properties_provided */
721 0, /* properties_destroyed */
722 0, /* todo_flags_start */
723 TODO_df_finish, /* todo_flags_finish */
724 };
725
726 class pass_stack_adjustments : public rtl_opt_pass
727 {
728 public:
729 pass_stack_adjustments (gcc::context *ctxt)
730 : rtl_opt_pass (pass_data_stack_adjustments, ctxt)
731 {}
732
733 /* opt_pass methods: */
734 virtual bool gate (function *);
735 virtual unsigned int execute (function *)
736 {
737 return rest_of_handle_stack_adjustments ();
738 }
739
740 }; // class pass_stack_adjustments
741
742 bool
743 pass_stack_adjustments::gate (function *)
744 {
745 /* This is kind of a heuristic. We need to run combine_stack_adjustments
746 even for machines with possibly nonzero TARGET_RETURN_POPS_ARGS
747 and ACCUMULATE_OUTGOING_ARGS. We expect that only ports having
748 push instructions will have popping returns. */
749 #ifndef PUSH_ROUNDING
750 if (ACCUMULATE_OUTGOING_ARGS)
751 return false;
752 #endif
753 return flag_combine_stack_adjustments;
754 }
755
756 } // anon namespace
757
758 rtl_opt_pass *
759 make_pass_stack_adjustments (gcc::context *ctxt)
760 {
761 return new pass_stack_adjustments (ctxt);
762 }