* gcc.dg/store-motion-fgcse-sm.c (dg-final): Cleanup
[official-gcc.git] / gcc / gimple-streamer-in.c
blob21b9c0e07b278acb9f1e420695b960664717a728
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
11 version.
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
16 for more details.
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/>. */
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "diagnostic.h"
26 #include "tree.h"
27 #include "predict.h"
28 #include "vec.h"
29 #include "hashtab.h"
30 #include "hash-set.h"
31 #include "machmode.h"
32 #include "tm.h"
33 #include "hard-reg-set.h"
34 #include "input.h"
35 #include "function.h"
36 #include "dominance.h"
37 #include "cfg.h"
38 #include "basic-block.h"
39 #include "tree-ssa-alias.h"
40 #include "internal-fn.h"
41 #include "tree-eh.h"
42 #include "gimple-expr.h"
43 #include "is-a.h"
44 #include "gimple.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"
50 #include "hash-map.h"
51 #include "plugin-api.h"
52 #include "ipa-ref.h"
53 #include "cgraph.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. */
62 static gphi *
63 input_phi (struct lto_input_block *ib, basic_block bb, struct data_in *data_in,
64 struct function *fn)
66 unsigned HOST_WIDE_INT ix;
67 tree phi_result;
68 int i, len;
69 gphi *result;
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);
87 edge e = NULL;
88 int j;
90 for (j = 0; j < len; j++)
91 if (EDGE_PRED (bb, j)->src == sbb)
93 e = EDGE_PRED (bb, j);
94 break;
97 add_phi_arg (result, def, e, arg_loc);
100 return result;
104 /* Read a statement with tag TAG in function FN from block IB using
105 descriptors in DATA_IN. */
107 static gimple
108 input_gimple_stmt (struct lto_input_block *ib, struct data_in *data_in,
109 enum LTO_tags tag)
111 gimple stmt;
112 enum gimple_code code;
113 unsigned HOST_WIDE_INT num_ops;
114 size_t i;
115 struct bitpack_d bp;
116 bool has_hist;
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. */
138 switch (code)
140 case GIMPLE_RESX:
141 gimple_resx_set_region (as_a <gresx *> (stmt),
142 streamer_read_hwi (ib));
143 break;
145 case GIMPLE_EH_MUST_NOT_THROW:
146 gimple_eh_must_not_throw_set_fndecl (
147 as_a <geh_mnt *> (stmt),
148 stream_read_tree (ib, data_in));
149 break;
151 case GIMPLE_EH_DISPATCH:
152 gimple_eh_dispatch_set_region (as_a <geh_dispatch *> (stmt),
153 streamer_read_hwi (ib));
154 break;
156 case GIMPLE_ASM:
158 /* FIXME lto. Move most of this into a new gimple_asm_set_string(). */
159 gasm *asm_stmt = as_a <gasm *> (stmt);
160 tree str;
161 asm_stmt->ni = streamer_read_uhwi (ib);
162 asm_stmt->no = streamer_read_uhwi (ib);
163 asm_stmt->nc = streamer_read_uhwi (ib);
164 asm_stmt->nl = streamer_read_uhwi (ib);
165 str = streamer_read_string_cst (data_in, ib);
166 asm_stmt->string = TREE_STRING_POINTER (str);
168 /* Fallthru */
170 case GIMPLE_ASSIGN:
171 case GIMPLE_CALL:
172 case GIMPLE_RETURN:
173 case GIMPLE_SWITCH:
174 case GIMPLE_LABEL:
175 case GIMPLE_COND:
176 case GIMPLE_GOTO:
177 case GIMPLE_DEBUG:
178 for (i = 0; i < num_ops; i++)
180 tree *opp, op = stream_read_tree (ib, data_in);
181 gimple_set_op (stmt, i, op);
182 if (!op)
183 continue;
185 opp = gimple_op_ptr (stmt, i);
186 if (TREE_CODE (*opp) == ADDR_EXPR)
187 opp = &TREE_OPERAND (*opp, 0);
188 while (handled_component_p (*opp))
189 opp = &TREE_OPERAND (*opp, 0);
190 /* At LTO output time we wrap all global decls in MEM_REFs to
191 allow seamless replacement with prevailing decls. Undo this
192 here if the prevailing decl allows for this.
193 ??? Maybe we should simply fold all stmts. */
194 if (TREE_CODE (*opp) == MEM_REF
195 && TREE_CODE (TREE_OPERAND (*opp, 0)) == ADDR_EXPR
196 && integer_zerop (TREE_OPERAND (*opp, 1))
197 && (TREE_THIS_VOLATILE (*opp)
198 == TREE_THIS_VOLATILE
199 (TREE_OPERAND (TREE_OPERAND (*opp, 0), 0)))
200 && !TYPE_REF_CAN_ALIAS_ALL (TREE_TYPE (TREE_OPERAND (*opp, 1)))
201 && (TREE_TYPE (*opp)
202 == TREE_TYPE (TREE_TYPE (TREE_OPERAND (*opp, 1))))
203 && (TREE_TYPE (*opp)
204 == TREE_TYPE (TREE_OPERAND (TREE_OPERAND (*opp, 0), 0))))
205 *opp = TREE_OPERAND (TREE_OPERAND (*opp, 0), 0);
207 if (gcall *call_stmt = dyn_cast <gcall *> (stmt))
209 if (gimple_call_internal_p (call_stmt))
210 gimple_call_set_internal_fn
211 (call_stmt, streamer_read_enum (ib, internal_fn, IFN_LAST));
212 else
213 gimple_call_set_fntype (call_stmt, stream_read_tree (ib, data_in));
215 break;
217 case GIMPLE_NOP:
218 case GIMPLE_PREDICT:
219 break;
221 case GIMPLE_TRANSACTION:
222 gimple_transaction_set_label (as_a <gtransaction *> (stmt),
223 stream_read_tree (ib, data_in));
224 break;
226 default:
227 internal_error ("bytecode stream: unknown GIMPLE statement tag %s",
228 lto_tag_name (tag));
231 /* Update the properties of symbols, SSA names and labels associated
232 with STMT. */
233 if (code == GIMPLE_ASSIGN || code == GIMPLE_CALL)
235 tree lhs = gimple_get_lhs (stmt);
236 if (lhs && TREE_CODE (lhs) == SSA_NAME)
237 SSA_NAME_DEF_STMT (lhs) = stmt;
239 else if (code == GIMPLE_ASM)
241 gasm *asm_stmt = as_a <gasm *> (stmt);
242 unsigned i;
244 for (i = 0; i < gimple_asm_noutputs (asm_stmt); i++)
246 tree op = TREE_VALUE (gimple_asm_output_op (asm_stmt, i));
247 if (TREE_CODE (op) == SSA_NAME)
248 SSA_NAME_DEF_STMT (op) = stmt;
252 /* Reset alias information. */
253 if (code == GIMPLE_CALL)
254 gimple_call_reset_alias_info (as_a <gcall *> (stmt));
256 /* Mark the statement modified so its operand vectors can be filled in. */
257 gimple_set_modified (stmt, true);
258 if (has_hist)
259 stream_in_histogram_value (ib, stmt);
261 return stmt;
265 /* Read a basic block with tag TAG from DATA_IN using input block IB.
266 FN is the function being processed. */
268 void
269 input_bb (struct lto_input_block *ib, enum LTO_tags tag,
270 struct data_in *data_in, struct function *fn,
271 int count_materialization_scale)
273 unsigned int index;
274 basic_block bb;
275 gimple_stmt_iterator bsi;
277 /* This routine assumes that CFUN is set to FN, as it needs to call
278 basic GIMPLE routines that use CFUN. */
279 gcc_assert (cfun == fn);
281 index = streamer_read_uhwi (ib);
282 bb = BASIC_BLOCK_FOR_FN (fn, index);
284 bb->count = apply_scale (streamer_read_gcov_count (ib),
285 count_materialization_scale);
286 bb->frequency = streamer_read_hwi (ib);
287 bb->flags = streamer_read_hwi (ib);
289 /* LTO_bb1 has statements. LTO_bb0 does not. */
290 if (tag == LTO_bb0)
291 return;
293 bsi = gsi_start_bb (bb);
294 tag = streamer_read_record_start (ib);
295 while (tag)
297 gimple stmt = input_gimple_stmt (ib, data_in, tag);
298 gsi_insert_after (&bsi, stmt, GSI_NEW_STMT);
300 /* After the statement, expect a 0 delimiter or the EH region
301 that the previous statement belongs to. */
302 tag = streamer_read_record_start (ib);
303 lto_tag_check_set (tag, 2, LTO_eh_region, LTO_null);
305 if (tag == LTO_eh_region)
307 HOST_WIDE_INT region = streamer_read_hwi (ib);
308 gcc_assert (region == (int) region);
309 add_stmt_to_eh_lp (stmt, region);
312 tag = streamer_read_record_start (ib);
315 tag = streamer_read_record_start (ib);
316 while (tag)
318 input_phi (ib, bb, data_in, fn);
319 tag = streamer_read_record_start (ib);