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"
30 #include "hard-reg-set.h"
33 #include "fold-const.h"
34 #include "internal-fn.h"
36 #include "gimple-iterator.h"
38 #include "data-streamer.h"
39 #include "tree-streamer.h"
40 #include "gimple-streamer.h"
41 #include "value-prof.h"
43 /* Read a PHI function for basic block BB in function FN. DATA_IN is
44 the file being read. IB is the input block to use for reading. */
47 input_phi (struct lto_input_block
*ib
, basic_block bb
, struct data_in
*data_in
,
50 unsigned HOST_WIDE_INT ix
;
55 ix
= streamer_read_uhwi (ib
);
56 phi_result
= (*SSANAMES (fn
))[ix
];
57 len
= EDGE_COUNT (bb
->preds
);
58 result
= create_phi_node (phi_result
, bb
);
60 /* We have to go through a lookup process here because the preds in the
61 reconstructed graph are generally in a different order than they
62 were in the original program. */
63 for (i
= 0; i
< len
; i
++)
65 tree def
= stream_read_tree (ib
, data_in
);
66 int src_index
= streamer_read_uhwi (ib
);
67 bitpack_d bp
= streamer_read_bitpack (ib
);
68 /* Do not cache a location - we do not have API to get pointer to the
69 location in PHI statement and we may trigger reallocation. */
70 location_t arg_loc
= stream_input_location_now (&bp
, data_in
);
71 basic_block sbb
= BASIC_BLOCK_FOR_FN (fn
, src_index
);
76 for (j
= 0; j
< len
; j
++)
77 if (EDGE_PRED (bb
, j
)->src
== sbb
)
79 e
= EDGE_PRED (bb
, j
);
83 add_phi_arg (result
, def
, e
, arg_loc
);
90 /* Read a statement with tag TAG in function FN from block IB using
91 descriptors in DATA_IN. */
94 input_gimple_stmt (struct lto_input_block
*ib
, struct data_in
*data_in
,
98 enum gimple_code code
;
99 unsigned HOST_WIDE_INT num_ops
;
104 code
= lto_tag_to_gimple_code (tag
);
106 /* Read the tuple header. */
107 bp
= streamer_read_bitpack (ib
);
108 num_ops
= bp_unpack_var_len_unsigned (&bp
);
109 stmt
= gimple_alloc (code
, num_ops
);
110 stmt
->no_warning
= bp_unpack_value (&bp
, 1);
111 if (is_gimple_assign (stmt
))
112 stmt
->nontemporal_move
= bp_unpack_value (&bp
, 1);
113 stmt
->has_volatile_ops
= bp_unpack_value (&bp
, 1);
114 has_hist
= bp_unpack_value (&bp
, 1);
115 stmt
->subcode
= bp_unpack_var_len_unsigned (&bp
);
117 /* Read location information. Caching here makes no sense until streamer
118 cache can handle the following gimple_set_block. */
119 gimple_set_location (stmt
, stream_input_location_now (&bp
, data_in
));
121 /* Read lexical block reference. */
122 gimple_set_block (stmt
, stream_read_tree (ib
, data_in
));
124 /* Read in all the operands. */
128 gimple_resx_set_region (as_a
<gresx
*> (stmt
),
129 streamer_read_hwi (ib
));
132 case GIMPLE_EH_MUST_NOT_THROW
:
133 gimple_eh_must_not_throw_set_fndecl (
134 as_a
<geh_mnt
*> (stmt
),
135 stream_read_tree (ib
, data_in
));
138 case GIMPLE_EH_DISPATCH
:
139 gimple_eh_dispatch_set_region (as_a
<geh_dispatch
*> (stmt
),
140 streamer_read_hwi (ib
));
145 /* FIXME lto. Move most of this into a new gimple_asm_set_string(). */
146 gasm
*asm_stmt
= as_a
<gasm
*> (stmt
);
148 asm_stmt
->ni
= streamer_read_uhwi (ib
);
149 asm_stmt
->no
= streamer_read_uhwi (ib
);
150 asm_stmt
->nc
= streamer_read_uhwi (ib
);
151 asm_stmt
->nl
= streamer_read_uhwi (ib
);
152 str
= streamer_read_string_cst (data_in
, ib
);
153 asm_stmt
->string
= TREE_STRING_POINTER (str
);
165 for (i
= 0; i
< num_ops
; i
++)
167 tree
*opp
, op
= stream_read_tree (ib
, data_in
);
168 gimple_set_op (stmt
, i
, op
);
172 opp
= gimple_op_ptr (stmt
, i
);
173 if (TREE_CODE (*opp
) == ADDR_EXPR
)
174 opp
= &TREE_OPERAND (*opp
, 0);
175 while (handled_component_p (*opp
))
176 opp
= &TREE_OPERAND (*opp
, 0);
177 /* At LTO output time we wrap all global decls in MEM_REFs to
178 allow seamless replacement with prevailing decls. Undo this
179 here if the prevailing decl allows for this.
180 ??? Maybe we should simply fold all stmts. */
181 if (TREE_CODE (*opp
) == MEM_REF
182 && TREE_CODE (TREE_OPERAND (*opp
, 0)) == ADDR_EXPR
183 && integer_zerop (TREE_OPERAND (*opp
, 1))
184 && (TREE_THIS_VOLATILE (*opp
)
185 == TREE_THIS_VOLATILE
186 (TREE_OPERAND (TREE_OPERAND (*opp
, 0), 0)))
187 && !TYPE_REF_CAN_ALIAS_ALL (TREE_TYPE (TREE_OPERAND (*opp
, 1)))
189 == TREE_TYPE (TREE_TYPE (TREE_OPERAND (*opp
, 1))))
191 == TREE_TYPE (TREE_OPERAND (TREE_OPERAND (*opp
, 0), 0))))
192 *opp
= TREE_OPERAND (TREE_OPERAND (*opp
, 0), 0);
194 if (gcall
*call_stmt
= dyn_cast
<gcall
*> (stmt
))
196 if (gimple_call_internal_p (call_stmt
))
197 gimple_call_set_internal_fn
198 (call_stmt
, streamer_read_enum (ib
, internal_fn
, IFN_LAST
));
200 gimple_call_set_fntype (call_stmt
, stream_read_tree (ib
, data_in
));
208 case GIMPLE_TRANSACTION
:
209 gimple_transaction_set_label (as_a
<gtransaction
*> (stmt
),
210 stream_read_tree (ib
, data_in
));
214 internal_error ("bytecode stream: unknown GIMPLE statement tag %s",
218 /* Update the properties of symbols, SSA names and labels associated
220 if (code
== GIMPLE_ASSIGN
|| code
== GIMPLE_CALL
)
222 tree lhs
= gimple_get_lhs (stmt
);
223 if (lhs
&& TREE_CODE (lhs
) == SSA_NAME
)
224 SSA_NAME_DEF_STMT (lhs
) = stmt
;
226 else if (code
== GIMPLE_ASM
)
228 gasm
*asm_stmt
= as_a
<gasm
*> (stmt
);
231 for (i
= 0; i
< gimple_asm_noutputs (asm_stmt
); i
++)
233 tree op
= TREE_VALUE (gimple_asm_output_op (asm_stmt
, i
));
234 if (TREE_CODE (op
) == SSA_NAME
)
235 SSA_NAME_DEF_STMT (op
) = stmt
;
239 /* Reset alias information. */
240 if (code
== GIMPLE_CALL
)
241 gimple_call_reset_alias_info (as_a
<gcall
*> (stmt
));
243 /* Mark the statement modified so its operand vectors can be filled in. */
244 gimple_set_modified (stmt
, true);
246 stream_in_histogram_value (ib
, stmt
);
252 /* Read a basic block with tag TAG from DATA_IN using input block IB.
253 FN is the function being processed. */
256 input_bb (struct lto_input_block
*ib
, enum LTO_tags tag
,
257 struct data_in
*data_in
, struct function
*fn
,
258 int count_materialization_scale
)
262 gimple_stmt_iterator bsi
;
264 /* This routine assumes that CFUN is set to FN, as it needs to call
265 basic GIMPLE routines that use CFUN. */
266 gcc_assert (cfun
== fn
);
268 index
= streamer_read_uhwi (ib
);
269 bb
= BASIC_BLOCK_FOR_FN (fn
, index
);
271 bb
->count
= apply_scale (streamer_read_gcov_count (ib
),
272 count_materialization_scale
);
273 bb
->frequency
= streamer_read_hwi (ib
);
274 bb
->flags
= streamer_read_hwi (ib
);
276 /* LTO_bb1 has statements. LTO_bb0 does not. */
280 bsi
= gsi_start_bb (bb
);
281 tag
= streamer_read_record_start (ib
);
284 gimple stmt
= input_gimple_stmt (ib
, data_in
, tag
);
285 gsi_insert_after (&bsi
, stmt
, GSI_NEW_STMT
);
287 /* After the statement, expect a 0 delimiter or the EH region
288 that the previous statement belongs to. */
289 tag
= streamer_read_record_start (ib
);
290 lto_tag_check_set (tag
, 2, LTO_eh_region
, LTO_null
);
292 if (tag
== LTO_eh_region
)
294 HOST_WIDE_INT region
= streamer_read_hwi (ib
);
295 gcc_assert (region
== (int) region
);
296 add_stmt_to_eh_lp (stmt
, region
);
299 tag
= streamer_read_record_start (ib
);
302 tag
= streamer_read_record_start (ib
);
305 input_phi (ib
, bb
, data_in
, fn
);
306 tag
= streamer_read_record_start (ib
);