]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/gimple-streamer-out.c
gimple-fold.h (follow_single_use_edges): Declare.
[thirdparty/gcc.git] / gcc / gimple-streamer-out.c
CommitLineData
f0efc7aa
DN
1/* Routines for emitting GIMPLE to a file stream.
2
23a5b65a 3 Copyright (C) 2011-2014 Free Software Foundation, Inc.
f0efc7aa
DN
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 "tree.h"
60393bbc
AM
26#include "predict.h"
27#include "vec.h"
28#include "hashtab.h"
29#include "hash-set.h"
30#include "machmode.h"
31#include "tm.h"
32#include "hard-reg-set.h"
33#include "input.h"
34#include "function.h"
2fb9a547
AM
35#include "basic-block.h"
36#include "tree-ssa-alias.h"
37#include "internal-fn.h"
38#include "tree-eh.h"
39#include "gimple-expr.h"
40#include "is-a.h"
442b4905 41#include "gimple.h"
5be5c238 42#include "gimple-iterator.h"
442b4905 43#include "gimple-ssa.h"
f0efc7aa
DN
44#include "data-streamer.h"
45#include "gimple-streamer.h"
46#include "lto-streamer.h"
b9393656 47#include "tree-streamer.h"
89ab31c1 48#include "value-prof.h"
f0efc7aa
DN
49
50/* Output PHI function PHI to the main stream in OB. */
51
52static void
53output_phi (struct output_block *ob, gimple phi)
54{
55 unsigned i, len = gimple_phi_num_args (phi);
56
412288f1
DN
57 streamer_write_record_start (ob, lto_gimple_code_to_tag (GIMPLE_PHI));
58 streamer_write_uhwi (ob, SSA_NAME_VERSION (PHI_RESULT (phi)));
f0efc7aa
DN
59
60 for (i = 0; i < len; i++)
61 {
b9393656 62 stream_write_tree (ob, gimple_phi_arg_def (phi, i), true);
412288f1 63 streamer_write_uhwi (ob, gimple_phi_arg_edge (phi, i)->src->index);
7cb7d208
RB
64 bitpack_d bp = bitpack_create (ob->main_stream);
65 stream_output_location (ob, &bp, gimple_phi_arg_location (phi, i));
66 streamer_write_bitpack (&bp);
f0efc7aa
DN
67 }
68}
69
70
71/* Emit statement STMT on the main stream of output block OB. */
72
73static void
74output_gimple_stmt (struct output_block *ob, gimple stmt)
75{
76 unsigned i;
77 enum gimple_code code;
78 enum LTO_tags tag;
79 struct bitpack_d bp;
89ab31c1 80 histogram_value hist;
f0efc7aa
DN
81
82 /* Emit identifying tag. */
83 code = gimple_code (stmt);
84 tag = lto_gimple_code_to_tag (code);
412288f1 85 streamer_write_record_start (ob, tag);
f0efc7aa
DN
86
87 /* Emit the tuple header. */
88 bp = bitpack_create (ob->main_stream);
89 bp_pack_var_len_unsigned (&bp, gimple_num_ops (stmt));
90 bp_pack_value (&bp, gimple_no_warning_p (stmt), 1);
91 if (is_gimple_assign (stmt))
92 bp_pack_value (&bp, gimple_assign_nontemporal_move_p (stmt), 1);
93 bp_pack_value (&bp, gimple_has_volatile_ops (stmt), 1);
89ab31c1
JH
94 hist = gimple_histogram_value (cfun, stmt);
95 bp_pack_value (&bp, hist != NULL, 1);
daa6e488 96 bp_pack_var_len_unsigned (&bp, stmt->subcode);
f0efc7aa
DN
97
98 /* Emit location information for the statement. */
7cb7d208
RB
99 stream_output_location (ob, &bp, LOCATION_LOCUS (gimple_location (stmt)));
100 streamer_write_bitpack (&bp);
f0efc7aa
DN
101
102 /* Emit the lexical block holding STMT. */
b9393656 103 stream_write_tree (ob, gimple_block (stmt), true);
f0efc7aa
DN
104
105 /* Emit the operands. */
106 switch (gimple_code (stmt))
107 {
108 case GIMPLE_RESX:
412288f1 109 streamer_write_hwi (ob, gimple_resx_region (stmt));
f0efc7aa
DN
110 break;
111
112 case GIMPLE_EH_MUST_NOT_THROW:
b9393656 113 stream_write_tree (ob, gimple_eh_must_not_throw_fndecl (stmt), true);
f0efc7aa
DN
114 break;
115
116 case GIMPLE_EH_DISPATCH:
412288f1 117 streamer_write_hwi (ob, gimple_eh_dispatch_region (stmt));
f0efc7aa
DN
118 break;
119
120 case GIMPLE_ASM:
412288f1
DN
121 streamer_write_uhwi (ob, gimple_asm_ninputs (stmt));
122 streamer_write_uhwi (ob, gimple_asm_noutputs (stmt));
123 streamer_write_uhwi (ob, gimple_asm_nclobbers (stmt));
124 streamer_write_uhwi (ob, gimple_asm_nlabels (stmt));
125 streamer_write_string (ob, ob->main_stream, gimple_asm_string (stmt),
126 true);
f0efc7aa
DN
127 /* Fallthru */
128
129 case GIMPLE_ASSIGN:
130 case GIMPLE_CALL:
131 case GIMPLE_RETURN:
132 case GIMPLE_SWITCH:
133 case GIMPLE_LABEL:
134 case GIMPLE_COND:
135 case GIMPLE_GOTO:
136 case GIMPLE_DEBUG:
137 for (i = 0; i < gimple_num_ops (stmt); i++)
138 {
139 tree op = gimple_op (stmt, i);
976a81ee 140 tree *basep = NULL;
f0efc7aa
DN
141 /* Wrap all uses of non-automatic variables inside MEM_REFs
142 so that we do not have to deal with type mismatches on
143 merged symbols during IL read in. The first operand
144 of GIMPLE_DEBUG must be a decl, not MEM_REF, though. */
145 if (op && (i || !is_gimple_debug (stmt)))
146 {
976a81ee 147 basep = &op;
3fede979
RB
148 if (TREE_CODE (*basep) == ADDR_EXPR)
149 basep = &TREE_OPERAND (*basep, 0);
f0efc7aa
DN
150 while (handled_component_p (*basep))
151 basep = &TREE_OPERAND (*basep, 0);
152 if (TREE_CODE (*basep) == VAR_DECL
153 && !auto_var_in_fn_p (*basep, current_function_decl)
154 && !DECL_REGISTER (*basep))
155 {
156 bool volatilep = TREE_THIS_VOLATILE (*basep);
3fede979 157 tree ptrtype = build_pointer_type (TREE_TYPE (*basep));
f0efc7aa 158 *basep = build2 (MEM_REF, TREE_TYPE (*basep),
3fede979
RB
159 build1 (ADDR_EXPR, ptrtype, *basep),
160 build_int_cst (ptrtype, 0));
f0efc7aa
DN
161 TREE_THIS_VOLATILE (*basep) = volatilep;
162 }
976a81ee
RB
163 else
164 basep = NULL;
f0efc7aa 165 }
b9393656 166 stream_write_tree (ob, op, true);
976a81ee
RB
167 /* Restore the original base if we wrapped it inside a MEM_REF. */
168 if (basep)
169 *basep = TREE_OPERAND (TREE_OPERAND (*basep, 0), 0);
f0efc7aa
DN
170 }
171 if (is_gimple_call (stmt))
172 {
173 if (gimple_call_internal_p (stmt))
412288f1
DN
174 streamer_write_enum (ob->main_stream, internal_fn,
175 IFN_LAST, gimple_call_internal_fn (stmt));
f0efc7aa 176 else
b9393656 177 stream_write_tree (ob, gimple_call_fntype (stmt), true);
f0efc7aa
DN
178 }
179 break;
180
181 case GIMPLE_NOP:
182 case GIMPLE_PREDICT:
183 break;
184
57ac2606
AH
185 case GIMPLE_TRANSACTION:
186 gcc_assert (gimple_transaction_body (stmt) == NULL);
187 stream_write_tree (ob, gimple_transaction_label (stmt), true);
188 break;
189
f0efc7aa
DN
190 default:
191 gcc_unreachable ();
192 }
89ab31c1
JH
193 if (hist)
194 stream_out_histogram_value (ob, hist);
f0efc7aa
DN
195}
196
197
198/* Output a basic block BB to the main stream in OB for this FN. */
199
200void
201output_bb (struct output_block *ob, basic_block bb, struct function *fn)
202{
203 gimple_stmt_iterator bsi = gsi_start_bb (bb);
204
412288f1
DN
205 streamer_write_record_start (ob,
206 (!gsi_end_p (bsi)) || phi_nodes (bb)
207 ? LTO_bb1
208 : LTO_bb0);
f0efc7aa 209
412288f1 210 streamer_write_uhwi (ob, bb->index);
89ab31c1 211 streamer_write_gcov_count (ob, bb->count);
412288f1
DN
212 streamer_write_hwi (ob, bb->frequency);
213 streamer_write_hwi (ob, bb->flags);
f0efc7aa
DN
214
215 if (!gsi_end_p (bsi) || phi_nodes (bb))
216 {
217 /* Output the statements. The list of statements is terminated
218 with a zero. */
219 for (bsi = gsi_start_bb (bb); !gsi_end_p (bsi); gsi_next (&bsi))
220 {
221 int region;
222 gimple stmt = gsi_stmt (bsi);
223
224 output_gimple_stmt (ob, stmt);
225
226 /* Emit the EH region holding STMT. */
227 region = lookup_stmt_eh_lp_fn (fn, stmt);
228 if (region != 0)
229 {
412288f1
DN
230 streamer_write_record_start (ob, LTO_eh_region);
231 streamer_write_hwi (ob, region);
f0efc7aa
DN
232 }
233 else
412288f1 234 streamer_write_record_start (ob, LTO_null);
f0efc7aa
DN
235 }
236
412288f1 237 streamer_write_record_start (ob, LTO_null);
f0efc7aa
DN
238
239 for (bsi = gsi_start_phis (bb); !gsi_end_p (bsi); gsi_next (&bsi))
240 {
241 gimple phi = gsi_stmt (bsi);
242
243 /* Only emit PHIs for gimple registers. PHI nodes for .MEM
244 will be filled in on reading when the SSA form is
245 updated. */
ea057359 246 if (!virtual_operand_p (gimple_phi_result (phi)))
f0efc7aa
DN
247 output_phi (ob, phi);
248 }
249
412288f1 250 streamer_write_record_start (ob, LTO_null);
f0efc7aa
DN
251 }
252}