OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.5.1/] [gcc/] [lto-symtab.c] - Blame information for rev 318

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

Line No. Rev Author Line
1 280 jeremybenn
/* LTO symbol table.
2
   Copyright 2009 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 "toplev.h"
25
#include "tree.h"
26
#include "gimple.h"
27
#include "ggc.h"        /* lambda.h needs this */
28
#include "lambda.h"     /* gcd */
29
#include "hashtab.h"
30
#include "plugin-api.h"
31
#include "lto-streamer.h"
32
 
33
/* Vector to keep track of external variables we've seen so far.  */
34
VEC(tree,gc) *lto_global_var_decls;
35
 
36
/* Symbol table entry.  */
37
 
38
struct GTY(()) lto_symtab_entry_def
39
{
40
  /* The symbol table entry key, an IDENTIFIER.  */
41
  tree id;
42
  /* The symbol table entry, a DECL.  */
43
  tree decl;
44
  /* The cgraph node if decl is a function decl.  Filled in during the
45
     merging process.  */
46
  struct cgraph_node *node;
47
  /* LTO file-data and symbol resolution for this decl.  */
48
  struct lto_file_decl_data * GTY((skip (""))) file_data;
49
  enum ld_plugin_symbol_resolution resolution;
50
  /* Pointer to the next entry with the same key.  Before decl merging
51
     this links all symbols from the different TUs.  After decl merging
52
     this links merged but incompatible decls, thus all prevailing ones
53
     remaining.  */
54
  struct lto_symtab_entry_def *next;
55
};
56
typedef struct lto_symtab_entry_def *lto_symtab_entry_t;
57
 
58
/* A poor man's symbol table. This hashes identifier to prevailing DECL
59
   if there is one. */
60
 
61
static GTY ((if_marked ("lto_symtab_entry_marked_p"),
62
             param_is (struct lto_symtab_entry_def)))
63
  htab_t lto_symtab_identifiers;
64
 
65
/* Return the hash value of an lto_symtab_entry_t object pointed to by P.  */
66
 
67
static hashval_t
68
lto_symtab_entry_hash (const void *p)
69
{
70
  const struct lto_symtab_entry_def *base =
71
    (const struct lto_symtab_entry_def *) p;
72
  return htab_hash_string (IDENTIFIER_POINTER (base->id));
73
}
74
 
75
/* Return non-zero if P1 and P2 points to lto_symtab_entry_def structs
76
   corresponding to the same symbol.  */
77
 
78
static int
79
lto_symtab_entry_eq (const void *p1, const void *p2)
80
{
81
  const struct lto_symtab_entry_def *base1 =
82
     (const struct lto_symtab_entry_def *) p1;
83
  const struct lto_symtab_entry_def *base2 =
84
     (const struct lto_symtab_entry_def *) p2;
85
  return (base1->id == base2->id);
86
}
87
 
88
/* Returns non-zero if P points to an lto_symtab_entry_def struct that needs
89
   to be marked for GC.  */
90
 
91
static int
92
lto_symtab_entry_marked_p (const void *p)
93
{
94
  const struct lto_symtab_entry_def *base =
95
     (const struct lto_symtab_entry_def *) p;
96
 
97
  /* Keep this only if the common IDENTIFIER_NODE of the symtab chain
98
     is marked which it will be if at least one of the DECLs in the
99
     chain is marked.  */
100
  return ggc_marked_p (base->id);
101
}
102
 
103
/* Lazily initialize resolution hash tables.  */
104
 
105
static void
106
lto_symtab_maybe_init_hash_table (void)
107
{
108
  if (lto_symtab_identifiers)
109
    return;
110
 
111
  lto_symtab_identifiers =
112
    htab_create_ggc (1021, lto_symtab_entry_hash,
113
                     lto_symtab_entry_eq, NULL);
114
}
115
 
116
/* Registers DECL with the LTO symbol table as having resolution RESOLUTION
117
   and read from FILE_DATA. */
118
 
119
void
120
lto_symtab_register_decl (tree decl,
121
                          ld_plugin_symbol_resolution_t resolution,
122
                          struct lto_file_decl_data *file_data)
