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