* g++.dg/cpp/ucn-1.C: Fix typo.
[official-gcc.git] / gcc / gimple-match-head.c
blob030cc749ad9d82c4985f4b158384e45da5f133dc
1 /* Preamble and helpers for the autogenerated gimple-match.c file.
2 Copyright (C) 2014-2015 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #include "config.h"
21 #include "system.h"
22 #include "coretypes.h"
23 #include "backend.h"
24 #include "target.h"
25 #include "rtl.h"
26 #include "tree.h"
27 #include "gimple.h"
28 #include "ssa.h"
29 #include "cgraph.h"
30 #include "fold-const.h"
31 #include "stor-layout.h"
32 #include "gimple-fold.h"
33 #include "calls.h"
34 #include "tree-dfa.h"
35 #include "builtins.h"
36 #include "gimple-match.h"
37 #include "tree-pass.h"
40 /* Forward declarations of the private auto-generated matchers.
41 They expect valueized operands in canonical order and do not
42 perform simplification of all-constant operands. */
43 static bool gimple_simplify (code_helper *, tree *,
44 gimple_seq *, tree (*)(tree),
45 code_helper, tree, tree);
46 static bool gimple_simplify (code_helper *, tree *,
47 gimple_seq *, tree (*)(tree),
48 code_helper, tree, tree, tree);
49 static bool gimple_simplify (code_helper *, tree *,
50 gimple_seq *, tree (*)(tree),
51 code_helper, tree, tree, tree, tree);
54 /* Return whether T is a constant that we'll dispatch to fold to
55 evaluate fully constant expressions. */
57 static inline bool
58 constant_for_folding (tree t)
60 return (CONSTANT_CLASS_P (t)
61 /* The following is only interesting to string builtins. */
62 || (TREE_CODE (t) == ADDR_EXPR
63 && TREE_CODE (TREE_OPERAND (t, 0)) == STRING_CST));
67 /* Helper that matches and simplifies the toplevel result from
68 a gimple_simplify run (where we don't want to build
69 a stmt in case it's used in in-place folding). Replaces
70 *RES_CODE and *RES_OPS with a simplified and/or canonicalized
71 result and returns whether any change was made. */
73 bool
74 gimple_resimplify1 (gimple_seq *seq,
75 code_helper *res_code, tree type, tree *res_ops,
76 tree (*valueize)(tree))
78 if (constant_for_folding (res_ops[0]))
80 tree tem = NULL_TREE;
81 if (res_code->is_tree_code ())
82 tem = const_unop (*res_code, type, res_ops[0]);
83 else
85 tree decl = builtin_decl_implicit (*res_code);
86 if (decl)
88 tem = fold_builtin_n (UNKNOWN_LOCATION, decl, res_ops, 1, false);
89 if (tem)
91 /* fold_builtin_n wraps the result inside a NOP_EXPR. */
92 STRIP_NOPS (tem);
93 tem = fold_convert (type, tem);
97 if (tem != NULL_TREE
98 && CONSTANT_CLASS_P (tem))
100 res_ops[0] = tem;
101 res_ops[1] = NULL_TREE;
102 res_ops[2] = NULL_TREE;
103 *res_code = TREE_CODE (res_ops[0]);
104 return true;
108 code_helper res_code2;
109 tree res_ops2[3] = {};
110 if (gimple_simplify (&res_code2, res_ops2, seq, valueize,
111 *res_code, type, res_ops[0]))
113 *res_code = res_code2;
114 res_ops[0] = res_ops2[0];
115 res_ops[1] = res_ops2[1];
116 res_ops[2] = res_ops2[2];
117 return true;
120 return false;
123 /* Helper that matches and simplifies the toplevel result from
124 a gimple_simplify run (where we don't want to build
125 a stmt in case it's used in in-place folding). Replaces
126 *RES_CODE and *RES_OPS with a simplified and/or canonicalized
127 result and returns whether any change was made. */
129 bool
130 gimple_resimplify2 (gimple_seq *seq,
131 code_helper *res_code, tree type, tree *res_ops,
132 tree (*valueize)(tree))
134 if (constant_for_folding (res_ops[0]) && constant_for_folding (res_ops[1]))
136 tree tem = NULL_TREE;
137 if (res_code->is_tree_code ())
138 tem = const_binop (*res_code, type, res_ops[0], res_ops[1]);
139 else
141 tree decl = builtin_decl_implicit (*res_code);
142 if (decl)
144 tem = fold_builtin_n (UNKNOWN_LOCATION, decl, res_ops, 2, false);
145 if (tem)
147 /* fold_builtin_n wraps the result inside a NOP_EXPR. */
148 STRIP_NOPS (tem);
149 tem = fold_convert (type, tem);
153 if (tem != NULL_TREE
154 && CONSTANT_CLASS_P (tem))
156 res_ops[0] = tem;
157 res_ops[1] = NULL_TREE;
158 res_ops[2] = NULL_TREE;
159 *res_code = TREE_CODE (res_ops[0]);
160 return true;
164 /* Canonicalize operand order. */
165 bool canonicalized = false;
166 if (res_code->is_tree_code ()
167 && (TREE_CODE_CLASS ((enum tree_code) *res_code) == tcc_comparison
168 || commutative_tree_code (*res_code))
169 && tree_swap_operands_p (res_ops[0], res_ops[1], false))
171 std::swap (res_ops[0], res_ops[1]);
172 if (TREE_CODE_CLASS ((enum tree_code) *res_code) == tcc_comparison)
173 *res_code = swap_tree_comparison (*res_code);
174 canonicalized = true;
177 code_helper res_code2;
178 tree res_ops2[3] = {};
179 if (gimple_simplify (&res_code2, res_ops2, seq, valueize,
180 *res_code, type, res_ops[0], res_ops[1]))
182 *res_code = res_code2;
183 res_ops[0] = res_ops2[0];
184 res_ops[1] = res_ops2[1];
185 res_ops[2] = res_ops2[2];
186 return true;
189 return canonicalized;
192 /* Helper that matches and simplifies the toplevel result from
193 a gimple_simplify run (where we don't want to build
194 a stmt in case it's used in in-place folding). Replaces
195 *RES_CODE and *RES_OPS with a simplified and/or canonicalized
196 result and returns whether any change was made. */
198 bool
199 gimple_resimplify3 (gimple_seq *seq,
200 code_helper *res_code, tree type, tree *res_ops,
201 tree (*valueize)(tree))
203 if (constant_for_folding (res_ops[0]) && constant_for_folding (res_ops[1])
204 && constant_for_folding (res_ops[2]))
206 tree tem = NULL_TREE;
207 if (res_code->is_tree_code ())
208 tem = fold_ternary/*_to_constant*/ (*res_code, type, res_ops[0],
209 res_ops[1], res_ops[2]);
210 else
212 tree decl = builtin_decl_implicit (*res_code);
213 if (decl)
215 tem = fold_builtin_n (UNKNOWN_LOCATION, decl, res_ops, 3, false);
216 if (tem)
218 /* fold_builtin_n wraps the result inside a NOP_EXPR. */
219 STRIP_NOPS (tem);
220 tem = fold_convert (type, tem);
224 if (tem != NULL_TREE
225 && CONSTANT_CLASS_P (tem))
227 res_ops[0] = tem;
228 res_ops[1] = NULL_TREE;
229 res_ops[2] = NULL_TREE;
230 *res_code = TREE_CODE (res_ops[0]);
231 return true;
235 /* Canonicalize operand order. */
236 bool canonicalized = false;
237 if (res_code->is_tree_code ()
238 && commutative_ternary_tree_code (*res_code)
239 && tree_swap_operands_p (res_ops[0], res_ops[1], false))
241 std::swap (res_ops[0], res_ops[1]);
242 canonicalized = true;
245 code_helper res_code2;
246 tree res_ops2[3] = {};
247 if (gimple_simplify (&res_code2, res_ops2, seq, valueize,
248 *res_code, type,
249 res_ops[0], res_ops[1], res_ops[2]))
251 *res_code = res_code2;
252 res_ops[0] = res_ops2[0];
253 res_ops[1] = res_ops2[1];
254 res_ops[2] = res_ops2[2];
255 return true;
258 return canonicalized;
262 /* If in GIMPLE expressions with CODE go as single-rhs build
263 a GENERIC tree for that expression into *OP0. */
265 void
266 maybe_build_generic_op (enum tree_code code, tree type,
267 tree *op0, tree op1, tree op2)
269 switch (code)
271 case REALPART_EXPR:
272 case IMAGPART_EXPR:
273 case VIEW_CONVERT_EXPR:
274 *op0 = build1 (code, type, *op0);
275 break;
276 case BIT_FIELD_REF:
277 *op0 = build3 (code, type, *op0, op1, op2);
278 break;
279 default:;
283 tree (*mprts_hook) (code_helper, tree, tree *);
285 /* Push the exploded expression described by RCODE, TYPE and OPS
286 as a statement to SEQ if necessary and return a gimple value
287 denoting the value of the expression. If RES is not NULL
288 then the result will be always RES and even gimple values are
289 pushed to SEQ. */
291 tree
292 maybe_push_res_to_seq (code_helper rcode, tree type, tree *ops,
293 gimple_seq *seq, tree res)
295 if (rcode.is_tree_code ())
297 if (!res
298 && gimple_simplified_result_is_gimple_val (rcode, ops))
299 return ops[0];
300 if (mprts_hook)
302 tree tem = mprts_hook (rcode, type, ops);
303 if (tem)
304 return tem;
306 if (!seq)
307 return NULL_TREE;
308 /* Play safe and do not allow abnormals to be mentioned in
309 newly created statements. */
310 if ((TREE_CODE (ops[0]) == SSA_NAME
311 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops[0]))
312 || (ops[1]
313 && TREE_CODE (ops[1]) == SSA_NAME
314 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops[1]))
315 || (ops[2]
316 && TREE_CODE (ops[2]) == SSA_NAME
317 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops[2])))
318 return NULL_TREE;
319 if (!res)
321 if (gimple_in_ssa_p (cfun))
322 res = make_ssa_name (type);
323 else
324 res = create_tmp_reg (type);
326 maybe_build_generic_op (rcode, type, &ops[0], ops[1], ops[2]);
327 gimple *new_stmt = gimple_build_assign (res, rcode,
328 ops[0], ops[1], ops[2]);
329 gimple_seq_add_stmt_without_update (seq, new_stmt);
330 return res;
332 else
334 if (!seq)
335 return NULL_TREE;
336 tree decl = builtin_decl_implicit (rcode);
337 if (!decl)
338 return NULL_TREE;
339 /* We can't and should not emit calls to non-const functions. */
340 if (!(flags_from_decl_or_type (decl) & ECF_CONST))
341 return NULL_TREE;
342 /* Play safe and do not allow abnormals to be mentioned in
343 newly created statements. */
344 unsigned nargs;
345 for (nargs = 0; nargs < 3; ++nargs)
347 if (!ops[nargs])
348 break;
349 if (TREE_CODE (ops[nargs]) == SSA_NAME
350 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops[nargs]))
351 return NULL_TREE;
353 gcc_assert (nargs != 0);
354 if (!res)
356 if (gimple_in_ssa_p (cfun))
357 res = make_ssa_name (type);
358 else
359 res = create_tmp_reg (type);
361 gimple *new_stmt = gimple_build_call (decl, nargs, ops[0], ops[1], ops[2]);
362 gimple_call_set_lhs (new_stmt, res);
363 gimple_seq_add_stmt_without_update (seq, new_stmt);
364 return res;
369 /* Public API overloads follow for operation being tree_code or
370 built_in_function and for one to three operands or arguments.
371 They return NULL_TREE if nothing could be simplified or
372 the resulting simplified value with parts pushed to SEQ.
373 If SEQ is NULL then if the simplification needs to create
374 new stmts it will fail. If VALUEIZE is non-NULL then all
375 SSA names will be valueized using that hook prior to
376 applying simplifications. */
378 /* Unary ops. */
380 tree
381 gimple_simplify (enum tree_code code, tree type,
382 tree op0,
383 gimple_seq *seq, tree (*valueize)(tree))
385 if (constant_for_folding (op0))
387 tree res = const_unop (code, type, op0);
388 if (res != NULL_TREE
389 && CONSTANT_CLASS_P (res))
390 return res;
393 code_helper rcode;
394 tree ops[3] = {};
395 if (!gimple_simplify (&rcode, ops, seq, valueize,
396 code, type, op0))
397 return NULL_TREE;
398 return maybe_push_res_to_seq (rcode, type, ops, seq);
401 /* Binary ops. */
403 tree
404 gimple_simplify (enum tree_code code, tree type,
405 tree op0, tree op1,
406 gimple_seq *seq, tree (*valueize)(tree))
408 if (constant_for_folding (op0) && constant_for_folding (op1))
410 tree res = const_binop (code, type, op0, op1);
411 if (res != NULL_TREE
412 && CONSTANT_CLASS_P (res))
413 return res;
416 /* Canonicalize operand order both for matching and fallback stmt
417 generation. */
418 if ((commutative_tree_code (code)
419 || TREE_CODE_CLASS (code) == tcc_comparison)
420 && tree_swap_operands_p (op0, op1, false))
422 std::swap (op0, op1);
423 if (TREE_CODE_CLASS (code) == tcc_comparison)
424 code = swap_tree_comparison (code);
427 code_helper rcode;
428 tree ops[3] = {};
429 if (!gimple_simplify (&rcode, ops, seq, valueize,
430 code, type, op0, op1))
431 return NULL_TREE;
432 return maybe_push_res_to_seq (rcode, type, ops, seq);
435 /* Ternary ops. */
437 tree
438 gimple_simplify (enum tree_code code, tree type,
439 tree op0, tree op1, tree op2,
440 gimple_seq *seq, tree (*valueize)(tree))
442 if (constant_for_folding (op0) && constant_for_folding (op1)
443 && constant_for_folding (op2))
445 tree res = fold_ternary/*_to_constant */ (code, type, op0, op1, op2);
446 if (res != NULL_TREE
447 && CONSTANT_CLASS_P (res))
448 return res;
451 /* Canonicalize operand order both for matching and fallback stmt
452 generation. */
453 if (commutative_ternary_tree_code (code)
454 && tree_swap_operands_p (op0, op1, false))
455 std::swap (op0, op1);
457 code_helper rcode;
458 tree ops[3] = {};
459 if (!gimple_simplify (&rcode, ops, seq, valueize,
460 code, type, op0, op1, op2))
461 return NULL_TREE;
462 return maybe_push_res_to_seq (rcode, type, ops, seq);
465 /* Builtin function with one argument. */
467 tree
468 gimple_simplify (enum built_in_function fn, tree type,
469 tree arg0,
470 gimple_seq *seq, tree (*valueize)(tree))
472 if (constant_for_folding (arg0))
474 tree decl = builtin_decl_implicit (fn);
475 if (decl)
477 tree res = fold_builtin_n (UNKNOWN_LOCATION, decl, &arg0, 1, false);
478 if (res)
480 /* fold_builtin_n wraps the result inside a NOP_EXPR. */
481 STRIP_NOPS (res);
482 res = fold_convert (type, res);
483 if (CONSTANT_CLASS_P (res))
484 return res;
489 code_helper rcode;
490 tree ops[3] = {};
491 if (!gimple_simplify (&rcode, ops, seq, valueize,
492 fn, type, arg0))
493 return NULL_TREE;
494 return maybe_push_res_to_seq (rcode, type, ops, seq);
497 /* Builtin function with two arguments. */
499 tree
500 gimple_simplify (enum built_in_function fn, tree type,
501 tree arg0, tree arg1,
502 gimple_seq *seq, tree (*valueize)(tree))
504 if (constant_for_folding (arg0)
505 && constant_for_folding (arg1))
507 tree decl = builtin_decl_implicit (fn);
508 if (decl)
510 tree args[2];
511 args[0] = arg0;
512 args[1] = arg1;
513 tree res = fold_builtin_n (UNKNOWN_LOCATION, decl, args, 2, false);
514 if (res)
516 /* fold_builtin_n wraps the result inside a NOP_EXPR. */
517 STRIP_NOPS (res);
518 res = fold_convert (type, res);
519 if (CONSTANT_CLASS_P (res))
520 return res;
525 code_helper rcode;
526 tree ops[3] = {};
527 if (!gimple_simplify (&rcode, ops, seq, valueize,
528 fn, type, arg0, arg1))
529 return NULL_TREE;
530 return maybe_push_res_to_seq (rcode, type, ops, seq);
533 /* Builtin function with three arguments. */
535 tree
536 gimple_simplify (enum built_in_function fn, tree type,
537 tree arg0, tree arg1, tree arg2,
538 gimple_seq *seq, tree (*valueize)(tree))
540 if (constant_for_folding (arg0)
541 && constant_for_folding (arg1)
542 && constant_for_folding (arg2))
544 tree decl = builtin_decl_implicit (fn);
545 if (decl)
547 tree args[3];
548 args[0] = arg0;
549 args[1] = arg1;
550 args[2] = arg2;
551 tree res = fold_builtin_n (UNKNOWN_LOCATION, decl, args, 3, false);
552 if (res)
554 /* fold_builtin_n wraps the result inside a NOP_EXPR. */
555 STRIP_NOPS (res);
556 res = fold_convert (type, res);
557 if (CONSTANT_CLASS_P (res))
558 return res;
563 code_helper rcode;
564 tree ops[3] = {};
565 if (!gimple_simplify (&rcode, ops, seq, valueize,
566 fn, type, arg0, arg1, arg2))
567 return NULL_TREE;
568 return maybe_push_res_to_seq (rcode, type, ops, seq);
571 /* Helper for gimple_simplify valueizing OP using VALUEIZE and setting
572 VALUEIZED to true if valueization changed OP. */
574 static inline tree
575 do_valueize (tree op, tree (*valueize)(tree), bool &valueized)
577 if (valueize && TREE_CODE (op) == SSA_NAME)
579 tree tem = valueize (op);
580 if (tem && tem != op)
582 op = tem;
583 valueized = true;
586 return op;
589 /* The main STMT based simplification entry. It is used by the fold_stmt
590 and the fold_stmt_to_constant APIs. */
592 bool
593 gimple_simplify (gimple *stmt,
594 code_helper *rcode, tree *ops,
595 gimple_seq *seq,
596 tree (*valueize)(tree), tree (*top_valueize)(tree))
598 switch (gimple_code (stmt))
600 case GIMPLE_ASSIGN:
602 enum tree_code code = gimple_assign_rhs_code (stmt);
603 tree type = TREE_TYPE (gimple_assign_lhs (stmt));
604 switch (gimple_assign_rhs_class (stmt))
606 case GIMPLE_SINGLE_RHS:
607 if (code == REALPART_EXPR
608 || code == IMAGPART_EXPR
609 || code == VIEW_CONVERT_EXPR)
611 tree op0 = TREE_OPERAND (gimple_assign_rhs1 (stmt), 0);
612 bool valueized = false;
613 op0 = do_valueize (op0, top_valueize, valueized);
614 *rcode = code;
615 ops[0] = op0;
616 return (gimple_resimplify1 (seq, rcode, type, ops, valueize)
617 || valueized);
619 else if (code == BIT_FIELD_REF)
621 tree rhs1 = gimple_assign_rhs1 (stmt);
622 tree op0 = TREE_OPERAND (rhs1, 0);
623 bool valueized = false;
624 op0 = do_valueize (op0, top_valueize, valueized);
625 *rcode = code;
626 ops[0] = op0;
627 ops[1] = TREE_OPERAND (rhs1, 1);
628 ops[2] = TREE_OPERAND (rhs1, 2);
629 return (gimple_resimplify3 (seq, rcode, type, ops, valueize)
630 || valueized);
632 else if (code == SSA_NAME
633 && top_valueize)
635 tree op0 = gimple_assign_rhs1 (stmt);
636 tree valueized = top_valueize (op0);
637 if (!valueized || op0 == valueized)
638 return false;
639 ops[0] = valueized;
640 *rcode = TREE_CODE (op0);
641 return true;
643 break;
644 case GIMPLE_UNARY_RHS:
646 tree rhs1 = gimple_assign_rhs1 (stmt);
647 bool valueized = false;
648 rhs1 = do_valueize (rhs1, top_valueize, valueized);
649 *rcode = code;
650 ops[0] = rhs1;
651 return (gimple_resimplify1 (seq, rcode, type, ops, valueize)
652 || valueized);
654 case GIMPLE_BINARY_RHS:
656 tree rhs1 = gimple_assign_rhs1 (stmt);
657 tree rhs2 = gimple_assign_rhs2 (stmt);
658 bool valueized = false;
659 rhs1 = do_valueize (rhs1, top_valueize, valueized);
660 rhs2 = do_valueize (rhs2, top_valueize, valueized);
661 *rcode = code;
662 ops[0] = rhs1;
663 ops[1] = rhs2;
664 return (gimple_resimplify2 (seq, rcode, type, ops, valueize)
665 || valueized);
667 case GIMPLE_TERNARY_RHS:
669 bool valueized = false;
670 tree rhs1 = gimple_assign_rhs1 (stmt);
671 /* If this is a [VEC_]COND_EXPR first try to simplify an
672 embedded GENERIC condition. */
673 if (code == COND_EXPR
674 || code == VEC_COND_EXPR)
676 if (COMPARISON_CLASS_P (rhs1))
678 tree lhs = TREE_OPERAND (rhs1, 0);
679 tree rhs = TREE_OPERAND (rhs1, 1);
680 lhs = do_valueize (lhs, top_valueize, valueized);
681 rhs = do_valueize (rhs, top_valueize, valueized);
682 code_helper rcode2 = TREE_CODE (rhs1);
683 tree ops2[3] = {};
684 ops2[0] = lhs;
685 ops2[1] = rhs;
686 if ((gimple_resimplify2 (seq, &rcode2, TREE_TYPE (rhs1),
687 ops2, valueize)
688 || valueized)
689 && rcode2.is_tree_code ())
691 valueized = true;
692 if (TREE_CODE_CLASS ((enum tree_code)rcode2)
693 == tcc_comparison)
694 rhs1 = build2 (rcode2, TREE_TYPE (rhs1),
695 ops2[0], ops2[1]);
696 else if (rcode2 == SSA_NAME
697 || rcode2 == INTEGER_CST
698 || rcode2 == VECTOR_CST)
699 rhs1 = ops2[0];
700 else
701 valueized = false;
705 tree rhs2 = gimple_assign_rhs2 (stmt);
706 tree rhs3 = gimple_assign_rhs3 (stmt);
707 rhs1 = do_valueize (rhs1, top_valueize, valueized);
708 rhs2 = do_valueize (rhs2, top_valueize, valueized);
709 rhs3 = do_valueize (rhs3, top_valueize, valueized);
710 *rcode = code;
711 ops[0] = rhs1;
712 ops[1] = rhs2;
713 ops[2] = rhs3;
714 return (gimple_resimplify3 (seq, rcode, type, ops, valueize)
715 || valueized);
717 default:
718 gcc_unreachable ();
720 break;
723 case GIMPLE_CALL:
724 /* ??? This way we can't simplify calls with side-effects. */
725 if (gimple_call_lhs (stmt) != NULL_TREE
726 && gimple_call_num_args (stmt) >= 1
727 && gimple_call_num_args (stmt) <= 3)
729 tree fn = gimple_call_fn (stmt);
730 /* ??? Internal function support missing. */
731 if (!fn)
732 return false;
733 bool valueized = false;
734 fn = do_valueize (fn, top_valueize, valueized);
735 if (TREE_CODE (fn) != ADDR_EXPR
736 || TREE_CODE (TREE_OPERAND (fn, 0)) != FUNCTION_DECL)
737 return false;
739 tree decl = TREE_OPERAND (fn, 0);
740 if (DECL_BUILT_IN_CLASS (decl) != BUILT_IN_NORMAL
741 || !gimple_builtin_call_types_compatible_p (stmt, decl))
742 return false;
744 tree type = TREE_TYPE (gimple_call_lhs (stmt));
745 *rcode = DECL_FUNCTION_CODE (decl);
746 for (unsigned i = 0; i < gimple_call_num_args (stmt); ++i)
748 tree arg = gimple_call_arg (stmt, i);
749 ops[i] = do_valueize (arg, top_valueize, valueized);
751 switch (gimple_call_num_args (stmt))
753 case 1:
754 return (gimple_resimplify1 (seq, rcode, type, ops, valueize)
755 || valueized);
756 case 2:
757 return (gimple_resimplify2 (seq, rcode, type, ops, valueize)
758 || valueized);
759 case 3:
760 return (gimple_resimplify3 (seq, rcode, type, ops, valueize)
761 || valueized);
762 default:
763 gcc_unreachable ();
766 break;
768 case GIMPLE_COND:
770 tree lhs = gimple_cond_lhs (stmt);
771 tree rhs = gimple_cond_rhs (stmt);
772 bool valueized = false;
773 lhs = do_valueize (lhs, top_valueize, valueized);
774 rhs = do_valueize (rhs, top_valueize, valueized);
775 *rcode = gimple_cond_code (stmt);
776 ops[0] = lhs;
777 ops[1] = rhs;
778 return (gimple_resimplify2 (seq, rcode,
779 boolean_type_node, ops, valueize)
780 || valueized);
783 default:
784 break;
787 return false;
791 /* Helper for the autogenerated code, valueize OP. */
793 inline tree
794 do_valueize (tree (*valueize)(tree), tree op)
796 if (valueize && TREE_CODE (op) == SSA_NAME)
797 return valueize (op);
798 return op;
801 /* Routine to determine if the types T1 and T2 are effectively
802 the same for GIMPLE. If T1 or T2 is not a type, the test
803 applies to their TREE_TYPE. */
805 static inline bool
806 types_match (tree t1, tree t2)
808 if (!TYPE_P (t1))
809 t1 = TREE_TYPE (t1);
810 if (!TYPE_P (t2))
811 t2 = TREE_TYPE (t2);
813 return types_compatible_p (t1, t2);
816 /* Return if T has a single use. For GIMPLE, we also allow any
817 non-SSA_NAME (ie constants) and zero uses to cope with uses
818 that aren't linked up yet. */
820 static inline bool
821 single_use (tree t)
823 return TREE_CODE (t) != SSA_NAME || has_zero_uses (t) || has_single_use (t);
826 /* Return true if math operations should be canonicalized,
827 e.g. sqrt(sqrt(x)) -> pow(x, 0.25). */
829 static inline bool
830 canonicalize_math_p ()
832 return !cfun || (cfun->curr_properties & PROP_gimple_opt_math) == 0;