]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/symtab.c
cgraph.h (symtab_node_base): Add next and previous pointers.
[thirdparty/gcc.git] / gcc / symtab.c
1 /* Symbol table.
2 Copyright (C) 2012 Free Software Foundation, Inc.
3 Contributed by Jan Hubicka
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 "tm.h"
25 #include "tree.h"
26 #include "tree-inline.h"
27 #include "hashtab.h"
28 #include "cgraph.h"
29
30 /* Linked list of symbol table nodes. */
31 symtab_node symtab_nodes;
32
33 /* The order index of the next symtab node to be created. This is
34 used so that we can sort the cgraph nodes in order by when we saw
35 them, to support -fno-toplevel-reorder. */
36 int symtab_order;
37
38 /* Add node into symbol table. This function is not used directly, but via
39 cgraph/varpool node creation routines. */
40
41 void
42 symtab_register_node (symtab_node node)
43 {
44 node->symbol.next = symtab_nodes;
45 node->symbol.previous = NULL;
46 if (symtab_nodes)
47 symtab_nodes->symbol.previous = node;
48 symtab_nodes = node;
49
50 node->symbol.order = symtab_order++;
51
52 ipa_empty_ref_list (&node->symbol.ref_list);
53 }
54
55 /* Remove node from symbol table. This function is not used directly, but via
56 cgraph/varpool node removal routines. */
57
58 void
59 symtab_unregister_node (symtab_node node)
60 {
61 ipa_remove_all_references (&node->symbol.ref_list);
62 ipa_remove_all_refering (&node->symbol.ref_list);
63
64 if (node->symbol.same_comdat_group)
65 {
66 symtab_node prev;
67 for (prev = node->symbol.same_comdat_group;
68 prev->symbol.same_comdat_group != node;
69 prev = prev->symbol.same_comdat_group)
70 ;
71 if (node->symbol.same_comdat_group == prev)
72 prev->symbol.same_comdat_group = NULL;
73 else
74 prev->symbol.same_comdat_group = node->symbol.same_comdat_group;
75 node->symbol.same_comdat_group = NULL;
76 }
77
78 if (node->symbol.previous)
79 node->symbol.previous->symbol.next = node->symbol.next;
80 else
81 symtab_nodes = node->symbol.next;
82 if (node->symbol.next)
83 node->symbol.next->symbol.previous = node->symbol.previous;
84 node->symbol.next = NULL;
85 node->symbol.previous = NULL;
86 }
87
88 /* Remove symtab NODE from the symbol table. */
89
90 void
91 symtab_remove_node (symtab_node node)
92 {
93 if (symtab_function_p (node))
94 cgraph_remove_node (cgraph (node));
95 else if (symtab_variable_p (node))
96 varpool_remove_node (varpool (node));
97 }