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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [lto/] [lto-lang.c] - Blame information for rev 716

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 716 jeremybenn
/* Language-dependent hooks for LTO.
2
   Copyright 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
3
   Contributed by CodeSourcery, Inc.
4
 
5
This file is part of GCC.
6
 
7
GCC is free software; you can redistribute it and/or modify it under
8
the terms of the GNU General Public License as published by the Free
9
Software Foundation; either version 3, or (at your option) any later
10
version.
11
 
12
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13
WARRANTY; without even the implied warranty of MERCHANTABILITY or
14
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15
for more details.
16
 
17
You should have received a copy of the GNU General Public License
18
along with GCC; see the file COPYING3.  If not see
19
<http://www.gnu.org/licenses/>.  */
20
 
21
#include "config.h"
22
#include "system.h"
23
#include "coretypes.h"
24
#include "flags.h"
25
#include "tm.h"
26
#include "tree.h"
27
#include "target.h"
28
#include "langhooks.h"
29
#include "langhooks-def.h"
30
#include "debug.h"
31
#include "lto-tree.h"
32
#include "lto.h"
33
#include "tree-inline.h"
34
#include "gimple.h"
35
#include "diagnostic-core.h"
36
#include "toplev.h"
37
#include "lto-streamer.h"
38
 
39
static tree handle_noreturn_attribute (tree *, tree, tree, int, bool *);
40
static tree handle_leaf_attribute (tree *, tree, tree, int, bool *);
41
static tree handle_const_attribute (tree *, tree, tree, int, bool *);
42
static tree handle_malloc_attribute (tree *, tree, tree, int, bool *);
43
static tree handle_pure_attribute (tree *, tree, tree, int, bool *);
44
static tree handle_novops_attribute (tree *, tree, tree, int, bool *);
45
static tree handle_nonnull_attribute (tree *, tree, tree, int, bool *);
46
static tree handle_nothrow_attribute (tree *, tree, tree, int, bool *);
47
static tree handle_sentinel_attribute (tree *, tree, tree, int, bool *);
48
static tree handle_type_generic_attribute (tree *, tree, tree, int, bool *);
49
static tree handle_transaction_pure_attribute (tree *, tree, tree, int, bool *);
50
static tree handle_returns_twice_attribute (tree *, tree, tree, int, bool *);
51
static tree ignore_attribute (tree *, tree, tree, int, bool *);
52
 
53
static tree handle_format_attribute (tree *, tree, tree, int, bool *);
54
static tree handle_format_arg_attribute (tree *, tree, tree, int, bool *);
55
 
56
/* Table of machine-independent attributes supported in GIMPLE.  */
57
const struct attribute_spec lto_attribute_table[] =
58
{
59
  /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
60
       do_diagnostic } */
61
  { "noreturn",               0, 0, true,  false, false,
62
                              handle_noreturn_attribute, false },
63
  { "leaf",                   0, 0, true,  false, false,
64
                              handle_leaf_attribute, false },
65
  /* The same comments as for noreturn attributes apply to const ones.  */
66
  { "const",                  0, 0, true,  false, false,
67
                              handle_const_attribute, false },
68
  { "malloc",                 0, 0, true,  false, false,
69
                              handle_malloc_attribute, false },
70
  { "pure",                   0, 0, true,  false, false,
71
                              handle_pure_attribute, false },
72
  { "no vops",                0, 0, true,  false, false,
73
                              handle_novops_attribute, false },
74
  { "nonnull",                0, -1, false, true, true,
75
                              handle_nonnull_attribute, false },
76
  { "nothrow",                0, 0, true,  false, false,
77
                              handle_nothrow_attribute, false },
78
  { "returns_twice",          0, 0, true,  false, false,
79
                              handle_returns_twice_attribute, false },
80
  { "sentinel",               0, 1, false, true, true,
81
                              handle_sentinel_attribute, false },
82
  { "type generic",           0, 0, false, true, true,
83
                              handle_type_generic_attribute, false },
84
  { "transaction_pure",       0, 0, false, true, true,
85
                              handle_transaction_pure_attribute, false },
86
  /* For internal use only.  The leading '*' both prevents its usage in
87
     source code and signals that it may be overridden by machine tables.  */
88
  { "*tm regparm",            0, 0, false, true, true,
89
                              ignore_attribute, false },
90
  { NULL,                     0, 0, false, false, false, NULL, false }
91
};
92
 
93
/* Give the specifications for the format attributes, used by C and all
94
   descendants.  */
95
 
96
const struct attribute_spec lto_format_attribute_table[] =
97
{
98
  /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
99
       affects_type_identity } */
100
  { "format",                 3, 3, false, true,  true,
101
                              handle_format_attribute, false },
102
  { "format_arg",             1, 1, false, true,  true,
103
                              handle_format_arg_attribute, false },
104
  { NULL,                     0, 0, false, false, false, NULL, false }
105
};
106
 
107
enum built_in_attribute
108
{
109
#define DEF_ATTR_NULL_TREE(ENUM) ENUM,
110
#define DEF_ATTR_INT(ENUM, VALUE) ENUM,
111
#define DEF_ATTR_IDENT(ENUM, STRING) ENUM,
112
#define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) ENUM,
113
#include "builtin-attrs.def"
114
#undef DEF_ATTR_NULL_TREE
115
#undef DEF_ATTR_INT
116
#undef DEF_ATTR_IDENT
117
#undef DEF_ATTR_TREE_LIST
118
  ATTR_LAST
119
};
120
 
121
static GTY(()) tree built_in_attributes[(int) ATTR_LAST];
122
 
123
/* Builtin types.  */
124
 
125
enum lto_builtin_type
126
{
127
#define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME,
128
#define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME,
129
#define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME,
130
#define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME,
131
#define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
132
#define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
133
#define DEF_FUNCTION_TYPE_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) NAME,
134
#define DEF_FUNCTION_TYPE_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6) NAME,
135
#define DEF_FUNCTION_TYPE_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7) NAME,
136
#define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME,
137
#define DEF_FUNCTION_TYPE_VAR_1(NAME, RETURN, ARG1) NAME,
138
#define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME,
139
#define DEF_FUNCTION_TYPE_VAR_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
140
#define DEF_FUNCTION_TYPE_VAR_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
141
#define DEF_FUNCTION_TYPE_VAR_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG6) \
142
  NAME,
143
#define DEF_POINTER_TYPE(NAME, TYPE) NAME,
144
#include "builtin-types.def"
145
#undef DEF_PRIMITIVE_TYPE
146
#undef DEF_FUNCTION_TYPE_0
147
#undef DEF_FUNCTION_TYPE_1
148
#undef DEF_FUNCTION_TYPE_2
149
#undef DEF_FUNCTION_TYPE_3
150
#undef DEF_FUNCTION_TYPE_4
151
#undef DEF_FUNCTION_TYPE_5
152
#undef DEF_FUNCTION_TYPE_6
153
#undef DEF_FUNCTION_TYPE_7
154
#undef DEF_FUNCTION_TYPE_VAR_0
155
#undef DEF_FUNCTION_TYPE_VAR_1
156
#undef DEF_FUNCTION_TYPE_VAR_2
157
#undef DEF_FUNCTION_TYPE_VAR_3
158
#undef DEF_FUNCTION_TYPE_VAR_4
159
#undef DEF_FUNCTION_TYPE_VAR_5
160
#undef DEF_POINTER_TYPE
161
  BT_LAST
162
};
163
 