123
{
124
  lto_symtab_entry_t new_entry;
125
  void **slot;
126
 
127
  /* Check that declarations reaching this function do not have
128
     properties inconsistent with having external linkage.  If any of
129
     these asertions fail, then the object file reader has failed to
130
     detect these cases and issue appropriate error messages.  */
131
  gcc_assert (decl
132
              && TREE_PUBLIC (decl)
133
              && (TREE_CODE (decl) == VAR_DECL
134
                  || TREE_CODE (decl) == FUNCTION_DECL)
135
              && DECL_ASSEMBLER_NAME_SET_P (decl));
136
  if (TREE_CODE (decl) == VAR_DECL
137
      && DECL_INITIAL (decl))
138
    gcc_assert (!DECL_EXTERNAL (decl)
139
                || (TREE_STATIC (decl) && TREE_READONLY (decl)));
140
  if (TREE_CODE (decl) == FUNCTION_DECL)
141
    gcc_assert (!DECL_ABSTRACT (decl));
142
 
143
  new_entry = GGC_CNEW (struct lto_symtab_entry_def);
144
  new_entry->id = DECL_ASSEMBLER_NAME (decl);
145
  new_entry->decl = decl;
146
  new_entry->resolution = resolution;
147
  new_entry->file_data = file_data;
148
 
149
  lto_symtab_maybe_init_hash_table ();
150
  slot = htab_find_slot (lto_symtab_identifiers, new_entry, INSERT);
151
  new_entry->next = (lto_symtab_entry_t) *slot;
152
  *slot = new_entry;
153
}
154
 
155
/* Get the lto_symtab_entry_def struct associated with ID
156
   if there is one.  */
157
 
158
static lto_symtab_entry_t
159
lto_symtab_get (tree id)
160
{
161
  struct lto_symtab_entry_def temp;
162
  void **slot;
163
 
164
  lto_symtab_maybe_init_hash_table ();
165
  temp.id = id;
166
  slot = htab_find_slot (lto_symtab_identifiers, &temp, NO_INSERT);
167
  return slot ? (lto_symtab_entry_t) *slot : NULL;
168
}
169
 
170
/* Get the linker resolution for DECL.  */
171
 
172
enum ld_plugin_symbol_resolution
173
lto_symtab_get_resolution (tree decl)
174
{
175
  lto_symtab_entry_t e;
176
 
177
  gcc_assert (DECL_ASSEMBLER_NAME_SET_P (decl));
178
 
179
  e = lto_symtab_get (DECL_ASSEMBLER_NAME (decl));
180
  while (e && e->decl != decl)
181
    e = e->next;
182
  if (!e)
183
    return LDPR_UNKNOWN;
184
 
185
  return e->resolution;
186
}
187
 
188
 
189
/* Replace the cgraph node NODE with PREVAILING_NODE in the cgraph, merging
190
   all edges and removing the old node.  */
191
 
192
static void
193
lto_cgraph_replace_node (struct cgraph_node *node,
194
                         struct cgraph_node *prevailing_node)
195
{
196
  struct cgraph_edge *e, *next;
197
 
198
  /* Merge node flags.  */
199
  if (node->needed)
200
    cgraph_mark_needed_node (prevailing_node);
201
  if (node->reachable)
202
    cgraph_mark_reachable_node (prevailing_node);
203
  if (node->address_taken)
204
    {
205
      gcc_assert (!prevailing_node->global.inlined_to);
206
      cgraph_mark_address_taken_node (prevailing_node);
207
    }
208
 
209
  /* Redirect all incoming edges.  */
210
  for (e = node->callers; e; e = next)
211
    {
212
      next = e->next_caller;
213
      cgraph_redirect_edge_callee (e, prevailing_node);
214
    }
215
 
216
  /* There are not supposed to be any outgoing edges from a node we
217
     replace.  Still this can happen for multiple instances of weak
218
     functions.  */
219
  for (e = node->callees; e; e = next)
220
    {
221
      next = e->next_callee;
222
      cgraph_remove_edge (e);
223
    }
224
 
225
  if (node->same_body)
226
    {
227
      struct cgraph_node *alias;
228
 
229
      for (alias = node->same_body; alias; alias = alias->next)
230
        if (DECL_ASSEMBLER_NAME_SET_P (alias->decl))
231
          {
232
            lto_symtab_entry_t se
233
              = lto_symtab_get (DECL_ASSEMBLER_NAME (alias->decl));
234
 
235
            for (; se; se = se->next)
236
              if (se->node == node)
237
                {
238
                  se->node = NULL;
239
                  break;
240
                }
241
          }
242
    }
243
 
244
  /* Finally remove the replaced node.  */
245
  cgraph_remove_node (node);
246
}
247
 
