1 /* Routines for reading GIMPLE from a file stream.
3 Copyright (C) 2011-2015 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"
29 #include "double-int.h"
37 #include "fold-const.h"
40 #include "hard-reg-set.h"
43 #include "dominance.h"
45 #include "basic-block.h"
46 #include "tree-ssa-alias.h"
47 #include "internal-fn.h"
49 #include "gimple-expr.h"
52 #include "gimple-iterator.h"
53 #include "gimple-ssa.h"
54 #include "tree-phinodes.h"
55 #include "stringpool.h"
56 #include "tree-ssanames.h"
57 #include "plugin-api.h"
60 #include "data-streamer.h"
61 #include "tree-streamer.h"
62 #include "gimple-streamer.h"
63 #include "value-prof.h"
65 /* Read a PHI function for basic block BB in function FN. DATA_IN is
66 the file being read. IB is the input block to use for reading. */
69 input_phi (struct lto_input_block
*ib
, basic_block bb
, struct data_in
*data_in
,
72 unsigned HOST_WIDE_INT ix
;
77 ix
= streamer_read_uhwi (ib
);
78 phi_result
= (*SSANAMES (fn
))[ix
];
79 len
= EDGE_COUNT (bb
->preds
);
80 result
= create_phi_node (phi_result
, bb
);
82 /* We have to go through a lookup process here because the preds in the
83 reconstructed graph are generally in a different order than they
84 were in the original program. */
85 for (i
= 0; i
< len
; i
++)
87 tree def
= stream_read_tree (ib
, data_in
);
88 int src_index
= streamer_read_uhwi (ib
);
89 bitpack_d bp
= streamer_read_bitpack (ib
);
90 location_t arg_loc
= stream_input_location (&bp
, data_in
);
91 basic_block sbb
= BASIC_BLOCK_FOR_FN (fn
, src_index
);
96 for (j
= 0; j
< len
; j
++)
97 if (EDGE_PRED (bb
, j
)->src
== sbb
)
99 e
= EDGE_PRED (bb
, j
);
103 add_phi_arg (result
, def
, e
, arg_loc
);
110 /* Read a statement with tag TAG in function FN from block IB using
111 descriptors in DATA_IN. */
114 input_gimple_stmt (struct lto_input_block
*ib
, struct data_in
*data_in
,
118 enum gimple_code code
;
119 unsigned HOST_WIDE_INT num_ops
;
124 code
= lto_tag_to_gimple_code (tag
);
126 /* Read the tuple header. */
127 bp
= streamer_read_bitpack (ib
);
128 num_ops
= bp_unpack_var_len_unsigned (&bp
);
129 stmt
= gimple_alloc (code
, num_ops
);
130 stmt
->no_warning
= bp_unpack_value (&bp
, 1);
131 if (is_gimple_assign (stmt
))
132 stmt
->nontemporal_move
= bp_unpack_value (&bp
, 1);
133 stmt
->has_volatile_ops
= bp_unpack_value (&bp
, 1);
134 has_hist
= bp_unpack_value (&bp
, 1);
135 stmt
->subcode
= bp_unpack_var_len_unsigned (&bp
);
137 /* Read location information. */
138 gimple_set_location (stmt
, stream_input_location (&bp
, data_in
));
140 /* Read lexical block reference. */
141 gimple_set_block (stmt
, stream_read_tree (ib
, data_in
));
143 /* Read in all the operands. */
147 gimple_resx_set_region (as_a
<gresx
*> (stmt
),
148 streamer_read_hwi (ib
));
151 case GIMPLE_EH_MUST_NOT_THROW
:
152 gimple_eh_must_not_throw_set_fndecl (
153 as_a
<geh_mnt
*> (stmt
),
154 stream_read_tree (ib
, data_in
));
157 case GIMPLE_EH_DISPATCH
:
158 gimple_eh_dispatch_set_region (as_a
<geh_dispatch
*> (stmt
),
159 streamer_read_hwi (ib
));
164 /* FIXME lto. Move most of this into a new gimple_asm_set_string(). */
165 gasm
*asm_stmt
= as_a
<gasm
*> (stmt
);
167 asm_stmt
->ni
= streamer_read_uhwi (ib
);
168 asm_stmt
->no
= streamer_read_uhwi (ib
);
169 asm_stmt
->nc
= streamer_read_uhwi (ib
);
170 asm_stmt
->nl
= streamer_read_uhwi (ib
);
171 str
= streamer_read_string_cst (data_in
, ib
);
172 asm_stmt
->string
= TREE_STRING_POINTER (str
);
184 for (i
= 0; i
< num_ops
; i
++)
186 tree
*opp
, op
= stream_read_tree (ib
, data_in
);
187 gimple_set_op (stmt
, i
, op
);
191 opp
= gimple_op_ptr (stmt
, i
);
192 if (TREE_CODE (*opp
) == ADDR_EXPR
)
193 opp
= &TREE_OPERAND (*opp
, 0);
194 while (handled_component_p (*opp
))
195 opp
= &TREE_OPERAND (*opp
, 0);
196 /* At LTO output time we wrap all global decls in MEM_REFs to
197 allow seamless replacement with prevailing decls. Undo this
198 here if the prevailing decl allows for this.
199 ??? Maybe we should simply fold all stmts. */
200 if (TREE_CODE (*opp
) == MEM_REF
201 && TREE_CODE (TREE_OPERAND (*opp
, 0)) == ADDR_EXPR
202 && integer_zerop (TREE_OPERAND (*opp
, 1))
203 && (TREE_THIS_VOLATILE (*opp
)
204 == TREE_THIS_VOLATILE
205 (TREE_OPERAND (TREE_OPERAND (*opp
, 0), 0)))
206 && !TYPE_REF_CAN_ALIAS_ALL (TREE_TYPE (TREE_OPERAND (*opp
, 1)))
208 == TREE_TYPE (TREE_TYPE (TREE_OPERAND (*opp
, 1))))
210 == TREE_TYPE (TREE_OPERAND (TREE_OPERAND (*opp
, 0), 0))))
211 *opp
= TREE_OPERAND (TREE_OPERAND (*opp
, 0), 0);
213 if (gcall
*call_stmt
= dyn_cast
<gcall
*> (stmt
))
215 if (gimple_call_internal_p (call_stmt
))
216 gimple_call_set_internal_fn
217 (call_stmt
, streamer_read_enum (ib
, internal_fn
, IFN_LAST
));
219 gimple_call_set_fntype (call_stmt
, stream_read_tree (ib
, data_in
));
227 case GIMPLE_TRANSACTION
:
228 gimple_transaction_set_label (as_a
<gtransaction
*> (stmt
),
229 stream_read_tree (ib
, data_in
));
233 internal_error ("bytecode stream: unknown GIMPLE statement tag %s",
237 /* Update the properties of symbols, SSA names and labels associated
239 if (code
== GIMPLE_ASSIGN
|| code
== GIMPLE_CALL
)
241 tree lhs
= gimple_get_lhs (stmt
);
242 if (lhs
&& TREE_CODE (lhs
) == SSA_NAME
)
243 SSA_NAME_DEF_STMT (lhs
) = stmt
;
245 else if (code
== GIMPLE_ASM
)
247 gasm
*asm_stmt
= as_a
<gasm
*> (stmt
);
250 for (i
= 0; i
< gimple_asm_noutputs (asm_stmt
); i
++)
252 tree op
= TREE_VALUE (gimple_asm_output_op (asm_stmt
, i
));
253 if (TREE_CODE (op
) == SSA_NAME
)
254 SSA_NAME_DEF_STMT (op
) = stmt
;
258 /* Reset alias information. */
259 if (code
== GIMPLE_CALL
)
260 gimple_call_reset_alias_info (as_a
<gcall
*> (stmt
));
262 /* Mark the statement modified so its operand vectors can be filled in. */
263 gimple_set_modified (stmt
, true);
265 stream_in_histogram_value (ib
, stmt
);
271 /* Read a basic block with tag TAG from DATA_IN using input block IB.
272 FN is the function being processed. */
275 input_bb (struct lto_input_block
*ib
, enum LTO_tags tag
,
276 struct data_in
*data_in
, struct function
*fn
,
277 int count_materialization_scale
)
281 gimple_stmt_iterator bsi
;
283 /* This routine assumes that CFUN is set to FN, as it needs to call
284 basic GIMPLE routines that use CFUN. */
285 gcc_assert (cfun
== fn
);
287 index
= streamer_read_uhwi (ib
);
288 bb
= BASIC_BLOCK_FOR_FN (fn
, index
);
290 bb
->count
= apply_scale (streamer_read_gcov_count (ib
),
291 count_materialization_scale
);
292 bb
->frequency
= streamer_read_hwi (ib
);
293 bb
->flags
= streamer_read_hwi (ib
);
295 /* LTO_bb1 has statements. LTO_bb0 does not. */
299 bsi
= gsi_start_bb (bb
);
300 tag
= streamer_read_record_start (ib
);
303 gimple stmt
= input_gimple_stmt (ib
, data_in
, tag
);
304 gsi_insert_after (&bsi
, stmt
, GSI_NEW_STMT
);
306 /* After the statement, expect a 0 delimiter or the EH region
307 that the previous statement belongs to. */
308 tag
= streamer_read_record_start (ib
);
309 lto_tag_check_set (tag
, 2, LTO_eh_region
, LTO_null
);
311 if (tag
== LTO_eh_region
)
313 HOST_WIDE_INT region
= streamer_read_hwi (ib
);
314 gcc_assert (region
== (int) region
);
315 add_stmt_to_eh_lp (stmt
, region
);
318 tag
= streamer_read_record_start (ib
);
321 tag
= streamer_read_record_start (ib
);
324 input_phi (ib
, bb
, data_in
, fn
);
325 tag
= streamer_read_record_start (ib
);