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
))
161 opp
= &TREE_OPERAND (*opp
, 0);
162 /* At LTO output time we wrap all global decls in MEM_REFs to
163 allow seamless replacement with prevailing decls. Undo this
164 here if the prevailing decl allows for this.
165 ??? Maybe we should simply fold all stmts. */
166 if (TREE_CODE (*opp
) == MEM_REF
167 && TREE_CODE (TREE_OPERAND (*opp
, 0)) == ADDR_EXPR
168 && integer_zerop (TREE_OPERAND (*opp
, 1))
169 && (TREE_THIS_VOLATILE (*opp
)
170 == TREE_THIS_VOLATILE
171 (TREE_OPERAND (TREE_OPERAND (*opp
, 0), 0)))
172 && !TYPE_REF_CAN_ALIAS_ALL (TREE_TYPE (TREE_OPERAND (*opp
, 1)))
174 == TREE_TYPE (TREE_TYPE (TREE_OPERAND (*opp
, 1))))
176 == TREE_TYPE (TREE_OPERAND (TREE_OPERAND (*opp
, 0), 0))))
177 *opp
= TREE_OPERAND (TREE_OPERAND (*opp
, 0), 0);
179 if (is_gimple_call (stmt
))
181 if (gimple_call_internal_p (stmt
))
182 gimple_call_set_internal_fn
183 (stmt
, streamer_read_enum (ib
, internal_fn
, IFN_LAST
));
185 gimple_call_set_fntype (stmt
, stream_read_tree (ib
, data_in
));
193 case GIMPLE_TRANSACTION
:
194 gimple_transaction_set_label (stmt
, stream_read_tree (ib
, data_in
));
198 internal_error ("bytecode stream: unknown GIMPLE statement tag %s",
202 /* Update the properties of symbols, SSA names and labels associated
204 if (code
== GIMPLE_ASSIGN
|| code
== GIMPLE_CALL
)
206 tree lhs
= gimple_get_lhs (stmt
);
207 if (lhs
&& TREE_CODE (lhs
) == SSA_NAME
)
208 SSA_NAME_DEF_STMT (lhs
) = stmt
;
210 else if (code
== GIMPLE_ASM
)
214 for (i
= 0; i
< gimple_asm_noutputs (stmt
); i
++)
216 tree op
= TREE_VALUE (gimple_asm_output_op (stmt
, i
));
217 if (TREE_CODE (op
) == SSA_NAME
)
218 SSA_NAME_DEF_STMT (op
) = stmt
;
222 /* Reset alias information. */
223 if (code
== GIMPLE_CALL
)
224 gimple_call_reset_alias_info (stmt
);
226 /* Mark the statement modified so its operand vectors can be filled in. */
227 gimple_set_modified (stmt
, true);
229 stream_in_histogram_value (ib
, stmt
);
235 /* Read a basic block with tag TAG from DATA_IN using input block IB.
236 FN is the function being processed. */
239 input_bb (struct lto_input_block
*ib
, enum LTO_tags tag
,
240 struct data_in
*data_in
, struct function
*fn
,
241 int count_materialization_scale
)
245 gimple_stmt_iterator bsi
;
247 /* This routine assumes that CFUN is set to FN, as it needs to call
248 basic GIMPLE routines that use CFUN. */
249 gcc_assert (cfun
== fn
);
251 index
= streamer_read_uhwi (ib
);
252 bb
= BASIC_BLOCK_FOR_FUNCTION (fn
, index
);
254 bb
->count
= apply_scale (streamer_read_gcov_count (ib
),
255 count_materialization_scale
);
256 bb
->frequency
= streamer_read_hwi (ib
);
257 bb
->flags
= streamer_read_hwi (ib
);
259 /* LTO_bb1 has statements. LTO_bb0 does not. */
263 bsi
= gsi_start_bb (bb
);
264 tag
= streamer_read_record_start (ib
);
267 gimple stmt
= input_gimple_stmt (ib
, data_in
, tag
);
268 gsi_insert_after (&bsi
, stmt
, GSI_NEW_STMT
);
270 /* After the statement, expect a 0 delimiter or the EH region
271 that the previous statement belongs to. */
272 tag
= streamer_read_record_start (ib
);
273 lto_tag_check_set (tag
, 2, LTO_eh_region
, LTO_null
);
275 if (tag
== LTO_eh_region
)
277 HOST_WIDE_INT region
= streamer_read_hwi (ib
);
278 gcc_assert (region
== (int) region
);
279 add_stmt_to_eh_lp (stmt
, region
);
282 tag
= streamer_read_record_start (ib
);
285 tag
= streamer_read_record_start (ib
);
288 input_phi (ib
, bb
, data_in
, fn
);
289 tag
= streamer_read_record_start (ib
);