248
/* Merge two variable or function symbol table entries PREVAILING and ENTRY.
249
   Return false if the symbols are not fully compatible and a diagnostic
250
   should be emitted.  */
251
 
252
static bool
253
lto_symtab_merge (lto_symtab_entry_t prevailing, lto_symtab_entry_t entry)
254
{
255
  tree prevailing_decl = prevailing->decl;
256
  tree decl = entry->decl;
257
  tree prevailing_type, type;
258
 
259
  /* Merge decl state in both directions, we may still end up using
260
     the new decl.  */
261
  TREE_ADDRESSABLE (prevailing_decl) |= TREE_ADDRESSABLE (decl);
262
  TREE_ADDRESSABLE (decl) |= TREE_ADDRESSABLE (prevailing_decl);
263
 
264
  /* The linker may ask us to combine two incompatible symbols.
265
     Detect this case and notify the caller of required diagnostics.  */
266
 
267
  if (TREE_CODE (decl) == FUNCTION_DECL)
268
    {
269
      if (TREE_TYPE (prevailing_decl) != TREE_TYPE (decl))
270
        /* If we don't have a merged type yet...sigh.  The linker
271
           wouldn't complain if the types were mismatched, so we
272
           probably shouldn't either.  Just use the type from
273
           whichever decl appears to be associated with the
274
           definition.  If for some odd reason neither decl is, the
275
           older one wins.  */
276
        (void) 0;
277
 
278
      return true;
279
    }
280
 
281
  /* Now we exclusively deal with VAR_DECLs.  */
282
 
283
  /* Sharing a global symbol is a strong hint that two types are
284
     compatible.  We could use this information to complete
285
     incomplete pointed-to types more aggressively here, ignoring
286
     mismatches in both field and tag names.  It's difficult though
287
     to guarantee that this does not have side-effects on merging
288
     more compatible types from other translation units though.  */
289
 
290
  /* We can tolerate differences in type qualification, the
291
     qualification of the prevailing definition will prevail.
292
     ???  In principle we might want to only warn for structurally
293
     incompatible types here, but unless we have protective measures
294
     for TBAA in place that would hide useful information.  */
295
  prevailing_type = TYPE_MAIN_VARIANT (TREE_TYPE (prevailing_decl));
296
  type = TYPE_MAIN_VARIANT (TREE_TYPE (decl));
297
 
298
  /* We have to register and fetch canonical types here as the global
299
     fixup process didn't yet run.  */
300
  prevailing_type = gimple_register_type (prevailing_type);
301
  type = gimple_register_type (type);
302
  if (prevailing_type != type)
303
    {
304
      if (COMPLETE_TYPE_P (type))
305
        return false;
306
 
307
      /* If type is incomplete then avoid warnings in the cases
308
         that TBAA handles just fine.  */
309
 
310
      if (TREE_CODE (prevailing_type) != TREE_CODE (type))
311
        return false;
312
 
313
      if (TREE_CODE (prevailing_type) == ARRAY_TYPE)
314
        {
315
          tree tem1 = TREE_TYPE (prevailing_type);
316
          tree tem2 = TREE_TYPE (type);
317
          while (TREE_CODE (tem1) == ARRAY_TYPE
318
                 && TREE_CODE (tem2) == ARRAY_TYPE)
319
            {
320
              tem1 = TREE_TYPE (tem1);
321
              tem2 = TREE_TYPE (tem2);
322
            }
323
 
324
          if (TREE_CODE (tem1) != TREE_CODE (tem2))
325
            return false;
326
 
327
          if (gimple_register_type (tem1) != gimple_register_type (tem2))
328
            return false;
329
        }
330
 
331
      /* Fallthru.  Compatible enough.  */
332
    }
333
 
334
  /* ???  We might want to emit a warning here if type qualification
335
     differences were spotted.  Do not do this unconditionally though.  */
336
 
337
  /* There is no point in comparing too many details of the decls here.
338
     The type compatibility checks or the completing of types has properly
339
     dealt with most issues.  */
340
 
341
  /* The following should all not invoke fatal errors as in non-LTO
342
     mode the linker wouldn't complain either.  Just emit warnings.  */
343
 
344
  /* Report a warning if user-specified alignments do not match.  */
345
  if ((DECL_USER_ALIGN (prevailing_decl) && DECL_USER_ALIGN (decl))
346
      && DECL_ALIGN (prevailing_decl) < DECL_ALIGN (decl))
347
    return false;
348
 
349
  return true;
350
}
351
 