164
typedef enum lto_builtin_type builtin_type;
165
 
166
static GTY(()) tree builtin_types[(int) BT_LAST + 1];
167
 
168
static GTY(()) tree string_type_node;
169
static GTY(()) tree const_string_type_node;
170
static GTY(()) tree wint_type_node;
171
static GTY(()) tree intmax_type_node;
172
static GTY(()) tree uintmax_type_node;
173
static GTY(()) tree signed_size_type_node;
174
 
175
/* Flags needed to process builtins.def.  */
176
int flag_isoc94;
177
int flag_isoc99;
178
 
179
/* Attribute handlers.  */
180
 
181
/* Handle a "noreturn" attribute; arguments as in
182
   struct attribute_spec.handler.  */
183
 
184
static tree
185
handle_noreturn_attribute (tree *node, tree ARG_UNUSED (name),
186
                           tree ARG_UNUSED (args), int ARG_UNUSED (flags),
187
                           bool * ARG_UNUSED (no_add_attrs))
188
{
189
  tree type = TREE_TYPE (*node);
190
 
191
  if (TREE_CODE (*node) == FUNCTION_DECL)
192
    TREE_THIS_VOLATILE (*node) = 1;
193
  else if (TREE_CODE (type) == POINTER_TYPE
194
           && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
195
    TREE_TYPE (*node)
196
      = build_pointer_type
197
        (build_type_variant (TREE_TYPE (type),
198
                             TYPE_READONLY (TREE_TYPE (type)), 1));
199
  else
200
    gcc_unreachable ();
201
 
202
  return NULL_TREE;
203
}
204
 
205
/* Handle a "leaf" attribute; arguments as in
206
   struct attribute_spec.handler.  */
207
 
208
static tree
209
handle_leaf_attribute (tree *node, tree name,
210
                       tree ARG_UNUSED (args),
211
                       int ARG_UNUSED (flags), bool *no_add_attrs)
212
{
213
  if (TREE_CODE (*node) != FUNCTION_DECL)
214
    {
215
      warning (OPT_Wattributes, "%qE attribute ignored", name);
216
      *no_add_attrs = true;
217
    }
218
  if (!TREE_PUBLIC (*node))
219
    {
220
      warning (OPT_Wattributes, "%qE attribute has no effect on unit local functions", name);
221
      *no_add_attrs = true;
222
    }
223
 
224
  return NULL_TREE;
225
}
226
 
227
/* Handle a "const" attribute; arguments as in
228
   struct attribute_spec.handler.  */
229
 
230
static tree
231
handle_const_attribute (tree *node, tree ARG_UNUSED (name),
232
                        tree ARG_UNUSED (args), int ARG_UNUSED (flags),
233
                        bool * ARG_UNUSED (no_add_attrs))
234
{
235
  tree type = TREE_TYPE (*node);
236
 
237
  /* See FIXME comment on noreturn in c_common_attribute_table.  */
238
  if (TREE_CODE (*node) == FUNCTION_DECL)
239
    TREE_READONLY (*node) = 1;
240
  else if (TREE_CODE (type) == POINTER_TYPE
241
           && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
242
    TREE_TYPE (*node)
243
      = build_pointer_type
244
        (build_type_variant (TREE_TYPE (type), 1,
245
                             TREE_THIS_VOLATILE (TREE_TYPE (type))));
246
  else
247
    gcc_unreachable ();
248
 
249
  return NULL_TREE;
250
}
251
 
252
 
253
/* Handle a "malloc" attribute; arguments as in
254
   struct attribute_spec.handler.  */
255
 
256
static tree
257
handle_malloc_attribute (tree *node, tree ARG_UNUSED (name),
258
                         tree ARG_UNUSED (args), int ARG_UNUSED (flags),
259
                         bool * ARG_UNUSED (no_add_attrs))
260
{
261
  if (TREE_CODE (*node) == FUNCTION_DECL
262
      && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (*node))))
263
    DECL_IS_MALLOC (*node) = 1;
264
  else
265
    gcc_unreachable ();
266
 
267
  return NULL_TREE;
268
}
269
 
270
 
271
/* Handle a "pure" attribute; arguments as in
272
   struct attribute_spec.handler.  */
273
 
274
static tree
275
handle_pure_attribute (tree *node, tree ARG_UNUSED (name),
276
                       tree ARG_UNUSED (args), int ARG_UNUSED (flags),
277
                       bool * ARG_UNUSED (no_add_attrs))
278
{
279
  if (TREE_CODE (*node) == FUNCTION_DECL)
280
    DECL_PURE_P (*node) = 1;
281
  else
282
    gcc_unreachable ();
283
 
284
  return NULL_TREE;
285
}
286
 
287
 
288
/* Handle a "no vops" attribute; arguments as in
289
   struct attribute_spec.handler.  */
290
 
291
static tree
292
handle_novops_attribute (tree *node, tree ARG_UNUSED (name),
293
                         tree ARG_UNUSED (args), int ARG_UNUSED (flags),
294
                         bool *ARG_UNUSED (no_add_attrs))
295
{
296
  gcc_assert (TREE_CODE (*node) == FUNCTION_DECL);
297
  DECL_IS_NOVOPS (*node) = 1;
298
  return NULL_TREE;
299
}
300
 
301
 
302
/* Helper for nonnull attribute handling; fetch the operand number
303
   from the attribute argument list.  */
304
 
305
static bool
306
get_nonnull_operand (tree arg_num_expr, unsigned HOST_WIDE_INT *valp)
307
{
308
  /* Verify the arg number is a constant.  */
309
  if (TREE_CODE (arg_num_expr) != INTEGER_CST
310
      || TREE_INT_CST_HIGH (arg_num_expr) != 0)
311
    return false;
312
 
313
  *valp = TREE_INT_CST_LOW (arg_num_expr);
314
  return true;
315
}
316
 
317
/* Handle the "nonnull" attribute.  */
318
 
319
static tree
320
handle_nonnull_attribute (tree *node, tree ARG_UNUSED (name),
321
                          tree args, int ARG_UNUSED (flags),
322
                          bool * ARG_UNUSED (no_add_attrs))
