1 /* Discover if the stack pointer is modified in a function.
2 Copyright (C) 2007, 2008, 2009
3 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
23 #include "coretypes.h"
29 #include "tree-pass.h"
30 #include "basic-block.h"
35 /* Determine if the stack pointer is constant over the life of the function.
36 Only useful before prologues have been emitted. */
39 notice_stack_pointer_modification_1 (rtx x
, const_rtx pat ATTRIBUTE_UNUSED
,
40 void *data ATTRIBUTE_UNUSED
)
42 if (x
== stack_pointer_rtx
43 /* The stack pointer is only modified indirectly as the result
44 of a push until later. See the comments in rtl.texi
45 regarding Embedded Side-Effects on Addresses. */
47 && GET_RTX_CLASS (GET_CODE (XEXP (x
, 0))) == RTX_AUTOINC
48 && XEXP (XEXP (x
, 0), 0) == stack_pointer_rtx
))
49 crtl
->sp_is_unchanging
= 0;
53 notice_stack_pointer_modification (void)
58 /* Assume that the stack pointer is unchanging if alloca hasn't
60 crtl
->sp_is_unchanging
= !cfun
->calls_alloca
;
61 if (crtl
->sp_is_unchanging
)
63 FOR_BB_INSNS (bb
, insn
)
67 /* Check if insn modifies the stack pointer. */
68 note_stores (PATTERN (insn
),
69 notice_stack_pointer_modification_1
,
71 if (! crtl
->sp_is_unchanging
)
76 /* The value coming into this pass was 0, and the exit block uses
77 are based on this. If the value is now 1, we need to redo the
79 if (df
&& crtl
->sp_is_unchanging
)
80 df_update_exit_block_uses ();
83 /* Some targets can emit simpler epilogues if they know that sp was
84 not ever modified during the function. After reload, of course,
85 we've already emitted the epilogue so there's no sense searching. */
88 rest_of_handle_stack_ptr_mod (void)
90 notice_stack_pointer_modification ();
94 struct rtl_opt_pass pass_stack_ptr_mod
=
98 "*stack_ptr_mod", /* name */
100 rest_of_handle_stack_ptr_mod
, /* execute */
103 0, /* static_pass_number */
105 0, /* properties_required */
106 0, /* properties_provided */
107 0, /* properties_destroyed */
108 0, /* todo_flags_start */
109 0 /* todo_flags_finish */