352
/* Return true if the symtab entry E can be replaced by another symtab
353
   entry.  */
354
 
355
static bool
356
lto_symtab_resolve_replaceable_p (lto_symtab_entry_t e)
357
{
358
  if (DECL_EXTERNAL (e->decl)
359
      || DECL_COMDAT (e->decl)
360
      || DECL_WEAK (e->decl))
361
    return true;
362
 
363
  if (TREE_CODE (e->decl) == VAR_DECL)
364
    return (DECL_COMMON (e->decl)
365
            || (!flag_no_common && !DECL_INITIAL (e->decl)));
366
 
367
  return false;
368
}
369
 
370
/* Return true if the symtab entry E can be the prevailing one.  */
371
 
372
static bool
373
lto_symtab_resolve_can_prevail_p (lto_symtab_entry_t e)
374
{
375
  /* The C++ frontend ends up neither setting TREE_STATIC nor
376
     DECL_EXTERNAL on virtual methods but only TREE_PUBLIC.
377
     So do not reject !TREE_STATIC here but only DECL_EXTERNAL.  */
378
  if (DECL_EXTERNAL (e->decl))
379
    return false;
380
 
381
  /* For functions we need a non-discarded body.  */
382
  if (TREE_CODE (e->decl) == FUNCTION_DECL)
383
    return (e->node && e->node->analyzed);
384
 
385
  /* A variable should have a size.  */
386
  else if (TREE_CODE (e->decl) == VAR_DECL)
387
    return (DECL_SIZE (e->decl) != NULL_TREE
388
            /* The C++ frontend retains TREE_STATIC on the declaration
389
               of foo_ in struct Foo { static Foo *foo_; }; but it is
390
               not a definition.  g++.dg/lto/20090315_0.C.  */
391
            && !DECL_EXTERNAL (e->decl));
392
 
393
  gcc_unreachable ();
394
}
395
 
396
/* Resolve the symbol with the candidates in the chain *SLOT and store
397
   their resolutions.  */
398
 
