annotate gcc/gimplify-me.c @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Tree lowering to gimple for middle end use only.
kono
parents:
diff changeset
2 This converts the GENERIC functions-as-trees tree representation into
kono
parents:
diff changeset
3 the GIMPLE form.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
4 Copyright (C) 2013-2020 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
5 Major work done by Sebastian Pop <s.pop@laposte.net>,
kono
parents:
diff changeset
6 Diego Novillo <dnovillo@redhat.com> and Jason Merrill <jason@redhat.com>.
kono
parents:
diff changeset
7
kono
parents:
diff changeset
8 This file is part of GCC.
kono
parents:
diff changeset
9
kono
parents:
diff changeset
10 GCC is free software; you can redistribute it and/or modify it under
kono
parents:
diff changeset
11 the terms of the GNU General Public License as published by the Free
kono
parents:
diff changeset
12 Software Foundation; either version 3, or (at your option) any later
kono
parents:
diff changeset
13 version.
kono
parents:
diff changeset
14
kono
parents:
diff changeset
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
kono
parents:
diff changeset
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
kono
parents:
diff changeset
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
kono
parents:
diff changeset
18 for more details.
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
21 along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
22 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
23
kono
parents:
diff changeset
24 #include "config.h"
kono
parents:
diff changeset
25 #include "system.h"
kono
parents:
diff changeset
26 #include "coretypes.h"
kono
parents:
diff changeset
27 #include "backend.h"
kono
parents:
diff changeset
28 #include "tree.h"
kono
parents:
diff changeset
29 #include "gimple.h"
kono
parents:
diff changeset
30 #include "ssa.h"
kono
parents:
diff changeset
31 #include "stmt.h"
kono
parents:
diff changeset
32 #include "stor-layout.h"
kono
parents:
diff changeset
33 #include "tree-eh.h"
kono
parents:
diff changeset
34 #include "gimple-iterator.h"
kono
parents:
diff changeset
35 #include "gimplify.h"
kono
parents:
diff changeset
36 #include "gimplify-me.h"
kono
parents:
diff changeset
37
kono
parents:
diff changeset
38
kono
parents:
diff changeset
39 /* Expand EXPR to list of gimple statements STMTS. GIMPLE_TEST_F specifies
kono
parents:
diff changeset
40 the predicate that will hold for the result. If VAR is not NULL, make the
kono
parents:
diff changeset
41 base variable of the final destination be VAR if suitable. */
kono
parents:
diff changeset
42
kono
parents:
diff changeset
43 tree
kono
parents:
diff changeset
44 force_gimple_operand_1 (tree expr, gimple_seq *stmts,
kono
parents:
diff changeset
45 gimple_predicate gimple_test_f, tree var)
kono
parents:
diff changeset
46 {
kono
parents:
diff changeset
47 enum gimplify_status ret;
kono
parents:
diff changeset
48 location_t saved_location;
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 *stmts = NULL;
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 /* gimple_test_f might be more strict than is_gimple_val, make
kono
parents:
diff changeset
53 sure we pass both. Just checking gimple_test_f doesn't work
kono
parents:
diff changeset
54 because most gimple predicates do not work recursively. */
kono
parents:
diff changeset
55 if (is_gimple_val (expr)
kono
parents:
diff changeset
56 && (*gimple_test_f) (expr))
kono
parents:
diff changeset
57 return expr;
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 push_gimplify_context (gimple_in_ssa_p (cfun), true);
kono
parents:
diff changeset
60 saved_location = input_location;
kono
parents:
diff changeset
61 input_location = UNKNOWN_LOCATION;
kono
parents:
diff changeset
62
kono
parents:
diff changeset
63 if (var)
kono
parents:
diff changeset
64 {
kono
parents:
diff changeset
65 if (gimple_in_ssa_p (cfun) && is_gimple_reg (var))
kono
parents:
diff changeset
66 var = make_ssa_name (var);
kono
parents:
diff changeset
67 expr = build2 (MODIFY_EXPR, TREE_TYPE (var), var, expr);
kono
parents:
diff changeset
68 }
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 if (TREE_CODE (expr) != MODIFY_EXPR
kono
parents:
diff changeset
71 && TREE_TYPE (expr) == void_type_node)
kono
parents:
diff changeset
72 {
kono
parents:
diff changeset
73 gimplify_and_add (expr, stmts);
kono
parents:
diff changeset
74 expr = NULL_TREE;
kono
parents:
diff changeset
75 }
kono
parents:
diff changeset
76 else
kono
parents:
diff changeset
77 {
kono
parents:
diff changeset
78 ret = gimplify_expr (&expr, stmts, NULL, gimple_test_f, fb_rvalue);
kono
parents:
diff changeset
79 gcc_assert (ret != GS_ERROR);
kono
parents:
diff changeset
80 }
kono
parents:
diff changeset
81
kono
parents:
diff changeset
82 input_location = saved_location;
kono
parents:
diff changeset
83 pop_gimplify_context (NULL);
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 return expr;
kono
parents:
diff changeset
86 }
kono
parents:
diff changeset
87
kono
parents:
diff changeset
88 /* Expand EXPR to list of gimple statements STMTS. If SIMPLE is true,
kono
parents:
diff changeset
89 force the result to be either ssa_name or an invariant, otherwise
kono
parents:
diff changeset
90 just force it to be a rhs expression. If VAR is not NULL, make the
kono
parents:
diff changeset
91 base variable of the final destination be VAR if suitable. */
kono
parents:
diff changeset
92
kono
parents:
diff changeset
93 tree
kono
parents:
diff changeset
94 force_gimple_operand (tree expr, gimple_seq *stmts, bool simple, tree var)
kono
parents:
diff changeset
95 {
kono
parents:
diff changeset
96 return force_gimple_operand_1 (expr, stmts,
kono
parents:
diff changeset
97 simple ? is_gimple_val : is_gimple_reg_rhs,
kono
parents:
diff changeset
98 var);
kono
parents:
diff changeset
99 }
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 /* Invoke force_gimple_operand_1 for EXPR with parameters GIMPLE_TEST_F
kono
parents:
diff changeset
102 and VAR. If some statements are produced, emits them at GSI.
kono
parents:
diff changeset
103 If BEFORE is true. the statements are appended before GSI, otherwise
kono
parents:
diff changeset
104 they are appended after it. M specifies the way GSI moves after
kono
parents:
diff changeset
105 insertion (GSI_SAME_STMT or GSI_CONTINUE_LINKING are the usual values). */
kono
parents:
diff changeset
106
kono
parents:
diff changeset
107 tree
kono
parents:
diff changeset
108 force_gimple_operand_gsi_1 (gimple_stmt_iterator *gsi, tree expr,
kono
parents:
diff changeset
109 gimple_predicate gimple_test_f,
kono
parents:
diff changeset
110 tree var, bool before,
kono
parents:
diff changeset
111 enum gsi_iterator_update m)
kono
parents:
diff changeset
112 {
kono
parents:
diff changeset
113 gimple_seq stmts;
kono
parents:
diff changeset
114
kono
parents:
diff changeset
115 expr = force_gimple_operand_1 (expr, &stmts, gimple_test_f, var);
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 if (!gimple_seq_empty_p (stmts))
kono
parents:
diff changeset
118 {
kono
parents:
diff changeset
119 if (before)
kono
parents:
diff changeset
120 gsi_insert_seq_before (gsi, stmts, m);
kono
parents:
diff changeset
121 else
kono
parents:
diff changeset
122 gsi_insert_seq_after (gsi, stmts, m);
kono
parents:
diff changeset
123 }
kono
parents:
diff changeset
124
kono
parents:
diff changeset
125 return expr;
kono
parents:
diff changeset
126 }
kono
parents:
diff changeset
127
kono
parents:
diff changeset
128 /* Invoke force_gimple_operand_1 for EXPR with parameter VAR.
kono
parents:
diff changeset
129 If SIMPLE is true, force the result to be either ssa_name or an invariant,
kono
parents:
diff changeset
130 otherwise just force it to be a rhs expression. If some statements are
kono
parents:
diff changeset
131 produced, emits them at GSI. If BEFORE is true, the statements are
kono
parents:
diff changeset
132 appended before GSI, otherwise they are appended after it. M specifies
kono
parents:
diff changeset
133 the way GSI moves after insertion (GSI_SAME_STMT or GSI_CONTINUE_LINKING
kono
parents:
diff changeset
134 are the usual values). */
kono
parents:
diff changeset
135
kono
parents:
diff changeset
136 tree
kono
parents:
diff changeset
137 force_gimple_operand_gsi (gimple_stmt_iterator *gsi, tree expr,
kono
parents:
diff changeset
138 bool simple_p, tree var, bool before,
kono
parents:
diff changeset
139 enum gsi_iterator_update m)
kono
parents:
diff changeset
140 {
kono
parents:
diff changeset
141 return force_gimple_operand_gsi_1 (gsi, expr,
kono
parents:
diff changeset
142 simple_p
kono
parents:
diff changeset
143 ? is_gimple_val : is_gimple_reg_rhs,
kono
parents:
diff changeset
144 var, before, m);
kono
parents:
diff changeset
145 }
kono
parents:
diff changeset
146
kono
parents:
diff changeset
147 /* Some transformations like inlining may invalidate the GIMPLE form
kono
parents:
diff changeset
148 for operands. This function traverses all the operands in STMT and
kono
parents:
diff changeset
149 gimplifies anything that is not a valid gimple operand. Any new
kono
parents:
diff changeset
150 GIMPLE statements are inserted before *GSI_P. */
kono
parents:
diff changeset
151
kono
parents:
diff changeset
152 void
kono
parents:
diff changeset
153 gimple_regimplify_operands (gimple *stmt, gimple_stmt_iterator *gsi_p)
kono
parents:
diff changeset
154 {
kono
parents:
diff changeset
155 size_t i, num_ops;
kono
parents:
diff changeset
156 tree lhs;
kono
parents:
diff changeset
157 gimple_seq pre = NULL;
kono
parents:
diff changeset
158 gimple *post_stmt = NULL;
kono
parents:
diff changeset
159
kono
parents:
diff changeset
160 push_gimplify_context (gimple_in_ssa_p (cfun));
kono
parents:
diff changeset
161
kono
parents:
diff changeset
162 switch (gimple_code (stmt))
kono
parents:
diff changeset
163 {
kono
parents:
diff changeset
164 case GIMPLE_COND:
kono
parents:
diff changeset
165 {
kono
parents:
diff changeset
166 gcond *cond_stmt = as_a <gcond *> (stmt);
kono
parents:
diff changeset
167 gimplify_expr (gimple_cond_lhs_ptr (cond_stmt), &pre, NULL,
kono
parents:
diff changeset
168 is_gimple_val, fb_rvalue);
kono
parents:
diff changeset
169 gimplify_expr (gimple_cond_rhs_ptr (cond_stmt), &pre, NULL,
kono
parents:
diff changeset
170 is_gimple_val, fb_rvalue);
kono
parents:
diff changeset
171 }
kono
parents:
diff changeset
172 break;
kono
parents:
diff changeset
173 case GIMPLE_SWITCH:
kono
parents:
diff changeset
174 gimplify_expr (gimple_switch_index_ptr (as_a <gswitch *> (stmt)),
kono
parents:
diff changeset
175 &pre, NULL, is_gimple_val, fb_rvalue);
kono
parents:
diff changeset
176 break;
kono
parents:
diff changeset
177 case GIMPLE_OMP_ATOMIC_LOAD:
kono
parents:
diff changeset
178 gimplify_expr (gimple_omp_atomic_load_rhs_ptr (
kono
parents:
diff changeset
179 as_a <gomp_atomic_load *> (stmt)),
kono
parents:
diff changeset
180 &pre, NULL, is_gimple_val, fb_rvalue);
kono
parents:
diff changeset
181 break;
kono
parents:
diff changeset
182 case GIMPLE_ASM:
kono
parents:
diff changeset
183 {
kono
parents:
diff changeset
184 gasm *asm_stmt = as_a <gasm *> (stmt);
kono
parents:
diff changeset
185 size_t i, noutputs = gimple_asm_noutputs (asm_stmt);
kono
parents:
diff changeset
186 const char *constraint, **oconstraints;
kono
parents:
diff changeset
187 bool allows_mem, allows_reg, is_inout;
kono
parents:
diff changeset
188
kono
parents:
diff changeset
189 oconstraints
kono
parents:
diff changeset
190 = (const char **) alloca ((noutputs) * sizeof (const char *));
kono
parents:
diff changeset
191 for (i = 0; i < noutputs; i++)
kono
parents:
diff changeset
192 {
kono
parents:
diff changeset
193 tree op = gimple_asm_output_op (asm_stmt, i);
kono
parents:
diff changeset
194 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op)));
kono
parents:
diff changeset
195 oconstraints[i] = constraint;
kono
parents:
diff changeset
196 parse_output_constraint (&constraint, i, 0, 0, &allows_mem,
kono
parents:
diff changeset
197 &allows_reg, &is_inout);
kono
parents:
diff changeset
198 gimplify_expr (&TREE_VALUE (op), &pre, NULL,
kono
parents:
diff changeset
199 is_inout ? is_gimple_min_lval : is_gimple_lvalue,
kono
parents:
diff changeset
200 fb_lvalue | fb_mayfail);
kono
parents:
diff changeset
201 }
kono
parents:
diff changeset
202 for (i = 0; i < gimple_asm_ninputs (asm_stmt); i++)
kono
parents:
diff changeset
203 {
kono
parents:
diff changeset
204 tree op = gimple_asm_input_op (asm_stmt, i);
kono
parents:
diff changeset
205 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op)));
kono
parents:
diff changeset
206 parse_input_constraint (&constraint, 0, 0, noutputs, 0,
kono
parents:
diff changeset
207 oconstraints, &allows_mem, &allows_reg);
kono
parents:
diff changeset
208 if (TREE_ADDRESSABLE (TREE_TYPE (TREE_VALUE (op))) && allows_mem)
kono
parents:
diff changeset
209 allows_reg = 0;
kono
parents:
diff changeset
210 if (!allows_reg && allows_mem)
kono
parents:
diff changeset
211 gimplify_expr (&TREE_VALUE (op), &pre, NULL,
kono
parents:
diff changeset
212 is_gimple_lvalue, fb_lvalue | fb_mayfail);
kono
parents:
diff changeset
213 else
kono
parents:
diff changeset
214 gimplify_expr (&TREE_VALUE (op), &pre, NULL,
kono
parents:
diff changeset
215 is_gimple_asm_val, fb_rvalue);
kono
parents:
diff changeset
216 }
kono
parents:
diff changeset
217 }
kono
parents:
diff changeset
218 break;
kono
parents:
diff changeset
219 default:
kono
parents:
diff changeset
220 /* NOTE: We start gimplifying operands from last to first to
kono
parents:
diff changeset
221 make sure that side-effects on the RHS of calls, assignments
kono
parents:
diff changeset
222 and ASMs are executed before the LHS. The ordering is not
kono
parents:
diff changeset
223 important for other statements. */
kono
parents:
diff changeset
224 num_ops = gimple_num_ops (stmt);
kono
parents:
diff changeset
225 for (i = num_ops; i > 0; i--)
kono
parents:
diff changeset
226 {
kono
parents:
diff changeset
227 tree op = gimple_op (stmt, i - 1);
kono
parents:
diff changeset
228 if (op == NULL_TREE)
kono
parents:
diff changeset
229 continue;
kono
parents:
diff changeset
230 if (i == 1 && (is_gimple_call (stmt) || is_gimple_assign (stmt)))
kono
parents:
diff changeset
231 gimplify_expr (&op, &pre, NULL, is_gimple_lvalue, fb_lvalue);
kono
parents:
diff changeset
232 else if (i == 2
kono
parents:
diff changeset
233 && is_gimple_assign (stmt)
kono
parents:
diff changeset
234 && num_ops == 2
kono
parents:
diff changeset
235 && get_gimple_rhs_class (gimple_expr_code (stmt))
kono
parents:
diff changeset
236 == GIMPLE_SINGLE_RHS)
kono
parents:
diff changeset
237 gimplify_expr (&op, &pre, NULL,
kono
parents:
diff changeset
238 rhs_predicate_for (gimple_assign_lhs (stmt)),
kono
parents:
diff changeset
239 fb_rvalue);
kono
parents:
diff changeset
240 else if (i == 2 && is_gimple_call (stmt))
kono
parents:
diff changeset
241 {
kono
parents:
diff changeset
242 if (TREE_CODE (op) == FUNCTION_DECL)
kono
parents:
diff changeset
243 continue;
kono
parents:
diff changeset
244 gimplify_expr (&op, &pre, NULL, is_gimple_call_addr, fb_rvalue);
kono
parents:
diff changeset
245 }
kono
parents:
diff changeset
246 else
kono
parents:
diff changeset
247 gimplify_expr (&op, &pre, NULL, is_gimple_val, fb_rvalue);
kono
parents:
diff changeset
248 gimple_set_op (stmt, i - 1, op);
kono
parents:
diff changeset
249 }
kono
parents:
diff changeset
250
kono
parents:
diff changeset
251 lhs = gimple_get_lhs (stmt);
kono
parents:
diff changeset
252 /* If the LHS changed it in a way that requires a simple RHS,
kono
parents:
diff changeset
253 create temporary. */
kono
parents:
diff changeset
254 if (lhs && !is_gimple_reg (lhs))
kono
parents:
diff changeset
255 {
kono
parents:
diff changeset
256 bool need_temp = false;
kono
parents:
diff changeset
257
kono
parents:
diff changeset
258 if (is_gimple_assign (stmt)
kono
parents:
diff changeset
259 && num_ops == 2
kono
parents:
diff changeset
260 && get_gimple_rhs_class (gimple_expr_code (stmt))
kono
parents:
diff changeset
261 == GIMPLE_SINGLE_RHS)
kono
parents:
diff changeset
262 gimplify_expr (gimple_assign_rhs1_ptr (stmt), &pre, NULL,
kono
parents:
diff changeset
263 rhs_predicate_for (gimple_assign_lhs (stmt)),
kono
parents:
diff changeset
264 fb_rvalue);
kono
parents:
diff changeset
265 else if (is_gimple_reg (lhs))
kono
parents:
diff changeset
266 {
kono
parents:
diff changeset
267 if (is_gimple_reg_type (TREE_TYPE (lhs)))
kono
parents:
diff changeset
268 {
kono
parents:
diff changeset
269 if (is_gimple_call (stmt))
kono
parents:
diff changeset
270 {
kono
parents:
diff changeset
271 i = gimple_call_flags (stmt);
kono
parents:
diff changeset
272 if ((i & ECF_LOOPING_CONST_OR_PURE)
kono
parents:
diff changeset
273 || !(i & (ECF_CONST | ECF_PURE)))
kono
parents:
diff changeset
274 need_temp = true;
kono
parents:
diff changeset
275 }
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
276 if (stmt_can_throw_internal (cfun, stmt))
111
kono
parents:
diff changeset
277 need_temp = true;
kono
parents:
diff changeset
278 }
kono
parents:
diff changeset
279 }
kono
parents:
diff changeset
280 else
kono
parents:
diff changeset
281 {
kono
parents:
diff changeset
282 if (is_gimple_reg_type (TREE_TYPE (lhs)))
kono
parents:
diff changeset
283 need_temp = true;
kono
parents:
diff changeset
284 else if (TYPE_MODE (TREE_TYPE (lhs)) != BLKmode)
kono
parents:
diff changeset
285 {
kono
parents:
diff changeset
286 if (is_gimple_call (stmt))
kono
parents:
diff changeset
287 {
kono
parents:
diff changeset
288 tree fndecl = gimple_call_fndecl (stmt);
kono
parents:
diff changeset
289
kono
parents:
diff changeset
290 if (!aggregate_value_p (TREE_TYPE (lhs), fndecl)
kono
parents:
diff changeset
291 && !(fndecl && DECL_RESULT (fndecl)
kono
parents:
diff changeset
292 && DECL_BY_REFERENCE (DECL_RESULT (fndecl))))
kono
parents:
diff changeset
293 need_temp = true;
kono
parents:
diff changeset
294 }
kono
parents:
diff changeset
295 else
kono
parents:
diff changeset
296 need_temp = true;
kono
parents:
diff changeset
297 }
kono
parents:
diff changeset
298 }
kono
parents:
diff changeset
299 if (need_temp)
kono
parents:
diff changeset
300 {
kono
parents:
diff changeset
301 tree temp = create_tmp_reg (TREE_TYPE (lhs));
kono
parents:
diff changeset
302 if (gimple_in_ssa_p (cfun)
kono
parents:
diff changeset
303 && is_gimple_reg_type (TREE_TYPE (lhs)))
kono
parents:
diff changeset
304 temp = make_ssa_name (temp);
kono
parents:
diff changeset
305 gimple_set_lhs (stmt, temp);
kono
parents:
diff changeset
306 post_stmt = gimple_build_assign (lhs, temp);
kono
parents:
diff changeset
307 }
kono
parents:
diff changeset
308 }
kono
parents:
diff changeset
309 break;
kono
parents:
diff changeset
310 }
kono
parents:
diff changeset
311
kono
parents:
diff changeset
312 if (!gimple_seq_empty_p (pre))
kono
parents:
diff changeset
313 gsi_insert_seq_before (gsi_p, pre, GSI_SAME_STMT);
kono
parents:
diff changeset
314 if (post_stmt)
kono
parents:
diff changeset
315 gsi_insert_after (gsi_p, post_stmt, GSI_NEW_STMT);
kono
parents:
diff changeset
316
kono
parents:
diff changeset
317 pop_gimplify_context (NULL);
kono
parents:
diff changeset
318
kono
parents:
diff changeset
319 update_stmt (stmt);
kono
parents:
diff changeset
320 }
kono
parents:
diff changeset
321
kono
parents:
diff changeset
322