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