]> gcc.gnu.org Git - gcc.git/blame - gcc/gimple-streamer-in.c
invoke.texi ([Wnarrowing]): Update for non-constants in C++11.
[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"
2fb9a547
AM
27#include "basic-block.h"
28#include "tree-ssa-alias.h"
29#include "internal-fn.h"
30#include "tree-eh.h"
31#include "gimple-expr.h"
32#include "is-a.h"
442b4905 33#include "gimple.h"
5be5c238 34#include "gimple-iterator.h"
442b4905
AM
35#include "gimple-ssa.h"
36#include "tree-phinodes.h"
d8a2d370 37#include "stringpool.h"
442b4905 38#include "tree-ssanames.h"
f0efc7aa
DN
39#include "data-streamer.h"
40#include "tree-streamer.h"
41#include "gimple-streamer.h"
89ab31c1 42#include "value-prof.h"
f0efc7aa
DN
43
44/* Read a PHI function for basic block BB in function FN. DATA_IN is
45 the file being read. IB is the input block to use for reading. */
46
47static gimple
48input_phi (struct lto_input_block *ib, basic_block bb, struct data_in *data_in,
49 struct function *fn)
50{
51 unsigned HOST_WIDE_INT ix;
52 tree phi_result;
53 int i, len;
54 gimple result;
55
412288f1 56 ix = streamer_read_uhwi (ib);
9771b263 57 phi_result = (*SSANAMES (fn))[ix];
f0efc7aa
DN
58 len = EDGE_COUNT (bb->preds);
59 result = create_phi_node (phi_result, bb);
f0efc7aa
DN
60
61 /* We have to go through a lookup process here because the preds in the
62 reconstructed graph are generally in a different order than they
63 were in the original program. */
64 for (i = 0; i < len; i++)
65 {
b9393656 66 tree def = stream_read_tree (ib, data_in);
412288f1 67 int src_index = streamer_read_uhwi (ib);
7cb7d208
RB
68 bitpack_d bp = streamer_read_bitpack (ib);
69 location_t arg_loc = stream_input_location (&bp, data_in);
bbd79259 70 basic_block sbb = BASIC_BLOCK_FOR_FN (fn, src_index);
f0efc7aa
DN
71
72 edge e = NULL;
73 int j;
74
75 for (j = 0; j < len; j++)
76 if (EDGE_PRED (bb, j)->src == sbb)
77 {
78 e = EDGE_PRED (bb, j);
79 break;
80 }
81
9e227d60 82 add_phi_arg (result, def, e, arg_loc);
f0efc7aa
DN
83 }
84
85 return result;
86}
87
88
89/* Read a statement with tag TAG in function FN from block IB using
90 descriptors in DATA_IN. */
91
92static gimple
93input_gimple_stmt (struct lto_input_block *ib, struct data_in *data_in,
8356c89c 94 enum LTO_tags tag)
f0efc7aa
DN
95{
96 gimple stmt;
97 enum gimple_code code;
98 unsigned HOST_WIDE_INT num_ops;
99 size_t i;
100 struct bitpack_d bp;
89ab31c1 101 bool has_hist;
f0efc7aa
DN
102
103 code = lto_tag_to_gimple_code (tag);
104
105 /* Read the tuple header. */
412288f1 106 bp = streamer_read_bitpack (ib);
f0efc7aa
DN
107 num_ops = bp_unpack_var_len_unsigned (&bp);
108 stmt = gimple_alloc (code, num_ops);
daa6e488 109 stmt->no_warning = bp_unpack_value (&bp, 1);
f0efc7aa 110 if (is_gimple_assign (stmt))
daa6e488
DM
111 stmt->nontemporal_move = bp_unpack_value (&bp, 1);
112 stmt->has_volatile_ops = bp_unpack_value (&bp, 1);
89ab31c1 113 has_hist = bp_unpack_value (&bp, 1);
daa6e488 114 stmt->subcode = bp_unpack_var_len_unsigned (&bp);
f0efc7aa
DN
115
116 /* Read location information. */
7cb7d208 117 gimple_set_location (stmt, stream_input_location (&bp, data_in));
f0efc7aa
DN
118
119 /* Read lexical block reference. */
b9393656 120 gimple_set_block (stmt, stream_read_tree (ib, data_in));
f0efc7aa
DN
121
122 /* Read in all the operands. */
123 switch (code)
124 {
125 case GIMPLE_RESX:
412288f1 126 gimple_resx_set_region (stmt, streamer_read_hwi (ib));
f0efc7aa
DN
127 break;
128
129 case GIMPLE_EH_MUST_NOT_THROW:
b9393656 130 gimple_eh_must_not_throw_set_fndecl (stmt, stream_read_tree (ib, data_in));
f0efc7aa
DN
131 break;
132
133 case GIMPLE_EH_DISPATCH:
412288f1 134 gimple_eh_dispatch_set_region (stmt, streamer_read_hwi (ib));
f0efc7aa
DN
135 break;
136
137 case GIMPLE_ASM:
138 {
139 /* FIXME lto. Move most of this into a new gimple_asm_set_string(). */
7de90a6c 140 gimple_statement_asm *asm_stmt = as_a <gimple_statement_asm *> (stmt);
f0efc7aa 141 tree str;
daa6e488
DM
142 asm_stmt->ni = streamer_read_uhwi (ib);
143 asm_stmt->no = streamer_read_uhwi (ib);
144 asm_stmt->nc = streamer_read_uhwi (ib);
145 asm_stmt->nl = streamer_read_uhwi (ib);
412288f1 146 str = streamer_read_string_cst (data_in, ib);
daa6e488 147 asm_stmt->string = TREE_STRING_POINTER (str);
f0efc7aa
DN
148 }
149 /* Fallthru */
150
151 case GIMPLE_ASSIGN:
152 case GIMPLE_CALL:
153 case GIMPLE_RETURN:
154 case GIMPLE_SWITCH:
155 case GIMPLE_LABEL:
156 case GIMPLE_COND:
157 case GIMPLE_GOTO:
158 case GIMPLE_DEBUG:
159 for (i = 0; i < num_ops; i++)
160 {
43320568 161 tree *opp, op = stream_read_tree (ib, data_in);
f0efc7aa
DN
162 gimple_set_op (stmt, i, op);
163 if (!op)
164 continue;
165
43320568
RB
166 opp = gimple_op_ptr (stmt, i);
167 if (TREE_CODE (*opp) == ADDR_EXPR)
168 opp = &TREE_OPERAND (*opp, 0);
169 while (handled_component_p (*opp))
3fede979 170 opp = &TREE_OPERAND (*opp, 0);
43320568
RB
171 /* At LTO output time we wrap all global decls in MEM_REFs to
172 allow seamless replacement with prevailing decls. Undo this
173 here if the prevailing decl allows for this.
174 ??? Maybe we should simply fold all stmts. */
175 if (TREE_CODE (*opp) == MEM_REF
176 && TREE_CODE (TREE_OPERAND (*opp, 0)) == ADDR_EXPR
177 && integer_zerop (TREE_OPERAND (*opp, 1))
178 && (TREE_THIS_VOLATILE (*opp)
179 == TREE_THIS_VOLATILE
180 (TREE_OPERAND (TREE_OPERAND (*opp, 0), 0)))
181 && !TYPE_REF_CAN_ALIAS_ALL (TREE_TYPE (TREE_OPERAND (*opp, 1)))
182 && (TREE_TYPE (*opp)
183 == TREE_TYPE (TREE_TYPE (TREE_OPERAND (*opp, 1))))
184 && (TREE_TYPE (*opp)
185 == TREE_TYPE (TREE_OPERAND (TREE_OPERAND (*opp, 0), 0))))
186 *opp = TREE_OPERAND (TREE_OPERAND (*opp, 0), 0);
f0efc7aa
DN
187 }
188 if (is_gimple_call (stmt))
189 {
190 if (gimple_call_internal_p (stmt))
191 gimple_call_set_internal_fn
412288f1 192 (stmt, streamer_read_enum (ib, internal_fn, IFN_LAST));
f0efc7aa 193 else
b9393656 194 gimple_call_set_fntype (stmt, stream_read_tree (ib, data_in));
f0efc7aa
DN
195 }
196 break;
197
198 case GIMPLE_NOP:
199 case GIMPLE_PREDICT:
200 break;
201
57ac2606
AH
202 case GIMPLE_TRANSACTION:
203 gimple_transaction_set_label (stmt, stream_read_tree (ib, data_in));
204 break;
205
f0efc7aa
DN
206 default:
207 internal_error ("bytecode stream: unknown GIMPLE statement tag %s",
208 lto_tag_name (tag));
209 }
210
211 /* Update the properties of symbols, SSA names and labels associated
212 with STMT. */
213 if (code == GIMPLE_ASSIGN || code == GIMPLE_CALL)
214 {
215 tree lhs = gimple_get_lhs (stmt);
216 if (lhs && TREE_CODE (lhs) == SSA_NAME)
217 SSA_NAME_DEF_STMT (lhs) = stmt;
218 }
f0efc7aa
DN
219 else if (code == GIMPLE_ASM)
220 {
221 unsigned i;
222
223 for (i = 0; i < gimple_asm_noutputs (stmt); i++)
224 {
225 tree op = TREE_VALUE (gimple_asm_output_op (stmt, i));
226 if (TREE_CODE (op) == SSA_NAME)
227 SSA_NAME_DEF_STMT (op) = stmt;
228 }
229 }
230
231 /* Reset alias information. */
232 if (code == GIMPLE_CALL)
233 gimple_call_reset_alias_info (stmt);
234
235 /* Mark the statement modified so its operand vectors can be filled in. */
236 gimple_set_modified (stmt, true);
89ab31c1
JH
237 if (has_hist)
238 stream_in_histogram_value (ib, stmt);
f0efc7aa
DN
239
240 return stmt;
241}
242
243
244/* Read a basic block with tag TAG from DATA_IN using input block IB.
245 FN is the function being processed. */
246
247void
248input_bb (struct lto_input_block *ib, enum LTO_tags tag,
249 struct data_in *data_in, struct function *fn,
250 int count_materialization_scale)
251{
252 unsigned int index;
253 basic_block bb;
254 gimple_stmt_iterator bsi;
255
256 /* This routine assumes that CFUN is set to FN, as it needs to call
257 basic GIMPLE routines that use CFUN. */
258 gcc_assert (cfun == fn);
259
412288f1 260 index = streamer_read_uhwi (ib);
bbd79259 261 bb = BASIC_BLOCK_FOR_FN (fn, index);
f0efc7aa 262
f41f80f9
TJ
263 bb->count = apply_scale (streamer_read_gcov_count (ib),
264 count_materialization_scale);
412288f1
DN
265 bb->frequency = streamer_read_hwi (ib);
266 bb->flags = streamer_read_hwi (ib);
f0efc7aa
DN
267
268 /* LTO_bb1 has statements. LTO_bb0 does not. */
269 if (tag == LTO_bb0)
270 return;
271
272 bsi = gsi_start_bb (bb);
412288f1 273 tag = streamer_read_record_start (ib);
f0efc7aa
DN
274 while (tag)
275 {
8356c89c 276 gimple stmt = input_gimple_stmt (ib, data_in, tag);
f0efc7aa
DN
277 gsi_insert_after (&bsi, stmt, GSI_NEW_STMT);
278
279 /* After the statement, expect a 0 delimiter or the EH region
280 that the previous statement belongs to. */
412288f1 281 tag = streamer_read_record_start (ib);
f0efc7aa
DN
282 lto_tag_check_set (tag, 2, LTO_eh_region, LTO_null);
283
284 if (tag == LTO_eh_region)
285 {
412288f1 286 HOST_WIDE_INT region = streamer_read_hwi (ib);
f0efc7aa
DN
287 gcc_assert (region == (int) region);
288 add_stmt_to_eh_lp (stmt, region);
289 }
290
412288f1 291 tag = streamer_read_record_start (ib);
f0efc7aa
DN
292 }
293
412288f1 294 tag = streamer_read_record_start (ib);
f0efc7aa
DN
295 while (tag)
296 {
46eb666a 297 input_phi (ib, bb, data_in, fn);
412288f1 298 tag = streamer_read_record_start (ib);
f0efc7aa
DN
299 }
300}
This page took 1.265271 seconds and 5 git commands to generate.