2015-05-05 Yvan Roux <yvan.roux@linaro.org>
[official-gcc.git] / gcc / gimple-match-head.c
blobc7b2f957baca4bd05c25988938d126d817404fbe
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 "tm.h"
24 #include "hash-set.h"
25 #include "machmode.h"
26 #include "vec.h"
27 #include "double-int.h"
28 #include "input.h"
29 #include "alias.h"
30 #include "symtab.h"
31 #include "options.h"
32 #include "wide-int.h"
33 #include "inchash.h"
34 #include "tree.h"
35 #include "fold-const.h"
36 #include "stringpool.h"
37 #include "stor-layout.h"
38 #include "flags.h"
39 #include "hard-reg-set.h"
40 #include "function.h"
41 #include "predict.h"
42 #include "basic-block.h"
43 #include "tree-ssa-alias.h"
44 #include "internal-fn.h"
45 #include "gimple-expr.h"
46 #include "is-a.h"
47 #include "gimple.h"
48 #include "gimple-ssa.h"
49 #include "tree-ssanames.h"
50 #include "gimple-fold.h"
51 #include "gimple-iterator.h"
52 #include "hashtab.h"
53 #include "rtl.h"
54 #include "statistics.h"
55 #include "real.h"
56 #include "fixed-value.h"
57 #include "insn-config.h"
58 #include "expmed.h"
59 #include "dojump.h"
60 #include "explow.h"
61 #include "calls.h"
62 #include "emit-rtl.h"
63 #include "varasm.h"
64 #include "stmt.h"
65 #include "expr.h"
66 #include "tree-dfa.h"
67 #include "builtins.h"
68 #include "tree-phinodes.h"
69 #include "ssa-iterators.h"
70 #include "dumpfile.h"
71 #include "gimple-match.h"
74 /* Forward declarations of the private auto-generated matchers.
75 They expect valueized operands in canonical order and do not
76 perform simplification of all-constant operands. */
77 static bool gimple_simplify (code_helper *, tree *,
78 gimple_seq *, tree (*)(tree),
79 code_helper, tree, tree);
80 static bool gimple_simplify (code_helper *, tree *,
81 gimple_seq *, tree (*)(tree),
82 code_helper, tree, tree, tree);
83 static bool gimple_simplify (code_helper *, tree *,
84 gimple_seq *, tree (*)(tree),
85 code_helper, tree, tree, tree, tree);
88 /* Return whether T is a constant that we'll dispatch to fold to
89 evaluate fully constant expressions. */
91 static inline bool
92 constant_for_folding (tree t)
94 return (CONSTANT_CLASS_P (t)
95 /* The following is only interesting to string builtins. */
96 || (TREE_CODE (t) == ADDR_EXPR
97 && TREE_CODE (TREE_OPERAND (t, 0)) == STRING_CST));
101 /* Helper that matches and simplifies the toplevel result from
102 a gimple_simplify run (where we don't want to build
103 a stmt in case it's used in in-place folding). Replaces
104 *RES_CODE and *RES_OPS with a simplified and/or canonicalized
105 result and returns whether any change was made. */
107 static bool
108 gimple_resimplify1 (gimple_seq *seq,
109 code_helper *res_code, tree type, tree *res_ops,
110 tree (*valueize)(tree))
112 if (constant_for_folding (res_ops[0]))
114 tree tem = NULL_TREE;
115 if (res_code->is_tree_code ())
116 tem = const_unop (*res_code, type, res_ops[0]);
117 else
119 tree decl = builtin_decl_implicit (*res_code);
120 if (decl)
122 tem = fold_builtin_n (UNKNOWN_LOCATION, decl, res_ops, 1, false);
123 if (tem)
125 /* fold_builtin_n wraps the result inside a NOP_EXPR. */
126 STRIP_NOPS (tem);
127 tem = fold_convert (type, tem);
131 if (tem != NULL_TREE
132 && CONSTANT_CLASS_P (tem))
134 res_ops[0] = tem;
135 res_ops[1] = NULL_TREE;
136 res_ops[2] = NULL_TREE;
137 *res_code = TREE_CODE (res_ops[0]);
138 return true;
142 code_helper res_code2;
143 tree res_ops2[3] = {};
144 if (gimple_simplify (&res_code2, res_ops2, seq, valueize,
145 *res_code, type, res_ops[0]))
147 *res_code = res_code2;
148 res_ops[0] = res_ops2[0];
149 res_ops[1] = res_ops2[1];
150 res_ops[2] = res_ops2[2];
151 return true;
154 return false;
157 /* Helper that matches and simplifies the toplevel result from
158 a gimple_simplify run (where we don't want to build
159 a stmt in case it's used in in-place folding). Replaces
160 *RES_CODE and *RES_OPS with a simplified and/or canonicalized
161 result and returns whether any change was made. */
163 static bool
164 gimple_resimplify2 (gimple_seq *seq,
165 code_helper *res_code, tree type, tree *res_ops,
166 tree (*valueize)(tree))
168 if (constant_for_folding (res_ops[0]) && constant_for_folding (res_ops[1]))
170 tree tem = NULL_TREE;
171 if (res_code->is_tree_code ())
172 tem = const_binop (*res_code, type, res_ops[0], res_ops[1]);
173 else
175 tree decl = builtin_decl_implicit (*res_code);
176 if (decl)
178 tem = fold_builtin_n (UNKNOWN_LOCATION, decl, res_ops, 2, false);
179 if (tem)
181 /* fold_builtin_n wraps the result inside a NOP_EXPR. */
182 STRIP_NOPS (tem);
183 tem = fold_convert (type, tem);
187 if (tem != NULL_TREE
188 && CONSTANT_CLASS_P (tem))
190 res_ops[0] = tem;
191 res_ops[1] = NULL_TREE;
192 res_ops[2] = NULL_TREE;
193 *res_code = TREE_CODE (res_ops[0]);
194 return true;
198 /* Canonicalize operand order. */
199 bool canonicalized = false;
200 if (res_code->is_tree_code ()
201 && (TREE_CODE_CLASS ((enum tree_code) *res_code) == tcc_comparison
202 || commutative_tree_code (*res_code))
203 && tree_swap_operands_p (res_ops[0], res_ops[1], false))
205 tree tem = res_ops[0];
206 res_ops[0] = res_ops[1];
207 res_ops[1] = tem;
208 if (TREE_CODE_CLASS ((enum tree_code) *res_code) == tcc_comparison)
209 *res_code = swap_tree_comparison (*res_code);
210 canonicalized = true;
213 code_helper res_code2;
214 tree res_ops2[3] = {};
215 if (gimple_simplify (&res_code2, res_ops2, seq, valueize,
216 *res_code, type, res_ops[0], res_ops[1]))
218 *res_code = res_code2;
219 res_ops[0] = res_ops2[0];
220 res_ops[1] = res_ops2[1];
221 res_ops[2] = res_ops2[2];
222 return true;
225 return canonicalized;
228 /* Helper that matches and simplifies the toplevel result from
229 a gimple_simplify run (where we don't want to build
230 a stmt in case it's used in in-place folding). Replaces
231 *RES_CODE and *RES_OPS with a simplified and/or canonicalized
232 result and returns whether any change was made. */
234 static bool
235 gimple_resimplify3 (gimple_seq *seq,
236 code_helper *res_code, tree type, tree *res_ops,
237 tree (*valueize)(tree))
239 if (constant_for_folding (res_ops[0]) && constant_for_folding (res_ops[1])
240 && constant_for_folding (res_ops[2]))
242 tree tem = NULL_TREE;
243 if (res_code->is_tree_code ())
244 tem = fold_ternary/*_to_constant*/ (*res_code, type, res_ops[0],
245 res_ops[1], res_ops[2]);
246 else
248 tree decl = builtin_decl_implicit (*res_code);
249 if (decl)
251 tem = fold_builtin_n (UNKNOWN_LOCATION, decl, res_ops, 3, false);
252 if (tem)
254 /* fold_builtin_n wraps the result inside a NOP_EXPR. */
255 STRIP_NOPS (tem);
256 tem = fold_convert (type, tem);
260 if (tem != NULL_TREE
261 && CONSTANT_CLASS_P (tem))
263 res_ops[0] = tem;
264 res_ops[1] = NULL_TREE;
265 res_ops[2] = NULL_TREE;
266 *res_code = TREE_CODE (res_ops[0]);
267 return true;
271 /* Canonicalize operand order. */
272 bool canonicalized = false;
273 if (res_code->is_tree_code ()
274 && commutative_ternary_tree_code (*res_code)
275 && tree_swap_operands_p (res_ops[0], res_ops[1], false))
277 tree tem = res_ops[0];
278 res_ops[0] = res_ops[1];
279 res_ops[1] = tem;
280 canonicalized = true;
283 code_helper res_code2;
284 tree res_ops2[3] = {};
285 if (gimple_simplify (&res_code2, res_ops2, seq, valueize,
286 *res_code, type,
287 res_ops[0], res_ops[1], res_ops[2]))
289 *res_code = res_code2;
290 res_ops[0] = res_ops2[0];
291 res_ops[1] = res_ops2[1];
292 res_ops[2] = res_ops2[2];
293 return true;
296 return canonicalized;
300 /* If in GIMPLE expressions with CODE go as single-rhs build
301 a GENERIC tree for that expression into *OP0. */
303 void
304 maybe_build_generic_op (enum tree_code code, tree type,
305 tree *op0, tree op1, tree op2)
307 switch (code)
309 case REALPART_EXPR:
310 case IMAGPART_EXPR:
311 case VIEW_CONVERT_EXPR:
312 *op0 = build1 (code, type, *op0);
313 break;
314 case BIT_FIELD_REF:
315 *op0 = build3 (code, type, *op0, op1, op2);
316 break;
317 default:;
321 /* Push the exploded expression described by RCODE, TYPE and OPS
322 as a statement to SEQ if necessary and return a gimple value
323 denoting the value of the expression. If RES is not NULL
324 then the result will be always RES and even gimple values are
325 pushed to SEQ. */
327 tree
328 maybe_push_res_to_seq (code_helper rcode, tree type, tree *ops,
329 gimple_seq *seq, tree res)
331 if (rcode.is_tree_code ())
333 if (!res
334 && (TREE_CODE_LENGTH ((tree_code) rcode) == 0
335 || ((tree_code) rcode) == ADDR_EXPR)
336 && is_gimple_val (ops[0]))
337 return ops[0];
338 if (!seq)
339 return NULL_TREE;
340 /* Play safe and do not allow abnormals to be mentioned in
341 newly created statements. */
342 if ((TREE_CODE (ops[0]) == SSA_NAME
343 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops[0]))
344 || (ops[1]
345 && TREE_CODE (ops[1]) == SSA_NAME
346 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops[1]))
347 || (ops[2]
348 && TREE_CODE (ops[2]) == SSA_NAME
349 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops[2])))
350 return NULL_TREE;
351 if (!res)
352 res = make_ssa_name (type);
353 maybe_build_generic_op (rcode, type, &ops[0], ops[1], ops[2]);
354 gimple new_stmt = gimple_build_assign (res, rcode,
355 ops[0], ops[1], ops[2]);
356 gimple_seq_add_stmt_without_update (seq, new_stmt);
357 return res;
359 else
361 if (!seq)
362 return NULL_TREE;
363 tree decl = builtin_decl_implicit (rcode);
364 if (!decl)
365 return NULL_TREE;
366 unsigned nargs = type_num_arguments (TREE_TYPE (decl));
367 gcc_assert (nargs <= 3);
368 /* Play safe and do not allow abnormals to be mentioned in
369 newly created statements. */
370 if ((TREE_CODE (ops[0]) == SSA_NAME
371 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops[0]))
372 || (nargs >= 2
373 && TREE_CODE (ops[1]) == SSA_NAME
374 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops[1]))
375 || (nargs == 3
376 && TREE_CODE (ops[2]) == SSA_NAME
377 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops[2])))
378 return NULL_TREE;
379 if (!res)
380 res = make_ssa_name (type);
381 gimple new_stmt = gimple_build_call (decl, nargs, ops[0], ops[1], ops[2]);
382 gimple_call_set_lhs (new_stmt, res);
383 gimple_seq_add_stmt_without_update (seq, new_stmt);
384 return res;
389 /* Public API overloads follow for operation being tree_code or
390 built_in_function and for one to three operands or arguments.
391 They return NULL_TREE if nothing could be simplified or
392 the resulting simplified value with parts pushed to SEQ.
393 If SEQ is NULL then if the simplification needs to create
394 new stmts it will fail. If VALUEIZE is non-NULL then all
395 SSA names will be valueized using that hook prior to
396 applying simplifications. */
398 /* Unary ops. */
400 tree
401 gimple_simplify (enum tree_code code, tree type,
402 tree op0,
403 gimple_seq *seq, tree (*valueize)(tree))
405 if (constant_for_folding (op0))
407 tree res = const_unop (code, type, op0);
408 if (res != NULL_TREE
409 && CONSTANT_CLASS_P (res))
410 return res;
413 code_helper rcode;
414 tree ops[3] = {};
415 if (!gimple_simplify (&rcode, ops, seq, valueize,
416 code, type, op0))
417 return NULL_TREE;
418 return maybe_push_res_to_seq (rcode, type, ops, seq);
421 /* Binary ops. */
423 tree
424 gimple_simplify (enum tree_code code, tree type,
425 tree op0, tree op1,
426 gimple_seq *seq, tree (*valueize)(tree))
428 if (constant_for_folding (op0) && constant_for_folding (op1))
430 tree res = const_binop (code, type, op0, op1);
431 if (res != NULL_TREE
432 && CONSTANT_CLASS_P (res))
433 return res;
436 /* Canonicalize operand order both for matching and fallback stmt
437 generation. */
438 if ((commutative_tree_code (code)
439 || TREE_CODE_CLASS (code) == tcc_comparison)
440 && tree_swap_operands_p (op0, op1, false))
442 tree tem = op0;
443 op0 = op1;
444 op1 = tem;
445 if (TREE_CODE_CLASS (code) == tcc_comparison)
446 code = swap_tree_comparison (code);
449 code_helper rcode;
450 tree ops[3] = {};
451 if (!gimple_simplify (&rcode, ops, seq, valueize,
452 code, type, op0, op1))
453 return NULL_TREE;
454 return maybe_push_res_to_seq (rcode, type, ops, seq);
457 /* Ternary ops. */
459 tree
460 gimple_simplify (enum tree_code code, tree type,
461 tree op0, tree op1, tree op2,
462 gimple_seq *seq, tree (*valueize)(tree))
464 if (constant_for_folding (op0) && constant_for_folding (op1)
465 && constant_for_folding (op2))
467 tree res = fold_ternary/*_to_constant */ (code, type, op0, op1, op2);
468 if (res != NULL_TREE
469 && CONSTANT_CLASS_P (res))
470 return res;
473 /* Canonicalize operand order both for matching and fallback stmt
474 generation. */
475 if (commutative_ternary_tree_code (code)
476 && tree_swap_operands_p (op0, op1, false))
478 tree tem = op0;
479 op0 = op1;
480 op1 = tem;
483 code_helper rcode;
484 tree ops[3] = {};
485 if (!gimple_simplify (&rcode, ops, seq, valueize,
486 code, type, op0, op1, op2))
487 return NULL_TREE;
488 return maybe_push_res_to_seq (rcode, type, ops, seq);
491 /* Builtin function with one argument. */
493 tree
494 gimple_simplify (enum built_in_function fn, tree type,
495 tree arg0,
496 gimple_seq *seq, tree (*valueize)(tree))
498 if (constant_for_folding (arg0))
500 tree decl = builtin_decl_implicit (fn);
501 if (decl)
503 tree res = fold_builtin_n (UNKNOWN_LOCATION, decl, &arg0, 1, false);
504 if (res)
506 /* fold_builtin_n wraps the result inside a NOP_EXPR. */
507 STRIP_NOPS (res);
508 res = fold_convert (type, res);
509 if (CONSTANT_CLASS_P (res))
510 return res;
515 code_helper rcode;
516 tree ops[3] = {};
517 if (!gimple_simplify (&rcode, ops, seq, valueize,
518 fn, type, arg0))
519 return NULL_TREE;
520 return maybe_push_res_to_seq (rcode, type, ops, seq);
523 /* Builtin function with two arguments. */
525 tree
526 gimple_simplify (enum built_in_function fn, tree type,
527 tree arg0, tree arg1,
528 gimple_seq *seq, tree (*valueize)(tree))
530 if (constant_for_folding (arg0)
531 && constant_for_folding (arg1))
533 tree decl = builtin_decl_implicit (fn);
534 if (decl)
536 tree args[2];
537 args[0] = arg0;
538 args[1] = arg1;
539 tree res = fold_builtin_n (UNKNOWN_LOCATION, decl, args, 2, false);
540 if (res)
542 /* fold_builtin_n wraps the result inside a NOP_EXPR. */
543 STRIP_NOPS (res);
544 res = fold_convert (type, res);
545 if (CONSTANT_CLASS_P (res))
546 return res;
551 code_helper rcode;
552 tree ops[3] = {};
553 if (!gimple_simplify (&rcode, ops, seq, valueize,
554 fn, type, arg0, arg1))
555 return NULL_TREE;
556 return maybe_push_res_to_seq (rcode, type, ops, seq);
559 /* Builtin function with three arguments. */
561 tree
562 gimple_simplify (enum built_in_function fn, tree type,
563 tree arg0, tree arg1, tree arg2,
564 gimple_seq *seq, tree (*valueize)(tree))
566 if (constant_for_folding (arg0)
567 && constant_for_folding (arg1)
568 && constant_for_folding (arg2))
570 tree decl = builtin_decl_implicit (fn);
571 if (decl)
573 tree args[3];
574 args[0] = arg0;
575 args[1] = arg1;
576 args[2] = arg2;
577 tree res = fold_builtin_n (UNKNOWN_LOCATION, decl, args, 3, false);
578 if (res)
580 /* fold_builtin_n wraps the result inside a NOP_EXPR. */
581 STRIP_NOPS (res);
582 res = fold_convert (type, res);
583 if (CONSTANT_CLASS_P (res))
584 return res;
589 code_helper rcode;
590 tree ops[3] = {};
591 if (!gimple_simplify (&rcode, ops, seq, valueize,
592 fn, type, arg0, arg1, arg2))
593 return NULL_TREE;
594 return maybe_push_res_to_seq (rcode, type, ops, seq);
598 /* The main STMT based simplification entry. It is used by the fold_stmt
599 and the fold_stmt_to_constant APIs. */
601 bool
602 gimple_simplify (gimple stmt,
603 code_helper *rcode, tree *ops,
604 gimple_seq *seq,
605 tree (*valueize)(tree), tree (*top_valueize)(tree))
607 switch (gimple_code (stmt))
609 case GIMPLE_ASSIGN:
611 enum tree_code code = gimple_assign_rhs_code (stmt);
612 tree type = TREE_TYPE (gimple_assign_lhs (stmt));
613 switch (gimple_assign_rhs_class (stmt))
615 case GIMPLE_SINGLE_RHS:
616 if (code == REALPART_EXPR
617 || code == IMAGPART_EXPR
618 || code == VIEW_CONVERT_EXPR)
620 tree op0 = TREE_OPERAND (gimple_assign_rhs1 (stmt), 0);
621 if (top_valueize && TREE_CODE (op0) == SSA_NAME)
623 tree tem = top_valueize (op0);
624 if (tem)
625 op0 = tem;
627 *rcode = code;
628 ops[0] = op0;
629 return gimple_resimplify1 (seq, rcode, type, ops, valueize);
631 else if (code == BIT_FIELD_REF)
633 tree rhs1 = gimple_assign_rhs1 (stmt);
634 tree op0 = TREE_OPERAND (rhs1, 0);
635 if (top_valueize && TREE_CODE (op0) == SSA_NAME)
637 tree tem = top_valueize (op0);
638 if (tem)
639 op0 = tem;
641 *rcode = code;
642 ops[0] = op0;
643 ops[1] = TREE_OPERAND (rhs1, 1);
644 ops[2] = TREE_OPERAND (rhs1, 2);
645 return gimple_resimplify3 (seq, rcode, type, ops, valueize);
647 else if (code == SSA_NAME
648 && top_valueize)
650 tree op0 = gimple_assign_rhs1 (stmt);
651 tree valueized = top_valueize (op0);
652 if (!valueized || op0 == valueized)
653 return false;
654 ops[0] = valueized;
655 *rcode = TREE_CODE (op0);
656 return true;
658 break;
659 case GIMPLE_UNARY_RHS:
661 tree rhs1 = gimple_assign_rhs1 (stmt);
662 if (top_valueize && TREE_CODE (rhs1) == SSA_NAME)
664 tree tem = top_valueize (rhs1);
665 if (tem)
666 rhs1 = tem;
668 *rcode = code;
669 ops[0] = rhs1;
670 return gimple_resimplify1 (seq, rcode, type, ops, valueize);
672 case GIMPLE_BINARY_RHS:
674 tree rhs1 = gimple_assign_rhs1 (stmt);
675 if (top_valueize && TREE_CODE (rhs1) == SSA_NAME)
677 tree tem = top_valueize (rhs1);
678 if (tem)
679 rhs1 = tem;
681 tree rhs2 = gimple_assign_rhs2 (stmt);
682 if (top_valueize && TREE_CODE (rhs2) == SSA_NAME)
684 tree tem = top_valueize (rhs2);
685 if (tem)
686 rhs2 = tem;
688 *rcode = code;
689 ops[0] = rhs1;
690 ops[1] = rhs2;
691 return gimple_resimplify2 (seq, rcode, type, ops, valueize);
693 case GIMPLE_TERNARY_RHS:
695 tree rhs1 = gimple_assign_rhs1 (stmt);
696 if (top_valueize && TREE_CODE (rhs1) == SSA_NAME)
698 tree tem = top_valueize (rhs1);
699 if (tem)
700 rhs1 = tem;
702 tree rhs2 = gimple_assign_rhs2 (stmt);
703 if (top_valueize && TREE_CODE (rhs2) == SSA_NAME)
705 tree tem = top_valueize (rhs2);
706 if (tem)
707 rhs2 = tem;
709 tree rhs3 = gimple_assign_rhs3 (stmt);
710 if (top_valueize && TREE_CODE (rhs3) == SSA_NAME)
712 tree tem = top_valueize (rhs3);
713 if (tem)
714 rhs3 = tem;
716 *rcode = code;
717 ops[0] = rhs1;
718 ops[1] = rhs2;
719 ops[2] = rhs3;
720 return gimple_resimplify3 (seq, rcode, type, ops, valueize);
722 default:
723 gcc_unreachable ();
725 break;
728 case GIMPLE_CALL:
729 /* ??? This way we can't simplify calls with side-effects. */
730 if (gimple_call_lhs (stmt) != NULL_TREE)
732 tree fn = gimple_call_fn (stmt);
733 /* ??? Internal function support missing. */
734 if (!fn)
735 return false;
736 if (top_valueize && TREE_CODE (fn) == SSA_NAME)
738 tree tem = top_valueize (fn);
739 if (tem)
740 fn = tem;
742 if (!fn
743 || TREE_CODE (fn) != ADDR_EXPR
744 || TREE_CODE (TREE_OPERAND (fn, 0)) != FUNCTION_DECL
745 || DECL_BUILT_IN_CLASS (TREE_OPERAND (fn, 0)) != BUILT_IN_NORMAL
746 || !builtin_decl_implicit (DECL_FUNCTION_CODE (TREE_OPERAND (fn, 0)))
747 || !gimple_builtin_call_types_compatible_p (stmt,
748 TREE_OPERAND (fn, 0)))
749 return false;
751 tree decl = TREE_OPERAND (fn, 0);
752 tree type = TREE_TYPE (gimple_call_lhs (stmt));
753 switch (gimple_call_num_args (stmt))
755 case 1:
757 tree arg1 = gimple_call_arg (stmt, 0);
758 if (top_valueize && TREE_CODE (arg1) == SSA_NAME)
760 tree tem = top_valueize (arg1);
761 if (tem)
762 arg1 = tem;
764 *rcode = DECL_FUNCTION_CODE (decl);
765 ops[0] = arg1;
766 return gimple_resimplify1 (seq, rcode, type, ops, valueize);
768 case 2:
770 tree arg1 = gimple_call_arg (stmt, 0);
771 if (top_valueize && TREE_CODE (arg1) == SSA_NAME)
773 tree tem = top_valueize (arg1);
774 if (tem)
775 arg1 = tem;
777 tree arg2 = gimple_call_arg (stmt, 1);
778 if (top_valueize && TREE_CODE (arg2) == SSA_NAME)
780 tree tem = top_valueize (arg2);
781 if (tem)
782 arg2 = tem;
784 *rcode = DECL_FUNCTION_CODE (decl);
785 ops[0] = arg1;
786 ops[1] = arg2;
787 return gimple_resimplify2 (seq, rcode, type, ops, valueize);
789 case 3:
791 tree arg1 = gimple_call_arg (stmt, 0);
792 if (top_valueize && TREE_CODE (arg1) == SSA_NAME)
794 tree tem = top_valueize (arg1);
795 if (tem)
796 arg1 = tem;
798 tree arg2 = gimple_call_arg (stmt, 1);
799 if (top_valueize && TREE_CODE (arg2) == SSA_NAME)
801 tree tem = top_valueize (arg2);
802 if (tem)
803 arg2 = tem;
805 tree arg3 = gimple_call_arg (stmt, 2);
806 if (top_valueize && TREE_CODE (arg3) == SSA_NAME)
808 tree tem = top_valueize (arg3);
809 if (tem)
810 arg3 = tem;
812 *rcode = DECL_FUNCTION_CODE (decl);
813 ops[0] = arg1;
814 ops[1] = arg2;
815 ops[2] = arg3;
816 return gimple_resimplify3 (seq, rcode, type, ops, valueize);
818 default:
819 return false;
822 break;
824 case GIMPLE_COND:
826 tree lhs = gimple_cond_lhs (stmt);
827 if (top_valueize && TREE_CODE (lhs) == SSA_NAME)
829 tree tem = top_valueize (lhs);
830 if (tem)
831 lhs = tem;
833 tree rhs = gimple_cond_rhs (stmt);
834 if (top_valueize && TREE_CODE (rhs) == SSA_NAME)
836 tree tem = top_valueize (rhs);
837 if (tem)
838 rhs = tem;
840 *rcode = gimple_cond_code (stmt);
841 ops[0] = lhs;
842 ops[1] = rhs;
843 return gimple_resimplify2 (seq, rcode, boolean_type_node, ops, valueize);
846 default:
847 break;
850 return false;
854 /* Helper for the autogenerated code, valueize OP. */
856 inline tree
857 do_valueize (tree (*valueize)(tree), tree op)
859 if (valueize && TREE_CODE (op) == SSA_NAME)
860 return valueize (op);
861 return op;