* gensupport.c (old_preds): Don't reference PREDICATE_CODES.
[official-gcc.git] / gcc / integrate.c
blobeadf6606830205aa1ef454d9c5c95755b7a57900
1 /* Procedure integration for GCC.
2 Copyright (C) 1988, 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000, 2001, 2002, 2003, 2004, 2005 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 2, 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 COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
21 02110-1301, USA. */
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "tm.h"
28 #include "rtl.h"
29 #include "tree.h"
30 #include "tm_p.h"
31 #include "regs.h"
32 #include "flags.h"
33 #include "debug.h"
34 #include "insn-config.h"
35 #include "expr.h"
36 #include "output.h"
37 #include "recog.h"
38 #include "integrate.h"
39 #include "real.h"
40 #include "except.h"
41 #include "function.h"
42 #include "toplev.h"
43 #include "intl.h"
44 #include "params.h"
45 #include "ggc.h"
46 #include "target.h"
47 #include "langhooks.h"
48 #include "tree-pass.h"
50 /* Round to the next highest integer that meets the alignment. */
51 #define CEIL_ROUND(VALUE,ALIGN) (((VALUE) + (ALIGN) - 1) & ~((ALIGN)- 1))
54 /* Private type used by {get/has}_hard_reg_initial_val. */
55 typedef struct initial_value_pair GTY(()) {
56 rtx hard_reg;
57 rtx pseudo;
58 } initial_value_pair;
59 typedef struct initial_value_struct GTY(()) {
60 int num_entries;
61 int max_entries;
62 initial_value_pair * GTY ((length ("%h.num_entries"))) entries;
63 } initial_value_struct;
65 static void set_block_origin_self (tree);
66 static void set_block_abstract_flags (tree, int);
69 /* Return false if the function FNDECL cannot be inlined on account of its
70 attributes, true otherwise. */
71 bool
72 function_attribute_inlinable_p (tree fndecl)
74 if (targetm.attribute_table)
76 tree a;
78 for (a = DECL_ATTRIBUTES (fndecl); a; a = TREE_CHAIN (a))
80 tree name = TREE_PURPOSE (a);
81 int i;
83 for (i = 0; targetm.attribute_table[i].name != NULL; i++)
84 if (is_attribute_p (targetm.attribute_table[i].name, name))
85 return targetm.function_attribute_inlinable_p (fndecl);
89 return true;
92 /* Copy NODE (which must be a DECL). The DECL originally was in the FROM_FN,
93 but now it will be in the TO_FN. */
95 tree
96 copy_decl_for_inlining (tree decl, tree from_fn, tree to_fn)
98 tree copy;
100 /* Copy the declaration. */
101 if (TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == RESULT_DECL)
103 tree type = TREE_TYPE (decl);
105 /* For a parameter or result, we must make an equivalent VAR_DECL, not a
106 new PARM_DECL. */
107 copy = build_decl (VAR_DECL, DECL_NAME (decl), type);
108 TREE_ADDRESSABLE (copy) = TREE_ADDRESSABLE (decl);
109 TREE_READONLY (copy) = TREE_READONLY (decl);
110 TREE_THIS_VOLATILE (copy) = TREE_THIS_VOLATILE (decl);
111 DECL_COMPLEX_GIMPLE_REG_P (copy) = DECL_COMPLEX_GIMPLE_REG_P (decl);
113 else
115 copy = copy_node (decl);
116 /* The COPY is not abstract; it will be generated in TO_FN. */
117 DECL_ABSTRACT (copy) = 0;
118 lang_hooks.dup_lang_specific_decl (copy);
120 /* TREE_ADDRESSABLE isn't used to indicate that a label's
121 address has been taken; it's for internal bookkeeping in
122 expand_goto_internal. */
123 if (TREE_CODE (copy) == LABEL_DECL)
125 TREE_ADDRESSABLE (copy) = 0;
126 LABEL_DECL_UID (copy) = -1;
130 /* Don't generate debug information for the copy if we wouldn't have
131 generated it for the copy either. */
132 DECL_ARTIFICIAL (copy) = DECL_ARTIFICIAL (decl);
133 DECL_IGNORED_P (copy) = DECL_IGNORED_P (decl);
135 /* Set the DECL_ABSTRACT_ORIGIN so the debugging routines know what
136 declaration inspired this copy. */
137 DECL_ABSTRACT_ORIGIN (copy) = DECL_ORIGIN (decl);
139 /* The new variable/label has no RTL, yet. */
140 if (CODE_CONTAINS_STRUCT (TREE_CODE (copy), TS_DECL_WRTL)
141 && !TREE_STATIC (copy) && !DECL_EXTERNAL (copy))
142 SET_DECL_RTL (copy, NULL_RTX);
144 /* These args would always appear unused, if not for this. */
145 TREE_USED (copy) = 1;
147 /* Set the context for the new declaration. */
148 if (!DECL_CONTEXT (decl))
149 /* Globals stay global. */
151 else if (DECL_CONTEXT (decl) != from_fn)
152 /* Things that weren't in the scope of the function we're inlining
153 from aren't in the scope we're inlining to, either. */
155 else if (TREE_STATIC (decl))
156 /* Function-scoped static variables should stay in the original
157 function. */
159 else
160 /* Ordinary automatic local variables are now in the scope of the
161 new function. */
162 DECL_CONTEXT (copy) = to_fn;
164 return copy;
168 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
169 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
170 that it points to the node itself, thus indicating that the node is its
171 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
172 the given node is NULL, recursively descend the decl/block tree which
173 it is the root of, and for each other ..._DECL or BLOCK node contained
174 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
175 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
176 values to point to themselves. */
178 static void
179 set_block_origin_self (tree stmt)
181 if (BLOCK_ABSTRACT_ORIGIN (stmt) == NULL_TREE)
183 BLOCK_ABSTRACT_ORIGIN (stmt) = stmt;
186 tree local_decl;
188 for (local_decl = BLOCK_VARS (stmt);
189 local_decl != NULL_TREE;
190 local_decl = TREE_CHAIN (local_decl))
191 set_decl_origin_self (local_decl); /* Potential recursion. */
195 tree subblock;
197 for (subblock = BLOCK_SUBBLOCKS (stmt);
198 subblock != NULL_TREE;
199 subblock = BLOCK_CHAIN (subblock))
200 set_block_origin_self (subblock); /* Recurse. */
205 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
206 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
207 node to so that it points to the node itself, thus indicating that the
208 node represents its own (abstract) origin. Additionally, if the
209 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
210 the decl/block tree of which the given node is the root of, and for
211 each other ..._DECL or BLOCK node contained therein whose
212 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
213 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
214 point to themselves. */
216 void
217 set_decl_origin_self (tree decl)
219 if (DECL_ABSTRACT_ORIGIN (decl) == NULL_TREE)
221 DECL_ABSTRACT_ORIGIN (decl) = decl;
222 if (TREE_CODE (decl) == FUNCTION_DECL)
224 tree arg;
226 for (arg = DECL_ARGUMENTS (decl); arg; arg = TREE_CHAIN (arg))
227 DECL_ABSTRACT_ORIGIN (arg) = arg;
228 if (DECL_INITIAL (decl) != NULL_TREE
229 && DECL_INITIAL (decl) != error_mark_node)
230 set_block_origin_self (DECL_INITIAL (decl));
235 /* Given a pointer to some BLOCK node, and a boolean value to set the
236 "abstract" flags to, set that value into the BLOCK_ABSTRACT flag for
237 the given block, and for all local decls and all local sub-blocks
238 (recursively) which are contained therein. */
240 static void
241 set_block_abstract_flags (tree stmt, int setting)
243 tree local_decl;
244 tree subblock;
246 BLOCK_ABSTRACT (stmt) = setting;
248 for (local_decl = BLOCK_VARS (stmt);
249 local_decl != NULL_TREE;
250 local_decl = TREE_CHAIN (local_decl))
251 set_decl_abstract_flags (local_decl, setting);
253 for (subblock = BLOCK_SUBBLOCKS (stmt);
254 subblock != NULL_TREE;
255 subblock = BLOCK_CHAIN (subblock))
256 set_block_abstract_flags (subblock, setting);
259 /* Given a pointer to some ..._DECL node, and a boolean value to set the
260 "abstract" flags to, set that value into the DECL_ABSTRACT flag for the
261 given decl, and (in the case where the decl is a FUNCTION_DECL) also
262 set the abstract flags for all of the parameters, local vars, local
263 blocks and sub-blocks (recursively) to the same setting. */
265 void
266 set_decl_abstract_flags (tree decl, int setting)
268 DECL_ABSTRACT (decl) = setting;
269 if (TREE_CODE (decl) == FUNCTION_DECL)
271 tree arg;
273 for (arg = DECL_ARGUMENTS (decl); arg; arg = TREE_CHAIN (arg))
274 DECL_ABSTRACT (arg) = setting;
275 if (DECL_INITIAL (decl) != NULL_TREE
276 && DECL_INITIAL (decl) != error_mark_node)
277 set_block_abstract_flags (DECL_INITIAL (decl), setting);
281 /* Functions to keep track of the values hard regs had at the start of
282 the function. */
285 get_hard_reg_initial_reg (struct function *fun, rtx reg)
287 struct initial_value_struct *ivs = fun->hard_reg_initial_vals;
288 int i;
290 if (ivs == 0)
291 return NULL_RTX;
293 for (i = 0; i < ivs->num_entries; i++)
294 if (rtx_equal_p (ivs->entries[i].pseudo, reg))
295 return ivs->entries[i].hard_reg;
297 return NULL_RTX;
300 /* Make sure that there's a pseudo register of mode MODE that stores the
301 initial value of hard register REGNO. Return an rtx for such a pseudo. */
304 get_hard_reg_initial_val (enum machine_mode mode, unsigned int regno)
306 struct initial_value_struct *ivs;
307 rtx rv;
309 rv = has_hard_reg_initial_val (mode, regno);
310 if (rv)
311 return rv;
313 ivs = cfun->hard_reg_initial_vals;
314 if (ivs == 0)
316 ivs = ggc_alloc (sizeof (initial_value_struct));
317 ivs->num_entries = 0;
318 ivs->max_entries = 5;
319 ivs->entries = ggc_alloc (5 * sizeof (initial_value_pair));
320 cfun->hard_reg_initial_vals = ivs;
323 if (ivs->num_entries >= ivs->max_entries)
325 ivs->max_entries += 5;
326 ivs->entries = ggc_realloc (ivs->entries,
327 ivs->max_entries
328 * sizeof (initial_value_pair));
331 ivs->entries[ivs->num_entries].hard_reg = gen_rtx_REG (mode, regno);
332 ivs->entries[ivs->num_entries].pseudo = gen_reg_rtx (mode);
334 return ivs->entries[ivs->num_entries++].pseudo;
337 /* See if get_hard_reg_initial_val has been used to create a pseudo
338 for the initial value of hard register REGNO in mode MODE. Return
339 the associated pseudo if so, otherwise return NULL. */
342 has_hard_reg_initial_val (enum machine_mode mode, unsigned int regno)
344 struct initial_value_struct *ivs;
345 int i;
347 ivs = cfun->hard_reg_initial_vals;
348 if (ivs != 0)
349 for (i = 0; i < ivs->num_entries; i++)
350 if (GET_MODE (ivs->entries[i].hard_reg) == mode
351 && REGNO (ivs->entries[i].hard_reg) == regno)
352 return ivs->entries[i].pseudo;
354 return NULL_RTX;
357 void
358 emit_initial_value_sets (void)
360 struct initial_value_struct *ivs = cfun->hard_reg_initial_vals;
361 int i;
362 rtx seq;
364 if (ivs == 0)
365 return;
367 start_sequence ();
368 for (i = 0; i < ivs->num_entries; i++)
369 emit_move_insn (ivs->entries[i].pseudo, ivs->entries[i].hard_reg);
370 seq = get_insns ();
371 end_sequence ();
373 emit_insn_after (seq, entry_of_function ());
376 struct tree_opt_pass pass_initial_value_sets =
378 NULL, /* name */
379 NULL, /* gate */
380 emit_initial_value_sets, /* execute */
381 NULL, /* sub */
382 NULL, /* next */
383 0, /* static_pass_number */
384 0, /* tv_id */
385 0, /* properties_required */
386 0, /* properties_provided */
387 0, /* properties_destroyed */
388 0, /* todo_flags_start */
389 0, /* todo_flags_finish */
390 0 /* letter */
393 /* If the backend knows where to allocate pseudos for hard
394 register initial values, register these allocations now. */
395 void
396 allocate_initial_values (rtx *reg_equiv_memory_loc ATTRIBUTE_UNUSED)
398 if (targetm.allocate_initial_value)
400 struct initial_value_struct *ivs = cfun->hard_reg_initial_vals;
401 int i;
403 if (ivs == 0)
404 return;
406 for (i = 0; i < ivs->num_entries; i++)
408 int regno = REGNO (ivs->entries[i].pseudo);
409 rtx x = targetm.allocate_initial_value (ivs->entries[i].hard_reg);
411 if (x && REG_N_SETS (REGNO (ivs->entries[i].pseudo)) <= 1)
413 if (MEM_P (x))
414 reg_equiv_memory_loc[regno] = x;
415 else
417 basic_block bb;
418 int new_regno;
420 gcc_assert (REG_P (x));
421 new_regno = REGNO (x);
422 reg_renumber[regno] = new_regno;
423 /* Poke the regno right into regno_reg_rtx so that even
424 fixed regs are accepted. */
425 REGNO (ivs->entries[i].pseudo) = new_regno;
426 /* Update global register liveness information. */
427 FOR_EACH_BB (bb)
429 struct rtl_bb_info *info = bb->il.rtl;
431 if (REGNO_REG_SET_P(info->global_live_at_start, regno))
432 SET_REGNO_REG_SET (info->global_live_at_start,
433 new_regno);
434 if (REGNO_REG_SET_P(info->global_live_at_end, regno))
435 SET_REGNO_REG_SET (info->global_live_at_end,
436 new_regno);
444 #include "gt-integrate.h"