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