annotate gcc/stack-ptr-mod.c @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1 /* Discover if the stack pointer is modified in a function.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2 Copyright (C) 2007-2020 Free Software Foundation, Inc.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 This file is part of GCC.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 GCC is free software; you can redistribute it and/or modify it under
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 the terms of the GNU General Public License as published by the Free
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 Software Foundation; either version 3, or (at your option) any later
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 version.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 for more details.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 along with GCC; see the file COPYING3. If not see
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 <http://www.gnu.org/licenses/>. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 #include "config.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 #include "system.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 #include "coretypes.h"
111
kono
parents: 55
diff changeset
23 #include "backend.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 #include "rtl.h"
111
kono
parents: 55
diff changeset
25 #include "df.h"
kono
parents: 55
diff changeset
26 #include "memmodel.h"
kono
parents: 55
diff changeset
27 #include "emit-rtl.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 #include "tree-pass.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 /* Determine if the stack pointer is constant over the life of the function.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 Only useful before prologues have been emitted. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 static void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 notice_stack_pointer_modification_1 (rtx x, const_rtx pat ATTRIBUTE_UNUSED,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 void *data ATTRIBUTE_UNUSED)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 if (x == stack_pointer_rtx
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 /* The stack pointer is only modified indirectly as the result
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 of a push until later. See the comments in rtl.texi
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 regarding Embedded Side-Effects on Addresses. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 || (MEM_P (x)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 && GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) == RTX_AUTOINC
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 && XEXP (XEXP (x, 0), 0) == stack_pointer_rtx))
111
kono
parents: 55
diff changeset
44 crtl->sp_is_unchanging = 0;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46
111
kono
parents: 55
diff changeset
47 /* Some targets can emit simpler epilogues if they know that sp was
kono
parents: 55
diff changeset
48 not ever modified during the function. After reload, of course,
kono
parents: 55
diff changeset
49 we've already emitted the epilogue so there's no sense searching. */
kono
parents: 55
diff changeset
50
kono
parents: 55
diff changeset
51 namespace {
kono
parents: 55
diff changeset
52
kono
parents: 55
diff changeset
53 const pass_data pass_data_stack_ptr_mod =
kono
parents: 55
diff changeset
54 {
kono
parents: 55
diff changeset
55 RTL_PASS, /* type */
kono
parents: 55
diff changeset
56 "*stack_ptr_mod", /* name */
kono
parents: 55
diff changeset
57 OPTGROUP_NONE, /* optinfo_flags */
kono
parents: 55
diff changeset
58 TV_NONE, /* tv_id */
kono
parents: 55
diff changeset
59 0, /* properties_required */
kono
parents: 55
diff changeset
60 0, /* properties_provided */
kono
parents: 55
diff changeset
61 0, /* properties_destroyed */
kono
parents: 55
diff changeset
62 0, /* todo_flags_start */
kono
parents: 55
diff changeset
63 0, /* todo_flags_finish */
kono
parents: 55
diff changeset
64 };
kono
parents: 55
diff changeset
65
kono
parents: 55
diff changeset
66 class pass_stack_ptr_mod : public rtl_opt_pass
kono
parents: 55
diff changeset
67 {
kono
parents: 55
diff changeset
68 public:
kono
parents: 55
diff changeset
69 pass_stack_ptr_mod (gcc::context *ctxt)
kono
parents: 55
diff changeset
70 : rtl_opt_pass (pass_data_stack_ptr_mod, ctxt)
kono
parents: 55
diff changeset
71 {}
kono
parents: 55
diff changeset
72
kono
parents: 55
diff changeset
73 /* opt_pass methods: */
kono
parents: 55
diff changeset
74 virtual unsigned int execute (function *);
kono
parents: 55
diff changeset
75
kono
parents: 55
diff changeset
76 }; // class pass_stack_ptr_mod
kono
parents: 55
diff changeset
77
kono
parents: 55
diff changeset
78 unsigned int
kono
parents: 55
diff changeset
79 pass_stack_ptr_mod::execute (function *fun)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 basic_block bb;
111
kono
parents: 55
diff changeset
82 rtx_insn *insn;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
83
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 /* Assume that the stack pointer is unchanging if alloca hasn't
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 been used. */
111
kono
parents: 55
diff changeset
86 crtl->sp_is_unchanging = !fun->calls_alloca;
kono
parents: 55
diff changeset
87 if (crtl->sp_is_unchanging)
kono
parents: 55
diff changeset
88 FOR_EACH_BB_FN (bb, fun)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 FOR_BB_INSNS (bb, insn)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 if (INSN_P (insn))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 /* Check if insn modifies the stack pointer. */
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
94 note_stores (insn, notice_stack_pointer_modification_1, NULL);
111
kono
parents: 55
diff changeset
95 if (! crtl->sp_is_unchanging)
kono
parents: 55
diff changeset
96 return 0;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
99
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 /* The value coming into this pass was 0, and the exit block uses
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 are based on this. If the value is now 1, we need to redo the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 exit block uses. */
111
kono
parents: 55
diff changeset
103 if (df && crtl->sp_is_unchanging)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 df_update_exit_block_uses ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
105
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 return 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
108
111
kono
parents: 55
diff changeset
109 } // anon namespace
kono
parents: 55
diff changeset
110
kono
parents: 55
diff changeset
111 rtl_opt_pass *
kono
parents: 55
diff changeset
112 make_pass_stack_ptr_mod (gcc::context *ctxt)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 {
111
kono
parents: 55
diff changeset
114 return new pass_stack_ptr_mod (ctxt);
kono
parents: 55
diff changeset
115 }