* Makefile.in (C_COMMON_OBJS): Depend on c-cilkplus.o.
[official-gcc.git] / gcc / gimple-streamer-in.c
blob6f8f51a18cee220be4fc8b53349dc011203a2ace
1 /* Routines for reading GIMPLE from a file stream.
3 Copyright (C) 2011-2013 Free Software Foundation, Inc.
4 Contributed by Diego Novillo <dnovillo@google.com>
6 This file is part of GCC.
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.
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.
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/>. */
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 "tree-ssanames.h"
32 #include "data-streamer.h"
33 #include "tree-streamer.h"
34 #include "gimple-streamer.h"
35 #include "value-prof.h"
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. */
40 static gimple
41 input_phi (struct lto_input_block *ib, basic_block bb, struct data_in *data_in,
42 struct function *fn)
44 unsigned HOST_WIDE_INT ix;
45 tree phi_result;
46 int i, len;
47 gimple result;
49 ix = streamer_read_uhwi (ib);
50 phi_result = (*SSANAMES (fn))[ix];
51 len = EDGE_COUNT (bb->preds);
52 result = create_phi_node (phi_result, bb);
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++)
59 tree def = stream_read_tree (ib, data_in);
60 int src_index = streamer_read_uhwi (ib);
61 bitpack_d bp = streamer_read_bitpack (ib);
62 location_t arg_loc = stream_input_location (&bp, data_in);
63 basic_block sbb = BASIC_BLOCK_FOR_FUNCTION (fn, src_index);
65 edge e = NULL;
66 int j;
68 for (j = 0; j < len; j++)
69 if (EDGE_PRED (bb, j)->src == sbb)
71 e = EDGE_PRED (bb, j);
72 break;
75 add_phi_arg (result, def, e, arg_loc);
78 return result;
82 /* Read a statement with tag TAG in function FN from block IB using
83 descriptors in DATA_IN. */
85 static gimple
86 input_gimple_stmt (struct lto_input_block *ib, struct data_in *data_in,
87 enum LTO_tags tag)
89 gimple stmt;
90 enum gimple_code code;
91 unsigned HOST_WIDE_INT num_ops;
92 size_t i;
93 struct bitpack_d bp;
94 bool has_hist;
96 code = lto_tag_to_gimple_code (tag);
98 /* Read the tuple header. */
99 bp = streamer_read_bitpack (ib);
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);
106 has_hist = bp_unpack_value (&bp, 1);
107 stmt->gsbase.subcode = bp_unpack_var_len_unsigned (&bp);
109 /* Read location information. */
110 gimple_set_location (stmt, stream_input_location (&bp, data_in));
112 /* Read lexical block reference. */
113 gimple_set_block (stmt, stream_read_tree (ib, data_in));
115 /* Read in all the operands. */
116 switch (code)
118 case GIMPLE_RESX:
119 gimple_resx_set_region (stmt, streamer_read_hwi (ib));
120 break;
122 case GIMPLE_EH_MUST_NOT_THROW:
123 gimple_eh_must_not_throw_set_fndecl (stmt, stream_read_tree (ib, data_in));
124 break;
126 case GIMPLE_EH_DISPATCH:
127 gimple_eh_dispatch_set_region (stmt, streamer_read_hwi (ib));
128 break;
130 case GIMPLE_ASM:
132 /* FIXME lto. Move most of this into a new gimple_asm_set_string(). */
133 tree str;
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);
139 stmt->gimple_asm.string = TREE_STRING_POINTER (str);
141 /* Fallthru */
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++)
153 tree *opp, op = stream_read_tree (ib, data_in);
154 gimple_set_op (stmt, i, op);
155 if (!op)
156 continue;
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))
162 opp = &TREE_OPERAND (*opp, 0);
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);
180 if (is_gimple_call (stmt))
182 if (gimple_call_internal_p (stmt))
183 gimple_call_set_internal_fn
184 (stmt, streamer_read_enum (ib, internal_fn, IFN_LAST));
185 else
186 gimple_call_set_fntype (stmt, stream_read_tree (ib, data_in));
188 break;
190 case GIMPLE_NOP:
191 case GIMPLE_PREDICT:
192 break;
194 case GIMPLE_TRANSACTION:
195 gimple_transaction_set_label (stmt, stream_read_tree (ib, data_in));
196 break;
198 default:
199 internal_error ("bytecode stream: unknown GIMPLE statement tag %s",
200 lto_tag_name (tag));
203 /* Update the properties of symbols, SSA names and labels associated
204 with STMT. */
205 if (code == GIMPLE_ASSIGN || code == GIMPLE_CALL)
207 tree lhs = gimple_get_lhs (stmt);
208 if (lhs && TREE_CODE (lhs) == SSA_NAME)
209 SSA_NAME_DEF_STMT (lhs) = stmt;
211 else if (code == GIMPLE_ASM)
213 unsigned i;
215 for (i = 0; i < gimple_asm_noutputs (stmt); i++)
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;
223 /* Reset alias information. */
224 if (code == GIMPLE_CALL)
225 gimple_call_reset_alias_info (stmt);
227 /* Mark the statement modified so its operand vectors can be filled in. */
228 gimple_set_modified (stmt, true);
229 if (has_hist)
230 stream_in_histogram_value (ib, stmt);
232 return stmt;
236 /* Read a basic block with tag TAG from DATA_IN using input block IB.
237 FN is the function being processed. */
239 void
240 input_bb (struct lto_input_block *ib, enum LTO_tags tag,
241 struct data_in *data_in, struct function *fn,
242 int count_materialization_scale)
244 unsigned int index;
245 basic_block bb;
246 gimple_stmt_iterator bsi;
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);
252 index = streamer_read_uhwi (ib);
253 bb = BASIC_BLOCK_FOR_FUNCTION (fn, index);
255 bb->count = apply_scale (streamer_read_gcov_count (ib),
256 count_materialization_scale);
257 bb->frequency = streamer_read_hwi (ib);
258 bb->flags = streamer_read_hwi (ib);
260 /* LTO_bb1 has statements. LTO_bb0 does not. */
261 if (tag == LTO_bb0)
262 return;
264 bsi = gsi_start_bb (bb);
265 tag = streamer_read_record_start (ib);
266 while (tag)
268 gimple stmt = input_gimple_stmt (ib, data_in, tag);
269 gsi_insert_after (&bsi, stmt, GSI_NEW_STMT);
271 /* After the statement, expect a 0 delimiter or the EH region
272 that the previous statement belongs to. */
273 tag = streamer_read_record_start (ib);
274 lto_tag_check_set (tag, 2, LTO_eh_region, LTO_null);
276 if (tag == LTO_eh_region)
278 HOST_WIDE_INT region = streamer_read_hwi (ib);
279 gcc_assert (region == (int) region);
280 add_stmt_to_eh_lp (stmt, region);
283 tag = streamer_read_record_start (ib);
286 tag = streamer_read_record_start (ib);
287 while (tag)
289 input_phi (ib, bb, data_in, fn);
290 tag = streamer_read_record_start (ib);