]>
Commit | Line | Data |
---|---|---|
48e1416a | 1 | /* Discover if the stack pointer is modified in a function. |
d353bf18 | 2 | Copyright (C) 2007-2015 Free Software Foundation, Inc. |
3072d30e | 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 | |
8c4c00c1 | 8 | Software Foundation; either version 3, or (at your option) any later |
3072d30e | 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 | |
8c4c00c1 | 17 | along with GCC; see the file COPYING3. If not see |
18 | <http://www.gnu.org/licenses/>. */ | |
3072d30e | 19 | |
20 | #include "config.h" | |
21 | #include "system.h" | |
22 | #include "coretypes.h" | |
9ef16211 | 23 | #include "backend.h" |
3072d30e | 24 | #include "rtl.h" |
7c29e30e | 25 | #include "tree.h" |
9ef16211 | 26 | #include "df.h" |
7c29e30e | 27 | #include "expmed.h" |
28 | #include "insn-config.h" | |
3072d30e | 29 | #include "regs.h" |
7c29e30e | 30 | #include "emit-rtl.h" |
31 | #include "alias.h" | |
d53441c8 | 32 | #include "flags.h" |
d53441c8 | 33 | #include "dojump.h" |
34 | #include "explow.h" | |
35 | #include "calls.h" | |
d53441c8 | 36 | #include "varasm.h" |
37 | #include "stmt.h" | |
3072d30e | 38 | #include "expr.h" |
39 | #include "tree-pass.h" | |
3072d30e | 40 | #include "output.h" |
3072d30e | 41 | |
42 | /* Determine if the stack pointer is constant over the life of the function. | |
43 | Only useful before prologues have been emitted. */ | |
44 | ||
45 | static void | |
81a410b1 | 46 | notice_stack_pointer_modification_1 (rtx x, const_rtx pat ATTRIBUTE_UNUSED, |
3072d30e | 47 | void *data ATTRIBUTE_UNUSED) |
48 | { | |
49 | if (x == stack_pointer_rtx | |
50 | /* The stack pointer is only modified indirectly as the result | |
51 | of a push until later. See the comments in rtl.texi | |
52 | regarding Embedded Side-Effects on Addresses. */ | |
53 | || (MEM_P (x) | |
54 | && GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) == RTX_AUTOINC | |
55 | && XEXP (XEXP (x, 0), 0) == stack_pointer_rtx)) | |
d5bf7b64 | 56 | crtl->sp_is_unchanging = 0; |
3072d30e | 57 | } |
58 | ||
3072d30e | 59 | /* Some targets can emit simpler epilogues if they know that sp was |
60 | not ever modified during the function. After reload, of course, | |
61 | we've already emitted the epilogue so there's no sense searching. */ | |
62 | ||
cbe8bda8 | 63 | namespace { |
64 | ||
65 | const pass_data pass_data_stack_ptr_mod = | |
3072d30e | 66 | { |
cbe8bda8 | 67 | RTL_PASS, /* type */ |
68 | "*stack_ptr_mod", /* name */ | |
69 | OPTGROUP_NONE, /* optinfo_flags */ | |
cbe8bda8 | 70 | TV_NONE, /* tv_id */ |
71 | 0, /* properties_required */ | |
72 | 0, /* properties_provided */ | |
73 | 0, /* properties_destroyed */ | |
74 | 0, /* todo_flags_start */ | |
75 | 0, /* todo_flags_finish */ | |
3072d30e | 76 | }; |
cbe8bda8 | 77 | |
78 | class pass_stack_ptr_mod : public rtl_opt_pass | |
79 | { | |
80 | public: | |
9af5ce0c | 81 | pass_stack_ptr_mod (gcc::context *ctxt) |
82 | : rtl_opt_pass (pass_data_stack_ptr_mod, ctxt) | |
cbe8bda8 | 83 | {} |
84 | ||
85 | /* opt_pass methods: */ | |
65b0537f | 86 | virtual unsigned int execute (function *); |
cbe8bda8 | 87 | |
88 | }; // class pass_stack_ptr_mod | |
89 | ||
65b0537f | 90 | unsigned int |
91 | pass_stack_ptr_mod::execute (function *fun) | |
92 | { | |
93 | basic_block bb; | |
555f0948 | 94 | rtx_insn *insn; |
65b0537f | 95 | |
96 | /* Assume that the stack pointer is unchanging if alloca hasn't | |
97 | been used. */ | |
98 | crtl->sp_is_unchanging = !fun->calls_alloca; | |
99 | if (crtl->sp_is_unchanging) | |
100 | FOR_EACH_BB_FN (bb, fun) | |
101 | FOR_BB_INSNS (bb, insn) | |
102 | { | |
103 | if (INSN_P (insn)) | |
104 | { | |
105 | /* Check if insn modifies the stack pointer. */ | |
106 | note_stores (PATTERN (insn), | |
107 | notice_stack_pointer_modification_1, | |
108 | NULL); | |
109 | if (! crtl->sp_is_unchanging) | |
110 | return 0; | |
111 | } | |
112 | } | |
113 | ||
114 | /* The value coming into this pass was 0, and the exit block uses | |
115 | are based on this. If the value is now 1, we need to redo the | |
116 | exit block uses. */ | |
117 | if (df && crtl->sp_is_unchanging) | |
118 | df_update_exit_block_uses (); | |
119 | ||
120 | return 0; | |
121 | } | |
122 | ||
cbe8bda8 | 123 | } // anon namespace |
124 | ||
125 | rtl_opt_pass * | |
126 | make_pass_stack_ptr_mod (gcc::context *ctxt) | |
127 | { | |
128 | return new pass_stack_ptr_mod (ctxt); | |
129 | } |