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