libgomp: Use pthread mutexes in the nvptx plugin.
[official-gcc.git] / gcc / stack-ptr-mod.c
blob4f74ed3c46a824b804bb70f5e76bb99c8280a1ff
1 /* Discover if the stack pointer is modified in a function.
2 Copyright (C) 2007-2015 Free Software Foundation, Inc.
4 This file is part of GCC.
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
8 Software Foundation; either version 3, or (at your option) any later
9 version.
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.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #include "config.h"
21 #include "system.h"
22 #include "coretypes.h"
23 #include "tm.h"
24 #include "hash-set.h"
25 #include "machmode.h"
26 #include "vec.h"
27 #include "double-int.h"
28 #include "input.h"
29 #include "alias.h"
30 #include "symtab.h"
31 #include "wide-int.h"
32 #include "inchash.h"
33 #include "tree.h"
34 #include "rtl.h"
35 #include "regs.h"
36 #include "expr.h"
37 #include "tree-pass.h"
38 #include "predict.h"
39 #include "hard-reg-set.h"
40 #include "input.h"
41 #include "function.h"
42 #include "dominance.h"
43 #include "cfg.h"
44 #include "basic-block.h"
45 #include "flags.h"
46 #include "output.h"
47 #include "df.h"
49 /* Determine if the stack pointer is constant over the life of the function.
50 Only useful before prologues have been emitted. */
52 static void
53 notice_stack_pointer_modification_1 (rtx x, const_rtx pat ATTRIBUTE_UNUSED,
54 void *data ATTRIBUTE_UNUSED)
56 if (x == stack_pointer_rtx
57 /* The stack pointer is only modified indirectly as the result
58 of a push until later. See the comments in rtl.texi
59 regarding Embedded Side-Effects on Addresses. */
60 || (MEM_P (x)
61 && GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) == RTX_AUTOINC
62 && XEXP (XEXP (x, 0), 0) == stack_pointer_rtx))
63 crtl->sp_is_unchanging = 0;
66 /* Some targets can emit simpler epilogues if they know that sp was
67 not ever modified during the function. After reload, of course,
68 we've already emitted the epilogue so there's no sense searching. */
70 namespace {
72 const pass_data pass_data_stack_ptr_mod =
74 RTL_PASS, /* type */
75 "*stack_ptr_mod", /* name */
76 OPTGROUP_NONE, /* optinfo_flags */
77 TV_NONE, /* tv_id */
78 0, /* properties_required */
79 0, /* properties_provided */
80 0, /* properties_destroyed */
81 0, /* todo_flags_start */
82 0, /* todo_flags_finish */
85 class pass_stack_ptr_mod : public rtl_opt_pass
87 public:
88 pass_stack_ptr_mod (gcc::context *ctxt)
89 : rtl_opt_pass (pass_data_stack_ptr_mod, ctxt)
92 /* opt_pass methods: */
93 virtual unsigned int execute (function *);
95 }; // class pass_stack_ptr_mod
97 unsigned int
98 pass_stack_ptr_mod::execute (function *fun)
100 basic_block bb;
101 rtx_insn *insn;
103 /* Assume that the stack pointer is unchanging if alloca hasn't
104 been used. */
105 crtl->sp_is_unchanging = !fun->calls_alloca;
106 if (crtl->sp_is_unchanging)
107 FOR_EACH_BB_FN (bb, fun)
108 FOR_BB_INSNS (bb, insn)
110 if (INSN_P (insn))
112 /* Check if insn modifies the stack pointer. */
113 note_stores (PATTERN (insn),
114 notice_stack_pointer_modification_1,
115 NULL);
116 if (! crtl->sp_is_unchanging)
117 return 0;
121 /* The value coming into this pass was 0, and the exit block uses
122 are based on this. If the value is now 1, we need to redo the
123 exit block uses. */
124 if (df && crtl->sp_is_unchanging)
125 df_update_exit_block_uses ();
127 return 0;
130 } // anon namespace
132 rtl_opt_pass *
133 make_pass_stack_ptr_mod (gcc::context *ctxt)
135 return new pass_stack_ptr_mod (ctxt);