1 /* Routines for reading GIMPLE from a file stream.
3 Copyright (C) 2011-2013 Free Software Foundation, Inc.
4 Contributed by Diego Novillo <dnovillo@google.com>
6 This file is part of GCC.
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
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
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/>. */
24 #include "coretypes.h"
25 #include "diagnostic.h"
28 #include "gimple-ssa.h"
29 #include "tree-phinodes.h"
30 #include "tree-ssanames.h"
31 #include "data-streamer.h"
32 #include "tree-streamer.h"
33 #include "gimple-streamer.h"
34 #include "value-prof.h"
36 /* Read a PHI function for basic block BB in function FN. DATA_IN is
37 the file being read. IB is the input block to use for reading. */
40 input_phi (struct lto_input_block
*ib
, basic_block bb
, struct data_in
*data_in
,
43 unsigned HOST_WIDE_INT ix
;
48 ix
= streamer_read_uhwi (ib
);
49 phi_result
= (*SSANAMES (fn
))[ix
];
50 len
= EDGE_COUNT (bb
->preds
);
51 result
= create_phi_node (phi_result
, bb
);
53 /* We have to go through a lookup process here because the preds in the
54 reconstructed graph are generally in a different order than they
55 were in the original program. */
56 for (i
= 0; i
< len
; i
++)
58 tree def
= stream_read_tree (ib
, data_in
);
59 int src_index
= streamer_read_uhwi (ib
);
60 bitpack_d bp
= streamer_read_bitpack (ib
);
61 location_t arg_loc
= stream_input_location (&bp
, data_in
);
62 basic_block sbb
= BASIC_BLOCK_FOR_FUNCTION (fn
, src_index
);
67 for (j
= 0; j
< len
; j
++)
68 if (EDGE_PRED (bb
, j
)->src
== sbb
)
70 e
= EDGE_PRED (bb
, j
);
74 add_phi_arg (result
, def
, e
, arg_loc
);
81 /* Read a statement with tag TAG in function FN from block IB using
82 descriptors in DATA_IN. */
85 input_gimple_stmt (struct lto_input_block
*ib
, struct data_in
*data_in
,
89 enum gimple_code code
;
90 unsigned HOST_WIDE_INT num_ops
;
95 code
= lto_tag_to_gimple_code (tag
);
97 /* Read the tuple header. */
98 bp
= streamer_read_bitpack (ib
);
99 num_ops
= bp_unpack_var_len_unsigned (&bp
);
100 stmt
= gimple_alloc (code
, num_ops
);
101 stmt
->gsbase
.no_warning
= bp_unpack_value (&bp
, 1);
102 if (is_gimple_assign (stmt
))
103 stmt
->gsbase
.nontemporal_move
= bp_unpack_value (&bp
, 1);
104 stmt
->gsbase
.has_volatile_ops
= bp_unpack_value (&bp
, 1);
105 has_hist
= bp_unpack_value (&bp
, 1);
106 stmt
->gsbase
.subcode
= bp_unpack_var_len_unsigned (&bp
);
108 /* Read location information. */
109 gimple_set_location (stmt
, stream_input_location (&bp
, data_in
));
111 /* Read lexical block reference. */
112 gimple_set_block (stmt
, stream_read_tree (ib
, data_in
));
114 /* Read in all the operands. */
118 gimple_resx_set_region (stmt
, streamer_read_hwi (ib
));
121 case GIMPLE_EH_MUST_NOT_THROW
:
122 gimple_eh_must_not_throw_set_fndecl (stmt
, stream_read_tree (ib
, data_in
));
125 case GIMPLE_EH_DISPATCH
:
126 gimple_eh_dispatch_set_region (stmt
, streamer_read_hwi (ib
));
131 /* FIXME lto. Move most of this into a new gimple_asm_set_string(). */
133 stmt
->gimple_asm
.ni
= streamer_read_uhwi (ib
);
134 stmt
->gimple_asm
.no
= streamer_read_uhwi (ib
);
135 stmt
->gimple_asm
.nc
= streamer_read_uhwi (ib
);
136 stmt
->gimple_asm
.nl
= streamer_read_uhwi (ib
);
137 str
= streamer_read_string_cst (data_in
, ib
);
138 stmt
->gimple_asm
.string
= TREE_STRING_POINTER (str
);
150 for (i
= 0; i
< num_ops
; i
++)
152 tree
*opp
, op
= stream_read_tree (ib
, data_in
);
153 gimple_set_op (stmt
, i
, op
);
157 opp
= gimple_op_ptr (stmt
, i
);
158 if (TREE_CODE (*opp
) == ADDR_EXPR
)
159 opp
= &TREE_OPERAND (*opp
, 0);
160 while (handled_component_p (*opp
))
162 if (TREE_CODE (*opp
) == COMPONENT_REF
)
164 /* Fixup FIELD_DECLs in COMPONENT_REFs, they are not handled
166 tree field
, type
, tem
;
167 tree closest_match
= NULL_TREE
;
168 field
= TREE_OPERAND (*opp
, 1);
169 type
= DECL_CONTEXT (field
);
170 for (tem
= TYPE_FIELDS (type
); tem
; tem
= TREE_CHAIN (tem
))
172 if (TREE_CODE (tem
) != FIELD_DECL
)
176 if (DECL_NONADDRESSABLE_P (tem
)
177 == DECL_NONADDRESSABLE_P (field
)
178 && gimple_compare_field_offset (tem
, field
))
180 if (types_compatible_p (TREE_TYPE (tem
),
187 /* In case of type mismatches across units we can fail
188 to unify some types and thus not find a proper
190 if (tem
== NULL_TREE
)
192 /* Thus, emit a ODR violation warning. */
193 if (warning_at (gimple_location (stmt
), 0,
194 "use of type %<%E%> with two mismatching "
195 "declarations at field %<%E%>",
196 type
, TREE_OPERAND (*opp
, 1)))
198 if (TYPE_FIELDS (type
))
199 inform (DECL_SOURCE_LOCATION (TYPE_FIELDS (type
)),
200 "original type declared here");
201 inform (DECL_SOURCE_LOCATION (TREE_OPERAND (*opp
, 1)),
202 "field in mismatching type declared here");
203 if (TYPE_NAME (TREE_TYPE (field
))
204 && (TREE_CODE (TYPE_NAME (TREE_TYPE (field
)))
206 inform (DECL_SOURCE_LOCATION
207 (TYPE_NAME (TREE_TYPE (field
))),
208 "type of field declared here");
210 && TYPE_NAME (TREE_TYPE (closest_match
))
211 && (TREE_CODE (TYPE_NAME
212 (TREE_TYPE (closest_match
))) == TYPE_DECL
))
213 inform (DECL_SOURCE_LOCATION
214 (TYPE_NAME (TREE_TYPE (closest_match
))),
215 "type of mismatching field declared here");
217 /* And finally fixup the types. */
218 TREE_OPERAND (*opp
, 0)
219 = build1 (VIEW_CONVERT_EXPR
, type
,
220 TREE_OPERAND (*opp
, 0));
223 TREE_OPERAND (*opp
, 1) = tem
;
225 else if ((TREE_CODE (*opp
) == ARRAY_REF
226 || TREE_CODE (*opp
) == ARRAY_RANGE_REF
)
227 && (TREE_CODE (TREE_TYPE (TREE_OPERAND (*opp
, 0)))
230 /* And ARRAY_REFs to objects that had mismatched types
231 during symbol merging to avoid ICEs. */
232 TREE_OPERAND (*opp
, 0)
233 = build1 (VIEW_CONVERT_EXPR
,
234 build_array_type (TREE_TYPE (*opp
), NULL_TREE
),
235 TREE_OPERAND (*opp
, 0));
238 opp
= &TREE_OPERAND (*opp
, 0);
240 /* At LTO output time we wrap all global decls in MEM_REFs to
241 allow seamless replacement with prevailing decls. Undo this
242 here if the prevailing decl allows for this.
243 ??? Maybe we should simply fold all stmts. */
244 if (TREE_CODE (*opp
) == MEM_REF
245 && TREE_CODE (TREE_OPERAND (*opp
, 0)) == ADDR_EXPR
246 && integer_zerop (TREE_OPERAND (*opp
, 1))
247 && (TREE_THIS_VOLATILE (*opp
)
248 == TREE_THIS_VOLATILE
249 (TREE_OPERAND (TREE_OPERAND (*opp
, 0), 0)))
250 && !TYPE_REF_CAN_ALIAS_ALL (TREE_TYPE (TREE_OPERAND (*opp
, 1)))
252 == TREE_TYPE (TREE_TYPE (TREE_OPERAND (*opp
, 1))))
254 == TREE_TYPE (TREE_OPERAND (TREE_OPERAND (*opp
, 0), 0))))
255 *opp
= TREE_OPERAND (TREE_OPERAND (*opp
, 0), 0);
257 if (is_gimple_call (stmt
))
259 if (gimple_call_internal_p (stmt
))
260 gimple_call_set_internal_fn
261 (stmt
, streamer_read_enum (ib
, internal_fn
, IFN_LAST
));
263 gimple_call_set_fntype (stmt
, stream_read_tree (ib
, data_in
));
271 case GIMPLE_TRANSACTION
:
272 gimple_transaction_set_label (stmt
, stream_read_tree (ib
, data_in
));
276 internal_error ("bytecode stream: unknown GIMPLE statement tag %s",
280 /* Update the properties of symbols, SSA names and labels associated
282 if (code
== GIMPLE_ASSIGN
|| code
== GIMPLE_CALL
)
284 tree lhs
= gimple_get_lhs (stmt
);
285 if (lhs
&& TREE_CODE (lhs
) == SSA_NAME
)
286 SSA_NAME_DEF_STMT (lhs
) = stmt
;
288 else if (code
== GIMPLE_ASM
)
292 for (i
= 0; i
< gimple_asm_noutputs (stmt
); i
++)
294 tree op
= TREE_VALUE (gimple_asm_output_op (stmt
, i
));
295 if (TREE_CODE (op
) == SSA_NAME
)
296 SSA_NAME_DEF_STMT (op
) = stmt
;
300 /* Reset alias information. */
301 if (code
== GIMPLE_CALL
)
302 gimple_call_reset_alias_info (stmt
);
304 /* Mark the statement modified so its operand vectors can be filled in. */
305 gimple_set_modified (stmt
, true);
307 stream_in_histogram_value (ib
, stmt
);
313 /* Read a basic block with tag TAG from DATA_IN using input block IB.
314 FN is the function being processed. */
317 input_bb (struct lto_input_block
*ib
, enum LTO_tags tag
,
318 struct data_in
*data_in
, struct function
*fn
,
319 int count_materialization_scale
)
323 gimple_stmt_iterator bsi
;
325 /* This routine assumes that CFUN is set to FN, as it needs to call
326 basic GIMPLE routines that use CFUN. */
327 gcc_assert (cfun
== fn
);
329 index
= streamer_read_uhwi (ib
);
330 bb
= BASIC_BLOCK_FOR_FUNCTION (fn
, index
);
332 bb
->count
= apply_scale (streamer_read_gcov_count (ib
),
333 count_materialization_scale
);
334 bb
->frequency
= streamer_read_hwi (ib
);
335 bb
->flags
= streamer_read_hwi (ib
);
337 /* LTO_bb1 has statements. LTO_bb0 does not. */
341 bsi
= gsi_start_bb (bb
);
342 tag
= streamer_read_record_start (ib
);
345 gimple stmt
= input_gimple_stmt (ib
, data_in
, tag
);
346 gsi_insert_after (&bsi
, stmt
, GSI_NEW_STMT
);
348 /* After the statement, expect a 0 delimiter or the EH region
349 that the previous statement belongs to. */
350 tag
= streamer_read_record_start (ib
);
351 lto_tag_check_set (tag
, 2, LTO_eh_region
, LTO_null
);
353 if (tag
== LTO_eh_region
)
355 HOST_WIDE_INT region
= streamer_read_hwi (ib
);
356 gcc_assert (region
== (int) region
);
357 add_stmt_to_eh_lp (stmt
, region
);
360 tag
= streamer_read_record_start (ib
);
363 tag
= streamer_read_record_start (ib
);
366 input_phi (ib
, bb
, data_in
, fn
);
367 tag
= streamer_read_record_start (ib
);