323
{
324
  tree type = *node;
325
 
326
  /* If no arguments are specified, all pointer arguments should be
327
     non-null.  Verify a full prototype is given so that the arguments
328
     will have the correct types when we actually check them later.  */
329
  if (!args)
330
    {
331
      gcc_assert (prototype_p (type));
332
      return NULL_TREE;
333
    }
334
 
335
  /* Argument list specified.  Verify that each argument number references
336
     a pointer argument.  */
337
  for (; args; args = TREE_CHAIN (args))
338
    {
339
      tree argument;
340
      unsigned HOST_WIDE_INT arg_num = 0, ck_num;
341
 
342
      if (!get_nonnull_operand (TREE_VALUE (args), &arg_num))
343
        gcc_unreachable ();
344
 
345
      argument = TYPE_ARG_TYPES (type);
346
      if (argument)
347
        {
348
          for (ck_num = 1; ; ck_num++)
349
            {
350
              if (!argument || ck_num == arg_num)
351
                break;
352
              argument = TREE_CHAIN (argument);
353
            }
354
 
355
          gcc_assert (argument
356
                      && TREE_CODE (TREE_VALUE (argument)) == POINTER_TYPE);
357
        }
358
    }
359
 
360
  return NULL_TREE;
361
}
362
 
363
 
364
/* Handle a "nothrow" attribute; arguments as in
365
   struct attribute_spec.handler.  */
366
 
367
static tree
368
handle_nothrow_attribute (tree *node, tree ARG_UNUSED (name),
369
                          tree ARG_UNUSED (args), int ARG_UNUSED (flags),
370
                          bool * ARG_UNUSED (no_add_attrs))
371
{
372
  if (TREE_CODE (*node) == FUNCTION_DECL)
373
    TREE_NOTHROW (*node) = 1;
374
  else
375
    gcc_unreachable ();
376
 
377
  return NULL_TREE;
378
}
379
 
380
 
381
/* Handle a "sentinel" attribute.  */
382
 
383
static tree
384
handle_sentinel_attribute (tree *node, tree ARG_UNUSED (name), tree args,
385
                           int ARG_UNUSED (flags),
386
                           bool * ARG_UNUSED (no_add_attrs))
387
{
388
  gcc_assert (stdarg_p (*node));
389
 
390
  if (args)
391
    {
392
      tree position = TREE_VALUE (args);
393
      gcc_assert (TREE_CODE (position) == INTEGER_CST);
394
      if (tree_int_cst_lt (position, integer_zero_node))
395
        gcc_unreachable ();
396
    }
397
 
398
  return NULL_TREE;
399
}
400
 
401
/* Handle a "type_generic" attribute.  */
402
 
403
static tree
404
handle_type_generic_attribute (tree *node, tree ARG_UNUSED (name),
405
                               tree ARG_UNUSED (args), int ARG_UNUSED (flags),
406
                               bool * ARG_UNUSED (no_add_attrs))
407
{
408
  /* Ensure we have a function type.  */
409
  gcc_assert (TREE_CODE (*node) == FUNCTION_TYPE);
410
 
411
  /* Ensure we have a variadic function.  */
412
  gcc_assert (!prototype_p (*node) || stdarg_p (*node));
413
 
414
  return NULL_TREE;
415
}
416
 
417
/* Handle a "transaction_pure" attribute.  */
418
 
419
static tree
420
handle_transaction_pure_attribute (tree *node, tree ARG_UNUSED (name),
421
                                   tree ARG_UNUSED (args),
422
                                   int ARG_UNUSED (flags),
423
                                   bool * ARG_UNUSED (no_add_attrs))
424
{
425
  /* Ensure we have a function type.  */
426
  gcc_assert (TREE_CODE (*node) == FUNCTION_TYPE);
427
 
428
  return NULL_TREE;
429
}
430
 
431
/* Handle a "returns_twice" attribute.  */
432
 
433
static tree
434
handle_returns_twice_attribute (tree *node, tree ARG_UNUSED (name),
435
                                tree ARG_UNUSED (args),
436
                                int ARG_UNUSED (flags),
437
                                bool * ARG_UNUSED (no_add_attrs))
438
{
439
  gcc_assert (TREE_CODE (*node) == FUNCTION_DECL);
440
 
441
  DECL_IS_RETURNS_TWICE (*node) = 1;
442
 
443
  return NULL_TREE;
444
}
445
 
446
/* Ignore the given attribute.  Used when this attribute may be usefully
447
   overridden by the target, but is not used generically.  */
448
 
449
static tree
450
ignore_attribute (tree * ARG_UNUSED (node), tree ARG_UNUSED (name),
451
                  tree ARG_UNUSED (args), int ARG_UNUSED (flags),
452
                  bool *no_add_attrs)
453
{
454
  *no_add_attrs = true;
455
  return NULL_TREE;
456
}
457
 
458
/* Handle a "format" attribute; arguments as in
459
   struct attribute_spec.handler.  */
460
 
461
static tree
462
handle_format_attribute (tree * ARG_UNUSED (node), tree ARG_UNUSED (name),
463
                         tree ARG_UNUSED (args), int ARG_UNUSED (flags),
464
                         bool *no_add_attrs)
465
{
466
  *no_add_attrs = true;
467
  return NULL_TREE;
468
}
469
 
470
 
471
/* Handle a "format_arg" attribute; arguments as in
472
   struct attribute_spec.handler.  */
473
 
474
tree
475
handle_format_arg_attribute (tree * ARG_UNUSED (node), tree ARG_UNUSED (name),
476
                             tree ARG_UNUSED (args), int ARG_UNUSED (flags),
477
                             bool *no_add_attrs)
478
{
479
  *no_add_attrs = true;
480
  return NULL_TREE;
481
}
482
 
483
 
484
/* Cribbed from c-common.c.  */
485
 
486
static void
487
def_fn_type (builtin_type def, builtin_type ret, bool var, int n, ...)
488
{
489
  tree t;
490
  tree *args = XALLOCAVEC (tree, n);
491
  va_list list;
492
  int i;
493
 
494
  va_start (list, n);
495
  for (i = 0; i < n; ++i)
496
    {
497
      builtin_type a = (builtin_type) va_arg (list, int);
498
      t = builtin_types[a];
499
      if (t == error_mark_node)
500
        goto egress;
501
      args[i] = t;
502
    }
503
  va_end (list);
504
 
505
  t = builtin_types[ret];
506
  if (t == error_mark_node)
507
    goto egress;
508
  if (var)
509
    t = build_varargs_function_type_array (t, n, args);
510
  else
511
    t = build_function_type_array (t, n, args);
512
 
513
 egress:
514
  builtin_types[def] = t;
515
  va_end (list);
516
}
517
 
518
/* Used to help initialize the builtin-types.def table.  When a type of
519
   the correct size doesn't exist, use error_mark_node instead of NULL.
520
   The later results in segfaults even when a decl using the type doesn't
521
   get invoked.  */
522
 
523
static tree
524
builtin_type_for_size (int size, bool unsignedp)
525
{
526
  tree type = lang_hooks.types.type_for_size (size, unsignedp);
527
  return type ? type : error_mark_node;
528
}
529
 
530
/* Support for DEF_BUILTIN.  */
531
 
532
static void
533
def_builtin_1 (enum built_in_function fncode, const char *name,
534
               enum built_in_class fnclass, tree fntype, tree libtype,
535
               bool both_p, bool fallback_p, bool nonansi_p,
536
               tree fnattrs, bool implicit_p)
