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
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 COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
24 #include "coretypes.h"
33 #include "insn-config.h"
37 #include "integrate.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(()) {
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 /* 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. */
102 set_block_origin_self (tree stmt
)
104 if (BLOCK_ABSTRACT_ORIGIN (stmt
) == NULL_TREE
)
106 BLOCK_ABSTRACT_ORIGIN (stmt
) = stmt
;
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. */
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. */
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
)
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. */
164 set_block_abstract_flags (tree stmt
, int setting
)
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. */
189 set_decl_abstract_flags (tree decl
, int setting
)
191 DECL_ABSTRACT (decl
) = setting
;
192 if (TREE_CODE (decl
) == FUNCTION_DECL
)
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
208 get_hard_reg_initial_reg (struct function
*fun
, rtx reg
)
210 struct initial_value_struct
*ivs
= fun
->hard_reg_initial_vals
;
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
;
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
;
232 rv
= has_hard_reg_initial_val (mode
, regno
);
236 ivs
= cfun
->hard_reg_initial_vals
;
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
,
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
;
270 ivs
= cfun
->hard_reg_initial_vals
;
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
;
281 emit_initial_value_sets (void)
283 struct initial_value_struct
*ivs
= cfun
->hard_reg_initial_vals
;
291 for (i
= 0; i
< ivs
->num_entries
; i
++)
292 emit_move_insn (ivs
->entries
[i
].pseudo
, ivs
->entries
[i
].hard_reg
);
296 emit_insn_at_entry (seq
);
300 struct tree_opt_pass pass_initial_value_sets
=
302 "initvals", /* name */
304 emit_initial_value_sets
, /* execute */
307 0, /* static_pass_number */
309 0, /* properties_required */
310 0, /* properties_provided */
311 0, /* properties_destroyed */
312 0, /* todo_flags_start */
313 TODO_dump_func
, /* todo_flags_finish */
317 /* If the backend knows where to allocate pseudos for hard
318 register initial values, register these allocations now. */
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
;
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)
338 reg_equiv_memory_loc
[regno
] = x
;
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. */
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
,
358 if (REGNO_REG_SET_P(info
->global_live_at_end
, regno
))
359 SET_REGNO_REG_SET (info
->global_live_at_end
,
368 #include "gt-integrate.h"