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