1 /* Discover if the stack pointer is modified in a function.
2 Copyright (C) 2007-2015 Free Software Foundation, Inc.
4 This file is part of GCC.
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
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
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/>. */
22 #include "coretypes.h"
27 #include "tree-pass.h"
29 /* Determine if the stack pointer is constant over the life of the function.
30 Only useful before prologues have been emitted. */
33 notice_stack_pointer_modification_1 (rtx x
, const_rtx pat ATTRIBUTE_UNUSED
,
34 void *data ATTRIBUTE_UNUSED
)
36 if (x
== stack_pointer_rtx
37 /* The stack pointer is only modified indirectly as the result
38 of a push until later. See the comments in rtl.texi
39 regarding Embedded Side-Effects on Addresses. */
41 && GET_RTX_CLASS (GET_CODE (XEXP (x
, 0))) == RTX_AUTOINC
42 && XEXP (XEXP (x
, 0), 0) == stack_pointer_rtx
))
43 crtl
->sp_is_unchanging
= 0;
46 /* Some targets can emit simpler epilogues if they know that sp was
47 not ever modified during the function. After reload, of course,
48 we've already emitted the epilogue so there's no sense searching. */
52 const pass_data pass_data_stack_ptr_mod
=
55 "*stack_ptr_mod", /* name */
56 OPTGROUP_NONE
, /* optinfo_flags */
58 0, /* properties_required */
59 0, /* properties_provided */
60 0, /* properties_destroyed */
61 0, /* todo_flags_start */
62 0, /* todo_flags_finish */
65 class pass_stack_ptr_mod
: public rtl_opt_pass
68 pass_stack_ptr_mod (gcc::context
*ctxt
)
69 : rtl_opt_pass (pass_data_stack_ptr_mod
, ctxt
)
72 /* opt_pass methods: */
73 virtual unsigned int execute (function
*);
75 }; // class pass_stack_ptr_mod
78 pass_stack_ptr_mod::execute (function
*fun
)
83 /* Assume that the stack pointer is unchanging if alloca hasn't
85 crtl
->sp_is_unchanging
= !fun
->calls_alloca
;
86 if (crtl
->sp_is_unchanging
)
87 FOR_EACH_BB_FN (bb
, fun
)
88 FOR_BB_INSNS (bb
, insn
)
92 /* Check if insn modifies the stack pointer. */
93 note_stores (PATTERN (insn
),
94 notice_stack_pointer_modification_1
,
96 if (! crtl
->sp_is_unchanging
)
101 /* The value coming into this pass was 0, and the exit block uses
102 are based on this. If the value is now 1, we need to redo the
104 if (df
&& crtl
->sp_is_unchanging
)
105 df_update_exit_block_uses ();
113 make_pass_stack_ptr_mod (gcc::context
*ctxt
)
115 return new pass_stack_ptr_mod (ctxt
);