OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.2.2/] [gcc/] [integrate.c] - Blame information for rev 318

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 38 julius
/* 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)
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 3, 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 COPYING3.  If not see
20
<http://www.gnu.org/licenses/>.  */
21
 
22
#include "config.h"
23
#include "system.h"
24
#include "coretypes.h"
25
#include "tm.h"
26
 
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"
48
 
49
/* Round to the next highest integer that meets the alignment.  */
50
#define CEIL_ROUND(VALUE,ALIGN) (((VALUE) + (ALIGN) - 1) & ~((ALIGN)- 1))
51
 
52
 
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;
63
 
64
static void set_block_origin_self (tree);
65
static void set_block_abstract_flags (tree, int);
66
 
67
 
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)
72
{
73
  if (targetm.attribute_table)
74
    {
75
      tree a;
76
 
77
      for (a = DECL_ATTRIBUTES (fndecl); a; a = TREE_CHAIN (a))
78
        {
79
          tree name = TREE_PURPOSE (a);
80
          int i;
81
 
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);
85
        }
86
    }
87
 
88
  return true;
89
}
90
 
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.  */
100
 
101
static void
102
set_block_origin_self (tree stmt)
103
{
104
  if (BLOCK_ABSTRACT_ORIGIN (stmt) == NULL_TREE)
105
    {
106
      BLOCK_ABSTRACT_ORIGIN (stmt) = stmt;
107
 
108
      {
109
        tree local_decl;
110
 
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.  */
115
      }
116
 
117
      {
118
        tree subblock;
119
 
120
        for (subblock = BLOCK_SUBBLOCKS (stmt);
121
             subblock != NULL_TREE;
122
             subblock = BLOCK_CHAIN (subblock))
123
          set_block_origin_self (subblock);     /* Recurse.  */
124
      }
125
    }
126
}
127
 
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.  */
138
 
139
void
140
set_decl_origin_self (tree decl)
141
{
142
  if (DECL_ABSTRACT_ORIGIN (decl) == NULL_TREE)
143
    {
144
      DECL_ABSTRACT_ORIGIN (decl) = decl;
145
      if (TREE_CODE (decl) == FUNCTION_DECL)
146
        {
147
          tree arg;
148
 
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));
154
        }
155
    }
156
}
157
 
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.  */
162
 
163
static void
164
set_block_abstract_flags (tree stmt, int setting)
165
{
166
  tree local_decl;
167
  tree subblock;
168
 
169
  BLOCK_ABSTRACT (stmt) = setting;
170
 
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);
175
 
176
  for (subblock = BLOCK_SUBBLOCKS (stmt);
177
       subblock != NULL_TREE;
178
       subblock = BLOCK_CHAIN (subblock))
179
    set_block_abstract_flags (subblock, setting);
180
}
181
 
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.  */
187
 
188
void
189
set_decl_abstract_flags (tree decl, int setting)
190
{
191
  DECL_ABSTRACT (decl) = setting;
192
  if (TREE_CODE (decl) == FUNCTION_DECL)
193
    {
194
      tree arg;
195
 
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);
201
    }
202
}
203
 
204
/* Functions to keep track of the values hard regs had at the start of
205
   the function.  */
206
 
207
rtx
208
get_hard_reg_initial_reg (struct function *fun, rtx reg)
209
{
210
  struct initial_value_struct *ivs = fun->hard_reg_initial_vals;
211
  int i;
212
 
213
  if (ivs == 0)
214
    return NULL_RTX;
215
 
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;
219
 
220
  return NULL_RTX;
221
}
222
 
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.  */
225
 
226
rtx
227
get_hard_reg_initial_val (enum machine_mode mode, unsigned int regno)
228
{
229
  struct initial_value_struct *ivs;
230
  rtx rv;
231
 
232
  rv = has_hard_reg_initial_val (mode, regno);
233
  if (rv)
234
    return rv;
235
 
236
  ivs = cfun->hard_reg_initial_vals;
237
  if (ivs == 0)
238
    {
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;
244
    }
245
 
246
  if (ivs->num_entries >= ivs->max_entries)
247
    {
248
      ivs->max_entries += 5;
249
      ivs->entries = ggc_realloc (ivs->entries,
250
                                  ivs->max_entries
251
                                  * sizeof (initial_value_pair));
252
    }
253
 
254
  ivs->entries[ivs->num_entries].hard_reg = gen_rtx_REG (mode, regno);
255
  ivs->entries[ivs->num_entries].pseudo = gen_reg_rtx (mode);
256
 
257
  return ivs->entries[ivs->num_entries++].pseudo;
258
}
259
 
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.  */
263
 
264
rtx
265
has_hard_reg_initial_val (enum machine_mode mode, unsigned int regno)
266
{
267
  struct initial_value_struct *ivs;
268
  int i;
269
 
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;
276
 
277
  return NULL_RTX;
278
}
279
 
280
unsigned int
281
emit_initial_value_sets (void)
282
{
283
  struct initial_value_struct *ivs = cfun->hard_reg_initial_vals;
284
  int i;
285
  rtx seq;
286
 
287
  if (ivs == 0)
288
    return 0;
289
 
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 ();
295
 
296
  emit_insn_at_entry (seq);
297
  return 0;
298
}
299
 
300
struct tree_opt_pass pass_initial_value_sets =
301
{
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
 
315
};
316
 
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)
321
{
322
  if (targetm.allocate_initial_value)
323
    {
324
      struct initial_value_struct *ivs = cfun->hard_reg_initial_vals;
325
      int i;
326
 
327
      if (ivs == 0)
328
        return;
329
 
330
      for (i = 0; i < ivs->num_entries; i++)
331
        {
332
          int regno = REGNO (ivs->entries[i].pseudo);
333
          rtx x = targetm.allocate_initial_value (ivs->entries[i].hard_reg);
334
 
335
          if (x && REG_N_SETS (REGNO (ivs->entries[i].pseudo)) <= 1)
336
            {
337
              if (MEM_P (x))
338
                reg_equiv_memory_loc[regno] = x;
339
              else
340
                {
341
                  basic_block bb;
342
                  int new_regno;
343
 
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)
352
                    {
353
                      struct rtl_bb_info *info = bb->il.rtl;
354
 
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);
361
                    }
362
                }
363
            }
364
        }
365
    }
366
}
367
 
368
#include "gt-integrate.h"

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.