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