1 /* Procedure integration for GCC.
2 Copyright (C) 1988, 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000, 2001, 2002, 2003, 2004 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
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
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, 59 Temple Place - Suite 330, Boston, MA
25 #include "coretypes.h"
34 #include "insn-config.h"
38 #include "integrate.h"
47 #include "langhooks.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}_func_hard_reg_initial_val. */
54 typedef struct initial_value_pair
GTY(()) {
58 typedef struct initial_value_struct
GTY(()) {
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. */
71 function_attribute_inlinable_p (tree fndecl
)
73 if (targetm
.attribute_table
)
77 for (a
= DECL_ATTRIBUTES (fndecl
); a
; a
= TREE_CHAIN (a
))
79 tree name
= TREE_PURPOSE (a
);
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
);
91 /* Copy NODE (which must be a DECL). The DECL originally was in the FROM_FN,
92 but now it will be in the TO_FN. */
95 copy_decl_for_inlining (tree decl
, tree from_fn
, tree to_fn
)
99 /* Copy the declaration. */
100 if (TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
)
102 tree type
= TREE_TYPE (decl
);
104 /* For a parameter or result, we must make an equivalent VAR_DECL, not a
106 copy
= build_decl (VAR_DECL
, DECL_NAME (decl
), type
);
107 TREE_ADDRESSABLE (copy
) = TREE_ADDRESSABLE (decl
);
108 TREE_READONLY (copy
) = TREE_READONLY (decl
);
109 TREE_THIS_VOLATILE (copy
) = TREE_THIS_VOLATILE (decl
);
113 copy
= copy_node (decl
);
114 /* The COPY is not abstract; it will be generated in TO_FN. */
115 DECL_ABSTRACT (copy
) = 0;
116 lang_hooks
.dup_lang_specific_decl (copy
);
118 /* TREE_ADDRESSABLE isn't used to indicate that a label's
119 address has been taken; it's for internal bookkeeping in
120 expand_goto_internal. */
121 if (TREE_CODE (copy
) == LABEL_DECL
)
123 TREE_ADDRESSABLE (copy
) = 0;
127 /* Don't generate debug information for the copy if we wouldn't have
128 generated it for the copy either. */
129 DECL_ARTIFICIAL (copy
) = DECL_ARTIFICIAL (decl
);
130 DECL_IGNORED_P (copy
) = DECL_IGNORED_P (decl
);
132 /* Set the DECL_ABSTRACT_ORIGIN so the debugging routines know what
133 declaration inspired this copy. */
134 DECL_ABSTRACT_ORIGIN (copy
) = DECL_ORIGIN (decl
);
136 /* The new variable/label has no RTL, yet. */
137 if (!TREE_STATIC (copy
) && !DECL_EXTERNAL (copy
))
138 SET_DECL_RTL (copy
, NULL_RTX
);
140 /* These args would always appear unused, if not for this. */
141 TREE_USED (copy
) = 1;
143 /* Set the context for the new declaration. */
144 if (!DECL_CONTEXT (decl
))
145 /* Globals stay global. */
147 else if (DECL_CONTEXT (decl
) != from_fn
)
148 /* Things that weren't in the scope of the function we're inlining
149 from aren't in the scope we're inlining to, either. */
151 else if (TREE_STATIC (decl
))
152 /* Function-scoped static variables should stay in the original
156 /* Ordinary automatic local variables are now in the scope of the
158 DECL_CONTEXT (copy
) = to_fn
;
164 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
165 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
166 that it points to the node itself, thus indicating that the node is its
167 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
168 the given node is NULL, recursively descend the decl/block tree which
169 it is the root of, and for each other ..._DECL or BLOCK node contained
170 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
171 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
172 values to point to themselves. */
175 set_block_origin_self (tree stmt
)
177 if (BLOCK_ABSTRACT_ORIGIN (stmt
) == NULL_TREE
)
179 BLOCK_ABSTRACT_ORIGIN (stmt
) = stmt
;
184 for (local_decl
= BLOCK_VARS (stmt
);
185 local_decl
!= NULL_TREE
;
186 local_decl
= TREE_CHAIN (local_decl
))
187 set_decl_origin_self (local_decl
); /* Potential recursion. */
193 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
194 subblock
!= NULL_TREE
;
195 subblock
= BLOCK_CHAIN (subblock
))
196 set_block_origin_self (subblock
); /* Recurse. */
201 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
202 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
203 node to so that it points to the node itself, thus indicating that the
204 node represents its own (abstract) origin. Additionally, if the
205 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
206 the decl/block tree of which the given node is the root of, and for
207 each other ..._DECL or BLOCK node contained therein whose
208 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
209 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
210 point to themselves. */
213 set_decl_origin_self (tree decl
)
215 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL_TREE
)
217 DECL_ABSTRACT_ORIGIN (decl
) = decl
;
218 if (TREE_CODE (decl
) == FUNCTION_DECL
)
222 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= TREE_CHAIN (arg
))
223 DECL_ABSTRACT_ORIGIN (arg
) = arg
;
224 if (DECL_INITIAL (decl
) != NULL_TREE
225 && DECL_INITIAL (decl
) != error_mark_node
)
226 set_block_origin_self (DECL_INITIAL (decl
));
231 /* Given a pointer to some BLOCK node, and a boolean value to set the
232 "abstract" flags to, set that value into the BLOCK_ABSTRACT flag for
233 the given block, and for all local decls and all local sub-blocks
234 (recursively) which are contained therein. */
237 set_block_abstract_flags (tree stmt
, int setting
)
242 BLOCK_ABSTRACT (stmt
) = setting
;
244 for (local_decl
= BLOCK_VARS (stmt
);
245 local_decl
!= NULL_TREE
;
246 local_decl
= TREE_CHAIN (local_decl
))
247 set_decl_abstract_flags (local_decl
, setting
);
249 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
250 subblock
!= NULL_TREE
;
251 subblock
= BLOCK_CHAIN (subblock
))
252 set_block_abstract_flags (subblock
, setting
);
255 /* Given a pointer to some ..._DECL node, and a boolean value to set the
256 "abstract" flags to, set that value into the DECL_ABSTRACT flag for the
257 given decl, and (in the case where the decl is a FUNCTION_DECL) also
258 set the abstract flags for all of the parameters, local vars, local
259 blocks and sub-blocks (recursively) to the same setting. */
262 set_decl_abstract_flags (tree decl
, int setting
)
264 DECL_ABSTRACT (decl
) = setting
;
265 if (TREE_CODE (decl
) == FUNCTION_DECL
)
269 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= TREE_CHAIN (arg
))
270 DECL_ABSTRACT (arg
) = setting
;
271 if (DECL_INITIAL (decl
) != NULL_TREE
272 && DECL_INITIAL (decl
) != error_mark_node
)
273 set_block_abstract_flags (DECL_INITIAL (decl
), setting
);
277 /* Functions to keep track of the values hard regs had at the start of
281 get_hard_reg_initial_reg (struct function
*fun
, rtx reg
)
283 struct initial_value_struct
*ivs
= fun
->hard_reg_initial_vals
;
289 for (i
= 0; i
< ivs
->num_entries
; i
++)
290 if (rtx_equal_p (ivs
->entries
[i
].pseudo
, reg
))
291 return ivs
->entries
[i
].hard_reg
;
297 has_func_hard_reg_initial_val (struct function
*fun
, rtx reg
)
299 struct initial_value_struct
*ivs
= fun
->hard_reg_initial_vals
;
305 for (i
= 0; i
< ivs
->num_entries
; i
++)
306 if (rtx_equal_p (ivs
->entries
[i
].hard_reg
, reg
))
307 return ivs
->entries
[i
].pseudo
;
313 get_func_hard_reg_initial_val (struct function
*fun
, rtx reg
)
315 struct initial_value_struct
*ivs
= fun
->hard_reg_initial_vals
;
316 rtx rv
= has_func_hard_reg_initial_val (fun
, reg
);
323 fun
->hard_reg_initial_vals
= ggc_alloc (sizeof (initial_value_struct
));
324 ivs
= fun
->hard_reg_initial_vals
;
325 ivs
->num_entries
= 0;
326 ivs
->max_entries
= 5;
327 ivs
->entries
= ggc_alloc (5 * sizeof (initial_value_pair
));
330 if (ivs
->num_entries
>= ivs
->max_entries
)
332 ivs
->max_entries
+= 5;
333 ivs
->entries
= ggc_realloc (ivs
->entries
,
335 * sizeof (initial_value_pair
));
338 ivs
->entries
[ivs
->num_entries
].hard_reg
= reg
;
339 ivs
->entries
[ivs
->num_entries
].pseudo
= gen_reg_rtx (GET_MODE (reg
));
341 return ivs
->entries
[ivs
->num_entries
++].pseudo
;
345 get_hard_reg_initial_val (enum machine_mode mode
, int regno
)
347 return get_func_hard_reg_initial_val (cfun
, gen_rtx_REG (mode
, regno
));
351 has_hard_reg_initial_val (enum machine_mode mode
, int regno
)
353 return has_func_hard_reg_initial_val (cfun
, gen_rtx_REG (mode
, regno
));
357 emit_initial_value_sets (void)
359 struct initial_value_struct
*ivs
= cfun
->hard_reg_initial_vals
;
367 for (i
= 0; i
< ivs
->num_entries
; i
++)
368 emit_move_insn (ivs
->entries
[i
].pseudo
, ivs
->entries
[i
].hard_reg
);
372 emit_insn_after (seq
, entry_of_function ());
375 /* If the backend knows where to allocate pseudos for hard
376 register initial values, register these allocations now. */
378 allocate_initial_values (rtx
*reg_equiv_memory_loc ATTRIBUTE_UNUSED
)
380 #ifdef ALLOCATE_INITIAL_VALUE
381 struct initial_value_struct
*ivs
= cfun
->hard_reg_initial_vals
;
387 for (i
= 0; i
< ivs
->num_entries
; i
++)
389 int regno
= REGNO (ivs
->entries
[i
].pseudo
);
390 rtx x
= ALLOCATE_INITIAL_VALUE (ivs
->entries
[i
].hard_reg
);
392 if (x
== NULL_RTX
|| REG_N_SETS (REGNO (ivs
->entries
[i
].pseudo
)) > 1)
395 reg_equiv_memory_loc
[regno
] = x
;
398 reg_renumber
[regno
] = REGNO (x
);
399 /* Poke the regno right into regno_reg_rtx
400 so that even fixed regs are accepted. */
401 REGNO (ivs
->entries
[i
].pseudo
) = REGNO (x
);
408 #include "gt-integrate.h"