Mercurial > hg > CbC > CbC_gcc
comparison gcc/stack-ptr-mod.c @ 111:04ced10e8804
gcc 7
author | kono |
---|---|
date | Fri, 27 Oct 2017 22:46:09 +0900 |
parents | 77e2b8dfacca |
children | 84e7813d76e9 |
comparison
equal
deleted
inserted
replaced
68:561a7518be6b | 111:04ced10e8804 |
---|---|
1 /* Discover if the stack pointer is modified in a function. | 1 /* Discover if the stack pointer is modified in a function. |
2 Copyright (C) 2007, 2008, 2009 | 2 Copyright (C) 2007-2017 Free Software Foundation, Inc. |
3 Free Software Foundation, Inc. | |
4 | 3 |
5 This file is part of GCC. | 4 This file is part of GCC. |
6 | 5 |
7 GCC is free software; you can redistribute it and/or modify it under | 6 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 | 7 the terms of the GNU General Public License as published by the Free |
19 <http://www.gnu.org/licenses/>. */ | 18 <http://www.gnu.org/licenses/>. */ |
20 | 19 |
21 #include "config.h" | 20 #include "config.h" |
22 #include "system.h" | 21 #include "system.h" |
23 #include "coretypes.h" | 22 #include "coretypes.h" |
24 #include "tm.h" | 23 #include "backend.h" |
25 #include "tree.h" | |
26 #include "rtl.h" | 24 #include "rtl.h" |
27 #include "regs.h" | 25 #include "df.h" |
28 #include "expr.h" | 26 #include "memmodel.h" |
27 #include "emit-rtl.h" | |
29 #include "tree-pass.h" | 28 #include "tree-pass.h" |
30 #include "basic-block.h" | |
31 #include "flags.h" | |
32 #include "output.h" | |
33 #include "df.h" | |
34 | 29 |
35 /* Determine if the stack pointer is constant over the life of the function. | 30 /* Determine if the stack pointer is constant over the life of the function. |
36 Only useful before prologues have been emitted. */ | 31 Only useful before prologues have been emitted. */ |
37 | 32 |
38 static void | 33 static void |
44 of a push until later. See the comments in rtl.texi | 39 of a push until later. See the comments in rtl.texi |
45 regarding Embedded Side-Effects on Addresses. */ | 40 regarding Embedded Side-Effects on Addresses. */ |
46 || (MEM_P (x) | 41 || (MEM_P (x) |
47 && GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) == RTX_AUTOINC | 42 && GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) == RTX_AUTOINC |
48 && XEXP (XEXP (x, 0), 0) == stack_pointer_rtx)) | 43 && XEXP (XEXP (x, 0), 0) == stack_pointer_rtx)) |
49 current_function_sp_is_unchanging = 0; | 44 crtl->sp_is_unchanging = 0; |
50 } | 45 } |
51 | 46 |
52 static void | 47 /* Some targets can emit simpler epilogues if they know that sp was |
53 notice_stack_pointer_modification (void) | 48 not ever modified during the function. After reload, of course, |
49 we've already emitted the epilogue so there's no sense searching. */ | |
50 | |
51 namespace { | |
52 | |
53 const pass_data pass_data_stack_ptr_mod = | |
54 { | |
55 RTL_PASS, /* type */ | |
56 "*stack_ptr_mod", /* name */ | |
57 OPTGROUP_NONE, /* optinfo_flags */ | |
58 TV_NONE, /* tv_id */ | |
59 0, /* properties_required */ | |
60 0, /* properties_provided */ | |
61 0, /* properties_destroyed */ | |
62 0, /* todo_flags_start */ | |
63 0, /* todo_flags_finish */ | |
64 }; | |
65 | |
66 class pass_stack_ptr_mod : public rtl_opt_pass | |
67 { | |
68 public: | |
69 pass_stack_ptr_mod (gcc::context *ctxt) | |
70 : rtl_opt_pass (pass_data_stack_ptr_mod, ctxt) | |
71 {} | |
72 | |
73 /* opt_pass methods: */ | |
74 virtual unsigned int execute (function *); | |
75 | |
76 }; // class pass_stack_ptr_mod | |
77 | |
78 unsigned int | |
79 pass_stack_ptr_mod::execute (function *fun) | |
54 { | 80 { |
55 basic_block bb; | 81 basic_block bb; |
56 rtx insn; | 82 rtx_insn *insn; |
57 | 83 |
58 /* Assume that the stack pointer is unchanging if alloca hasn't | 84 /* Assume that the stack pointer is unchanging if alloca hasn't |
59 been used. */ | 85 been used. */ |
60 current_function_sp_is_unchanging = !cfun->calls_alloca; | 86 crtl->sp_is_unchanging = !fun->calls_alloca; |
61 if (current_function_sp_is_unchanging) | 87 if (crtl->sp_is_unchanging) |
62 FOR_EACH_BB (bb) | 88 FOR_EACH_BB_FN (bb, fun) |
63 FOR_BB_INSNS (bb, insn) | 89 FOR_BB_INSNS (bb, insn) |
64 { | 90 { |
65 if (INSN_P (insn)) | 91 if (INSN_P (insn)) |
66 { | 92 { |
67 /* Check if insn modifies the stack pointer. */ | 93 /* Check if insn modifies the stack pointer. */ |
68 note_stores (PATTERN (insn), | 94 note_stores (PATTERN (insn), |
69 notice_stack_pointer_modification_1, | 95 notice_stack_pointer_modification_1, |
70 NULL); | 96 NULL); |
71 if (! current_function_sp_is_unchanging) | 97 if (! crtl->sp_is_unchanging) |
72 return; | 98 return 0; |
73 } | 99 } |
74 } | 100 } |
75 | 101 |
76 /* The value coming into this pass was 0, and the exit block uses | 102 /* The value coming into this pass was 0, and the exit block uses |
77 are based on this. If the value is now 1, we need to redo the | 103 are based on this. If the value is now 1, we need to redo the |
78 exit block uses. */ | 104 exit block uses. */ |
79 if (df && current_function_sp_is_unchanging) | 105 if (df && crtl->sp_is_unchanging) |
80 df_update_exit_block_uses (); | 106 df_update_exit_block_uses (); |
81 } | |
82 | 107 |
83 /* Some targets can emit simpler epilogues if they know that sp was | |
84 not ever modified during the function. After reload, of course, | |
85 we've already emitted the epilogue so there's no sense searching. */ | |
86 | |
87 static unsigned int | |
88 rest_of_handle_stack_ptr_mod (void) | |
89 { | |
90 notice_stack_pointer_modification (); | |
91 return 0; | 108 return 0; |
92 } | 109 } |
93 | 110 |
94 struct rtl_opt_pass pass_stack_ptr_mod = | 111 } // anon namespace |
112 | |
113 rtl_opt_pass * | |
114 make_pass_stack_ptr_mod (gcc::context *ctxt) | |
95 { | 115 { |
96 { | 116 return new pass_stack_ptr_mod (ctxt); |
97 RTL_PASS, | 117 } |
98 "*stack_ptr_mod", /* name */ | |
99 NULL, /* gate */ | |
100 rest_of_handle_stack_ptr_mod, /* execute */ | |
101 NULL, /* sub */ | |
102 NULL, /* next */ | |
103 0, /* static_pass_number */ | |
104 TV_NONE, /* tv_id */ | |
105 0, /* properties_required */ | |
106 0, /* properties_provided */ | |
107 0, /* properties_destroyed */ | |
108 0, /* todo_flags_start */ | |
109 0 /* todo_flags_finish */ | |
110 } | |
111 }; |