399
static void
400
lto_symtab_resolve_symbols (void **slot)
401
{
402
  lto_symtab_entry_t e;
403
  lto_symtab_entry_t prevailing = NULL;
404
 
405
  /* Always set e->node so that edges are updated to reflect decl merging. */
406
  for (e = (lto_symtab_entry_t) *slot; e; e = e->next)
407
    {
408
      if (TREE_CODE (e->decl) == FUNCTION_DECL)
409
        e->node = cgraph_get_node (e->decl);
410
      else if (TREE_CODE (e->decl) == VAR_DECL)
411
        {
412
          /* The LTO plugin for gold doesn't handle common symbols
413
             properly.  Let us choose manually.  */
414
          if (DECL_COMMON (e->decl))
415
            e->resolution = LDPR_UNKNOWN;
416
        }
417
    }
418
 
419
  e = (lto_symtab_entry_t) *slot;
420
 
421
  /* If the chain is already resolved there is nothing else to do.  */
422
  if (e->resolution != LDPR_UNKNOWN)
423
    return;
424
 
425
  /* Find the single non-replaceable prevailing symbol and
426
     diagnose ODR violations.  */
427
  for (e = (lto_symtab_entry_t) *slot; e; e = e->next)
428
    {
429
      if (!lto_symtab_resolve_can_prevail_p (e))
430
        {
431
          e->resolution = LDPR_RESOLVED_IR;
432
          continue;
433
        }
434
 
435
      /* Set a default resolution - the final prevailing one will get
436
         adjusted later.  */
437
      e->resolution = LDPR_PREEMPTED_IR;
438
      if (!lto_symtab_resolve_replaceable_p (e))
439
        {
440
          if (prevailing)
441
            {
442
              error_at (DECL_SOURCE_LOCATION (e->decl),
443
                        "%qD has already been defined", e->decl);
444
              inform (DECL_SOURCE_LOCATION (prevailing->decl),
445
                      "previously defined here");
446
            }
447
          prevailing = e;
448
        }
449
    }
450
  if (prevailing)
451
    goto found;
452
 
453
  /* Do a second round choosing one from the replaceable prevailing decls.  */
454
  for (e = (lto_symtab_entry_t) *slot; e; e = e->next)
455
    {
456
      if (e->resolution != LDPR_PREEMPTED_IR)
457
        continue;
458
 
459
      /* Choose the first function that can prevail as prevailing.  */
460
      if (TREE_CODE (e->decl) == FUNCTION_DECL)
461
        {
462
          prevailing = e;
463
          break;
464
        }
465
 
466
      /* From variables that can prevail choose the largest one.  */
467
      if (!prevailing
468
          || tree_int_cst_lt (DECL_SIZE (prevailing->decl),
469
                              DECL_SIZE (e->decl)))
470
        prevailing = e;
471
    }
472
 
473
  if (!prevailing)
474
    return;
475
 
476
found:
477
  if (TREE_CODE (prevailing->decl) == VAR_DECL
478
      && TREE_READONLY (prevailing->decl))
479
    prevailing->resolution = LDPR_PREVAILING_DEF_IRONLY;
480
  else
481
    prevailing->resolution = LDPR_PREVAILING_DEF;
482
}
483
 
484
/* Merge all decls in the symbol table chain to the prevailing decl and
485
   issue diagnostics about type mismatches.  */
486
 
487
static void
488
lto_symtab_merge_decls_2 (void **slot)
489
{
490
  lto_symtab_entry_t prevailing, e;
491
  VEC(tree, heap) *mismatches = NULL;
492
  unsigned i;
493
  tree decl;
494
  bool diagnosed_p = false;
495
 
496
  /* Nothing to do for a single entry.  */
497
  prevailing = (lto_symtab_entry_t) *slot;
498
  if (!prevailing->next)
499
    return;
500
 
501
  /* Try to merge each entry with the prevailing one.  */
502
  for (e = prevailing->next; e; e = e->next)
503
    {
504
      if (!lto_symtab_merge (prevailing, e))
505
        VEC_safe_push (tree, heap, mismatches, e->decl);
506
    }
507
  if (VEC_empty (tree, mismatches))
508
    return;
509
 
510
  /* Diagnose all mismatched re-declarations.  */
511
  for (i = 0; VEC_iterate (tree, mismatches, i, decl); ++i)
512
    {
513
      if (TREE_TYPE (prevailing->decl) != TREE_TYPE (decl))
514
        diagnosed_p |= warning_at (DECL_SOURCE_LOCATION (decl), 0,
515
                                   "type of %qD does not match original "
516
                                   "declaration", decl);
517
 
518
      else if ((DECL_USER_ALIGN (prevailing->decl) && DECL_USER_ALIGN (decl))
519
               && DECL_ALIGN (prevailing->decl) < DECL_ALIGN (decl))
520
        {
521
          diagnosed_p |= warning_at (DECL_SOURCE_LOCATION (decl), 0,
522
                                     "alignment of %qD is bigger than "
523
                                     "original declaration", decl);
524
        }
525
    }
526
  if (diagnosed_p)
527
    inform (DECL_SOURCE_LOCATION (prevailing->decl),
528
            "previously declared here");
529
 
530
  VEC_free (tree, heap, mismatches);
531
}
532
 
