OSDN Git Service

gcc/fortran:
[pf3gnuchains/gcc-fork.git] / gcc / stack-ptr-mod.c
1 /* Discover if the stack pointer is modified in a function. 
2    Copyright (C) 2007
3    Free Software Foundation, Inc.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING.  If not, write to the Free
19 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
20 02110-1301, USA.  */
21
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "tree.h"
27 #include "rtl.h"
28 #include "regs.h"
29 #include "expr.h"
30 #include "tree-pass.h"
31 #include "basic-block.h"
32 #include "flags.h"
33 #include "output.h"
34 #include "df.h"
35
36 /* Determine if the stack pointer is constant over the life of the function.
37    Only useful before prologues have been emitted.  */
38
39 static void
40 notice_stack_pointer_modification_1 (rtx x, rtx pat ATTRIBUTE_UNUSED,
41                                      void *data ATTRIBUTE_UNUSED)
42 {
43   if (x == stack_pointer_rtx
44       /* The stack pointer is only modified indirectly as the result
45          of a push until later.  See the comments in rtl.texi
46          regarding Embedded Side-Effects on Addresses.  */
47       || (MEM_P (x)
48           && GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) == RTX_AUTOINC
49           && XEXP (XEXP (x, 0), 0) == stack_pointer_rtx))
50     current_function_sp_is_unchanging = 0;
51 }
52
53 static void
54 notice_stack_pointer_modification (void)
55 {
56   basic_block bb;
57   rtx insn;
58
59   /* Assume that the stack pointer is unchanging if alloca hasn't
60      been used.  */
61   current_function_sp_is_unchanging = !current_function_calls_alloca;
62   if (current_function_sp_is_unchanging)
63     FOR_EACH_BB (bb)
64       FOR_BB_INSNS (bb, insn)
65         {
66           if (INSN_P (insn))
67             {
68               /* Check if insn modifies the stack pointer.  */
69               note_stores (PATTERN (insn),
70                            notice_stack_pointer_modification_1,
71                            NULL);
72               if (! current_function_sp_is_unchanging)
73                 return;
74             }
75         }
76
77   /* The value coming into this pass was 0, and the exit block uses
78      are based on this.  If the value is now 1, we need to redo the
79      exit block uses.  */
80   if (df && current_function_sp_is_unchanging)
81     df_update_exit_block_uses ();
82 }
83
84   /* Some targets can emit simpler epilogues if they know that sp was
85      not ever modified during the function.  After reload, of course,
86      we've already emitted the epilogue so there's no sense searching.  */
87
88 static unsigned int
89 rest_of_handle_stack_ptr_mod (void)
90 {
91   notice_stack_pointer_modification ();
92   return 0;
93 }
94
95 struct tree_opt_pass pass_stack_ptr_mod =
96 {
97   NULL,                                 /* name */
98   NULL,                                 /* gate */
99   rest_of_handle_stack_ptr_mod,         /* execute */
100   NULL,                                 /* sub */
101   NULL,                                 /* next */
102   0,                                    /* static_pass_number */
103   0,                                    /* tv_id */
104   0,                                    /* properties_required */
105   0,                                    /* properties_provided */
106   0,                                    /* properties_destroyed */
107   0,                                    /* todo_flags_start */
108   0,                                    /* todo_flags_finish */
109   0                                     /* letter */
110 };