compiler: Create dummy labels for blank labels.
[official-gcc.git] / gcc / gimple-match-head.c
blob2b1423806bca237910a1f75912182f372e5b346d
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 "tree.h"
25 #include "gimple.h"
26 #include "rtl.h"
27 #include "ssa.h"
28 #include "alias.h"
29 #include "options.h"
30 #include "fold-const.h"
31 #include "stor-layout.h"
32 #include "flags.h"
33 #include "internal-fn.h"
34 #include "gimple-fold.h"
35 #include "gimple-iterator.h"
36 #include "insn-config.h"
37 #include "expmed.h"
38 #include "dojump.h"
39 #include "explow.h"
40 #include "calls.h"
41 #include "emit-rtl.h"
42 #include "varasm.h"
43 #include "stmt.h"
44 #include "expr.h"
45 #include "tree-dfa.h"
46 #include "builtins.h"
47 #include "dumpfile.h"
48 #include "target.h"
49 #include "gimple-match.h"
52 /* Forward declarations of the private auto-generated matchers.
53 They expect valueized operands in canonical order and do not
54 perform simplification of all-constant operands. */
55 static bool gimple_simplify (code_helper *, tree *,
56 gimple_seq *, tree (*)(tree),
57 code_helper, tree, tree);
58 static bool gimple_simplify (code_helper *, tree *,
59 gimple_seq *, tree (*)(tree),
60 code_helper, tree, tree, tree);
61 static bool gimple_simplify (code_helper *, tree *,
62 gimple_seq *, tree (*)(tree),
63 code_helper, tree, tree, tree, tree);
66 /* Return whether T is a constant that we'll dispatch to fold to
67 evaluate fully constant expressions. */
69 static inline bool
70 constant_for_folding (tree t)
72 return (CONSTANT_CLASS_P (t)
73 /* The following is only interesting to string builtins. */
74 || (TREE_CODE (t) == ADDR_EXPR
75 && TREE_CODE (TREE_OPERAND (t, 0)) == STRING_CST));
79 /* Helper that matches and simplifies the toplevel result from
80 a gimple_simplify run (where we don't want to build
81 a stmt in case it's used in in-place folding). Replaces
82 *RES_CODE and *RES_OPS with a simplified and/or canonicalized
83 result and returns whether any change was made. */
85 static bool
86 gimple_resimplify1 (gimple_seq *seq,
87 code_helper *res_code, tree type, tree *res_ops,
88 tree (*valueize)(tree))
90 if (constant_for_folding (res_ops[0]))
92 tree tem = NULL_TREE;
93 if (res_code->is_tree_code ())
94 tem = const_unop (*res_code, type, res_ops[0]);
95 else
97 tree decl = builtin_decl_implicit (*res_code);
98 if (decl)
100 tem = fold_builtin_n (UNKNOWN_LOCATION, decl, res_ops, 1, false);
101 if (tem)
103 /* fold_builtin_n wraps the result inside a NOP_EXPR. */
104 STRIP_NOPS (tem);
105 tem = fold_convert (type, tem);
109 if (tem != NULL_TREE
110 && CONSTANT_CLASS_P (tem))
112 res_ops[0] = tem;
113 res_ops[1] = NULL_TREE;
114 res_ops[2] = NULL_TREE;
115 *res_code = TREE_CODE (res_ops[0]);
116 return true;
120 code_helper res_code2;
121 tree res_ops2[3] = {};
122 if (gimple_simplify (&res_code2, res_ops2, seq, valueize,
123 *res_code, type, res_ops[0]))
125 *res_code = res_code2;
126 res_ops[0] = res_ops2[0];
127 res_ops[1] = res_ops2[1];
128 res_ops[2] = res_ops2[2];
129 return true;
132 return false;
135 /* Helper that matches and simplifies the toplevel result from
136 a gimple_simplify run (where we don't want to build
137 a stmt in case it's used in in-place folding). Replaces
138 *RES_CODE and *RES_OPS with a simplified and/or canonicalized
139 result and returns whether any change was made. */
141 static bool
142 gimple_resimplify2 (gimple_seq *seq,
143 code_helper *res_code, tree type, tree *res_ops,
144 tree (*valueize)(tree))
146 if (constant_for_folding (res_ops[0]) && constant_for_folding (res_ops[1]))
148 tree tem = NULL_TREE;
149 if (res_code->is_tree_code ())
150 tem = const_binop (*res_code, type, res_ops[0], res_ops[1]);
151 else
153 tree decl = builtin_decl_implicit (*res_code);
154 if (decl)
156 tem = fold_builtin_n (UNKNOWN_LOCATION, decl, res_ops, 2, false);
157 if (tem)
159 /* fold_builtin_n wraps the result inside a NOP_EXPR. */
160 STRIP_NOPS (tem);
161 tem = fold_convert (type, tem);
165 if (tem != NULL_TREE
166 && CONSTANT_CLASS_P (tem))
168 res_ops[0] = tem;
169 res_ops[1] = NULL_TREE;
170 res_ops[2] = NULL_TREE;
171 *res_code = TREE_CODE (res_ops[0]);
172 return true;
176 /* Canonicalize operand order. */
177 bool canonicalized = false;
178 if (res_code->is_tree_code ()
179 && (TREE_CODE_CLASS ((enum tree_code) *res_code) == tcc_comparison
180 || commutative_tree_code (*res_code))
181 && tree_swap_operands_p (res_ops[0], res_ops[1], false))
183 std::swap (res_ops[0], res_ops[1]);
184 if (TREE_CODE_CLASS ((enum tree_code) *res_code) == tcc_comparison)
185 *res_code = swap_tree_comparison (*res_code);
186 canonicalized = true;
189 code_helper res_code2;
190 tree res_ops2[3] = {};
191 if (gimple_simplify (&res_code2, res_ops2, seq, valueize,
192 *res_code, type, res_ops[0], res_ops[1]))
194 *res_code = res_code2;
195 res_ops[0] = res_ops2[0];
196 res_ops[1] = res_ops2[1];
197 res_ops[2] = res_ops2[2];
198 return true;
201 return canonicalized;
204 /* Helper that matches and simplifies the toplevel result from
205 a gimple_simplify run (where we don't want to build
206 a stmt in case it's used in in-place folding). Replaces
207 *RES_CODE and *RES_OPS with a simplified and/or canonicalized
208 result and returns whether any change was made. */
210 static bool
211 gimple_resimplify3 (gimple_seq *seq,
212 code_helper *res_code, tree type, tree *res_ops,
213 tree (*valueize)(tree))
215 if (constant_for_folding (res_ops[0]) && constant_for_folding (res_ops[1])
216 && constant_for_folding (res_ops[2]))
218 tree tem = NULL_TREE;
219 if (res_code->is_tree_code ())
220 tem = fold_ternary/*_to_constant*/ (*res_code, type, res_ops[0],
221 res_ops[1], res_ops[2]);
222 else
224 tree decl = builtin_decl_implicit (*res_code);
225 if (decl)
227 tem = fold_builtin_n (UNKNOWN_LOCATION, decl, res_ops, 3, false);
228 if (tem)
230 /* fold_builtin_n wraps the result inside a NOP_EXPR. */
231 STRIP_NOPS (tem);
232 tem = fold_convert (type, tem);
236 if (tem != NULL_TREE
237 && CONSTANT_CLASS_P (tem))
239 res_ops[0] = tem;
240 res_ops[1] = NULL_TREE;
241 res_ops[2] = NULL_TREE;
242 *res_code = TREE_CODE (res_ops[0]);
243 return true;
247 /* Canonicalize operand order. */
248 bool canonicalized = false;
249 if (res_code->is_tree_code ()
250 && commutative_ternary_tree_code (*res_code)
251 && tree_swap_operands_p (res_ops[0], res_ops[1], false))
253 std::swap (res_ops[0], res_ops[1]);
254 canonicalized = true;
257 code_helper res_code2;
258 tree res_ops2[3] = {};
259 if (gimple_simplify (&res_code2, res_ops2, seq, valueize,
260 *res_code, type,
261 res_ops[0], res_ops[1], res_ops[2]))
263 *res_code = res_code2;
264 res_ops[0] = res_ops2[0];
265 res_ops[1] = res_ops2[1];
266 res_ops[2] = res_ops2[2];
267 return true;
270 return canonicalized;
274 /* If in GIMPLE expressions with CODE go as single-rhs build
275 a GENERIC tree for that expression into *OP0. */
277 void
278 maybe_build_generic_op (enum tree_code code, tree type,
279 tree *op0, tree op1, tree op2)
281 switch (code)
283 case REALPART_EXPR:
284 case IMAGPART_EXPR:
285 case VIEW_CONVERT_EXPR:
286 *op0 = build1 (code, type, *op0);
287 break;
288 case BIT_FIELD_REF:
289 *op0 = build3 (code, type, *op0, op1, op2);
290 break;
291 default:;
295 /* Push the exploded expression described by RCODE, TYPE and OPS
296 as a statement to SEQ if necessary and return a gimple value
297 denoting the value of the expression. If RES is not NULL
298 then the result will be always RES and even gimple values are
299 pushed to SEQ. */
301 tree
302 maybe_push_res_to_seq (code_helper rcode, tree type, tree *ops,
303 gimple_seq *seq, tree res)
305 if (rcode.is_tree_code ())
307 if (!res
308 && (TREE_CODE_LENGTH ((tree_code) rcode) == 0
309 || ((tree_code) rcode) == ADDR_EXPR)
310 && is_gimple_val (ops[0]))
311 return ops[0];
312 if (!seq)
313 return NULL_TREE;
314 /* Play safe and do not allow abnormals to be mentioned in
315 newly created statements. */
316 if ((TREE_CODE (ops[0]) == SSA_NAME
317 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops[0]))
318 || (ops[1]
319 && TREE_CODE (ops[1]) == SSA_NAME
320 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops[1]))
321 || (ops[2]
322 && TREE_CODE (ops[2]) == SSA_NAME
323 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops[2])))
324 return NULL_TREE;
325 if (!res)
326 res = make_ssa_name (type);
327 maybe_build_generic_op (rcode, type, &ops[0], ops[1], ops[2]);
328 gimple new_stmt = gimple_build_assign (res, rcode,
329 ops[0], ops[1], ops[2]);
330 gimple_seq_add_stmt_without_update (seq, new_stmt);
331 return res;
333 else
335 if (!seq)
336 return NULL_TREE;
337 tree decl = builtin_decl_implicit (rcode);
338 if (!decl)
339 return NULL_TREE;
340 unsigned nargs = type_num_arguments (TREE_TYPE (decl));
341 gcc_assert (nargs <= 3);
342 /* Play safe and do not allow abnormals to be mentioned in
343 newly created statements. */
344 if ((TREE_CODE (ops[0]) == SSA_NAME
345 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops[0]))
346 || (nargs >= 2
347 && TREE_CODE (ops[1]) == SSA_NAME
348 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops[1]))
349 || (nargs == 3
350 && TREE_CODE (ops[2]) == SSA_NAME
351 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops[2])))
352 return NULL_TREE;
353 if (!res)
354 res = make_ssa_name (type);
355 gimple new_stmt = gimple_build_call (decl, nargs, ops[0], ops[1], ops[2]);
356 gimple_call_set_lhs (new_stmt, res);
357 gimple_seq_add_stmt_without_update (seq, new_stmt);
358 return res;
363 /* Public API overloads follow for operation being tree_code or
364 built_in_function and for one to three operands or arguments.
365 They return NULL_TREE if nothing could be simplified or
366 the resulting simplified value with parts pushed to SEQ.
367 If SEQ is NULL then if the simplification needs to create
368 new stmts it will fail. If VALUEIZE is non-NULL then all
369 SSA names will be valueized using that hook prior to
370 applying simplifications. */
372 /* Unary ops. */
374 tree
375 gimple_simplify (enum tree_code code, tree type,
376 tree op0,
377 gimple_seq *seq, tree (*valueize)(tree))
379 if (constant_for_folding (op0))
381 tree res = const_unop (code, type, op0);
382 if (res != NULL_TREE
383 && CONSTANT_CLASS_P (res))
384 return res;
387 code_helper rcode;
388 tree ops[3] = {};
389 if (!gimple_simplify (&rcode, ops, seq, valueize,
390 code, type, op0))
391 return NULL_TREE;
392 return maybe_push_res_to_seq (rcode, type, ops, seq);
395 /* Binary ops. */
397 tree
398 gimple_simplify (enum tree_code code, tree type,
399 tree op0, tree op1,
400 gimple_seq *seq, tree (*valueize)(tree))
402 if (constant_for_folding (op0) && constant_for_folding (op1))
404 tree res = const_binop (code, type, op0, op1);
405 if (res != NULL_TREE
406 && CONSTANT_CLASS_P (res))
407 return res;
410 /* Canonicalize operand order both for matching and fallback stmt
411 generation. */
412 if ((commutative_tree_code (code)
413 || TREE_CODE_CLASS (code) == tcc_comparison)
414 && tree_swap_operands_p (op0, op1, false))
416 std::swap (op0, op1);
417 if (TREE_CODE_CLASS (code) == tcc_comparison)
418 code = swap_tree_comparison (code);
421 code_helper rcode;
422 tree ops[3] = {};
423 if (!gimple_simplify (&rcode, ops, seq, valueize,
424 code, type, op0, op1))
425 return NULL_TREE;
426 return maybe_push_res_to_seq (rcode, type, ops, seq);
429 /* Ternary ops. */
431 tree
432 gimple_simplify (enum tree_code code, tree type,
433 tree op0, tree op1, tree op2,
434 gimple_seq *seq, tree (*valueize)(tree))
436 if (constant_for_folding (op0) && constant_for_folding (op1)
437 && constant_for_folding (op2))
439 tree res = fold_ternary/*_to_constant */ (code, type, op0, op1, op2);
440 if (res != NULL_TREE
441 && CONSTANT_CLASS_P (res))
442 return res;
445 /* Canonicalize operand order both for matching and fallback stmt
446 generation. */
447 if (commutative_ternary_tree_code (code)
448 && tree_swap_operands_p (op0, op1, false))
449 std::swap (op0, op1);
451 code_helper rcode;
452 tree ops[3] = {};
453 if (!gimple_simplify (&rcode, ops, seq, valueize,
454 code, type, op0, op1, op2))
455 return NULL_TREE;
456 return maybe_push_res_to_seq (rcode, type, ops, seq);
459 /* Builtin function with one argument. */
461 tree
462 gimple_simplify (enum built_in_function fn, tree type,
463 tree arg0,
464 gimple_seq *seq, tree (*valueize)(tree))
466 if (constant_for_folding (arg0))
468 tree decl = builtin_decl_implicit (fn);
469 if (decl)
471 tree res = fold_builtin_n (UNKNOWN_LOCATION, decl, &arg0, 1, false);
472 if (res)
474 /* fold_builtin_n wraps the result inside a NOP_EXPR. */
475 STRIP_NOPS (res);
476 res = fold_convert (type, res);
477 if (CONSTANT_CLASS_P (res))
478 return res;
483 code_helper rcode;
484 tree ops[3] = {};
485 if (!gimple_simplify (&rcode, ops, seq, valueize,
486 fn, type, arg0))
487 return NULL_TREE;
488 return maybe_push_res_to_seq (rcode, type, ops, seq);
491 /* Builtin function with two arguments. */
493 tree
494 gimple_simplify (enum built_in_function fn, tree type,
495 tree arg0, tree arg1,
496 gimple_seq *seq, tree (*valueize)(tree))
498 if (constant_for_folding (arg0)
499 && constant_for_folding (arg1))
501 tree decl = builtin_decl_implicit (fn);
502 if (decl)
504 tree args[2];
505 args[0] = arg0;
506 args[1] = arg1;
507 tree res = fold_builtin_n (UNKNOWN_LOCATION, decl, args, 2, false);
508 if (res)
510 /* fold_builtin_n wraps the result inside a NOP_EXPR. */
511 STRIP_NOPS (res);
512 res = fold_convert (type, res);
513 if (CONSTANT_CLASS_P (res))
514 return res;
519 code_helper rcode;
520 tree ops[3] = {};
521 if (!gimple_simplify (&rcode, ops, seq, valueize,
522 fn, type, arg0, arg1))
523 return NULL_TREE;
524 return maybe_push_res_to_seq (rcode, type, ops, seq);
527 /* Builtin function with three arguments. */
529 tree
530 gimple_simplify (enum built_in_function fn, tree type,
531 tree arg0, tree arg1, tree arg2,
532 gimple_seq *seq, tree (*valueize)(tree))
534 if (constant_for_folding (arg0)
535 && constant_for_folding (arg1)
536 && constant_for_folding (arg2))
538 tree decl = builtin_decl_implicit (fn);
539 if (decl)
541 tree args[3];
542 args[0] = arg0;
543 args[1] = arg1;
544 args[2] = arg2;
545 tree res = fold_builtin_n (UNKNOWN_LOCATION, decl, args, 3, false);
546 if (res)
548 /* fold_builtin_n wraps the result inside a NOP_EXPR. */
549 STRIP_NOPS (res);
550 res = fold_convert (type, res);
551 if (CONSTANT_CLASS_P (res))
552 return res;
557 code_helper rcode;
558 tree ops[3] = {};
559 if (!gimple_simplify (&rcode, ops, seq, valueize,
560 fn, type, arg0, arg1, arg2))
561 return NULL_TREE;
562 return maybe_push_res_to_seq (rcode, type, ops, seq);
566 /* The main STMT based simplification entry. It is used by the fold_stmt
567 and the fold_stmt_to_constant APIs. */
569 bool
570 gimple_simplify (gimple stmt,
571 code_helper *rcode, tree *ops,
572 gimple_seq *seq,
573 tree (*valueize)(tree), tree (*top_valueize)(tree))
575 switch (gimple_code (stmt))
577 case GIMPLE_ASSIGN:
579 enum tree_code code = gimple_assign_rhs_code (stmt);
580 tree type = TREE_TYPE (gimple_assign_lhs (stmt));
581 switch (gimple_assign_rhs_class (stmt))
583 case GIMPLE_SINGLE_RHS:
584 if (code == REALPART_EXPR
585 || code == IMAGPART_EXPR
586 || code == VIEW_CONVERT_EXPR)
588 tree op0 = TREE_OPERAND (gimple_assign_rhs1 (stmt), 0);
589 if (top_valueize && TREE_CODE (op0) == SSA_NAME)
591 tree tem = top_valueize (op0);
592 if (tem)
593 op0 = tem;
595 *rcode = code;
596 ops[0] = op0;
597 return gimple_resimplify1 (seq, rcode, type, ops, valueize);
599 else if (code == BIT_FIELD_REF)
601 tree rhs1 = gimple_assign_rhs1 (stmt);
602 tree op0 = TREE_OPERAND (rhs1, 0);
603 if (top_valueize && TREE_CODE (op0) == SSA_NAME)
605 tree tem = top_valueize (op0);
606 if (tem)
607 op0 = tem;
609 *rcode = code;
610 ops[0] = op0;
611 ops[1] = TREE_OPERAND (rhs1, 1);
612 ops[2] = TREE_OPERAND (rhs1, 2);
613 return gimple_resimplify3 (seq, rcode, type, ops, valueize);
615 else if (code == SSA_NAME
616 && top_valueize)
618 tree op0 = gimple_assign_rhs1 (stmt);
619 tree valueized = top_valueize (op0);
620 if (!valueized || op0 == valueized)
621 return false;
622 ops[0] = valueized;
623 *rcode = TREE_CODE (op0);
624 return true;
626 break;
627 case GIMPLE_UNARY_RHS:
629 tree rhs1 = gimple_assign_rhs1 (stmt);
630 if (top_valueize && TREE_CODE (rhs1) == SSA_NAME)
632 tree tem = top_valueize (rhs1);
633 if (tem)
634 rhs1 = tem;
636 *rcode = code;
637 ops[0] = rhs1;
638 return gimple_resimplify1 (seq, rcode, type, ops, valueize);
640 case GIMPLE_BINARY_RHS:
642 tree rhs1 = gimple_assign_rhs1 (stmt);
643 if (top_valueize && TREE_CODE (rhs1) == SSA_NAME)
645 tree tem = top_valueize (rhs1);
646 if (tem)
647 rhs1 = tem;
649 tree rhs2 = gimple_assign_rhs2 (stmt);
650 if (top_valueize && TREE_CODE (rhs2) == SSA_NAME)
652 tree tem = top_valueize (rhs2);
653 if (tem)
654 rhs2 = tem;
656 *rcode = code;
657 ops[0] = rhs1;
658 ops[1] = rhs2;
659 return gimple_resimplify2 (seq, rcode, type, ops, valueize);
661 case GIMPLE_TERNARY_RHS:
663 tree rhs1 = gimple_assign_rhs1 (stmt);
664 if (top_valueize && TREE_CODE (rhs1) == SSA_NAME)
666 tree tem = top_valueize (rhs1);
667 if (tem)
668 rhs1 = tem;
670 tree rhs2 = gimple_assign_rhs2 (stmt);
671 if (top_valueize && TREE_CODE (rhs2) == SSA_NAME)
673 tree tem = top_valueize (rhs2);
674 if (tem)
675 rhs2 = tem;
677 tree rhs3 = gimple_assign_rhs3 (stmt);
678 if (top_valueize && TREE_CODE (rhs3) == SSA_NAME)
680 tree tem = top_valueize (rhs3);
681 if (tem)
682 rhs3 = tem;
684 *rcode = code;
685 ops[0] = rhs1;
686 ops[1] = rhs2;
687 ops[2] = rhs3;
688 return gimple_resimplify3 (seq, rcode, type, ops, valueize);
690 default:
691 gcc_unreachable ();
693 break;
696 case GIMPLE_CALL:
697 /* ??? This way we can't simplify calls with side-effects. */
698 if (gimple_call_lhs (stmt) != NULL_TREE)
700 tree fn = gimple_call_fn (stmt);
701 /* ??? Internal function support missing. */
702 if (!fn)
703 return false;
704 if (top_valueize && TREE_CODE (fn) == SSA_NAME)
706 tree tem = top_valueize (fn);
707 if (tem)
708 fn = tem;
710 if (!fn
711 || TREE_CODE (fn) != ADDR_EXPR
712 || TREE_CODE (TREE_OPERAND (fn, 0)) != FUNCTION_DECL
713 || DECL_BUILT_IN_CLASS (TREE_OPERAND (fn, 0)) != BUILT_IN_NORMAL
714 || !builtin_decl_implicit (DECL_FUNCTION_CODE (TREE_OPERAND (fn, 0)))
715 || !gimple_builtin_call_types_compatible_p (stmt,
716 TREE_OPERAND (fn, 0)))
717 return false;
719 tree decl = TREE_OPERAND (fn, 0);
720 tree type = TREE_TYPE (gimple_call_lhs (stmt));
721 switch (gimple_call_num_args (stmt))
723 case 1:
725 tree arg1 = gimple_call_arg (stmt, 0);
726 if (top_valueize && TREE_CODE (arg1) == SSA_NAME)
728 tree tem = top_valueize (arg1);
729 if (tem)
730 arg1 = tem;
732 *rcode = DECL_FUNCTION_CODE (decl);
733 ops[0] = arg1;
734 return gimple_resimplify1 (seq, rcode, type, ops, valueize);
736 case 2:
738 tree arg1 = gimple_call_arg (stmt, 0);
739 if (top_valueize && TREE_CODE (arg1) == SSA_NAME)
741 tree tem = top_valueize (arg1);
742 if (tem)
743 arg1 = tem;
745 tree arg2 = gimple_call_arg (stmt, 1);
746 if (top_valueize && TREE_CODE (arg2) == SSA_NAME)
748 tree tem = top_valueize (arg2);
749 if (tem)
750 arg2 = tem;
752 *rcode = DECL_FUNCTION_CODE (decl);
753 ops[0] = arg1;
754 ops[1] = arg2;
755 return gimple_resimplify2 (seq, rcode, type, ops, valueize);
757 case 3:
759 tree arg1 = gimple_call_arg (stmt, 0);
760 if (top_valueize && TREE_CODE (arg1) == SSA_NAME)
762 tree tem = top_valueize (arg1);
763 if (tem)
764 arg1 = tem;
766 tree arg2 = gimple_call_arg (stmt, 1);
767 if (top_valueize && TREE_CODE (arg2) == SSA_NAME)
769 tree tem = top_valueize (arg2);
770 if (tem)
771 arg2 = tem;
773 tree arg3 = gimple_call_arg (stmt, 2);
774 if (top_valueize && TREE_CODE (arg3) == SSA_NAME)
776 tree tem = top_valueize (arg3);
777 if (tem)
778 arg3 = tem;
780 *rcode = DECL_FUNCTION_CODE (decl);
781 ops[0] = arg1;
782 ops[1] = arg2;
783 ops[2] = arg3;
784 return gimple_resimplify3 (seq, rcode, type, ops, valueize);
786 default:
787 return false;
790 break;
792 case GIMPLE_COND:
794 tree lhs = gimple_cond_lhs (stmt);
795 if (top_valueize && TREE_CODE (lhs) == SSA_NAME)
797 tree tem = top_valueize (lhs);
798 if (tem)
799 lhs = tem;
801 tree rhs = gimple_cond_rhs (stmt);
802 if (top_valueize && TREE_CODE (rhs) == SSA_NAME)
804 tree tem = top_valueize (rhs);
805 if (tem)
806 rhs = tem;
808 *rcode = gimple_cond_code (stmt);
809 ops[0] = lhs;
810 ops[1] = rhs;
811 return gimple_resimplify2 (seq, rcode, boolean_type_node, ops, valueize);
814 default:
815 break;
818 return false;
822 /* Helper for the autogenerated code, valueize OP. */
824 inline tree
825 do_valueize (tree (*valueize)(tree), tree op)
827 if (valueize && TREE_CODE (op) == SSA_NAME)
828 return valueize (op);
829 return op;
832 /* Routine to determine if the types T1 and T2 are effectively
833 the same for GIMPLE. If T1 or T2 is not a type, the test
834 applies to their TREE_TYPE. */
836 static inline bool
837 types_match (tree t1, tree t2)
839 if (!TYPE_P (t1))
840 t1 = TREE_TYPE (t1);
841 if (!TYPE_P (t2))
842 t2 = TREE_TYPE (t2);
844 return types_compatible_p (t1, t2);
847 /* Return if T has a single use. For GIMPLE, we also allow any
848 non-SSA_NAME (ie constants) and zero uses to cope with uses
849 that aren't linked up yet. */
851 static inline bool
852 single_use (tree t)
854 return TREE_CODE (t) != SSA_NAME || has_zero_uses (t) || has_single_use (t);