]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/stack-ptr-mod.c
sh.c: Do not include algorithm.
[thirdparty/gcc.git] / gcc / stack-ptr-mod.c
CommitLineData
b8698a0f 1/* Discover if the stack pointer is modified in a function.
23a5b65a 2 Copyright (C) 2007-2014 Free Software Foundation, Inc.
6fb5fa3c
DB
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
9dcd6f09 8Software Foundation; either version 3, or (at your option) any later
6fb5fa3c
DB
9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14for more details.
15
16You should have received a copy of the GNU General Public License
9dcd6f09
NC
17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
6fb5fa3c
DB
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"
60393bbc
AM
29#include "predict.h"
30#include "vec.h"
31#include "hashtab.h"
32#include "hash-set.h"
33#include "machmode.h"
34#include "hard-reg-set.h"
35#include "input.h"
36#include "function.h"
37#include "dominance.h"
38#include "cfg.h"
6fb5fa3c
DB
39#include "basic-block.h"
40#include "flags.h"
41#include "output.h"
42#include "df.h"
43
44/* Determine if the stack pointer is constant over the life of the function.
45 Only useful before prologues have been emitted. */
46
47static void
7bc980e1 48notice_stack_pointer_modification_1 (rtx x, const_rtx pat ATTRIBUTE_UNUSED,
6fb5fa3c
DB
49 void *data ATTRIBUTE_UNUSED)
50{
51 if (x == stack_pointer_rtx
52 /* The stack pointer is only modified indirectly as the result
53 of a push until later. See the comments in rtl.texi
54 regarding Embedded Side-Effects on Addresses. */
55 || (MEM_P (x)
56 && GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) == RTX_AUTOINC
57 && XEXP (XEXP (x, 0), 0) == stack_pointer_rtx))
416ff32e 58 crtl->sp_is_unchanging = 0;
6fb5fa3c
DB
59}
60
6fb5fa3c
DB
61 /* Some targets can emit simpler epilogues if they know that sp was
62 not ever modified during the function. After reload, of course,
63 we've already emitted the epilogue so there's no sense searching. */
64
27a4cd48
DM
65namespace {
66
67const pass_data pass_data_stack_ptr_mod =
6fb5fa3c 68{
27a4cd48
DM
69 RTL_PASS, /* type */
70 "*stack_ptr_mod", /* name */
71 OPTGROUP_NONE, /* optinfo_flags */
27a4cd48
DM
72 TV_NONE, /* tv_id */
73 0, /* properties_required */
74 0, /* properties_provided */
75 0, /* properties_destroyed */
76 0, /* todo_flags_start */
77 0, /* todo_flags_finish */
6fb5fa3c 78};
27a4cd48
DM
79
80class pass_stack_ptr_mod : public rtl_opt_pass
81{
82public:
c3284718
RS
83 pass_stack_ptr_mod (gcc::context *ctxt)
84 : rtl_opt_pass (pass_data_stack_ptr_mod, ctxt)
27a4cd48
DM
85 {}
86
87 /* opt_pass methods: */
be55bfe6 88 virtual unsigned int execute (function *);
27a4cd48
DM
89
90}; // class pass_stack_ptr_mod
91
be55bfe6
TS
92unsigned int
93pass_stack_ptr_mod::execute (function *fun)
94{
95 basic_block bb;
21f110ce 96 rtx_insn *insn;
be55bfe6
TS
97
98 /* Assume that the stack pointer is unchanging if alloca hasn't
99 been used. */
100 crtl->sp_is_unchanging = !fun->calls_alloca;
101 if (crtl->sp_is_unchanging)
102 FOR_EACH_BB_FN (bb, fun)
103 FOR_BB_INSNS (bb, insn)
104 {
105 if (INSN_P (insn))
106 {
107 /* Check if insn modifies the stack pointer. */
108 note_stores (PATTERN (insn),
109 notice_stack_pointer_modification_1,
110 NULL);
111 if (! crtl->sp_is_unchanging)
112 return 0;
113 }
114 }
115
116 /* The value coming into this pass was 0, and the exit block uses
117 are based on this. If the value is now 1, we need to redo the
118 exit block uses. */
119 if (df && crtl->sp_is_unchanging)
120 df_update_exit_block_uses ();
121
122 return 0;
123}
124
27a4cd48
DM
125} // anon namespace
126
127rtl_opt_pass *
128make_pass_stack_ptr_mod (gcc::context *ctxt)
129{
130 return new pass_stack_ptr_mod (ctxt);
131}