Mark ChangeLog
[official-gcc.git] / gcc / integrate.c
blobdf3d503bc7201b5b12a5303cf7969c39c3bae12c
1 /* Procedure integration for GCC.
2 Copyright (C) 1988, 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000, 2001, 2002, 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
4 Contributed by Michael Tiemann (tiemann@cygnus.com)
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
27 #include "rtl.h"
28 #include "tree.h"
29 #include "tm_p.h"
30 #include "regs.h"
31 #include "flags.h"
32 #include "debug.h"
33 #include "insn-config.h"
34 #include "expr.h"
35 #include "output.h"
36 #include "recog.h"
37 #include "integrate.h"
38 #include "real.h"
39 #include "except.h"
40 #include "function.h"
41 #include "toplev.h"
42 #include "intl.h"
43 #include "params.h"
44 #include "ggc.h"
45 #include "target.h"
46 #include "langhooks.h"
47 #include "tree-pass.h"
49 /* Round to the next highest integer that meets the alignment. */
50 #define CEIL_ROUND(VALUE,ALIGN) (((VALUE) + (ALIGN) - 1) & ~((ALIGN)- 1))
53 /* Private type used by {get/has}_hard_reg_initial_val. */
54 typedef struct initial_value_pair GTY(()) {
55 rtx hard_reg;
56 rtx pseudo;
57 } initial_value_pair;
58 typedef struct initial_value_struct GTY(()) {
59 int num_entries;
60 int max_entries;
61 initial_value_pair * GTY ((length ("%h.num_entries"))) entries;
62 } initial_value_struct;
64 static void set_block_origin_self (tree);
65 static void set_block_abstract_flags (tree, int);
68 /* Return false if the function FNDECL cannot be inlined on account of its
69 attributes, true otherwise. */
70 bool
71 function_attribute_inlinable_p (tree fndecl)
73 if (targetm.attribute_table)
75 tree a;
77 for (a = DECL_ATTRIBUTES (fndecl); a; a = TREE_CHAIN (a))
79 tree name = TREE_PURPOSE (a);
80 int i;
82 for (i = 0; targetm.attribute_table[i].name != NULL; i++)
83 if (is_attribute_p (targetm.attribute_table[i].name, name))
84 return targetm.function_attribute_inlinable_p (fndecl);
88 return true;
91 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
92 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
93 that it points to the node itself, thus indicating that the node is its
94 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
95 the given node is NULL, recursively descend the decl/block tree which
96 it is the root of, and for each other ..._DECL or BLOCK node contained
97 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
98 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
99 values to point to themselves. */
101 static void
102 set_block_origin_self (tree stmt)
104 if (BLOCK_ABSTRACT_ORIGIN (stmt) == NULL_TREE)
106 BLOCK_ABSTRACT_ORIGIN (stmt) = stmt;
109 tree local_decl;
111 for (local_decl = BLOCK_VARS (stmt);
112 local_decl != NULL_TREE;
113 local_decl = TREE_CHAIN (local_decl))
114 set_decl_origin_self (local_decl); /* Potential recursion. */
118 tree subblock;
120 for (subblock = BLOCK_SUBBLOCKS (stmt);
121 subblock != NULL_TREE;
122 subblock = BLOCK_CHAIN (subblock))
123 set_block_origin_self (subblock); /* Recurse. */
128 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
129 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
130 node to so that it points to the node itself, thus indicating that the
131 node represents its own (abstract) origin. Additionally, if the
132 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
133 the decl/block tree of which the given node is the root of, and for
134 each other ..._DECL or BLOCK node contained therein whose
135 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
136 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
137 point to themselves. */
139 void
140 set_decl_origin_self (tree decl)
142 if (DECL_ABSTRACT_ORIGIN (decl) == NULL_TREE)
144 DECL_ABSTRACT_ORIGIN (decl) = decl;
145 if (TREE_CODE (decl) == FUNCTION_DECL)
147 tree arg;
149 for (arg = DECL_ARGUMENTS (decl); arg; arg = TREE_CHAIN (arg))
150 DECL_ABSTRACT_ORIGIN (arg) = arg;
151 if (DECL_INITIAL (decl) != NULL_TREE
152 && DECL_INITIAL (decl) != error_mark_node)
153 set_block_origin_self (DECL_INITIAL (decl));
158 /* Given a pointer to some BLOCK node, and a boolean value to set the
159 "abstract" flags to, set that value into the BLOCK_ABSTRACT flag for
160 the given block, and for all local decls and all local sub-blocks
161 (recursively) which are contained therein. */
163 static void
164 set_block_abstract_flags (tree stmt, int setting)
166 tree local_decl;
167 tree subblock;
169 BLOCK_ABSTRACT (stmt) = setting;
171 for (local_decl = BLOCK_VARS (stmt);
172 local_decl != NULL_TREE;
173 local_decl = TREE_CHAIN (local_decl))
174 set_decl_abstract_flags (local_decl, setting);
176 for (subblock = BLOCK_SUBBLOCKS (stmt);
177 subblock != NULL_TREE;
178 subblock = BLOCK_CHAIN (subblock))
179 set_block_abstract_flags (subblock, setting);
182 /* Given a pointer to some ..._DECL node, and a boolean value to set the
183 "abstract" flags to, set that value into the DECL_ABSTRACT flag for the
184 given decl, and (in the case where the decl is a FUNCTION_DECL) also
185 set the abstract flags for all of the parameters, local vars, local
186 blocks and sub-blocks (recursively) to the same setting. */
188 void
189 set_decl_abstract_flags (tree decl, int setting)
191 DECL_ABSTRACT (decl) = setting;
192 if (TREE_CODE (decl) == FUNCTION_DECL)
194 tree arg;
196 for (arg = DECL_ARGUMENTS (decl); arg; arg = TREE_CHAIN (arg))
197 DECL_ABSTRACT (arg) = setting;
198 if (DECL_INITIAL (decl) != NULL_TREE
199 && DECL_INITIAL (decl) != error_mark_node)
200 set_block_abstract_flags (DECL_INITIAL (decl), setting);
204 /* Functions to keep track of the values hard regs had at the start of
205 the function. */
208 get_hard_reg_initial_reg (struct function *fun, rtx reg)
210 struct initial_value_struct *ivs = fun->hard_reg_initial_vals;
211 int i;
213 if (ivs == 0)
214 return NULL_RTX;
216 for (i = 0; i < ivs->num_entries; i++)
217 if (rtx_equal_p (ivs->entries[i].pseudo, reg))
218 return ivs->entries[i].hard_reg;
220 return NULL_RTX;
223 /* Make sure that there's a pseudo register of mode MODE that stores the
224 initial value of hard register REGNO. Return an rtx for such a pseudo. */
227 get_hard_reg_initial_val (enum machine_mode mode, unsigned int regno)
229 struct initial_value_struct *ivs;
230 rtx rv;
232 rv = has_hard_reg_initial_val (mode, regno);
233 if (rv)
234 return rv;
236 ivs = cfun->hard_reg_initial_vals;
237 if (ivs == 0)
239 ivs = ggc_alloc (sizeof (initial_value_struct));
240 ivs->num_entries = 0;
241 ivs->max_entries = 5;
242 ivs->entries = ggc_alloc (5 * sizeof (initial_value_pair));
243 cfun->hard_reg_initial_vals = ivs;
246 if (ivs->num_entries >= ivs->max_entries)
248 ivs->max_entries += 5;
249 ivs->entries = ggc_realloc (ivs->entries,
250 ivs->max_entries
251 * sizeof (initial_value_pair));
254 ivs->entries[ivs->num_entries].hard_reg = gen_rtx_REG (mode, regno);
255 ivs->entries[ivs->num_entries].pseudo = gen_reg_rtx (mode);
257 return ivs->entries[ivs->num_entries++].pseudo;
260 /* See if get_hard_reg_initial_val has been used to create a pseudo
261 for the initial value of hard register REGNO in mode MODE. Return
262 the associated pseudo if so, otherwise return NULL. */
265 has_hard_reg_initial_val (enum machine_mode mode, unsigned int regno)
267 struct initial_value_struct *ivs;
268 int i;
270 ivs = cfun->hard_reg_initial_vals;
271 if (ivs != 0)
272 for (i = 0; i < ivs->num_entries; i++)
273 if (GET_MODE (ivs->entries[i].hard_reg) == mode
274 && REGNO (ivs->entries[i].hard_reg) == regno)
275 return ivs->entries[i].pseudo;
277 return NULL_RTX;
280 unsigned int
281 emit_initial_value_sets (void)
283 struct initial_value_struct *ivs = cfun->hard_reg_initial_vals;
284 int i;
285 rtx seq;
287 if (ivs == 0)
288 return 0;
290 start_sequence ();
291 for (i = 0; i < ivs->num_entries; i++)
292 emit_move_insn (ivs->entries[i].pseudo, ivs->entries[i].hard_reg);
293 seq = get_insns ();
294 end_sequence ();
296 emit_insn_at_entry (seq);
297 return 0;
300 struct tree_opt_pass pass_initial_value_sets =
302 "initvals", /* name */
303 NULL, /* gate */
304 emit_initial_value_sets, /* execute */
305 NULL, /* sub */
306 NULL, /* next */
307 0, /* static_pass_number */
308 0, /* tv_id */
309 0, /* properties_required */
310 0, /* properties_provided */
311 0, /* properties_destroyed */
312 0, /* todo_flags_start */
313 TODO_dump_func, /* todo_flags_finish */
314 0 /* letter */
317 /* If the backend knows where to allocate pseudos for hard
318 register initial values, register these allocations now. */
319 void
320 allocate_initial_values (rtx *reg_equiv_memory_loc ATTRIBUTE_UNUSED)
322 if (targetm.allocate_initial_value)
324 struct initial_value_struct *ivs = cfun->hard_reg_initial_vals;
325 int i;
327 if (ivs == 0)
328 return;
330 for (i = 0; i < ivs->num_entries; i++)
332 int regno = REGNO (ivs->entries[i].pseudo);
333 rtx x = targetm.allocate_initial_value (ivs->entries[i].hard_reg);
335 if (x && REG_N_SETS (REGNO (ivs->entries[i].pseudo)) <= 1)
337 if (MEM_P (x))
338 reg_equiv_memory_loc[regno] = x;
339 else
341 basic_block bb;
342 int new_regno;
344 gcc_assert (REG_P (x));
345 new_regno = REGNO (x);
346 reg_renumber[regno] = new_regno;
347 /* Poke the regno right into regno_reg_rtx so that even
348 fixed regs are accepted. */
349 REGNO (ivs->entries[i].pseudo) = new_regno;
350 /* Update global register liveness information. */
351 FOR_EACH_BB (bb)
353 struct rtl_bb_info *info = bb->il.rtl;
355 if (REGNO_REG_SET_P(info->global_live_at_start, regno))
356 SET_REGNO_REG_SET (info->global_live_at_start,
357 new_regno);
358 if (REGNO_REG_SET_P(info->global_live_at_end, regno))
359 SET_REGNO_REG_SET (info->global_live_at_end,
360 new_regno);
368 #include "gt-integrate.h"