]>
Commit | Line | Data |
---|---|---|
2541503d | 1 | /* Routines for reading GIMPLE from a file stream. |
2 | ||
3 | Copyright 2011 Free Software Foundation, Inc. | |
4 | Contributed by Diego Novillo <dnovillo@google.com> | |
5 | ||
6 | This file is part of GCC. | |
7 | ||
8 | GCC is free software; you can redistribute it and/or modify it under | |
9 | the terms of the GNU General Public License as published by the Free | |
10 | Software Foundation; either version 3, or (at your option) any later | |
11 | version. | |
12 | ||
13 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY | |
14 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 | for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with GCC; see the file COPYING3. If not see | |
20 | <http://www.gnu.org/licenses/>. */ | |
21 | ||
22 | #include "config.h" | |
23 | #include "system.h" | |
24 | #include "coretypes.h" | |
25 | #include "diagnostic.h" | |
26 | #include "tree.h" | |
27 | #include "tree-flow.h" | |
28 | #include "data-streamer.h" | |
29 | #include "tree-streamer.h" | |
30 | #include "gimple-streamer.h" | |
31 | ||
32 | /* Read a PHI function for basic block BB in function FN. DATA_IN is | |
33 | the file being read. IB is the input block to use for reading. */ | |
34 | ||
35 | static gimple | |
36 | input_phi (struct lto_input_block *ib, basic_block bb, struct data_in *data_in, | |
37 | struct function *fn) | |
38 | { | |
39 | unsigned HOST_WIDE_INT ix; | |
40 | tree phi_result; | |
41 | int i, len; | |
42 | gimple result; | |
43 | ||
7f385784 | 44 | ix = streamer_read_uhwi (ib); |
2541503d | 45 | phi_result = VEC_index (tree, SSANAMES (fn), ix); |
46 | len = EDGE_COUNT (bb->preds); | |
47 | result = create_phi_node (phi_result, bb); | |
2541503d | 48 | |
49 | /* We have to go through a lookup process here because the preds in the | |
50 | reconstructed graph are generally in a different order than they | |
51 | were in the original program. */ | |
52 | for (i = 0; i < len; i++) | |
53 | { | |
515cf651 | 54 | tree def = stream_read_tree (ib, data_in); |
7f385784 | 55 | int src_index = streamer_read_uhwi (ib); |
2541503d | 56 | location_t arg_loc = lto_input_location (ib, data_in); |
57 | basic_block sbb = BASIC_BLOCK_FOR_FUNCTION (fn, src_index); | |
58 | ||
59 | edge e = NULL; | |
60 | int j; | |
61 | ||
62 | for (j = 0; j < len; j++) | |
63 | if (EDGE_PRED (bb, j)->src == sbb) | |
64 | { | |
65 | e = EDGE_PRED (bb, j); | |
66 | break; | |
67 | } | |
68 | ||
60d535d2 | 69 | add_phi_arg (result, def, e, arg_loc); |
2541503d | 70 | } |
71 | ||
72 | return result; | |
73 | } | |
74 | ||
75 | ||
76 | /* Read a statement with tag TAG in function FN from block IB using | |
77 | descriptors in DATA_IN. */ | |
78 | ||
79 | static gimple | |
80 | input_gimple_stmt (struct lto_input_block *ib, struct data_in *data_in, | |
81 | struct function *fn, enum LTO_tags tag) | |
82 | { | |
83 | gimple stmt; | |
84 | enum gimple_code code; | |
85 | unsigned HOST_WIDE_INT num_ops; | |
86 | size_t i; | |
87 | struct bitpack_d bp; | |
88 | ||
89 | code = lto_tag_to_gimple_code (tag); | |
90 | ||
91 | /* Read the tuple header. */ | |
7f385784 | 92 | bp = streamer_read_bitpack (ib); |
2541503d | 93 | num_ops = bp_unpack_var_len_unsigned (&bp); |
94 | stmt = gimple_alloc (code, num_ops); | |
95 | stmt->gsbase.no_warning = bp_unpack_value (&bp, 1); | |
96 | if (is_gimple_assign (stmt)) | |
97 | stmt->gsbase.nontemporal_move = bp_unpack_value (&bp, 1); | |
98 | stmt->gsbase.has_volatile_ops = bp_unpack_value (&bp, 1); | |
99 | stmt->gsbase.subcode = bp_unpack_var_len_unsigned (&bp); | |
100 | ||
101 | /* Read location information. */ | |
102 | gimple_set_location (stmt, lto_input_location (ib, data_in)); | |
103 | ||
104 | /* Read lexical block reference. */ | |
515cf651 | 105 | gimple_set_block (stmt, stream_read_tree (ib, data_in)); |
2541503d | 106 | |
107 | /* Read in all the operands. */ | |
108 | switch (code) | |
109 | { | |
110 | case GIMPLE_RESX: | |
7f385784 | 111 | gimple_resx_set_region (stmt, streamer_read_hwi (ib)); |
2541503d | 112 | break; |
113 | ||
114 | case GIMPLE_EH_MUST_NOT_THROW: | |
515cf651 | 115 | gimple_eh_must_not_throw_set_fndecl (stmt, stream_read_tree (ib, data_in)); |
2541503d | 116 | break; |
117 | ||
118 | case GIMPLE_EH_DISPATCH: | |
7f385784 | 119 | gimple_eh_dispatch_set_region (stmt, streamer_read_hwi (ib)); |
2541503d | 120 | break; |
121 | ||
122 | case GIMPLE_ASM: | |
123 | { | |
124 | /* FIXME lto. Move most of this into a new gimple_asm_set_string(). */ | |
125 | tree str; | |
7f385784 | 126 | stmt->gimple_asm.ni = streamer_read_uhwi (ib); |
127 | stmt->gimple_asm.no = streamer_read_uhwi (ib); | |
128 | stmt->gimple_asm.nc = streamer_read_uhwi (ib); | |
129 | stmt->gimple_asm.nl = streamer_read_uhwi (ib); | |
130 | str = streamer_read_string_cst (data_in, ib); | |
2541503d | 131 | stmt->gimple_asm.string = TREE_STRING_POINTER (str); |
132 | } | |
133 | /* Fallthru */ | |
134 | ||
135 | case GIMPLE_ASSIGN: | |
136 | case GIMPLE_CALL: | |
137 | case GIMPLE_RETURN: | |
138 | case GIMPLE_SWITCH: | |
139 | case GIMPLE_LABEL: | |
140 | case GIMPLE_COND: | |
141 | case GIMPLE_GOTO: | |
142 | case GIMPLE_DEBUG: | |
143 | for (i = 0; i < num_ops; i++) | |
144 | { | |
515cf651 | 145 | tree op = stream_read_tree (ib, data_in); |
2541503d | 146 | gimple_set_op (stmt, i, op); |
147 | if (!op) | |
148 | continue; | |
149 | ||
150 | /* Fixup FIELD_DECLs in COMPONENT_REFs, they are not handled | |
151 | by decl merging. */ | |
152 | if (TREE_CODE (op) == ADDR_EXPR) | |
153 | op = TREE_OPERAND (op, 0); | |
154 | while (handled_component_p (op)) | |
155 | { | |
156 | if (TREE_CODE (op) == COMPONENT_REF) | |
157 | { | |
158 | tree field, type, tem; | |
159 | tree closest_match = NULL_TREE; | |
160 | field = TREE_OPERAND (op, 1); | |
161 | type = DECL_CONTEXT (field); | |
162 | for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem)) | |
163 | { | |
93784f3f | 164 | if (TREE_CODE (tem) != FIELD_DECL) |
165 | continue; | |
2541503d | 166 | if (tem == field) |
167 | break; | |
168 | if (DECL_NONADDRESSABLE_P (tem) | |
169 | == DECL_NONADDRESSABLE_P (field) | |
170 | && gimple_compare_field_offset (tem, field)) | |
171 | { | |
172 | if (types_compatible_p (TREE_TYPE (tem), | |
173 | TREE_TYPE (field))) | |
174 | break; | |
175 | else | |
176 | closest_match = tem; | |
177 | } | |
178 | } | |
179 | /* In case of type mismatches across units we can fail | |
180 | to unify some types and thus not find a proper | |
181 | field-decl here. */ | |
182 | if (tem == NULL_TREE) | |
183 | { | |
184 | /* Thus, emit a ODR violation warning. */ | |
185 | if (warning_at (gimple_location (stmt), 0, | |
186 | "use of type %<%E%> with two mismatching " | |
187 | "declarations at field %<%E%>", | |
188 | type, TREE_OPERAND (op, 1))) | |
189 | { | |
190 | if (TYPE_FIELDS (type)) | |
191 | inform (DECL_SOURCE_LOCATION (TYPE_FIELDS (type)), | |
192 | "original type declared here"); | |
193 | inform (DECL_SOURCE_LOCATION (TREE_OPERAND (op, 1)), | |
194 | "field in mismatching type declared here"); | |
195 | if (TYPE_NAME (TREE_TYPE (field)) | |
196 | && (TREE_CODE (TYPE_NAME (TREE_TYPE (field))) | |
197 | == TYPE_DECL)) | |
198 | inform (DECL_SOURCE_LOCATION | |
199 | (TYPE_NAME (TREE_TYPE (field))), | |
200 | "type of field declared here"); | |
201 | if (closest_match | |
202 | && TYPE_NAME (TREE_TYPE (closest_match)) | |
203 | && (TREE_CODE (TYPE_NAME | |
204 | (TREE_TYPE (closest_match))) == TYPE_DECL)) | |
205 | inform (DECL_SOURCE_LOCATION | |
206 | (TYPE_NAME (TREE_TYPE (closest_match))), | |
207 | "type of mismatching field declared here"); | |
208 | } | |
209 | /* And finally fixup the types. */ | |
210 | TREE_OPERAND (op, 0) | |
211 | = build1 (VIEW_CONVERT_EXPR, type, | |
212 | TREE_OPERAND (op, 0)); | |
213 | } | |
214 | else | |
215 | TREE_OPERAND (op, 1) = tem; | |
216 | } | |
217 | ||
218 | op = TREE_OPERAND (op, 0); | |
219 | } | |
220 | } | |
221 | if (is_gimple_call (stmt)) | |
222 | { | |
223 | if (gimple_call_internal_p (stmt)) | |
224 | gimple_call_set_internal_fn | |
7f385784 | 225 | (stmt, streamer_read_enum (ib, internal_fn, IFN_LAST)); |
2541503d | 226 | else |
515cf651 | 227 | gimple_call_set_fntype (stmt, stream_read_tree (ib, data_in)); |
2541503d | 228 | } |
229 | break; | |
230 | ||
231 | case GIMPLE_NOP: | |
232 | case GIMPLE_PREDICT: | |
233 | break; | |
234 | ||
ea0e88d1 | 235 | case GIMPLE_TRANSACTION: |
236 | gimple_transaction_set_label (stmt, stream_read_tree (ib, data_in)); | |
237 | break; | |
238 | ||
2541503d | 239 | default: |
240 | internal_error ("bytecode stream: unknown GIMPLE statement tag %s", | |
241 | lto_tag_name (tag)); | |
242 | } | |
243 | ||
244 | /* Update the properties of symbols, SSA names and labels associated | |
245 | with STMT. */ | |
246 | if (code == GIMPLE_ASSIGN || code == GIMPLE_CALL) | |
247 | { | |
248 | tree lhs = gimple_get_lhs (stmt); | |
249 | if (lhs && TREE_CODE (lhs) == SSA_NAME) | |
250 | SSA_NAME_DEF_STMT (lhs) = stmt; | |
251 | } | |
252 | else if (code == GIMPLE_LABEL) | |
253 | gcc_assert (emit_label_in_global_context_p (gimple_label_label (stmt)) | |
254 | || DECL_CONTEXT (gimple_label_label (stmt)) == fn->decl); | |
255 | else if (code == GIMPLE_ASM) | |
256 | { | |
257 | unsigned i; | |
258 | ||
259 | for (i = 0; i < gimple_asm_noutputs (stmt); i++) | |
260 | { | |
261 | tree op = TREE_VALUE (gimple_asm_output_op (stmt, i)); | |
262 | if (TREE_CODE (op) == SSA_NAME) | |
263 | SSA_NAME_DEF_STMT (op) = stmt; | |
264 | } | |
265 | } | |
266 | ||
267 | /* Reset alias information. */ | |
268 | if (code == GIMPLE_CALL) | |
269 | gimple_call_reset_alias_info (stmt); | |
270 | ||
271 | /* Mark the statement modified so its operand vectors can be filled in. */ | |
272 | gimple_set_modified (stmt, true); | |
273 | ||
274 | return stmt; | |
275 | } | |
276 | ||
277 | ||
278 | /* Read a basic block with tag TAG from DATA_IN using input block IB. | |
279 | FN is the function being processed. */ | |
280 | ||
281 | void | |
282 | input_bb (struct lto_input_block *ib, enum LTO_tags tag, | |
283 | struct data_in *data_in, struct function *fn, | |
284 | int count_materialization_scale) | |
285 | { | |
286 | unsigned int index; | |
287 | basic_block bb; | |
288 | gimple_stmt_iterator bsi; | |
289 | ||
290 | /* This routine assumes that CFUN is set to FN, as it needs to call | |
291 | basic GIMPLE routines that use CFUN. */ | |
292 | gcc_assert (cfun == fn); | |
293 | ||
7f385784 | 294 | index = streamer_read_uhwi (ib); |
2541503d | 295 | bb = BASIC_BLOCK_FOR_FUNCTION (fn, index); |
296 | ||
7f385784 | 297 | bb->count = (streamer_read_hwi (ib) * count_materialization_scale |
2541503d | 298 | + REG_BR_PROB_BASE / 2) / REG_BR_PROB_BASE; |
7f385784 | 299 | bb->loop_depth = streamer_read_hwi (ib); |
300 | bb->frequency = streamer_read_hwi (ib); | |
301 | bb->flags = streamer_read_hwi (ib); | |
2541503d | 302 | |
303 | /* LTO_bb1 has statements. LTO_bb0 does not. */ | |
304 | if (tag == LTO_bb0) | |
305 | return; | |
306 | ||
307 | bsi = gsi_start_bb (bb); | |
7f385784 | 308 | tag = streamer_read_record_start (ib); |
2541503d | 309 | while (tag) |
310 | { | |
311 | gimple stmt = input_gimple_stmt (ib, data_in, fn, tag); | |
2541503d | 312 | gsi_insert_after (&bsi, stmt, GSI_NEW_STMT); |
313 | ||
314 | /* After the statement, expect a 0 delimiter or the EH region | |
315 | that the previous statement belongs to. */ | |
7f385784 | 316 | tag = streamer_read_record_start (ib); |
2541503d | 317 | lto_tag_check_set (tag, 2, LTO_eh_region, LTO_null); |
318 | ||
319 | if (tag == LTO_eh_region) | |
320 | { | |
7f385784 | 321 | HOST_WIDE_INT region = streamer_read_hwi (ib); |
2541503d | 322 | gcc_assert (region == (int) region); |
323 | add_stmt_to_eh_lp (stmt, region); | |
324 | } | |
325 | ||
7f385784 | 326 | tag = streamer_read_record_start (ib); |
2541503d | 327 | } |
328 | ||
7f385784 | 329 | tag = streamer_read_record_start (ib); |
2541503d | 330 | while (tag) |
331 | { | |
b03e5397 | 332 | input_phi (ib, bb, data_in, fn); |
7f385784 | 333 | tag = streamer_read_record_start (ib); |
2541503d | 334 | } |
335 | } |