OSDN Git Service

* gcc.dg/vect/vect-116.c: Add vect_int target requirement.
[pf3gnuchains/gcc-fork.git] / gcc / integrate.c
1 /* Procedure integration for GCC.
2    Copyright (C) 1988, 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3    2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
4    Contributed by Michael Tiemann (tiemann@cygnus.com)
5
6 This file is part of GCC.
7
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.
12
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.
17
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.  */
22
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "tm.h"
27
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"
49 #include "df.h"
50
51 /* Round to the next highest integer that meets the alignment.  */
52 #define CEIL_ROUND(VALUE,ALIGN) (((VALUE) + (ALIGN) - 1) & ~((ALIGN)- 1))
53 \f
54
55 /* Private type used by {get/has}_hard_reg_initial_val.  */
56 typedef struct initial_value_pair GTY(()) {
57   rtx hard_reg;
58   rtx pseudo;
59 } initial_value_pair;
60 typedef struct initial_value_struct GTY(()) {
61   int num_entries;
62   int max_entries;
63   initial_value_pair * GTY ((length ("%h.num_entries"))) entries;
64 } initial_value_struct;
65
66 static void set_block_origin_self (tree);
67 static void set_block_abstract_flags (tree, int);
68 \f
69
70 /* Return false if the function FNDECL cannot be inlined on account of its
71    attributes, true otherwise.  */
72 bool
73 function_attribute_inlinable_p (tree fndecl)
74 {
75   if (targetm.attribute_table)
76     {
77       tree a;
78
79       for (a = DECL_ATTRIBUTES (fndecl); a; a = TREE_CHAIN (a))
80         {
81           tree name = TREE_PURPOSE (a);
82           int i;
83
84           for (i = 0; targetm.attribute_table[i].name != NULL; i++)
85             if (is_attribute_p (targetm.attribute_table[i].name, name))
86               return targetm.function_attribute_inlinable_p (fndecl);
87         }
88     }
89
90   return true;
91 }
92 \f
93 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
94    given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
95    that it points to the node itself, thus indicating that the node is its
96    own (abstract) origin.  Additionally, if the BLOCK_ABSTRACT_ORIGIN for
97    the given node is NULL, recursively descend the decl/block tree which
98    it is the root of, and for each other ..._DECL or BLOCK node contained
99    therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
100    still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
101    values to point to themselves.  */
102
103 static void
104 set_block_origin_self (tree stmt)
105 {
106   if (BLOCK_ABSTRACT_ORIGIN (stmt) == NULL_TREE)
107     {
108       BLOCK_ABSTRACT_ORIGIN (stmt) = stmt;
109
110       {
111         tree local_decl;
112
113         for (local_decl = BLOCK_VARS (stmt);
114              local_decl != NULL_TREE;
115              local_decl = TREE_CHAIN (local_decl))
116           set_decl_origin_self (local_decl);    /* Potential recursion.  */
117       }
118
119       {
120         tree subblock;
121
122         for (subblock = BLOCK_SUBBLOCKS (stmt);
123              subblock != NULL_TREE;
124              subblock = BLOCK_CHAIN (subblock))
125           set_block_origin_self (subblock);     /* Recurse.  */
126       }
127     }
128 }
129
130 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
131    the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
132    node to so that it points to the node itself, thus indicating that the
133    node represents its own (abstract) origin.  Additionally, if the
134    DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
135    the decl/block tree of which the given node is the root of, and for
136    each other ..._DECL or BLOCK node contained therein whose
137    DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
138    set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
139    point to themselves.  */
140
141 void
142 set_decl_origin_self (tree decl)
143 {
144   if (DECL_ABSTRACT_ORIGIN (decl) == NULL_TREE)
145     {
146       DECL_ABSTRACT_ORIGIN (decl) = decl;
147       if (TREE_CODE (decl) == FUNCTION_DECL)
148         {
149           tree arg;
150
151           for (arg = DECL_ARGUMENTS (decl); arg; arg = TREE_CHAIN (arg))
152             DECL_ABSTRACT_ORIGIN (arg) = arg;
153           if (DECL_INITIAL (decl) != NULL_TREE
154               && DECL_INITIAL (decl) != error_mark_node)
155             set_block_origin_self (DECL_INITIAL (decl));
156         }
157     }
158 }
159 \f
160 /* Given a pointer to some BLOCK node, and a boolean value to set the
161    "abstract" flags to, set that value into the BLOCK_ABSTRACT flag for
162    the given block, and for all local decls and all local sub-blocks
163    (recursively) which are contained therein.  */
164
165 static void
166 set_block_abstract_flags (tree stmt, int setting)
167 {
168   tree local_decl;
169   tree subblock;
170
171   BLOCK_ABSTRACT (stmt) = setting;
172
173   for (local_decl = BLOCK_VARS (stmt);
174        local_decl != NULL_TREE;
175        local_decl = TREE_CHAIN (local_decl))
176     set_decl_abstract_flags (local_decl, setting);
177
178   for (subblock = BLOCK_SUBBLOCKS (stmt);
179        subblock != NULL_TREE;
180        subblock = BLOCK_CHAIN (subblock))
181     set_block_abstract_flags (subblock, setting);
182 }
183
184 /* Given a pointer to some ..._DECL node, and a boolean value to set the
185    "abstract" flags to, set that value into the DECL_ABSTRACT flag for the
186    given decl, and (in the case where the decl is a FUNCTION_DECL) also
187    set the abstract flags for all of the parameters, local vars, local
188    blocks and sub-blocks (recursively) to the same setting.  */
189
190 void
191 set_decl_abstract_flags (tree decl, int setting)
192 {
193   DECL_ABSTRACT (decl) = setting;
194   if (TREE_CODE (decl) == FUNCTION_DECL)
195     {
196       tree arg;
197
198       for (arg = DECL_ARGUMENTS (decl); arg; arg = TREE_CHAIN (arg))
199         DECL_ABSTRACT (arg) = setting;
200       if (DECL_INITIAL (decl) != NULL_TREE
201           && DECL_INITIAL (decl) != error_mark_node)
202         set_block_abstract_flags (DECL_INITIAL (decl), setting);
203     }
204 }
205 \f
206 /* Functions to keep track of the values hard regs had at the start of
207    the function.  */
208
209 rtx
210 get_hard_reg_initial_reg (struct function *fun, rtx reg)
211 {
212   struct initial_value_struct *ivs = fun->hard_reg_initial_vals;
213   int i;
214
215   if (ivs == 0)
216     return NULL_RTX;
217
218   for (i = 0; i < ivs->num_entries; i++)
219     if (rtx_equal_p (ivs->entries[i].pseudo, reg))
220       return ivs->entries[i].hard_reg;
221
222   return NULL_RTX;
223 }
224
225 /* Make sure that there's a pseudo register of mode MODE that stores the
226    initial value of hard register REGNO.  Return an rtx for such a pseudo.  */
227
228 rtx
229 get_hard_reg_initial_val (enum machine_mode mode, unsigned int regno)
230 {
231   struct initial_value_struct *ivs;
232   rtx rv;
233
234   rv = has_hard_reg_initial_val (mode, regno);
235   if (rv)
236     return rv;
237
238   ivs = cfun->hard_reg_initial_vals;
239   if (ivs == 0)
240     {
241       ivs = ggc_alloc (sizeof (initial_value_struct));
242       ivs->num_entries = 0;
243       ivs->max_entries = 5;
244       ivs->entries = ggc_alloc (5 * sizeof (initial_value_pair));
245       cfun->hard_reg_initial_vals = ivs;
246     }
247
248   if (ivs->num_entries >= ivs->max_entries)
249     {
250       ivs->max_entries += 5;
251       ivs->entries = ggc_realloc (ivs->entries,
252                                   ivs->max_entries
253                                   * sizeof (initial_value_pair));
254     }
255
256   ivs->entries[ivs->num_entries].hard_reg = gen_rtx_REG (mode, regno);
257   ivs->entries[ivs->num_entries].pseudo = gen_reg_rtx (mode);
258
259   return ivs->entries[ivs->num_entries++].pseudo;
260 }
261
262 /* See if get_hard_reg_initial_val has been used to create a pseudo
263    for the initial value of hard register REGNO in mode MODE.  Return
264    the associated pseudo if so, otherwise return NULL.  */
265
266 rtx
267 has_hard_reg_initial_val (enum machine_mode mode, unsigned int regno)
268 {
269   struct initial_value_struct *ivs;
270   int i;
271
272   ivs = cfun->hard_reg_initial_vals;
273   if (ivs != 0)
274     for (i = 0; i < ivs->num_entries; i++)
275       if (GET_MODE (ivs->entries[i].hard_reg) == mode
276           && REGNO (ivs->entries[i].hard_reg) == regno)
277         return ivs->entries[i].pseudo;
278
279   return NULL_RTX;
280 }
281
282 unsigned int
283 emit_initial_value_sets (void)
284 {
285   struct initial_value_struct *ivs = cfun->hard_reg_initial_vals;
286   int i;
287   rtx seq;
288
289   if (ivs == 0)
290     return 0;
291
292   start_sequence ();
293   for (i = 0; i < ivs->num_entries; i++)
294     emit_move_insn (ivs->entries[i].pseudo, ivs->entries[i].hard_reg);
295   seq = get_insns ();
296   end_sequence ();
297
298   emit_insn_at_entry (seq);
299   return 0;
300 }
301
302 struct tree_opt_pass pass_initial_value_sets =
303 {
304   "initvals",                           /* name */
305   NULL,                                 /* gate */
306   emit_initial_value_sets,              /* execute */
307   NULL,                                 /* sub */
308   NULL,                                 /* next */
309   0,                                    /* static_pass_number */
310   0,                                    /* tv_id */
311   0,                                    /* properties_required */
312   0,                                    /* properties_provided */
313   0,                                    /* properties_destroyed */
314   0,                                    /* todo_flags_start */
315   TODO_dump_func,                       /* todo_flags_finish */
316   0                                     /* letter */
317 };
318
319 /* If the backend knows where to allocate pseudos for hard
320    register initial values, register these allocations now.  */
321 void
322 allocate_initial_values (rtx *reg_equiv_memory_loc)
323 {
324   if (targetm.allocate_initial_value)
325     {
326       struct initial_value_struct *ivs = cfun->hard_reg_initial_vals;
327       int i;
328
329       if (ivs == 0)
330         return;
331
332       for (i = 0; i < ivs->num_entries; i++)
333         {
334           int regno = REGNO (ivs->entries[i].pseudo);
335           rtx x = targetm.allocate_initial_value (ivs->entries[i].hard_reg);
336   
337           if (x && REG_N_SETS (REGNO (ivs->entries[i].pseudo)) <= 1)
338             {
339               if (MEM_P (x))
340                 reg_equiv_memory_loc[regno] = x;
341               else
342                 {
343                   basic_block bb;
344                   int new_regno;
345
346                   gcc_assert (REG_P (x));
347                   new_regno = REGNO (x);
348                   reg_renumber[regno] = new_regno;
349                   /* Poke the regno right into regno_reg_rtx so that even
350                      fixed regs are accepted.  */
351                   SET_REGNO (ivs->entries[i].pseudo, new_regno);
352                   /* Update global register liveness information.  */
353                   FOR_EACH_BB (bb)
354                     {
355                       if (REGNO_REG_SET_P(df_get_live_in (bb), regno))
356                         SET_REGNO_REG_SET (df_get_live_in (bb), new_regno);
357                       if (REGNO_REG_SET_P(df_get_live_out (bb), regno))
358                         SET_REGNO_REG_SET (df_get_live_out (bb), new_regno);
359                     }
360                 }
361             }
362         }
363     }
364 }
365
366 #include "gt-integrate.h"