]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/gimple-streamer-in.c
coretypes.h: Include machmode.h...
[thirdparty/gcc.git] / gcc / gimple-streamer-in.c
1 /* Routines for reading GIMPLE from a file stream.
2
3 Copyright (C) 2011-2015 Free Software Foundation, Inc.
4 Contributed by Diego Novillo <dnovillo@google.com>
5
6 This file is part of GCC.
7
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.
12
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.
17
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/>. */
21
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "diagnostic.h"
26 #include "hash-set.h"
27 #include "vec.h"
28 #include "input.h"
29 #include "alias.h"
30 #include "symtab.h"
31 #include "options.h"
32 #include "inchash.h"
33 #include "tree.h"
34 #include "fold-const.h"
35 #include "predict.h"
36 #include "tm.h"
37 #include "hard-reg-set.h"
38 #include "input.h"
39 #include "function.h"
40 #include "dominance.h"
41 #include "cfg.h"
42 #include "basic-block.h"
43 #include "tree-ssa-alias.h"
44 #include "internal-fn.h"
45 #include "tree-eh.h"
46 #include "gimple-expr.h"
47 #include "is-a.h"
48 #include "gimple.h"
49 #include "gimple-iterator.h"
50 #include "gimple-ssa.h"
51 #include "tree-phinodes.h"
52 #include "stringpool.h"
53 #include "tree-ssanames.h"
54 #include "plugin-api.h"
55 #include "ipa-ref.h"
56 #include "cgraph.h"
57 #include "data-streamer.h"
58 #include "tree-streamer.h"
59 #include "gimple-streamer.h"
60 #include "value-prof.h"
61
62 /* Read a PHI function for basic block BB in function FN. DATA_IN is
63 the file being read. IB is the input block to use for reading. */
64
65 static gphi *
66 input_phi (struct lto_input_block *ib, basic_block bb, struct data_in *data_in,
67 struct function *fn)
68 {
69 unsigned HOST_WIDE_INT ix;
70 tree phi_result;
71 int i, len;
72 gphi *result;
73
74 ix = streamer_read_uhwi (ib);
75 phi_result = (*SSANAMES (fn))[ix];
76 len = EDGE_COUNT (bb->preds);
77 result = create_phi_node (phi_result, bb);
78
79 /* We have to go through a lookup process here because the preds in the
80 reconstructed graph are generally in a different order than they
81 were in the original program. */
82 for (i = 0; i < len; i++)
83 {
84 tree def = stream_read_tree (ib, data_in);
85 int src_index = streamer_read_uhwi (ib);
86 bitpack_d bp = streamer_read_bitpack (ib);
87 /* Do not cache a location - we do not have API to get pointer to the
88 location in PHI statement and we may trigger reallocation. */
89 location_t arg_loc = stream_input_location_now (&bp, data_in);
90 basic_block sbb = BASIC_BLOCK_FOR_FN (fn, src_index);
91
92 edge e = NULL;
93 int j;
94
95 for (j = 0; j < len; j++)
96 if (EDGE_PRED (bb, j)->src == sbb)
97 {
98 e = EDGE_PRED (bb, j);
99 break;
100 }
101
102 add_phi_arg (result, def, e, arg_loc);
103 }
104
105 return result;
106 }
107
108
109 /* Read a statement with tag TAG in function FN from block IB using
110 descriptors in DATA_IN. */
111
112 static gimple
113 input_gimple_stmt (struct lto_input_block *ib, struct data_in *data_in,
114 enum LTO_tags tag)
115 {
116 gimple stmt;
117 enum gimple_code code;
118 unsigned HOST_WIDE_INT num_ops;
119 size_t i;
120 struct bitpack_d bp;
121 bool has_hist;
122
123 code = lto_tag_to_gimple_code (tag);
124
125 /* Read the tuple header. */
126 bp = streamer_read_bitpack (ib);
127 num_ops = bp_unpack_var_len_unsigned (&bp);
128 stmt = gimple_alloc (code, num_ops);
129 stmt->no_warning = bp_unpack_value (&bp, 1);
130 if (is_gimple_assign (stmt))
131 stmt->nontemporal_move = bp_unpack_value (&bp, 1);
132 stmt->has_volatile_ops = bp_unpack_value (&bp, 1);
133 has_hist = bp_unpack_value (&bp, 1);
134 stmt->subcode = bp_unpack_var_len_unsigned (&bp);
135
136 /* Read location information. Caching here makes no sense until streamer
137 cache can handle the following gimple_set_block. */
138 gimple_set_location (stmt, stream_input_location_now (&bp, data_in));
139
140 /* Read lexical block reference. */
141 gimple_set_block (stmt, stream_read_tree (ib, data_in));
142
143 /* Read in all the operands. */
144 switch (code)
145 {
146 case GIMPLE_RESX:
147 gimple_resx_set_region (as_a <gresx *> (stmt),
148 streamer_read_hwi (ib));
149 break;
150
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));
155 break;
156
157 case GIMPLE_EH_DISPATCH:
158 gimple_eh_dispatch_set_region (as_a <geh_dispatch *> (stmt),
159 streamer_read_hwi (ib));
160 break;
161
162 case GIMPLE_ASM:
163 {
164 /* FIXME lto. Move most of this into a new gimple_asm_set_string(). */
165 gasm *asm_stmt = as_a <gasm *> (stmt);
166 tree str;
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);
173 }
174 /* Fallthru */
175
176 case GIMPLE_ASSIGN:
177 case GIMPLE_CALL:
178 case GIMPLE_RETURN:
179 case GIMPLE_SWITCH:
180 case GIMPLE_LABEL:
181 case GIMPLE_COND:
182 case GIMPLE_GOTO:
183 case GIMPLE_DEBUG:
184 for (i = 0; i < num_ops; i++)
185 {
186 tree *opp, op = stream_read_tree (ib, data_in);
187 gimple_set_op (stmt, i, op);
188 if (!op)
189 continue;
190
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)))
207 && (TREE_TYPE (*opp)
208 == TREE_TYPE (TREE_TYPE (TREE_OPERAND (*opp, 1))))
209 && (TREE_TYPE (*opp)
210 == TREE_TYPE (TREE_OPERAND (TREE_OPERAND (*opp, 0), 0))))
211 *opp = TREE_OPERAND (TREE_OPERAND (*opp, 0), 0);
212 }
213 if (gcall *call_stmt = dyn_cast <gcall *> (stmt))
214 {
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));
218 else
219 gimple_call_set_fntype (call_stmt, stream_read_tree (ib, data_in));
220 }
221 break;
222
223 case GIMPLE_NOP:
224 case GIMPLE_PREDICT:
225 break;
226
227 case GIMPLE_TRANSACTION:
228 gimple_transaction_set_label (as_a <gtransaction *> (stmt),
229 stream_read_tree (ib, data_in));
230 break;
231
232 default:
233 internal_error ("bytecode stream: unknown GIMPLE statement tag %s",
234 lto_tag_name (tag));
235 }
236
237 /* Update the properties of symbols, SSA names and labels associated
238 with STMT. */
239 if (code == GIMPLE_ASSIGN || code == GIMPLE_CALL)
240 {
241 tree lhs = gimple_get_lhs (stmt);
242 if (lhs && TREE_CODE (lhs) == SSA_NAME)
243 SSA_NAME_DEF_STMT (lhs) = stmt;
244 }
245 else if (code == GIMPLE_ASM)
246 {
247 gasm *asm_stmt = as_a <gasm *> (stmt);
248 unsigned i;
249
250 for (i = 0; i < gimple_asm_noutputs (asm_stmt); i++)
251 {
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;
255 }
256 }
257
258 /* Reset alias information. */
259 if (code == GIMPLE_CALL)
260 gimple_call_reset_alias_info (as_a <gcall *> (stmt));
261
262 /* Mark the statement modified so its operand vectors can be filled in. */
263 gimple_set_modified (stmt, true);
264 if (has_hist)
265 stream_in_histogram_value (ib, stmt);
266
267 return stmt;
268 }
269
270
271 /* Read a basic block with tag TAG from DATA_IN using input block IB.
272 FN is the function being processed. */
273
274 void
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)
278 {
279 unsigned int index;
280 basic_block bb;
281 gimple_stmt_iterator bsi;
282
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);
286
287 index = streamer_read_uhwi (ib);
288 bb = BASIC_BLOCK_FOR_FN (fn, index);
289
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);
294
295 /* LTO_bb1 has statements. LTO_bb0 does not. */
296 if (tag == LTO_bb0)
297 return;
298
299 bsi = gsi_start_bb (bb);
300 tag = streamer_read_record_start (ib);
301 while (tag)
302 {
303 gimple stmt = input_gimple_stmt (ib, data_in, tag);
304 gsi_insert_after (&bsi, stmt, GSI_NEW_STMT);
305
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);
310
311 if (tag == LTO_eh_region)
312 {
313 HOST_WIDE_INT region = streamer_read_hwi (ib);
314 gcc_assert (region == (int) region);
315 add_stmt_to_eh_lp (stmt, region);
316 }
317
318 tag = streamer_read_record_start (ib);
319 }
320
321 tag = streamer_read_record_start (ib);
322 while (tag)
323 {
324 input_phi (ib, bb, data_in, fn);
325 tag = streamer_read_record_start (ib);
326 }
327 }