1 /* Routines for reading GIMPLE from a file stream.
3 Copyright (C) 2011-2014 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"
33 #include "hard-reg-set.h"
36 #include "dominance.h"
38 #include "basic-block.h"
39 #include "tree-ssa-alias.h"
40 #include "internal-fn.h"
42 #include "gimple-expr.h"
45 #include "gimple-iterator.h"
46 #include "gimple-ssa.h"
47 #include "tree-phinodes.h"
48 #include "stringpool.h"
49 #include "tree-ssanames.h"
51 #include "plugin-api.h"
54 #include "data-streamer.h"
55 #include "tree-streamer.h"
56 #include "gimple-streamer.h"
57 #include "value-prof.h"
59 /* Read a PHI function for basic block BB in function FN. DATA_IN is
60 the file being read. IB is the input block to use for reading. */
63 input_phi (struct lto_input_block
*ib
, basic_block bb
, struct data_in
*data_in
,
66 unsigned HOST_WIDE_INT ix
;
71 ix
= streamer_read_uhwi (ib
);
72 phi_result
= (*SSANAMES (fn
))[ix
];
73 len
= EDGE_COUNT (bb
->preds
);
74 result
= create_phi_node (phi_result
, bb
);
76 /* We have to go through a lookup process here because the preds in the
77 reconstructed graph are generally in a different order than they
78 were in the original program. */
79 for (i
= 0; i
< len
; i
++)
81 tree def
= stream_read_tree (ib
, data_in
);
82 int src_index
= streamer_read_uhwi (ib
);
83 bitpack_d bp
= streamer_read_bitpack (ib
);
84 location_t arg_loc
= stream_input_location (&bp
, data_in
);
85 basic_block sbb
= BASIC_BLOCK_FOR_FN (fn
, src_index
);
90 for (j
= 0; j
< len
; j
++)
91 if (EDGE_PRED (bb
, j
)->src
== sbb
)
93 e
= EDGE_PRED (bb
, j
);
97 add_phi_arg (result
, def
, e
, arg_loc
);
104 /* Read a statement with tag TAG in function FN from block IB using
105 descriptors in DATA_IN. */
108 input_gimple_stmt (struct lto_input_block
*ib
, struct data_in
*data_in
,
112 enum gimple_code code
;
113 unsigned HOST_WIDE_INT num_ops
;
118 code
= lto_tag_to_gimple_code (tag
);
120 /* Read the tuple header. */
121 bp
= streamer_read_bitpack (ib
);
122 num_ops
= bp_unpack_var_len_unsigned (&bp
);
123 stmt
= gimple_alloc (code
, num_ops
);
124 stmt
->no_warning
= bp_unpack_value (&bp
, 1);
125 if (is_gimple_assign (stmt
))
126 stmt
->nontemporal_move
= bp_unpack_value (&bp
, 1);
127 stmt
->has_volatile_ops
= bp_unpack_value (&bp
, 1);
128 has_hist
= bp_unpack_value (&bp
, 1);
129 stmt
->subcode
= bp_unpack_var_len_unsigned (&bp
);
131 /* Read location information. */
132 gimple_set_location (stmt
, stream_input_location (&bp
, data_in
));
134 /* Read lexical block reference. */
135 gimple_set_block (stmt
, stream_read_tree (ib
, data_in
));
137 /* Read in all the operands. */
141 gimple_resx_set_region (stmt
, streamer_read_hwi (ib
));
144 case GIMPLE_EH_MUST_NOT_THROW
:
145 gimple_eh_must_not_throw_set_fndecl (stmt
, stream_read_tree (ib
, data_in
));
148 case GIMPLE_EH_DISPATCH
:
149 gimple_eh_dispatch_set_region (stmt
, streamer_read_hwi (ib
));
154 /* FIXME lto. Move most of this into a new gimple_asm_set_string(). */
155 gimple_statement_asm
*asm_stmt
= as_a
<gimple_statement_asm
*> (stmt
);
157 asm_stmt
->ni
= streamer_read_uhwi (ib
);
158 asm_stmt
->no
= streamer_read_uhwi (ib
);
159 asm_stmt
->nc
= streamer_read_uhwi (ib
);
160 asm_stmt
->nl
= streamer_read_uhwi (ib
);
161 str
= streamer_read_string_cst (data_in
, ib
);
162 asm_stmt
->string
= TREE_STRING_POINTER (str
);
174 for (i
= 0; i
< num_ops
; i
++)
176 tree
*opp
, op
= stream_read_tree (ib
, data_in
);
177 gimple_set_op (stmt
, i
, op
);
181 opp
= gimple_op_ptr (stmt
, i
);
182 if (TREE_CODE (*opp
) == ADDR_EXPR
)
183 opp
= &TREE_OPERAND (*opp
, 0);
184 while (handled_component_p (*opp
))
185 opp
= &TREE_OPERAND (*opp
, 0);
186 /* At LTO output time we wrap all global decls in MEM_REFs to
187 allow seamless replacement with prevailing decls. Undo this
188 here if the prevailing decl allows for this.
189 ??? Maybe we should simply fold all stmts. */
190 if (TREE_CODE (*opp
) == MEM_REF
191 && TREE_CODE (TREE_OPERAND (*opp
, 0)) == ADDR_EXPR
192 && integer_zerop (TREE_OPERAND (*opp
, 1))
193 && (TREE_THIS_VOLATILE (*opp
)
194 == TREE_THIS_VOLATILE
195 (TREE_OPERAND (TREE_OPERAND (*opp
, 0), 0)))
196 && !TYPE_REF_CAN_ALIAS_ALL (TREE_TYPE (TREE_OPERAND (*opp
, 1)))
198 == TREE_TYPE (TREE_TYPE (TREE_OPERAND (*opp
, 1))))
200 == TREE_TYPE (TREE_OPERAND (TREE_OPERAND (*opp
, 0), 0))))
201 *opp
= TREE_OPERAND (TREE_OPERAND (*opp
, 0), 0);
203 if (is_gimple_call (stmt
))
205 if (gimple_call_internal_p (stmt
))
206 gimple_call_set_internal_fn
207 (stmt
, streamer_read_enum (ib
, internal_fn
, IFN_LAST
));
209 gimple_call_set_fntype (stmt
, stream_read_tree (ib
, data_in
));
217 case GIMPLE_TRANSACTION
:
218 gimple_transaction_set_label (stmt
, stream_read_tree (ib
, data_in
));
222 internal_error ("bytecode stream: unknown GIMPLE statement tag %s",
226 /* Update the properties of symbols, SSA names and labels associated
228 if (code
== GIMPLE_ASSIGN
|| code
== GIMPLE_CALL
)
230 tree lhs
= gimple_get_lhs (stmt
);
231 if (lhs
&& TREE_CODE (lhs
) == SSA_NAME
)
232 SSA_NAME_DEF_STMT (lhs
) = stmt
;
234 else if (code
== GIMPLE_ASM
)
238 for (i
= 0; i
< gimple_asm_noutputs (stmt
); i
++)
240 tree op
= TREE_VALUE (gimple_asm_output_op (stmt
, i
));
241 if (TREE_CODE (op
) == SSA_NAME
)
242 SSA_NAME_DEF_STMT (op
) = stmt
;
246 /* Reset alias information. */
247 if (code
== GIMPLE_CALL
)
248 gimple_call_reset_alias_info (stmt
);
250 /* Mark the statement modified so its operand vectors can be filled in. */
251 gimple_set_modified (stmt
, true);
253 stream_in_histogram_value (ib
, stmt
);
259 /* Read a basic block with tag TAG from DATA_IN using input block IB.
260 FN is the function being processed. */
263 input_bb (struct lto_input_block
*ib
, enum LTO_tags tag
,
264 struct data_in
*data_in
, struct function
*fn
,
265 int count_materialization_scale
)
269 gimple_stmt_iterator bsi
;
271 /* This routine assumes that CFUN is set to FN, as it needs to call
272 basic GIMPLE routines that use CFUN. */
273 gcc_assert (cfun
== fn
);
275 index
= streamer_read_uhwi (ib
);
276 bb
= BASIC_BLOCK_FOR_FN (fn
, index
);
278 bb
->count
= apply_scale (streamer_read_gcov_count (ib
),
279 count_materialization_scale
);
280 bb
->frequency
= streamer_read_hwi (ib
);
281 bb
->flags
= streamer_read_hwi (ib
);
283 /* LTO_bb1 has statements. LTO_bb0 does not. */
287 bsi
= gsi_start_bb (bb
);
288 tag
= streamer_read_record_start (ib
);
291 gimple stmt
= input_gimple_stmt (ib
, data_in
, tag
);
292 gsi_insert_after (&bsi
, stmt
, GSI_NEW_STMT
);
294 /* After the statement, expect a 0 delimiter or the EH region
295 that the previous statement belongs to. */
296 tag
= streamer_read_record_start (ib
);
297 lto_tag_check_set (tag
, 2, LTO_eh_region
, LTO_null
);
299 if (tag
== LTO_eh_region
)
301 HOST_WIDE_INT region
= streamer_read_hwi (ib
);
302 gcc_assert (region
== (int) region
);
303 add_stmt_to_eh_lp (stmt
, region
);
306 tag
= streamer_read_record_start (ib
);
309 tag
= streamer_read_record_start (ib
);
312 input_phi (ib
, bb
, data_in
, fn
);
313 tag
= streamer_read_record_start (ib
);