Mercurial > hg > CbC > CbC_gcc
annotate gcc/varpool.c @ 63:b7f97abdc517 gcc-4.6-20100522
update gcc from gcc-4.5.0 to gcc-4.6
author | ryoma <e075725@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 24 May 2010 12:47:05 +0900 |
parents | 77e2b8dfacca |
children | f6334be47118 |
rev | line source |
---|---|
0 | 1 /* Callgraph handling code. |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2010 |
0 | 3 Free Software Foundation, Inc. |
4 Contributed by Jan Hubicka | |
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 #include "tree.h" | |
27 #include "cgraph.h" | |
28 #include "langhooks.h" | |
29 #include "diagnostic.h" | |
30 #include "hashtab.h" | |
31 #include "ggc.h" | |
32 #include "timevar.h" | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
33 #include "debug.h" |
0 | 34 #include "target.h" |
35 #include "output.h" | |
36 #include "gimple.h" | |
37 #include "tree-flow.h" | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
38 #include "flags.h" |
0 | 39 |
40 /* This file contains basic routines manipulating variable pool. | |
41 | |
42 Varpool acts as interface in between the front-end and middle-end | |
43 and drives the decision process on what variables and when are | |
44 going to be compiled. | |
45 | |
46 The varpool nodes are allocated lazily for declarations | |
47 either by frontend or at callgraph construction time. | |
48 All variables supposed to be output into final file needs to be | |
49 explicitly marked by frontend via VARPOOL_FINALIZE_DECL function. */ | |
50 | |
51 /* Hash table used to convert declarations into nodes. */ | |
52 static GTY((param_is (struct varpool_node))) htab_t varpool_hash; | |
53 | |
54 /* The linked list of cgraph varpool nodes. | |
55 Linked via node->next pointer. */ | |
56 struct varpool_node *varpool_nodes; | |
57 | |
58 /* Queue of cgraph nodes scheduled to be lowered and output. | |
59 The queue is maintained via mark_needed_node, linked via node->next_needed | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
60 pointer. |
0 | 61 |
62 LAST_NEEDED_NODE points to the end of queue, so it can be | |
63 maintained in forward order. GTY is needed to make it friendly to | |
64 PCH. | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
65 |
0 | 66 During compilation we construct the queue of needed variables |
67 twice: first time it is during cgraph construction, second time it is at the | |
68 end of compilation in VARPOOL_REMOVE_UNREFERENCED_DECLS so we can avoid | |
69 optimized out variables being output. | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
70 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
71 Each variable is thus first analyzed and then later possibly output. |
0 | 72 FIRST_UNANALYZED_NODE points to first node in queue that was not analyzed |
73 yet and is moved via VARPOOL_ANALYZE_PENDING_DECLS. */ | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
74 |
0 | 75 struct varpool_node *varpool_nodes_queue; |
76 static GTY(()) struct varpool_node *varpool_last_needed_node; | |
77 static GTY(()) struct varpool_node *varpool_first_unanalyzed_node; | |
78 | |
79 /* Lists all assembled variables to be sent to debugger output later on. */ | |
80 static GTY(()) struct varpool_node *varpool_assembled_nodes_queue; | |
81 | |
82 /* Return name of the node used in debug output. */ | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
83 const char * |
0 | 84 varpool_node_name (struct varpool_node *node) |
85 { | |
86 return lang_hooks.decl_printable_name (node->decl, 2); | |
87 } | |
88 | |
89 /* Returns a hash code for P. */ | |
90 static hashval_t | |
91 hash_varpool_node (const void *p) | |
92 { | |
93 const struct varpool_node *n = (const struct varpool_node *) p; | |
94 return (hashval_t) DECL_UID (n->decl); | |
95 } | |
96 | |
97 /* Returns nonzero if P1 and P2 are equal. */ | |
98 static int | |
99 eq_varpool_node (const void *p1, const void *p2) | |
100 { | |
101 const struct varpool_node *n1 = | |
102 (const struct varpool_node *) p1; | |
103 const struct varpool_node *n2 = | |
104 (const struct varpool_node *) p2; | |
105 return DECL_UID (n1->decl) == DECL_UID (n2->decl); | |
106 } | |
107 | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
108 /* Return varpool node assigned to DECL without creating new one. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
109 struct varpool_node * |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
110 varpool_get_node (tree decl) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
111 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
112 struct varpool_node key, **slot; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
113 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
114 gcc_assert (DECL_P (decl) && TREE_CODE (decl) != FUNCTION_DECL); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
115 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
116 if (!varpool_hash) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
117 return NULL; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
118 key.decl = decl; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
119 slot = (struct varpool_node **) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
120 htab_find_slot (varpool_hash, &key, INSERT); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
121 return *slot; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
122 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
123 |
0 | 124 /* Return varpool node assigned to DECL. Create new one when needed. */ |
125 struct varpool_node * | |
126 varpool_node (tree decl) | |
127 { | |
128 struct varpool_node key, *node, **slot; | |
129 | |
130 gcc_assert (DECL_P (decl) && TREE_CODE (decl) != FUNCTION_DECL); | |
131 | |
132 if (!varpool_hash) | |
133 varpool_hash = htab_create_ggc (10, hash_varpool_node, | |
134 eq_varpool_node, NULL); | |
135 key.decl = decl; | |
136 slot = (struct varpool_node **) | |
137 htab_find_slot (varpool_hash, &key, INSERT); | |
138 if (*slot) | |
139 return *slot; | |
140 node = GGC_CNEW (struct varpool_node); | |
141 node->decl = decl; | |
142 node->order = cgraph_order++; | |
143 node->next = varpool_nodes; | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
144 ipa_empty_ref_list (&node->ref_list); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
145 if (varpool_nodes) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
146 varpool_nodes->prev = node; |
0 | 147 varpool_nodes = node; |
148 *slot = node; | |
149 return node; | |
150 } | |
151 | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
152 /* Remove node from the varpool. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
153 void |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
154 varpool_remove_node (struct varpool_node *node) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
155 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
156 void **slot; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
157 slot = htab_find_slot (varpool_hash, node, NO_INSERT); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
158 gcc_assert (*slot == node); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
159 htab_clear_slot (varpool_hash, slot); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
160 gcc_assert (!varpool_assembled_nodes_queue); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
161 if (!node->alias) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
162 while (node->extra_name) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
163 varpool_remove_node (node->extra_name); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
164 if (node->next) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
165 node->next->prev = node->prev; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
166 if (node->prev) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
167 node->prev->next = node->next; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
168 else |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
169 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
170 if (node->alias && node->extra_name) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
171 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
172 gcc_assert (node->extra_name->extra_name == node); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
173 node->extra_name->extra_name = node->next; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
174 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
175 else |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
176 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
177 gcc_assert (varpool_nodes == node); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
178 varpool_nodes = node->next; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
179 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
180 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
181 if (varpool_first_unanalyzed_node == node) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
182 varpool_first_unanalyzed_node = node->next_needed; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
183 if (node->next_needed) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
184 node->next_needed->prev_needed = node->prev_needed; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
185 else if (node->prev_needed) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
186 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
187 gcc_assert (varpool_last_needed_node); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
188 varpool_last_needed_node = node->prev_needed; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
189 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
190 if (node->prev_needed) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
191 node->prev_needed->next_needed = node->next_needed; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
192 else if (node->next_needed) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
193 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
194 gcc_assert (varpool_nodes_queue == node); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
195 varpool_nodes_queue = node->next_needed; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
196 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
197 if (node->same_comdat_group) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
198 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
199 struct varpool_node *prev; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
200 for (prev = node->same_comdat_group; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
201 prev->same_comdat_group != node; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
202 prev = prev->same_comdat_group) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
203 ; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
204 if (node->same_comdat_group == prev) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
205 prev->same_comdat_group = NULL; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
206 else |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
207 prev->same_comdat_group = node->same_comdat_group; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
208 node->same_comdat_group = NULL; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
209 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
210 ipa_remove_all_references (&node->ref_list); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
211 ipa_remove_all_refering (&node->ref_list); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
212 ggc_free (node); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
213 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
214 |
0 | 215 /* Dump given cgraph node. */ |
216 void | |
217 dump_varpool_node (FILE *f, struct varpool_node *node) | |
218 { | |
219 fprintf (f, "%s:", varpool_node_name (node)); | |
220 fprintf (f, " availability:%s", | |
221 cgraph_function_flags_ready | |
222 ? cgraph_availability_names[cgraph_variable_initializer_availability (node)] | |
223 : "not-ready"); | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
224 if (DECL_ASSEMBLER_NAME_SET_P (node->decl)) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
225 fprintf (f, " (asm: %s)", IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (node->decl))); |
0 | 226 if (DECL_INITIAL (node->decl)) |
227 fprintf (f, " initialized"); | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
228 if (TREE_ASM_WRITTEN (node->decl)) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
229 fprintf (f, " (asm written)"); |
0 | 230 if (node->needed) |
231 fprintf (f, " needed"); | |
232 if (node->analyzed) | |
233 fprintf (f, " analyzed"); | |
234 if (node->finalized) | |
235 fprintf (f, " finalized"); | |
236 if (node->output) | |
237 fprintf (f, " output"); | |
238 if (node->externally_visible) | |
239 fprintf (f, " externally_visible"); | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
240 if (node->in_other_partition) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
241 fprintf (f, " in_other_partition"); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
242 else if (node->used_from_other_partition) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
243 fprintf (f, " used_from_other_partition"); |
0 | 244 fprintf (f, "\n"); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
245 fprintf (f, " References: "); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
246 ipa_dump_references (f, &node->ref_list); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
247 fprintf (f, " Refering this var: "); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
248 ipa_dump_refering (f, &node->ref_list); |
0 | 249 } |
250 | |
251 /* Dump the variable pool. */ | |
252 void | |
253 dump_varpool (FILE *f) | |
254 { | |
255 struct varpool_node *node; | |
256 | |
257 fprintf (f, "variable pool:\n\n"); | |
258 for (node = varpool_nodes; node; node = node->next) | |
259 dump_varpool_node (f, node); | |
260 } | |
261 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
262 /* Dump the variable pool to stderr. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
263 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
264 void |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
265 debug_varpool (void) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
266 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
267 dump_varpool (stderr); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
268 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
269 |
0 | 270 /* Given an assembler name, lookup node. */ |
271 struct varpool_node * | |
272 varpool_node_for_asm (tree asmname) | |
273 { | |
274 struct varpool_node *node; | |
275 | |
276 for (node = varpool_nodes; node ; node = node->next) | |
277 if (decl_assembler_name_equal (node->decl, asmname)) | |
278 return node; | |
279 | |
280 return NULL; | |
281 } | |
282 | |
283 /* Helper function for finalization code - add node into lists so it will | |
284 be analyzed and compiled. */ | |
285 static void | |
286 varpool_enqueue_needed_node (struct varpool_node *node) | |
287 { | |
288 if (varpool_last_needed_node) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
289 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
290 varpool_last_needed_node->next_needed = node; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
291 node->prev_needed = varpool_last_needed_node; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
292 } |
0 | 293 varpool_last_needed_node = node; |
294 node->next_needed = NULL; | |
295 if (!varpool_nodes_queue) | |
296 varpool_nodes_queue = node; | |
297 if (!varpool_first_unanalyzed_node) | |
298 varpool_first_unanalyzed_node = node; | |
299 notice_global_symbol (node->decl); | |
300 } | |
301 | |
302 /* Notify finalize_compilation_unit that given node is reachable | |
303 or needed. */ | |
304 void | |
305 varpool_mark_needed_node (struct varpool_node *node) | |
306 { | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
307 if (node->alias && node->extra_name) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
308 node = node->extra_name; |
0 | 309 if (!node->needed && node->finalized |
310 && !TREE_ASM_WRITTEN (node->decl)) | |
311 varpool_enqueue_needed_node (node); | |
312 node->needed = 1; | |
313 } | |
314 | |
315 /* Reset the queue of needed nodes. */ | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
316 void |
0 | 317 varpool_reset_queue (void) |
318 { | |
319 varpool_last_needed_node = NULL; | |
320 varpool_nodes_queue = NULL; | |
321 varpool_first_unanalyzed_node = NULL; | |
322 } | |
323 | |
324 /* Determine if variable DECL is needed. That is, visible to something | |
325 either outside this translation unit, something magic in the system | |
326 configury */ | |
327 bool | |
328 decide_is_variable_needed (struct varpool_node *node, tree decl) | |
329 { | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
330 if (node->used_from_other_partition) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
331 return true; |
0 | 332 /* If the user told us it is used, then it must be so. */ |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
333 if ((node->externally_visible && !DECL_COMDAT (decl)) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
334 || node->force_output) |
0 | 335 return true; |
336 | |
337 /* Externally visible variables must be output. The exception is | |
338 COMDAT variables that must be output only when they are needed. */ | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
339 if (TREE_PUBLIC (decl) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
340 && !flag_whole_program |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
341 && !flag_lto |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
342 && !flag_whopr |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
343 && !DECL_COMDAT (decl) |
0 | 344 && !DECL_EXTERNAL (decl)) |
345 return true; | |
346 | |
347 /* When emulating tls, we actually see references to the control | |
348 variable, rather than the user-level variable. */ | |
349 if (!targetm.have_tls | |
350 && TREE_CODE (decl) == VAR_DECL | |
351 && DECL_THREAD_LOCAL_P (decl)) | |
352 { | |
353 tree control = emutls_decl (decl); | |
354 if (decide_is_variable_needed (varpool_node (control), control)) | |
355 return true; | |
356 } | |
357 | |
358 /* When not reordering top level variables, we have to assume that | |
359 we are going to keep everything. */ | |
360 if (flag_toplevel_reorder) | |
361 return false; | |
362 | |
363 /* We want to emit COMDAT variables only when absolutely necessary. */ | |
364 if (DECL_COMDAT (decl)) | |
365 return false; | |
366 return true; | |
367 } | |
368 | |
369 /* Mark DECL as finalized. By finalizing the declaration, frontend instruct the | |
370 middle end to output the variable to asm file, if needed or externally | |
371 visible. */ | |
372 void | |
373 varpool_finalize_decl (tree decl) | |
374 { | |
375 struct varpool_node *node = varpool_node (decl); | |
376 | |
377 /* The first declaration of a variable that comes through this function | |
378 decides whether it is global (in C, has external linkage) | |
379 or local (in C, has internal linkage). So do nothing more | |
380 if this function has already run. */ | |
381 if (node->finalized) | |
382 { | |
383 if (cgraph_global_info_ready) | |
384 varpool_assemble_pending_decls (); | |
385 return; | |
386 } | |
387 if (node->needed) | |
388 varpool_enqueue_needed_node (node); | |
389 node->finalized = true; | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
390 if (TREE_THIS_VOLATILE (decl) || DECL_PRESERVE_P (decl)) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
391 node->force_output = true; |
0 | 392 |
393 if (decide_is_variable_needed (node, decl)) | |
394 varpool_mark_needed_node (node); | |
395 /* Since we reclaim unreachable nodes at the end of every language | |
396 level unit, we need to be conservative about possible entry points | |
397 there. */ | |
398 else if (TREE_PUBLIC (decl) && !DECL_COMDAT (decl) && !DECL_EXTERNAL (decl)) | |
399 varpool_mark_needed_node (node); | |
400 if (cgraph_global_info_ready) | |
401 varpool_assemble_pending_decls (); | |
402 } | |
403 | |
404 /* Return variable availability. See cgraph.h for description of individual | |
405 return values. */ | |
406 enum availability | |
407 cgraph_variable_initializer_availability (struct varpool_node *node) | |
408 { | |
409 gcc_assert (cgraph_function_flags_ready); | |
410 if (!node->finalized) | |
411 return AVAIL_NOT_AVAILABLE; | |
412 if (!TREE_PUBLIC (node->decl)) | |
413 return AVAIL_AVAILABLE; | |
414 /* If the variable can be overwritten, return OVERWRITABLE. Takes | |
415 care of at least two notable extensions - the COMDAT variables | |
416 used to share template instantiations in C++. */ | |
417 if (!(*targetm.binds_local_p) (node->decl) && !DECL_COMDAT (node->decl)) | |
418 return AVAIL_OVERWRITABLE; | |
419 return AVAIL_AVAILABLE; | |
420 } | |
421 | |
422 /* Walk the decls we marked as necessary and see if they reference new | |
423 variables or functions and add them into the worklists. */ | |
424 bool | |
425 varpool_analyze_pending_decls (void) | |
426 { | |
427 bool changed = false; | |
428 | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
429 timevar_push (TV_VARPOOL); |
0 | 430 while (varpool_first_unanalyzed_node) |
431 { | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
432 struct varpool_node *node = varpool_first_unanalyzed_node, *next; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
433 tree decl = node->decl; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
434 bool analyzed = node->analyzed; |
0 | 435 |
436 varpool_first_unanalyzed_node->analyzed = true; | |
437 | |
438 varpool_first_unanalyzed_node = varpool_first_unanalyzed_node->next_needed; | |
439 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
440 /* When reading back varpool at LTO time, we re-construct the queue in order |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
441 to have "needed" list right by inserting all needed nodes into varpool. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
442 We however don't want to re-analyze already analyzed nodes. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
443 if (!analyzed) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
444 { |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
445 gcc_assert (!in_lto_p || cgraph_function_flags_ready); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
446 /* Compute the alignment early so function body expanders are |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
447 already informed about increased alignment. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
448 align_variable (decl, 0); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
449 } |
0 | 450 if (DECL_INITIAL (decl)) |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
451 record_references_in_initializer (decl, analyzed); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
452 if (node->same_comdat_group) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
453 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
454 for (next = node->same_comdat_group; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
455 next != node; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
456 next = next->same_comdat_group) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
457 varpool_mark_needed_node (next); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
458 } |
0 | 459 changed = true; |
460 } | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
461 timevar_pop (TV_VARPOOL); |
0 | 462 return changed; |
463 } | |
464 | |
465 /* Output one variable, if necessary. Return whether we output it. */ | |
466 bool | |
467 varpool_assemble_decl (struct varpool_node *node) | |
468 { | |
469 tree decl = node->decl; | |
470 | |
471 if (!TREE_ASM_WRITTEN (decl) | |
472 && !node->alias | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
473 && !node->in_other_partition |
0 | 474 && !DECL_EXTERNAL (decl) |
475 && (TREE_CODE (decl) != VAR_DECL || !DECL_HAS_VALUE_EXPR_P (decl))) | |
476 { | |
477 assemble_variable (decl, 0, 1, 0); | |
478 if (TREE_ASM_WRITTEN (decl)) | |
479 { | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
480 struct varpool_node *alias; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
481 |
0 | 482 node->next_needed = varpool_assembled_nodes_queue; |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
483 node->prev_needed = NULL; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
484 if (varpool_assembled_nodes_queue) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
485 varpool_assembled_nodes_queue->prev_needed = node; |
0 | 486 varpool_assembled_nodes_queue = node; |
487 node->finalized = 1; | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
488 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
489 /* Also emit any extra name aliases. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
490 for (alias = node->extra_name; alias; alias = alias->next) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
491 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
492 /* Update linkage fields in case they've changed. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
493 DECL_WEAK (alias->decl) = DECL_WEAK (decl); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
494 TREE_PUBLIC (alias->decl) = TREE_PUBLIC (decl); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
495 DECL_VISIBILITY (alias->decl) = DECL_VISIBILITY (decl); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
496 assemble_alias (alias->decl, DECL_ASSEMBLER_NAME (decl)); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
497 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
498 |
0 | 499 return true; |
500 } | |
501 } | |
502 | |
503 return false; | |
504 } | |
505 | |
506 /* Optimization of function bodies might've rendered some variables as | |
507 unnecessary so we want to avoid these from being compiled. | |
508 | |
509 This is done by pruning the queue and keeping only the variables that | |
510 really appear needed (ie they are either externally visible or referenced | |
511 by compiled function). Re-doing the reachability analysis on variables | |
512 brings back the remaining variables referenced by these. */ | |
513 void | |
514 varpool_remove_unreferenced_decls (void) | |
515 { | |
516 struct varpool_node *next, *node = varpool_nodes_queue; | |
517 | |
518 varpool_reset_queue (); | |
519 | |
520 if (errorcount || sorrycount) | |
521 return; | |
522 | |
523 while (node) | |
524 { | |
525 tree decl = node->decl; | |
526 next = node->next_needed; | |
527 node->needed = 0; | |
528 | |
529 if (node->finalized | |
530 && (decide_is_variable_needed (node, decl) | |
531 /* ??? Cgraph does not yet rule the world with an iron hand, | |
532 and does not control the emission of debug information. | |
533 After a variable has its DECL_RTL set, we must assume that | |
534 it may be referenced by the debug information, and we can | |
535 no longer elide it. */ | |
536 || DECL_RTL_SET_P (decl))) | |
537 varpool_mark_needed_node (node); | |
538 | |
539 node = next; | |
540 } | |
541 /* Make sure we mark alias targets as used targets. */ | |
542 finish_aliases_1 (); | |
543 varpool_analyze_pending_decls (); | |
544 } | |
545 | |
546 /* Output all variables enqueued to be assembled. */ | |
547 bool | |
548 varpool_assemble_pending_decls (void) | |
549 { | |
550 bool changed = false; | |
551 | |
552 if (errorcount || sorrycount) | |
553 return false; | |
554 | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
555 timevar_push (TV_VAROUT); |
0 | 556 /* EH might mark decls as needed during expansion. This should be safe since |
557 we don't create references to new function, but it should not be used | |
558 elsewhere. */ | |
559 varpool_analyze_pending_decls (); | |
560 | |
561 while (varpool_nodes_queue) | |
562 { | |
563 struct varpool_node *node = varpool_nodes_queue; | |
564 | |
565 varpool_nodes_queue = varpool_nodes_queue->next_needed; | |
566 if (varpool_assemble_decl (node)) | |
567 changed = true; | |
568 else | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
569 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
570 node->prev_needed = NULL; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
571 node->next_needed = NULL; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
572 } |
0 | 573 } |
574 /* varpool_nodes_queue is now empty, clear the pointer to the last element | |
575 in the queue. */ | |
576 varpool_last_needed_node = NULL; | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
577 timevar_pop (TV_VAROUT); |
0 | 578 return changed; |
579 } | |
580 | |
581 /* Remove all elements from the queue so we can re-use it for debug output. */ | |
582 void | |
583 varpool_empty_needed_queue (void) | |
584 { | |
585 /* EH might mark decls as needed during expansion. This should be safe since | |
586 we don't create references to new function, but it should not be used | |
587 elsewhere. */ | |
588 varpool_analyze_pending_decls (); | |
589 | |
590 while (varpool_nodes_queue) | |
591 { | |
592 struct varpool_node *node = varpool_nodes_queue; | |
593 varpool_nodes_queue = varpool_nodes_queue->next_needed; | |
594 node->next_needed = NULL; | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
595 node->prev_needed = NULL; |
0 | 596 } |
597 /* varpool_nodes_queue is now empty, clear the pointer to the last element | |
598 in the queue. */ | |
599 varpool_last_needed_node = NULL; | |
600 } | |
601 | |
602 /* Create a new global variable of type TYPE. */ | |
603 tree | |
604 add_new_static_var (tree type) | |
605 { | |
606 tree new_decl; | |
607 struct varpool_node *new_node; | |
608 | |
609 new_decl = create_tmp_var (type, NULL); | |
610 DECL_NAME (new_decl) = create_tmp_var_name (NULL); | |
611 TREE_READONLY (new_decl) = 0; | |
612 TREE_STATIC (new_decl) = 1; | |
613 TREE_USED (new_decl) = 1; | |
614 DECL_CONTEXT (new_decl) = NULL_TREE; | |
615 DECL_ABSTRACT (new_decl) = 0; | |
616 lang_hooks.dup_lang_specific_decl (new_decl); | |
617 create_var_ann (new_decl); | |
618 new_node = varpool_node (new_decl); | |
619 varpool_mark_needed_node (new_node); | |
620 add_referenced_var (new_decl); | |
621 varpool_finalize_decl (new_decl); | |
622 | |
623 return new_node->decl; | |
624 } | |
625 | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
626 /* Attempt to mark ALIAS as an alias to DECL. Return TRUE if successful. |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
627 Extra name aliases are output whenever DECL is output. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
628 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
629 bool |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
630 varpool_extra_name_alias (tree alias, tree decl) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
631 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
632 struct varpool_node key, *alias_node, *decl_node, **slot; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
633 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
634 #ifndef ASM_OUTPUT_DEF |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
635 /* If aliases aren't supported by the assembler, fail. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
636 return false; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
637 #endif |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
638 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
639 gcc_assert (TREE_CODE (decl) == VAR_DECL); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
640 gcc_assert (TREE_CODE (alias) == VAR_DECL); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
641 /* Make sure the hash table has been created. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
642 decl_node = varpool_node (decl); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
643 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
644 key.decl = alias; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
645 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
646 slot = (struct varpool_node **) htab_find_slot (varpool_hash, &key, INSERT); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
647 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
648 /* If the varpool_node has been already created, fail. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
649 if (*slot) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
650 return false; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
651 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
652 alias_node = GGC_CNEW (struct varpool_node); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
653 alias_node->decl = alias; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
654 alias_node->alias = 1; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
655 alias_node->extra_name = decl_node; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
656 alias_node->next = decl_node->extra_name; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
657 ipa_empty_ref_list (&alias_node->ref_list); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
658 if (decl_node->extra_name) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
659 decl_node->extra_name->prev = alias_node; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
660 decl_node->extra_name = alias_node; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
661 *slot = alias_node; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
662 return true; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
663 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
664 |
0 | 665 #include "gt-varpool.h" |