annotate gcc/gimple-streamer-out.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Routines for emitting GIMPLE to a file stream.
kono
parents:
diff changeset
2
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3 Copyright (C) 2011-2018 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
4 Contributed by Diego Novillo <dnovillo@google.com>
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 This file is part of GCC.
kono
parents:
diff changeset
7
kono
parents:
diff changeset
8 GCC is free software; you can redistribute it and/or modify it under
kono
parents:
diff changeset
9 the terms of the GNU General Public License as published by the Free
kono
parents:
diff changeset
10 Software Foundation; either version 3, or (at your option) any later
kono
parents:
diff changeset
11 version.
kono
parents:
diff changeset
12
kono
parents:
diff changeset
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
kono
parents:
diff changeset
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
kono
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
kono
parents:
diff changeset
16 for more details.
kono
parents:
diff changeset
17
kono
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
19 along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
20 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
21
kono
parents:
diff changeset
22 #include "config.h"
kono
parents:
diff changeset
23 #include "system.h"
kono
parents:
diff changeset
24 #include "coretypes.h"
kono
parents:
diff changeset
25 #include "backend.h"
kono
parents:
diff changeset
26 #include "tree.h"
kono
parents:
diff changeset
27 #include "gimple.h"
kono
parents:
diff changeset
28 #include "gimple-ssa.h"
kono
parents:
diff changeset
29 #include "gimple-streamer.h"
kono
parents:
diff changeset
30 #include "tree-eh.h"
kono
parents:
diff changeset
31 #include "gimple-iterator.h"
kono
parents:
diff changeset
32 #include "cgraph.h"
kono
parents:
diff changeset
33 #include "value-prof.h"
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
34 #include "gimple-pretty-print.h"
111
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 /* Output PHI function PHI to the main stream in OB. */
kono
parents:
diff changeset
37
kono
parents:
diff changeset
38 static void
kono
parents:
diff changeset
39 output_phi (struct output_block *ob, gphi *phi)
kono
parents:
diff changeset
40 {
kono
parents:
diff changeset
41 unsigned i, len = gimple_phi_num_args (phi);
kono
parents:
diff changeset
42
kono
parents:
diff changeset
43 streamer_write_record_start (ob, lto_gimple_code_to_tag (GIMPLE_PHI));
kono
parents:
diff changeset
44 streamer_write_uhwi (ob, SSA_NAME_VERSION (PHI_RESULT (phi)));
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 for (i = 0; i < len; i++)
kono
parents:
diff changeset
47 {
kono
parents:
diff changeset
48 stream_write_tree (ob, gimple_phi_arg_def (phi, i), true);
kono
parents:
diff changeset
49 streamer_write_uhwi (ob, gimple_phi_arg_edge (phi, i)->src->index);
kono
parents:
diff changeset
50 bitpack_d bp = bitpack_create (ob->main_stream);
kono
parents:
diff changeset
51 stream_output_location (ob, &bp, gimple_phi_arg_location (phi, i));
kono
parents:
diff changeset
52 streamer_write_bitpack (&bp);
kono
parents:
diff changeset
53 }
kono
parents:
diff changeset
54 }
kono
parents:
diff changeset
55
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 /* Emit statement STMT on the main stream of output block OB. */
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 static void
kono
parents:
diff changeset
60 output_gimple_stmt (struct output_block *ob, gimple *stmt)
kono
parents:
diff changeset
61 {
kono
parents:
diff changeset
62 unsigned i;
kono
parents:
diff changeset
63 enum gimple_code code;
kono
parents:
diff changeset
64 enum LTO_tags tag;
kono
parents:
diff changeset
65 struct bitpack_d bp;
kono
parents:
diff changeset
66 histogram_value hist;
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 /* Emit identifying tag. */
kono
parents:
diff changeset
69 code = gimple_code (stmt);
kono
parents:
diff changeset
70 tag = lto_gimple_code_to_tag (code);
kono
parents:
diff changeset
71 streamer_write_record_start (ob, tag);
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73 /* Emit the tuple header. */
kono
parents:
diff changeset
74 bp = bitpack_create (ob->main_stream);
kono
parents:
diff changeset
75 bp_pack_var_len_unsigned (&bp, gimple_num_ops (stmt));
kono
parents:
diff changeset
76 bp_pack_value (&bp, gimple_no_warning_p (stmt), 1);
kono
parents:
diff changeset
77 if (is_gimple_assign (stmt))
kono
parents:
diff changeset
78 bp_pack_value (&bp,
kono
parents:
diff changeset
79 gimple_assign_nontemporal_move_p (
kono
parents:
diff changeset
80 as_a <gassign *> (stmt)),
kono
parents:
diff changeset
81 1);
kono
parents:
diff changeset
82 bp_pack_value (&bp, gimple_has_volatile_ops (stmt), 1);
kono
parents:
diff changeset
83 hist = gimple_histogram_value (cfun, stmt);
kono
parents:
diff changeset
84 bp_pack_value (&bp, hist != NULL, 1);
kono
parents:
diff changeset
85 bp_pack_var_len_unsigned (&bp, stmt->subcode);
kono
parents:
diff changeset
86
kono
parents:
diff changeset
87 /* Emit location information for the statement. */
kono
parents:
diff changeset
88 stream_output_location (ob, &bp, LOCATION_LOCUS (gimple_location (stmt)));
kono
parents:
diff changeset
89 streamer_write_bitpack (&bp);
kono
parents:
diff changeset
90
kono
parents:
diff changeset
91 /* Emit the lexical block holding STMT. */
kono
parents:
diff changeset
92 stream_write_tree (ob, gimple_block (stmt), true);
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 /* Emit the operands. */
kono
parents:
diff changeset
95 switch (gimple_code (stmt))
kono
parents:
diff changeset
96 {
kono
parents:
diff changeset
97 case GIMPLE_RESX:
kono
parents:
diff changeset
98 streamer_write_hwi (ob, gimple_resx_region (as_a <gresx *> (stmt)));
kono
parents:
diff changeset
99 break;
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 case GIMPLE_EH_MUST_NOT_THROW:
kono
parents:
diff changeset
102 stream_write_tree (ob,
kono
parents:
diff changeset
103 gimple_eh_must_not_throw_fndecl (
kono
parents:
diff changeset
104 as_a <geh_mnt *> (stmt)),
kono
parents:
diff changeset
105 true);
kono
parents:
diff changeset
106 break;
kono
parents:
diff changeset
107
kono
parents:
diff changeset
108 case GIMPLE_EH_DISPATCH:
kono
parents:
diff changeset
109 streamer_write_hwi (ob,
kono
parents:
diff changeset
110 gimple_eh_dispatch_region (
kono
parents:
diff changeset
111 as_a <geh_dispatch *> (stmt)));
kono
parents:
diff changeset
112 break;
kono
parents:
diff changeset
113
kono
parents:
diff changeset
114 case GIMPLE_ASM:
kono
parents:
diff changeset
115 {
kono
parents:
diff changeset
116 gasm *asm_stmt = as_a <gasm *> (stmt);
kono
parents:
diff changeset
117 streamer_write_uhwi (ob, gimple_asm_ninputs (asm_stmt));
kono
parents:
diff changeset
118 streamer_write_uhwi (ob, gimple_asm_noutputs (asm_stmt));
kono
parents:
diff changeset
119 streamer_write_uhwi (ob, gimple_asm_nclobbers (asm_stmt));
kono
parents:
diff changeset
120 streamer_write_uhwi (ob, gimple_asm_nlabels (asm_stmt));
kono
parents:
diff changeset
121 streamer_write_string (ob, ob->main_stream,
kono
parents:
diff changeset
122 gimple_asm_string (asm_stmt), true);
kono
parents:
diff changeset
123 }
kono
parents:
diff changeset
124 /* Fallthru */
kono
parents:
diff changeset
125
kono
parents:
diff changeset
126 case GIMPLE_ASSIGN:
kono
parents:
diff changeset
127 case GIMPLE_CALL:
kono
parents:
diff changeset
128 case GIMPLE_RETURN:
kono
parents:
diff changeset
129 case GIMPLE_SWITCH:
kono
parents:
diff changeset
130 case GIMPLE_LABEL:
kono
parents:
diff changeset
131 case GIMPLE_COND:
kono
parents:
diff changeset
132 case GIMPLE_GOTO:
kono
parents:
diff changeset
133 case GIMPLE_DEBUG:
kono
parents:
diff changeset
134 for (i = 0; i < gimple_num_ops (stmt); i++)
kono
parents:
diff changeset
135 {
kono
parents:
diff changeset
136 tree op = gimple_op (stmt, i);
kono
parents:
diff changeset
137 tree *basep = NULL;
kono
parents:
diff changeset
138 /* Wrap all uses of non-automatic variables inside MEM_REFs
kono
parents:
diff changeset
139 so that we do not have to deal with type mismatches on
kono
parents:
diff changeset
140 merged symbols during IL read in. The first operand
kono
parents:
diff changeset
141 of GIMPLE_DEBUG must be a decl, not MEM_REF, though. */
kono
parents:
diff changeset
142 if (op && (i || !is_gimple_debug (stmt)))
kono
parents:
diff changeset
143 {
kono
parents:
diff changeset
144 basep = &op;
kono
parents:
diff changeset
145 if (TREE_CODE (*basep) == ADDR_EXPR)
kono
parents:
diff changeset
146 basep = &TREE_OPERAND (*basep, 0);
kono
parents:
diff changeset
147 while (handled_component_p (*basep))
kono
parents:
diff changeset
148 basep = &TREE_OPERAND (*basep, 0);
kono
parents:
diff changeset
149 if (VAR_P (*basep)
kono
parents:
diff changeset
150 && !auto_var_in_fn_p (*basep, current_function_decl)
kono
parents:
diff changeset
151 && !DECL_REGISTER (*basep))
kono
parents:
diff changeset
152 {
kono
parents:
diff changeset
153 bool volatilep = TREE_THIS_VOLATILE (*basep);
kono
parents:
diff changeset
154 tree ptrtype = build_pointer_type (TREE_TYPE (*basep));
kono
parents:
diff changeset
155 *basep = build2 (MEM_REF, TREE_TYPE (*basep),
kono
parents:
diff changeset
156 build1 (ADDR_EXPR, ptrtype, *basep),
kono
parents:
diff changeset
157 build_int_cst (ptrtype, 0));
kono
parents:
diff changeset
158 TREE_THIS_VOLATILE (*basep) = volatilep;
kono
parents:
diff changeset
159 }
kono
parents:
diff changeset
160 else
kono
parents:
diff changeset
161 basep = NULL;
kono
parents:
diff changeset
162 }
kono
parents:
diff changeset
163 stream_write_tree (ob, op, true);
kono
parents:
diff changeset
164 /* Restore the original base if we wrapped it inside a MEM_REF. */
kono
parents:
diff changeset
165 if (basep)
kono
parents:
diff changeset
166 *basep = TREE_OPERAND (TREE_OPERAND (*basep, 0), 0);
kono
parents:
diff changeset
167 }
kono
parents:
diff changeset
168 if (is_gimple_call (stmt))
kono
parents:
diff changeset
169 {
kono
parents:
diff changeset
170 if (gimple_call_internal_p (stmt))
kono
parents:
diff changeset
171 streamer_write_enum (ob->main_stream, internal_fn,
kono
parents:
diff changeset
172 IFN_LAST, gimple_call_internal_fn (stmt));
kono
parents:
diff changeset
173 else
kono
parents:
diff changeset
174 stream_write_tree (ob, gimple_call_fntype (stmt), true);
kono
parents:
diff changeset
175 }
kono
parents:
diff changeset
176 break;
kono
parents:
diff changeset
177
kono
parents:
diff changeset
178 case GIMPLE_NOP:
kono
parents:
diff changeset
179 case GIMPLE_PREDICT:
kono
parents:
diff changeset
180 break;
kono
parents:
diff changeset
181
kono
parents:
diff changeset
182 case GIMPLE_TRANSACTION:
kono
parents:
diff changeset
183 {
kono
parents:
diff changeset
184 gtransaction *txn = as_a <gtransaction *> (stmt);
kono
parents:
diff changeset
185 gcc_assert (gimple_transaction_body (txn) == NULL);
kono
parents:
diff changeset
186 stream_write_tree (ob, gimple_transaction_label_norm (txn), true);
kono
parents:
diff changeset
187 stream_write_tree (ob, gimple_transaction_label_uninst (txn), true);
kono
parents:
diff changeset
188 stream_write_tree (ob, gimple_transaction_label_over (txn), true);
kono
parents:
diff changeset
189 }
kono
parents:
diff changeset
190 break;
kono
parents:
diff changeset
191
kono
parents:
diff changeset
192 default:
kono
parents:
diff changeset
193 gcc_unreachable ();
kono
parents:
diff changeset
194 }
kono
parents:
diff changeset
195 if (hist)
kono
parents:
diff changeset
196 stream_out_histogram_value (ob, hist);
kono
parents:
diff changeset
197 }
kono
parents:
diff changeset
198
kono
parents:
diff changeset
199
kono
parents:
diff changeset
200 /* Output a basic block BB to the main stream in OB for this FN. */
kono
parents:
diff changeset
201
kono
parents:
diff changeset
202 void
kono
parents:
diff changeset
203 output_bb (struct output_block *ob, basic_block bb, struct function *fn)
kono
parents:
diff changeset
204 {
kono
parents:
diff changeset
205 gimple_stmt_iterator bsi = gsi_start_bb (bb);
kono
parents:
diff changeset
206
kono
parents:
diff changeset
207 streamer_write_record_start (ob,
kono
parents:
diff changeset
208 (!gsi_end_p (bsi)) || phi_nodes (bb)
kono
parents:
diff changeset
209 ? LTO_bb1
kono
parents:
diff changeset
210 : LTO_bb0);
kono
parents:
diff changeset
211
kono
parents:
diff changeset
212 streamer_write_uhwi (ob, bb->index);
kono
parents:
diff changeset
213 bb->count.stream_out (ob);
kono
parents:
diff changeset
214 streamer_write_hwi (ob, bb->flags);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
215 streamer_write_hwi (ob, bb->discriminator);
111
kono
parents:
diff changeset
216
kono
parents:
diff changeset
217 if (!gsi_end_p (bsi) || phi_nodes (bb))
kono
parents:
diff changeset
218 {
kono
parents:
diff changeset
219 /* Output the statements. The list of statements is terminated
kono
parents:
diff changeset
220 with a zero. */
kono
parents:
diff changeset
221 for (bsi = gsi_start_bb (bb); !gsi_end_p (bsi); gsi_next (&bsi))
kono
parents:
diff changeset
222 {
kono
parents:
diff changeset
223 int region;
kono
parents:
diff changeset
224 gimple *stmt = gsi_stmt (bsi);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
225 if (streamer_dump_file)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
226 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
227 fprintf (streamer_dump_file, " Streaming gimple stmt ");
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
228 print_gimple_stmt (streamer_dump_file, stmt, 0, TDF_SLIM);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
229 }
111
kono
parents:
diff changeset
230
kono
parents:
diff changeset
231 output_gimple_stmt (ob, stmt);
kono
parents:
diff changeset
232
kono
parents:
diff changeset
233 /* Emit the EH region holding STMT. */
kono
parents:
diff changeset
234 region = lookup_stmt_eh_lp_fn (fn, stmt);
kono
parents:
diff changeset
235 if (region != 0)
kono
parents:
diff changeset
236 {
kono
parents:
diff changeset
237 streamer_write_record_start (ob, LTO_eh_region);
kono
parents:
diff changeset
238 streamer_write_hwi (ob, region);
kono
parents:
diff changeset
239 }
kono
parents:
diff changeset
240 else
kono
parents:
diff changeset
241 streamer_write_record_start (ob, LTO_null);
kono
parents:
diff changeset
242 }
kono
parents:
diff changeset
243
kono
parents:
diff changeset
244 streamer_write_record_start (ob, LTO_null);
kono
parents:
diff changeset
245
kono
parents:
diff changeset
246 for (gphi_iterator psi = gsi_start_phis (bb);
kono
parents:
diff changeset
247 !gsi_end_p (psi);
kono
parents:
diff changeset
248 gsi_next (&psi))
kono
parents:
diff changeset
249 {
kono
parents:
diff changeset
250 gphi *phi = psi.phi ();
kono
parents:
diff changeset
251
kono
parents:
diff changeset
252 /* Only emit PHIs for gimple registers. PHI nodes for .MEM
kono
parents:
diff changeset
253 will be filled in on reading when the SSA form is
kono
parents:
diff changeset
254 updated. */
kono
parents:
diff changeset
255 if (!virtual_operand_p (gimple_phi_result (phi)))
kono
parents:
diff changeset
256 output_phi (ob, phi);
kono
parents:
diff changeset
257 }
kono
parents:
diff changeset
258
kono
parents:
diff changeset
259 streamer_write_record_start (ob, LTO_null);
kono
parents:
diff changeset
260 }
kono
parents:
diff changeset
261 }