1 /* Routines for reading GIMPLE from a file stream.
3 Copyright 2011 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"
27 #include "tree-flow.h"
28 #include "data-streamer.h"
29 #include "tree-streamer.h"
30 #include "gimple-streamer.h"
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. */
36 input_phi (struct lto_input_block
*ib
, basic_block bb
, struct data_in
*data_in
,
39 unsigned HOST_WIDE_INT ix
;
44 ix
= streamer_read_uhwi (ib
);
45 phi_result
= VEC_index (tree
, SSANAMES (fn
), ix
);
46 len
= EDGE_COUNT (bb
->preds
);
47 result
= create_phi_node (phi_result
, bb
);
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
++)
54 tree def
= stream_read_tree (ib
, data_in
);
55 int src_index
= streamer_read_uhwi (ib
);
56 location_t arg_loc
= lto_input_location (ib
, data_in
);
57 basic_block sbb
= BASIC_BLOCK_FOR_FUNCTION (fn
, src_index
);
62 for (j
= 0; j
< len
; j
++)
63 if (EDGE_PRED (bb
, j
)->src
== sbb
)
65 e
= EDGE_PRED (bb
, j
);
69 add_phi_arg (result
, def
, e
, arg_loc
);
76 /* Read a statement with tag TAG in function FN from block IB using
77 descriptors in DATA_IN. */
80 input_gimple_stmt (struct lto_input_block
*ib
, struct data_in
*data_in
,
81 struct function
*fn
, enum LTO_tags tag
)
84 enum gimple_code code
;
85 unsigned HOST_WIDE_INT num_ops
;
89 code
= lto_tag_to_gimple_code (tag
);
91 /* Read the tuple header. */
92 bp
= streamer_read_bitpack (ib
);
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
);
101 /* Read location information. */
102 gimple_set_location (stmt
, lto_input_location (ib
, data_in
));
104 /* Read lexical block reference. */
105 gimple_set_block (stmt
, stream_read_tree (ib
, data_in
));
107 /* Read in all the operands. */
111 gimple_resx_set_region (stmt
, streamer_read_hwi (ib
));
114 case GIMPLE_EH_MUST_NOT_THROW
:
115 gimple_eh_must_not_throw_set_fndecl (stmt
, stream_read_tree (ib
, data_in
));
118 case GIMPLE_EH_DISPATCH
:
119 gimple_eh_dispatch_set_region (stmt
, streamer_read_hwi (ib
));
124 /* FIXME lto. Move most of this into a new gimple_asm_set_string(). */
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
);
131 stmt
->gimple_asm
.string
= TREE_STRING_POINTER (str
);
143 for (i
= 0; i
< num_ops
; i
++)
145 tree op
= stream_read_tree (ib
, data_in
);
146 gimple_set_op (stmt
, i
, op
);
150 /* Fixup FIELD_DECLs in COMPONENT_REFs, they are not handled
152 if (TREE_CODE (op
) == ADDR_EXPR
)
153 op
= TREE_OPERAND (op
, 0);
154 while (handled_component_p (op
))
156 if (TREE_CODE (op
) == COMPONENT_REF
)
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
))
164 if (TREE_CODE (tem
) != FIELD_DECL
)
168 if (DECL_NONADDRESSABLE_P (tem
)
169 == DECL_NONADDRESSABLE_P (field
)
170 && gimple_compare_field_offset (tem
, field
))
172 if (types_compatible_p (TREE_TYPE (tem
),
179 /* In case of type mismatches across units we can fail
180 to unify some types and thus not find a proper
182 if (tem
== NULL_TREE
)
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)))
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
)))
198 inform (DECL_SOURCE_LOCATION
199 (TYPE_NAME (TREE_TYPE (field
))),
200 "type of field declared here");
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");
209 /* And finally fixup the types. */
211 = build1 (VIEW_CONVERT_EXPR
, type
,
212 TREE_OPERAND (op
, 0));
215 TREE_OPERAND (op
, 1) = tem
;
218 op
= TREE_OPERAND (op
, 0);
221 if (is_gimple_call (stmt
))
223 if (gimple_call_internal_p (stmt
))
224 gimple_call_set_internal_fn
225 (stmt
, streamer_read_enum (ib
, internal_fn
, IFN_LAST
));
227 gimple_call_set_fntype (stmt
, stream_read_tree (ib
, data_in
));
235 case GIMPLE_TRANSACTION
:
236 gimple_transaction_set_label (stmt
, stream_read_tree (ib
, data_in
));
240 internal_error ("bytecode stream: unknown GIMPLE statement tag %s",
244 /* Update the properties of symbols, SSA names and labels associated
246 if (code
== GIMPLE_ASSIGN
|| code
== GIMPLE_CALL
)
248 tree lhs
= gimple_get_lhs (stmt
);
249 if (lhs
&& TREE_CODE (lhs
) == SSA_NAME
)
250 SSA_NAME_DEF_STMT (lhs
) = stmt
;
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
)
259 for (i
= 0; i
< gimple_asm_noutputs (stmt
); i
++)
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
;
267 /* Reset alias information. */
268 if (code
== GIMPLE_CALL
)
269 gimple_call_reset_alias_info (stmt
);
271 /* Mark the statement modified so its operand vectors can be filled in. */
272 gimple_set_modified (stmt
, true);
278 /* Read a basic block with tag TAG from DATA_IN using input block IB.
279 FN is the function being processed. */
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
)
288 gimple_stmt_iterator bsi
;
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
);
294 index
= streamer_read_uhwi (ib
);
295 bb
= BASIC_BLOCK_FOR_FUNCTION (fn
, index
);
297 bb
->count
= (streamer_read_hwi (ib
) * count_materialization_scale
298 + REG_BR_PROB_BASE
/ 2) / REG_BR_PROB_BASE
;
299 bb
->frequency
= streamer_read_hwi (ib
);
300 bb
->flags
= streamer_read_hwi (ib
);
302 /* LTO_bb1 has statements. LTO_bb0 does not. */
306 bsi
= gsi_start_bb (bb
);
307 tag
= streamer_read_record_start (ib
);
310 gimple stmt
= input_gimple_stmt (ib
, data_in
, fn
, tag
);
311 gsi_insert_after (&bsi
, stmt
, GSI_NEW_STMT
);
313 /* After the statement, expect a 0 delimiter or the EH region
314 that the previous statement belongs to. */
315 tag
= streamer_read_record_start (ib
);
316 lto_tag_check_set (tag
, 2, LTO_eh_region
, LTO_null
);
318 if (tag
== LTO_eh_region
)
320 HOST_WIDE_INT region
= streamer_read_hwi (ib
);
321 gcc_assert (region
== (int) region
);
322 add_stmt_to_eh_lp (stmt
, region
);
325 tag
= streamer_read_record_start (ib
);
328 tag
= streamer_read_record_start (ib
);
331 input_phi (ib
, bb
, data_in
, fn
);
332 tag
= streamer_read_record_start (ib
);