gcc/
[official-gcc.git] / gcc / gimple-match-head.c
blob7b1f1ace8f9f91f7469d11c6870a5add2a6de36b
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 "alias.h"
25 #include "symtab.h"
26 #include "options.h"
27 #include "tree.h"
28 #include "fold-const.h"
29 #include "stringpool.h"
30 #include "stor-layout.h"
31 #include "flags.h"
32 #include "hard-reg-set.h"
33 #include "function.h"
34 #include "predict.h"
35 #include "basic-block.h"
36 #include "tree-ssa-alias.h"
37 #include "internal-fn.h"
38 #include "gimple-expr.h"
39 #include "gimple.h"
40 #include "gimple-ssa.h"
41 #include "tree-ssanames.h"
42 #include "gimple-fold.h"
43 #include "gimple-iterator.h"
44 #include "rtl.h"
45 #include "insn-config.h"
46 #include "expmed.h"
47 #include "dojump.h"
48 #include "explow.h"
49 #include "calls.h"
50 #include "emit-rtl.h"
51 #include "varasm.h"
52 #include "stmt.h"
53 #include "expr.h"
54 #include "tree-dfa.h"
55 #include "builtins.h"
56 #include "tree-phinodes.h"
57 #include "ssa-iterators.h"
58 #include "dumpfile.h"
59 #include "gimple-match.h"
62 /* Forward declarations of the private auto-generated matchers.
63 They expect valueized operands in canonical order and do not
64 perform simplification of all-constant operands. */
65 static bool gimple_simplify (code_helper *, tree *,
66 gimple_seq *, tree (*)(tree),
67 code_helper, tree, tree);
68 static bool gimple_simplify (code_helper *, tree *,
69 gimple_seq *, tree (*)(tree),
70 code_helper, tree, tree, tree);
71 static bool gimple_simplify (code_helper *, tree *,
72 gimple_seq *, tree (*)(tree),
73 code_helper, tree, tree, tree, tree);
76 /* Return whether T is a constant that we'll dispatch to fold to
77 evaluate fully constant expressions. */
79 static inline bool
80 constant_for_folding (tree t)
82 return (CONSTANT_CLASS_P (t)
83 /* The following is only interesting to string builtins. */
84 || (TREE_CODE (t) == ADDR_EXPR
85 && TREE_CODE (TREE_OPERAND (t, 0)) == STRING_CST));
89 /* Helper that matches and simplifies the toplevel result from
90 a gimple_simplify run (where we don't want to build
91 a stmt in case it's used in in-place folding). Replaces
92 *RES_CODE and *RES_OPS with a simplified and/or canonicalized
93 result and returns whether any change was made. */
95 static bool
96 gimple_resimplify1 (gimple_seq *seq,
97 code_helper *res_code, tree type, tree *res_ops,
98 tree (*valueize)(tree))
100 if (constant_for_folding (res_ops[0]))
102 tree tem = NULL_TREE;
103 if (res_code->is_tree_code ())
104 tem = const_unop (*res_code, type, res_ops[0]);
105 else
107 tree decl = builtin_decl_implicit (*res_code);
108 if (decl)
110 tem = fold_builtin_n (UNKNOWN_LOCATION, decl, res_ops, 1, false);
111 if (tem)
113 /* fold_builtin_n wraps the result inside a NOP_EXPR. */
114 STRIP_NOPS (tem);
115 tem = fold_convert (type, tem);
119 if (tem != NULL_TREE
120 && CONSTANT_CLASS_P (tem))
122 res_ops[0] = tem;
123 res_ops[1] = NULL_TREE;
124 res_ops[2] = NULL_TREE;
125 *res_code = TREE_CODE (res_ops[0]);
126 return true;
130 code_helper res_code2;
131 tree res_ops2[3] = {};
132 if (gimple_simplify (&res_code2, res_ops2, seq, valueize,
133 *res_code, type, res_ops[0]))
135 *res_code = res_code2;
136 res_ops[0] = res_ops2[0];
137 res_ops[1] = res_ops2[1];
138 res_ops[2] = res_ops2[2];
139 return true;
142 return false;
145 /* Helper that matches and simplifies the toplevel result from
146 a gimple_simplify run (where we don't want to build
147 a stmt in case it's used in in-place folding). Replaces
148 *RES_CODE and *RES_OPS with a simplified and/or canonicalized
149 result and returns whether any change was made. */
151 static bool
152 gimple_resimplify2 (gimple_seq *seq,
153 code_helper *res_code, tree type, tree *res_ops,
154 tree (*valueize)(tree))
156 if (constant_for_folding (res_ops[0]) && constant_for_folding (res_ops[1]))
158 tree tem = NULL_TREE;
159 if (res_code->is_tree_code ())
160 tem = const_binop (*res_code, type, res_ops[0], res_ops[1]);
161 else
163 tree decl = builtin_decl_implicit (*res_code);
164 if (decl)
166 tem = fold_builtin_n (UNKNOWN_LOCATION, decl, res_ops, 2, false);
167 if (tem)
169 /* fold_builtin_n wraps the result inside a NOP_EXPR. */
170 STRIP_NOPS (tem);
171 tem = fold_convert (type, tem);
175 if (tem != NULL_TREE
176 && CONSTANT_CLASS_P (tem))
178 res_ops[0] = tem;
179 res_ops[1] = NULL_TREE;
180 res_ops[2] = NULL_TREE;
181 *res_code = TREE_CODE (res_ops[0]);
182 return true;
186 /* Canonicalize operand order. */
187 bool canonicalized = false;
188 if (res_code->is_tree_code ()
189 && (TREE_CODE_CLASS ((enum tree_code) *res_code) == tcc_comparison
190 || commutative_tree_code (*res_code))
191 && tree_swap_operands_p (res_ops[0], res_ops[1], false))
193 std::swap (res_ops[0], res_ops[1]);
194 if (TREE_CODE_CLASS ((enum tree_code) *res_code) == tcc_comparison)
195 *res_code = swap_tree_comparison (*res_code);
196 canonicalized = true;
199 code_helper res_code2;
200 tree res_ops2[3] = {};
201 if (gimple_simplify (&res_code2, res_ops2, seq, valueize,
202 *res_code, type, res_ops[0], res_ops[1]))
204 *res_code = res_code2;
205 res_ops[0] = res_ops2[0];
206 res_ops[1] = res_ops2[1];
207 res_ops[2] = res_ops2[2];
208 return true;
211 return canonicalized;
214 /* Helper that matches and simplifies the toplevel result from
215 a gimple_simplify run (where we don't want to build
216 a stmt in case it's used in in-place folding). Replaces
217 *RES_CODE and *RES_OPS with a simplified and/or canonicalized
218 result and returns whether any change was made. */
220 static bool
221 gimple_resimplify3 (gimple_seq *seq,
222 code_helper *res_code, tree type, tree *res_ops,
223 tree (*valueize)(tree))
225 if (constant_for_folding (res_ops[0]) && constant_for_folding (res_ops[1])
226 && constant_for_folding (res_ops[2]))
228 tree tem = NULL_TREE;
229 if (res_code->is_tree_code ())
230 tem = fold_ternary/*_to_constant*/ (*res_code, type, res_ops[0],
231 res_ops[1], res_ops[2]);
232 else
234 tree decl = builtin_decl_implicit (*res_code);
235 if (decl)
237 tem = fold_builtin_n (UNKNOWN_LOCATION, decl, res_ops, 3, false);
238 if (tem)
240 /* fold_builtin_n wraps the result inside a NOP_EXPR. */
241 STRIP_NOPS (tem);
242 tem = fold_convert (type, tem);
246 if (tem != NULL_TREE
247 && CONSTANT_CLASS_P (tem))
249 res_ops[0] = tem;
250 res_ops[1] = NULL_TREE;
251 res_ops[2] = NULL_TREE;
252 *res_code = TREE_CODE (res_ops[0]);
253 return true;
257 /* Canonicalize operand order. */
258 bool canonicalized = false;
259 if (res_code->is_tree_code ()
260 && commutative_ternary_tree_code (*res_code)
261 && tree_swap_operands_p (res_ops[0], res_ops[1], false))
263 std::swap (res_ops[0], res_ops[1]);
264 canonicalized = true;
267 code_helper res_code2;
268 tree res_ops2[3] = {};
269 if (gimple_simplify (&res_code2, res_ops2, seq, valueize,
270 *res_code, type,
271 res_ops[0], res_ops[1], res_ops[2]))
273 *res_code = res_code2;
274 res_ops[0] = res_ops2[0];
275 res_ops[1] = res_ops2[1];
276 res_ops[2] = res_ops2[2];
277 return true;
280 return canonicalized;
284 /* If in GIMPLE expressions with CODE go as single-rhs build
285 a GENERIC tree for that expression into *OP0. */
287 void
288 maybe_build_generic_op (enum tree_code code, tree type,
289 tree *op0, tree op1, tree op2)
291 switch (code)
293 case REALPART_EXPR:
294 case IMAGPART_EXPR:
295 case VIEW_CONVERT_EXPR:
296 *op0 = build1 (code, type, *op0);
297 break;
298 case BIT_FIELD_REF:
299 *op0 = build3 (code, type, *op0, op1, op2);
300 break;
301 default:;
305 /* Push the exploded expression described by RCODE, TYPE and OPS
306 as a statement to SEQ if necessary and return a gimple value
307 denoting the value of the expression. If RES is not NULL
308 then the result will be always RES and even gimple values are
309 pushed to SEQ. */
311 tree
312 maybe_push_res_to_seq (code_helper rcode, tree type, tree *ops,
313 gimple_seq *seq, tree res)
315 if (rcode.is_tree_code ())
317 if (!res
318 && (TREE_CODE_LENGTH ((tree_code) rcode) == 0
319 || ((tree_code) rcode) == ADDR_EXPR)
320 && is_gimple_val (ops[0]))
321 return ops[0];
322 if (!seq)
323 return NULL_TREE;
324 /* Play safe and do not allow abnormals to be mentioned in
325 newly created statements. */
326 if ((TREE_CODE (ops[0]) == SSA_NAME
327 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops[0]))
328 || (ops[1]
329 && TREE_CODE (ops[1]) == SSA_NAME
330 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops[1]))
331 || (ops[2]
332 && TREE_CODE (ops[2]) == SSA_NAME
333 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops[2])))
334 return NULL_TREE;
335 if (!res)
336 res = make_ssa_name (type);
337 maybe_build_generic_op (rcode, type, &ops[0], ops[1], ops[2]);
338 gimple new_stmt = gimple_build_assign (res, rcode,
339 ops[0], ops[1], ops[2]);
340 gimple_seq_add_stmt_without_update (seq, new_stmt);
341 return res;
343 else
345 if (!seq)
346 return NULL_TREE;
347 tree decl = builtin_decl_implicit (rcode);
348 if (!decl)
349 return NULL_TREE;
350 unsigned nargs = type_num_arguments (TREE_TYPE (decl));
351 gcc_assert (nargs <= 3);
352 /* Play safe and do not allow abnormals to be mentioned in
353 newly created statements. */
354 if ((TREE_CODE (ops[0]) == SSA_NAME
355 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops[0]))
356 || (nargs >= 2
357 && TREE_CODE (ops[1]) == SSA_NAME
358 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops[1]))
359 || (nargs == 3
360 && TREE_CODE (ops[2]) == SSA_NAME
361 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops[2])))
362 return NULL_TREE;
363 if (!res)
364 res = make_ssa_name (type);
365 gimple new_stmt = gimple_build_call (decl, nargs, ops[0], ops[1], ops[2]);
366 gimple_call_set_lhs (new_stmt, res);
367 gimple_seq_add_stmt_without_update (seq, new_stmt);
368 return res;
373 /* Public API overloads follow for operation being tree_code or
374 built_in_function and for one to three operands or arguments.
375 They return NULL_TREE if nothing could be simplified or
376 the resulting simplified value with parts pushed to SEQ.
377 If SEQ is NULL then if the simplification needs to create
378 new stmts it will fail. If VALUEIZE is non-NULL then all
379 SSA names will be valueized using that hook prior to
380 applying simplifications. */
382 /* Unary ops. */
384 tree
385 gimple_simplify (enum tree_code code, tree type,
386 tree op0,
387 gimple_seq *seq, tree (*valueize)(tree))
389 if (constant_for_folding (op0))
391 tree res = const_unop (code, type, op0);
392 if (res != NULL_TREE
393 && CONSTANT_CLASS_P (res))
394 return res;
397 code_helper rcode;
398 tree ops[3] = {};
399 if (!gimple_simplify (&rcode, ops, seq, valueize,
400 code, type, op0))
401 return NULL_TREE;
402 return maybe_push_res_to_seq (rcode, type, ops, seq);
405 /* Binary ops. */
407 tree
408 gimple_simplify (enum tree_code code, tree type,
409 tree op0, tree op1,
410 gimple_seq *seq, tree (*valueize)(tree))
412 if (constant_for_folding (op0) && constant_for_folding (op1))
414 tree res = const_binop (code, type, op0, op1);
415 if (res != NULL_TREE
416 && CONSTANT_CLASS_P (res))
417 return res;
420 /* Canonicalize operand order both for matching and fallback stmt
421 generation. */
422 if ((commutative_tree_code (code)
423 || TREE_CODE_CLASS (code) == tcc_comparison)
424 && tree_swap_operands_p (op0, op1, false))
426 std::swap (op0, op1);
427 if (TREE_CODE_CLASS (code) == tcc_comparison)
428 code = swap_tree_comparison (code);
431 code_helper rcode;
432 tree ops[3] = {};
433 if (!gimple_simplify (&rcode, ops, seq, valueize,
434 code, type, op0, op1))
435 return NULL_TREE;
436 return maybe_push_res_to_seq (rcode, type, ops, seq);
439 /* Ternary ops. */
441 tree
442 gimple_simplify (enum tree_code code, tree type,
443 tree op0, tree op1, tree op2,
444 gimple_seq *seq, tree (*valueize)(tree))
446 if (constant_for_folding (op0) && constant_for_folding (op1)
447 && constant_for_folding (op2))
449 tree res = fold_ternary/*_to_constant */ (code, type, op0, op1, op2);
450 if (res != NULL_TREE
451 && CONSTANT_CLASS_P (res))
452 return res;
455 /* Canonicalize operand order both for matching and fallback stmt
456 generation. */
457 if (commutative_ternary_tree_code (code)
458 && tree_swap_operands_p (op0, op1, false))
459 std::swap (op0, op1);
461 code_helper rcode;
462 tree ops[3] = {};
463 if (!gimple_simplify (&rcode, ops, seq, valueize,
464 code, type, op0, op1, op2))
465 return NULL_TREE;
466 return maybe_push_res_to_seq (rcode, type, ops, seq);
469 /* Builtin function with one argument. */
471 tree
472 gimple_simplify (enum built_in_function fn, tree type,
473 tree arg0,
474 gimple_seq *seq, tree (*valueize)(tree))
476 if (constant_for_folding (arg0))
478 tree decl = builtin_decl_implicit (fn);
479 if (decl)
481 tree res = fold_builtin_n (UNKNOWN_LOCATION, decl, &arg0, 1, false);
482 if (res)
484 /* fold_builtin_n wraps the result inside a NOP_EXPR. */
485 STRIP_NOPS (res);
486 res = fold_convert (type, res);
487 if (CONSTANT_CLASS_P (res))
488 return res;
493 code_helper rcode;
494 tree ops[3] = {};
495 if (!gimple_simplify (&rcode, ops, seq, valueize,
496 fn, type, arg0))
497 return NULL_TREE;
498 return maybe_push_res_to_seq (rcode, type, ops, seq);
501 /* Builtin function with two arguments. */
503 tree
504 gimple_simplify (enum built_in_function fn, tree type,
505 tree arg0, tree arg1,
506 gimple_seq *seq, tree (*valueize)(tree))
508 if (constant_for_folding (arg0)
509 && constant_for_folding (arg1))
511 tree decl = builtin_decl_implicit (fn);
512 if (decl)
514 tree args[2];
515 args[0] = arg0;
516 args[1] = arg1;
517 tree res = fold_builtin_n (UNKNOWN_LOCATION, decl, args, 2, false);
518 if (res)
520 /* fold_builtin_n wraps the result inside a NOP_EXPR. */
521 STRIP_NOPS (res);
522 res = fold_convert (type, res);
523 if (CONSTANT_CLASS_P (res))
524 return res;
529 code_helper rcode;
530 tree ops[3] = {};
531 if (!gimple_simplify (&rcode, ops, seq, valueize,
532 fn, type, arg0, arg1))
533 return NULL_TREE;
534 return maybe_push_res_to_seq (rcode, type, ops, seq);
537 /* Builtin function with three arguments. */
539 tree
540 gimple_simplify (enum built_in_function fn, tree type,
541 tree arg0, tree arg1, tree arg2,
542 gimple_seq *seq, tree (*valueize)(tree))
544 if (constant_for_folding (arg0)
545 && constant_for_folding (arg1)
546 && constant_for_folding (arg2))
548 tree decl = builtin_decl_implicit (fn);
549 if (decl)
551 tree args[3];
552 args[0] = arg0;
553 args[1] = arg1;
554 args[2] = arg2;
555 tree res = fold_builtin_n (UNKNOWN_LOCATION, decl, args, 3, false);
556 if (res)
558 /* fold_builtin_n wraps the result inside a NOP_EXPR. */
559 STRIP_NOPS (res);
560 res = fold_convert (type, res);
561 if (CONSTANT_CLASS_P (res))
562 return res;
567 code_helper rcode;
568 tree ops[3] = {};
569 if (!gimple_simplify (&rcode, ops, seq, valueize,
570 fn, type, arg0, arg1, arg2))
571 return NULL_TREE;
572 return maybe_push_res_to_seq (rcode, type, ops, seq);
576 /* The main STMT based simplification entry. It is used by the fold_stmt
577 and the fold_stmt_to_constant APIs. */
579 bool
580 gimple_simplify (gimple stmt,
581 code_helper *rcode, tree *ops,
582 gimple_seq *seq,
583 tree (*valueize)(tree), tree (*top_valueize)(tree))
585 switch (gimple_code (stmt))
587 case GIMPLE_ASSIGN:
589 enum tree_code code = gimple_assign_rhs_code (stmt);
590 tree type = TREE_TYPE (gimple_assign_lhs (stmt));
591 switch (gimple_assign_rhs_class (stmt))
593 case GIMPLE_SINGLE_RHS:
594 if (code == REALPART_EXPR
595 || code == IMAGPART_EXPR
596 || code == VIEW_CONVERT_EXPR)
598 tree op0 = TREE_OPERAND (gimple_assign_rhs1 (stmt), 0);
599 if (top_valueize && TREE_CODE (op0) == SSA_NAME)
601 tree tem = top_valueize (op0);
602 if (tem)
603 op0 = tem;
605 *rcode = code;
606 ops[0] = op0;
607 return gimple_resimplify1 (seq, rcode, type, ops, valueize);
609 else if (code == BIT_FIELD_REF)
611 tree rhs1 = gimple_assign_rhs1 (stmt);
612 tree op0 = TREE_OPERAND (rhs1, 0);
613 if (top_valueize && TREE_CODE (op0) == SSA_NAME)
615 tree tem = top_valueize (op0);
616 if (tem)
617 op0 = tem;
619 *rcode = code;
620 ops[0] = op0;
621 ops[1] = TREE_OPERAND (rhs1, 1);
622 ops[2] = TREE_OPERAND (rhs1, 2);
623 return gimple_resimplify3 (seq, rcode, type, ops, valueize);
625 else if (code == SSA_NAME
626 && top_valueize)
628 tree op0 = gimple_assign_rhs1 (stmt);
629 tree valueized = top_valueize (op0);
630 if (!valueized || op0 == valueized)
631 return false;
632 ops[0] = valueized;
633 *rcode = TREE_CODE (op0);
634 return true;
636 break;
637 case GIMPLE_UNARY_RHS:
639 tree rhs1 = gimple_assign_rhs1 (stmt);
640 if (top_valueize && TREE_CODE (rhs1) == SSA_NAME)
642 tree tem = top_valueize (rhs1);
643 if (tem)
644 rhs1 = tem;
646 *rcode = code;
647 ops[0] = rhs1;
648 return gimple_resimplify1 (seq, rcode, type, ops, valueize);
650 case GIMPLE_BINARY_RHS:
652 tree rhs1 = gimple_assign_rhs1 (stmt);
653 if (top_valueize && TREE_CODE (rhs1) == SSA_NAME)
655 tree tem = top_valueize (rhs1);
656 if (tem)
657 rhs1 = tem;
659 tree rhs2 = gimple_assign_rhs2 (stmt);
660 if (top_valueize && TREE_CODE (rhs2) == SSA_NAME)
662 tree tem = top_valueize (rhs2);
663 if (tem)
664 rhs2 = tem;
666 *rcode = code;
667 ops[0] = rhs1;
668 ops[1] = rhs2;
669 return gimple_resimplify2 (seq, rcode, type, ops, valueize);
671 case GIMPLE_TERNARY_RHS:
673 tree rhs1 = gimple_assign_rhs1 (stmt);
674 if (top_valueize && TREE_CODE (rhs1) == SSA_NAME)
676 tree tem = top_valueize (rhs1);
677 if (tem)
678 rhs1 = tem;
680 tree rhs2 = gimple_assign_rhs2 (stmt);
681 if (top_valueize && TREE_CODE (rhs2) == SSA_NAME)
683 tree tem = top_valueize (rhs2);
684 if (tem)
685 rhs2 = tem;
687 tree rhs3 = gimple_assign_rhs3 (stmt);
688 if (top_valueize && TREE_CODE (rhs3) == SSA_NAME)
690 tree tem = top_valueize (rhs3);
691 if (tem)
692 rhs3 = tem;
694 *rcode = code;
695 ops[0] = rhs1;
696 ops[1] = rhs2;
697 ops[2] = rhs3;
698 return gimple_resimplify3 (seq, rcode, type, ops, valueize);
700 default:
701 gcc_unreachable ();
703 break;
706 case GIMPLE_CALL:
707 /* ??? This way we can't simplify calls with side-effects. */
708 if (gimple_call_lhs (stmt) != NULL_TREE)
710 tree fn = gimple_call_fn (stmt);
711 /* ??? Internal function support missing. */
712 if (!fn)
713 return false;
714 if (top_valueize && TREE_CODE (fn) == SSA_NAME)
716 tree tem = top_valueize (fn);
717 if (tem)
718 fn = tem;
720 if (!fn
721 || TREE_CODE (fn) != ADDR_EXPR
722 || TREE_CODE (TREE_OPERAND (fn, 0)) != FUNCTION_DECL
723 || DECL_BUILT_IN_CLASS (TREE_OPERAND (fn, 0)) != BUILT_IN_NORMAL
724 || !builtin_decl_implicit (DECL_FUNCTION_CODE (TREE_OPERAND (fn, 0)))
725 || !gimple_builtin_call_types_compatible_p (stmt,
726 TREE_OPERAND (fn, 0)))
727 return false;
729 tree decl = TREE_OPERAND (fn, 0);
730 tree type = TREE_TYPE (gimple_call_lhs (stmt));
731 switch (gimple_call_num_args (stmt))
733 case 1:
735 tree arg1 = gimple_call_arg (stmt, 0);
736 if (top_valueize && TREE_CODE (arg1) == SSA_NAME)
738 tree tem = top_valueize (arg1);
739 if (tem)
740 arg1 = tem;
742 *rcode = DECL_FUNCTION_CODE (decl);
743 ops[0] = arg1;
744 return gimple_resimplify1 (seq, rcode, type, ops, valueize);
746 case 2:
748 tree arg1 = gimple_call_arg (stmt, 0);
749 if (top_valueize && TREE_CODE (arg1) == SSA_NAME)
751 tree tem = top_valueize (arg1);
752 if (tem)
753 arg1 = tem;
755 tree arg2 = gimple_call_arg (stmt, 1);
756 if (top_valueize && TREE_CODE (arg2) == SSA_NAME)
758 tree tem = top_valueize (arg2);
759 if (tem)
760 arg2 = tem;
762 *rcode = DECL_FUNCTION_CODE (decl);
763 ops[0] = arg1;
764 ops[1] = arg2;
765 return gimple_resimplify2 (seq, rcode, type, ops, valueize);
767 case 3:
769 tree arg1 = gimple_call_arg (stmt, 0);
770 if (top_valueize && TREE_CODE (arg1) == SSA_NAME)
772 tree tem = top_valueize (arg1);
773 if (tem)
774 arg1 = tem;
776 tree arg2 = gimple_call_arg (stmt, 1);
777 if (top_valueize && TREE_CODE (arg2) == SSA_NAME)
779 tree tem = top_valueize (arg2);
780 if (tem)
781 arg2 = tem;
783 tree arg3 = gimple_call_arg (stmt, 2);
784 if (top_valueize && TREE_CODE (arg3) == SSA_NAME)
786 tree tem = top_valueize (arg3);
787 if (tem)
788 arg3 = tem;
790 *rcode = DECL_FUNCTION_CODE (decl);
791 ops[0] = arg1;
792 ops[1] = arg2;
793 ops[2] = arg3;
794 return gimple_resimplify3 (seq, rcode, type, ops, valueize);
796 default:
797 return false;
800 break;
802 case GIMPLE_COND:
804 tree lhs = gimple_cond_lhs (stmt);
805 if (top_valueize && TREE_CODE (lhs) == SSA_NAME)
807 tree tem = top_valueize (lhs);
808 if (tem)
809 lhs = tem;
811 tree rhs = gimple_cond_rhs (stmt);
812 if (top_valueize && TREE_CODE (rhs) == SSA_NAME)
814 tree tem = top_valueize (rhs);
815 if (tem)
816 rhs = tem;
818 *rcode = gimple_cond_code (stmt);
819 ops[0] = lhs;
820 ops[1] = rhs;
821 return gimple_resimplify2 (seq, rcode, boolean_type_node, ops, valueize);
824 default:
825 break;
828 return false;
832 /* Helper for the autogenerated code, valueize OP. */
834 inline tree
835 do_valueize (tree (*valueize)(tree), tree op)
837 if (valueize && TREE_CODE (op) == SSA_NAME)
838 return valueize (op);
839 return op;
842 /* Routine to determine if the types T1 and T2 are effectively
843 the same for GIMPLE. If T1 or T2 is not a type, the test
844 applies to their TREE_TYPE. */
846 static inline bool
847 types_match (tree t1, tree t2)
849 if (!TYPE_P (t1))
850 t1 = TREE_TYPE (t1);
851 if (!TYPE_P (t2))
852 t2 = TREE_TYPE (t2);
854 return types_compatible_p (t1, t2);
857 /* Return if T has a single use. For GIMPLE, we also allow any
858 non-SSA_NAME (ie constants) and zero uses to cope with uses
859 that aren't linked up yet. */
861 static inline bool
862 single_use (tree t)
864 return TREE_CODE (t) != SSA_NAME || has_zero_uses (t) || has_single_use (t);