533
/* Helper to process the decl chain for the symbol table entry *SLOT.  */
534
 
535
static int
536
lto_symtab_merge_decls_1 (void **slot, void *data ATTRIBUTE_UNUSED)
537
{
538
  lto_symtab_entry_t e, prevailing;
539
  bool diagnosed_p = false;
540
 
541
  /* Compute the symbol resolutions.  This is a no-op when using the
542
     linker plugin.  */
543
  lto_symtab_resolve_symbols (slot);
544
 
545
  /* Find the prevailing decl.  */
546
  for (prevailing = (lto_symtab_entry_t) *slot;
547
       prevailing
548
       && prevailing->resolution != LDPR_PREVAILING_DEF_IRONLY
549
       && prevailing->resolution != LDPR_PREVAILING_DEF;
550
       prevailing = prevailing->next)
551
    ;
552
 
553
  /* Assert it's the only one.  */
554
  if (prevailing)
555
    for (e = prevailing->next; e; e = e->next)
556
      gcc_assert (e->resolution != LDPR_PREVAILING_DEF_IRONLY
557
                  && e->resolution != LDPR_PREVAILING_DEF);
558
 
559
  /* If there's not a prevailing symbol yet it's an external reference.
560
     Happens a lot during ltrans.  Choose the first symbol with a
561
     cgraph or a varpool node.  */
562
  if (!prevailing)
563
    {
564
      prevailing = (lto_symtab_entry_t) *slot;
565
      /* For functions choose one with a cgraph node.  */
566
      if (TREE_CODE (prevailing->decl) == FUNCTION_DECL)
567
        while (!prevailing->node
568
               && prevailing->next)
569
          prevailing = prevailing->next;
570
      /* We do not stream varpool nodes, so the first decl has to
571
         be good enough for now.
572
         ???  For QOI choose a variable with readonly initializer
573
         if there is one.  This matches C++
574
         struct Foo { static const int i = 1; }; without a real
575
         definition.  */
576
      if (TREE_CODE (prevailing->decl) == VAR_DECL)
577
        while (!(TREE_READONLY (prevailing->decl)
578
                 && DECL_INITIAL (prevailing->decl))
579
               && prevailing->next)
580
          prevailing = prevailing->next;
581
    }
582
 
583
  /* Move it first in the list.  */
584
  if ((lto_symtab_entry_t) *slot != prevailing)
585
    {
586
      for (e = (lto_symtab_entry_t) *slot; e->next != prevailing; e = e->next)
587
        ;
588
      e->next = prevailing->next;
589
      prevailing->next = (lto_symtab_entry_t) *slot;
590
      *slot = (void *) prevailing;
591
    }
592
 
593
  /* Record the prevailing variable.  */
594
  if (TREE_CODE (prevailing->decl) == VAR_DECL)
595
    VEC_safe_push (tree, gc, lto_global_var_decls, prevailing->decl);
596
 
597
  /* Diagnose mismatched objects.  */
598
  for (e = prevailing->next; e; e = e->next)
599
    {
600
      if (TREE_CODE (prevailing->decl) == TREE_CODE (e->decl))
601
        continue;
602
 
603
      switch (TREE_CODE (prevailing->decl))
604
        {
605
        case VAR_DECL:
606
          gcc_assert (TREE_CODE (e->decl) == FUNCTION_DECL);
607
          error_at (DECL_SOURCE_LOCATION (e->decl),
608
                    "variable %qD redeclared as function", prevailing->decl);
609
          break;
610
 
611
        case FUNCTION_DECL:
612
          gcc_assert (TREE_CODE (e->decl) == VAR_DECL);
613
          error_at (DECL_SOURCE_LOCATION (e->decl),
614
                    "function %qD redeclared as variable", prevailing->decl);
615
          break;
616
 
617
        default:
618
          gcc_unreachable ();
619
        }
620
 
621
      diagnosed_p = true;
622
    }
623
  if (diagnosed_p)
624
      inform (DECL_SOURCE_LOCATION (prevailing->decl),
625
              "previously declared here");
626
 
627
  /* Register and adjust types of the entries.  */
628
  for (e = (lto_symtab_entry_t) *slot; e; e = e->next)
629
    TREE_TYPE (e->decl) = gimple_register_type (TREE_TYPE (e->decl));
630
 
631
  /* Merge the chain to the single prevailing decl and diagnose
632
     mismatches.  */
633
  lto_symtab_merge_decls_2 (slot);
634
 
635
  /* Drop all but the prevailing decl from the symtab.  */
636
  if (TREE_CODE (prevailing->decl) != FUNCTION_DECL)
637
    prevailing->next = NULL;
638
 
639
  return 1;
640
}
641
 