537
{
538
  tree decl;
539
  const char *libname;
540
 
541
  if (fntype == error_mark_node)
542
    return;
543
 
544
  libname = name + strlen ("__builtin_");
545
  decl = add_builtin_function (name, fntype, fncode, fnclass,
546
                               (fallback_p ? libname : NULL),
547
                               fnattrs);
548
 
549
  if (both_p
550
      && !flag_no_builtin
551
      && !(nonansi_p && flag_no_nonansi_builtin))
552
    add_builtin_function (libname, libtype, fncode, fnclass,
553
                          NULL, fnattrs);
554
 
555
  set_builtin_decl (fncode, decl, implicit_p);
556
}
557
 
558
 
559
/* Initialize the attribute table for all the supported builtins.  */
560
 
561
static void
562
lto_init_attributes (void)
563
{
564
  /* Fill in the built_in_attributes array.  */
565
#define DEF_ATTR_NULL_TREE(ENUM)                                \
566
  built_in_attributes[(int) ENUM] = NULL_TREE;
567
#define DEF_ATTR_INT(ENUM, VALUE)                               \
568
  built_in_attributes[(int) ENUM] = build_int_cst (NULL_TREE, VALUE);
569
#define DEF_ATTR_IDENT(ENUM, STRING)                            \
570
  built_in_attributes[(int) ENUM] = get_identifier (STRING);
571
#define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) \
572
  built_in_attributes[(int) ENUM]                       \
573
    = tree_cons (built_in_attributes[(int) PURPOSE],    \
574
                 built_in_attributes[(int) VALUE],      \
575
                 built_in_attributes[(int) CHAIN]);
576
#include "builtin-attrs.def"
577
#undef DEF_ATTR_NULL_TREE
578
#undef DEF_ATTR_INT
579
#undef DEF_ATTR_IDENT
580
#undef DEF_ATTR_TREE_LIST
581
}
582
 
583
/* Create builtin types and functions.  VA_LIST_REF_TYPE_NODE and
584
   VA_LIST_ARG_TYPE_NODE are used in builtin-types.def.  */
585
 
586
static void
587
lto_define_builtins (tree va_list_ref_type_node ATTRIBUTE_UNUSED,
588
                     tree va_list_arg_type_node ATTRIBUTE_UNUSED)
