annotate gcc/gimple-match-head.c @ 120:f93fa5091070

fix conv1.c
author mir3636
date Thu, 08 Mar 2018 14:53:42 +0900
parents 04ced10e8804
children 84e7813d76e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Preamble and helpers for the autogenerated gimple-match.c file.
kono
parents:
diff changeset
2 Copyright (C) 2014-2017 Free Software Foundation, Inc.
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 This file is part of GCC.
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 GCC is free software; you can redistribute it and/or modify it under
kono
parents:
diff changeset
7 the terms of the GNU General Public License as published by the Free
kono
parents:
diff changeset
8 Software Foundation; either version 3, or (at your option) any later
kono
parents:
diff changeset
9 version.
kono
parents:
diff changeset
10
kono
parents:
diff changeset
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
kono
parents:
diff changeset
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
kono
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
kono
parents:
diff changeset
14 for more details.
kono
parents:
diff changeset
15
kono
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
17 along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
18 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 #include "config.h"
kono
parents:
diff changeset
21 #include "system.h"
kono
parents:
diff changeset
22 #include "coretypes.h"
kono
parents:
diff changeset
23 #include "backend.h"
kono
parents:
diff changeset
24 #include "target.h"
kono
parents:
diff changeset
25 #include "rtl.h"
kono
parents:
diff changeset
26 #include "tree.h"
kono
parents:
diff changeset
27 #include "gimple.h"
kono
parents:
diff changeset
28 #include "ssa.h"
kono
parents:
diff changeset
29 #include "cgraph.h"
kono
parents:
diff changeset
30 #include "fold-const.h"
kono
parents:
diff changeset
31 #include "fold-const-call.h"
kono
parents:
diff changeset
32 #include "stor-layout.h"
kono
parents:
diff changeset
33 #include "gimple-fold.h"
kono
parents:
diff changeset
34 #include "calls.h"
kono
parents:
diff changeset
35 #include "tree-dfa.h"
kono
parents:
diff changeset
36 #include "builtins.h"
kono
parents:
diff changeset
37 #include "gimple-match.h"
kono
parents:
diff changeset
38 #include "tree-pass.h"
kono
parents:
diff changeset
39 #include "internal-fn.h"
kono
parents:
diff changeset
40 #include "case-cfn-macros.h"
kono
parents:
diff changeset
41 #include "gimplify.h"
kono
parents:
diff changeset
42 #include "optabs-tree.h"
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44
kono
parents:
diff changeset
45 /* Forward declarations of the private auto-generated matchers.
kono
parents:
diff changeset
46 They expect valueized operands in canonical order and do not
kono
parents:
diff changeset
47 perform simplification of all-constant operands. */
kono
parents:
diff changeset
48 static bool gimple_simplify (code_helper *, tree *,
kono
parents:
diff changeset
49 gimple_seq *, tree (*)(tree),
kono
parents:
diff changeset
50 code_helper, tree, tree);
kono
parents:
diff changeset
51 static bool gimple_simplify (code_helper *, tree *,
kono
parents:
diff changeset
52 gimple_seq *, tree (*)(tree),
kono
parents:
diff changeset
53 code_helper, tree, tree, tree);
kono
parents:
diff changeset
54 static bool gimple_simplify (code_helper *, tree *,
kono
parents:
diff changeset
55 gimple_seq *, tree (*)(tree),
kono
parents:
diff changeset
56 code_helper, tree, tree, tree, tree);
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 /* Return whether T is a constant that we'll dispatch to fold to
kono
parents:
diff changeset
60 evaluate fully constant expressions. */
kono
parents:
diff changeset
61
kono
parents:
diff changeset
62 static inline bool
kono
parents:
diff changeset
63 constant_for_folding (tree t)
kono
parents:
diff changeset
64 {
kono
parents:
diff changeset
65 return (CONSTANT_CLASS_P (t)
kono
parents:
diff changeset
66 /* The following is only interesting to string builtins. */
kono
parents:
diff changeset
67 || (TREE_CODE (t) == ADDR_EXPR
kono
parents:
diff changeset
68 && TREE_CODE (TREE_OPERAND (t, 0)) == STRING_CST));
kono
parents:
diff changeset
69 }
kono
parents:
diff changeset
70
kono
parents:
diff changeset
71
kono
parents:
diff changeset
72 /* Helper that matches and simplifies the toplevel result from
kono
parents:
diff changeset
73 a gimple_simplify run (where we don't want to build
kono
parents:
diff changeset
74 a stmt in case it's used in in-place folding). Replaces
kono
parents:
diff changeset
75 *RES_CODE and *RES_OPS with a simplified and/or canonicalized
kono
parents:
diff changeset
76 result and returns whether any change was made. */
kono
parents:
diff changeset
77
kono
parents:
diff changeset
78 bool
kono
parents:
diff changeset
79 gimple_resimplify1 (gimple_seq *seq,
kono
parents:
diff changeset
80 code_helper *res_code, tree type, tree *res_ops,
kono
parents:
diff changeset
81 tree (*valueize)(tree))
kono
parents:
diff changeset
82 {
kono
parents:
diff changeset
83 if (constant_for_folding (res_ops[0]))
kono
parents:
diff changeset
84 {
kono
parents:
diff changeset
85 tree tem = NULL_TREE;
kono
parents:
diff changeset
86 if (res_code->is_tree_code ())
kono
parents:
diff changeset
87 tem = const_unop (*res_code, type, res_ops[0]);
kono
parents:
diff changeset
88 else
kono
parents:
diff changeset
89 tem = fold_const_call (combined_fn (*res_code), type, res_ops[0]);
kono
parents:
diff changeset
90 if (tem != NULL_TREE
kono
parents:
diff changeset
91 && CONSTANT_CLASS_P (tem))
kono
parents:
diff changeset
92 {
kono
parents:
diff changeset
93 if (TREE_OVERFLOW_P (tem))
kono
parents:
diff changeset
94 tem = drop_tree_overflow (tem);
kono
parents:
diff changeset
95 res_ops[0] = tem;
kono
parents:
diff changeset
96 res_ops[1] = NULL_TREE;
kono
parents:
diff changeset
97 res_ops[2] = NULL_TREE;
kono
parents:
diff changeset
98 *res_code = TREE_CODE (res_ops[0]);
kono
parents:
diff changeset
99 return true;
kono
parents:
diff changeset
100 }
kono
parents:
diff changeset
101 }
kono
parents:
diff changeset
102
kono
parents:
diff changeset
103 code_helper res_code2;
kono
parents:
diff changeset
104 tree res_ops2[3] = {};
kono
parents:
diff changeset
105 if (gimple_simplify (&res_code2, res_ops2, seq, valueize,
kono
parents:
diff changeset
106 *res_code, type, res_ops[0]))
kono
parents:
diff changeset
107 {
kono
parents:
diff changeset
108 *res_code = res_code2;
kono
parents:
diff changeset
109 res_ops[0] = res_ops2[0];
kono
parents:
diff changeset
110 res_ops[1] = res_ops2[1];
kono
parents:
diff changeset
111 res_ops[2] = res_ops2[2];
kono
parents:
diff changeset
112 return true;
kono
parents:
diff changeset
113 }
kono
parents:
diff changeset
114
kono
parents:
diff changeset
115 return false;
kono
parents:
diff changeset
116 }
kono
parents:
diff changeset
117
kono
parents:
diff changeset
118 /* Helper that matches and simplifies the toplevel result from
kono
parents:
diff changeset
119 a gimple_simplify run (where we don't want to build
kono
parents:
diff changeset
120 a stmt in case it's used in in-place folding). Replaces
kono
parents:
diff changeset
121 *RES_CODE and *RES_OPS with a simplified and/or canonicalized
kono
parents:
diff changeset
122 result and returns whether any change was made. */
kono
parents:
diff changeset
123
kono
parents:
diff changeset
124 bool
kono
parents:
diff changeset
125 gimple_resimplify2 (gimple_seq *seq,
kono
parents:
diff changeset
126 code_helper *res_code, tree type, tree *res_ops,
kono
parents:
diff changeset
127 tree (*valueize)(tree))
kono
parents:
diff changeset
128 {
kono
parents:
diff changeset
129 if (constant_for_folding (res_ops[0]) && constant_for_folding (res_ops[1]))
kono
parents:
diff changeset
130 {
kono
parents:
diff changeset
131 tree tem = NULL_TREE;
kono
parents:
diff changeset
132 if (res_code->is_tree_code ())
kono
parents:
diff changeset
133 tem = const_binop (*res_code, type, res_ops[0], res_ops[1]);
kono
parents:
diff changeset
134 else
kono
parents:
diff changeset
135 tem = fold_const_call (combined_fn (*res_code), type,
kono
parents:
diff changeset
136 res_ops[0], res_ops[1]);
kono
parents:
diff changeset
137 if (tem != NULL_TREE
kono
parents:
diff changeset
138 && CONSTANT_CLASS_P (tem))
kono
parents:
diff changeset
139 {
kono
parents:
diff changeset
140 if (TREE_OVERFLOW_P (tem))
kono
parents:
diff changeset
141 tem = drop_tree_overflow (tem);
kono
parents:
diff changeset
142 res_ops[0] = tem;
kono
parents:
diff changeset
143 res_ops[1] = NULL_TREE;
kono
parents:
diff changeset
144 res_ops[2] = NULL_TREE;
kono
parents:
diff changeset
145 *res_code = TREE_CODE (res_ops[0]);
kono
parents:
diff changeset
146 return true;
kono
parents:
diff changeset
147 }
kono
parents:
diff changeset
148 }
kono
parents:
diff changeset
149
kono
parents:
diff changeset
150 /* Canonicalize operand order. */
kono
parents:
diff changeset
151 bool canonicalized = false;
kono
parents:
diff changeset
152 if (res_code->is_tree_code ()
kono
parents:
diff changeset
153 && (TREE_CODE_CLASS ((enum tree_code) *res_code) == tcc_comparison
kono
parents:
diff changeset
154 || commutative_tree_code (*res_code))
kono
parents:
diff changeset
155 && tree_swap_operands_p (res_ops[0], res_ops[1]))
kono
parents:
diff changeset
156 {
kono
parents:
diff changeset
157 std::swap (res_ops[0], res_ops[1]);
kono
parents:
diff changeset
158 if (TREE_CODE_CLASS ((enum tree_code) *res_code) == tcc_comparison)
kono
parents:
diff changeset
159 *res_code = swap_tree_comparison (*res_code);
kono
parents:
diff changeset
160 canonicalized = true;
kono
parents:
diff changeset
161 }
kono
parents:
diff changeset
162
kono
parents:
diff changeset
163 code_helper res_code2;
kono
parents:
diff changeset
164 tree res_ops2[3] = {};
kono
parents:
diff changeset
165 if (gimple_simplify (&res_code2, res_ops2, seq, valueize,
kono
parents:
diff changeset
166 *res_code, type, res_ops[0], res_ops[1]))
kono
parents:
diff changeset
167 {
kono
parents:
diff changeset
168 *res_code = res_code2;
kono
parents:
diff changeset
169 res_ops[0] = res_ops2[0];
kono
parents:
diff changeset
170 res_ops[1] = res_ops2[1];
kono
parents:
diff changeset
171 res_ops[2] = res_ops2[2];
kono
parents:
diff changeset
172 return true;
kono
parents:
diff changeset
173 }
kono
parents:
diff changeset
174
kono
parents:
diff changeset
175 return canonicalized;
kono
parents:
diff changeset
176 }
kono
parents:
diff changeset
177
kono
parents:
diff changeset
178 /* Helper that matches and simplifies the toplevel result from
kono
parents:
diff changeset
179 a gimple_simplify run (where we don't want to build
kono
parents:
diff changeset
180 a stmt in case it's used in in-place folding). Replaces
kono
parents:
diff changeset
181 *RES_CODE and *RES_OPS with a simplified and/or canonicalized
kono
parents:
diff changeset
182 result and returns whether any change was made. */
kono
parents:
diff changeset
183
kono
parents:
diff changeset
184 bool
kono
parents:
diff changeset
185 gimple_resimplify3 (gimple_seq *seq,
kono
parents:
diff changeset
186 code_helper *res_code, tree type, tree *res_ops,
kono
parents:
diff changeset
187 tree (*valueize)(tree))
kono
parents:
diff changeset
188 {
kono
parents:
diff changeset
189 if (constant_for_folding (res_ops[0]) && constant_for_folding (res_ops[1])
kono
parents:
diff changeset
190 && constant_for_folding (res_ops[2]))
kono
parents:
diff changeset
191 {
kono
parents:
diff changeset
192 tree tem = NULL_TREE;
kono
parents:
diff changeset
193 if (res_code->is_tree_code ())
kono
parents:
diff changeset
194 tem = fold_ternary/*_to_constant*/ (*res_code, type, res_ops[0],
kono
parents:
diff changeset
195 res_ops[1], res_ops[2]);
kono
parents:
diff changeset
196 else
kono
parents:
diff changeset
197 tem = fold_const_call (combined_fn (*res_code), type,
kono
parents:
diff changeset
198 res_ops[0], res_ops[1], res_ops[2]);
kono
parents:
diff changeset
199 if (tem != NULL_TREE
kono
parents:
diff changeset
200 && CONSTANT_CLASS_P (tem))
kono
parents:
diff changeset
201 {
kono
parents:
diff changeset
202 if (TREE_OVERFLOW_P (tem))
kono
parents:
diff changeset
203 tem = drop_tree_overflow (tem);
kono
parents:
diff changeset
204 res_ops[0] = tem;
kono
parents:
diff changeset
205 res_ops[1] = NULL_TREE;
kono
parents:
diff changeset
206 res_ops[2] = NULL_TREE;
kono
parents:
diff changeset
207 *res_code = TREE_CODE (res_ops[0]);
kono
parents:
diff changeset
208 return true;
kono
parents:
diff changeset
209 }
kono
parents:
diff changeset
210 }
kono
parents:
diff changeset
211
kono
parents:
diff changeset
212 /* Canonicalize operand order. */
kono
parents:
diff changeset
213 bool canonicalized = false;
kono
parents:
diff changeset
214 if (res_code->is_tree_code ()
kono
parents:
diff changeset
215 && commutative_ternary_tree_code (*res_code)
kono
parents:
diff changeset
216 && tree_swap_operands_p (res_ops[0], res_ops[1]))
kono
parents:
diff changeset
217 {
kono
parents:
diff changeset
218 std::swap (res_ops[0], res_ops[1]);
kono
parents:
diff changeset
219 canonicalized = true;
kono
parents:
diff changeset
220 }
kono
parents:
diff changeset
221
kono
parents:
diff changeset
222 code_helper res_code2;
kono
parents:
diff changeset
223 tree res_ops2[3] = {};
kono
parents:
diff changeset
224 if (gimple_simplify (&res_code2, res_ops2, seq, valueize,
kono
parents:
diff changeset
225 *res_code, type,
kono
parents:
diff changeset
226 res_ops[0], res_ops[1], res_ops[2]))
kono
parents:
diff changeset
227 {
kono
parents:
diff changeset
228 *res_code = res_code2;
kono
parents:
diff changeset
229 res_ops[0] = res_ops2[0];
kono
parents:
diff changeset
230 res_ops[1] = res_ops2[1];
kono
parents:
diff changeset
231 res_ops[2] = res_ops2[2];
kono
parents:
diff changeset
232 return true;
kono
parents:
diff changeset
233 }
kono
parents:
diff changeset
234
kono
parents:
diff changeset
235 return canonicalized;
kono
parents:
diff changeset
236 }
kono
parents:
diff changeset
237
kono
parents:
diff changeset
238
kono
parents:
diff changeset
239 /* If in GIMPLE expressions with CODE go as single-rhs build
kono
parents:
diff changeset
240 a GENERIC tree for that expression into *OP0. */
kono
parents:
diff changeset
241
kono
parents:
diff changeset
242 void
kono
parents:
diff changeset
243 maybe_build_generic_op (enum tree_code code, tree type, tree *ops)
kono
parents:
diff changeset
244 {
kono
parents:
diff changeset
245 switch (code)
kono
parents:
diff changeset
246 {
kono
parents:
diff changeset
247 case REALPART_EXPR:
kono
parents:
diff changeset
248 case IMAGPART_EXPR:
kono
parents:
diff changeset
249 case VIEW_CONVERT_EXPR:
kono
parents:
diff changeset
250 ops[0] = build1 (code, type, ops[0]);
kono
parents:
diff changeset
251 break;
kono
parents:
diff changeset
252 case BIT_FIELD_REF:
kono
parents:
diff changeset
253 ops[0] = build3 (code, type, ops[0], ops[1], ops[2]);
kono
parents:
diff changeset
254 ops[1] = ops[2] = NULL_TREE;
kono
parents:
diff changeset
255 break;
kono
parents:
diff changeset
256 default:;
kono
parents:
diff changeset
257 }
kono
parents:
diff changeset
258 }
kono
parents:
diff changeset
259
kono
parents:
diff changeset
260 tree (*mprts_hook) (code_helper, tree, tree *);
kono
parents:
diff changeset
261
kono
parents:
diff changeset
262 /* Try to build a call to FN with return type TYPE and the NARGS
kono
parents:
diff changeset
263 arguments given in OPS. Return null if the target doesn't support
kono
parents:
diff changeset
264 the function. */
kono
parents:
diff changeset
265
kono
parents:
diff changeset
266 static gcall *
kono
parents:
diff changeset
267 build_call_internal (internal_fn fn, tree type, unsigned int nargs, tree *ops)
kono
parents:
diff changeset
268 {
kono
parents:
diff changeset
269 if (direct_internal_fn_p (fn))
kono
parents:
diff changeset
270 {
kono
parents:
diff changeset
271 tree_pair types = direct_internal_fn_types (fn, type, ops);
kono
parents:
diff changeset
272 if (!direct_internal_fn_supported_p (fn, types, OPTIMIZE_FOR_BOTH))
kono
parents:
diff changeset
273 return NULL;
kono
parents:
diff changeset
274 }
kono
parents:
diff changeset
275 return gimple_build_call_internal (fn, nargs, ops[0], ops[1], ops[2]);
kono
parents:
diff changeset
276 }
kono
parents:
diff changeset
277
kono
parents:
diff changeset
278 /* Push the exploded expression described by RCODE, TYPE and OPS
kono
parents:
diff changeset
279 as a statement to SEQ if necessary and return a gimple value
kono
parents:
diff changeset
280 denoting the value of the expression. If RES is not NULL
kono
parents:
diff changeset
281 then the result will be always RES and even gimple values are
kono
parents:
diff changeset
282 pushed to SEQ. */
kono
parents:
diff changeset
283
kono
parents:
diff changeset
284 tree
kono
parents:
diff changeset
285 maybe_push_res_to_seq (code_helper rcode, tree type, tree *ops,
kono
parents:
diff changeset
286 gimple_seq *seq, tree res)
kono
parents:
diff changeset
287 {
kono
parents:
diff changeset
288 if (rcode.is_tree_code ())
kono
parents:
diff changeset
289 {
kono
parents:
diff changeset
290 if (!res
kono
parents:
diff changeset
291 && gimple_simplified_result_is_gimple_val (rcode, ops))
kono
parents:
diff changeset
292 return ops[0];
kono
parents:
diff changeset
293 if (mprts_hook)
kono
parents:
diff changeset
294 {
kono
parents:
diff changeset
295 tree tem = mprts_hook (rcode, type, ops);
kono
parents:
diff changeset
296 if (tem)
kono
parents:
diff changeset
297 return tem;
kono
parents:
diff changeset
298 }
kono
parents:
diff changeset
299 if (!seq)
kono
parents:
diff changeset
300 return NULL_TREE;
kono
parents:
diff changeset
301 /* Play safe and do not allow abnormals to be mentioned in
kono
parents:
diff changeset
302 newly created statements. */
kono
parents:
diff changeset
303 if ((TREE_CODE (ops[0]) == SSA_NAME
kono
parents:
diff changeset
304 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops[0]))
kono
parents:
diff changeset
305 || (ops[1]
kono
parents:
diff changeset
306 && TREE_CODE (ops[1]) == SSA_NAME
kono
parents:
diff changeset
307 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops[1]))
kono
parents:
diff changeset
308 || (ops[2]
kono
parents:
diff changeset
309 && TREE_CODE (ops[2]) == SSA_NAME
kono
parents:
diff changeset
310 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops[2]))
kono
parents:
diff changeset
311 || (COMPARISON_CLASS_P (ops[0])
kono
parents:
diff changeset
312 && ((TREE_CODE (TREE_OPERAND (ops[0], 0)) == SSA_NAME
kono
parents:
diff changeset
313 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (TREE_OPERAND (ops[0],
kono
parents:
diff changeset
314 0)))
kono
parents:
diff changeset
315 || (TREE_CODE (TREE_OPERAND (ops[0], 1)) == SSA_NAME
kono
parents:
diff changeset
316 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (TREE_OPERAND (ops[0],
kono
parents:
diff changeset
317 1))))))
kono
parents:
diff changeset
318 return NULL_TREE;
kono
parents:
diff changeset
319 if (!res)
kono
parents:
diff changeset
320 {
kono
parents:
diff changeset
321 if (gimple_in_ssa_p (cfun))
kono
parents:
diff changeset
322 res = make_ssa_name (type);
kono
parents:
diff changeset
323 else
kono
parents:
diff changeset
324 res = create_tmp_reg (type);
kono
parents:
diff changeset
325 }
kono
parents:
diff changeset
326 maybe_build_generic_op (rcode, type, ops);
kono
parents:
diff changeset
327 gimple *new_stmt = gimple_build_assign (res, rcode,
kono
parents:
diff changeset
328 ops[0], ops[1], ops[2]);
kono
parents:
diff changeset
329 gimple_seq_add_stmt_without_update (seq, new_stmt);
kono
parents:
diff changeset
330 return res;
kono
parents:
diff changeset
331 }
kono
parents:
diff changeset
332 else
kono
parents:
diff changeset
333 {
kono
parents:
diff changeset
334 if (!seq)
kono
parents:
diff changeset
335 return NULL_TREE;
kono
parents:
diff changeset
336 combined_fn fn = rcode;
kono
parents:
diff changeset
337 /* Play safe and do not allow abnormals to be mentioned in
kono
parents:
diff changeset
338 newly created statements. */
kono
parents:
diff changeset
339 unsigned nargs;
kono
parents:
diff changeset
340 for (nargs = 0; nargs < 3; ++nargs)
kono
parents:
diff changeset
341 {
kono
parents:
diff changeset
342 if (!ops[nargs])
kono
parents:
diff changeset
343 break;
kono
parents:
diff changeset
344 if (TREE_CODE (ops[nargs]) == SSA_NAME
kono
parents:
diff changeset
345 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops[nargs]))
kono
parents:
diff changeset
346 return NULL_TREE;
kono
parents:
diff changeset
347 }
kono
parents:
diff changeset
348 gcc_assert (nargs != 0);
kono
parents:
diff changeset
349 gcall *new_stmt = NULL;
kono
parents:
diff changeset
350 if (internal_fn_p (fn))
kono
parents:
diff changeset
351 {
kono
parents:
diff changeset
352 /* Generate the given function if we can. */
kono
parents:
diff changeset
353 internal_fn ifn = as_internal_fn (fn);
kono
parents:
diff changeset
354 new_stmt = build_call_internal (ifn, type, nargs, ops);
kono
parents:
diff changeset
355 if (!new_stmt)
kono
parents:
diff changeset
356 return NULL_TREE;
kono
parents:
diff changeset
357 }
kono
parents:
diff changeset
358 else
kono
parents:
diff changeset
359 {
kono
parents:
diff changeset
360 /* Find the function we want to call. */
kono
parents:
diff changeset
361 tree decl = builtin_decl_implicit (as_builtin_fn (fn));
kono
parents:
diff changeset
362 if (!decl)
kono
parents:
diff changeset
363 return NULL;
kono
parents:
diff changeset
364
kono
parents:
diff changeset
365 /* We can't and should not emit calls to non-const functions. */
kono
parents:
diff changeset
366 if (!(flags_from_decl_or_type (decl) & ECF_CONST))
kono
parents:
diff changeset
367 return NULL;
kono
parents:
diff changeset
368
kono
parents:
diff changeset
369 new_stmt = gimple_build_call (decl, nargs, ops[0], ops[1], ops[2]);
kono
parents:
diff changeset
370 }
kono
parents:
diff changeset
371 if (!res)
kono
parents:
diff changeset
372 {
kono
parents:
diff changeset
373 if (gimple_in_ssa_p (cfun))
kono
parents:
diff changeset
374 res = make_ssa_name (type);
kono
parents:
diff changeset
375 else
kono
parents:
diff changeset
376 res = create_tmp_reg (type);
kono
parents:
diff changeset
377 }
kono
parents:
diff changeset
378 gimple_call_set_lhs (new_stmt, res);
kono
parents:
diff changeset
379 gimple_seq_add_stmt_without_update (seq, new_stmt);
kono
parents:
diff changeset
380 return res;
kono
parents:
diff changeset
381 }
kono
parents:
diff changeset
382 }
kono
parents:
diff changeset
383
kono
parents:
diff changeset
384
kono
parents:
diff changeset
385 /* Public API overloads follow for operation being tree_code or
kono
parents:
diff changeset
386 built_in_function and for one to three operands or arguments.
kono
parents:
diff changeset
387 They return NULL_TREE if nothing could be simplified or
kono
parents:
diff changeset
388 the resulting simplified value with parts pushed to SEQ.
kono
parents:
diff changeset
389 If SEQ is NULL then if the simplification needs to create
kono
parents:
diff changeset
390 new stmts it will fail. If VALUEIZE is non-NULL then all
kono
parents:
diff changeset
391 SSA names will be valueized using that hook prior to
kono
parents:
diff changeset
392 applying simplifications. */
kono
parents:
diff changeset
393
kono
parents:
diff changeset
394 /* Unary ops. */
kono
parents:
diff changeset
395
kono
parents:
diff changeset
396 tree
kono
parents:
diff changeset
397 gimple_simplify (enum tree_code code, tree type,
kono
parents:
diff changeset
398 tree op0,
kono
parents:
diff changeset
399 gimple_seq *seq, tree (*valueize)(tree))
kono
parents:
diff changeset
400 {
kono
parents:
diff changeset
401 if (constant_for_folding (op0))
kono
parents:
diff changeset
402 {
kono
parents:
diff changeset
403 tree res = const_unop (code, type, op0);
kono
parents:
diff changeset
404 if (res != NULL_TREE
kono
parents:
diff changeset
405 && CONSTANT_CLASS_P (res))
kono
parents:
diff changeset
406 return res;
kono
parents:
diff changeset
407 }
kono
parents:
diff changeset
408
kono
parents:
diff changeset
409 code_helper rcode;
kono
parents:
diff changeset
410 tree ops[3] = {};
kono
parents:
diff changeset
411 if (!gimple_simplify (&rcode, ops, seq, valueize,
kono
parents:
diff changeset
412 code, type, op0))
kono
parents:
diff changeset
413 return NULL_TREE;
kono
parents:
diff changeset
414 return maybe_push_res_to_seq (rcode, type, ops, seq);
kono
parents:
diff changeset
415 }
kono
parents:
diff changeset
416
kono
parents:
diff changeset
417 /* Binary ops. */
kono
parents:
diff changeset
418
kono
parents:
diff changeset
419 tree
kono
parents:
diff changeset
420 gimple_simplify (enum tree_code code, tree type,
kono
parents:
diff changeset
421 tree op0, tree op1,
kono
parents:
diff changeset
422 gimple_seq *seq, tree (*valueize)(tree))
kono
parents:
diff changeset
423 {
kono
parents:
diff changeset
424 if (constant_for_folding (op0) && constant_for_folding (op1))
kono
parents:
diff changeset
425 {
kono
parents:
diff changeset
426 tree res = const_binop (code, type, op0, op1);
kono
parents:
diff changeset
427 if (res != NULL_TREE
kono
parents:
diff changeset
428 && CONSTANT_CLASS_P (res))
kono
parents:
diff changeset
429 return res;
kono
parents:
diff changeset
430 }
kono
parents:
diff changeset
431
kono
parents:
diff changeset
432 /* Canonicalize operand order both for matching and fallback stmt
kono
parents:
diff changeset
433 generation. */
kono
parents:
diff changeset
434 if ((commutative_tree_code (code)
kono
parents:
diff changeset
435 || TREE_CODE_CLASS (code) == tcc_comparison)
kono
parents:
diff changeset
436 && tree_swap_operands_p (op0, op1))
kono
parents:
diff changeset
437 {
kono
parents:
diff changeset
438 std::swap (op0, op1);
kono
parents:
diff changeset
439 if (TREE_CODE_CLASS (code) == tcc_comparison)
kono
parents:
diff changeset
440 code = swap_tree_comparison (code);
kono
parents:
diff changeset
441 }
kono
parents:
diff changeset
442
kono
parents:
diff changeset
443 code_helper rcode;
kono
parents:
diff changeset
444 tree ops[3] = {};
kono
parents:
diff changeset
445 if (!gimple_simplify (&rcode, ops, seq, valueize,
kono
parents:
diff changeset
446 code, type, op0, op1))
kono
parents:
diff changeset
447 return NULL_TREE;
kono
parents:
diff changeset
448 return maybe_push_res_to_seq (rcode, type, ops, seq);
kono
parents:
diff changeset
449 }
kono
parents:
diff changeset
450
kono
parents:
diff changeset
451 /* Ternary ops. */
kono
parents:
diff changeset
452
kono
parents:
diff changeset
453 tree
kono
parents:
diff changeset
454 gimple_simplify (enum tree_code code, tree type,
kono
parents:
diff changeset
455 tree op0, tree op1, tree op2,
kono
parents:
diff changeset
456 gimple_seq *seq, tree (*valueize)(tree))
kono
parents:
diff changeset
457 {
kono
parents:
diff changeset
458 if (constant_for_folding (op0) && constant_for_folding (op1)
kono
parents:
diff changeset
459 && constant_for_folding (op2))
kono
parents:
diff changeset
460 {
kono
parents:
diff changeset
461 tree res = fold_ternary/*_to_constant */ (code, type, op0, op1, op2);
kono
parents:
diff changeset
462 if (res != NULL_TREE
kono
parents:
diff changeset
463 && CONSTANT_CLASS_P (res))
kono
parents:
diff changeset
464 return res;
kono
parents:
diff changeset
465 }
kono
parents:
diff changeset
466
kono
parents:
diff changeset
467 /* Canonicalize operand order both for matching and fallback stmt
kono
parents:
diff changeset
468 generation. */
kono
parents:
diff changeset
469 if (commutative_ternary_tree_code (code)
kono
parents:
diff changeset
470 && tree_swap_operands_p (op0, op1))
kono
parents:
diff changeset
471 std::swap (op0, op1);
kono
parents:
diff changeset
472
kono
parents:
diff changeset
473 code_helper rcode;
kono
parents:
diff changeset
474 tree ops[3] = {};
kono
parents:
diff changeset
475 if (!gimple_simplify (&rcode, ops, seq, valueize,
kono
parents:
diff changeset
476 code, type, op0, op1, op2))
kono
parents:
diff changeset
477 return NULL_TREE;
kono
parents:
diff changeset
478 return maybe_push_res_to_seq (rcode, type, ops, seq);
kono
parents:
diff changeset
479 }
kono
parents:
diff changeset
480
kono
parents:
diff changeset
481 /* Builtin function with one argument. */
kono
parents:
diff changeset
482
kono
parents:
diff changeset
483 tree
kono
parents:
diff changeset
484 gimple_simplify (enum built_in_function fn, tree type,
kono
parents:
diff changeset
485 tree arg0,
kono
parents:
diff changeset
486 gimple_seq *seq, tree (*valueize)(tree))
kono
parents:
diff changeset
487 {
kono
parents:
diff changeset
488 if (constant_for_folding (arg0))
kono
parents:
diff changeset
489 {
kono
parents:
diff changeset
490 tree res = fold_const_call (as_combined_fn (fn), type, arg0);
kono
parents:
diff changeset
491 if (res && CONSTANT_CLASS_P (res))
kono
parents:
diff changeset
492 return res;
kono
parents:
diff changeset
493 }
kono
parents:
diff changeset
494
kono
parents:
diff changeset
495 code_helper rcode;
kono
parents:
diff changeset
496 tree ops[3] = {};
kono
parents:
diff changeset
497 if (!gimple_simplify (&rcode, ops, seq, valueize,
kono
parents:
diff changeset
498 as_combined_fn (fn), type, arg0))
kono
parents:
diff changeset
499 return NULL_TREE;
kono
parents:
diff changeset
500 return maybe_push_res_to_seq (rcode, type, ops, seq);
kono
parents:
diff changeset
501 }
kono
parents:
diff changeset
502
kono
parents:
diff changeset
503 /* Builtin function with two arguments. */
kono
parents:
diff changeset
504
kono
parents:
diff changeset
505 tree
kono
parents:
diff changeset
506 gimple_simplify (enum built_in_function fn, tree type,
kono
parents:
diff changeset
507 tree arg0, tree arg1,
kono
parents:
diff changeset
508 gimple_seq *seq, tree (*valueize)(tree))
kono
parents:
diff changeset
509 {
kono
parents:
diff changeset
510 if (constant_for_folding (arg0)
kono
parents:
diff changeset
511 && constant_for_folding (arg1))
kono
parents:
diff changeset
512 {
kono
parents:
diff changeset
513 tree res = fold_const_call (as_combined_fn (fn), type, arg0, arg1);
kono
parents:
diff changeset
514 if (res && CONSTANT_CLASS_P (res))
kono
parents:
diff changeset
515 return res;
kono
parents:
diff changeset
516 }
kono
parents:
diff changeset
517
kono
parents:
diff changeset
518 code_helper rcode;
kono
parents:
diff changeset
519 tree ops[3] = {};
kono
parents:
diff changeset
520 if (!gimple_simplify (&rcode, ops, seq, valueize,
kono
parents:
diff changeset
521 as_combined_fn (fn), type, arg0, arg1))
kono
parents:
diff changeset
522 return NULL_TREE;
kono
parents:
diff changeset
523 return maybe_push_res_to_seq (rcode, type, ops, seq);
kono
parents:
diff changeset
524 }
kono
parents:
diff changeset
525
kono
parents:
diff changeset
526 /* Builtin function with three arguments. */
kono
parents:
diff changeset
527
kono
parents:
diff changeset
528 tree
kono
parents:
diff changeset
529 gimple_simplify (enum built_in_function fn, tree type,
kono
parents:
diff changeset
530 tree arg0, tree arg1, tree arg2,
kono
parents:
diff changeset
531 gimple_seq *seq, tree (*valueize)(tree))
kono
parents:
diff changeset
532 {
kono
parents:
diff changeset
533 if (constant_for_folding (arg0)
kono
parents:
diff changeset
534 && constant_for_folding (arg1)
kono
parents:
diff changeset
535 && constant_for_folding (arg2))
kono
parents:
diff changeset
536 {
kono
parents:
diff changeset
537 tree res = fold_const_call (as_combined_fn (fn), type, arg0, arg1, arg2);
kono
parents:
diff changeset
538 if (res && CONSTANT_CLASS_P (res))
kono
parents:
diff changeset
539 return res;
kono
parents:
diff changeset
540 }
kono
parents:
diff changeset
541
kono
parents:
diff changeset
542 code_helper rcode;
kono
parents:
diff changeset
543 tree ops[3] = {};
kono
parents:
diff changeset
544 if (!gimple_simplify (&rcode, ops, seq, valueize,
kono
parents:
diff changeset
545 as_combined_fn (fn), type, arg0, arg1, arg2))
kono
parents:
diff changeset
546 return NULL_TREE;
kono
parents:
diff changeset
547 return maybe_push_res_to_seq (rcode, type, ops, seq);
kono
parents:
diff changeset
548 }
kono
parents:
diff changeset
549
kono
parents:
diff changeset
550 /* Helper for gimple_simplify valueizing OP using VALUEIZE and setting
kono
parents:
diff changeset
551 VALUEIZED to true if valueization changed OP. */
kono
parents:
diff changeset
552
kono
parents:
diff changeset
553 static inline tree
kono
parents:
diff changeset
554 do_valueize (tree op, tree (*valueize)(tree), bool &valueized)
kono
parents:
diff changeset
555 {
kono
parents:
diff changeset
556 if (valueize && TREE_CODE (op) == SSA_NAME)
kono
parents:
diff changeset
557 {
kono
parents:
diff changeset
558 tree tem = valueize (op);
kono
parents:
diff changeset
559 if (tem && tem != op)
kono
parents:
diff changeset
560 {
kono
parents:
diff changeset
561 op = tem;
kono
parents:
diff changeset
562 valueized = true;
kono
parents:
diff changeset
563 }
kono
parents:
diff changeset
564 }
kono
parents:
diff changeset
565 return op;
kono
parents:
diff changeset
566 }
kono
parents:
diff changeset
567
kono
parents:
diff changeset
568 /* The main STMT based simplification entry. It is used by the fold_stmt
kono
parents:
diff changeset
569 and the fold_stmt_to_constant APIs. */
kono
parents:
diff changeset
570
kono
parents:
diff changeset
571 bool
kono
parents:
diff changeset
572 gimple_simplify (gimple *stmt,
kono
parents:
diff changeset
573 code_helper *rcode, tree *ops,
kono
parents:
diff changeset
574 gimple_seq *seq,
kono
parents:
diff changeset
575 tree (*valueize)(tree), tree (*top_valueize)(tree))
kono
parents:
diff changeset
576 {
kono
parents:
diff changeset
577 switch (gimple_code (stmt))
kono
parents:
diff changeset
578 {
kono
parents:
diff changeset
579 case GIMPLE_ASSIGN:
kono
parents:
diff changeset
580 {
kono
parents:
diff changeset
581 enum tree_code code = gimple_assign_rhs_code (stmt);
kono
parents:
diff changeset
582 tree type = TREE_TYPE (gimple_assign_lhs (stmt));
kono
parents:
diff changeset
583 switch (gimple_assign_rhs_class (stmt))
kono
parents:
diff changeset
584 {
kono
parents:
diff changeset
585 case GIMPLE_SINGLE_RHS:
kono
parents:
diff changeset
586 if (code == REALPART_EXPR
kono
parents:
diff changeset
587 || code == IMAGPART_EXPR
kono
parents:
diff changeset
588 || code == VIEW_CONVERT_EXPR)
kono
parents:
diff changeset
589 {
kono
parents:
diff changeset
590 tree op0 = TREE_OPERAND (gimple_assign_rhs1 (stmt), 0);
kono
parents:
diff changeset
591 bool valueized = false;
kono
parents:
diff changeset
592 op0 = do_valueize (op0, top_valueize, valueized);
kono
parents:
diff changeset
593 *rcode = code;
kono
parents:
diff changeset
594 ops[0] = op0;
kono
parents:
diff changeset
595 return (gimple_resimplify1 (seq, rcode, type, ops, valueize)
kono
parents:
diff changeset
596 || valueized);
kono
parents:
diff changeset
597 }
kono
parents:
diff changeset
598 else if (code == BIT_FIELD_REF)
kono
parents:
diff changeset
599 {
kono
parents:
diff changeset
600 tree rhs1 = gimple_assign_rhs1 (stmt);
kono
parents:
diff changeset
601 tree op0 = TREE_OPERAND (rhs1, 0);
kono
parents:
diff changeset
602 bool valueized = false;
kono
parents:
diff changeset
603 op0 = do_valueize (op0, top_valueize, valueized);
kono
parents:
diff changeset
604 *rcode = code;
kono
parents:
diff changeset
605 ops[0] = op0;
kono
parents:
diff changeset
606 ops[1] = TREE_OPERAND (rhs1, 1);
kono
parents:
diff changeset
607 ops[2] = TREE_OPERAND (rhs1, 2);
kono
parents:
diff changeset
608 return (gimple_resimplify3 (seq, rcode, type, ops, valueize)
kono
parents:
diff changeset
609 || valueized);
kono
parents:
diff changeset
610 }
kono
parents:
diff changeset
611 else if (code == SSA_NAME
kono
parents:
diff changeset
612 && top_valueize)
kono
parents:
diff changeset
613 {
kono
parents:
diff changeset
614 tree op0 = gimple_assign_rhs1 (stmt);
kono
parents:
diff changeset
615 tree valueized = top_valueize (op0);
kono
parents:
diff changeset
616 if (!valueized || op0 == valueized)
kono
parents:
diff changeset
617 return false;
kono
parents:
diff changeset
618 ops[0] = valueized;
kono
parents:
diff changeset
619 *rcode = TREE_CODE (op0);
kono
parents:
diff changeset
620 return true;
kono
parents:
diff changeset
621 }
kono
parents:
diff changeset
622 break;
kono
parents:
diff changeset
623 case GIMPLE_UNARY_RHS:
kono
parents:
diff changeset
624 {
kono
parents:
diff changeset
625 tree rhs1 = gimple_assign_rhs1 (stmt);
kono
parents:
diff changeset
626 bool valueized = false;
kono
parents:
diff changeset
627 rhs1 = do_valueize (rhs1, top_valueize, valueized);
kono
parents:
diff changeset
628 *rcode = code;
kono
parents:
diff changeset
629 ops[0] = rhs1;
kono
parents:
diff changeset
630 return (gimple_resimplify1 (seq, rcode, type, ops, valueize)
kono
parents:
diff changeset
631 || valueized);
kono
parents:
diff changeset
632 }
kono
parents:
diff changeset
633 case GIMPLE_BINARY_RHS:
kono
parents:
diff changeset
634 {
kono
parents:
diff changeset
635 tree rhs1 = gimple_assign_rhs1 (stmt);
kono
parents:
diff changeset
636 tree rhs2 = gimple_assign_rhs2 (stmt);
kono
parents:
diff changeset
637 bool valueized = false;
kono
parents:
diff changeset
638 rhs1 = do_valueize (rhs1, top_valueize, valueized);
kono
parents:
diff changeset
639 rhs2 = do_valueize (rhs2, top_valueize, valueized);
kono
parents:
diff changeset
640 *rcode = code;
kono
parents:
diff changeset
641 ops[0] = rhs1;
kono
parents:
diff changeset
642 ops[1] = rhs2;
kono
parents:
diff changeset
643 return (gimple_resimplify2 (seq, rcode, type, ops, valueize)
kono
parents:
diff changeset
644 || valueized);
kono
parents:
diff changeset
645 }
kono
parents:
diff changeset
646 case GIMPLE_TERNARY_RHS:
kono
parents:
diff changeset
647 {
kono
parents:
diff changeset
648 bool valueized = false;
kono
parents:
diff changeset
649 tree rhs1 = gimple_assign_rhs1 (stmt);
kono
parents:
diff changeset
650 /* If this is a [VEC_]COND_EXPR first try to simplify an
kono
parents:
diff changeset
651 embedded GENERIC condition. */
kono
parents:
diff changeset
652 if (code == COND_EXPR
kono
parents:
diff changeset
653 || code == VEC_COND_EXPR)
kono
parents:
diff changeset
654 {
kono
parents:
diff changeset
655 if (COMPARISON_CLASS_P (rhs1))
kono
parents:
diff changeset
656 {
kono
parents:
diff changeset
657 tree lhs = TREE_OPERAND (rhs1, 0);
kono
parents:
diff changeset
658 tree rhs = TREE_OPERAND (rhs1, 1);
kono
parents:
diff changeset
659 lhs = do_valueize (lhs, top_valueize, valueized);
kono
parents:
diff changeset
660 rhs = do_valueize (rhs, top_valueize, valueized);
kono
parents:
diff changeset
661 code_helper rcode2 = TREE_CODE (rhs1);
kono
parents:
diff changeset
662 tree ops2[3] = {};
kono
parents:
diff changeset
663 ops2[0] = lhs;
kono
parents:
diff changeset
664 ops2[1] = rhs;
kono
parents:
diff changeset
665 if ((gimple_resimplify2 (seq, &rcode2, TREE_TYPE (rhs1),
kono
parents:
diff changeset
666 ops2, valueize)
kono
parents:
diff changeset
667 || valueized)
kono
parents:
diff changeset
668 && rcode2.is_tree_code ())
kono
parents:
diff changeset
669 {
kono
parents:
diff changeset
670 valueized = true;
kono
parents:
diff changeset
671 if (TREE_CODE_CLASS ((enum tree_code)rcode2)
kono
parents:
diff changeset
672 == tcc_comparison)
kono
parents:
diff changeset
673 rhs1 = build2 (rcode2, TREE_TYPE (rhs1),
kono
parents:
diff changeset
674 ops2[0], ops2[1]);
kono
parents:
diff changeset
675 else if (rcode2 == SSA_NAME
kono
parents:
diff changeset
676 || rcode2 == INTEGER_CST
kono
parents:
diff changeset
677 || rcode2 == VECTOR_CST)
kono
parents:
diff changeset
678 rhs1 = ops2[0];
kono
parents:
diff changeset
679 else
kono
parents:
diff changeset
680 valueized = false;
kono
parents:
diff changeset
681 }
kono
parents:
diff changeset
682 }
kono
parents:
diff changeset
683 }
kono
parents:
diff changeset
684 tree rhs2 = gimple_assign_rhs2 (stmt);
kono
parents:
diff changeset
685 tree rhs3 = gimple_assign_rhs3 (stmt);
kono
parents:
diff changeset
686 rhs1 = do_valueize (rhs1, top_valueize, valueized);
kono
parents:
diff changeset
687 rhs2 = do_valueize (rhs2, top_valueize, valueized);
kono
parents:
diff changeset
688 rhs3 = do_valueize (rhs3, top_valueize, valueized);
kono
parents:
diff changeset
689 *rcode = code;
kono
parents:
diff changeset
690 ops[0] = rhs1;
kono
parents:
diff changeset
691 ops[1] = rhs2;
kono
parents:
diff changeset
692 ops[2] = rhs3;
kono
parents:
diff changeset
693 return (gimple_resimplify3 (seq, rcode, type, ops, valueize)
kono
parents:
diff changeset
694 || valueized);
kono
parents:
diff changeset
695 }
kono
parents:
diff changeset
696 default:
kono
parents:
diff changeset
697 gcc_unreachable ();
kono
parents:
diff changeset
698 }
kono
parents:
diff changeset
699 break;
kono
parents:
diff changeset
700 }
kono
parents:
diff changeset
701
kono
parents:
diff changeset
702 case GIMPLE_CALL:
kono
parents:
diff changeset
703 /* ??? This way we can't simplify calls with side-effects. */
kono
parents:
diff changeset
704 if (gimple_call_lhs (stmt) != NULL_TREE
kono
parents:
diff changeset
705 && gimple_call_num_args (stmt) >= 1
kono
parents:
diff changeset
706 && gimple_call_num_args (stmt) <= 3)
kono
parents:
diff changeset
707 {
kono
parents:
diff changeset
708 bool valueized = false;
kono
parents:
diff changeset
709 if (gimple_call_internal_p (stmt))
kono
parents:
diff changeset
710 *rcode = as_combined_fn (gimple_call_internal_fn (stmt));
kono
parents:
diff changeset
711 else
kono
parents:
diff changeset
712 {
kono
parents:
diff changeset
713 tree fn = gimple_call_fn (stmt);
kono
parents:
diff changeset
714 if (!fn)
kono
parents:
diff changeset
715 return false;
kono
parents:
diff changeset
716
kono
parents:
diff changeset
717 fn = do_valueize (fn, top_valueize, valueized);
kono
parents:
diff changeset
718 if (TREE_CODE (fn) != ADDR_EXPR
kono
parents:
diff changeset
719 || TREE_CODE (TREE_OPERAND (fn, 0)) != FUNCTION_DECL)
kono
parents:
diff changeset
720 return false;
kono
parents:
diff changeset
721
kono
parents:
diff changeset
722 tree decl = TREE_OPERAND (fn, 0);
kono
parents:
diff changeset
723 if (DECL_BUILT_IN_CLASS (decl) != BUILT_IN_NORMAL
kono
parents:
diff changeset
724 || !gimple_builtin_call_types_compatible_p (stmt, decl))
kono
parents:
diff changeset
725 return false;
kono
parents:
diff changeset
726
kono
parents:
diff changeset
727 *rcode = as_combined_fn (DECL_FUNCTION_CODE (decl));
kono
parents:
diff changeset
728 }
kono
parents:
diff changeset
729
kono
parents:
diff changeset
730 tree type = TREE_TYPE (gimple_call_lhs (stmt));
kono
parents:
diff changeset
731 for (unsigned i = 0; i < gimple_call_num_args (stmt); ++i)
kono
parents:
diff changeset
732 {
kono
parents:
diff changeset
733 tree arg = gimple_call_arg (stmt, i);
kono
parents:
diff changeset
734 ops[i] = do_valueize (arg, top_valueize, valueized);
kono
parents:
diff changeset
735 }
kono
parents:
diff changeset
736 switch (gimple_call_num_args (stmt))
kono
parents:
diff changeset
737 {
kono
parents:
diff changeset
738 case 1:
kono
parents:
diff changeset
739 return (gimple_resimplify1 (seq, rcode, type, ops, valueize)
kono
parents:
diff changeset
740 || valueized);
kono
parents:
diff changeset
741 case 2:
kono
parents:
diff changeset
742 return (gimple_resimplify2 (seq, rcode, type, ops, valueize)
kono
parents:
diff changeset
743 || valueized);
kono
parents:
diff changeset
744 case 3:
kono
parents:
diff changeset
745 return (gimple_resimplify3 (seq, rcode, type, ops, valueize)
kono
parents:
diff changeset
746 || valueized);
kono
parents:
diff changeset
747 default:
kono
parents:
diff changeset
748 gcc_unreachable ();
kono
parents:
diff changeset
749 }
kono
parents:
diff changeset
750 }
kono
parents:
diff changeset
751 break;
kono
parents:
diff changeset
752
kono
parents:
diff changeset
753 case GIMPLE_COND:
kono
parents:
diff changeset
754 {
kono
parents:
diff changeset
755 tree lhs = gimple_cond_lhs (stmt);
kono
parents:
diff changeset
756 tree rhs = gimple_cond_rhs (stmt);
kono
parents:
diff changeset
757 bool valueized = false;
kono
parents:
diff changeset
758 lhs = do_valueize (lhs, top_valueize, valueized);
kono
parents:
diff changeset
759 rhs = do_valueize (rhs, top_valueize, valueized);
kono
parents:
diff changeset
760 *rcode = gimple_cond_code (stmt);
kono
parents:
diff changeset
761 ops[0] = lhs;
kono
parents:
diff changeset
762 ops[1] = rhs;
kono
parents:
diff changeset
763 return (gimple_resimplify2 (seq, rcode,
kono
parents:
diff changeset
764 boolean_type_node, ops, valueize)
kono
parents:
diff changeset
765 || valueized);
kono
parents:
diff changeset
766 }
kono
parents:
diff changeset
767
kono
parents:
diff changeset
768 default:
kono
parents:
diff changeset
769 break;
kono
parents:
diff changeset
770 }
kono
parents:
diff changeset
771
kono
parents:
diff changeset
772 return false;
kono
parents:
diff changeset
773 }
kono
parents:
diff changeset
774
kono
parents:
diff changeset
775
kono
parents:
diff changeset
776 /* Helper for the autogenerated code, valueize OP. */
kono
parents:
diff changeset
777
kono
parents:
diff changeset
778 inline tree
kono
parents:
diff changeset
779 do_valueize (tree (*valueize)(tree), tree op)
kono
parents:
diff changeset
780 {
kono
parents:
diff changeset
781 if (valueize && TREE_CODE (op) == SSA_NAME)
kono
parents:
diff changeset
782 {
kono
parents:
diff changeset
783 tree tem = valueize (op);
kono
parents:
diff changeset
784 if (tem)
kono
parents:
diff changeset
785 return tem;
kono
parents:
diff changeset
786 }
kono
parents:
diff changeset
787 return op;
kono
parents:
diff changeset
788 }
kono
parents:
diff changeset
789
kono
parents:
diff changeset
790 /* Helper for the autogenerated code, get at the definition of NAME when
kono
parents:
diff changeset
791 VALUEIZE allows that. */
kono
parents:
diff changeset
792
kono
parents:
diff changeset
793 inline gimple *
kono
parents:
diff changeset
794 get_def (tree (*valueize)(tree), tree name)
kono
parents:
diff changeset
795 {
kono
parents:
diff changeset
796 if (valueize && ! valueize (name))
kono
parents:
diff changeset
797 return NULL;
kono
parents:
diff changeset
798 return SSA_NAME_DEF_STMT (name);
kono
parents:
diff changeset
799 }
kono
parents:
diff changeset
800
kono
parents:
diff changeset
801 /* Routine to determine if the types T1 and T2 are effectively
kono
parents:
diff changeset
802 the same for GIMPLE. If T1 or T2 is not a type, the test
kono
parents:
diff changeset
803 applies to their TREE_TYPE. */
kono
parents:
diff changeset
804
kono
parents:
diff changeset
805 static inline bool
kono
parents:
diff changeset
806 types_match (tree t1, tree t2)
kono
parents:
diff changeset
807 {
kono
parents:
diff changeset
808 if (!TYPE_P (t1))
kono
parents:
diff changeset
809 t1 = TREE_TYPE (t1);
kono
parents:
diff changeset
810 if (!TYPE_P (t2))
kono
parents:
diff changeset
811 t2 = TREE_TYPE (t2);
kono
parents:
diff changeset
812
kono
parents:
diff changeset
813 return types_compatible_p (t1, t2);
kono
parents:
diff changeset
814 }
kono
parents:
diff changeset
815
kono
parents:
diff changeset
816 /* Return if T has a single use. For GIMPLE, we also allow any
kono
parents:
diff changeset
817 non-SSA_NAME (ie constants) and zero uses to cope with uses
kono
parents:
diff changeset
818 that aren't linked up yet. */
kono
parents:
diff changeset
819
kono
parents:
diff changeset
820 static inline bool
kono
parents:
diff changeset
821 single_use (tree t)
kono
parents:
diff changeset
822 {
kono
parents:
diff changeset
823 return TREE_CODE (t) != SSA_NAME || has_zero_uses (t) || has_single_use (t);
kono
parents:
diff changeset
824 }
kono
parents:
diff changeset
825
kono
parents:
diff changeset
826 /* Return true if math operations should be canonicalized,
kono
parents:
diff changeset
827 e.g. sqrt(sqrt(x)) -> pow(x, 0.25). */
kono
parents:
diff changeset
828
kono
parents:
diff changeset
829 static inline bool
kono
parents:
diff changeset
830 canonicalize_math_p ()
kono
parents:
diff changeset
831 {
kono
parents:
diff changeset
832 return !cfun || (cfun->curr_properties & PROP_gimple_opt_math) == 0;
kono
parents:
diff changeset
833 }