642
/* Resolve and merge all symbol table chains to a prevailing decl.  */
643
 
644
void
645
lto_symtab_merge_decls (void)
646
{
647
  lto_symtab_maybe_init_hash_table ();
648
  htab_traverse (lto_symtab_identifiers, lto_symtab_merge_decls_1, NULL);
649
}
650
 
651
/* Helper to process the decl chain for the symbol table entry *SLOT.  */
652
 
653
static int
654
lto_symtab_merge_cgraph_nodes_1 (void **slot, void *data ATTRIBUTE_UNUSED)
655
{
656
  lto_symtab_entry_t e, prevailing = (lto_symtab_entry_t) *slot;
657
 
658
  if (!prevailing->next)
659
    return 1;
660
 
661
  gcc_assert (TREE_CODE (prevailing->decl) == FUNCTION_DECL);
662
 
663
  /* Replace the cgraph node of each entry with the prevailing one.  */
664
  for (e = prevailing->next; e; e = e->next)
665
    {
666
      if (e->node != NULL)
667
        {
668
          if (e->node->decl != e->decl && e->node->same_body)
669
            {
670
              struct cgraph_node *alias;
671
 
672
              for (alias = e->node->same_body; alias; alias = alias->next)
673
                if (alias->decl == e->decl)
674
                  break;
675
              if (alias)
676
                {
677
                  cgraph_remove_same_body_alias (alias);
678
                  continue;
679
                }
680
            }
681
          lto_cgraph_replace_node (e->node, prevailing->node);
682
        }
683
    }
684
 
685
  /* Drop all but the prevailing decl from the symtab.  */
686
  prevailing->next = NULL;
687
 
688
  return 1;
689
}
690
 
691
/* Merge cgraph nodes according to the symbol merging done by
692
   lto_symtab_merge_decls.  */
693
 
694
void
695
lto_symtab_merge_cgraph_nodes (void)
696
{
697
  lto_symtab_maybe_init_hash_table ();
698
  htab_traverse (lto_symtab_identifiers, lto_symtab_merge_cgraph_nodes_1, NULL);
699
}
700
 
701
/* Given the decl DECL, return the prevailing decl with the same name. */
702
 
703
tree
704
lto_symtab_prevailing_decl (tree decl)
705
{
706
  lto_symtab_entry_t ret;
707
 
708
  /* Builtins and local symbols are their own prevailing decl.  */
709
  if (!TREE_PUBLIC (decl) || is_builtin_fn (decl))
710
    return decl;
711
 
712
  /* DECL_ABSTRACTs are their own prevailng decl.  */
713
  if (TREE_CODE (decl) == FUNCTION_DECL && DECL_ABSTRACT (decl))
714
    return decl;
715
 
716
  /* Ensure DECL_ASSEMBLER_NAME will not set assembler name.  */
717
  gcc_assert (DECL_ASSEMBLER_NAME_SET_P (decl));
718
 
719
  /* Walk through the list of candidates and return the one we merged to.  */
720
  ret = lto_symtab_get (DECL_ASSEMBLER_NAME (decl));
721
  if (!ret)
722
    return NULL_TREE;
723
 
724
  return ret->decl;
725
}
726
 
727
#include "gt-lto-symtab.h"

powered by: WebSVN 2.1.0

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