]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/gimple-streamer-in.c
Merger of git branch "gimple-classes-v2-option-3"
[thirdparty/gcc.git] / gcc / gimple-streamer-in.c
CommitLineData
f0efc7aa
DN
1/* Routines for reading GIMPLE from a file stream.
2
23a5b65a 3 Copyright (C) 2011-2014 Free Software Foundation, Inc.
f0efc7aa
DN
4 Contributed by Diego Novillo <dnovillo@google.com>
5
6This file is part of GCC.
7
8GCC is free software; you can redistribute it and/or modify it under
9the terms of the GNU General Public License as published by the Free
10Software Foundation; either version 3, or (at your option) any later
11version.
12
13GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14WARRANTY; without even the implied warranty of MERCHANTABILITY or
15FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16for more details.
17
18You should have received a copy of the GNU General Public License
19along 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 "tree.h"
60393bbc
AM
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"
2fb9a547
AM
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"
442b4905 44#include "gimple.h"
5be5c238 45#include "gimple-iterator.h"
442b4905
AM
46#include "gimple-ssa.h"
47#include "tree-phinodes.h"
d8a2d370 48#include "stringpool.h"
442b4905 49#include "tree-ssanames.h"
c582198b
AM
50#include "hash-map.h"
51#include "plugin-api.h"
52#include "ipa-ref.h"
53#include "cgraph.h"
f0efc7aa
DN
54#include "data-streamer.h"
55#include "tree-streamer.h"
56#include "gimple-streamer.h"
89ab31c1 57#include "value-prof.h"
f0efc7aa
DN
58
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. */
61
538dd0b7 62static gphi *
f0efc7aa
DN
63input_phi (struct lto_input_block *ib, basic_block bb, struct data_in *data_in,
64 struct function *fn)
65{
66 unsigned HOST_WIDE_INT ix;
67 tree phi_result;
68 int i, len;
538dd0b7 69 gphi *result;
f0efc7aa 70
412288f1 71 ix = streamer_read_uhwi (ib);
9771b263 72 phi_result = (*SSANAMES (fn))[ix];
f0efc7aa
DN
73 len = EDGE_COUNT (bb->preds);
74 result = create_phi_node (phi_result, bb);
f0efc7aa
DN
75
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++)
80 {
b9393656 81 tree def = stream_read_tree (ib, data_in);
412288f1 82 int src_index = streamer_read_uhwi (ib);
7cb7d208
RB
83 bitpack_d bp = streamer_read_bitpack (ib);
84 location_t arg_loc = stream_input_location (&bp, data_in);
bbd79259 85 basic_block sbb = BASIC_BLOCK_FOR_FN (fn, src_index);
f0efc7aa
DN
86
87 edge e = NULL;
88 int j;
89
90 for (j = 0; j < len; j++)
91 if (EDGE_PRED (bb, j)->src == sbb)
92 {
93 e = EDGE_PRED (bb, j);
94 break;
95 }
96
9e227d60 97 add_phi_arg (result, def, e, arg_loc);
f0efc7aa
DN
98 }
99
100 return result;
101}
102
103
104/* Read a statement with tag TAG in function FN from block IB using
105 descriptors in DATA_IN. */
106
107static gimple
108input_gimple_stmt (struct lto_input_block *ib, struct data_in *data_in,
8356c89c 109 enum LTO_tags tag)
f0efc7aa
DN
110{
111 gimple stmt;
112 enum gimple_code code;
113 unsigned HOST_WIDE_INT num_ops;
114 size_t i;
115 struct bitpack_d bp;
89ab31c1 116 bool has_hist;
f0efc7aa
DN
117
118 code = lto_tag_to_gimple_code (tag);
119
120 /* Read the tuple header. */
412288f1 121 bp = streamer_read_bitpack (ib);
f0efc7aa
DN
122 num_ops = bp_unpack_var_len_unsigned (&bp);
123 stmt = gimple_alloc (code, num_ops);
daa6e488 124 stmt->no_warning = bp_unpack_value (&bp, 1);
f0efc7aa 125 if (is_gimple_assign (stmt))
daa6e488
DM
126 stmt->nontemporal_move = bp_unpack_value (&bp, 1);
127 stmt->has_volatile_ops = bp_unpack_value (&bp, 1);
89ab31c1 128 has_hist = bp_unpack_value (&bp, 1);
daa6e488 129 stmt->subcode = bp_unpack_var_len_unsigned (&bp);
f0efc7aa
DN
130
131 /* Read location information. */
7cb7d208 132 gimple_set_location (stmt, stream_input_location (&bp, data_in));
f0efc7aa
DN
133
134 /* Read lexical block reference. */
b9393656 135 gimple_set_block (stmt, stream_read_tree (ib, data_in));
f0efc7aa
DN
136
137 /* Read in all the operands. */
138 switch (code)
139 {
140 case GIMPLE_RESX:
538dd0b7
DM
141 gimple_resx_set_region (as_a <gresx *> (stmt),
142 streamer_read_hwi (ib));
f0efc7aa
DN
143 break;
144
145 case GIMPLE_EH_MUST_NOT_THROW:
538dd0b7
DM
146 gimple_eh_must_not_throw_set_fndecl (
147 as_a <geh_mnt *> (stmt),
148 stream_read_tree (ib, data_in));
f0efc7aa
DN
149 break;
150
151 case GIMPLE_EH_DISPATCH:
538dd0b7
DM
152 gimple_eh_dispatch_set_region (as_a <geh_dispatch *> (stmt),
153 streamer_read_hwi (ib));
f0efc7aa
DN
154 break;
155
156 case GIMPLE_ASM:
157 {
158 /* FIXME lto. Move most of this into a new gimple_asm_set_string(). */
538dd0b7 159 gasm *asm_stmt = as_a <gasm *> (stmt);
f0efc7aa 160 tree str;
daa6e488
DM
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);
412288f1 165 str = streamer_read_string_cst (data_in, ib);
daa6e488 166 asm_stmt->string = TREE_STRING_POINTER (str);
f0efc7aa
DN
167 }
168 /* Fallthru */
169
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++)
179 {
43320568 180 tree *opp, op = stream_read_tree (ib, data_in);
f0efc7aa
DN
181 gimple_set_op (stmt, i, op);
182 if (!op)
183 continue;
184
43320568
RB
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))
3fede979 189 opp = &TREE_OPERAND (*opp, 0);
43320568
RB
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);
f0efc7aa 206 }
538dd0b7 207 if (gcall *call_stmt = dyn_cast <gcall *> (stmt))
f0efc7aa 208 {
538dd0b7 209 if (gimple_call_internal_p (call_stmt))
f0efc7aa 210 gimple_call_set_internal_fn
538dd0b7 211 (call_stmt, streamer_read_enum (ib, internal_fn, IFN_LAST));
f0efc7aa 212 else
538dd0b7 213 gimple_call_set_fntype (call_stmt, stream_read_tree (ib, data_in));
f0efc7aa
DN
214 }
215 break;
216
217 case GIMPLE_NOP:
218 case GIMPLE_PREDICT:
219 break;
220
57ac2606 221 case GIMPLE_TRANSACTION:
538dd0b7
DM
222 gimple_transaction_set_label (as_a <gtransaction *> (stmt),
223 stream_read_tree (ib, data_in));
57ac2606
AH
224 break;
225
f0efc7aa
DN
226 default:
227 internal_error ("bytecode stream: unknown GIMPLE statement tag %s",
228 lto_tag_name (tag));
229 }
230
231 /* Update the properties of symbols, SSA names and labels associated
232 with STMT. */
233 if (code == GIMPLE_ASSIGN || code == GIMPLE_CALL)
234 {
235 tree lhs = gimple_get_lhs (stmt);
236 if (lhs && TREE_CODE (lhs) == SSA_NAME)
237 SSA_NAME_DEF_STMT (lhs) = stmt;
238 }
f0efc7aa
DN
239 else if (code == GIMPLE_ASM)
240 {
538dd0b7 241 gasm *asm_stmt = as_a <gasm *> (stmt);
f0efc7aa
DN
242 unsigned i;
243
538dd0b7 244 for (i = 0; i < gimple_asm_noutputs (asm_stmt); i++)
f0efc7aa 245 {
538dd0b7 246 tree op = TREE_VALUE (gimple_asm_output_op (asm_stmt, i));
f0efc7aa
DN
247 if (TREE_CODE (op) == SSA_NAME)
248 SSA_NAME_DEF_STMT (op) = stmt;
249 }
250 }
251
252 /* Reset alias information. */
253 if (code == GIMPLE_CALL)
538dd0b7 254 gimple_call_reset_alias_info (as_a <gcall *> (stmt));
f0efc7aa
DN
255
256 /* Mark the statement modified so its operand vectors can be filled in. */
257 gimple_set_modified (stmt, true);
89ab31c1
JH
258 if (has_hist)
259 stream_in_histogram_value (ib, stmt);
f0efc7aa
DN
260
261 return stmt;
262}
263
264
265/* Read a basic block with tag TAG from DATA_IN using input block IB.
266 FN is the function being processed. */
267
268void
269input_bb (struct lto_input_block *ib, enum LTO_tags tag,
270 struct data_in *data_in, struct function *fn,
271 int count_materialization_scale)
272{
273 unsigned int index;
274 basic_block bb;
275 gimple_stmt_iterator bsi;
276
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);
280
412288f1 281 index = streamer_read_uhwi (ib);
bbd79259 282 bb = BASIC_BLOCK_FOR_FN (fn, index);
f0efc7aa 283
f41f80f9
TJ
284 bb->count = apply_scale (streamer_read_gcov_count (ib),
285 count_materialization_scale);
412288f1
DN
286 bb->frequency = streamer_read_hwi (ib);
287 bb->flags = streamer_read_hwi (ib);
f0efc7aa
DN
288
289 /* LTO_bb1 has statements. LTO_bb0 does not. */
290 if (tag == LTO_bb0)
291 return;
292
293 bsi = gsi_start_bb (bb);
412288f1 294 tag = streamer_read_record_start (ib);
f0efc7aa
DN
295 while (tag)
296 {
8356c89c 297 gimple stmt = input_gimple_stmt (ib, data_in, tag);
f0efc7aa
DN
298 gsi_insert_after (&bsi, stmt, GSI_NEW_STMT);
299
300 /* After the statement, expect a 0 delimiter or the EH region
301 that the previous statement belongs to. */
412288f1 302 tag = streamer_read_record_start (ib);
f0efc7aa
DN
303 lto_tag_check_set (tag, 2, LTO_eh_region, LTO_null);
304
305 if (tag == LTO_eh_region)
306 {
412288f1 307 HOST_WIDE_INT region = streamer_read_hwi (ib);
f0efc7aa
DN
308 gcc_assert (region == (int) region);
309 add_stmt_to_eh_lp (stmt, region);
310 }
311
412288f1 312 tag = streamer_read_record_start (ib);
f0efc7aa
DN
313 }
314
412288f1 315 tag = streamer_read_record_start (ib);
f0efc7aa
DN
316 while (tag)
317 {
46eb666a 318 input_phi (ib, bb, data_in, fn);
412288f1 319 tag = streamer_read_record_start (ib);
f0efc7aa
DN
320 }
321}