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