589
{
590
#define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
591
  builtin_types[ENUM] = VALUE;
592
#define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
593
  def_fn_type (ENUM, RETURN, 0, 0);
594
#define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
595
  def_fn_type (ENUM, RETURN, 0, 1, ARG1);
596
#define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \
597
  def_fn_type (ENUM, RETURN, 0, 2, ARG1, ARG2);
598
#define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
599
  def_fn_type (ENUM, RETURN, 0, 3, ARG1, ARG2, ARG3);
600
#define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
601
  def_fn_type (ENUM, RETURN, 0, 4, ARG1, ARG2, ARG3, ARG4);
602
#define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
603
  def_fn_type (ENUM, RETURN, 0, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
604
#define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
605
                            ARG6)                                       \
606
  def_fn_type (ENUM, RETURN, 0, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
607
#define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
608
                            ARG6, ARG7)                                 \
609
  def_fn_type (ENUM, RETURN, 0, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
610
#define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \
611
  def_fn_type (ENUM, RETURN, 1, 0);
612
#define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1) \
613
  def_fn_type (ENUM, RETURN, 1, 1, ARG1);
614
#define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) \
615
  def_fn_type (ENUM, RETURN, 1, 2, ARG1, ARG2);
616
#define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
617
  def_fn_type (ENUM, RETURN, 1, 3, ARG1, ARG2, ARG3);
618
#define DEF_FUNCTION_TYPE_VAR_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
619
  def_fn_type (ENUM, RETURN, 1, 4, ARG1, ARG2, ARG3, ARG4);
620
#define DEF_FUNCTION_TYPE_VAR_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
621
  def_fn_type (ENUM, RETURN, 1, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
622
#define DEF_POINTER_TYPE(ENUM, TYPE) \
623
  builtin_types[(int) ENUM] = build_pointer_type (builtin_types[(int) TYPE]);
624
 
625
#include "builtin-types.def"
626
 
627
#undef DEF_PRIMITIVE_TYPE
628
#undef DEF_FUNCTION_TYPE_1
629
#undef DEF_FUNCTION_TYPE_2
630
#undef DEF_FUNCTION_TYPE_3
631
#undef DEF_FUNCTION_TYPE_4
632
#undef DEF_FUNCTION_TYPE_5
633
#undef DEF_FUNCTION_TYPE_6
634
#undef DEF_FUNCTION_TYPE_VAR_0
635
#undef DEF_FUNCTION_TYPE_VAR_1
636
#undef DEF_FUNCTION_TYPE_VAR_2
637
#undef DEF_FUNCTION_TYPE_VAR_3
638
#undef DEF_FUNCTION_TYPE_VAR_4
639
#undef DEF_FUNCTION_TYPE_VAR_5
640
#undef DEF_POINTER_TYPE
641
  builtin_types[(int) BT_LAST] = NULL_TREE;
642
 
643
  lto_init_attributes ();
644
 
645
#define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, BOTH_P, FALLBACK_P,\
646
                    NONANSI_P, ATTRS, IMPLICIT, COND)                   \
647
    if (NAME && COND)                                                   \
648
      def_builtin_1 (ENUM, NAME, CLASS, builtin_types[(int) TYPE],      \
649
                     builtin_types[(int) LIBTYPE], BOTH_P, FALLBACK_P,  \
650
                     NONANSI_P, built_in_attributes[(int) ATTRS], IMPLICIT);
651
#include "builtins.def"
652
#undef DEF_BUILTIN
653
}
654
 
655
static GTY(()) tree registered_builtin_types;
656
 
657
/* Language hooks.  */
658
 
659
static unsigned int
660
lto_option_lang_mask (void)
661
{
662
  return CL_LTO;
663
}
664
 
665
static bool
666
lto_complain_wrong_lang_p (const struct cl_option *option ATTRIBUTE_UNUSED)
667
{
668
  /* The LTO front end inherits all the options from the first front
669
     end that was used.  However, not all the original front end
670
     options make sense in LTO.
671
 
672
     A real solution would be to filter this in collect2, but collect2
673
     does not have access to all the option attributes to know what to
674
     filter.  So, in lto1 we silently accept inherited flags and do
675
     nothing about it.  */
676
  return false;
677
}
678
 
679
static void
680
lto_init_options_struct (struct gcc_options *opts)
681
{
682
  /* By default, C99-like requirements for complex multiply and divide.
683
     ???  Until the complex method is encoded in the IL this is the only
684
     safe choice.  This will pessimize Fortran code with LTO unless
685
     people specify a complex method manually or use -ffast-math.  */
686
  opts->x_flag_complex_method = 2;
687
}
688
 
689
/* Handle command-line option SCODE.  If the option takes an argument, it is
690
   stored in ARG, which is otherwise NULL.  VALUE holds either a numerical
691
   argument or a binary value indicating whether the positive or negative form
692
   of the option was supplied.  */
693
 
694
const char *resolution_file_name;
695
static bool
696
lto_handle_option (size_t scode, const char *arg,
697
                   int value ATTRIBUTE_UNUSED, int kind ATTRIBUTE_UNUSED,
698
                   location_t loc ATTRIBUTE_UNUSED,
699
                   const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED)
700
{
701
  enum opt_code code = (enum opt_code) scode;
702
  bool result = true;
703
 
704
  switch (code)
705
    {
706
    case OPT_fresolution_:
707
      resolution_file_name = arg;
708
      break;
709
 
710
    case OPT_Wabi:
711
      warn_psabi = value;
712
      break;
713
 
714
    default:
715
      break;
716
    }
717
 
718
  return result;
719
}
720
 
721
/* Perform post-option processing.  Does additional initialization based on
722
   command-line options.  PFILENAME is the main input filename.  Returns false
723
   to enable subsequent back-end initialization.  */
724
 
725
static bool
726
lto_post_options (const char **pfilename ATTRIBUTE_UNUSED)
727
{
728
  /* -fltrans and -fwpa are mutually exclusive.  Check for that here.  */
729
  if (flag_wpa && flag_ltrans)
730
    error ("-fwpa and -fltrans are mutually exclusive");
731
 
732
  if (flag_ltrans)
733
    {
734
      flag_generate_lto = 0;
735
 
736
      /* During LTRANS, we are not looking at the whole program, only
737
         a subset of the whole callgraph.  */
738
      flag_whole_program = 0;
739
    }
740
 
741
  if (flag_wpa)
742
    flag_generate_lto = 1;
743
 
744
  /* Excess precision other than "fast" requires front-end
745
     support.  */
746
  flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;
747
 
748
  /* Initialize the compiler back end.  */
749
  return false;
750
}
751
 
752
/* Return an integer type with PRECISION bits of precision,
753
   that is unsigned if UNSIGNEDP is nonzero, otherwise signed.  */
754
 
755
static tree
756
lto_type_for_size (unsigned precision, int unsignedp)
757
{
758
  if (precision == TYPE_PRECISION (integer_type_node))
759
    return unsignedp ? unsigned_type_node : integer_type_node;
760
 
761
  if (precision == TYPE_PRECISION (signed_char_type_node))
762
    return unsignedp ? unsigned_char_type_node : signed_char_type_node;
763
 
764
  if (precision == TYPE_PRECISION (short_integer_type_node))
765
    return unsignedp ? short_unsigned_type_node : short_integer_type_node;
766
 
767
  if (precision == TYPE_PRECISION (long_integer_type_node))
768
    return unsignedp ? long_unsigned_type_node : long_integer_type_node;
769
 
770
  if (precision == TYPE_PRECISION (long_long_integer_type_node))
771
    return unsignedp
772
           ? long_long_unsigned_type_node
773
           : long_long_integer_type_node;
774
 
775
  if (precision <= TYPE_PRECISION (intQI_type_node))
776
    return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
777
 
778
  if (precision <= TYPE_PRECISION (intHI_type_node))
779
    return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
780
 
781
  if (precision <= TYPE_PRECISION (intSI_type_node))
782
    return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
783
 
784
  if (precision <= TYPE_PRECISION (intDI_type_node))
785
    return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
786
 
787
  if (precision <= TYPE_PRECISION (intTI_type_node))
788
    return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
789
 
790
  return NULL_TREE;
791
}
792
 
793
 
794
/* Return a data type that has machine mode MODE.
795
   If the mode is an integer,
796
   then UNSIGNEDP selects between signed and unsigned types.
797
   If the mode is a fixed-point mode,
798
   then UNSIGNEDP selects between saturating and nonsaturating types.  */
799
 
800
static tree
801
lto_type_for_mode (enum machine_mode mode, int unsigned_p)
802
{
803
  tree t;
804
 
805
  if (mode == TYPE_MODE (integer_type_node))
806
    return unsigned_p ? unsigned_type_node : integer_type_node;
807
 
808
  if (mode == TYPE_MODE (signed_char_type_node))
809
    return unsigned_p ? unsigned_char_type_node : signed_char_type_node;
810
 
811
  if (mode == TYPE_MODE (short_integer_type_node))
812
    return unsigned_p ? short_unsigned_type_node : short_integer_type_node;
813
 
814
  if (mode == TYPE_MODE (long_integer_type_node))
815
    return unsigned_p ? long_unsigned_type_node : long_integer_type_node;
816
 
817
  if (mode == TYPE_MODE (long_long_integer_type_node))
818
    return unsigned_p ? long_long_unsigned_type_node : long_long_integer_type_node;
819
 
820
  if (mode == QImode)
821
    return unsigned_p ? unsigned_intQI_type_node : intQI_type_node;
822
 
823
  if (mode == HImode)
824
    return unsigned_p ? unsigned_intHI_type_node : intHI_type_node;
825
 
826
  if (mode == SImode)
827
    return unsigned_p ? unsigned_intSI_type_node : intSI_type_node;
828
 
829
  if (mode == DImode)
830
    return unsigned_p ? unsigned_intDI_type_node : intDI_type_node;
831
 
832
#if HOST_BITS_PER_WIDE_INT >= 64
833
  if (mode == TYPE_MODE (intTI_type_node))
834
    return unsigned_p ? unsigned_intTI_type_node : intTI_type_node;
835
#endif
836
 
837
  if (mode == TYPE_MODE (float_type_node))
838
    return float_type_node;
839
 
840
  if (mode == TYPE_MODE (double_type_node))
841
    return double_type_node;
842
 
843
  if (mode == TYPE_MODE (long_double_type_node))
844
    return long_double_type_node;
845
 
846
  if (mode == TYPE_MODE (void_type_node))
847
    return void_type_node;
848
 
849
  if (mode == TYPE_MODE (build_pointer_type (char_type_node)))
850
    return (unsigned_p
851
            ? make_unsigned_type (GET_MODE_PRECISION (mode))
852
            : make_signed_type (GET_MODE_PRECISION (mode)));
853
 
854
  if (mode == TYPE_MODE (build_pointer_type (integer_type_node)))
855
    return (unsigned_p
856
            ? make_unsigned_type (GET_MODE_PRECISION (mode))
857
            : make_signed_type (GET_MODE_PRECISION (mode)));
858
 
859
  if (COMPLEX_MODE_P (mode))
860
    {
861
      enum machine_mode inner_mode;
862
      tree inner_type;
863
 
864
      if (mode == TYPE_MODE (complex_float_type_node))
865
        return complex_float_type_node;
866
      if (mode == TYPE_MODE (complex_double_type_node))
867
        return complex_double_type_node;
868
      if (mode == TYPE_MODE (complex_long_double_type_node))
869
        return complex_long_double_type_node;
870
 
871
      if (mode == TYPE_MODE (complex_integer_type_node) && !unsigned_p)
872
        return complex_integer_type_node;
873
 
874
      inner_mode = GET_MODE_INNER (mode);
875
      inner_type = lto_type_for_mode (inner_mode, unsigned_p);
876
      if (inner_type != NULL_TREE)
877
        return build_complex_type (inner_type);
878
    }
879
  else if (VECTOR_MODE_P (mode))
880
    {
881
      enum machine_mode inner_mode = GET_MODE_INNER (mode);
882
      tree inner_type = lto_type_for_mode (inner_mode, unsigned_p);
883
      if (inner_type != NULL_TREE)
884
        return build_vector_type_for_mode (inner_type, mode);
885
    }
886
 
887
  if (mode == TYPE_MODE (dfloat32_type_node))
888
    return dfloat32_type_node;
889
  if (mode == TYPE_MODE (dfloat64_type_node))
890
    return dfloat64_type_node;
891
  if (mode == TYPE_MODE (dfloat128_type_node))
892
    return dfloat128_type_node;
893
 
894
  if (ALL_SCALAR_FIXED_POINT_MODE_P (mode))
895
    {
896
      if (mode == TYPE_MODE (short_fract_type_node))
897
        return unsigned_p ? sat_short_fract_type_node : short_fract_type_node;
898
      if (mode == TYPE_MODE (fract_type_node))
899
        return unsigned_p ? sat_fract_type_node : fract_type_node;
900
      if (mode == TYPE_MODE (long_fract_type_node))
901
        return unsigned_p ? sat_long_fract_type_node : long_fract_type_node;
902
      if (mode == TYPE_MODE (long_long_fract_type_node))
903
        return unsigned_p ? sat_long_long_fract_type_node
904
                         : long_long_fract_type_node;
905
 
906
      if (mode == TYPE_MODE (unsigned_short_fract_type_node))
907
        return unsigned_p ? sat_unsigned_short_fract_type_node
908
                         : unsigned_short_fract_type_node;
909
      if (mode == TYPE_MODE (unsigned_fract_type_node))
910
        return unsigned_p ? sat_unsigned_fract_type_node
911
                         : unsigned_fract_type_node;
912
      if (mode == TYPE_MODE (unsigned_long_fract_type_node))
913
        return unsigned_p ? sat_unsigned_long_fract_type_node
914
                         : unsigned_long_fract_type_node;
915
      if (mode == TYPE_MODE (unsigned_long_long_fract_type_node))
916
        return unsigned_p ? sat_unsigned_long_long_fract_type_node
917
                         : unsigned_long_long_fract_type_node;
918
 
919
      if (mode == TYPE_MODE (short_accum_type_node))
920
        return unsigned_p ? sat_short_accum_type_node : short_accum_type_node;
921
      if (mode == TYPE_MODE (accum_type_node))
922
        return unsigned_p ? sat_accum_type_node : accum_type_node;
923
      if (mode == TYPE_MODE (long_accum_type_node))
924
        return unsigned_p ? sat_long_accum_type_node : long_accum_type_node;
925
      if (mode == TYPE_MODE (long_long_accum_type_node))
926
        return unsigned_p ? sat_long_long_accum_type_node
927
                         : long_long_accum_type_node;
928
 
929
      if (mode == TYPE_MODE (unsigned_short_accum_type_node))
930
        return unsigned_p ? sat_unsigned_short_accum_type_node
931
                         : unsigned_short_accum_type_node;
932
      if (mode == TYPE_MODE (unsigned_accum_type_node))
933
        return unsigned_p ? sat_unsigned_accum_type_node
934
                         : unsigned_accum_type_node;
935
      if (mode == TYPE_MODE (unsigned_long_accum_type_node))
936
        return unsigned_p ? sat_unsigned_long_accum_type_node
937
                         : unsigned_long_accum_type_node;
938
      if (mode == TYPE_MODE (unsigned_long_long_accum_type_node))
939
        return unsigned_p ? sat_unsigned_long_long_accum_type_node
940
                         : unsigned_long_long_accum_type_node;
941
 
942
      if (mode == QQmode)
943
        return unsigned_p ? sat_qq_type_node : qq_type_node;
944
      if (mode == HQmode)
945
        return unsigned_p ? sat_hq_type_node : hq_type_node;
946
      if (mode == SQmode)
947
        return unsigned_p ? sat_sq_type_node : sq_type_node;
948
      if (mode == DQmode)
949
        return unsigned_p ? sat_dq_type_node : dq_type_node;
950
      if (mode == TQmode)
951
        return unsigned_p ? sat_tq_type_node : tq_type_node;
952
 
953
      if (mode == UQQmode)
954
        return unsigned_p ? sat_uqq_type_node : uqq_type_node;
955
      if (mode == UHQmode)
956
        return unsigned_p ? sat_uhq_type_node : uhq_type_node;
957
      if (mode == USQmode)
958
        return unsigned_p ? sat_usq_type_node : usq_type_node;
959
      if (mode == UDQmode)
960
        return unsigned_p ? sat_udq_type_node : udq_type_node;
961
      if (mode == UTQmode)
962
        return unsigned_p ? sat_utq_type_node : utq_type_node;
963
 
964
      if (mode == HAmode)
965
        return unsigned_p ? sat_ha_type_node : ha_type_node;
966
      if (mode == SAmode)
967
        return unsigned_p ? sat_sa_type_node : sa_type_node;
968
      if (mode == DAmode)
969
        return unsigned_p ? sat_da_type_node : da_type_node;
970
      if (mode == TAmode)
971
        return unsigned_p ? sat_ta_type_node : ta_type_node;
972
 
973
      if (mode == UHAmode)
974
        return unsigned_p ? sat_uha_type_node : uha_type_node;
975
      if (mode == USAmode)
976
        return unsigned_p ? sat_usa_type_node : usa_type_node;
977
      if (mode == UDAmode)
978
        return unsigned_p ? sat_uda_type_node : uda_type_node;
979
      if (mode == UTAmode)
980
        return unsigned_p ? sat_uta_type_node : uta_type_node;
981
    }
982
 
983
  for (t = registered_builtin_types; t; t = TREE_CHAIN (t))
984
    if (TYPE_MODE (TREE_VALUE (t)) == mode)
985
      return TREE_VALUE (t);
986
 
987
  return NULL_TREE;
988
}
989
 
990
/* Return true if we are in the global binding level.  */
991
 
992
static bool
993
lto_global_bindings_p (void)
994
{
995
  return cfun == NULL;
996
}
997
 
998
static void
999
lto_set_decl_assembler_name (tree decl)
1000
{
1001
  /* This is almost the same as lhd_set_decl_assembler_name, except that
1002
     we need to uniquify file-scope names, even if they are not
1003
     TREE_PUBLIC, to avoid conflicts between individual files.  */
1004
  tree id;
1005
 
1006
  if (TREE_PUBLIC (decl))
1007
    id = targetm.mangle_decl_assembler_name (decl, DECL_NAME (decl));
1008
  else
1009
    {
1010
      const char *name = IDENTIFIER_POINTER (DECL_NAME (decl));
1011
      char *label;
1012
 
1013
      ASM_FORMAT_PRIVATE_NAME (label, name, DECL_UID (decl));
1014
      id = get_identifier (label);
1015
    }
1016
 
1017
  SET_DECL_ASSEMBLER_NAME (decl, id);
1018
}
1019
 
1020
static tree
1021
lto_pushdecl (tree t ATTRIBUTE_UNUSED)
1022
{
1023
  /* Do nothing, since we get all information from DWARF and LTO
1024
     sections.  */
1025
  return NULL_TREE;
1026
}
1027
 
1028
static tree
1029
lto_getdecls (void)
1030
{
1031
  /* We have our own write_globals langhook, hence the getdecls
1032
     langhook shouldn't be used, except by dbxout.c, so we can't
1033
     just abort here.  */
1034
  return NULL_TREE;
1035
}
1036
 
1037
static void
1038
lto_write_globals (void)
1039
{
1040
  tree *vec = VEC_address (tree, lto_global_var_decls);
1041
  int len = VEC_length (tree, lto_global_var_decls);
1042
  wrapup_global_declarations (vec, len);
1043
  emit_debug_global_declarations (vec, len);
1044
  VEC_free (tree, gc, lto_global_var_decls);
1045
}
1046
 
1047
static tree
1048
lto_builtin_function (tree decl)
1049
{
1050
  return decl;
1051
}
1052
 
1053
static void
1054
lto_register_builtin_type (tree type, const char *name)
1055
{
1056
  tree decl;
1057
 
1058
  decl = build_decl (UNKNOWN_LOCATION, TYPE_DECL, get_identifier (name), type);
1059
  DECL_ARTIFICIAL (decl) = 1;
1060
  if (!TYPE_NAME (type))
1061
    TYPE_NAME (type) = decl;
1062
 
1063
  registered_builtin_types = tree_cons (0, type, registered_builtin_types);
1064
}
1065
 
1066
/* Build nodes that would have be created by the C front-end; necessary
1067
   for including builtin-types.def and ultimately builtins.def.  */
1068
 
1069
static void
1070
lto_build_c_type_nodes (void)
1071
{
1072
  gcc_assert (void_type_node);
1073
 
1074
  void_list_node = build_tree_list (NULL_TREE, void_type_node);
1075
  string_type_node = build_pointer_type (char_type_node);
1076
  const_string_type_node
1077
    = build_pointer_type (build_qualified_type (char_type_node, TYPE_QUAL_CONST));
1078
 
1079
  if (strcmp (SIZE_TYPE, "unsigned int") == 0)
1080
    {
1081
      intmax_type_node = integer_type_node;
1082
      uintmax_type_node = unsigned_type_node;
1083
      signed_size_type_node = integer_type_node;
1084
    }
1085
  else if (strcmp (SIZE_TYPE, "long unsigned int") == 0)
1086
    {
1087
      intmax_type_node = long_integer_type_node;
1088
      uintmax_type_node = long_unsigned_type_node;
1089
      signed_size_type_node = long_integer_type_node;
1090
    }
1091
  else if (strcmp (SIZE_TYPE, "long long unsigned int") == 0)
1092
    {
1093
      intmax_type_node = long_long_integer_type_node;
1094
      uintmax_type_node = long_long_unsigned_type_node;
1095
      signed_size_type_node = long_long_integer_type_node;
1096
    }
1097
  else
1098
    gcc_unreachable ();
1099
 
1100
  wint_type_node = unsigned_type_node;
1101
  pid_type_node = integer_type_node;
1102
}
1103
 
1104
/* Re-compute TYPE_CANONICAL for NODE and related types.  */
1105
 
1106
static void
1107
lto_register_canonical_types (tree node)
1108
{
1109
  if (!node
1110
      || !TYPE_P (node))
1111
    return;
1112
 
1113
  TYPE_CANONICAL (node) = NULL_TREE;
1114
  TYPE_CANONICAL (node) = gimple_register_canonical_type (node);
1115
 
1116
  if (POINTER_TYPE_P (node)
1117
      || TREE_CODE (node) == COMPLEX_TYPE
1118
      || TREE_CODE (node) == ARRAY_TYPE)
1119
    lto_register_canonical_types (TREE_TYPE (node));
1120
}
1121
 
1122
/* Perform LTO-specific initialization.  */
1123
 
1124
static bool
1125
lto_init (void)
1126
{
1127
  unsigned i;
1128
 
1129
  /* We need to generate LTO if running in WPA mode.  */
1130
  flag_generate_lto = flag_wpa;
1131
 
1132
  /* Initialize libcpp line maps for gcc_assert to work.  */
1133
  linemap_add (line_table, LC_ENTER, 0, NULL, 0);
1134
 
1135
  /* Create the basic integer types.  */
1136
  build_common_tree_nodes (flag_signed_char, /*short_double=*/false);
1137
 
1138
  /* The global tree for the main identifier is filled in by
1139
     language-specific front-end initialization that is not run in the
1140
     LTO back-end.  It appears that all languages that perform such
1141
     initialization currently do so in the same way, so we do it here.  */
1142
  if (main_identifier_node == NULL_TREE)
1143
    main_identifier_node = get_identifier ("main");
1144
 
1145
  /* In the C++ front-end, fileptr_type_node is defined as a variant
1146
     copy of of ptr_type_node, rather than ptr_node itself.  The
1147
     distinction should only be relevant to the front-end, so we
1148
     always use the C definition here in lto1.  */
1149
  gcc_assert (fileptr_type_node == ptr_type_node);
1150
  gcc_assert (TYPE_MAIN_VARIANT (fileptr_type_node) == ptr_type_node);
1151
 
1152
  ptrdiff_type_node = integer_type_node;
1153
 
1154
  lto_build_c_type_nodes ();
1155
  gcc_assert (va_list_type_node);
1156
 
1157
  if (TREE_CODE (va_list_type_node) == ARRAY_TYPE)
1158
    {
1159
      tree x = build_pointer_type (TREE_TYPE (va_list_type_node));
1160
      lto_define_builtins (x, x);
1161
    }
1162
  else
1163
    {
1164
      lto_define_builtins (va_list_type_node,
1165
                           build_reference_type (va_list_type_node));
1166
    }
1167
 
1168
  targetm.init_builtins ();
1169
  build_common_builtin_nodes ();
1170
 
1171
  /* Assign names to the builtin types, otherwise they'll end up
1172
     as __unknown__ in debug info.
1173
     ???  We simply need to stop pre-seeding the streamer cache.
1174
     Below is modeled after from c-common.c:c_common_nodes_and_builtins  */
1175
#define NAME_TYPE(t,n) \
1176
  if (t) \
1177
    TYPE_NAME (t) = build_decl (UNKNOWN_LOCATION, TYPE_DECL, \
1178
                                get_identifier (n), t)
1179
  NAME_TYPE (integer_type_node, "int");
1180
  NAME_TYPE (char_type_node, "char");
1181
  NAME_TYPE (long_integer_type_node, "long int");
1182
  NAME_TYPE (unsigned_type_node, "unsigned int");
1183
  NAME_TYPE (long_unsigned_type_node, "long unsigned int");
1184
  NAME_TYPE (long_long_integer_type_node, "long long int");
1185
  NAME_TYPE (long_long_unsigned_type_node, "long long unsigned int");
1186
  NAME_TYPE (short_integer_type_node, "short int");
1187
  NAME_TYPE (short_unsigned_type_node, "short unsigned int");
1188
  if (signed_char_type_node != char_type_node)
1189
    NAME_TYPE (signed_char_type_node, "signed char");
1190
  if (unsigned_char_type_node != char_type_node)
1191
    NAME_TYPE (unsigned_char_type_node, "unsigned char");
1192
  NAME_TYPE (float_type_node, "float");
1193
  NAME_TYPE (double_type_node, "double");
1194
  NAME_TYPE (long_double_type_node, "long double");
1195
  NAME_TYPE (void_type_node, "void");
1196
  NAME_TYPE (boolean_type_node, "bool");
1197
#undef NAME_TYPE
1198
 
1199
  /* Register the common node types with the canonical type machinery so
1200
     we properly share alias-sets across languages and TUs.  Do not
1201
     expose the common nodes as type merge target - those that should be
1202
     are already exposed so by pre-loading the LTO streamer caches.  */
1203
  for (i = 0; i < itk_none; ++i)
1204
    lto_register_canonical_types (integer_types[i]);
1205
  /* The sizetypes are not used to access data so we do not need to
1206
     do anything about them.  */
1207
  for (i = 0; i < TI_MAX; ++i)
1208
    lto_register_canonical_types (global_trees[i]);
1209
 
1210
  /* Initialize LTO-specific data structures.  */
1211
  lto_global_var_decls = VEC_alloc (tree, gc, 256);
1212
  in_lto_p = true;
1213
 
1214
  return true;
1215
}
1216
 
1217
/* Initialize tree structures required by the LTO front end.  */
1218
 
1219
static void lto_init_ts (void)
1220
{
1221
  tree_contains_struct[NAMESPACE_DECL][TS_DECL_MINIMAL] = 1;
1222
}
1223
 
1224
#undef LANG_HOOKS_NAME
1225
#define LANG_HOOKS_NAME "GNU GIMPLE"
1226
#undef LANG_HOOKS_OPTION_LANG_MASK
1227
#define LANG_HOOKS_OPTION_LANG_MASK lto_option_lang_mask
1228
#undef LANG_HOOKS_COMPLAIN_WRONG_LANG_P
1229
#define LANG_HOOKS_COMPLAIN_WRONG_LANG_P lto_complain_wrong_lang_p
1230
#undef LANG_HOOKS_INIT_OPTIONS_STRUCT
1231
#define LANG_HOOKS_INIT_OPTIONS_STRUCT lto_init_options_struct
1232
#undef LANG_HOOKS_HANDLE_OPTION
1233
#define LANG_HOOKS_HANDLE_OPTION lto_handle_option
1234
#undef LANG_HOOKS_POST_OPTIONS
1235
#define LANG_HOOKS_POST_OPTIONS lto_post_options
1236
#undef LANG_HOOKS_GET_ALIAS_SET
1237
#define LANG_HOOKS_GET_ALIAS_SET gimple_get_alias_set
1238
#undef LANG_HOOKS_TYPE_FOR_MODE
1239
#define LANG_HOOKS_TYPE_FOR_MODE lto_type_for_mode
1240
#undef LANG_HOOKS_TYPE_FOR_SIZE
1241
#define LANG_HOOKS_TYPE_FOR_SIZE lto_type_for_size
1242
#undef LANG_HOOKS_SET_DECL_ASSEMBLER_NAME
1243
#define LANG_HOOKS_SET_DECL_ASSEMBLER_NAME lto_set_decl_assembler_name
1244
#undef LANG_HOOKS_GLOBAL_BINDINGS_P
1245
#define LANG_HOOKS_GLOBAL_BINDINGS_P lto_global_bindings_p
1246
#undef LANG_HOOKS_PUSHDECL
1247
#define LANG_HOOKS_PUSHDECL lto_pushdecl
1248
#undef LANG_HOOKS_GETDECLS
1249
#define LANG_HOOKS_GETDECLS lto_getdecls
1250
#undef LANG_HOOKS_WRITE_GLOBALS
1251
#define LANG_HOOKS_WRITE_GLOBALS lto_write_globals
1252
#undef LANG_HOOKS_REGISTER_BUILTIN_TYPE
1253
#define LANG_HOOKS_REGISTER_BUILTIN_TYPE lto_register_builtin_type
1254
#undef LANG_HOOKS_BUILTIN_FUNCTION
1255
#define LANG_HOOKS_BUILTIN_FUNCTION lto_builtin_function
1256
#undef LANG_HOOKS_INIT
1257
#define LANG_HOOKS_INIT lto_init
1258
#undef LANG_HOOKS_PARSE_FILE
1259
#define LANG_HOOKS_PARSE_FILE lto_main
1260
#undef LANG_HOOKS_CALLGRAPH_EXPAND_FUNCTION
1261
#define LANG_HOOKS_CALLGRAPH_EXPAND_FUNCTION tree_rest_of_compilation
1262
#undef LANG_HOOKS_REDUCE_BIT_FIELD_OPERATIONS
1263
#define LANG_HOOKS_REDUCE_BIT_FIELD_OPERATIONS true
1264
#undef LANG_HOOKS_TYPES_COMPATIBLE_P
1265
#define LANG_HOOKS_TYPES_COMPATIBLE_P NULL
1266
#undef LANG_HOOKS_EH_PERSONALITY
1267
#define LANG_HOOKS_EH_PERSONALITY lto_eh_personality
1268
 
1269
/* Attribute hooks.  */
1270
#undef LANG_HOOKS_COMMON_ATTRIBUTE_TABLE
1271
#define LANG_HOOKS_COMMON_ATTRIBUTE_TABLE lto_attribute_table
1272
#undef LANG_HOOKS_FORMAT_ATTRIBUTE_TABLE
1273
#define LANG_HOOKS_FORMAT_ATTRIBUTE_TABLE lto_format_attribute_table
1274
 
1275
#undef LANG_HOOKS_BEGIN_SECTION
1276
#define LANG_HOOKS_BEGIN_SECTION lto_obj_begin_section
1277
#undef LANG_HOOKS_APPEND_DATA
1278
#define LANG_HOOKS_APPEND_DATA lto_obj_append_data
1279
#undef LANG_HOOKS_END_SECTION
1280
#define LANG_HOOKS_END_SECTION lto_obj_end_section
1281
 
1282
#undef LANG_HOOKS_INIT_TS
1283
#define LANG_HOOKS_INIT_TS lto_init_ts
1284
 
1285
struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
1286
 
1287
/* Language hooks that are not part of lang_hooks.  */
1288
 
1289
tree
1290
convert (tree type ATTRIBUTE_UNUSED, tree expr ATTRIBUTE_UNUSED)
1291
{
1292
  gcc_unreachable ();
1293
}
1294
 
1295
/* Tree walking support.  */
1296
 
1297
static enum lto_tree_node_structure_enum
1298
lto_tree_node_structure (union lang_tree_node *t ATTRIBUTE_UNUSED)
1299
{
1300
  return TS_LTO_GENERIC;
1301
}
1302
 
1303
#include "ggc.h"
1304
#include "gtype-lto.h"
1305
#include "gt-lto-lto-lang.h"

powered by: WebSVN 2.1.0

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