comparison gcc/tree.c @ 55:77e2b8dfacca gcc-4.4.5

update it from 4.4.3 to 4.5.0
author ryoma <e075725@ie.u-ryukyu.ac.jp>
date Fri, 12 Feb 2010 23:39:51 +0900
parents 58ad6c70ea60
children 326d9e06c2e3 b7f97abdc517
comparison
equal deleted inserted replaced
52:c156f1bd5cd9 55:77e2b8dfacca
1 /* Language-independent node constructors for parse phase of GNU compiler. 1 /* Language-independent node constructors for parse phase of GNU compiler.
2 Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2 Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
4 Free Software Foundation, Inc. 4 Free Software Foundation, Inc.
5 5
6 This file is part of GCC. 6 This file is part of GCC.
7 7
8 GCC is free software; you can redistribute it and/or modify it under 8 GCC is free software; you can redistribute it and/or modify it under
43 #include "ggc.h" 43 #include "ggc.h"
44 #include "hashtab.h" 44 #include "hashtab.h"
45 #include "output.h" 45 #include "output.h"
46 #include "target.h" 46 #include "target.h"
47 #include "langhooks.h" 47 #include "langhooks.h"
48 #include "tree-inline.h"
48 #include "tree-iterator.h" 49 #include "tree-iterator.h"
49 #include "basic-block.h" 50 #include "basic-block.h"
50 #include "tree-flow.h" 51 #include "tree-flow.h"
51 #include "params.h" 52 #include "params.h"
52 #include "pointer-set.h" 53 #include "pointer-set.h"
53 #include "fixed-value.h" 54 #include "fixed-value.h"
55 #include "tree-pass.h"
56 #include "langhooks-def.h"
57 #include "diagnostic.h"
58 #include "cgraph.h"
59 #include "timevar.h"
60 #include "except.h"
61 #include "debug.h"
62 #include "intl.h"
54 63
55 /* Tree code classes. */ 64 /* Tree code classes. */
56 65
57 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE, 66 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
58 #define END_OF_BASE_TREE_CODES tcc_exceptional, 67 #define END_OF_BASE_TREE_CODES tcc_exceptional,
142 151
143 /* Unique id for next decl created. */ 152 /* Unique id for next decl created. */
144 static GTY(()) int next_decl_uid; 153 static GTY(()) int next_decl_uid;
145 /* Unique id for next type created. */ 154 /* Unique id for next type created. */
146 static GTY(()) int next_type_uid = 1; 155 static GTY(()) int next_type_uid = 1;
156 /* Unique id for next debug decl created. Use negative numbers,
157 to catch erroneous uses. */
158 static GTY(()) int next_debug_decl_uid;
147 159
148 /* Since we cannot rehash a type after it is in the table, we have to 160 /* Since we cannot rehash a type after it is in the table, we have to
149 keep the hash code. */ 161 keep the hash code. */
150 162
151 struct type_hash GTY(()) 163 struct GTY(()) type_hash {
152 {
153 unsigned long hash; 164 unsigned long hash;
154 tree type; 165 tree type;
155 }; 166 };
156 167
157 /* Initial size of the hash table (rounded to next prime). */ 168 /* Initial size of the hash table (rounded to next prime). */
183 htab_t cl_option_hash_table; 194 htab_t cl_option_hash_table;
184 195
185 /* General tree->tree mapping structure for use in hash tables. */ 196 /* General tree->tree mapping structure for use in hash tables. */
186 197
187 198
188 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map))) 199 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map)))
189 htab_t debug_expr_for_decl; 200 htab_t debug_expr_for_decl;
190 201
191 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map))) 202 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map)))
192 htab_t value_expr_for_decl; 203 htab_t value_expr_for_decl;
193 204
194 static GTY ((if_marked ("tree_priority_map_marked_p"), 205 static GTY ((if_marked ("tree_priority_map_marked_p"),
195 param_is (struct tree_priority_map))) 206 param_is (struct tree_priority_map)))
196 htab_t init_priority_for_decl; 207 htab_t init_priority_for_decl;
197
198 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map)))
199 htab_t restrict_base_for_decl;
200 208
201 static void set_type_quals (tree, int); 209 static void set_type_quals (tree, int);
202 static int type_hash_eq (const void *, const void *); 210 static int type_hash_eq (const void *, const void *);
203 static hashval_t type_hash_hash (const void *); 211 static hashval_t type_hash_hash (const void *);
204 static hashval_t int_cst_hash_hash (const void *); 212 static hashval_t int_cst_hash_hash (const void *);
255 "ordered", 263 "ordered",
256 "default", 264 "default",
257 "collapse", 265 "collapse",
258 "untied" 266 "untied"
259 }; 267 };
260 268
261 /* Init tree.c. */ 269
262 270 /* Return the tree node structure used by tree code CODE. */
263 void 271
264 init_ttree (void) 272 static inline enum tree_node_structure_enum
265 { 273 tree_node_structure_for_code (enum tree_code code)
266 /* Initialize the hash table of types. */
267 type_hash_table = htab_create_ggc (TYPE_HASH_INITIAL_SIZE, type_hash_hash,
268 type_hash_eq, 0);
269
270 debug_expr_for_decl = htab_create_ggc (512, tree_map_hash,
271 tree_map_eq, 0);
272
273 value_expr_for_decl = htab_create_ggc (512, tree_map_hash,
274 tree_map_eq, 0);
275 init_priority_for_decl = htab_create_ggc (512, tree_priority_map_hash,
276 tree_priority_map_eq, 0);
277 restrict_base_for_decl = htab_create_ggc (256, tree_map_hash,
278 tree_map_eq, 0);
279
280 int_cst_hash_table = htab_create_ggc (1024, int_cst_hash_hash,
281 int_cst_hash_eq, NULL);
282
283 int_cst_node = make_node (INTEGER_CST);
284
285 cl_option_hash_table = htab_create_ggc (64, cl_option_hash_hash,
286 cl_option_hash_eq, NULL);
287
288 cl_optimization_node = make_node (OPTIMIZATION_NODE);
289 cl_target_option_node = make_node (TARGET_OPTION_NODE);
290
291 tree_contains_struct[FUNCTION_DECL][TS_DECL_NON_COMMON] = 1;
292 tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_NON_COMMON] = 1;
293 tree_contains_struct[TYPE_DECL][TS_DECL_NON_COMMON] = 1;
294
295
296 tree_contains_struct[CONST_DECL][TS_DECL_COMMON] = 1;
297 tree_contains_struct[VAR_DECL][TS_DECL_COMMON] = 1;
298 tree_contains_struct[PARM_DECL][TS_DECL_COMMON] = 1;
299 tree_contains_struct[RESULT_DECL][TS_DECL_COMMON] = 1;
300 tree_contains_struct[FUNCTION_DECL][TS_DECL_COMMON] = 1;
301 tree_contains_struct[TYPE_DECL][TS_DECL_COMMON] = 1;
302 tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_COMMON] = 1;
303 tree_contains_struct[LABEL_DECL][TS_DECL_COMMON] = 1;
304 tree_contains_struct[FIELD_DECL][TS_DECL_COMMON] = 1;
305
306
307 tree_contains_struct[CONST_DECL][TS_DECL_WRTL] = 1;
308 tree_contains_struct[VAR_DECL][TS_DECL_WRTL] = 1;
309 tree_contains_struct[PARM_DECL][TS_DECL_WRTL] = 1;
310 tree_contains_struct[RESULT_DECL][TS_DECL_WRTL] = 1;
311 tree_contains_struct[FUNCTION_DECL][TS_DECL_WRTL] = 1;
312 tree_contains_struct[LABEL_DECL][TS_DECL_WRTL] = 1;
313
314 tree_contains_struct[CONST_DECL][TS_DECL_MINIMAL] = 1;
315 tree_contains_struct[VAR_DECL][TS_DECL_MINIMAL] = 1;
316 tree_contains_struct[PARM_DECL][TS_DECL_MINIMAL] = 1;
317 tree_contains_struct[RESULT_DECL][TS_DECL_MINIMAL] = 1;
318 tree_contains_struct[FUNCTION_DECL][TS_DECL_MINIMAL] = 1;
319 tree_contains_struct[TYPE_DECL][TS_DECL_MINIMAL] = 1;
320 tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_MINIMAL] = 1;
321 tree_contains_struct[LABEL_DECL][TS_DECL_MINIMAL] = 1;
322 tree_contains_struct[FIELD_DECL][TS_DECL_MINIMAL] = 1;
323 tree_contains_struct[NAME_MEMORY_TAG][TS_DECL_MINIMAL] = 1;
324 tree_contains_struct[SYMBOL_MEMORY_TAG][TS_DECL_MINIMAL] = 1;
325 tree_contains_struct[MEMORY_PARTITION_TAG][TS_DECL_MINIMAL] = 1;
326
327 tree_contains_struct[NAME_MEMORY_TAG][TS_MEMORY_TAG] = 1;
328 tree_contains_struct[SYMBOL_MEMORY_TAG][TS_MEMORY_TAG] = 1;
329 tree_contains_struct[MEMORY_PARTITION_TAG][TS_MEMORY_TAG] = 1;
330
331 tree_contains_struct[MEMORY_PARTITION_TAG][TS_MEMORY_PARTITION_TAG] = 1;
332
333 tree_contains_struct[VAR_DECL][TS_DECL_WITH_VIS] = 1;
334 tree_contains_struct[FUNCTION_DECL][TS_DECL_WITH_VIS] = 1;
335 tree_contains_struct[TYPE_DECL][TS_DECL_WITH_VIS] = 1;
336 tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_WITH_VIS] = 1;
337
338 tree_contains_struct[VAR_DECL][TS_VAR_DECL] = 1;
339 tree_contains_struct[FIELD_DECL][TS_FIELD_DECL] = 1;
340 tree_contains_struct[PARM_DECL][TS_PARM_DECL] = 1;
341 tree_contains_struct[LABEL_DECL][TS_LABEL_DECL] = 1;
342 tree_contains_struct[RESULT_DECL][TS_RESULT_DECL] = 1;
343 tree_contains_struct[CONST_DECL][TS_CONST_DECL] = 1;
344 tree_contains_struct[TYPE_DECL][TS_TYPE_DECL] = 1;
345 tree_contains_struct[FUNCTION_DECL][TS_FUNCTION_DECL] = 1;
346 tree_contains_struct[IMPORTED_DECL][TS_DECL_MINIMAL] = 1;
347 tree_contains_struct[IMPORTED_DECL][TS_DECL_COMMON] = 1;
348
349 lang_hooks.init_ts ();
350 }
351
352
353 /* The name of the object as the assembler will see it (but before any
354 translations made by ASM_OUTPUT_LABELREF). Often this is the same
355 as DECL_NAME. It is an IDENTIFIER_NODE. */
356 tree
357 decl_assembler_name (tree decl)
358 {
359 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
360 lang_hooks.set_decl_assembler_name (decl);
361 return DECL_WITH_VIS_CHECK (decl)->decl_with_vis.assembler_name;
362 }
363
364 /* Compare ASMNAME with the DECL_ASSEMBLER_NAME of DECL. */
365
366 bool
367 decl_assembler_name_equal (tree decl, const_tree asmname)
368 {
369 tree decl_asmname = DECL_ASSEMBLER_NAME (decl);
370 const char *decl_str;
371 const char *asmname_str;
372 bool test = false;
373
374 if (decl_asmname == asmname)
375 return true;
376
377 decl_str = IDENTIFIER_POINTER (decl_asmname);
378 asmname_str = IDENTIFIER_POINTER (asmname);
379
380
381 /* If the target assembler name was set by the user, things are trickier.
382 We have a leading '*' to begin with. After that, it's arguable what
383 is the correct thing to do with -fleading-underscore. Arguably, we've
384 historically been doing the wrong thing in assemble_alias by always
385 printing the leading underscore. Since we're not changing that, make
386 sure user_label_prefix follows the '*' before matching. */
387 if (decl_str[0] == '*')
388 {
389 size_t ulp_len = strlen (user_label_prefix);
390
391 decl_str ++;
392
393 if (ulp_len == 0)
394 test = true;
395 else if (strncmp (decl_str, user_label_prefix, ulp_len) == 0)
396 decl_str += ulp_len, test=true;
397 else
398 decl_str --;
399 }
400 if (asmname_str[0] == '*')
401 {
402 size_t ulp_len = strlen (user_label_prefix);
403
404 asmname_str ++;
405
406 if (ulp_len == 0)
407 test = true;
408 else if (strncmp (asmname_str, user_label_prefix, ulp_len) == 0)
409 asmname_str += ulp_len, test=true;
410 else
411 asmname_str --;
412 }
413
414 if (!test)
415 return false;
416 return strcmp (decl_str, asmname_str) == 0;
417 }
418
419 /* Hash asmnames ignoring the user specified marks. */
420
421 hashval_t
422 decl_assembler_name_hash (const_tree asmname)
423 {
424 if (IDENTIFIER_POINTER (asmname)[0] == '*')
425 {
426 const char *decl_str = IDENTIFIER_POINTER (asmname) + 1;
427 size_t ulp_len = strlen (user_label_prefix);
428
429 if (ulp_len == 0)
430 ;
431 else if (strncmp (decl_str, user_label_prefix, ulp_len) == 0)
432 decl_str += ulp_len;
433
434 return htab_hash_string (decl_str);
435 }
436
437 return htab_hash_string (IDENTIFIER_POINTER (asmname));
438 }
439
440 /* Compute the number of bytes occupied by a tree with code CODE.
441 This function cannot be used for nodes that have variable sizes,
442 including TREE_VEC, STRING_CST, and CALL_EXPR. */
443 size_t
444 tree_code_size (enum tree_code code)
445 { 274 {
446 switch (TREE_CODE_CLASS (code)) 275 switch (TREE_CODE_CLASS (code))
447 { 276 {
448 case tcc_declaration: /* A decl node */
449 {
450 switch (code)
451 {
452 case FIELD_DECL:
453 return sizeof (struct tree_field_decl);
454 case PARM_DECL:
455 return sizeof (struct tree_parm_decl);
456 case VAR_DECL:
457 return sizeof (struct tree_var_decl);
458 case LABEL_DECL:
459 return sizeof (struct tree_label_decl);
460 case RESULT_DECL:
461 return sizeof (struct tree_result_decl);
462 case CONST_DECL:
463 return sizeof (struct tree_const_decl);
464 case TYPE_DECL:
465 return sizeof (struct tree_type_decl);
466 case FUNCTION_DECL:
467 return sizeof (struct tree_function_decl);
468 case NAME_MEMORY_TAG:
469 case SYMBOL_MEMORY_TAG:
470 return sizeof (struct tree_memory_tag);
471 case MEMORY_PARTITION_TAG:
472 return sizeof (struct tree_memory_partition_tag);
473 default:
474 return sizeof (struct tree_decl_non_common);
475 }
476 }
477
478 case tcc_type: /* a type node */
479 return sizeof (struct tree_type);
480
481 case tcc_reference: /* a reference */
482 case tcc_expression: /* an expression */
483 case tcc_statement: /* an expression with side effects */
484 case tcc_comparison: /* a comparison expression */
485 case tcc_unary: /* a unary arithmetic expression */
486 case tcc_binary: /* a binary arithmetic expression */
487 return (sizeof (struct tree_exp)
488 + (TREE_CODE_LENGTH (code) - 1) * sizeof (tree));
489
490 case tcc_constant: /* a constant */
491 switch (code)
492 {
493 case INTEGER_CST: return sizeof (struct tree_int_cst);
494 case REAL_CST: return sizeof (struct tree_real_cst);
495 case FIXED_CST: return sizeof (struct tree_fixed_cst);
496 case COMPLEX_CST: return sizeof (struct tree_complex);
497 case VECTOR_CST: return sizeof (struct tree_vector);
498 case STRING_CST: gcc_unreachable ();
499 default:
500 return lang_hooks.tree_size (code);
501 }
502
503 case tcc_exceptional: /* something random, like an identifier. */
504 switch (code)
505 {
506 case IDENTIFIER_NODE: return lang_hooks.identifier_size;
507 case TREE_LIST: return sizeof (struct tree_list);
508
509 case ERROR_MARK:
510 case PLACEHOLDER_EXPR: return sizeof (struct tree_common);
511
512 case TREE_VEC:
513 case OMP_CLAUSE: gcc_unreachable ();
514
515 case SSA_NAME: return sizeof (struct tree_ssa_name);
516
517 case STATEMENT_LIST: return sizeof (struct tree_statement_list);
518 case BLOCK: return sizeof (struct tree_block);
519 case CONSTRUCTOR: return sizeof (struct tree_constructor);
520 case OPTIMIZATION_NODE: return sizeof (struct tree_optimization_option);
521 case TARGET_OPTION_NODE: return sizeof (struct tree_target_option);
522
523 default:
524 return lang_hooks.tree_size (code);
525 }
526
527 default:
528 gcc_unreachable ();
529 }
530 }
531
532 /* Compute the number of bytes occupied by NODE. This routine only
533 looks at TREE_CODE, except for those nodes that have variable sizes. */
534 size_t
535 tree_size (const_tree node)
536 {
537 const enum tree_code code = TREE_CODE (node);
538 switch (code)
539 {
540 case TREE_BINFO:
541 return (offsetof (struct tree_binfo, base_binfos)
542 + VEC_embedded_size (tree, BINFO_N_BASE_BINFOS (node)));
543
544 case TREE_VEC:
545 return (sizeof (struct tree_vec)
546 + (TREE_VEC_LENGTH (node) - 1) * sizeof (tree));
547
548 case STRING_CST:
549 return TREE_STRING_LENGTH (node) + offsetof (struct tree_string, str) + 1;
550
551 case OMP_CLAUSE:
552 return (sizeof (struct tree_omp_clause)
553 + (omp_clause_num_ops[OMP_CLAUSE_CODE (node)] - 1)
554 * sizeof (tree));
555
556 default:
557 if (TREE_CODE_CLASS (code) == tcc_vl_exp)
558 return (sizeof (struct tree_exp)
559 + (VL_EXP_OPERAND_LENGTH (node) - 1) * sizeof (tree));
560 else
561 return tree_code_size (code);
562 }
563 }
564
565 /* Return a newly allocated node of code CODE. For decl and type
566 nodes, some other fields are initialized. The rest of the node is
567 initialized to zero. This function cannot be used for TREE_VEC or
568 OMP_CLAUSE nodes, which is enforced by asserts in tree_code_size.
569
570 Achoo! I got a code in the node. */
571
572 tree
573 make_node_stat (enum tree_code code MEM_STAT_DECL)
574 {
575 tree t;
576 enum tree_code_class type = TREE_CODE_CLASS (code);
577 size_t length = tree_code_size (code);
578 #ifdef GATHER_STATISTICS
579 tree_node_kind kind;
580
581 switch (type)
582 {
583 case tcc_declaration: /* A decl node */
584 kind = d_kind;
585 break;
586
587 case tcc_type: /* a type node */
588 kind = t_kind;
589 break;
590
591 case tcc_statement: /* an expression with side effects */
592 kind = s_kind;
593 break;
594
595 case tcc_reference: /* a reference */
596 kind = r_kind;
597 break;
598
599 case tcc_expression: /* an expression */
600 case tcc_comparison: /* a comparison expression */
601 case tcc_unary: /* a unary arithmetic expression */
602 case tcc_binary: /* a binary arithmetic expression */
603 kind = e_kind;
604 break;
605
606 case tcc_constant: /* a constant */
607 kind = c_kind;
608 break;
609
610 case tcc_exceptional: /* something random, like an identifier. */
611 switch (code)
612 {
613 case IDENTIFIER_NODE:
614 kind = id_kind;
615 break;
616
617 case TREE_VEC:
618 kind = vec_kind;
619 break;
620
621 case TREE_BINFO:
622 kind = binfo_kind;
623 break;
624
625 case SSA_NAME:
626 kind = ssa_name_kind;
627 break;
628
629 case BLOCK:
630 kind = b_kind;
631 break;
632
633 case CONSTRUCTOR:
634 kind = constr_kind;
635 break;
636
637 default:
638 kind = x_kind;
639 break;
640 }
641 break;
642
643 default:
644 gcc_unreachable ();
645 }
646
647 tree_node_counts[(int) kind]++;
648 tree_node_sizes[(int) kind] += length;
649 #endif
650
651 if (code == IDENTIFIER_NODE)
652 t = (tree) ggc_alloc_zone_pass_stat (length, &tree_id_zone);
653 else
654 t = (tree) ggc_alloc_zone_pass_stat (length, &tree_zone);
655
656 memset (t, 0, length);
657
658 TREE_SET_CODE (t, code);
659
660 switch (type)
661 {
662 case tcc_statement:
663 TREE_SIDE_EFFECTS (t) = 1;
664 break;
665
666 case tcc_declaration:
667 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
668 {
669 if (code == FUNCTION_DECL)
670 {
671 DECL_ALIGN (t) = FUNCTION_BOUNDARY;
672 DECL_MODE (t) = FUNCTION_MODE;
673 }
674 else
675 DECL_ALIGN (t) = 1;
676 /* We have not yet computed the alias set for this declaration. */
677 DECL_POINTER_ALIAS_SET (t) = -1;
678 }
679 DECL_SOURCE_LOCATION (t) = input_location;
680 DECL_UID (t) = next_decl_uid++;
681
682 break;
683
684 case tcc_type:
685 TYPE_UID (t) = next_type_uid++;
686 TYPE_ALIGN (t) = BITS_PER_UNIT;
687 TYPE_USER_ALIGN (t) = 0;
688 TYPE_MAIN_VARIANT (t) = t;
689 TYPE_CANONICAL (t) = t;
690
691 /* Default to no attributes for type, but let target change that. */
692 TYPE_ATTRIBUTES (t) = NULL_TREE;
693 targetm.set_default_type_attributes (t);
694
695 /* We have not yet computed the alias set for this type. */
696 TYPE_ALIAS_SET (t) = -1;
697 break;
698
699 case tcc_constant:
700 TREE_CONSTANT (t) = 1;
701 break;
702
703 case tcc_expression:
704 switch (code)
705 {
706 case INIT_EXPR:
707 case MODIFY_EXPR:
708 case VA_ARG_EXPR:
709 case PREDECREMENT_EXPR:
710 case PREINCREMENT_EXPR:
711 case POSTDECREMENT_EXPR:
712 case POSTINCREMENT_EXPR:
713 /* All of these have side-effects, no matter what their
714 operands are. */
715 TREE_SIDE_EFFECTS (t) = 1;
716 break;
717
718 default:
719 break;
720 }
721 break;
722
723 default:
724 /* Other classes need no special treatment. */
725 break;
726 }
727
728 return t;
729 }
730
731 /* Return a new node with the same contents as NODE except that its
732 TREE_CHAIN is zero and it has a fresh uid. */
733
734 tree
735 copy_node_stat (tree node MEM_STAT_DECL)
736 {
737 tree t;
738 enum tree_code code = TREE_CODE (node);
739 size_t length;
740
741 gcc_assert (code != STATEMENT_LIST);
742
743 length = tree_size (node);
744 t = (tree) ggc_alloc_zone_pass_stat (length, &tree_zone);
745 memcpy (t, node, length);
746
747 TREE_CHAIN (t) = 0;
748 TREE_ASM_WRITTEN (t) = 0;
749 TREE_VISITED (t) = 0;
750 t->base.ann = 0;
751
752 if (TREE_CODE_CLASS (code) == tcc_declaration)
753 {
754 DECL_UID (t) = next_decl_uid++;
755 if ((TREE_CODE (node) == PARM_DECL || TREE_CODE (node) == VAR_DECL)
756 && DECL_HAS_VALUE_EXPR_P (node))
757 {
758 SET_DECL_VALUE_EXPR (t, DECL_VALUE_EXPR (node));
759 DECL_HAS_VALUE_EXPR_P (t) = 1;
760 }
761 if (TREE_CODE (node) == VAR_DECL && DECL_HAS_INIT_PRIORITY_P (node))
762 {
763 SET_DECL_INIT_PRIORITY (t, DECL_INIT_PRIORITY (node));
764 DECL_HAS_INIT_PRIORITY_P (t) = 1;
765 }
766 if (TREE_CODE (node) == VAR_DECL && DECL_BASED_ON_RESTRICT_P (node))
767 {
768 SET_DECL_RESTRICT_BASE (t, DECL_GET_RESTRICT_BASE (node));
769 DECL_BASED_ON_RESTRICT_P (t) = 1;
770 }
771 }
772 else if (TREE_CODE_CLASS (code) == tcc_type)
773 {
774 TYPE_UID (t) = next_type_uid++;
775 /* The following is so that the debug code for
776 the copy is different from the original type.
777 The two statements usually duplicate each other
778 (because they clear fields of the same union),
779 but the optimizer should catch that. */
780 TYPE_SYMTAB_POINTER (t) = 0;
781 TYPE_SYMTAB_ADDRESS (t) = 0;
782
783 /* Do not copy the values cache. */
784 if (TYPE_CACHED_VALUES_P(t))
785 {
786 TYPE_CACHED_VALUES_P (t) = 0;
787 TYPE_CACHED_VALUES (t) = NULL_TREE;
788 }
789 }
790
791 return t;
792 }
793
794 /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
795 For example, this can copy a list made of TREE_LIST nodes. */
796
797 tree
798 copy_list (tree list)
799 {
800 tree head;
801 tree prev, next;
802
803 if (list == 0)
804 return 0;
805
806 head = prev = copy_node (list);
807 next = TREE_CHAIN (list);
808 while (next)
809 {
810 TREE_CHAIN (prev) = copy_node (next);
811 prev = TREE_CHAIN (prev);
812 next = TREE_CHAIN (next);
813 }
814 return head;
815 }
816
817
818 /* Create an INT_CST node with a LOW value sign extended. */
819
820 tree
821 build_int_cst (tree type, HOST_WIDE_INT low)
822 {
823 /* Support legacy code. */
824 if (!type)
825 type = integer_type_node;
826
827 return build_int_cst_wide (type, low, low < 0 ? -1 : 0);
828 }
829
830 /* Create an INT_CST node with a LOW value zero extended. */
831
832 tree
833 build_int_cstu (tree type, unsigned HOST_WIDE_INT low)
834 {
835 return build_int_cst_wide (type, low, 0);
836 }
837
838 /* Create an INT_CST node with a LOW value in TYPE. The value is sign extended
839 if it is negative. This function is similar to build_int_cst, but
840 the extra bits outside of the type precision are cleared. Constants
841 with these extra bits may confuse the fold so that it detects overflows
842 even in cases when they do not occur, and in general should be avoided.
843 We cannot however make this a default behavior of build_int_cst without
844 more intrusive changes, since there are parts of gcc that rely on the extra
845 precision of the integer constants. */
846
847 tree
848 build_int_cst_type (tree type, HOST_WIDE_INT low)
849 {
850 unsigned HOST_WIDE_INT low1;
851 HOST_WIDE_INT hi;
852
853 gcc_assert (type);
854
855 fit_double_type (low, low < 0 ? -1 : 0, &low1, &hi, type);
856
857 return build_int_cst_wide (type, low1, hi);
858 }
859
860 /* Create an INT_CST node of TYPE and value HI:LOW. The value is truncated
861 and sign extended according to the value range of TYPE. */
862
863 tree
864 build_int_cst_wide_type (tree type,
865 unsigned HOST_WIDE_INT low, HOST_WIDE_INT high)
866 {
867 fit_double_type (low, high, &low, &high, type);
868 return build_int_cst_wide (type, low, high);
869 }
870
871 /* These are the hash table functions for the hash table of INTEGER_CST
872 nodes of a sizetype. */
873
874 /* Return the hash code code X, an INTEGER_CST. */
875
876 static hashval_t
877 int_cst_hash_hash (const void *x)
878 {
879 const_tree const t = (const_tree) x;
880
881 return (TREE_INT_CST_HIGH (t) ^ TREE_INT_CST_LOW (t)
882 ^ htab_hash_pointer (TREE_TYPE (t)));
883 }
884
885 /* Return nonzero if the value represented by *X (an INTEGER_CST tree node)
886 is the same as that given by *Y, which is the same. */
887
888 static int
889 int_cst_hash_eq (const void *x, const void *y)
890 {
891 const_tree const xt = (const_tree) x;
892 const_tree const yt = (const_tree) y;
893
894 return (TREE_TYPE (xt) == TREE_TYPE (yt)
895 && TREE_INT_CST_HIGH (xt) == TREE_INT_CST_HIGH (yt)
896 && TREE_INT_CST_LOW (xt) == TREE_INT_CST_LOW (yt));
897 }
898
899 /* Create an INT_CST node of TYPE and value HI:LOW.
900 The returned node is always shared. For small integers we use a
901 per-type vector cache, for larger ones we use a single hash table. */
902
903 tree
904 build_int_cst_wide (tree type, unsigned HOST_WIDE_INT low, HOST_WIDE_INT hi)
905 {
906 tree t;
907 int ix = -1;
908 int limit = 0;
909
910 gcc_assert (type);
911
912 switch (TREE_CODE (type))
913 {
914 case POINTER_TYPE:
915 case REFERENCE_TYPE:
916 /* Cache NULL pointer. */
917 if (!hi && !low)
918 {
919 limit = 1;
920 ix = 0;
921 }
922 break;
923
924 case BOOLEAN_TYPE:
925 /* Cache false or true. */
926 limit = 2;
927 if (!hi && low < 2)
928 ix = low;
929 break;
930
931 case INTEGER_TYPE:
932 case OFFSET_TYPE:
933 if (TYPE_UNSIGNED (type))
934 {
935 /* Cache 0..N */
936 limit = INTEGER_SHARE_LIMIT;
937 if (!hi && low < (unsigned HOST_WIDE_INT)INTEGER_SHARE_LIMIT)
938 ix = low;
939 }
940 else
941 {
942 /* Cache -1..N */
943 limit = INTEGER_SHARE_LIMIT + 1;
944 if (!hi && low < (unsigned HOST_WIDE_INT)INTEGER_SHARE_LIMIT)
945 ix = low + 1;
946 else if (hi == -1 && low == -(unsigned HOST_WIDE_INT)1)
947 ix = 0;
948 }
949 break;
950
951 case ENUMERAL_TYPE:
952 break;
953
954 default:
955 gcc_unreachable ();
956 }
957
958 if (ix >= 0)
959 {
960 /* Look for it in the type's vector of small shared ints. */
961 if (!TYPE_CACHED_VALUES_P (type))
962 {
963 TYPE_CACHED_VALUES_P (type) = 1;
964 TYPE_CACHED_VALUES (type) = make_tree_vec (limit);
965 }
966
967 t = TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix);
968 if (t)
969 {
970 /* Make sure no one is clobbering the shared constant. */
971 gcc_assert (TREE_TYPE (t) == type);
972 gcc_assert (TREE_INT_CST_LOW (t) == low);
973 gcc_assert (TREE_INT_CST_HIGH (t) == hi);
974 }
975 else
976 {
977 /* Create a new shared int. */
978 t = make_node (INTEGER_CST);
979
980 TREE_INT_CST_LOW (t) = low;
981 TREE_INT_CST_HIGH (t) = hi;
982 TREE_TYPE (t) = type;
983
984 TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix) = t;
985 }
986 }
987 else
988 {
989 /* Use the cache of larger shared ints. */
990 void **slot;
991
992 TREE_INT_CST_LOW (int_cst_node) = low;
993 TREE_INT_CST_HIGH (int_cst_node) = hi;
994 TREE_TYPE (int_cst_node) = type;
995
996 slot = htab_find_slot (int_cst_hash_table, int_cst_node, INSERT);
997 t = (tree) *slot;
998 if (!t)
999 {
1000 /* Insert this one into the hash table. */
1001 t = int_cst_node;
1002 *slot = t;
1003 /* Make a new node for next time round. */
1004 int_cst_node = make_node (INTEGER_CST);
1005 }
1006 }
1007
1008 return t;
1009 }
1010
1011 /* Builds an integer constant in TYPE such that lowest BITS bits are ones
1012 and the rest are zeros. */
1013
1014 tree
1015 build_low_bits_mask (tree type, unsigned bits)
1016 {
1017 unsigned HOST_WIDE_INT low;
1018 HOST_WIDE_INT high;
1019 unsigned HOST_WIDE_INT all_ones = ~(unsigned HOST_WIDE_INT) 0;
1020
1021 gcc_assert (bits <= TYPE_PRECISION (type));
1022
1023 if (bits == TYPE_PRECISION (type)
1024 && !TYPE_UNSIGNED (type))
1025 {
1026 /* Sign extended all-ones mask. */
1027 low = all_ones;
1028 high = -1;
1029 }
1030 else if (bits <= HOST_BITS_PER_WIDE_INT)
1031 {
1032 low = all_ones >> (HOST_BITS_PER_WIDE_INT - bits);
1033 high = 0;
1034 }
1035 else
1036 {
1037 bits -= HOST_BITS_PER_WIDE_INT;
1038 low = all_ones;
1039 high = all_ones >> (HOST_BITS_PER_WIDE_INT - bits);
1040 }
1041
1042 return build_int_cst_wide (type, low, high);
1043 }
1044
1045 /* Checks that X is integer constant that can be expressed in (unsigned)
1046 HOST_WIDE_INT without loss of precision. */
1047
1048 bool
1049 cst_and_fits_in_hwi (const_tree x)
1050 {
1051 if (TREE_CODE (x) != INTEGER_CST)
1052 return false;
1053
1054 if (TYPE_PRECISION (TREE_TYPE (x)) > HOST_BITS_PER_WIDE_INT)
1055 return false;
1056
1057 return (TREE_INT_CST_HIGH (x) == 0
1058 || TREE_INT_CST_HIGH (x) == -1);
1059 }
1060
1061 /* Return a new VECTOR_CST node whose type is TYPE and whose values
1062 are in a list pointed to by VALS. */
1063
1064 tree
1065 build_vector (tree type, tree vals)
1066 {
1067 tree v = make_node (VECTOR_CST);
1068 int over = 0;
1069 tree link;
1070
1071 TREE_VECTOR_CST_ELTS (v) = vals;
1072 TREE_TYPE (v) = type;
1073
1074 /* Iterate through elements and check for overflow. */
1075 for (link = vals; link; link = TREE_CHAIN (link))
1076 {
1077 tree value = TREE_VALUE (link);
1078
1079 /* Don't crash if we get an address constant. */
1080 if (!CONSTANT_CLASS_P (value))
1081 continue;
1082
1083 over |= TREE_OVERFLOW (value);
1084 }
1085
1086 TREE_OVERFLOW (v) = over;
1087 return v;
1088 }
1089
1090 /* Return a new VECTOR_CST node whose type is TYPE and whose values
1091 are extracted from V, a vector of CONSTRUCTOR_ELT. */
1092
1093 tree
1094 build_vector_from_ctor (tree type, VEC(constructor_elt,gc) *v)
1095 {
1096 tree list = NULL_TREE;
1097 unsigned HOST_WIDE_INT idx;
1098 tree value;
1099
1100 FOR_EACH_CONSTRUCTOR_VALUE (v, idx, value)
1101 list = tree_cons (NULL_TREE, value, list);
1102 return build_vector (type, nreverse (list));
1103 }
1104
1105 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
1106 are in the VEC pointed to by VALS. */
1107 tree
1108 build_constructor (tree type, VEC(constructor_elt,gc) *vals)
1109 {
1110 tree c = make_node (CONSTRUCTOR);
1111 TREE_TYPE (c) = type;
1112 CONSTRUCTOR_ELTS (c) = vals;
1113 return c;
1114 }
1115
1116 /* Build a CONSTRUCTOR node made of a single initializer, with the specified
1117 INDEX and VALUE. */
1118 tree
1119 build_constructor_single (tree type, tree index, tree value)
1120 {
1121 VEC(constructor_elt,gc) *v;
1122 constructor_elt *elt;
1123 tree t;
1124
1125 v = VEC_alloc (constructor_elt, gc, 1);
1126 elt = VEC_quick_push (constructor_elt, v, NULL);
1127 elt->index = index;
1128 elt->value = value;
1129
1130 t = build_constructor (type, v);
1131 TREE_CONSTANT (t) = TREE_CONSTANT (value);
1132 return t;
1133 }
1134
1135
1136 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
1137 are in a list pointed to by VALS. */
1138 tree
1139 build_constructor_from_list (tree type, tree vals)
1140 {
1141 tree t, val;
1142 VEC(constructor_elt,gc) *v = NULL;
1143 bool constant_p = true;
1144
1145 if (vals)
1146 {
1147 v = VEC_alloc (constructor_elt, gc, list_length (vals));
1148 for (t = vals; t; t = TREE_CHAIN (t))
1149 {
1150 constructor_elt *elt = VEC_quick_push (constructor_elt, v, NULL);
1151 val = TREE_VALUE (t);
1152 elt->index = TREE_PURPOSE (t);
1153 elt->value = val;
1154 if (!TREE_CONSTANT (val))
1155 constant_p = false;
1156 }
1157 }
1158
1159 t = build_constructor (type, v);
1160 TREE_CONSTANT (t) = constant_p;
1161 return t;
1162 }
1163
1164 /* Return a new FIXED_CST node whose type is TYPE and value is F. */
1165
1166 tree
1167 build_fixed (tree type, FIXED_VALUE_TYPE f)
1168 {
1169 tree v;
1170 FIXED_VALUE_TYPE *fp;
1171
1172 v = make_node (FIXED_CST);
1173 fp = GGC_NEW (FIXED_VALUE_TYPE);
1174 memcpy (fp, &f, sizeof (FIXED_VALUE_TYPE));
1175
1176 TREE_TYPE (v) = type;
1177 TREE_FIXED_CST_PTR (v) = fp;
1178 return v;
1179 }
1180
1181 /* Return a new REAL_CST node whose type is TYPE and value is D. */
1182
1183 tree
1184 build_real (tree type, REAL_VALUE_TYPE d)
1185 {
1186 tree v;
1187 REAL_VALUE_TYPE *dp;
1188 int overflow = 0;
1189
1190 /* ??? Used to check for overflow here via CHECK_FLOAT_TYPE.
1191 Consider doing it via real_convert now. */
1192
1193 v = make_node (REAL_CST);
1194 dp = GGC_NEW (REAL_VALUE_TYPE);
1195 memcpy (dp, &d, sizeof (REAL_VALUE_TYPE));
1196
1197 TREE_TYPE (v) = type;
1198 TREE_REAL_CST_PTR (v) = dp;
1199 TREE_OVERFLOW (v) = overflow;
1200 return v;
1201 }
1202
1203 /* Return a new REAL_CST node whose type is TYPE
1204 and whose value is the integer value of the INTEGER_CST node I. */
1205
1206 REAL_VALUE_TYPE
1207 real_value_from_int_cst (const_tree type, const_tree i)
1208 {
1209 REAL_VALUE_TYPE d;
1210
1211 /* Clear all bits of the real value type so that we can later do
1212 bitwise comparisons to see if two values are the same. */
1213 memset (&d, 0, sizeof d);
1214
1215 real_from_integer (&d, type ? TYPE_MODE (type) : VOIDmode,
1216 TREE_INT_CST_LOW (i), TREE_INT_CST_HIGH (i),
1217 TYPE_UNSIGNED (TREE_TYPE (i)));
1218 return d;
1219 }
1220
1221 /* Given a tree representing an integer constant I, return a tree
1222 representing the same value as a floating-point constant of type TYPE. */
1223
1224 tree
1225 build_real_from_int_cst (tree type, const_tree i)
1226 {
1227 tree v;
1228 int overflow = TREE_OVERFLOW (i);
1229
1230 v = build_real (type, real_value_from_int_cst (type, i));
1231
1232 TREE_OVERFLOW (v) |= overflow;
1233 return v;
1234 }
1235
1236 /* Return a newly constructed STRING_CST node whose value is
1237 the LEN characters at STR.
1238 The TREE_TYPE is not initialized. */
1239
1240 tree
1241 build_string (int len, const char *str)
1242 {
1243 tree s;
1244 size_t length;
1245
1246 /* Do not waste bytes provided by padding of struct tree_string. */
1247 length = len + offsetof (struct tree_string, str) + 1;
1248
1249 #ifdef GATHER_STATISTICS
1250 tree_node_counts[(int) c_kind]++;
1251 tree_node_sizes[(int) c_kind] += length;
1252 #endif
1253
1254 s = ggc_alloc_tree (length);
1255
1256 memset (s, 0, sizeof (struct tree_common));
1257 TREE_SET_CODE (s, STRING_CST);
1258 TREE_CONSTANT (s) = 1;
1259 TREE_STRING_LENGTH (s) = len;
1260 memcpy (s->string.str, str, len);
1261 s->string.str[len] = '\0';
1262
1263 return s;
1264 }
1265
1266 /* Return a newly constructed COMPLEX_CST node whose value is
1267 specified by the real and imaginary parts REAL and IMAG.
1268 Both REAL and IMAG should be constant nodes. TYPE, if specified,
1269 will be the type of the COMPLEX_CST; otherwise a new type will be made. */
1270
1271 tree
1272 build_complex (tree type, tree real, tree imag)
1273 {
1274 tree t = make_node (COMPLEX_CST);
1275
1276 TREE_REALPART (t) = real;
1277 TREE_IMAGPART (t) = imag;
1278 TREE_TYPE (t) = type ? type : build_complex_type (TREE_TYPE (real));
1279 TREE_OVERFLOW (t) = TREE_OVERFLOW (real) | TREE_OVERFLOW (imag);
1280 return t;
1281 }
1282
1283 /* Return a constant of arithmetic type TYPE which is the
1284 multiplicative identity of the set TYPE. */
1285
1286 tree
1287 build_one_cst (tree type)
1288 {
1289 switch (TREE_CODE (type))
1290 {
1291 case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
1292 case POINTER_TYPE: case REFERENCE_TYPE:
1293 case OFFSET_TYPE:
1294 return build_int_cst (type, 1);
1295
1296 case REAL_TYPE:
1297 return build_real (type, dconst1);
1298
1299 case FIXED_POINT_TYPE:
1300 /* We can only generate 1 for accum types. */
1301 gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type)));
1302 return build_fixed (type, FCONST1(TYPE_MODE (type)));
1303
1304 case VECTOR_TYPE:
1305 {
1306 tree scalar, cst;
1307 int i;
1308
1309 scalar = build_one_cst (TREE_TYPE (type));
1310
1311 /* Create 'vect_cst_ = {cst,cst,...,cst}' */
1312 cst = NULL_TREE;
1313 for (i = TYPE_VECTOR_SUBPARTS (type); --i >= 0; )
1314 cst = tree_cons (NULL_TREE, scalar, cst);
1315
1316 return build_vector (type, cst);
1317 }
1318
1319 case COMPLEX_TYPE:
1320 return build_complex (type,
1321 build_one_cst (TREE_TYPE (type)),
1322 fold_convert (TREE_TYPE (type), integer_zero_node));
1323
1324 default:
1325 gcc_unreachable ();
1326 }
1327 }
1328
1329 /* Build a BINFO with LEN language slots. */
1330
1331 tree
1332 make_tree_binfo_stat (unsigned base_binfos MEM_STAT_DECL)
1333 {
1334 tree t;
1335 size_t length = (offsetof (struct tree_binfo, base_binfos)
1336 + VEC_embedded_size (tree, base_binfos));
1337
1338 #ifdef GATHER_STATISTICS
1339 tree_node_counts[(int) binfo_kind]++;
1340 tree_node_sizes[(int) binfo_kind] += length;
1341 #endif
1342
1343 t = (tree) ggc_alloc_zone_pass_stat (length, &tree_zone);
1344
1345 memset (t, 0, offsetof (struct tree_binfo, base_binfos));
1346
1347 TREE_SET_CODE (t, TREE_BINFO);
1348
1349 VEC_embedded_init (tree, BINFO_BASE_BINFOS (t), base_binfos);
1350
1351 return t;
1352 }
1353
1354
1355 /* Build a newly constructed TREE_VEC node of length LEN. */
1356
1357 tree
1358 make_tree_vec_stat (int len MEM_STAT_DECL)
1359 {
1360 tree t;
1361 int length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
1362
1363 #ifdef GATHER_STATISTICS
1364 tree_node_counts[(int) vec_kind]++;
1365 tree_node_sizes[(int) vec_kind] += length;
1366 #endif
1367
1368 t = (tree) ggc_alloc_zone_pass_stat (length, &tree_zone);
1369
1370 memset (t, 0, length);
1371
1372 TREE_SET_CODE (t, TREE_VEC);
1373 TREE_VEC_LENGTH (t) = len;
1374
1375 return t;
1376 }
1377
1378 /* Return 1 if EXPR is the integer constant zero or a complex constant
1379 of zero. */
1380
1381 int
1382 integer_zerop (const_tree expr)
1383 {
1384 STRIP_NOPS (expr);
1385
1386 return ((TREE_CODE (expr) == INTEGER_CST
1387 && TREE_INT_CST_LOW (expr) == 0
1388 && TREE_INT_CST_HIGH (expr) == 0)
1389 || (TREE_CODE (expr) == COMPLEX_CST
1390 && integer_zerop (TREE_REALPART (expr))
1391 && integer_zerop (TREE_IMAGPART (expr))));
1392 }
1393
1394 /* Return 1 if EXPR is the integer constant one or the corresponding
1395 complex constant. */
1396
1397 int
1398 integer_onep (const_tree expr)
1399 {
1400 STRIP_NOPS (expr);
1401
1402 return ((TREE_CODE (expr) == INTEGER_CST
1403 && TREE_INT_CST_LOW (expr) == 1
1404 && TREE_INT_CST_HIGH (expr) == 0)
1405 || (TREE_CODE (expr) == COMPLEX_CST
1406 && integer_onep (TREE_REALPART (expr))
1407 && integer_zerop (TREE_IMAGPART (expr))));
1408 }
1409
1410 /* Return 1 if EXPR is an integer containing all 1's in as much precision as
1411 it contains. Likewise for the corresponding complex constant. */
1412
1413 int
1414 integer_all_onesp (const_tree expr)
1415 {
1416 int prec;
1417 int uns;
1418
1419 STRIP_NOPS (expr);
1420
1421 if (TREE_CODE (expr) == COMPLEX_CST
1422 && integer_all_onesp (TREE_REALPART (expr))
1423 && integer_zerop (TREE_IMAGPART (expr)))
1424 return 1;
1425
1426 else if (TREE_CODE (expr) != INTEGER_CST)
1427 return 0;
1428
1429 uns = TYPE_UNSIGNED (TREE_TYPE (expr));
1430 if (TREE_INT_CST_LOW (expr) == ~(unsigned HOST_WIDE_INT) 0
1431 && TREE_INT_CST_HIGH (expr) == -1)
1432 return 1;
1433 if (!uns)
1434 return 0;
1435
1436 /* Note that using TYPE_PRECISION here is wrong. We care about the
1437 actual bits, not the (arbitrary) range of the type. */
1438 prec = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (expr)));
1439 if (prec >= HOST_BITS_PER_WIDE_INT)
1440 {
1441 HOST_WIDE_INT high_value;
1442 int shift_amount;
1443
1444 shift_amount = prec - HOST_BITS_PER_WIDE_INT;
1445
1446 /* Can not handle precisions greater than twice the host int size. */
1447 gcc_assert (shift_amount <= HOST_BITS_PER_WIDE_INT);
1448 if (shift_amount == HOST_BITS_PER_WIDE_INT)
1449 /* Shifting by the host word size is undefined according to the ANSI
1450 standard, so we must handle this as a special case. */
1451 high_value = -1;
1452 else
1453 high_value = ((HOST_WIDE_INT) 1 << shift_amount) - 1;
1454
1455 return (TREE_INT_CST_LOW (expr) == ~(unsigned HOST_WIDE_INT) 0
1456 && TREE_INT_CST_HIGH (expr) == high_value);
1457 }
1458 else
1459 return TREE_INT_CST_LOW (expr) == ((unsigned HOST_WIDE_INT) 1 << prec) - 1;
1460 }
1461
1462 /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only
1463 one bit on). */
1464
1465 int
1466 integer_pow2p (const_tree expr)
1467 {
1468 int prec;
1469 HOST_WIDE_INT high, low;
1470
1471 STRIP_NOPS (expr);
1472
1473 if (TREE_CODE (expr) == COMPLEX_CST
1474 && integer_pow2p (TREE_REALPART (expr))
1475 && integer_zerop (TREE_IMAGPART (expr)))
1476 return 1;
1477
1478 if (TREE_CODE (expr) != INTEGER_CST)
1479 return 0;
1480
1481 prec = (POINTER_TYPE_P (TREE_TYPE (expr))
1482 ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr)));
1483 high = TREE_INT_CST_HIGH (expr);
1484 low = TREE_INT_CST_LOW (expr);
1485
1486 /* First clear all bits that are beyond the type's precision in case
1487 we've been sign extended. */
1488
1489 if (prec == 2 * HOST_BITS_PER_WIDE_INT)
1490 ;
1491 else if (prec > HOST_BITS_PER_WIDE_INT)
1492 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
1493 else
1494 {
1495 high = 0;
1496 if (prec < HOST_BITS_PER_WIDE_INT)
1497 low &= ~((HOST_WIDE_INT) (-1) << prec);
1498 }
1499
1500 if (high == 0 && low == 0)
1501 return 0;
1502
1503 return ((high == 0 && (low & (low - 1)) == 0)
1504 || (low == 0 && (high & (high - 1)) == 0));
1505 }
1506
1507 /* Return 1 if EXPR is an integer constant other than zero or a
1508 complex constant other than zero. */
1509
1510 int
1511 integer_nonzerop (const_tree expr)
1512 {
1513 STRIP_NOPS (expr);
1514
1515 return ((TREE_CODE (expr) == INTEGER_CST
1516 && (TREE_INT_CST_LOW (expr) != 0
1517 || TREE_INT_CST_HIGH (expr) != 0))
1518 || (TREE_CODE (expr) == COMPLEX_CST
1519 && (integer_nonzerop (TREE_REALPART (expr))
1520 || integer_nonzerop (TREE_IMAGPART (expr)))));
1521 }
1522
1523 /* Return 1 if EXPR is the fixed-point constant zero. */
1524
1525 int
1526 fixed_zerop (const_tree expr)
1527 {
1528 return (TREE_CODE (expr) == FIXED_CST
1529 && double_int_zero_p (TREE_FIXED_CST (expr).data));
1530 }
1531
1532 /* Return the power of two represented by a tree node known to be a
1533 power of two. */
1534
1535 int
1536 tree_log2 (const_tree expr)
1537 {
1538 int prec;
1539 HOST_WIDE_INT high, low;
1540
1541 STRIP_NOPS (expr);
1542
1543 if (TREE_CODE (expr) == COMPLEX_CST)
1544 return tree_log2 (TREE_REALPART (expr));
1545
1546 prec = (POINTER_TYPE_P (TREE_TYPE (expr))
1547 ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr)));
1548
1549 high = TREE_INT_CST_HIGH (expr);
1550 low = TREE_INT_CST_LOW (expr);
1551
1552 /* First clear all bits that are beyond the type's precision in case
1553 we've been sign extended. */
1554
1555 if (prec == 2 * HOST_BITS_PER_WIDE_INT)
1556 ;
1557 else if (prec > HOST_BITS_PER_WIDE_INT)
1558 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
1559 else
1560 {
1561 high = 0;
1562 if (prec < HOST_BITS_PER_WIDE_INT)
1563 low &= ~((HOST_WIDE_INT) (-1) << prec);
1564 }
1565
1566 return (high != 0 ? HOST_BITS_PER_WIDE_INT + exact_log2 (high)
1567 : exact_log2 (low));
1568 }
1569
1570 /* Similar, but return the largest integer Y such that 2 ** Y is less
1571 than or equal to EXPR. */
1572
1573 int
1574 tree_floor_log2 (const_tree expr)
1575 {
1576 int prec;
1577 HOST_WIDE_INT high, low;
1578
1579 STRIP_NOPS (expr);
1580
1581 if (TREE_CODE (expr) == COMPLEX_CST)
1582 return tree_log2 (TREE_REALPART (expr));
1583
1584 prec = (POINTER_TYPE_P (TREE_TYPE (expr))
1585 ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr)));
1586
1587 high = TREE_INT_CST_HIGH (expr);
1588 low = TREE_INT_CST_LOW (expr);
1589
1590 /* First clear all bits that are beyond the type's precision in case
1591 we've been sign extended. Ignore if type's precision hasn't been set
1592 since what we are doing is setting it. */
1593
1594 if (prec == 2 * HOST_BITS_PER_WIDE_INT || prec == 0)
1595 ;
1596 else if (prec > HOST_BITS_PER_WIDE_INT)
1597 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
1598 else
1599 {
1600 high = 0;
1601 if (prec < HOST_BITS_PER_WIDE_INT)
1602 low &= ~((HOST_WIDE_INT) (-1) << prec);
1603 }
1604
1605 return (high != 0 ? HOST_BITS_PER_WIDE_INT + floor_log2 (high)
1606 : floor_log2 (low));
1607 }
1608
1609 /* Return 1 if EXPR is the real constant zero. Trailing zeroes matter for
1610 decimal float constants, so don't return 1 for them. */
1611
1612 int
1613 real_zerop (const_tree expr)
1614 {
1615 STRIP_NOPS (expr);
1616
1617 return ((TREE_CODE (expr) == REAL_CST
1618 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst0)
1619 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr)))))
1620 || (TREE_CODE (expr) == COMPLEX_CST
1621 && real_zerop (TREE_REALPART (expr))
1622 && real_zerop (TREE_IMAGPART (expr))));
1623 }
1624
1625 /* Return 1 if EXPR is the real constant one in real or complex form.
1626 Trailing zeroes matter for decimal float constants, so don't return
1627 1 for them. */
1628
1629 int
1630 real_onep (const_tree expr)
1631 {
1632 STRIP_NOPS (expr);
1633
1634 return ((TREE_CODE (expr) == REAL_CST
1635 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst1)
1636 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr)))))
1637 || (TREE_CODE (expr) == COMPLEX_CST
1638 && real_onep (TREE_REALPART (expr))
1639 && real_zerop (TREE_IMAGPART (expr))));
1640 }
1641
1642 /* Return 1 if EXPR is the real constant two. Trailing zeroes matter
1643 for decimal float constants, so don't return 1 for them. */
1644
1645 int
1646 real_twop (const_tree expr)
1647 {
1648 STRIP_NOPS (expr);
1649
1650 return ((TREE_CODE (expr) == REAL_CST
1651 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst2)
1652 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr)))))
1653 || (TREE_CODE (expr) == COMPLEX_CST
1654 && real_twop (TREE_REALPART (expr))
1655 && real_zerop (TREE_IMAGPART (expr))));
1656 }
1657
1658 /* Return 1 if EXPR is the real constant minus one. Trailing zeroes
1659 matter for decimal float constants, so don't return 1 for them. */
1660
1661 int
1662 real_minus_onep (const_tree expr)
1663 {
1664 STRIP_NOPS (expr);
1665
1666 return ((TREE_CODE (expr) == REAL_CST
1667 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconstm1)
1668 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr)))))
1669 || (TREE_CODE (expr) == COMPLEX_CST
1670 && real_minus_onep (TREE_REALPART (expr))
1671 && real_zerop (TREE_IMAGPART (expr))));
1672 }
1673
1674 /* Nonzero if EXP is a constant or a cast of a constant. */
1675
1676 int
1677 really_constant_p (const_tree exp)
1678 {
1679 /* This is not quite the same as STRIP_NOPS. It does more. */
1680 while (CONVERT_EXPR_P (exp)
1681 || TREE_CODE (exp) == NON_LVALUE_EXPR)
1682 exp = TREE_OPERAND (exp, 0);
1683 return TREE_CONSTANT (exp);
1684 }
1685
1686 /* Return first list element whose TREE_VALUE is ELEM.
1687 Return 0 if ELEM is not in LIST. */
1688
1689 tree
1690 value_member (tree elem, tree list)
1691 {
1692 while (list)
1693 {
1694 if (elem == TREE_VALUE (list))
1695 return list;
1696 list = TREE_CHAIN (list);
1697 }
1698 return NULL_TREE;
1699 }
1700
1701 /* Return first list element whose TREE_PURPOSE is ELEM.
1702 Return 0 if ELEM is not in LIST. */
1703
1704 tree
1705 purpose_member (const_tree elem, tree list)
1706 {
1707 while (list)
1708 {
1709 if (elem == TREE_PURPOSE (list))
1710 return list;
1711 list = TREE_CHAIN (list);
1712 }
1713 return NULL_TREE;
1714 }
1715
1716 /* Return nonzero if ELEM is part of the chain CHAIN. */
1717
1718 int
1719 chain_member (const_tree elem, const_tree chain)
1720 {
1721 while (chain)
1722 {
1723 if (elem == chain)
1724 return 1;
1725 chain = TREE_CHAIN (chain);
1726 }
1727
1728 return 0;
1729 }
1730
1731 /* Return the length of a chain of nodes chained through TREE_CHAIN.
1732 We expect a null pointer to mark the end of the chain.
1733 This is the Lisp primitive `length'. */
1734
1735 int
1736 list_length (const_tree t)
1737 {
1738 const_tree p = t;
1739 #ifdef ENABLE_TREE_CHECKING
1740 const_tree q = t;
1741 #endif
1742 int len = 0;
1743
1744 while (p)
1745 {
1746 p = TREE_CHAIN (p);
1747 #ifdef ENABLE_TREE_CHECKING
1748 if (len % 2)
1749 q = TREE_CHAIN (q);
1750 gcc_assert (p != q);
1751 #endif
1752 len++;
1753 }
1754
1755 return len;
1756 }
1757
1758 /* Returns the number of FIELD_DECLs in TYPE. */
1759
1760 int
1761 fields_length (const_tree type)
1762 {
1763 tree t = TYPE_FIELDS (type);
1764 int count = 0;
1765
1766 for (; t; t = TREE_CHAIN (t))
1767 if (TREE_CODE (t) == FIELD_DECL)
1768 ++count;
1769
1770 return count;
1771 }
1772
1773 /* Concatenate two chains of nodes (chained through TREE_CHAIN)
1774 by modifying the last node in chain 1 to point to chain 2.
1775 This is the Lisp primitive `nconc'. */
1776
1777 tree
1778 chainon (tree op1, tree op2)
1779 {
1780 tree t1;
1781
1782 if (!op1)
1783 return op2;
1784 if (!op2)
1785 return op1;
1786
1787 for (t1 = op1; TREE_CHAIN (t1); t1 = TREE_CHAIN (t1))
1788 continue;
1789 TREE_CHAIN (t1) = op2;
1790
1791 #ifdef ENABLE_TREE_CHECKING
1792 {
1793 tree t2;
1794 for (t2 = op2; t2; t2 = TREE_CHAIN (t2))
1795 gcc_assert (t2 != t1);
1796 }
1797 #endif
1798
1799 return op1;
1800 }
1801
1802 /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
1803
1804 tree
1805 tree_last (tree chain)
1806 {
1807 tree next;
1808 if (chain)
1809 while ((next = TREE_CHAIN (chain)))
1810 chain = next;
1811 return chain;
1812 }
1813
1814 /* Reverse the order of elements in the chain T,
1815 and return the new head of the chain (old last element). */
1816
1817 tree
1818 nreverse (tree t)
1819 {
1820 tree prev = 0, decl, next;
1821 for (decl = t; decl; decl = next)
1822 {
1823 next = TREE_CHAIN (decl);
1824 TREE_CHAIN (decl) = prev;
1825 prev = decl;
1826 }
1827 return prev;
1828 }
1829
1830 /* Return a newly created TREE_LIST node whose
1831 purpose and value fields are PARM and VALUE. */
1832
1833 tree
1834 build_tree_list_stat (tree parm, tree value MEM_STAT_DECL)
1835 {
1836 tree t = make_node_stat (TREE_LIST PASS_MEM_STAT);
1837 TREE_PURPOSE (t) = parm;
1838 TREE_VALUE (t) = value;
1839 return t;
1840 }
1841
1842 /* Return a newly created TREE_LIST node whose
1843 purpose and value fields are PURPOSE and VALUE
1844 and whose TREE_CHAIN is CHAIN. */
1845
1846 tree
1847 tree_cons_stat (tree purpose, tree value, tree chain MEM_STAT_DECL)
1848 {
1849 tree node;
1850
1851 node = (tree) ggc_alloc_zone_pass_stat (sizeof (struct tree_list), &tree_zone);
1852
1853 memset (node, 0, sizeof (struct tree_common));
1854
1855 #ifdef GATHER_STATISTICS
1856 tree_node_counts[(int) x_kind]++;
1857 tree_node_sizes[(int) x_kind] += sizeof (struct tree_list);
1858 #endif
1859
1860 TREE_SET_CODE (node, TREE_LIST);
1861 TREE_CHAIN (node) = chain;
1862 TREE_PURPOSE (node) = purpose;
1863 TREE_VALUE (node) = value;
1864 return node;
1865 }
1866
1867 /* Return the elements of a CONSTRUCTOR as a TREE_LIST. */
1868
1869 tree
1870 ctor_to_list (tree ctor)
1871 {
1872 tree list = NULL_TREE;
1873 tree *p = &list;
1874 unsigned ix;
1875 tree purpose, val;
1876
1877 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), ix, purpose, val)
1878 {
1879 *p = build_tree_list (purpose, val);
1880 p = &TREE_CHAIN (*p);
1881 }
1882
1883 return list;
1884 }
1885
1886 /* Return the size nominally occupied by an object of type TYPE
1887 when it resides in memory. The value is measured in units of bytes,
1888 and its data type is that normally used for type sizes
1889 (which is the first type created by make_signed_type or
1890 make_unsigned_type). */
1891
1892 tree
1893 size_in_bytes (const_tree type)
1894 {
1895 tree t;
1896
1897 if (type == error_mark_node)
1898 return integer_zero_node;
1899
1900 type = TYPE_MAIN_VARIANT (type);
1901 t = TYPE_SIZE_UNIT (type);
1902
1903 if (t == 0)
1904 {
1905 lang_hooks.types.incomplete_type_error (NULL_TREE, type);
1906 return size_zero_node;
1907 }
1908
1909 return t;
1910 }
1911
1912 /* Return the size of TYPE (in bytes) as a wide integer
1913 or return -1 if the size can vary or is larger than an integer. */
1914
1915 HOST_WIDE_INT
1916 int_size_in_bytes (const_tree type)
1917 {
1918 tree t;
1919
1920 if (type == error_mark_node)
1921 return 0;
1922
1923 type = TYPE_MAIN_VARIANT (type);
1924 t = TYPE_SIZE_UNIT (type);
1925 if (t == 0
1926 || TREE_CODE (t) != INTEGER_CST
1927 || TREE_INT_CST_HIGH (t) != 0
1928 /* If the result would appear negative, it's too big to represent. */
1929 || (HOST_WIDE_INT) TREE_INT_CST_LOW (t) < 0)
1930 return -1;
1931
1932 return TREE_INT_CST_LOW (t);
1933 }
1934
1935 /* Return the maximum size of TYPE (in bytes) as a wide integer
1936 or return -1 if the size can vary or is larger than an integer. */
1937
1938 HOST_WIDE_INT
1939 max_int_size_in_bytes (const_tree type)
1940 {
1941 HOST_WIDE_INT size = -1;
1942 tree size_tree;
1943
1944 /* If this is an array type, check for a possible MAX_SIZE attached. */
1945
1946 if (TREE_CODE (type) == ARRAY_TYPE)
1947 {
1948 size_tree = TYPE_ARRAY_MAX_SIZE (type);
1949
1950 if (size_tree && host_integerp (size_tree, 1))
1951 size = tree_low_cst (size_tree, 1);
1952 }
1953
1954 /* If we still haven't been able to get a size, see if the language
1955 can compute a maximum size. */
1956
1957 if (size == -1)
1958 {
1959 size_tree = lang_hooks.types.max_size (type);
1960
1961 if (size_tree && host_integerp (size_tree, 1))
1962 size = tree_low_cst (size_tree, 1);
1963 }
1964
1965 return size;
1966 }
1967
1968 /* Return the bit position of FIELD, in bits from the start of the record.
1969 This is a tree of type bitsizetype. */
1970
1971 tree
1972 bit_position (const_tree field)
1973 {
1974 return bit_from_pos (DECL_FIELD_OFFSET (field),
1975 DECL_FIELD_BIT_OFFSET (field));
1976 }
1977
1978 /* Likewise, but return as an integer. It must be representable in
1979 that way (since it could be a signed value, we don't have the
1980 option of returning -1 like int_size_in_byte can. */
1981
1982 HOST_WIDE_INT
1983 int_bit_position (const_tree field)
1984 {
1985 return tree_low_cst (bit_position (field), 0);
1986 }
1987
1988 /* Return the byte position of FIELD, in bytes from the start of the record.
1989 This is a tree of type sizetype. */
1990
1991 tree
1992 byte_position (const_tree field)
1993 {
1994 return byte_from_pos (DECL_FIELD_OFFSET (field),
1995 DECL_FIELD_BIT_OFFSET (field));
1996 }
1997
1998 /* Likewise, but return as an integer. It must be representable in
1999 that way (since it could be a signed value, we don't have the
2000 option of returning -1 like int_size_in_byte can. */
2001
2002 HOST_WIDE_INT
2003 int_byte_position (const_tree field)
2004 {
2005 return tree_low_cst (byte_position (field), 0);
2006 }
2007
2008 /* Return the strictest alignment, in bits, that T is known to have. */
2009
2010 unsigned int
2011 expr_align (const_tree t)
2012 {
2013 unsigned int align0, align1;
2014
2015 switch (TREE_CODE (t))
2016 {
2017 CASE_CONVERT: case NON_LVALUE_EXPR:
2018 /* If we have conversions, we know that the alignment of the
2019 object must meet each of the alignments of the types. */
2020 align0 = expr_align (TREE_OPERAND (t, 0));
2021 align1 = TYPE_ALIGN (TREE_TYPE (t));
2022 return MAX (align0, align1);
2023
2024 case SAVE_EXPR: case COMPOUND_EXPR: case MODIFY_EXPR:
2025 case INIT_EXPR: case TARGET_EXPR: case WITH_CLEANUP_EXPR:
2026 case CLEANUP_POINT_EXPR:
2027 /* These don't change the alignment of an object. */
2028 return expr_align (TREE_OPERAND (t, 0));
2029
2030 case COND_EXPR:
2031 /* The best we can do is say that the alignment is the least aligned
2032 of the two arms. */
2033 align0 = expr_align (TREE_OPERAND (t, 1));
2034 align1 = expr_align (TREE_OPERAND (t, 2));
2035 return MIN (align0, align1);
2036
2037 /* FIXME: LABEL_DECL and CONST_DECL never have DECL_ALIGN set
2038 meaningfully, it's always 1. */
2039 case LABEL_DECL: case CONST_DECL:
2040 case VAR_DECL: case PARM_DECL: case RESULT_DECL:
2041 case FUNCTION_DECL:
2042 gcc_assert (DECL_ALIGN (t) != 0);
2043 return DECL_ALIGN (t);
2044
2045 default:
2046 break;
2047 }
2048
2049 /* Otherwise take the alignment from that of the type. */
2050 return TYPE_ALIGN (TREE_TYPE (t));
2051 }
2052
2053 /* Return, as a tree node, the number of elements for TYPE (which is an
2054 ARRAY_TYPE) minus one. This counts only elements of the top array. */
2055
2056 tree
2057 array_type_nelts (const_tree type)
2058 {
2059 tree index_type, min, max;
2060
2061 /* If they did it with unspecified bounds, then we should have already
2062 given an error about it before we got here. */
2063 if (! TYPE_DOMAIN (type))
2064 return error_mark_node;
2065
2066 index_type = TYPE_DOMAIN (type);
2067 min = TYPE_MIN_VALUE (index_type);
2068 max = TYPE_MAX_VALUE (index_type);
2069
2070 return (integer_zerop (min)
2071 ? max
2072 : fold_build2 (MINUS_EXPR, TREE_TYPE (max), max, min));
2073 }
2074
2075 /* If arg is static -- a reference to an object in static storage -- then
2076 return the object. This is not the same as the C meaning of `static'.
2077 If arg isn't static, return NULL. */
2078
2079 tree
2080 staticp (tree arg)
2081 {
2082 switch (TREE_CODE (arg))
2083 {
2084 case FUNCTION_DECL:
2085 /* Nested functions are static, even though taking their address will
2086 involve a trampoline as we unnest the nested function and create
2087 the trampoline on the tree level. */
2088 return arg;
2089
2090 case VAR_DECL:
2091 return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
2092 && ! DECL_THREAD_LOCAL_P (arg)
2093 && ! DECL_DLLIMPORT_P (arg)
2094 ? arg : NULL);
2095
2096 case CONST_DECL:
2097 return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
2098 ? arg : NULL);
2099
2100 case CONSTRUCTOR:
2101 return TREE_STATIC (arg) ? arg : NULL;
2102
2103 case LABEL_DECL:
2104 case STRING_CST:
2105 return arg;
2106
2107 case COMPONENT_REF:
2108 /* If the thing being referenced is not a field, then it is
2109 something language specific. */
2110 if (TREE_CODE (TREE_OPERAND (arg, 1)) != FIELD_DECL)
2111 return (*lang_hooks.staticp) (arg);
2112
2113 /* If we are referencing a bitfield, we can't evaluate an
2114 ADDR_EXPR at compile time and so it isn't a constant. */
2115 if (DECL_BIT_FIELD (TREE_OPERAND (arg, 1)))
2116 return NULL;
2117
2118 return staticp (TREE_OPERAND (arg, 0));
2119
2120 case BIT_FIELD_REF:
2121 return NULL;
2122
2123 case MISALIGNED_INDIRECT_REF:
2124 case ALIGN_INDIRECT_REF:
2125 case INDIRECT_REF:
2126 return TREE_CONSTANT (TREE_OPERAND (arg, 0)) ? arg : NULL;
2127
2128 case ARRAY_REF:
2129 case ARRAY_RANGE_REF:
2130 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST
2131 && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST)
2132 return staticp (TREE_OPERAND (arg, 0));
2133 else
2134 return false;
2135
2136 default:
2137 if ((unsigned int) TREE_CODE (arg)
2138 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
2139 return lang_hooks.staticp (arg);
2140 else
2141 return NULL;
2142 }
2143 }
2144
2145
2146
2147
2148 /* Return whether OP is a DECL whose address is function-invariant. */
2149
2150 bool
2151 decl_address_invariant_p (const_tree op)
2152 {
2153 /* The conditions below are slightly less strict than the one in
2154 staticp. */
2155
2156 switch (TREE_CODE (op))
2157 {
2158 case PARM_DECL:
2159 case RESULT_DECL:
2160 case LABEL_DECL:
2161 case FUNCTION_DECL:
2162 return true;
2163
2164 case VAR_DECL:
2165 if (((TREE_STATIC (op) || DECL_EXTERNAL (op))
2166 && !DECL_DLLIMPORT_P (op))
2167 || DECL_THREAD_LOCAL_P (op)
2168 || DECL_CONTEXT (op) == current_function_decl
2169 || decl_function_context (op) == current_function_decl)
2170 return true;
2171 break;
2172
2173 case CONST_DECL:
2174 if ((TREE_STATIC (op) || DECL_EXTERNAL (op))
2175 || decl_function_context (op) == current_function_decl)
2176 return true;
2177 break;
2178
2179 default:
2180 break;
2181 }
2182
2183 return false;
2184 }
2185
2186 /* Return whether OP is a DECL whose address is interprocedural-invariant. */
2187
2188 bool
2189 decl_address_ip_invariant_p (const_tree op)
2190 {
2191 /* The conditions below are slightly less strict than the one in
2192 staticp. */
2193
2194 switch (TREE_CODE (op))
2195 {
2196 case LABEL_DECL:
2197 case FUNCTION_DECL:
2198 case STRING_CST:
2199 return true;
2200
2201 case VAR_DECL:
2202 if (((TREE_STATIC (op) || DECL_EXTERNAL (op))
2203 && !DECL_DLLIMPORT_P (op))
2204 || DECL_THREAD_LOCAL_P (op))
2205 return true;
2206 break;
2207
2208 case CONST_DECL:
2209 if ((TREE_STATIC (op) || DECL_EXTERNAL (op)))
2210 return true;
2211 break;
2212
2213 default:
2214 break;
2215 }
2216
2217 return false;
2218 }
2219
2220
2221 /* Return true if T is function-invariant (internal function, does
2222 not handle arithmetic; that's handled in skip_simple_arithmetic and
2223 tree_invariant_p). */
2224
2225 static bool tree_invariant_p (tree t);
2226
2227 static bool
2228 tree_invariant_p_1 (tree t)
2229 {
2230 tree op;
2231
2232 if (TREE_CONSTANT (t)
2233 || (TREE_READONLY (t) && !TREE_SIDE_EFFECTS (t)))
2234 return true;
2235
2236 switch (TREE_CODE (t))
2237 {
2238 case SAVE_EXPR:
2239 return true;
2240
2241 case ADDR_EXPR:
2242 op = TREE_OPERAND (t, 0);
2243 while (handled_component_p (op))
2244 {
2245 switch (TREE_CODE (op))
2246 {
2247 case ARRAY_REF:
2248 case ARRAY_RANGE_REF:
2249 if (!tree_invariant_p (TREE_OPERAND (op, 1))
2250 || TREE_OPERAND (op, 2) != NULL_TREE
2251 || TREE_OPERAND (op, 3) != NULL_TREE)
2252 return false;
2253 break;
2254
2255 case COMPONENT_REF:
2256 if (TREE_OPERAND (op, 2) != NULL_TREE)
2257 return false;
2258 break;
2259
2260 default:;
2261 }
2262 op = TREE_OPERAND (op, 0);
2263 }
2264
2265 return CONSTANT_CLASS_P (op) || decl_address_invariant_p (op);
2266
2267 default:
2268 break;
2269 }
2270
2271 return false;
2272 }
2273
2274 /* Return true if T is function-invariant. */
2275
2276 static bool
2277 tree_invariant_p (tree t)
2278 {
2279 tree inner = skip_simple_arithmetic (t);
2280 return tree_invariant_p_1 (inner);
2281 }
2282
2283 /* Wrap a SAVE_EXPR around EXPR, if appropriate.
2284 Do this to any expression which may be used in more than one place,
2285 but must be evaluated only once.
2286
2287 Normally, expand_expr would reevaluate the expression each time.
2288 Calling save_expr produces something that is evaluated and recorded
2289 the first time expand_expr is called on it. Subsequent calls to
2290 expand_expr just reuse the recorded value.
2291
2292 The call to expand_expr that generates code that actually computes
2293 the value is the first call *at compile time*. Subsequent calls
2294 *at compile time* generate code to use the saved value.
2295 This produces correct result provided that *at run time* control
2296 always flows through the insns made by the first expand_expr
2297 before reaching the other places where the save_expr was evaluated.
2298 You, the caller of save_expr, must make sure this is so.
2299
2300 Constants, and certain read-only nodes, are returned with no
2301 SAVE_EXPR because that is safe. Expressions containing placeholders
2302 are not touched; see tree.def for an explanation of what these
2303 are used for. */
2304
2305 tree
2306 save_expr (tree expr)
2307 {
2308 tree t = fold (expr);
2309 tree inner;
2310
2311 /* If the tree evaluates to a constant, then we don't want to hide that
2312 fact (i.e. this allows further folding, and direct checks for constants).
2313 However, a read-only object that has side effects cannot be bypassed.
2314 Since it is no problem to reevaluate literals, we just return the
2315 literal node. */
2316 inner = skip_simple_arithmetic (t);
2317 if (TREE_CODE (inner) == ERROR_MARK)
2318 return inner;
2319
2320 if (tree_invariant_p_1 (inner))
2321 return t;
2322
2323 /* If INNER contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
2324 it means that the size or offset of some field of an object depends on
2325 the value within another field.
2326
2327 Note that it must not be the case that T contains both a PLACEHOLDER_EXPR
2328 and some variable since it would then need to be both evaluated once and
2329 evaluated more than once. Front-ends must assure this case cannot
2330 happen by surrounding any such subexpressions in their own SAVE_EXPR
2331 and forcing evaluation at the proper time. */
2332 if (contains_placeholder_p (inner))
2333 return t;
2334
2335 t = build1 (SAVE_EXPR, TREE_TYPE (expr), t);
2336
2337 /* This expression might be placed ahead of a jump to ensure that the
2338 value was computed on both sides of the jump. So make sure it isn't
2339 eliminated as dead. */
2340 TREE_SIDE_EFFECTS (t) = 1;
2341 return t;
2342 }
2343
2344 /* Look inside EXPR and into any simple arithmetic operations. Return
2345 the innermost non-arithmetic node. */
2346
2347 tree
2348 skip_simple_arithmetic (tree expr)
2349 {
2350 tree inner;
2351
2352 /* We don't care about whether this can be used as an lvalue in this
2353 context. */
2354 while (TREE_CODE (expr) == NON_LVALUE_EXPR)
2355 expr = TREE_OPERAND (expr, 0);
2356
2357 /* If we have simple operations applied to a SAVE_EXPR or to a SAVE_EXPR and
2358 a constant, it will be more efficient to not make another SAVE_EXPR since
2359 it will allow better simplification and GCSE will be able to merge the
2360 computations if they actually occur. */
2361 inner = expr;
2362 while (1)
2363 {
2364 if (UNARY_CLASS_P (inner))
2365 inner = TREE_OPERAND (inner, 0);
2366 else if (BINARY_CLASS_P (inner))
2367 {
2368 if (tree_invariant_p (TREE_OPERAND (inner, 1)))
2369 inner = TREE_OPERAND (inner, 0);
2370 else if (tree_invariant_p (TREE_OPERAND (inner, 0)))
2371 inner = TREE_OPERAND (inner, 1);
2372 else
2373 break;
2374 }
2375 else
2376 break;
2377 }
2378
2379 return inner;
2380 }
2381
2382 /* Return which tree structure is used by T. */
2383
2384 enum tree_node_structure_enum
2385 tree_node_structure (const_tree t)
2386 {
2387 const enum tree_code code = TREE_CODE (t);
2388
2389 switch (TREE_CODE_CLASS (code))
2390 {
2391 case tcc_declaration: 277 case tcc_declaration:
2392 { 278 {
2393 switch (code) 279 switch (code)
2394 { 280 {
2395 case FIELD_DECL: 281 case FIELD_DECL:
2400 return TS_VAR_DECL; 286 return TS_VAR_DECL;
2401 case LABEL_DECL: 287 case LABEL_DECL:
2402 return TS_LABEL_DECL; 288 return TS_LABEL_DECL;
2403 case RESULT_DECL: 289 case RESULT_DECL:
2404 return TS_RESULT_DECL; 290 return TS_RESULT_DECL;
291 case DEBUG_EXPR_DECL:
292 return TS_DECL_WRTL;
2405 case CONST_DECL: 293 case CONST_DECL:
2406 return TS_CONST_DECL; 294 return TS_CONST_DECL;
2407 case TYPE_DECL: 295 case TYPE_DECL:
2408 return TS_TYPE_DECL; 296 return TS_TYPE_DECL;
2409 case FUNCTION_DECL: 297 case FUNCTION_DECL:
2410 return TS_FUNCTION_DECL; 298 return TS_FUNCTION_DECL;
2411 case SYMBOL_MEMORY_TAG:
2412 case NAME_MEMORY_TAG:
2413 case MEMORY_PARTITION_TAG:
2414 return TS_MEMORY_TAG;
2415 default: 299 default:
2416 return TS_DECL_NON_COMMON; 300 return TS_DECL_NON_COMMON;
2417 } 301 }
2418 } 302 }
2419 case tcc_type: 303 case tcc_type:
2455 339
2456 default: 340 default:
2457 gcc_unreachable (); 341 gcc_unreachable ();
2458 } 342 }
2459 } 343 }
344
345
346 /* Initialize tree_contains_struct to describe the hierarchy of tree
347 nodes. */
348
349 static void
350 initialize_tree_contains_struct (void)
351 {
352 unsigned i;
353
354 #define MARK_TS_BASE(C) \
355 do { \
356 tree_contains_struct[C][TS_BASE] = 1; \
357 } while (0)
358
359 #define MARK_TS_COMMON(C) \
360 do { \
361 MARK_TS_BASE (C); \
362 tree_contains_struct[C][TS_COMMON] = 1; \
363 } while (0)
364
365 #define MARK_TS_DECL_MINIMAL(C) \
366 do { \
367 MARK_TS_COMMON (C); \
368 tree_contains_struct[C][TS_DECL_MINIMAL] = 1; \
369 } while (0)
370
371 #define MARK_TS_DECL_COMMON(C) \
372 do { \
373 MARK_TS_DECL_MINIMAL (C); \
374 tree_contains_struct[C][TS_DECL_COMMON] = 1; \
375 } while (0)
376
377 #define MARK_TS_DECL_WRTL(C) \
378 do { \
379 MARK_TS_DECL_COMMON (C); \
380 tree_contains_struct[C][TS_DECL_WRTL] = 1; \
381 } while (0)
382
383 #define MARK_TS_DECL_WITH_VIS(C) \
384 do { \
385 MARK_TS_DECL_WRTL (C); \
386 tree_contains_struct[C][TS_DECL_WITH_VIS] = 1; \
387 } while (0)
388
389 #define MARK_TS_DECL_NON_COMMON(C) \
390 do { \
391 MARK_TS_DECL_WITH_VIS (C); \
392 tree_contains_struct[C][TS_DECL_NON_COMMON] = 1; \
393 } while (0)
394
395 for (i = ERROR_MARK; i < LAST_AND_UNUSED_TREE_CODE; i++)
396 {
397 enum tree_code code;
398 enum tree_node_structure_enum ts_code;
399
400 code = (enum tree_code) i;
401 ts_code = tree_node_structure_for_code (code);
402
403 /* Mark the TS structure itself. */
404 tree_contains_struct[code][ts_code] = 1;
405
406 /* Mark all the structures that TS is derived from. */
407 switch (ts_code)
408 {
409 case TS_COMMON:
410 MARK_TS_BASE (code);
411 break;
412
413 case TS_INT_CST:
414 case TS_REAL_CST:
415 case TS_FIXED_CST:
416 case TS_VECTOR:
417 case TS_STRING:
418 case TS_COMPLEX:
419 case TS_IDENTIFIER:
420 case TS_DECL_MINIMAL:
421 case TS_TYPE:
422 case TS_LIST:
423 case TS_VEC:
424 case TS_EXP:
425 case TS_SSA_NAME:
426 case TS_BLOCK:
427 case TS_BINFO:
428 case TS_STATEMENT_LIST:
429 case TS_CONSTRUCTOR:
430 case TS_OMP_CLAUSE:
431 case TS_OPTIMIZATION:
432 case TS_TARGET_OPTION:
433 MARK_TS_COMMON (code);
434 break;
435
436 case TS_DECL_COMMON:
437 MARK_TS_DECL_MINIMAL (code);
438 break;
439
440 case TS_DECL_WRTL:
441 MARK_TS_DECL_COMMON (code);
442 break;
443
444 case TS_DECL_NON_COMMON:
445 MARK_TS_DECL_WITH_VIS (code);
446 break;
447
448 case TS_DECL_WITH_VIS:
449 case TS_PARM_DECL:
450 case TS_LABEL_DECL:
451 case TS_RESULT_DECL:
452 case TS_CONST_DECL:
453 MARK_TS_DECL_WRTL (code);
454 break;
455
456 case TS_FIELD_DECL:
457 MARK_TS_DECL_COMMON (code);
458 break;
459
460 case TS_VAR_DECL:
461 MARK_TS_DECL_WITH_VIS (code);
462 break;
463
464 case TS_TYPE_DECL:
465 case TS_FUNCTION_DECL:
466 MARK_TS_DECL_NON_COMMON (code);
467 break;
468
469 default:
470 gcc_unreachable ();
471 }
472 }
473
474 /* Basic consistency checks for attributes used in fold. */
475 gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_NON_COMMON]);
476 gcc_assert (tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_NON_COMMON]);
477 gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_NON_COMMON]);
478 gcc_assert (tree_contains_struct[CONST_DECL][TS_DECL_COMMON]);
479 gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_COMMON]);
480 gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_COMMON]);
481 gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_COMMON]);
482 gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_COMMON]);
483 gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_COMMON]);
484 gcc_assert (tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_COMMON]);
485 gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_COMMON]);
486 gcc_assert (tree_contains_struct[FIELD_DECL][TS_DECL_COMMON]);
487 gcc_assert (tree_contains_struct[CONST_DECL][TS_DECL_WRTL]);
488 gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_WRTL]);
489 gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_WRTL]);
490 gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_WRTL]);
491 gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_WRTL]);
492 gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_WRTL]);
493 gcc_assert (tree_contains_struct[CONST_DECL][TS_DECL_MINIMAL]);
494 gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_MINIMAL]);
495 gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_MINIMAL]);
496 gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_MINIMAL]);
497 gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_MINIMAL]);
498 gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_MINIMAL]);
499 gcc_assert (tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_MINIMAL]);
500 gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_MINIMAL]);
501 gcc_assert (tree_contains_struct[FIELD_DECL][TS_DECL_MINIMAL]);
502 gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_WITH_VIS]);
503 gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_WITH_VIS]);
504 gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_WITH_VIS]);
505 gcc_assert (tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_WITH_VIS]);
506 gcc_assert (tree_contains_struct[VAR_DECL][TS_VAR_DECL]);
507 gcc_assert (tree_contains_struct[FIELD_DECL][TS_FIELD_DECL]);
508 gcc_assert (tree_contains_struct[PARM_DECL][TS_PARM_DECL]);
509 gcc_assert (tree_contains_struct[LABEL_DECL][TS_LABEL_DECL]);
510 gcc_assert (tree_contains_struct[RESULT_DECL][TS_RESULT_DECL]);
511 gcc_assert (tree_contains_struct[CONST_DECL][TS_CONST_DECL]);
512 gcc_assert (tree_contains_struct[TYPE_DECL][TS_TYPE_DECL]);
513 gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_FUNCTION_DECL]);
514 gcc_assert (tree_contains_struct[IMPORTED_DECL][TS_DECL_MINIMAL]);
515 gcc_assert (tree_contains_struct[IMPORTED_DECL][TS_DECL_COMMON]);
516
517 #undef MARK_TS_BASE
518 #undef MARK_TS_COMMON
519 #undef MARK_TS_DECL_MINIMAL
520 #undef MARK_TS_DECL_COMMON
521 #undef MARK_TS_DECL_WRTL
522 #undef MARK_TS_DECL_WITH_VIS
523 #undef MARK_TS_DECL_NON_COMMON
524 }
525
526
527 /* Init tree.c. */
528
529 void
530 init_ttree (void)
531 {
532 /* Initialize the hash table of types. */
533 type_hash_table = htab_create_ggc (TYPE_HASH_INITIAL_SIZE, type_hash_hash,
534 type_hash_eq, 0);
535
536 debug_expr_for_decl = htab_create_ggc (512, tree_map_hash,
537 tree_map_eq, 0);
538
539 value_expr_for_decl = htab_create_ggc (512, tree_map_hash,
540 tree_map_eq, 0);
541 init_priority_for_decl = htab_create_ggc (512, tree_priority_map_hash,
542 tree_priority_map_eq, 0);
543
544 int_cst_hash_table = htab_create_ggc (1024, int_cst_hash_hash,
545 int_cst_hash_eq, NULL);
546
547 int_cst_node = make_node (INTEGER_CST);
548
549 cl_option_hash_table = htab_create_ggc (64, cl_option_hash_hash,
550 cl_option_hash_eq, NULL);
551
552 cl_optimization_node = make_node (OPTIMIZATION_NODE);
553 cl_target_option_node = make_node (TARGET_OPTION_NODE);
554
555 /* Initialize the tree_contains_struct array. */
556 initialize_tree_contains_struct ();
557 lang_hooks.init_ts ();
558 }
559
560
561 /* The name of the object as the assembler will see it (but before any
562 translations made by ASM_OUTPUT_LABELREF). Often this is the same
563 as DECL_NAME. It is an IDENTIFIER_NODE. */
564 tree
565 decl_assembler_name (tree decl)
566 {
567 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
568 lang_hooks.set_decl_assembler_name (decl);
569 return DECL_WITH_VIS_CHECK (decl)->decl_with_vis.assembler_name;
570 }
571
572 /* Compare ASMNAME with the DECL_ASSEMBLER_NAME of DECL. */
573
574 bool
575 decl_assembler_name_equal (tree decl, const_tree asmname)
576 {
577 tree decl_asmname = DECL_ASSEMBLER_NAME (decl);
578 const char *decl_str;
579 const char *asmname_str;
580 bool test = false;
581
582 if (decl_asmname == asmname)
583 return true;
584
585 decl_str = IDENTIFIER_POINTER (decl_asmname);
586 asmname_str = IDENTIFIER_POINTER (asmname);
587
588
589 /* If the target assembler name was set by the user, things are trickier.
590 We have a leading '*' to begin with. After that, it's arguable what
591 is the correct thing to do with -fleading-underscore. Arguably, we've
592 historically been doing the wrong thing in assemble_alias by always
593 printing the leading underscore. Since we're not changing that, make
594 sure user_label_prefix follows the '*' before matching. */
595 if (decl_str[0] == '*')
596 {
597 size_t ulp_len = strlen (user_label_prefix);
598
599 decl_str ++;
600
601 if (ulp_len == 0)
602 test = true;
603 else if (strncmp (decl_str, user_label_prefix, ulp_len) == 0)
604 decl_str += ulp_len, test=true;
605 else
606 decl_str --;
607 }
608 if (asmname_str[0] == '*')
609 {
610 size_t ulp_len = strlen (user_label_prefix);
611
612 asmname_str ++;
613
614 if (ulp_len == 0)
615 test = true;
616 else if (strncmp (asmname_str, user_label_prefix, ulp_len) == 0)
617 asmname_str += ulp_len, test=true;
618 else
619 asmname_str --;
620 }
621
622 if (!test)
623 return false;
624 return strcmp (decl_str, asmname_str) == 0;
625 }
626
627 /* Hash asmnames ignoring the user specified marks. */
628
629 hashval_t
630 decl_assembler_name_hash (const_tree asmname)
631 {
632 if (IDENTIFIER_POINTER (asmname)[0] == '*')
633 {
634 const char *decl_str = IDENTIFIER_POINTER (asmname) + 1;
635 size_t ulp_len = strlen (user_label_prefix);
636
637 if (ulp_len == 0)
638 ;
639 else if (strncmp (decl_str, user_label_prefix, ulp_len) == 0)
640 decl_str += ulp_len;
641
642 return htab_hash_string (decl_str);
643 }
644
645 return htab_hash_string (IDENTIFIER_POINTER (asmname));
646 }
647
648 /* Compute the number of bytes occupied by a tree with code CODE.
649 This function cannot be used for nodes that have variable sizes,
650 including TREE_VEC, STRING_CST, and CALL_EXPR. */
651 size_t
652 tree_code_size (enum tree_code code)
653 {
654 switch (TREE_CODE_CLASS (code))
655 {
656 case tcc_declaration: /* A decl node */
657 {
658 switch (code)
659 {
660 case FIELD_DECL:
661 return sizeof (struct tree_field_decl);
662 case PARM_DECL:
663 return sizeof (struct tree_parm_decl);
664 case VAR_DECL:
665 return sizeof (struct tree_var_decl);
666 case LABEL_DECL:
667 return sizeof (struct tree_label_decl);
668 case RESULT_DECL:
669 return sizeof (struct tree_result_decl);
670 case CONST_DECL:
671 return sizeof (struct tree_const_decl);
672 case TYPE_DECL:
673 return sizeof (struct tree_type_decl);
674 case FUNCTION_DECL:
675 return sizeof (struct tree_function_decl);
676 case DEBUG_EXPR_DECL:
677 return sizeof (struct tree_decl_with_rtl);
678 default:
679 return sizeof (struct tree_decl_non_common);
680 }
681 }
682
683 case tcc_type: /* a type node */
684 return sizeof (struct tree_type);
685
686 case tcc_reference: /* a reference */
687 case tcc_expression: /* an expression */
688 case tcc_statement: /* an expression with side effects */
689 case tcc_comparison: /* a comparison expression */
690 case tcc_unary: /* a unary arithmetic expression */
691 case tcc_binary: /* a binary arithmetic expression */
692 return (sizeof (struct tree_exp)
693 + (TREE_CODE_LENGTH (code) - 1) * sizeof (tree));
694
695 case tcc_constant: /* a constant */
696 switch (code)
697 {
698 case INTEGER_CST: return sizeof (struct tree_int_cst);
699 case REAL_CST: return sizeof (struct tree_real_cst);
700 case FIXED_CST: return sizeof (struct tree_fixed_cst);
701 case COMPLEX_CST: return sizeof (struct tree_complex);
702 case VECTOR_CST: return sizeof (struct tree_vector);
703 case STRING_CST: gcc_unreachable ();
704 default:
705 return lang_hooks.tree_size (code);
706 }
707
708 case tcc_exceptional: /* something random, like an identifier. */
709 switch (code)
710 {
711 case IDENTIFIER_NODE: return lang_hooks.identifier_size;
712 case TREE_LIST: return sizeof (struct tree_list);
713
714 case ERROR_MARK:
715 case PLACEHOLDER_EXPR: return sizeof (struct tree_common);
716
717 case TREE_VEC:
718 case OMP_CLAUSE: gcc_unreachable ();
719
720 case SSA_NAME: return sizeof (struct tree_ssa_name);
721
722 case STATEMENT_LIST: return sizeof (struct tree_statement_list);
723 case BLOCK: return sizeof (struct tree_block);
724 case CONSTRUCTOR: return sizeof (struct tree_constructor);
725 case OPTIMIZATION_NODE: return sizeof (struct tree_optimization_option);
726 case TARGET_OPTION_NODE: return sizeof (struct tree_target_option);
727
728 default:
729 return lang_hooks.tree_size (code);
730 }
731
732 default:
733 gcc_unreachable ();
734 }
735 }
736
737 /* Compute the number of bytes occupied by NODE. This routine only
738 looks at TREE_CODE, except for those nodes that have variable sizes. */
739 size_t
740 tree_size (const_tree node)
741 {
742 const enum tree_code code = TREE_CODE (node);
743 switch (code)
744 {
745 case TREE_BINFO:
746 return (offsetof (struct tree_binfo, base_binfos)
747 + VEC_embedded_size (tree, BINFO_N_BASE_BINFOS (node)));
748
749 case TREE_VEC:
750 return (sizeof (struct tree_vec)
751 + (TREE_VEC_LENGTH (node) - 1) * sizeof (tree));
752
753 case STRING_CST:
754 return TREE_STRING_LENGTH (node) + offsetof (struct tree_string, str) + 1;
755
756 case OMP_CLAUSE:
757 return (sizeof (struct tree_omp_clause)
758 + (omp_clause_num_ops[OMP_CLAUSE_CODE (node)] - 1)
759 * sizeof (tree));
760
761 default:
762 if (TREE_CODE_CLASS (code) == tcc_vl_exp)
763 return (sizeof (struct tree_exp)
764 + (VL_EXP_OPERAND_LENGTH (node) - 1) * sizeof (tree));
765 else
766 return tree_code_size (code);
767 }
768 }
769
770 /* Return a newly allocated node of code CODE. For decl and type
771 nodes, some other fields are initialized. The rest of the node is
772 initialized to zero. This function cannot be used for TREE_VEC or
773 OMP_CLAUSE nodes, which is enforced by asserts in tree_code_size.
774
775 Achoo! I got a code in the node. */
776
777 tree
778 make_node_stat (enum tree_code code MEM_STAT_DECL)
779 {
780 tree t;
781 enum tree_code_class type = TREE_CODE_CLASS (code);
782 size_t length = tree_code_size (code);
783 #ifdef GATHER_STATISTICS
784 tree_node_kind kind;
785
786 switch (type)
787 {
788 case tcc_declaration: /* A decl node */
789 kind = d_kind;
790 break;
791
792 case tcc_type: /* a type node */
793 kind = t_kind;
794 break;
795
796 case tcc_statement: /* an expression with side effects */
797 kind = s_kind;
798 break;
799
800 case tcc_reference: /* a reference */
801 kind = r_kind;
802 break;
803
804 case tcc_expression: /* an expression */
805 case tcc_comparison: /* a comparison expression */
806 case tcc_unary: /* a unary arithmetic expression */
807 case tcc_binary: /* a binary arithmetic expression */
808 kind = e_kind;
809 break;
810
811 case tcc_constant: /* a constant */
812 kind = c_kind;
813 break;
814
815 case tcc_exceptional: /* something random, like an identifier. */
816 switch (code)
817 {
818 case IDENTIFIER_NODE:
819 kind = id_kind;
820 break;
821
822 case TREE_VEC:
823 kind = vec_kind;
824 break;
825
826 case TREE_BINFO:
827 kind = binfo_kind;
828 break;
829
830 case SSA_NAME:
831 kind = ssa_name_kind;
832 break;
833
834 case BLOCK:
835 kind = b_kind;
836 break;
837
838 case CONSTRUCTOR:
839 kind = constr_kind;
840 break;
841
842 default:
843 kind = x_kind;
844 break;
845 }
846 break;
847
848 default:
849 gcc_unreachable ();
850 }
851
852 tree_node_counts[(int) kind]++;
853 tree_node_sizes[(int) kind] += length;
854 #endif
855
856 if (code == IDENTIFIER_NODE)
857 t = (tree) ggc_alloc_zone_pass_stat (length, &tree_id_zone);
858 else
859 t = (tree) ggc_alloc_zone_pass_stat (length, &tree_zone);
860
861 memset (t, 0, length);
862
863 TREE_SET_CODE (t, code);
864
865 switch (type)
866 {
867 case tcc_statement:
868 TREE_SIDE_EFFECTS (t) = 1;
869 break;
870
871 case tcc_declaration:
872 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
873 {
874 if (code == FUNCTION_DECL)
875 {
876 DECL_ALIGN (t) = FUNCTION_BOUNDARY;
877 DECL_MODE (t) = FUNCTION_MODE;
878 }
879 else
880 DECL_ALIGN (t) = 1;
881 }
882 DECL_SOURCE_LOCATION (t) = input_location;
883 if (TREE_CODE (t) == DEBUG_EXPR_DECL)
884 DECL_UID (t) = --next_debug_decl_uid;
885 else
886 DECL_UID (t) = next_decl_uid++;
887 if (TREE_CODE (t) == LABEL_DECL)
888 LABEL_DECL_UID (t) = -1;
889
890 break;
891
892 case tcc_type:
893 TYPE_UID (t) = next_type_uid++;
894 TYPE_ALIGN (t) = BITS_PER_UNIT;
895 TYPE_USER_ALIGN (t) = 0;
896 TYPE_MAIN_VARIANT (t) = t;
897 TYPE_CANONICAL (t) = t;
898
899 /* Default to no attributes for type, but let target change that. */
900 TYPE_ATTRIBUTES (t) = NULL_TREE;
901 targetm.set_default_type_attributes (t);
902
903 /* We have not yet computed the alias set for this type. */
904 TYPE_ALIAS_SET (t) = -1;
905 break;
906
907 case tcc_constant:
908 TREE_CONSTANT (t) = 1;
909 break;
910
911 case tcc_expression:
912 switch (code)
913 {
914 case INIT_EXPR:
915 case MODIFY_EXPR:
916 case VA_ARG_EXPR:
917 case PREDECREMENT_EXPR:
918 case PREINCREMENT_EXPR:
919 case POSTDECREMENT_EXPR:
920 case POSTINCREMENT_EXPR:
921 /* All of these have side-effects, no matter what their
922 operands are. */
923 TREE_SIDE_EFFECTS (t) = 1;
924 break;
925
926 default:
927 break;
928 }
929 break;
930
931 default:
932 /* Other classes need no special treatment. */
933 break;
934 }
935
936 return t;
937 }
938
939 /* Return a new node with the same contents as NODE except that its
940 TREE_CHAIN is zero and it has a fresh uid. */
941
942 tree
943 copy_node_stat (tree node MEM_STAT_DECL)
944 {
945 tree t;
946 enum tree_code code = TREE_CODE (node);
947 size_t length;
948
949 gcc_assert (code != STATEMENT_LIST);
950
951 length = tree_size (node);
952 t = (tree) ggc_alloc_zone_pass_stat (length, &tree_zone);
953 memcpy (t, node, length);
954
955 TREE_CHAIN (t) = 0;
956 TREE_ASM_WRITTEN (t) = 0;
957 TREE_VISITED (t) = 0;
958 if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
959 *DECL_VAR_ANN_PTR (t) = 0;
960
961 if (TREE_CODE_CLASS (code) == tcc_declaration)
962 {
963 if (code == DEBUG_EXPR_DECL)
964 DECL_UID (t) = --next_debug_decl_uid;
965 else
966 DECL_UID (t) = next_decl_uid++;
967 if ((TREE_CODE (node) == PARM_DECL || TREE_CODE (node) == VAR_DECL)
968 && DECL_HAS_VALUE_EXPR_P (node))
969 {
970 SET_DECL_VALUE_EXPR (t, DECL_VALUE_EXPR (node));
971 DECL_HAS_VALUE_EXPR_P (t) = 1;
972 }
973 if (TREE_CODE (node) == VAR_DECL && DECL_HAS_INIT_PRIORITY_P (node))
974 {
975 SET_DECL_INIT_PRIORITY (t, DECL_INIT_PRIORITY (node));
976 DECL_HAS_INIT_PRIORITY_P (t) = 1;
977 }
978 }
979 else if (TREE_CODE_CLASS (code) == tcc_type)
980 {
981 TYPE_UID (t) = next_type_uid++;
982 /* The following is so that the debug code for
983 the copy is different from the original type.
984 The two statements usually duplicate each other
985 (because they clear fields of the same union),
986 but the optimizer should catch that. */
987 TYPE_SYMTAB_POINTER (t) = 0;
988 TYPE_SYMTAB_ADDRESS (t) = 0;
989
990 /* Do not copy the values cache. */
991 if (TYPE_CACHED_VALUES_P(t))
992 {
993 TYPE_CACHED_VALUES_P (t) = 0;
994 TYPE_CACHED_VALUES (t) = NULL_TREE;
995 }
996 }
997
998 return t;
999 }
1000
1001 /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
1002 For example, this can copy a list made of TREE_LIST nodes. */
1003
1004 tree
1005 copy_list (tree list)
1006 {
1007 tree head;
1008 tree prev, next;
1009
1010 if (list == 0)
1011 return 0;
1012
1013 head = prev = copy_node (list);
1014 next = TREE_CHAIN (list);
1015 while (next)
1016 {
1017 TREE_CHAIN (prev) = copy_node (next);
1018 prev = TREE_CHAIN (prev);
1019 next = TREE_CHAIN (next);
1020 }
1021 return head;
1022 }
1023
1024
1025 /* Create an INT_CST node with a LOW value sign extended. */
1026
1027 tree
1028 build_int_cst (tree type, HOST_WIDE_INT low)
1029 {
1030 /* Support legacy code. */
1031 if (!type)
1032 type = integer_type_node;
1033
1034 return build_int_cst_wide (type, low, low < 0 ? -1 : 0);
1035 }
1036
1037 /* Create an INT_CST node with a LOW value zero extended. */
1038
1039 tree
1040 build_int_cstu (tree type, unsigned HOST_WIDE_INT low)
1041 {
1042 return build_int_cst_wide (type, low, 0);
1043 }
1044
1045 /* Create an INT_CST node with a LOW value in TYPE. The value is sign extended
1046 if it is negative. This function is similar to build_int_cst, but
1047 the extra bits outside of the type precision are cleared. Constants
1048 with these extra bits may confuse the fold so that it detects overflows
1049 even in cases when they do not occur, and in general should be avoided.
1050 We cannot however make this a default behavior of build_int_cst without
1051 more intrusive changes, since there are parts of gcc that rely on the extra
1052 precision of the integer constants. */
1053
1054 tree
1055 build_int_cst_type (tree type, HOST_WIDE_INT low)
1056 {
1057 unsigned HOST_WIDE_INT low1;
1058 HOST_WIDE_INT hi;
1059
1060 gcc_assert (type);
1061
1062 fit_double_type (low, low < 0 ? -1 : 0, &low1, &hi, type);
1063
1064 return build_int_cst_wide (type, low1, hi);
1065 }
1066
1067 /* Create an INT_CST node of TYPE and value HI:LOW. The value is truncated
1068 and sign extended according to the value range of TYPE. */
1069
1070 tree
1071 build_int_cst_wide_type (tree type,
1072 unsigned HOST_WIDE_INT low, HOST_WIDE_INT high)
1073 {
1074 fit_double_type (low, high, &low, &high, type);
1075 return build_int_cst_wide (type, low, high);
1076 }
1077
1078 /* These are the hash table functions for the hash table of INTEGER_CST
1079 nodes of a sizetype. */
1080
1081 /* Return the hash code code X, an INTEGER_CST. */
1082
1083 static hashval_t
1084 int_cst_hash_hash (const void *x)
1085 {
1086 const_tree const t = (const_tree) x;
1087
1088 return (TREE_INT_CST_HIGH (t) ^ TREE_INT_CST_LOW (t)
1089 ^ htab_hash_pointer (TREE_TYPE (t)));
1090 }
1091
1092 /* Return nonzero if the value represented by *X (an INTEGER_CST tree node)
1093 is the same as that given by *Y, which is the same. */
1094
1095 static int
1096 int_cst_hash_eq (const void *x, const void *y)
1097 {
1098 const_tree const xt = (const_tree) x;
1099 const_tree const yt = (const_tree) y;
1100
1101 return (TREE_TYPE (xt) == TREE_TYPE (yt)
1102 && TREE_INT_CST_HIGH (xt) == TREE_INT_CST_HIGH (yt)
1103 && TREE_INT_CST_LOW (xt) == TREE_INT_CST_LOW (yt));
1104 }
1105
1106 /* Create an INT_CST node of TYPE and value HI:LOW.
1107 The returned node is always shared. For small integers we use a
1108 per-type vector cache, for larger ones we use a single hash table. */
1109
1110 tree
1111 build_int_cst_wide (tree type, unsigned HOST_WIDE_INT low, HOST_WIDE_INT hi)
1112 {
1113 tree t;
1114 int ix = -1;
1115 int limit = 0;
1116
1117 gcc_assert (type);
1118
1119 switch (TREE_CODE (type))
1120 {
1121 case POINTER_TYPE:
1122 case REFERENCE_TYPE:
1123 /* Cache NULL pointer. */
1124 if (!hi && !low)
1125 {
1126 limit = 1;
1127 ix = 0;
1128 }
1129 break;
1130
1131 case BOOLEAN_TYPE:
1132 /* Cache false or true. */
1133 limit = 2;
1134 if (!hi && low < 2)
1135 ix = low;
1136 break;
1137
1138 case INTEGER_TYPE:
1139 case OFFSET_TYPE:
1140 if (TYPE_UNSIGNED (type))
1141 {
1142 /* Cache 0..N */
1143 limit = INTEGER_SHARE_LIMIT;
1144 if (!hi && low < (unsigned HOST_WIDE_INT)INTEGER_SHARE_LIMIT)
1145 ix = low;
1146 }
1147 else
1148 {
1149 /* Cache -1..N */
1150 limit = INTEGER_SHARE_LIMIT + 1;
1151 if (!hi && low < (unsigned HOST_WIDE_INT)INTEGER_SHARE_LIMIT)
1152 ix = low + 1;
1153 else if (hi == -1 && low == -(unsigned HOST_WIDE_INT)1)
1154 ix = 0;
1155 }
1156 break;
1157
1158 case ENUMERAL_TYPE:
1159 break;
1160
1161 default:
1162 gcc_unreachable ();
1163 }
1164
1165 if (ix >= 0)
1166 {
1167 /* Look for it in the type's vector of small shared ints. */
1168 if (!TYPE_CACHED_VALUES_P (type))
1169 {
1170 TYPE_CACHED_VALUES_P (type) = 1;
1171 TYPE_CACHED_VALUES (type) = make_tree_vec (limit);
1172 }
1173
1174 t = TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix);
1175 if (t)
1176 {
1177 /* Make sure no one is clobbering the shared constant. */
1178 gcc_assert (TREE_TYPE (t) == type);
1179 gcc_assert (TREE_INT_CST_LOW (t) == low);
1180 gcc_assert (TREE_INT_CST_HIGH (t) == hi);
1181 }
1182 else
1183 {
1184 /* Create a new shared int. */
1185 t = make_node (INTEGER_CST);
1186
1187 TREE_INT_CST_LOW (t) = low;
1188 TREE_INT_CST_HIGH (t) = hi;
1189 TREE_TYPE (t) = type;
1190
1191 TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix) = t;
1192 }
1193 }
1194 else
1195 {
1196 /* Use the cache of larger shared ints. */
1197 void **slot;
1198
1199 TREE_INT_CST_LOW (int_cst_node) = low;
1200 TREE_INT_CST_HIGH (int_cst_node) = hi;
1201 TREE_TYPE (int_cst_node) = type;
1202
1203 slot = htab_find_slot (int_cst_hash_table, int_cst_node, INSERT);
1204 t = (tree) *slot;
1205 if (!t)
1206 {
1207 /* Insert this one into the hash table. */
1208 t = int_cst_node;
1209 *slot = t;
1210 /* Make a new node for next time round. */
1211 int_cst_node = make_node (INTEGER_CST);
1212 }
1213 }
1214
1215 return t;
1216 }
1217
1218 /* Builds an integer constant in TYPE such that lowest BITS bits are ones
1219 and the rest are zeros. */
1220
1221 tree
1222 build_low_bits_mask (tree type, unsigned bits)
1223 {
1224 unsigned HOST_WIDE_INT low;
1225 HOST_WIDE_INT high;
1226 unsigned HOST_WIDE_INT all_ones = ~(unsigned HOST_WIDE_INT) 0;
1227
1228 gcc_assert (bits <= TYPE_PRECISION (type));
1229
1230 if (bits == TYPE_PRECISION (type)
1231 && !TYPE_UNSIGNED (type))
1232 {
1233 /* Sign extended all-ones mask. */
1234 low = all_ones;
1235 high = -1;
1236 }
1237 else if (bits <= HOST_BITS_PER_WIDE_INT)
1238 {
1239 low = all_ones >> (HOST_BITS_PER_WIDE_INT - bits);
1240 high = 0;
1241 }
1242 else
1243 {
1244 bits -= HOST_BITS_PER_WIDE_INT;
1245 low = all_ones;
1246 high = all_ones >> (HOST_BITS_PER_WIDE_INT - bits);
1247 }
1248
1249 return build_int_cst_wide (type, low, high);
1250 }
1251
1252 /* Checks that X is integer constant that can be expressed in (unsigned)
1253 HOST_WIDE_INT without loss of precision. */
1254
1255 bool
1256 cst_and_fits_in_hwi (const_tree x)
1257 {
1258 if (TREE_CODE (x) != INTEGER_CST)
1259 return false;
1260
1261 if (TYPE_PRECISION (TREE_TYPE (x)) > HOST_BITS_PER_WIDE_INT)
1262 return false;
1263
1264 return (TREE_INT_CST_HIGH (x) == 0
1265 || TREE_INT_CST_HIGH (x) == -1);
1266 }
1267
1268 /* Return a new VECTOR_CST node whose type is TYPE and whose values
1269 are in a list pointed to by VALS. */
1270
1271 tree
1272 build_vector (tree type, tree vals)
1273 {
1274 tree v = make_node (VECTOR_CST);
1275 int over = 0;
1276 tree link;
1277
1278 TREE_VECTOR_CST_ELTS (v) = vals;
1279 TREE_TYPE (v) = type;
1280
1281 /* Iterate through elements and check for overflow. */
1282 for (link = vals; link; link = TREE_CHAIN (link))
1283 {
1284 tree value = TREE_VALUE (link);
1285
1286 /* Don't crash if we get an address constant. */
1287 if (!CONSTANT_CLASS_P (value))
1288 continue;
1289
1290 over |= TREE_OVERFLOW (value);
1291 }
1292
1293 TREE_OVERFLOW (v) = over;
1294 return v;
1295 }
1296
1297 /* Return a new VECTOR_CST node whose type is TYPE and whose values
1298 are extracted from V, a vector of CONSTRUCTOR_ELT. */
1299
1300 tree
1301 build_vector_from_ctor (tree type, VEC(constructor_elt,gc) *v)
1302 {
1303 tree list = NULL_TREE;
1304 unsigned HOST_WIDE_INT idx;
1305 tree value;
1306
1307 FOR_EACH_CONSTRUCTOR_VALUE (v, idx, value)
1308 list = tree_cons (NULL_TREE, value, list);
1309 return build_vector (type, nreverse (list));
1310 }
1311
1312 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
1313 are in the VEC pointed to by VALS. */
1314 tree
1315 build_constructor (tree type, VEC(constructor_elt,gc) *vals)
1316 {
1317 tree c = make_node (CONSTRUCTOR);
1318 TREE_TYPE (c) = type;
1319 CONSTRUCTOR_ELTS (c) = vals;
1320 return c;
1321 }
1322
1323 /* Build a CONSTRUCTOR node made of a single initializer, with the specified
1324 INDEX and VALUE. */
1325 tree
1326 build_constructor_single (tree type, tree index, tree value)
1327 {
1328 VEC(constructor_elt,gc) *v;
1329 constructor_elt *elt;
1330 tree t;
1331
1332 v = VEC_alloc (constructor_elt, gc, 1);
1333 elt = VEC_quick_push (constructor_elt, v, NULL);
1334 elt->index = index;
1335 elt->value = value;
1336
1337 t = build_constructor (type, v);
1338 TREE_CONSTANT (t) = TREE_CONSTANT (value);
1339 return t;
1340 }
1341
1342
1343 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
1344 are in a list pointed to by VALS. */
1345 tree
1346 build_constructor_from_list (tree type, tree vals)
1347 {
1348 tree t, val;
1349 VEC(constructor_elt,gc) *v = NULL;
1350 bool constant_p = true;
1351
1352 if (vals)
1353 {
1354 v = VEC_alloc (constructor_elt, gc, list_length (vals));
1355 for (t = vals; t; t = TREE_CHAIN (t))
1356 {
1357 constructor_elt *elt = VEC_quick_push (constructor_elt, v, NULL);
1358 val = TREE_VALUE (t);
1359 elt->index = TREE_PURPOSE (t);
1360 elt->value = val;
1361 if (!TREE_CONSTANT (val))
1362 constant_p = false;
1363 }
1364 }
1365
1366 t = build_constructor (type, v);
1367 TREE_CONSTANT (t) = constant_p;
1368 return t;
1369 }
1370
1371 /* Return a new FIXED_CST node whose type is TYPE and value is F. */
1372
1373 tree
1374 build_fixed (tree type, FIXED_VALUE_TYPE f)
1375 {
1376 tree v;
1377 FIXED_VALUE_TYPE *fp;
1378
1379 v = make_node (FIXED_CST);
1380 fp = GGC_NEW (FIXED_VALUE_TYPE);
1381 memcpy (fp, &f, sizeof (FIXED_VALUE_TYPE));
1382
1383 TREE_TYPE (v) = type;
1384 TREE_FIXED_CST_PTR (v) = fp;
1385 return v;
1386 }
1387
1388 /* Return a new REAL_CST node whose type is TYPE and value is D. */
1389
1390 tree
1391 build_real (tree type, REAL_VALUE_TYPE d)
1392 {
1393 tree v;
1394 REAL_VALUE_TYPE *dp;
1395 int overflow = 0;
1396
1397 /* ??? Used to check for overflow here via CHECK_FLOAT_TYPE.
1398 Consider doing it via real_convert now. */
1399
1400 v = make_node (REAL_CST);
1401 dp = GGC_NEW (REAL_VALUE_TYPE);
1402 memcpy (dp, &d, sizeof (REAL_VALUE_TYPE));
1403
1404 TREE_TYPE (v) = type;
1405 TREE_REAL_CST_PTR (v) = dp;
1406 TREE_OVERFLOW (v) = overflow;
1407 return v;
1408 }
1409
1410 /* Return a new REAL_CST node whose type is TYPE
1411 and whose value is the integer value of the INTEGER_CST node I. */
1412
1413 REAL_VALUE_TYPE
1414 real_value_from_int_cst (const_tree type, const_tree i)
1415 {
1416 REAL_VALUE_TYPE d;
1417
1418 /* Clear all bits of the real value type so that we can later do
1419 bitwise comparisons to see if two values are the same. */
1420 memset (&d, 0, sizeof d);
1421
1422 real_from_integer (&d, type ? TYPE_MODE (type) : VOIDmode,
1423 TREE_INT_CST_LOW (i), TREE_INT_CST_HIGH (i),
1424 TYPE_UNSIGNED (TREE_TYPE (i)));
1425 return d;
1426 }
1427
1428 /* Given a tree representing an integer constant I, return a tree
1429 representing the same value as a floating-point constant of type TYPE. */
1430
1431 tree
1432 build_real_from_int_cst (tree type, const_tree i)
1433 {
1434 tree v;
1435 int overflow = TREE_OVERFLOW (i);
1436
1437 v = build_real (type, real_value_from_int_cst (type, i));
1438
1439 TREE_OVERFLOW (v) |= overflow;
1440 return v;
1441 }
1442
1443 /* Return a newly constructed STRING_CST node whose value is
1444 the LEN characters at STR.
1445 The TREE_TYPE is not initialized. */
1446
1447 tree
1448 build_string (int len, const char *str)
1449 {
1450 tree s;
1451 size_t length;
1452
1453 /* Do not waste bytes provided by padding of struct tree_string. */
1454 length = len + offsetof (struct tree_string, str) + 1;
1455
1456 #ifdef GATHER_STATISTICS
1457 tree_node_counts[(int) c_kind]++;
1458 tree_node_sizes[(int) c_kind] += length;
1459 #endif
1460
1461 s = ggc_alloc_tree (length);
1462
1463 memset (s, 0, sizeof (struct tree_common));
1464 TREE_SET_CODE (s, STRING_CST);
1465 TREE_CONSTANT (s) = 1;
1466 TREE_STRING_LENGTH (s) = len;
1467 memcpy (s->string.str, str, len);
1468 s->string.str[len] = '\0';
1469
1470 return s;
1471 }
1472
1473 /* Return a newly constructed COMPLEX_CST node whose value is
1474 specified by the real and imaginary parts REAL and IMAG.
1475 Both REAL and IMAG should be constant nodes. TYPE, if specified,
1476 will be the type of the COMPLEX_CST; otherwise a new type will be made. */
1477
1478 tree
1479 build_complex (tree type, tree real, tree imag)
1480 {
1481 tree t = make_node (COMPLEX_CST);
1482
1483 TREE_REALPART (t) = real;
1484 TREE_IMAGPART (t) = imag;
1485 TREE_TYPE (t) = type ? type : build_complex_type (TREE_TYPE (real));
1486 TREE_OVERFLOW (t) = TREE_OVERFLOW (real) | TREE_OVERFLOW (imag);
1487 return t;
1488 }
1489
1490 /* Return a constant of arithmetic type TYPE which is the
1491 multiplicative identity of the set TYPE. */
1492
1493 tree
1494 build_one_cst (tree type)
1495 {
1496 switch (TREE_CODE (type))
1497 {
1498 case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
1499 case POINTER_TYPE: case REFERENCE_TYPE:
1500 case OFFSET_TYPE:
1501 return build_int_cst (type, 1);
1502
1503 case REAL_TYPE:
1504 return build_real (type, dconst1);
1505
1506 case FIXED_POINT_TYPE:
1507 /* We can only generate 1 for accum types. */
1508 gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type)));
1509 return build_fixed (type, FCONST1(TYPE_MODE (type)));
1510
1511 case VECTOR_TYPE:
1512 {
1513 tree scalar, cst;
1514 int i;
1515
1516 scalar = build_one_cst (TREE_TYPE (type));
1517
1518 /* Create 'vect_cst_ = {cst,cst,...,cst}' */
1519 cst = NULL_TREE;
1520 for (i = TYPE_VECTOR_SUBPARTS (type); --i >= 0; )
1521 cst = tree_cons (NULL_TREE, scalar, cst);
1522
1523 return build_vector (type, cst);
1524 }
1525
1526 case COMPLEX_TYPE:
1527 return build_complex (type,
1528 build_one_cst (TREE_TYPE (type)),
1529 fold_convert (TREE_TYPE (type), integer_zero_node));
1530
1531 default:
1532 gcc_unreachable ();
1533 }
1534 }
1535
1536 /* Build a BINFO with LEN language slots. */
1537
1538 tree
1539 make_tree_binfo_stat (unsigned base_binfos MEM_STAT_DECL)
1540 {
1541 tree t;
1542 size_t length = (offsetof (struct tree_binfo, base_binfos)
1543 + VEC_embedded_size (tree, base_binfos));
1544
1545 #ifdef GATHER_STATISTICS
1546 tree_node_counts[(int) binfo_kind]++;
1547 tree_node_sizes[(int) binfo_kind] += length;
1548 #endif
1549
1550 t = (tree) ggc_alloc_zone_pass_stat (length, &tree_zone);
1551
1552 memset (t, 0, offsetof (struct tree_binfo, base_binfos));
1553
1554 TREE_SET_CODE (t, TREE_BINFO);
1555
1556 VEC_embedded_init (tree, BINFO_BASE_BINFOS (t), base_binfos);
1557
1558 return t;
1559 }
1560
1561
1562 /* Build a newly constructed TREE_VEC node of length LEN. */
1563
1564 tree
1565 make_tree_vec_stat (int len MEM_STAT_DECL)
1566 {
1567 tree t;
1568 int length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
1569
1570 #ifdef GATHER_STATISTICS
1571 tree_node_counts[(int) vec_kind]++;
1572 tree_node_sizes[(int) vec_kind] += length;
1573 #endif
1574
1575 t = (tree) ggc_alloc_zone_pass_stat (length, &tree_zone);
1576
1577 memset (t, 0, length);
1578
1579 TREE_SET_CODE (t, TREE_VEC);
1580 TREE_VEC_LENGTH (t) = len;
1581
1582 return t;
1583 }
1584
1585 /* Return 1 if EXPR is the integer constant zero or a complex constant
1586 of zero. */
1587
1588 int
1589 integer_zerop (const_tree expr)
1590 {
1591 STRIP_NOPS (expr);
1592
1593 return ((TREE_CODE (expr) == INTEGER_CST
1594 && TREE_INT_CST_LOW (expr) == 0
1595 && TREE_INT_CST_HIGH (expr) == 0)
1596 || (TREE_CODE (expr) == COMPLEX_CST
1597 && integer_zerop (TREE_REALPART (expr))
1598 && integer_zerop (TREE_IMAGPART (expr))));
1599 }
1600
1601 /* Return 1 if EXPR is the integer constant one or the corresponding
1602 complex constant. */
1603
1604 int
1605 integer_onep (const_tree expr)
1606 {
1607 STRIP_NOPS (expr);
1608
1609 return ((TREE_CODE (expr) == INTEGER_CST
1610 && TREE_INT_CST_LOW (expr) == 1
1611 && TREE_INT_CST_HIGH (expr) == 0)
1612 || (TREE_CODE (expr) == COMPLEX_CST
1613 && integer_onep (TREE_REALPART (expr))
1614 && integer_zerop (TREE_IMAGPART (expr))));
1615 }
1616
1617 /* Return 1 if EXPR is an integer containing all 1's in as much precision as
1618 it contains. Likewise for the corresponding complex constant. */
1619
1620 int
1621 integer_all_onesp (const_tree expr)
1622 {
1623 int prec;
1624 int uns;
1625
1626 STRIP_NOPS (expr);
1627
1628 if (TREE_CODE (expr) == COMPLEX_CST
1629 && integer_all_onesp (TREE_REALPART (expr))
1630 && integer_zerop (TREE_IMAGPART (expr)))
1631 return 1;
1632
1633 else if (TREE_CODE (expr) != INTEGER_CST)
1634 return 0;
1635
1636 uns = TYPE_UNSIGNED (TREE_TYPE (expr));
1637 if (TREE_INT_CST_LOW (expr) == ~(unsigned HOST_WIDE_INT) 0
1638 && TREE_INT_CST_HIGH (expr) == -1)
1639 return 1;
1640 if (!uns)
1641 return 0;
1642
1643 /* Note that using TYPE_PRECISION here is wrong. We care about the
1644 actual bits, not the (arbitrary) range of the type. */
1645 prec = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (expr)));
1646 if (prec >= HOST_BITS_PER_WIDE_INT)
1647 {
1648 HOST_WIDE_INT high_value;
1649 int shift_amount;
1650
1651 shift_amount = prec - HOST_BITS_PER_WIDE_INT;
1652
1653 /* Can not handle precisions greater than twice the host int size. */
1654 gcc_assert (shift_amount <= HOST_BITS_PER_WIDE_INT);
1655 if (shift_amount == HOST_BITS_PER_WIDE_INT)
1656 /* Shifting by the host word size is undefined according to the ANSI
1657 standard, so we must handle this as a special case. */
1658 high_value = -1;
1659 else
1660 high_value = ((HOST_WIDE_INT) 1 << shift_amount) - 1;
1661
1662 return (TREE_INT_CST_LOW (expr) == ~(unsigned HOST_WIDE_INT) 0
1663 && TREE_INT_CST_HIGH (expr) == high_value);
1664 }
1665 else
1666 return TREE_INT_CST_LOW (expr) == ((unsigned HOST_WIDE_INT) 1 << prec) - 1;
1667 }
1668
1669 /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only
1670 one bit on). */
1671
1672 int
1673 integer_pow2p (const_tree expr)
1674 {
1675 int prec;
1676 HOST_WIDE_INT high, low;
1677
1678 STRIP_NOPS (expr);
1679
1680 if (TREE_CODE (expr) == COMPLEX_CST
1681 && integer_pow2p (TREE_REALPART (expr))
1682 && integer_zerop (TREE_IMAGPART (expr)))
1683 return 1;
1684
1685 if (TREE_CODE (expr) != INTEGER_CST)
1686 return 0;
1687
1688 prec = TYPE_PRECISION (TREE_TYPE (expr));
1689 high = TREE_INT_CST_HIGH (expr);
1690 low = TREE_INT_CST_LOW (expr);
1691
1692 /* First clear all bits that are beyond the type's precision in case
1693 we've been sign extended. */
1694
1695 if (prec == 2 * HOST_BITS_PER_WIDE_INT)
1696 ;
1697 else if (prec > HOST_BITS_PER_WIDE_INT)
1698 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
1699 else
1700 {
1701 high = 0;
1702 if (prec < HOST_BITS_PER_WIDE_INT)
1703 low &= ~((HOST_WIDE_INT) (-1) << prec);
1704 }
1705
1706 if (high == 0 && low == 0)
1707 return 0;
1708
1709 return ((high == 0 && (low & (low - 1)) == 0)
1710 || (low == 0 && (high & (high - 1)) == 0));
1711 }
1712
1713 /* Return 1 if EXPR is an integer constant other than zero or a
1714 complex constant other than zero. */
1715
1716 int
1717 integer_nonzerop (const_tree expr)
1718 {
1719 STRIP_NOPS (expr);
1720
1721 return ((TREE_CODE (expr) == INTEGER_CST
1722 && (TREE_INT_CST_LOW (expr) != 0
1723 || TREE_INT_CST_HIGH (expr) != 0))
1724 || (TREE_CODE (expr) == COMPLEX_CST
1725 && (integer_nonzerop (TREE_REALPART (expr))
1726 || integer_nonzerop (TREE_IMAGPART (expr)))));
1727 }
1728
1729 /* Return 1 if EXPR is the fixed-point constant zero. */
1730
1731 int
1732 fixed_zerop (const_tree expr)
1733 {
1734 return (TREE_CODE (expr) == FIXED_CST
1735 && double_int_zero_p (TREE_FIXED_CST (expr).data));
1736 }
1737
1738 /* Return the power of two represented by a tree node known to be a
1739 power of two. */
1740
1741 int
1742 tree_log2 (const_tree expr)
1743 {
1744 int prec;
1745 HOST_WIDE_INT high, low;
1746
1747 STRIP_NOPS (expr);
1748
1749 if (TREE_CODE (expr) == COMPLEX_CST)
1750 return tree_log2 (TREE_REALPART (expr));
1751
1752 prec = TYPE_PRECISION (TREE_TYPE (expr));
1753 high = TREE_INT_CST_HIGH (expr);
1754 low = TREE_INT_CST_LOW (expr);
1755
1756 /* First clear all bits that are beyond the type's precision in case
1757 we've been sign extended. */
1758
1759 if (prec == 2 * HOST_BITS_PER_WIDE_INT)
1760 ;
1761 else if (prec > HOST_BITS_PER_WIDE_INT)
1762 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
1763 else
1764 {
1765 high = 0;
1766 if (prec < HOST_BITS_PER_WIDE_INT)
1767 low &= ~((HOST_WIDE_INT) (-1) << prec);
1768 }
1769
1770 return (high != 0 ? HOST_BITS_PER_WIDE_INT + exact_log2 (high)
1771 : exact_log2 (low));
1772 }
1773
1774 /* Similar, but return the largest integer Y such that 2 ** Y is less
1775 than or equal to EXPR. */
1776
1777 int
1778 tree_floor_log2 (const_tree expr)
1779 {
1780 int prec;
1781 HOST_WIDE_INT high, low;
1782
1783 STRIP_NOPS (expr);
1784
1785 if (TREE_CODE (expr) == COMPLEX_CST)
1786 return tree_log2 (TREE_REALPART (expr));
1787
1788 prec = TYPE_PRECISION (TREE_TYPE (expr));
1789 high = TREE_INT_CST_HIGH (expr);
1790 low = TREE_INT_CST_LOW (expr);
1791
1792 /* First clear all bits that are beyond the type's precision in case
1793 we've been sign extended. Ignore if type's precision hasn't been set
1794 since what we are doing is setting it. */
1795
1796 if (prec == 2 * HOST_BITS_PER_WIDE_INT || prec == 0)
1797 ;
1798 else if (prec > HOST_BITS_PER_WIDE_INT)
1799 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
1800 else
1801 {
1802 high = 0;
1803 if (prec < HOST_BITS_PER_WIDE_INT)
1804 low &= ~((HOST_WIDE_INT) (-1) << prec);
1805 }
1806
1807 return (high != 0 ? HOST_BITS_PER_WIDE_INT + floor_log2 (high)
1808 : floor_log2 (low));
1809 }
1810
1811 /* Return 1 if EXPR is the real constant zero. Trailing zeroes matter for
1812 decimal float constants, so don't return 1 for them. */
1813
1814 int
1815 real_zerop (const_tree expr)
1816 {
1817 STRIP_NOPS (expr);
1818
1819 return ((TREE_CODE (expr) == REAL_CST
1820 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst0)
1821 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr)))))
1822 || (TREE_CODE (expr) == COMPLEX_CST
1823 && real_zerop (TREE_REALPART (expr))
1824 && real_zerop (TREE_IMAGPART (expr))));
1825 }
1826
1827 /* Return 1 if EXPR is the real constant one in real or complex form.
1828 Trailing zeroes matter for decimal float constants, so don't return
1829 1 for them. */
1830
1831 int
1832 real_onep (const_tree expr)
1833 {
1834 STRIP_NOPS (expr);
1835
1836 return ((TREE_CODE (expr) == REAL_CST
1837 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst1)
1838 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr)))))
1839 || (TREE_CODE (expr) == COMPLEX_CST
1840 && real_onep (TREE_REALPART (expr))
1841 && real_zerop (TREE_IMAGPART (expr))));
1842 }
1843
1844 /* Return 1 if EXPR is the real constant two. Trailing zeroes matter
1845 for decimal float constants, so don't return 1 for them. */
1846
1847 int
1848 real_twop (const_tree expr)
1849 {
1850 STRIP_NOPS (expr);
1851
1852 return ((TREE_CODE (expr) == REAL_CST
1853 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst2)
1854 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr)))))
1855 || (TREE_CODE (expr) == COMPLEX_CST
1856 && real_twop (TREE_REALPART (expr))
1857 && real_zerop (TREE_IMAGPART (expr))));
1858 }
1859
1860 /* Return 1 if EXPR is the real constant minus one. Trailing zeroes
1861 matter for decimal float constants, so don't return 1 for them. */
1862
1863 int
1864 real_minus_onep (const_tree expr)
1865 {
1866 STRIP_NOPS (expr);
1867
1868 return ((TREE_CODE (expr) == REAL_CST
1869 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconstm1)
1870 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr)))))
1871 || (TREE_CODE (expr) == COMPLEX_CST
1872 && real_minus_onep (TREE_REALPART (expr))
1873 && real_zerop (TREE_IMAGPART (expr))));
1874 }
1875
1876 /* Nonzero if EXP is a constant or a cast of a constant. */
1877
1878 int
1879 really_constant_p (const_tree exp)
1880 {
1881 /* This is not quite the same as STRIP_NOPS. It does more. */
1882 while (CONVERT_EXPR_P (exp)
1883 || TREE_CODE (exp) == NON_LVALUE_EXPR)
1884 exp = TREE_OPERAND (exp, 0);
1885 return TREE_CONSTANT (exp);
1886 }
1887
1888 /* Return first list element whose TREE_VALUE is ELEM.
1889 Return 0 if ELEM is not in LIST. */
1890
1891 tree
1892 value_member (tree elem, tree list)
1893 {
1894 while (list)
1895 {
1896 if (elem == TREE_VALUE (list))
1897 return list;
1898 list = TREE_CHAIN (list);
1899 }
1900 return NULL_TREE;
1901 }
1902
1903 /* Return first list element whose TREE_PURPOSE is ELEM.
1904 Return 0 if ELEM is not in LIST. */
1905
1906 tree
1907 purpose_member (const_tree elem, tree list)
1908 {
1909 while (list)
1910 {
1911 if (elem == TREE_PURPOSE (list))
1912 return list;
1913 list = TREE_CHAIN (list);
1914 }
1915 return NULL_TREE;
1916 }
1917
1918 /* Returns element number IDX (zero-origin) of chain CHAIN, or
1919 NULL_TREE. */
1920
1921 tree
1922 chain_index (int idx, tree chain)
1923 {
1924 for (; chain && idx > 0; --idx)
1925 chain = TREE_CHAIN (chain);
1926 return chain;
1927 }
1928
1929 /* Return nonzero if ELEM is part of the chain CHAIN. */
1930
1931 int
1932 chain_member (const_tree elem, const_tree chain)
1933 {
1934 while (chain)
1935 {
1936 if (elem == chain)
1937 return 1;
1938 chain = TREE_CHAIN (chain);
1939 }
1940
1941 return 0;
1942 }
1943
1944 /* Return the length of a chain of nodes chained through TREE_CHAIN.
1945 We expect a null pointer to mark the end of the chain.
1946 This is the Lisp primitive `length'. */
1947
1948 int
1949 list_length (const_tree t)
1950 {
1951 const_tree p = t;
1952 #ifdef ENABLE_TREE_CHECKING
1953 const_tree q = t;
1954 #endif
1955 int len = 0;
1956
1957 while (p)
1958 {
1959 p = TREE_CHAIN (p);
1960 #ifdef ENABLE_TREE_CHECKING
1961 if (len % 2)
1962 q = TREE_CHAIN (q);
1963 gcc_assert (p != q);
1964 #endif
1965 len++;
1966 }
1967
1968 return len;
1969 }
1970
1971 /* Returns the number of FIELD_DECLs in TYPE. */
1972
1973 int
1974 fields_length (const_tree type)
1975 {
1976 tree t = TYPE_FIELDS (type);
1977 int count = 0;
1978
1979 for (; t; t = TREE_CHAIN (t))
1980 if (TREE_CODE (t) == FIELD_DECL)
1981 ++count;
1982
1983 return count;
1984 }
1985
1986 /* Concatenate two chains of nodes (chained through TREE_CHAIN)
1987 by modifying the last node in chain 1 to point to chain 2.
1988 This is the Lisp primitive `nconc'. */
1989
1990 tree
1991 chainon (tree op1, tree op2)
1992 {
1993 tree t1;
1994
1995 if (!op1)
1996 return op2;
1997 if (!op2)
1998 return op1;
1999
2000 for (t1 = op1; TREE_CHAIN (t1); t1 = TREE_CHAIN (t1))
2001 continue;
2002 TREE_CHAIN (t1) = op2;
2003
2004 #ifdef ENABLE_TREE_CHECKING
2005 {
2006 tree t2;
2007 for (t2 = op2; t2; t2 = TREE_CHAIN (t2))
2008 gcc_assert (t2 != t1);
2009 }
2010 #endif
2011
2012 return op1;
2013 }
2014
2015 /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
2016
2017 tree
2018 tree_last (tree chain)
2019 {
2020 tree next;
2021 if (chain)
2022 while ((next = TREE_CHAIN (chain)))
2023 chain = next;
2024 return chain;
2025 }
2026
2027 /* Reverse the order of elements in the chain T,
2028 and return the new head of the chain (old last element). */
2029
2030 tree
2031 nreverse (tree t)
2032 {
2033 tree prev = 0, decl, next;
2034 for (decl = t; decl; decl = next)
2035 {
2036 next = TREE_CHAIN (decl);
2037 TREE_CHAIN (decl) = prev;
2038 prev = decl;
2039 }
2040 return prev;
2041 }
2042
2043 /* Return a newly created TREE_LIST node whose
2044 purpose and value fields are PARM and VALUE. */
2045
2046 tree
2047 build_tree_list_stat (tree parm, tree value MEM_STAT_DECL)
2048 {
2049 tree t = make_node_stat (TREE_LIST PASS_MEM_STAT);
2050 TREE_PURPOSE (t) = parm;
2051 TREE_VALUE (t) = value;
2052 return t;
2053 }
2054
2055 /* Build a chain of TREE_LIST nodes from a vector. */
2056
2057 tree
2058 build_tree_list_vec_stat (const VEC(tree,gc) *vec MEM_STAT_DECL)
2059 {
2060 tree ret = NULL_TREE;
2061 tree *pp = &ret;
2062 unsigned int i;
2063 tree t;
2064 for (i = 0; VEC_iterate (tree, vec, i, t); ++i)
2065 {
2066 *pp = build_tree_list_stat (NULL, t PASS_MEM_STAT);
2067 pp = &TREE_CHAIN (*pp);
2068 }
2069 return ret;
2070 }
2071
2072 /* Return a newly created TREE_LIST node whose
2073 purpose and value fields are PURPOSE and VALUE
2074 and whose TREE_CHAIN is CHAIN. */
2075
2076 tree
2077 tree_cons_stat (tree purpose, tree value, tree chain MEM_STAT_DECL)
2078 {
2079 tree node;
2080
2081 node = (tree) ggc_alloc_zone_pass_stat (sizeof (struct tree_list), &tree_zone);
2082
2083 memset (node, 0, sizeof (struct tree_common));
2084
2085 #ifdef GATHER_STATISTICS
2086 tree_node_counts[(int) x_kind]++;
2087 tree_node_sizes[(int) x_kind] += sizeof (struct tree_list);
2088 #endif
2089
2090 TREE_SET_CODE (node, TREE_LIST);
2091 TREE_CHAIN (node) = chain;
2092 TREE_PURPOSE (node) = purpose;
2093 TREE_VALUE (node) = value;
2094 return node;
2095 }
2096
2097 /* Return the elements of a CONSTRUCTOR as a TREE_LIST. */
2098
2099 tree
2100 ctor_to_list (tree ctor)
2101 {
2102 tree list = NULL_TREE;
2103 tree *p = &list;
2104 unsigned ix;
2105 tree purpose, val;
2106
2107 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), ix, purpose, val)
2108 {
2109 *p = build_tree_list (purpose, val);
2110 p = &TREE_CHAIN (*p);
2111 }
2112
2113 return list;
2114 }
2115
2116 /* Return the values of the elements of a CONSTRUCTOR as a vector of
2117 trees. */
2118
2119 VEC(tree,gc) *
2120 ctor_to_vec (tree ctor)
2121 {
2122 VEC(tree, gc) *vec = VEC_alloc (tree, gc, CONSTRUCTOR_NELTS (ctor));
2123 unsigned int ix;
2124 tree val;
2125
2126 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor), ix, val)
2127 VEC_quick_push (tree, vec, val);
2128
2129 return vec;
2130 }
2131
2132 /* Return the size nominally occupied by an object of type TYPE
2133 when it resides in memory. The value is measured in units of bytes,
2134 and its data type is that normally used for type sizes
2135 (which is the first type created by make_signed_type or
2136 make_unsigned_type). */
2137
2138 tree
2139 size_in_bytes (const_tree type)
2140 {
2141 tree t;
2142
2143 if (type == error_mark_node)
2144 return integer_zero_node;
2145
2146 type = TYPE_MAIN_VARIANT (type);
2147 t = TYPE_SIZE_UNIT (type);
2148
2149 if (t == 0)
2150 {
2151 lang_hooks.types.incomplete_type_error (NULL_TREE, type);
2152 return size_zero_node;
2153 }
2154
2155 return t;
2156 }
2157
2158 /* Return the size of TYPE (in bytes) as a wide integer
2159 or return -1 if the size can vary or is larger than an integer. */
2160
2161 HOST_WIDE_INT
2162 int_size_in_bytes (const_tree type)
2163 {
2164 tree t;
2165
2166 if (type == error_mark_node)
2167 return 0;
2168
2169 type = TYPE_MAIN_VARIANT (type);
2170 t = TYPE_SIZE_UNIT (type);
2171 if (t == 0
2172 || TREE_CODE (t) != INTEGER_CST
2173 || TREE_INT_CST_HIGH (t) != 0
2174 /* If the result would appear negative, it's too big to represent. */
2175 || (HOST_WIDE_INT) TREE_INT_CST_LOW (t) < 0)
2176 return -1;
2177
2178 return TREE_INT_CST_LOW (t);
2179 }
2180
2181 /* Return the maximum size of TYPE (in bytes) as a wide integer
2182 or return -1 if the size can vary or is larger than an integer. */
2183
2184 HOST_WIDE_INT
2185 max_int_size_in_bytes (const_tree type)
2186 {
2187 HOST_WIDE_INT size = -1;
2188 tree size_tree;
2189
2190 /* If this is an array type, check for a possible MAX_SIZE attached. */
2191
2192 if (TREE_CODE (type) == ARRAY_TYPE)
2193 {
2194 size_tree = TYPE_ARRAY_MAX_SIZE (type);
2195
2196 if (size_tree && host_integerp (size_tree, 1))
2197 size = tree_low_cst (size_tree, 1);
2198 }
2199
2200 /* If we still haven't been able to get a size, see if the language
2201 can compute a maximum size. */
2202
2203 if (size == -1)
2204 {
2205 size_tree = lang_hooks.types.max_size (type);
2206
2207 if (size_tree && host_integerp (size_tree, 1))
2208 size = tree_low_cst (size_tree, 1);
2209 }
2210
2211 return size;
2212 }
2213
2214 /* Returns a tree for the size of EXP in bytes. */
2215
2216 tree
2217 tree_expr_size (const_tree exp)
2218 {
2219 if (DECL_P (exp)
2220 && DECL_SIZE_UNIT (exp) != 0)
2221 return DECL_SIZE_UNIT (exp);
2222 else
2223 return size_in_bytes (TREE_TYPE (exp));
2224 }
2225
2226 /* Return the bit position of FIELD, in bits from the start of the record.
2227 This is a tree of type bitsizetype. */
2228
2229 tree
2230 bit_position (const_tree field)
2231 {
2232 return bit_from_pos (DECL_FIELD_OFFSET (field),
2233 DECL_FIELD_BIT_OFFSET (field));
2234 }
2235
2236 /* Likewise, but return as an integer. It must be representable in
2237 that way (since it could be a signed value, we don't have the
2238 option of returning -1 like int_size_in_byte can. */
2239
2240 HOST_WIDE_INT
2241 int_bit_position (const_tree field)
2242 {
2243 return tree_low_cst (bit_position (field), 0);
2244 }
2245
2246 /* Return the byte position of FIELD, in bytes from the start of the record.
2247 This is a tree of type sizetype. */
2248
2249 tree
2250 byte_position (const_tree field)
2251 {
2252 return byte_from_pos (DECL_FIELD_OFFSET (field),
2253 DECL_FIELD_BIT_OFFSET (field));
2254 }
2255
2256 /* Likewise, but return as an integer. It must be representable in
2257 that way (since it could be a signed value, we don't have the
2258 option of returning -1 like int_size_in_byte can. */
2259
2260 HOST_WIDE_INT
2261 int_byte_position (const_tree field)
2262 {
2263 return tree_low_cst (byte_position (field), 0);
2264 }
2265
2266 /* Return the strictest alignment, in bits, that T is known to have. */
2267
2268 unsigned int
2269 expr_align (const_tree t)
2270 {
2271 unsigned int align0, align1;
2272
2273 switch (TREE_CODE (t))
2274 {
2275 CASE_CONVERT: case NON_LVALUE_EXPR:
2276 /* If we have conversions, we know that the alignment of the
2277 object must meet each of the alignments of the types. */
2278 align0 = expr_align (TREE_OPERAND (t, 0));
2279 align1 = TYPE_ALIGN (TREE_TYPE (t));
2280 return MAX (align0, align1);
2281
2282 case SAVE_EXPR: case COMPOUND_EXPR: case MODIFY_EXPR:
2283 case INIT_EXPR: case TARGET_EXPR: case WITH_CLEANUP_EXPR:
2284 case CLEANUP_POINT_EXPR:
2285 /* These don't change the alignment of an object. */
2286 return expr_align (TREE_OPERAND (t, 0));
2287
2288 case COND_EXPR:
2289 /* The best we can do is say that the alignment is the least aligned
2290 of the two arms. */
2291 align0 = expr_align (TREE_OPERAND (t, 1));
2292 align1 = expr_align (TREE_OPERAND (t, 2));
2293 return MIN (align0, align1);
2294
2295 /* FIXME: LABEL_DECL and CONST_DECL never have DECL_ALIGN set
2296 meaningfully, it's always 1. */
2297 case LABEL_DECL: case CONST_DECL:
2298 case VAR_DECL: case PARM_DECL: case RESULT_DECL:
2299 case FUNCTION_DECL:
2300 gcc_assert (DECL_ALIGN (t) != 0);
2301 return DECL_ALIGN (t);
2302
2303 default:
2304 break;
2305 }
2306
2307 /* Otherwise take the alignment from that of the type. */
2308 return TYPE_ALIGN (TREE_TYPE (t));
2309 }
2310
2311 /* Return, as a tree node, the number of elements for TYPE (which is an
2312 ARRAY_TYPE) minus one. This counts only elements of the top array. */
2313
2314 tree
2315 array_type_nelts (const_tree type)
2316 {
2317 tree index_type, min, max;
2318
2319 /* If they did it with unspecified bounds, then we should have already
2320 given an error about it before we got here. */
2321 if (! TYPE_DOMAIN (type))
2322 return error_mark_node;
2323
2324 index_type = TYPE_DOMAIN (type);
2325 min = TYPE_MIN_VALUE (index_type);
2326 max = TYPE_MAX_VALUE (index_type);
2327
2328 return (integer_zerop (min)
2329 ? max
2330 : fold_build2 (MINUS_EXPR, TREE_TYPE (max), max, min));
2331 }
2332
2333 /* If arg is static -- a reference to an object in static storage -- then
2334 return the object. This is not the same as the C meaning of `static'.
2335 If arg isn't static, return NULL. */
2336
2337 tree
2338 staticp (tree arg)
2339 {
2340 switch (TREE_CODE (arg))
2341 {
2342 case FUNCTION_DECL:
2343 /* Nested functions are static, even though taking their address will
2344 involve a trampoline as we unnest the nested function and create
2345 the trampoline on the tree level. */
2346 return arg;
2347
2348 case VAR_DECL:
2349 return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
2350 && ! DECL_THREAD_LOCAL_P (arg)
2351 && ! DECL_DLLIMPORT_P (arg)
2352 ? arg : NULL);
2353
2354 case CONST_DECL:
2355 return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
2356 ? arg : NULL);
2357
2358 case CONSTRUCTOR:
2359 return TREE_STATIC (arg) ? arg : NULL;
2360
2361 case LABEL_DECL:
2362 case STRING_CST:
2363 return arg;
2364
2365 case COMPONENT_REF:
2366 /* If the thing being referenced is not a field, then it is
2367 something language specific. */
2368 gcc_assert (TREE_CODE (TREE_OPERAND (arg, 1)) == FIELD_DECL);
2369
2370 /* If we are referencing a bitfield, we can't evaluate an
2371 ADDR_EXPR at compile time and so it isn't a constant. */
2372 if (DECL_BIT_FIELD (TREE_OPERAND (arg, 1)))
2373 return NULL;
2374
2375 return staticp (TREE_OPERAND (arg, 0));
2376
2377 case BIT_FIELD_REF:
2378 return NULL;
2379
2380 case MISALIGNED_INDIRECT_REF:
2381 case ALIGN_INDIRECT_REF:
2382 case INDIRECT_REF:
2383 return TREE_CONSTANT (TREE_OPERAND (arg, 0)) ? arg : NULL;
2384
2385 case ARRAY_REF:
2386 case ARRAY_RANGE_REF:
2387 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST
2388 && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST)
2389 return staticp (TREE_OPERAND (arg, 0));
2390 else
2391 return NULL;
2392
2393 case COMPOUND_LITERAL_EXPR:
2394 return TREE_STATIC (COMPOUND_LITERAL_EXPR_DECL (arg)) ? arg : NULL;
2395
2396 default:
2397 return NULL;
2398 }
2399 }
2400
2401
2402
2403
2404 /* Return whether OP is a DECL whose address is function-invariant. */
2405
2406 bool
2407 decl_address_invariant_p (const_tree op)
2408 {
2409 /* The conditions below are slightly less strict than the one in
2410 staticp. */
2411
2412 switch (TREE_CODE (op))
2413 {
2414 case PARM_DECL:
2415 case RESULT_DECL:
2416 case LABEL_DECL:
2417 case FUNCTION_DECL:
2418 return true;
2419
2420 case VAR_DECL:
2421 if (((TREE_STATIC (op) || DECL_EXTERNAL (op))
2422 && !DECL_DLLIMPORT_P (op))
2423 || DECL_THREAD_LOCAL_P (op)
2424 || DECL_CONTEXT (op) == current_function_decl
2425 || decl_function_context (op) == current_function_decl)
2426 return true;
2427 break;
2428
2429 case CONST_DECL:
2430 if ((TREE_STATIC (op) || DECL_EXTERNAL (op))
2431 || decl_function_context (op) == current_function_decl)
2432 return true;
2433 break;
2434
2435 default:
2436 break;
2437 }
2438
2439 return false;
2440 }
2441
2442 /* Return whether OP is a DECL whose address is interprocedural-invariant. */
2443
2444 bool
2445 decl_address_ip_invariant_p (const_tree op)
2446 {
2447 /* The conditions below are slightly less strict than the one in
2448 staticp. */
2449
2450 switch (TREE_CODE (op))
2451 {
2452 case LABEL_DECL:
2453 case FUNCTION_DECL:
2454 case STRING_CST:
2455 return true;
2456
2457 case VAR_DECL:
2458 if (((TREE_STATIC (op) || DECL_EXTERNAL (op))
2459 && !DECL_DLLIMPORT_P (op))
2460 || DECL_THREAD_LOCAL_P (op))
2461 return true;
2462 break;
2463
2464 case CONST_DECL:
2465 if ((TREE_STATIC (op) || DECL_EXTERNAL (op)))
2466 return true;
2467 break;
2468
2469 default:
2470 break;
2471 }
2472
2473 return false;
2474 }
2475
2476
2477 /* Return true if T is function-invariant (internal function, does
2478 not handle arithmetic; that's handled in skip_simple_arithmetic and
2479 tree_invariant_p). */
2480
2481 static bool tree_invariant_p (tree t);
2482
2483 static bool
2484 tree_invariant_p_1 (tree t)
2485 {
2486 tree op;
2487
2488 if (TREE_CONSTANT (t)
2489 || (TREE_READONLY (t) && !TREE_SIDE_EFFECTS (t)))
2490 return true;
2491
2492 switch (TREE_CODE (t))
2493 {
2494 case SAVE_EXPR:
2495 return true;
2496
2497 case ADDR_EXPR:
2498 op = TREE_OPERAND (t, 0);
2499 while (handled_component_p (op))
2500 {
2501 switch (TREE_CODE (op))
2502 {
2503 case ARRAY_REF:
2504 case ARRAY_RANGE_REF:
2505 if (!tree_invariant_p (TREE_OPERAND (op, 1))
2506 || TREE_OPERAND (op, 2) != NULL_TREE
2507 || TREE_OPERAND (op, 3) != NULL_TREE)
2508 return false;
2509 break;
2510
2511 case COMPONENT_REF:
2512 if (TREE_OPERAND (op, 2) != NULL_TREE)
2513 return false;
2514 break;
2515
2516 default:;
2517 }
2518 op = TREE_OPERAND (op, 0);
2519 }
2520
2521 return CONSTANT_CLASS_P (op) || decl_address_invariant_p (op);
2522
2523 default:
2524 break;
2525 }
2526
2527 return false;
2528 }
2529
2530 /* Return true if T is function-invariant. */
2531
2532 static bool
2533 tree_invariant_p (tree t)
2534 {
2535 tree inner = skip_simple_arithmetic (t);
2536 return tree_invariant_p_1 (inner);
2537 }
2538
2539 /* Wrap a SAVE_EXPR around EXPR, if appropriate.
2540 Do this to any expression which may be used in more than one place,
2541 but must be evaluated only once.
2542
2543 Normally, expand_expr would reevaluate the expression each time.
2544 Calling save_expr produces something that is evaluated and recorded
2545 the first time expand_expr is called on it. Subsequent calls to
2546 expand_expr just reuse the recorded value.
2547
2548 The call to expand_expr that generates code that actually computes
2549 the value is the first call *at compile time*. Subsequent calls
2550 *at compile time* generate code to use the saved value.
2551 This produces correct result provided that *at run time* control
2552 always flows through the insns made by the first expand_expr
2553 before reaching the other places where the save_expr was evaluated.
2554 You, the caller of save_expr, must make sure this is so.
2555
2556 Constants, and certain read-only nodes, are returned with no
2557 SAVE_EXPR because that is safe. Expressions containing placeholders
2558 are not touched; see tree.def for an explanation of what these
2559 are used for. */
2560
2561 tree
2562 save_expr (tree expr)
2563 {
2564 tree t = fold (expr);
2565 tree inner;
2566
2567 /* If the tree evaluates to a constant, then we don't want to hide that
2568 fact (i.e. this allows further folding, and direct checks for constants).
2569 However, a read-only object that has side effects cannot be bypassed.
2570 Since it is no problem to reevaluate literals, we just return the
2571 literal node. */
2572 inner = skip_simple_arithmetic (t);
2573 if (TREE_CODE (inner) == ERROR_MARK)
2574 return inner;
2575
2576 if (tree_invariant_p_1 (inner))
2577 return t;
2578
2579 /* If INNER contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
2580 it means that the size or offset of some field of an object depends on
2581 the value within another field.
2582
2583 Note that it must not be the case that T contains both a PLACEHOLDER_EXPR
2584 and some variable since it would then need to be both evaluated once and
2585 evaluated more than once. Front-ends must assure this case cannot
2586 happen by surrounding any such subexpressions in their own SAVE_EXPR
2587 and forcing evaluation at the proper time. */
2588 if (contains_placeholder_p (inner))
2589 return t;
2590
2591 t = build1 (SAVE_EXPR, TREE_TYPE (expr), t);
2592 SET_EXPR_LOCATION (t, EXPR_LOCATION (expr));
2593
2594 /* This expression might be placed ahead of a jump to ensure that the
2595 value was computed on both sides of the jump. So make sure it isn't
2596 eliminated as dead. */
2597 TREE_SIDE_EFFECTS (t) = 1;
2598 return t;
2599 }
2600
2601 /* Look inside EXPR and into any simple arithmetic operations. Return
2602 the innermost non-arithmetic node. */
2603
2604 tree
2605 skip_simple_arithmetic (tree expr)
2606 {
2607 tree inner;
2608
2609 /* We don't care about whether this can be used as an lvalue in this
2610 context. */
2611 while (TREE_CODE (expr) == NON_LVALUE_EXPR)
2612 expr = TREE_OPERAND (expr, 0);
2613
2614 /* If we have simple operations applied to a SAVE_EXPR or to a SAVE_EXPR and
2615 a constant, it will be more efficient to not make another SAVE_EXPR since
2616 it will allow better simplification and GCSE will be able to merge the
2617 computations if they actually occur. */
2618 inner = expr;
2619 while (1)
2620 {
2621 if (UNARY_CLASS_P (inner))
2622 inner = TREE_OPERAND (inner, 0);
2623 else if (BINARY_CLASS_P (inner))
2624 {
2625 if (tree_invariant_p (TREE_OPERAND (inner, 1)))
2626 inner = TREE_OPERAND (inner, 0);
2627 else if (tree_invariant_p (TREE_OPERAND (inner, 0)))
2628 inner = TREE_OPERAND (inner, 1);
2629 else
2630 break;
2631 }
2632 else
2633 break;
2634 }
2635
2636 return inner;
2637 }
2638
2639
2640 /* Return which tree structure is used by T. */
2641
2642 enum tree_node_structure_enum
2643 tree_node_structure (const_tree t)
2644 {
2645 const enum tree_code code = TREE_CODE (t);
2646 return tree_node_structure_for_code (code);
2647 }
2648
2649 /* Set various status flags when building a CALL_EXPR object T. */
2650
2651 static void
2652 process_call_operands (tree t)
2653 {
2654 bool side_effects = TREE_SIDE_EFFECTS (t);
2655 bool read_only = false;
2656 int i = call_expr_flags (t);
2657
2658 /* Calls have side-effects, except those to const or pure functions. */
2659 if ((i & ECF_LOOPING_CONST_OR_PURE) || !(i & (ECF_CONST | ECF_PURE)))
2660 side_effects = true;
2661 /* Propagate TREE_READONLY of arguments for const functions. */
2662 if (i & ECF_CONST)
2663 read_only = true;
2664
2665 if (!side_effects || read_only)
2666 for (i = 1; i < TREE_OPERAND_LENGTH (t); i++)
2667 {
2668 tree op = TREE_OPERAND (t, i);
2669 if (op && TREE_SIDE_EFFECTS (op))
2670 side_effects = true;
2671 if (op && !TREE_READONLY (op) && !CONSTANT_CLASS_P (op))
2672 read_only = false;
2673 }
2674
2675 TREE_SIDE_EFFECTS (t) = side_effects;
2676 TREE_READONLY (t) = read_only;
2677 }
2460 2678
2461 /* Return 1 if EXP contains a PLACEHOLDER_EXPR; i.e., if it represents a size 2679 /* Return 1 if EXP contains a PLACEHOLDER_EXPR; i.e., if it represents a size
2462 or offset that depends on a field within a record. */ 2680 or offset that depends on a field within a record. */
2463 2681
2464 bool 2682 bool
2631 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = result + 1; 2849 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = result + 1;
2632 2850
2633 return result; 2851 return result;
2634 } 2852 }
2635 2853
2636 /* Given a tree EXP, a FIELD_DECL F, and a replacement value R, 2854 /* Push tree EXP onto vector QUEUE if it is not already present. */
2637 return a tree with all occurrences of references to F in a 2855
2638 PLACEHOLDER_EXPR replaced by R. Note that we assume here that EXP 2856 static void
2639 contains only arithmetic expressions or a CALL_EXPR with a 2857 push_without_duplicates (tree exp, VEC (tree, heap) **queue)
2640 PLACEHOLDER_EXPR occurring only in its arglist. */ 2858 {
2641 2859 unsigned int i;
2642 tree 2860 tree iter;
2643 substitute_in_expr (tree exp, tree f, tree r) 2861
2862 for (i = 0; VEC_iterate (tree, *queue, i, iter); i++)
2863 if (simple_cst_equal (iter, exp) == 1)
2864 break;
2865
2866 if (!iter)
2867 VEC_safe_push (tree, heap, *queue, exp);
2868 }
2869
2870 /* Given a tree EXP, find all occurences of references to fields
2871 in a PLACEHOLDER_EXPR and place them in vector REFS without
2872 duplicates. Also record VAR_DECLs and CONST_DECLs. Note that
2873 we assume here that EXP contains only arithmetic expressions
2874 or CALL_EXPRs with PLACEHOLDER_EXPRs occurring only in their
2875 argument list. */
2876
2877 void
2878 find_placeholder_in_expr (tree exp, VEC (tree, heap) **refs)
2644 { 2879 {
2645 enum tree_code code = TREE_CODE (exp); 2880 enum tree_code code = TREE_CODE (exp);
2646 tree op0, op1, op2, op3; 2881 tree inner;
2647 tree new_tree, inner; 2882 int i;
2648 2883
2649 /* We handle TREE_LIST and COMPONENT_REF separately. */ 2884 /* We handle TREE_LIST and COMPONENT_REF separately. */
2650 if (code == TREE_LIST) 2885 if (code == TREE_LIST)
2651 { 2886 {
2652 op0 = SUBSTITUTE_IN_EXPR (TREE_CHAIN (exp), f, r); 2887 FIND_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp), refs);
2653 op1 = SUBSTITUTE_IN_EXPR (TREE_VALUE (exp), f, r); 2888 FIND_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp), refs);
2654 if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
2655 return exp;
2656
2657 return tree_cons (TREE_PURPOSE (exp), op1, op0);
2658 } 2889 }
2659 else if (code == COMPONENT_REF) 2890 else if (code == COMPONENT_REF)
2660 { 2891 {
2661 /* If this expression is getting a value from a PLACEHOLDER_EXPR 2892 for (inner = TREE_OPERAND (exp, 0);
2662 and it is the right field, replace it with R. */ 2893 REFERENCE_CLASS_P (inner);
2663 for (inner = TREE_OPERAND (exp, 0); 2894 inner = TREE_OPERAND (inner, 0))
2664 REFERENCE_CLASS_P (inner); 2895 ;
2665 inner = TREE_OPERAND (inner, 0)) 2896
2666 ; 2897 if (TREE_CODE (inner) == PLACEHOLDER_EXPR)
2667 if (TREE_CODE (inner) == PLACEHOLDER_EXPR 2898 push_without_duplicates (exp, refs);
2668 && TREE_OPERAND (exp, 1) == f) 2899 else
2669 return r; 2900 FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), refs);
2670
2671 /* If this expression hasn't been completed let, leave it alone. */
2672 if (TREE_CODE (inner) == PLACEHOLDER_EXPR && TREE_TYPE (inner) == 0)
2673 return exp;
2674
2675 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
2676 if (op0 == TREE_OPERAND (exp, 0))
2677 return exp;
2678
2679 new_tree = fold_build3 (COMPONENT_REF, TREE_TYPE (exp),
2680 op0, TREE_OPERAND (exp, 1), NULL_TREE);
2681 } 2901 }
2682 else 2902 else
2683 switch (TREE_CODE_CLASS (code)) 2903 switch (TREE_CODE_CLASS (code))
2684 { 2904 {
2685 case tcc_constant: 2905 case tcc_constant:
2906 break;
2907
2686 case tcc_declaration: 2908 case tcc_declaration:
2687 return exp; 2909 /* Variables allocated to static storage can stay. */
2910 if (!TREE_STATIC (exp))
2911 push_without_duplicates (exp, refs);
2912 break;
2913
2914 case tcc_expression:
2915 /* This is the pattern built in ada/make_aligning_type. */
2916 if (code == ADDR_EXPR
2917 && TREE_CODE (TREE_OPERAND (exp, 0)) == PLACEHOLDER_EXPR)
2918 {
2919 push_without_duplicates (exp, refs);
2920 break;
2921 }
2922
2923 /* Fall through... */
2688 2924
2689 case tcc_exceptional: 2925 case tcc_exceptional:
2690 case tcc_unary: 2926 case tcc_unary:
2691 case tcc_binary: 2927 case tcc_binary:
2692 case tcc_comparison: 2928 case tcc_comparison:
2929 case tcc_reference:
2930 for (i = 0; i < TREE_CODE_LENGTH (code); i++)
2931 FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, i), refs);
2932 break;
2933
2934 case tcc_vl_exp:
2935 for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++)
2936 FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, i), refs);
2937 break;
2938
2939 default:
2940 gcc_unreachable ();
2941 }
2942 }
2943
2944 /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
2945 return a tree with all occurrences of references to F in a
2946 PLACEHOLDER_EXPR replaced by R. Also handle VAR_DECLs and
2947 CONST_DECLs. Note that we assume here that EXP contains only
2948 arithmetic expressions or CALL_EXPRs with PLACEHOLDER_EXPRs
2949 occurring only in their argument list. */
2950
2951 tree
2952 substitute_in_expr (tree exp, tree f, tree r)
2953 {
2954 enum tree_code code = TREE_CODE (exp);
2955 tree op0, op1, op2, op3;
2956 tree new_tree;
2957
2958 /* We handle TREE_LIST and COMPONENT_REF separately. */
2959 if (code == TREE_LIST)
2960 {
2961 op0 = SUBSTITUTE_IN_EXPR (TREE_CHAIN (exp), f, r);
2962 op1 = SUBSTITUTE_IN_EXPR (TREE_VALUE (exp), f, r);
2963 if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
2964 return exp;
2965
2966 return tree_cons (TREE_PURPOSE (exp), op1, op0);
2967 }
2968 else if (code == COMPONENT_REF)
2969 {
2970 tree inner;
2971
2972 /* If this expression is getting a value from a PLACEHOLDER_EXPR
2973 and it is the right field, replace it with R. */
2974 for (inner = TREE_OPERAND (exp, 0);
2975 REFERENCE_CLASS_P (inner);
2976 inner = TREE_OPERAND (inner, 0))
2977 ;
2978
2979 /* The field. */
2980 op1 = TREE_OPERAND (exp, 1);
2981
2982 if (TREE_CODE (inner) == PLACEHOLDER_EXPR && op1 == f)
2983 return r;
2984
2985 /* If this expression hasn't been completed let, leave it alone. */
2986 if (TREE_CODE (inner) == PLACEHOLDER_EXPR && !TREE_TYPE (inner))
2987 return exp;
2988
2989 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
2990 if (op0 == TREE_OPERAND (exp, 0))
2991 return exp;
2992
2993 new_tree
2994 = fold_build3 (COMPONENT_REF, TREE_TYPE (exp), op0, op1, NULL_TREE);
2995 }
2996 else
2997 switch (TREE_CODE_CLASS (code))
2998 {
2999 case tcc_constant:
3000 return exp;
3001
3002 case tcc_declaration:
3003 if (exp == f)
3004 return r;
3005 else
3006 return exp;
3007
2693 case tcc_expression: 3008 case tcc_expression:
3009 if (exp == f)
3010 return r;
3011
3012 /* Fall through... */
3013
3014 case tcc_exceptional:
3015 case tcc_unary:
3016 case tcc_binary:
3017 case tcc_comparison:
2694 case tcc_reference: 3018 case tcc_reference:
2695 switch (TREE_CODE_LENGTH (code)) 3019 switch (TREE_CODE_LENGTH (code))
2696 { 3020 {
2697 case 0: 3021 case 0:
2698 return exp; 3022 return exp;
2736 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1) 3060 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
2737 && op2 == TREE_OPERAND (exp, 2) 3061 && op2 == TREE_OPERAND (exp, 2)
2738 && op3 == TREE_OPERAND (exp, 3)) 3062 && op3 == TREE_OPERAND (exp, 3))
2739 return exp; 3063 return exp;
2740 3064
2741 new_tree = fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3)); 3065 new_tree
3066 = fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3));
2742 break; 3067 break;
2743 3068
2744 default: 3069 default:
2745 gcc_unreachable (); 3070 gcc_unreachable ();
2746 } 3071 }
2747 break; 3072 break;
2748 3073
2749 case tcc_vl_exp: 3074 case tcc_vl_exp:
2750 { 3075 {
2751 tree copy = NULL_TREE;
2752 int i; 3076 int i;
3077
3078 new_tree = NULL_TREE;
3079
3080 /* If we are trying to replace F with a constant, inline back
3081 functions which do nothing else than computing a value from
3082 the arguments they are passed. This makes it possible to
3083 fold partially or entirely the replacement expression. */
3084 if (CONSTANT_CLASS_P (r) && code == CALL_EXPR)
3085 {
3086 tree t = maybe_inline_call_in_expr (exp);
3087 if (t)
3088 return SUBSTITUTE_IN_EXPR (t, f, r);
3089 }
2753 3090
2754 for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++) 3091 for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++)
2755 { 3092 {
2756 tree op = TREE_OPERAND (exp, i); 3093 tree op = TREE_OPERAND (exp, i);
2757 tree new_op = SUBSTITUTE_IN_EXPR (op, f, r); 3094 tree new_op = SUBSTITUTE_IN_EXPR (op, f, r);
2758 if (new_op != op) 3095 if (new_op != op)
2759 { 3096 {
2760 if (!copy) 3097 if (!new_tree)
2761 copy = copy_node (exp); 3098 new_tree = copy_node (exp);
2762 TREE_OPERAND (copy, i) = new_op; 3099 TREE_OPERAND (new_tree, i) = new_op;
2763 } 3100 }
2764 } 3101 }
2765 3102
2766 if (copy) 3103 if (new_tree)
2767 new_tree = fold (copy); 3104 {
3105 new_tree = fold (new_tree);
3106 if (TREE_CODE (new_tree) == CALL_EXPR)
3107 process_call_operands (new_tree);
3108 }
2768 else 3109 else
2769 return exp; 3110 return exp;
2770 } 3111 }
2771 break; 3112 break;
2772 3113
2773 default: 3114 default:
2774 gcc_unreachable (); 3115 gcc_unreachable ();
2775 } 3116 }
2776 3117
2777 TREE_READONLY (new_tree) = TREE_READONLY (exp); 3118 TREE_READONLY (new_tree) |= TREE_READONLY (exp);
2778 return new_tree; 3119 return new_tree;
2779 } 3120 }
2780 3121
2781 /* Similar, but look for a PLACEHOLDER_EXPR in EXP and find a replacement 3122 /* Similar, but look for a PLACEHOLDER_EXPR in EXP and find a replacement
2782 for it within OBJ, a tree that is an object or a chain of references. */ 3123 for it within OBJ, a tree that is an object or a chain of references. */
2784 tree 3125 tree
2785 substitute_placeholder_in_expr (tree exp, tree obj) 3126 substitute_placeholder_in_expr (tree exp, tree obj)
2786 { 3127 {
2787 enum tree_code code = TREE_CODE (exp); 3128 enum tree_code code = TREE_CODE (exp);
2788 tree op0, op1, op2, op3; 3129 tree op0, op1, op2, op3;
3130 tree new_tree;
2789 3131
2790 /* If this is a PLACEHOLDER_EXPR, see if we find a corresponding type 3132 /* If this is a PLACEHOLDER_EXPR, see if we find a corresponding type
2791 in the chain of OBJ. */ 3133 in the chain of OBJ. */
2792 if (code == PLACEHOLDER_EXPR) 3134 if (code == PLACEHOLDER_EXPR)
2793 { 3135 {
2859 3201
2860 case 1: 3202 case 1:
2861 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj); 3203 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
2862 if (op0 == TREE_OPERAND (exp, 0)) 3204 if (op0 == TREE_OPERAND (exp, 0))
2863 return exp; 3205 return exp;
2864 else 3206
2865 return fold_build1 (code, TREE_TYPE (exp), op0); 3207 new_tree = fold_build1 (code, TREE_TYPE (exp), op0);
3208 break;
2866 3209
2867 case 2: 3210 case 2:
2868 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj); 3211 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
2869 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj); 3212 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
2870 3213
2871 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)) 3214 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
2872 return exp; 3215 return exp;
2873 else 3216
2874 return fold_build2 (code, TREE_TYPE (exp), op0, op1); 3217 new_tree = fold_build2 (code, TREE_TYPE (exp), op0, op1);
3218 break;
2875 3219
2876 case 3: 3220 case 3:
2877 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj); 3221 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
2878 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj); 3222 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
2879 op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj); 3223 op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj);
2880 3224
2881 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1) 3225 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
2882 && op2 == TREE_OPERAND (exp, 2)) 3226 && op2 == TREE_OPERAND (exp, 2))
2883 return exp; 3227 return exp;
2884 else 3228
2885 return fold_build3 (code, TREE_TYPE (exp), op0, op1, op2); 3229 new_tree = fold_build3 (code, TREE_TYPE (exp), op0, op1, op2);
3230 break;
2886 3231
2887 case 4: 3232 case 4:
2888 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj); 3233 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
2889 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj); 3234 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
2890 op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj); 3235 op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj);
2892 3237
2893 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1) 3238 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
2894 && op2 == TREE_OPERAND (exp, 2) 3239 && op2 == TREE_OPERAND (exp, 2)
2895 && op3 == TREE_OPERAND (exp, 3)) 3240 && op3 == TREE_OPERAND (exp, 3))
2896 return exp; 3241 return exp;
2897 else 3242
2898 return fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3)); 3243 new_tree
3244 = fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3));
3245 break;
2899 3246
2900 default: 3247 default:
2901 gcc_unreachable (); 3248 gcc_unreachable ();
2902 } 3249 }
2903 break; 3250 break;
2904 3251
2905 case tcc_vl_exp: 3252 case tcc_vl_exp:
2906 { 3253 {
2907 tree copy = NULL_TREE;
2908 int i; 3254 int i;
3255
3256 new_tree = NULL_TREE;
2909 3257
2910 for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++) 3258 for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++)
2911 { 3259 {
2912 tree op = TREE_OPERAND (exp, i); 3260 tree op = TREE_OPERAND (exp, i);
2913 tree new_op = SUBSTITUTE_PLACEHOLDER_IN_EXPR (op, obj); 3261 tree new_op = SUBSTITUTE_PLACEHOLDER_IN_EXPR (op, obj);
2914 if (new_op != op) 3262 if (new_op != op)
2915 { 3263 {
2916 if (!copy) 3264 if (!new_tree)
2917 copy = copy_node (exp); 3265 new_tree = copy_node (exp);
2918 TREE_OPERAND (copy, i) = new_op; 3266 TREE_OPERAND (new_tree, i) = new_op;
2919 } 3267 }
2920 } 3268 }
2921 3269
2922 if (copy) 3270 if (new_tree)
2923 return fold (copy); 3271 {
3272 new_tree = fold (new_tree);
3273 if (TREE_CODE (new_tree) == CALL_EXPR)
3274 process_call_operands (new_tree);
3275 }
2924 else 3276 else
2925 return exp; 3277 return exp;
2926 } 3278 }
3279 break;
2927 3280
2928 default: 3281 default:
2929 gcc_unreachable (); 3282 gcc_unreachable ();
2930 } 3283 }
3284
3285 TREE_READONLY (new_tree) |= TREE_READONLY (exp);
3286 return new_tree;
2931 } 3287 }
2932 3288
2933 /* Stabilize a reference so that we can use it any number of times 3289 /* Stabilize a reference so that we can use it any number of times
2934 without causing its operands to be evaluated more than once. 3290 without causing its operands to be evaluated more than once.
2935 Returns the stabilized reference. This works by means of save_expr, 3291 Returns the stabilized reference. This works by means of save_expr,
3273 } 3629 }
3274 3630
3275 return t; 3631 return t;
3276 } 3632 }
3277 3633
3278 #define PROCESS_ARG(N) \ 3634 #define PROCESS_ARG(N) \
3279 do { \ 3635 do { \
3280 TREE_OPERAND (t, N) = arg##N; \ 3636 TREE_OPERAND (t, N) = arg##N; \
3281 if (arg##N &&!TYPE_P (arg##N)) \ 3637 if (arg##N &&!TYPE_P (arg##N)) \
3282 { \ 3638 { \
3283 if (TREE_SIDE_EFFECTS (arg##N)) \ 3639 if (TREE_SIDE_EFFECTS (arg##N)) \
3284 side_effects = 1; \ 3640 side_effects = 1; \
3285 if (!TREE_READONLY (arg##N)) \ 3641 if (!TREE_READONLY (arg##N) \
3286 read_only = 0; \ 3642 && !CONSTANT_CLASS_P (arg##N)) \
3287 if (!TREE_CONSTANT (arg##N)) \ 3643 read_only = 0; \
3288 constant = 0; \ 3644 if (!TREE_CONSTANT (arg##N)) \
3289 } \ 3645 constant = 0; \
3646 } \
3290 } while (0) 3647 } while (0)
3291 3648
3292 tree 3649 tree
3293 build2_stat (enum tree_code code, tree tt, tree arg0, tree arg1 MEM_STAT_DECL) 3650 build2_stat (enum tree_code code, tree tt, tree arg0, tree arg1 MEM_STAT_DECL)
3294 { 3651 {
3350 gcc_assert (TREE_CODE_LENGTH (code) == 3); 3707 gcc_assert (TREE_CODE_LENGTH (code) == 3);
3351 gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp); 3708 gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
3352 3709
3353 t = make_node_stat (code PASS_MEM_STAT); 3710 t = make_node_stat (code PASS_MEM_STAT);
3354 TREE_TYPE (t) = tt; 3711 TREE_TYPE (t) = tt;
3712
3713 read_only = 1;
3355 3714
3356 /* As a special exception, if COND_EXPR has NULL branches, we 3715 /* As a special exception, if COND_EXPR has NULL branches, we
3357 assume that it is a gimple statement and always consider 3716 assume that it is a gimple statement and always consider
3358 it to have side effects. */ 3717 it to have side effects. */
3359 if (code == COND_EXPR 3718 if (code == COND_EXPR
3366 3725
3367 PROCESS_ARG(0); 3726 PROCESS_ARG(0);
3368 PROCESS_ARG(1); 3727 PROCESS_ARG(1);
3369 PROCESS_ARG(2); 3728 PROCESS_ARG(2);
3370 3729
3730 if (code == COND_EXPR)
3731 TREE_READONLY (t) = read_only;
3732
3371 TREE_SIDE_EFFECTS (t) = side_effects; 3733 TREE_SIDE_EFFECTS (t) = side_effects;
3372 TREE_THIS_VOLATILE (t) 3734 TREE_THIS_VOLATILE (t)
3373 = (TREE_CODE_CLASS (code) == tcc_reference 3735 = (TREE_CODE_CLASS (code) == tcc_reference
3374 && arg0 && TREE_THIS_VOLATILE (arg0)); 3736 && arg0 && TREE_THIS_VOLATILE (arg0));
3375 3737
3430 3792
3431 return t; 3793 return t;
3432 } 3794 }
3433 3795
3434 tree 3796 tree
3435 build7_stat (enum tree_code code, tree tt, tree arg0, tree arg1, 3797 build6_stat (enum tree_code code, tree tt, tree arg0, tree arg1,
3436 tree arg2, tree arg3, tree arg4, tree arg5, 3798 tree arg2, tree arg3, tree arg4, tree arg5 MEM_STAT_DECL)
3437 tree arg6 MEM_STAT_DECL)
3438 { 3799 {
3439 bool constant, read_only, side_effects; 3800 bool constant, read_only, side_effects;
3440 tree t; 3801 tree t;
3441 3802
3442 gcc_assert (code == TARGET_MEM_REF); 3803 gcc_assert (code == TARGET_MEM_REF);
3450 PROCESS_ARG(1); 3811 PROCESS_ARG(1);
3451 PROCESS_ARG(2); 3812 PROCESS_ARG(2);
3452 PROCESS_ARG(3); 3813 PROCESS_ARG(3);
3453 PROCESS_ARG(4); 3814 PROCESS_ARG(4);
3454 PROCESS_ARG(5); 3815 PROCESS_ARG(5);
3455 PROCESS_ARG(6);
3456 3816
3457 TREE_SIDE_EFFECTS (t) = side_effects; 3817 TREE_SIDE_EFFECTS (t) = side_effects;
3458 TREE_THIS_VOLATILE (t) = 0; 3818 TREE_THIS_VOLATILE (t) = 0;
3459 3819
3460 return t; 3820 return t;
3501 CALL_EXPR_STATIC_CHAIN (t) = NULL_TREE; 3861 CALL_EXPR_STATIC_CHAIN (t) = NULL_TREE;
3502 for (i = 0; arglist; arglist = TREE_CHAIN (arglist), i++) 3862 for (i = 0; arglist; arglist = TREE_CHAIN (arglist), i++)
3503 CALL_EXPR_ARG (t, i) = TREE_VALUE (arglist); 3863 CALL_EXPR_ARG (t, i) = TREE_VALUE (arglist);
3504 return t; 3864 return t;
3505 } 3865 }
3866
3867 /* Similar to build_nt, but for creating a CALL_EXPR object with a
3868 tree VEC. */
3869
3870 tree
3871 build_nt_call_vec (tree fn, VEC(tree,gc) *args)
3872 {
3873 tree ret, t;
3874 unsigned int ix;
3875
3876 ret = build_vl_exp (CALL_EXPR, VEC_length (tree, args) + 3);
3877 CALL_EXPR_FN (ret) = fn;
3878 CALL_EXPR_STATIC_CHAIN (ret) = NULL_TREE;
3879 for (ix = 0; VEC_iterate (tree, args, ix, t); ++ix)
3880 CALL_EXPR_ARG (ret, ix) = t;
3881 return ret;
3882 }
3506 3883
3507 /* Create a DECL_... node of code CODE, name NAME and data type TYPE. 3884 /* Create a DECL_... node of code CODE, name NAME and data type TYPE.
3508 We do NOT enter this node in any sort of symbol table. 3885 We do NOT enter this node in any sort of symbol table.
3509 3886
3887 LOC is the location of the decl.
3888
3510 layout_decl is used to set up the decl's storage layout. 3889 layout_decl is used to set up the decl's storage layout.
3511 Other slots are initialized to 0 or null pointers. */ 3890 Other slots are initialized to 0 or null pointers. */
3512 3891
3513 tree 3892 tree
3514 build_decl_stat (enum tree_code code, tree name, tree type MEM_STAT_DECL) 3893 build_decl_stat (location_t loc, enum tree_code code, tree name,
3894 tree type MEM_STAT_DECL)
3515 { 3895 {
3516 tree t; 3896 tree t;
3517 3897
3518 t = make_node_stat (code PASS_MEM_STAT); 3898 t = make_node_stat (code PASS_MEM_STAT);
3899 DECL_SOURCE_LOCATION (t) = loc;
3519 3900
3520 /* if (type == error_mark_node) 3901 /* if (type == error_mark_node)
3521 type = integer_type_node; */ 3902 type = integer_type_node; */
3522 /* That is not done, deliberately, so that having error_mark_node 3903 /* That is not done, deliberately, so that having error_mark_node
3523 as the type can suppress useless errors in the use of this variable. */ 3904 as the type can suppress useless errors in the use of this variable. */
3535 3916
3536 tree 3917 tree
3537 build_fn_decl (const char *name, tree type) 3918 build_fn_decl (const char *name, tree type)
3538 { 3919 {
3539 tree id = get_identifier (name); 3920 tree id = get_identifier (name);
3540 tree decl = build_decl (FUNCTION_DECL, id, type); 3921 tree decl = build_decl (input_location, FUNCTION_DECL, id, type);
3541 3922
3542 DECL_EXTERNAL (decl) = 1; 3923 DECL_EXTERNAL (decl) = 1;
3543 TREE_PUBLIC (decl) = 1; 3924 TREE_PUBLIC (decl) = 1;
3544 DECL_ARTIFICIAL (decl) = 1; 3925 DECL_ARTIFICIAL (decl) = 1;
3545 TREE_NOTHROW (decl) = 1; 3926 TREE_NOTHROW (decl) = 1;
3566 3947
3567 expanded_location 3948 expanded_location
3568 expand_location (source_location loc) 3949 expand_location (source_location loc)
3569 { 3950 {
3570 expanded_location xloc; 3951 expanded_location xloc;
3571 if (loc == 0) 3952 if (loc <= BUILTINS_LOCATION)
3572 { 3953 {
3573 xloc.file = NULL; 3954 xloc.file = loc == UNKNOWN_LOCATION ? NULL : _("<built-in>");
3574 xloc.line = 0; 3955 xloc.line = 0;
3575 xloc.column = 0; 3956 xloc.column = 0;
3576 xloc.sysp = 0; 3957 xloc.sysp = 0;
3577 } 3958 }
3578 else 3959 else
3585 }; 3966 };
3586 return xloc; 3967 return xloc;
3587 } 3968 }
3588 3969
3589 3970
3590 /* Source location accessor functions. */ 3971 /* Like SET_EXPR_LOCATION, but make sure the tree can have a location.
3591 3972
3973 LOC is the location to use in tree T. */
3592 3974
3593 void 3975 void
3594 set_expr_locus (tree node, source_location *loc) 3976 protected_set_expr_location (tree t, location_t loc)
3595 {
3596 if (loc == NULL)
3597 EXPR_CHECK (node)->exp.locus = UNKNOWN_LOCATION;
3598 else
3599 EXPR_CHECK (node)->exp.locus = *loc;
3600 }
3601
3602 /* Like SET_EXPR_LOCATION, but make sure the tree can have a location.
3603
3604 LOC is the location to use in tree T. */
3605
3606 void protected_set_expr_location (tree t, location_t loc)
3607 { 3977 {
3608 if (t && CAN_HAVE_LOCATION_P (t)) 3978 if (t && CAN_HAVE_LOCATION_P (t))
3609 SET_EXPR_LOCATION (t, loc); 3979 SET_EXPR_LOCATION (t, loc);
3610 } 3980 }
3611 3981
3643 4013
3644 mix (a, val, val2); 4014 mix (a, val, val2);
3645 return val2; 4015 return val2;
3646 } 4016 }
3647 4017
3648 /* Produce good hash value combining PTR and VAL2. */
3649 static inline hashval_t
3650 iterative_hash_pointer (const void *ptr, hashval_t val2)
3651 {
3652 if (sizeof (ptr) == sizeof (hashval_t))
3653 return iterative_hash_hashval_t ((size_t) ptr, val2);
3654 else
3655 {
3656 hashval_t a = (hashval_t) (size_t) ptr;
3657 /* Avoid warnings about shifting of more than the width of the type on
3658 hosts that won't execute this path. */
3659 int zero = 0;
3660 hashval_t b = (hashval_t) ((size_t) ptr >> (sizeof (hashval_t) * 8 + zero));
3661 mix (a, b, val2);
3662 return val2;
3663 }
3664 }
3665
3666 /* Produce good hash value combining VAL and VAL2. */ 4018 /* Produce good hash value combining VAL and VAL2. */
3667 static inline hashval_t 4019 hashval_t
3668 iterative_hash_host_wide_int (HOST_WIDE_INT val, hashval_t val2) 4020 iterative_hash_host_wide_int (HOST_WIDE_INT val, hashval_t val2)
3669 { 4021 {
3670 if (sizeof (HOST_WIDE_INT) == sizeof (hashval_t)) 4022 if (sizeof (HOST_WIDE_INT) == sizeof (hashval_t))
3671 return iterative_hash_hashval_t (val, val2); 4023 return iterative_hash_hashval_t (val, val2);
3672 else 4024 else
3690 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE 4042 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
3691 is ATTRIBUTE and its qualifiers are QUALS. 4043 is ATTRIBUTE and its qualifiers are QUALS.
3692 4044
3693 Record such modified types already made so we don't make duplicates. */ 4045 Record such modified types already made so we don't make duplicates. */
3694 4046
3695 static tree 4047 tree
3696 build_type_attribute_qual_variant (tree ttype, tree attribute, int quals) 4048 build_type_attribute_qual_variant (tree ttype, tree attribute, int quals)
3697 { 4049 {
3698 if (! attribute_list_equal (TYPE_ATTRIBUTES (ttype), attribute)) 4050 if (! attribute_list_equal (TYPE_ATTRIBUTES (ttype), attribute))
3699 { 4051 {
3700 hashval_t hashcode = 0; 4052 hashval_t hashcode = 0;
3786 { 4138 {
3787 return build_type_attribute_qual_variant (ttype, attribute, 4139 return build_type_attribute_qual_variant (ttype, attribute,
3788 TYPE_QUALS (ttype)); 4140 TYPE_QUALS (ttype));
3789 } 4141 }
3790 4142
4143
4144 /* Reset all the fields in a binfo node BINFO. We only keep
4145 BINFO_VIRTUALS, which is used by gimple_fold_obj_type_ref. */
4146
4147 static void
4148 free_lang_data_in_binfo (tree binfo)
4149 {
4150 unsigned i;
4151 tree t;
4152
4153 gcc_assert (TREE_CODE (binfo) == TREE_BINFO);
4154
4155 BINFO_VTABLE (binfo) = NULL_TREE;
4156 BINFO_BASE_ACCESSES (binfo) = NULL;
4157 BINFO_INHERITANCE_CHAIN (binfo) = NULL_TREE;
4158 BINFO_SUBVTT_INDEX (binfo) = NULL_TREE;
4159
4160 for (i = 0; VEC_iterate (tree, BINFO_BASE_BINFOS (binfo), i, t); i++)
4161 free_lang_data_in_binfo (t);
4162 }
4163
4164
4165 /* Reset all language specific information still present in TYPE. */
4166
4167 static void
4168 free_lang_data_in_type (tree type)
4169 {
4170 gcc_assert (TYPE_P (type));
4171
4172 /* Give the FE a chance to remove its own data first. */
4173 lang_hooks.free_lang_data (type);
4174
4175 TREE_LANG_FLAG_0 (type) = 0;
4176 TREE_LANG_FLAG_1 (type) = 0;
4177 TREE_LANG_FLAG_2 (type) = 0;
4178 TREE_LANG_FLAG_3 (type) = 0;
4179 TREE_LANG_FLAG_4 (type) = 0;
4180 TREE_LANG_FLAG_5 (type) = 0;
4181 TREE_LANG_FLAG_6 (type) = 0;
4182
4183 if (TREE_CODE (type) == FUNCTION_TYPE)
4184 {
4185 /* Remove the const and volatile qualifiers from arguments. The
4186 C++ front end removes them, but the C front end does not,
4187 leading to false ODR violation errors when merging two
4188 instances of the same function signature compiled by
4189 different front ends. */
4190 tree p;
4191
4192 for (p = TYPE_ARG_TYPES (type); p; p = TREE_CHAIN (p))
4193 {
4194 tree arg_type = TREE_VALUE (p);
4195
4196 if (TYPE_READONLY (arg_type) || TYPE_VOLATILE (arg_type))
4197 {
4198 int quals = TYPE_QUALS (arg_type)
4199 & ~TYPE_QUAL_CONST
4200 & ~TYPE_QUAL_VOLATILE;
4201 TREE_VALUE (p) = build_qualified_type (arg_type, quals);
4202 free_lang_data_in_type (TREE_VALUE (p));
4203 }
4204 }
4205 }
4206
4207 /* Remove members that are not actually FIELD_DECLs from the field
4208 list of an aggregate. These occur in C++. */
4209 if (RECORD_OR_UNION_TYPE_P (type))
4210 {
4211 tree prev, member;
4212
4213 /* Note that TYPE_FIELDS can be shared across distinct
4214 TREE_TYPEs. Therefore, if the first field of TYPE_FIELDS is
4215 to be removed, we cannot set its TREE_CHAIN to NULL.
4216 Otherwise, we would not be able to find all the other fields
4217 in the other instances of this TREE_TYPE.
4218
4219 This was causing an ICE in testsuite/g++.dg/lto/20080915.C. */
4220 prev = NULL_TREE;
4221 member = TYPE_FIELDS (type);
4222 while (member)
4223 {
4224 if (TREE_CODE (member) == FIELD_DECL)
4225 {
4226 if (prev)
4227 TREE_CHAIN (prev) = member;
4228 else
4229 TYPE_FIELDS (type) = member;
4230 prev = member;
4231 }
4232
4233 member = TREE_CHAIN (member);
4234 }
4235
4236 if (prev)
4237 TREE_CHAIN (prev) = NULL_TREE;
4238 else
4239 TYPE_FIELDS (type) = NULL_TREE;
4240
4241 TYPE_METHODS (type) = NULL_TREE;
4242 if (TYPE_BINFO (type))
4243 free_lang_data_in_binfo (TYPE_BINFO (type));
4244 }
4245 else
4246 {
4247 /* For non-aggregate types, clear out the language slot (which
4248 overloads TYPE_BINFO). */
4249 TYPE_LANG_SLOT_1 (type) = NULL_TREE;
4250 }
4251
4252 TYPE_CONTEXT (type) = NULL_TREE;
4253 if (debug_info_level < DINFO_LEVEL_TERSE)
4254 TYPE_STUB_DECL (type) = NULL_TREE;
4255 }
4256
4257
4258 /* Return true if DECL may need an assembler name to be set. */
4259
4260 static inline bool
4261 need_assembler_name_p (tree decl)
4262 {
4263 /* Only FUNCTION_DECLs and VAR_DECLs are considered. */
4264 if (TREE_CODE (decl) != FUNCTION_DECL
4265 && TREE_CODE (decl) != VAR_DECL)
4266 return false;
4267
4268 /* If DECL already has its assembler name set, it does not need a
4269 new one. */
4270 if (!HAS_DECL_ASSEMBLER_NAME_P (decl)
4271 || DECL_ASSEMBLER_NAME_SET_P (decl))
4272 return false;
4273
4274 /* Abstract decls do not need an assembler name. */
4275 if (DECL_ABSTRACT (decl))
4276 return false;
4277
4278 /* For VAR_DECLs, only static, public and external symbols need an
4279 assembler name. */
4280 if (TREE_CODE (decl) == VAR_DECL
4281 && !TREE_STATIC (decl)
4282 && !TREE_PUBLIC (decl)
4283 && !DECL_EXTERNAL (decl))
4284 return false;
4285
4286 if (TREE_CODE (decl) == FUNCTION_DECL)
4287 {
4288 /* Do not set assembler name on builtins. Allow RTL expansion to
4289 decide whether to expand inline or via a regular call. */
4290 if (DECL_BUILT_IN (decl)
4291 && DECL_BUILT_IN_CLASS (decl) != BUILT_IN_FRONTEND)
4292 return false;
4293
4294 /* Functions represented in the callgraph need an assembler name. */
4295 if (cgraph_get_node (decl) != NULL)
4296 return true;
4297
4298 /* Unused and not public functions don't need an assembler name. */
4299 if (!TREE_USED (decl) && !TREE_PUBLIC (decl))
4300 return false;
4301 }
4302
4303 return true;
4304 }
4305
4306
4307 /* Remove all the non-variable decls from BLOCK. LOCALS is the set of
4308 variables in DECL_STRUCT_FUNCTION (FN)->local_decls. Every decl
4309 in BLOCK that is not in LOCALS is removed. */
4310
4311 static void
4312 free_lang_data_in_block (tree fn, tree block, struct pointer_set_t *locals)
4313 {
4314 tree *tp, t;
4315
4316 tp = &BLOCK_VARS (block);
4317 while (*tp)
4318 {
4319 if (!pointer_set_contains (locals, *tp))
4320 *tp = TREE_CHAIN (*tp);
4321 else
4322 tp = &TREE_CHAIN (*tp);
4323 }
4324
4325 for (t = BLOCK_SUBBLOCKS (block); t; t = BLOCK_CHAIN (t))
4326 free_lang_data_in_block (fn, t, locals);
4327 }
4328
4329
4330 /* Reset all language specific information still present in symbol
4331 DECL. */
4332
4333 static void
4334 free_lang_data_in_decl (tree decl)
4335 {
4336 gcc_assert (DECL_P (decl));
4337
4338 /* Give the FE a chance to remove its own data first. */
4339 lang_hooks.free_lang_data (decl);
4340
4341 TREE_LANG_FLAG_0 (decl) = 0;
4342 TREE_LANG_FLAG_1 (decl) = 0;
4343 TREE_LANG_FLAG_2 (decl) = 0;
4344 TREE_LANG_FLAG_3 (decl) = 0;
4345 TREE_LANG_FLAG_4 (decl) = 0;
4346 TREE_LANG_FLAG_5 (decl) = 0;
4347 TREE_LANG_FLAG_6 (decl) = 0;
4348
4349 /* Identifiers need not have a type. */
4350 if (DECL_NAME (decl))
4351 TREE_TYPE (DECL_NAME (decl)) = NULL_TREE;
4352
4353 /* Ignore any intervening types, because we are going to clear their
4354 TYPE_CONTEXT fields. */
4355 if (TREE_CODE (decl) != FIELD_DECL)
4356 DECL_CONTEXT (decl) = decl_function_context (decl);
4357
4358 if (DECL_CONTEXT (decl)
4359 && TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
4360 DECL_CONTEXT (decl) = NULL_TREE;
4361
4362 if (TREE_CODE (decl) == VAR_DECL)
4363 {
4364 tree context = DECL_CONTEXT (decl);
4365
4366 if (context)
4367 {
4368 enum tree_code code = TREE_CODE (context);
4369 if (code == FUNCTION_DECL && DECL_ABSTRACT (context))
4370 {
4371 /* Do not clear the decl context here, that will promote
4372 all vars to global ones. */
4373 DECL_INITIAL (decl) = NULL_TREE;
4374 }
4375
4376 if (TREE_STATIC (decl))
4377 DECL_CONTEXT (decl) = NULL_TREE;
4378 }
4379 }
4380
4381 /* ??? We could free non-constant DECL_SIZE, DECL_SIZE_UNIT
4382 and DECL_FIELD_OFFSET. But it's cheap enough to not do
4383 that and refrain from adding workarounds to dwarf2out.c */
4384
4385 /* DECL_FCONTEXT is only used for debug info generation. */
4386 if (TREE_CODE (decl) == FIELD_DECL
4387 && debug_info_level < DINFO_LEVEL_TERSE)
4388 DECL_FCONTEXT (decl) = NULL_TREE;
4389
4390 if (TREE_CODE (decl) == FUNCTION_DECL)
4391 {
4392 if (gimple_has_body_p (decl))
4393 {
4394 tree t;
4395 struct pointer_set_t *locals;
4396
4397 /* If DECL has a gimple body, then the context for its
4398 arguments must be DECL. Otherwise, it doesn't really
4399 matter, as we will not be emitting any code for DECL. In
4400 general, there may be other instances of DECL created by
4401 the front end and since PARM_DECLs are generally shared,
4402 their DECL_CONTEXT changes as the replicas of DECL are
4403 created. The only time where DECL_CONTEXT is important
4404 is for the FUNCTION_DECLs that have a gimple body (since
4405 the PARM_DECL will be used in the function's body). */
4406 for (t = DECL_ARGUMENTS (decl); t; t = TREE_CHAIN (t))
4407 DECL_CONTEXT (t) = decl;
4408
4409 /* Collect all the symbols declared in DECL. */
4410 locals = pointer_set_create ();
4411 t = DECL_STRUCT_FUNCTION (decl)->local_decls;
4412 for (; t; t = TREE_CHAIN (t))
4413 {
4414 pointer_set_insert (locals, TREE_VALUE (t));
4415
4416 /* All the local symbols should have DECL as their
4417 context. */
4418 DECL_CONTEXT (TREE_VALUE (t)) = decl;
4419 }
4420
4421 /* Get rid of any decl not in local_decls. */
4422 free_lang_data_in_block (decl, DECL_INITIAL (decl), locals);
4423
4424 pointer_set_destroy (locals);
4425 }
4426
4427 /* DECL_SAVED_TREE holds the GENERIC representation for DECL.
4428 At this point, it is not needed anymore. */
4429 DECL_SAVED_TREE (decl) = NULL_TREE;
4430 }
4431 else if (TREE_CODE (decl) == VAR_DECL)
4432 {
4433 tree expr = DECL_DEBUG_EXPR (decl);
4434 if (expr
4435 && TREE_CODE (expr) == VAR_DECL
4436 && !TREE_STATIC (expr) && !DECL_EXTERNAL (expr))
4437 SET_DECL_DEBUG_EXPR (decl, NULL_TREE);
4438
4439 if (DECL_EXTERNAL (decl)
4440 && (!TREE_STATIC (decl) || !TREE_READONLY (decl)))
4441 DECL_INITIAL (decl) = NULL_TREE;
4442 }
4443 else if (TREE_CODE (decl) == TYPE_DECL)
4444 {
4445 DECL_INITIAL (decl) = NULL_TREE;
4446
4447 /* DECL_CONTEXT is overloaded as DECL_FIELD_CONTEXT for
4448 FIELD_DECLs, which should be preserved. Otherwise,
4449 we shouldn't be concerned with source-level lexical
4450 nesting beyond this point. */
4451 DECL_CONTEXT (decl) = NULL_TREE;
4452 }
4453 }
4454
4455
4456 /* Data used when collecting DECLs and TYPEs for language data removal. */
4457
4458 struct free_lang_data_d
4459 {
4460 /* Worklist to avoid excessive recursion. */
4461 VEC(tree,heap) *worklist;
4462
4463 /* Set of traversed objects. Used to avoid duplicate visits. */
4464 struct pointer_set_t *pset;
4465
4466 /* Array of symbols to process with free_lang_data_in_decl. */
4467 VEC(tree,heap) *decls;
4468
4469 /* Array of types to process with free_lang_data_in_type. */
4470 VEC(tree,heap) *types;
4471 };
4472
4473
4474 /* Save all language fields needed to generate proper debug information
4475 for DECL. This saves most fields cleared out by free_lang_data_in_decl. */
4476
4477 static void
4478 save_debug_info_for_decl (tree t)
4479 {
4480 /*struct saved_debug_info_d *sdi;*/
4481
4482 gcc_assert (debug_info_level > DINFO_LEVEL_TERSE && t && DECL_P (t));
4483
4484 /* FIXME. Partial implementation for saving debug info removed. */
4485 }
4486
4487
4488 /* Save all language fields needed to generate proper debug information
4489 for TYPE. This saves most fields cleared out by free_lang_data_in_type. */
4490
4491 static void
4492 save_debug_info_for_type (tree t)
4493 {
4494 /*struct saved_debug_info_d *sdi;*/
4495
4496 gcc_assert (debug_info_level > DINFO_LEVEL_TERSE && t && TYPE_P (t));
4497
4498 /* FIXME. Partial implementation for saving debug info removed. */
4499 }
4500
4501
4502 /* Add type or decl T to one of the list of tree nodes that need their
4503 language data removed. The lists are held inside FLD. */
4504
4505 static void
4506 add_tree_to_fld_list (tree t, struct free_lang_data_d *fld)
4507 {
4508 if (DECL_P (t))
4509 {
4510 VEC_safe_push (tree, heap, fld->decls, t);
4511 if (debug_info_level > DINFO_LEVEL_TERSE)
4512 save_debug_info_for_decl (t);
4513 }
4514 else if (TYPE_P (t))
4515 {
4516 VEC_safe_push (tree, heap, fld->types, t);
4517 if (debug_info_level > DINFO_LEVEL_TERSE)
4518 save_debug_info_for_type (t);
4519 }
4520 else
4521 gcc_unreachable ();
4522 }
4523
4524 /* Push tree node T into FLD->WORKLIST. */
4525
4526 static inline void
4527 fld_worklist_push (tree t, struct free_lang_data_d *fld)
4528 {
4529 if (t && !is_lang_specific (t) && !pointer_set_contains (fld->pset, t))
4530 VEC_safe_push (tree, heap, fld->worklist, (t));
4531 }
4532
4533
4534 /* Operand callback helper for free_lang_data_in_node. *TP is the
4535 subtree operand being considered. */
4536
4537 static tree
4538 find_decls_types_r (tree *tp, int *ws, void *data)
4539 {
4540 tree t = *tp;
4541 struct free_lang_data_d *fld = (struct free_lang_data_d *) data;
4542
4543 if (TREE_CODE (t) == TREE_LIST)
4544 return NULL_TREE;
4545
4546 /* Language specific nodes will be removed, so there is no need
4547 to gather anything under them. */
4548 if (is_lang_specific (t))
4549 {
4550 *ws = 0;
4551 return NULL_TREE;
4552 }
4553
4554 if (DECL_P (t))
4555 {
4556 /* Note that walk_tree does not traverse every possible field in
4557 decls, so we have to do our own traversals here. */
4558 add_tree_to_fld_list (t, fld);
4559
4560 fld_worklist_push (DECL_NAME (t), fld);
4561 fld_worklist_push (DECL_CONTEXT (t), fld);
4562 fld_worklist_push (DECL_SIZE (t), fld);
4563 fld_worklist_push (DECL_SIZE_UNIT (t), fld);
4564
4565 /* We are going to remove everything under DECL_INITIAL for
4566 TYPE_DECLs. No point walking them. */
4567 if (TREE_CODE (t) != TYPE_DECL)
4568 fld_worklist_push (DECL_INITIAL (t), fld);
4569
4570 fld_worklist_push (DECL_ATTRIBUTES (t), fld);
4571 fld_worklist_push (DECL_ABSTRACT_ORIGIN (t), fld);
4572
4573 if (TREE_CODE (t) == FUNCTION_DECL)
4574 {
4575 fld_worklist_push (DECL_ARGUMENTS (t), fld);
4576 fld_worklist_push (DECL_RESULT (t), fld);
4577 }
4578 else if (TREE_CODE (t) == TYPE_DECL)
4579 {
4580 fld_worklist_push (DECL_ARGUMENT_FLD (t), fld);
4581 fld_worklist_push (DECL_VINDEX (t), fld);
4582 }
4583 else if (TREE_CODE (t) == FIELD_DECL)
4584 {
4585 fld_worklist_push (DECL_FIELD_OFFSET (t), fld);
4586 fld_worklist_push (DECL_BIT_FIELD_TYPE (t), fld);
4587 fld_worklist_push (DECL_QUALIFIER (t), fld);
4588 fld_worklist_push (DECL_FIELD_BIT_OFFSET (t), fld);
4589 fld_worklist_push (DECL_FCONTEXT (t), fld);
4590 }
4591 else if (TREE_CODE (t) == VAR_DECL)
4592 {
4593 fld_worklist_push (DECL_SECTION_NAME (t), fld);
4594 fld_worklist_push (DECL_COMDAT_GROUP (t), fld);
4595 }
4596
4597 if (TREE_CODE (t) != FIELD_DECL)
4598 fld_worklist_push (TREE_CHAIN (t), fld);
4599 *ws = 0;
4600 }
4601 else if (TYPE_P (t))
4602 {
4603 /* Note that walk_tree does not traverse every possible field in
4604 types, so we have to do our own traversals here. */
4605 add_tree_to_fld_list (t, fld);
4606
4607 if (!RECORD_OR_UNION_TYPE_P (t))
4608 fld_worklist_push (TYPE_CACHED_VALUES (t), fld);
4609 fld_worklist_push (TYPE_SIZE (t), fld);
4610 fld_worklist_push (TYPE_SIZE_UNIT (t), fld);
4611 fld_worklist_push (TYPE_ATTRIBUTES (t), fld);
4612 fld_worklist_push (TYPE_POINTER_TO (t), fld);
4613 fld_worklist_push (TYPE_REFERENCE_TO (t), fld);
4614 fld_worklist_push (TYPE_NAME (t), fld);
4615 fld_worklist_push (TYPE_MINVAL (t), fld);
4616 if (!RECORD_OR_UNION_TYPE_P (t))
4617 fld_worklist_push (TYPE_MAXVAL (t), fld);
4618 fld_worklist_push (TYPE_MAIN_VARIANT (t), fld);
4619 fld_worklist_push (TYPE_NEXT_VARIANT (t), fld);
4620 fld_worklist_push (TYPE_CONTEXT (t), fld);
4621 fld_worklist_push (TYPE_CANONICAL (t), fld);
4622
4623 if (RECORD_OR_UNION_TYPE_P (t) && TYPE_BINFO (t))
4624 {
4625 unsigned i;
4626 tree tem;
4627 for (i = 0; VEC_iterate (tree, BINFO_BASE_BINFOS (TYPE_BINFO (t)),
4628 i, tem); ++i)
4629 fld_worklist_push (TREE_TYPE (tem), fld);
4630 tem = BINFO_VIRTUALS (TYPE_BINFO (t));
4631 if (tem
4632 /* The Java FE overloads BINFO_VIRTUALS for its own purpose. */
4633 && TREE_CODE (tem) == TREE_LIST)
4634 do
4635 {
4636 fld_worklist_push (TREE_VALUE (tem), fld);
4637 tem = TREE_CHAIN (tem);
4638 }
4639 while (tem);
4640 }
4641 if (RECORD_OR_UNION_TYPE_P (t))
4642 {
4643 tree tem;
4644 /* Push all TYPE_FIELDS - there can be interleaving interesting
4645 and non-interesting things. */
4646 tem = TYPE_FIELDS (t);
4647 while (tem)
4648 {
4649 if (TREE_CODE (tem) == FIELD_DECL)
4650 fld_worklist_push (tem, fld);
4651 tem = TREE_CHAIN (tem);
4652 }
4653 }
4654
4655 fld_worklist_push (TREE_CHAIN (t), fld);
4656 *ws = 0;
4657 }
4658
4659 fld_worklist_push (TREE_TYPE (t), fld);
4660
4661 return NULL_TREE;
4662 }
4663
4664
4665 /* Find decls and types in T. */
4666
4667 static void
4668 find_decls_types (tree t, struct free_lang_data_d *fld)
4669 {
4670 while (1)
4671 {
4672 if (!pointer_set_contains (fld->pset, t))
4673 walk_tree (&t, find_decls_types_r, fld, fld->pset);
4674 if (VEC_empty (tree, fld->worklist))
4675 break;
4676 t = VEC_pop (tree, fld->worklist);
4677 }
4678 }
4679
4680 /* Translate all the types in LIST with the corresponding runtime
4681 types. */
4682
4683 static tree
4684 get_eh_types_for_runtime (tree list)
4685 {
4686 tree head, prev;
4687
4688 if (list == NULL_TREE)
4689 return NULL_TREE;
4690
4691 head = build_tree_list (0, lookup_type_for_runtime (TREE_VALUE (list)));
4692 prev = head;
4693 list = TREE_CHAIN (list);
4694 while (list)
4695 {
4696 tree n = build_tree_list (0, lookup_type_for_runtime (TREE_VALUE (list)));
4697 TREE_CHAIN (prev) = n;
4698 prev = TREE_CHAIN (prev);
4699 list = TREE_CHAIN (list);
4700 }
4701
4702 return head;
4703 }
4704
4705
4706 /* Find decls and types referenced in EH region R and store them in
4707 FLD->DECLS and FLD->TYPES. */
4708
4709 static void
4710 find_decls_types_in_eh_region (eh_region r, struct free_lang_data_d *fld)
4711 {
4712 switch (r->type)
4713 {
4714 case ERT_CLEANUP:
4715 break;
4716
4717 case ERT_TRY:
4718 {
4719 eh_catch c;
4720
4721 /* The types referenced in each catch must first be changed to the
4722 EH types used at runtime. This removes references to FE types
4723 in the region. */
4724 for (c = r->u.eh_try.first_catch; c ; c = c->next_catch)
4725 {
4726 c->type_list = get_eh_types_for_runtime (c->type_list);
4727 walk_tree (&c->type_list, find_decls_types_r, fld, fld->pset);
4728 }
4729 }
4730 break;
4731
4732 case ERT_ALLOWED_EXCEPTIONS:
4733 r->u.allowed.type_list
4734 = get_eh_types_for_runtime (r->u.allowed.type_list);
4735 walk_tree (&r->u.allowed.type_list, find_decls_types_r, fld, fld->pset);
4736 break;
4737
4738 case ERT_MUST_NOT_THROW:
4739 walk_tree (&r->u.must_not_throw.failure_decl,
4740 find_decls_types_r, fld, fld->pset);
4741 break;
4742 }
4743 }
4744
4745
4746 /* Find decls and types referenced in cgraph node N and store them in
4747 FLD->DECLS and FLD->TYPES. Unlike pass_referenced_vars, this will
4748 look for *every* kind of DECL and TYPE node reachable from N,
4749 including those embedded inside types and decls (i.e,, TYPE_DECLs,
4750 NAMESPACE_DECLs, etc). */
4751
4752 static void
4753 find_decls_types_in_node (struct cgraph_node *n, struct free_lang_data_d *fld)
4754 {
4755 basic_block bb;
4756 struct function *fn;
4757 tree t;
4758
4759 find_decls_types (n->decl, fld);
4760
4761 if (!gimple_has_body_p (n->decl))
4762 return;
4763
4764 gcc_assert (current_function_decl == NULL_TREE && cfun == NULL);
4765
4766 fn = DECL_STRUCT_FUNCTION (n->decl);
4767
4768 /* Traverse locals. */
4769 for (t = fn->local_decls; t; t = TREE_CHAIN (t))
4770 find_decls_types (TREE_VALUE (t), fld);
4771
4772 /* Traverse EH regions in FN. */
4773 {
4774 eh_region r;
4775 FOR_ALL_EH_REGION_FN (r, fn)
4776 find_decls_types_in_eh_region (r, fld);
4777 }
4778
4779 /* Traverse every statement in FN. */
4780 FOR_EACH_BB_FN (bb, fn)
4781 {
4782 gimple_stmt_iterator si;
4783 unsigned i;
4784
4785 for (si = gsi_start_phis (bb); !gsi_end_p (si); gsi_next (&si))
4786 {
4787 gimple phi = gsi_stmt (si);
4788
4789 for (i = 0; i < gimple_phi_num_args (phi); i++)
4790 {
4791 tree *arg_p = gimple_phi_arg_def_ptr (phi, i);
4792 find_decls_types (*arg_p, fld);
4793 }
4794 }
4795
4796 for (si = gsi_start_bb (bb); !gsi_end_p (si); gsi_next (&si))
4797 {
4798 gimple stmt = gsi_stmt (si);
4799
4800 for (i = 0; i < gimple_num_ops (stmt); i++)
4801 {
4802 tree arg = gimple_op (stmt, i);
4803 find_decls_types (arg, fld);
4804 }
4805 }
4806 }
4807 }
4808
4809
4810 /* Find decls and types referenced in varpool node N and store them in
4811 FLD->DECLS and FLD->TYPES. Unlike pass_referenced_vars, this will
4812 look for *every* kind of DECL and TYPE node reachable from N,
4813 including those embedded inside types and decls (i.e,, TYPE_DECLs,
4814 NAMESPACE_DECLs, etc). */
4815
4816 static void
4817 find_decls_types_in_var (struct varpool_node *v, struct free_lang_data_d *fld)
4818 {
4819 find_decls_types (v->decl, fld);
4820 }
4821
4822
4823 /* Free language specific information for every operand and expression
4824 in every node of the call graph. This process operates in three stages:
4825
4826 1- Every callgraph node and varpool node is traversed looking for
4827 decls and types embedded in them. This is a more exhaustive
4828 search than that done by find_referenced_vars, because it will
4829 also collect individual fields, decls embedded in types, etc.
4830
4831 2- All the decls found are sent to free_lang_data_in_decl.
4832
4833 3- All the types found are sent to free_lang_data_in_type.
4834
4835 The ordering between decls and types is important because
4836 free_lang_data_in_decl sets assembler names, which includes
4837 mangling. So types cannot be freed up until assembler names have
4838 been set up. */
4839
4840 static void
4841 free_lang_data_in_cgraph (void)
4842 {
4843 struct cgraph_node *n;
4844 struct varpool_node *v;
4845 struct free_lang_data_d fld;
4846 tree t;
4847 unsigned i;
4848 alias_pair *p;
4849
4850 /* Initialize sets and arrays to store referenced decls and types. */
4851 fld.pset = pointer_set_create ();
4852 fld.worklist = NULL;
4853 fld.decls = VEC_alloc (tree, heap, 100);
4854 fld.types = VEC_alloc (tree, heap, 100);
4855
4856 /* Find decls and types in the body of every function in the callgraph. */
4857 for (n = cgraph_nodes; n; n = n->next)
4858 find_decls_types_in_node (n, &fld);
4859
4860 for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); i++)
4861 find_decls_types (p->decl, &fld);
4862
4863 /* Find decls and types in every varpool symbol. */
4864 for (v = varpool_nodes_queue; v; v = v->next_needed)
4865 find_decls_types_in_var (v, &fld);
4866
4867 /* Set the assembler name on every decl found. We need to do this
4868 now because free_lang_data_in_decl will invalidate data needed
4869 for mangling. This breaks mangling on interdependent decls. */
4870 for (i = 0; VEC_iterate (tree, fld.decls, i, t); i++)
4871 if (need_assembler_name_p (t))
4872 {
4873 /* When setting DECL_ASSEMBLER_NAME, the C++ mangler may emit
4874 diagnostics that use input_location to show locus
4875 information. The problem here is that, at this point,
4876 input_location is generally anchored to the end of the file
4877 (since the parser is long gone), so we don't have a good
4878 position to pin it to.
4879
4880 To alleviate this problem, this uses the location of T's
4881 declaration. Examples of this are
4882 testsuite/g++.dg/template/cond2.C and
4883 testsuite/g++.dg/template/pr35240.C. */
4884 location_t saved_location = input_location;
4885 input_location = DECL_SOURCE_LOCATION (t);
4886
4887 decl_assembler_name (t);
4888
4889 input_location = saved_location;
4890 }
4891
4892 /* Traverse every decl found freeing its language data. */
4893 for (i = 0; VEC_iterate (tree, fld.decls, i, t); i++)
4894 free_lang_data_in_decl (t);
4895
4896 /* Traverse every type found freeing its language data. */
4897 for (i = 0; VEC_iterate (tree, fld.types, i, t); i++)
4898 free_lang_data_in_type (t);
4899
4900 pointer_set_destroy (fld.pset);
4901 VEC_free (tree, heap, fld.worklist);
4902 VEC_free (tree, heap, fld.decls);
4903 VEC_free (tree, heap, fld.types);
4904 }
4905
4906
4907 /* Free resources that are used by FE but are not needed once they are done. */
4908
4909 static unsigned
4910 free_lang_data (void)
4911 {
4912 unsigned i;
4913
4914 /* If we are the LTO frontend we have freed lang-specific data already. */
4915 if (in_lto_p
4916 || !flag_generate_lto)
4917 return 0;
4918
4919 /* Allocate and assign alias sets to the standard integer types
4920 while the slots are still in the way the frontends generated them. */
4921 for (i = 0; i < itk_none; ++i)
4922 if (integer_types[i])
4923 TYPE_ALIAS_SET (integer_types[i]) = get_alias_set (integer_types[i]);
4924
4925 /* Traverse the IL resetting language specific information for
4926 operands, expressions, etc. */
4927 free_lang_data_in_cgraph ();
4928
4929 /* Create gimple variants for common types. */
4930 ptrdiff_type_node = integer_type_node;
4931 fileptr_type_node = ptr_type_node;
4932 if (TREE_CODE (boolean_type_node) != BOOLEAN_TYPE
4933 || (TYPE_MODE (boolean_type_node)
4934 != mode_for_size (BOOL_TYPE_SIZE, MODE_INT, 0))
4935 || TYPE_PRECISION (boolean_type_node) != 1
4936 || !TYPE_UNSIGNED (boolean_type_node))
4937 {
4938 boolean_type_node = make_unsigned_type (BOOL_TYPE_SIZE);
4939 TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE);
4940 TYPE_MAX_VALUE (boolean_type_node) = build_int_cst (boolean_type_node, 1);
4941 TYPE_PRECISION (boolean_type_node) = 1;
4942 boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
4943 boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
4944 }
4945
4946 /* Unify char_type_node with its properly signed variant. */
4947 if (TYPE_UNSIGNED (char_type_node))
4948 unsigned_char_type_node = char_type_node;
4949 else
4950 signed_char_type_node = char_type_node;
4951
4952 /* Reset some langhooks. Do not reset types_compatible_p, it may
4953 still be used indirectly via the get_alias_set langhook. */
4954 lang_hooks.callgraph.analyze_expr = NULL;
4955 lang_hooks.dwarf_name = lhd_dwarf_name;
4956 lang_hooks.decl_printable_name = gimple_decl_printable_name;
4957 lang_hooks.set_decl_assembler_name = lhd_set_decl_assembler_name;
4958 lang_hooks.fold_obj_type_ref = gimple_fold_obj_type_ref;
4959
4960 /* Reset diagnostic machinery. */
4961 diagnostic_starter (global_dc) = default_diagnostic_starter;
4962 diagnostic_finalizer (global_dc) = default_diagnostic_finalizer;
4963 diagnostic_format_decoder (global_dc) = default_tree_printer;
4964
4965 return 0;
4966 }
4967
4968
4969 struct simple_ipa_opt_pass pass_ipa_free_lang_data =
4970 {
4971 {
4972 SIMPLE_IPA_PASS,
4973 "*free_lang_data", /* name */
4974 NULL, /* gate */
4975 free_lang_data, /* execute */
4976 NULL, /* sub */
4977 NULL, /* next */
4978 0, /* static_pass_number */
4979 TV_IPA_FREE_LANG_DATA, /* tv_id */
4980 0, /* properties_required */
4981 0, /* properties_provided */
4982 0, /* properties_destroyed */
4983 0, /* todo_flags_start */
4984 TODO_ggc_collect /* todo_flags_finish */
4985 }
4986 };
4987
3791 /* Return nonzero if IDENT is a valid name for attribute ATTR, 4988 /* Return nonzero if IDENT is a valid name for attribute ATTR,
3792 or zero if not. 4989 or zero if not.
3793 4990
3794 We try both `text' and `__text__', ATTR may be either one. */ 4991 We try both `text' and `__text__', ATTR may be either one. */
3795 /* ??? It might be a reasonable simplification to require ATTR to be only 4992 /* ??? It might be a reasonable simplification to require ATTR to be only
3802 int ident_len; 4999 int ident_len;
3803 const char *p; 5000 const char *p;
3804 5001
3805 if (TREE_CODE (ident) != IDENTIFIER_NODE) 5002 if (TREE_CODE (ident) != IDENTIFIER_NODE)
3806 return 0; 5003 return 0;
3807 5004
3808 p = IDENTIFIER_POINTER (ident); 5005 p = IDENTIFIER_POINTER (ident);
3809 ident_len = IDENTIFIER_LENGTH (ident); 5006 ident_len = IDENTIFIER_LENGTH (ident);
3810 5007
3811 if (ident_len == attr_len 5008 if (ident_len == attr_len
3812 && strcmp (attr, p) == 0) 5009 && strcmp (attr, p) == 0)
3813 return 1; 5010 return 1;
3814 5011
3815 /* If ATTR is `__text__', IDENT must be `text'; and vice versa. */ 5012 /* If ATTR is `__text__', IDENT must be `text'; and vice versa. */
3987 /* What we need to do here is remove from `old' dllimport if it doesn't 5184 /* What we need to do here is remove from `old' dllimport if it doesn't
3988 appear in `new'. dllimport behaves like extern: if a declaration is 5185 appear in `new'. dllimport behaves like extern: if a declaration is
3989 marked dllimport and a definition appears later, then the object 5186 marked dllimport and a definition appears later, then the object
3990 is not dllimport'd. We also remove a `new' dllimport if the old list 5187 is not dllimport'd. We also remove a `new' dllimport if the old list
3991 contains dllexport: dllexport always overrides dllimport, regardless 5188 contains dllexport: dllexport always overrides dllimport, regardless
3992 of the order of declaration. */ 5189 of the order of declaration. */
3993 if (!VAR_OR_FUNCTION_DECL_P (new_tree)) 5190 if (!VAR_OR_FUNCTION_DECL_P (new_tree))
3994 delete_dllimport_p = 0; 5191 delete_dllimport_p = 0;
3995 else if (DECL_DLLIMPORT_P (new_tree) 5192 else if (DECL_DLLIMPORT_P (new_tree)
3996 && lookup_attribute ("dllexport", DECL_ATTRIBUTES (old))) 5193 && lookup_attribute ("dllexport", DECL_ATTRIBUTES (old)))
3997 { 5194 {
3998 DECL_DLLIMPORT_P (new_tree) = 0; 5195 DECL_DLLIMPORT_P (new_tree) = 0;
3999 warning (OPT_Wattributes, "%q+D already declared with dllexport attribute: " 5196 warning (OPT_Wattributes, "%q+D already declared with dllexport attribute: "
4000 "dllimport ignored", new_tree); 5197 "dllimport ignored", new_tree);
4001 } 5198 }
4002 else if (DECL_DLLIMPORT_P (old) && !DECL_DLLIMPORT_P (new_tree)) 5199 else if (DECL_DLLIMPORT_P (old) && !DECL_DLLIMPORT_P (new_tree))
4018 if (TREE_CODE (old) == VAR_DECL && TREE_ADDRESSABLE (old)) 5215 if (TREE_CODE (old) == VAR_DECL && TREE_ADDRESSABLE (old))
4019 DECL_DLLIMPORT_P (new_tree) = 1; 5216 DECL_DLLIMPORT_P (new_tree) = 1;
4020 } 5217 }
4021 5218
4022 /* Let an inline definition silently override the external reference, 5219 /* Let an inline definition silently override the external reference,
4023 but otherwise warn about attribute inconsistency. */ 5220 but otherwise warn about attribute inconsistency. */
4024 else if (TREE_CODE (new_tree) == VAR_DECL 5221 else if (TREE_CODE (new_tree) == VAR_DECL
4025 || !DECL_DECLARED_INLINE_P (new_tree)) 5222 || !DECL_DECLARED_INLINE_P (new_tree))
4026 warning (OPT_Wattributes, "%q+D redeclared without dllimport attribute: " 5223 warning (OPT_Wattributes, "%q+D redeclared without dllimport attribute: "
4027 "previous dllimport ignored", new_tree); 5224 "previous dllimport ignored", new_tree);
4028 } 5225 }
4029 else 5226 else
4030 delete_dllimport_p = 0; 5227 delete_dllimport_p = 0;
4031 5228
4032 a = merge_attributes (DECL_ATTRIBUTES (old), DECL_ATTRIBUTES (new_tree)); 5229 a = merge_attributes (DECL_ATTRIBUTES (old), DECL_ATTRIBUTES (new_tree));
4033 5230
4034 if (delete_dllimport_p) 5231 if (delete_dllimport_p)
4035 { 5232 {
4036 tree prev, t; 5233 tree prev, t;
4037 const size_t attr_len = strlen ("dllimport"); 5234 const size_t attr_len = strlen ("dllimport");
4038 5235
4039 /* Scan the list for dllimport and delete it. */ 5236 /* Scan the list for dllimport and delete it. */
4040 for (prev = NULL_TREE, t = a; t; prev = t, t = TREE_CHAIN (t)) 5237 for (prev = NULL_TREE, t = a; t; prev = t, t = TREE_CHAIN (t))
4041 { 5238 {
4042 if (is_attribute_with_length_p ("dllimport", attr_len, 5239 if (is_attribute_with_length_p ("dllimport", attr_len,
4043 TREE_PURPOSE (t))) 5240 TREE_PURPOSE (t)))
4060 tree 5257 tree
4061 handle_dll_attribute (tree * pnode, tree name, tree args, int flags, 5258 handle_dll_attribute (tree * pnode, tree name, tree args, int flags,
4062 bool *no_add_attrs) 5259 bool *no_add_attrs)
4063 { 5260 {
4064 tree node = *pnode; 5261 tree node = *pnode;
5262 bool is_dllimport;
4065 5263
4066 /* These attributes may apply to structure and union types being created, 5264 /* These attributes may apply to structure and union types being created,
4067 but otherwise should pass to the declaration involved. */ 5265 but otherwise should pass to the declaration involved. */
4068 if (!DECL_P (node)) 5266 if (!DECL_P (node))
4069 { 5267 {
4080 if (!node) 5278 if (!node)
4081 return NULL_TREE; 5279 return NULL_TREE;
4082 } 5280 }
4083 else 5281 else
4084 { 5282 {
4085 warning (OPT_Wattributes, "%qs attribute ignored", 5283 warning (OPT_Wattributes, "%qE attribute ignored",
4086 IDENTIFIER_POINTER (name)); 5284 name);
4087 *no_add_attrs = true; 5285 *no_add_attrs = true;
4088 return NULL_TREE; 5286 return NULL_TREE;
4089 } 5287 }
4090 } 5288 }
4091 5289
4092 if (TREE_CODE (node) != FUNCTION_DECL 5290 if (TREE_CODE (node) != FUNCTION_DECL
4093 && TREE_CODE (node) != VAR_DECL 5291 && TREE_CODE (node) != VAR_DECL
4094 && TREE_CODE (node) != TYPE_DECL) 5292 && TREE_CODE (node) != TYPE_DECL)
4095 { 5293 {
4096 *no_add_attrs = true; 5294 *no_add_attrs = true;
4097 warning (OPT_Wattributes, "%qs attribute ignored", 5295 warning (OPT_Wattributes, "%qE attribute ignored",
4098 IDENTIFIER_POINTER (name)); 5296 name);
4099 return NULL_TREE; 5297 return NULL_TREE;
4100 } 5298 }
4101 5299
4102 if (TREE_CODE (node) == TYPE_DECL 5300 if (TREE_CODE (node) == TYPE_DECL
4103 && TREE_CODE (TREE_TYPE (node)) != RECORD_TYPE 5301 && TREE_CODE (TREE_TYPE (node)) != RECORD_TYPE
4104 && TREE_CODE (TREE_TYPE (node)) != UNION_TYPE) 5302 && TREE_CODE (TREE_TYPE (node)) != UNION_TYPE)
4105 { 5303 {
4106 *no_add_attrs = true; 5304 *no_add_attrs = true;
4107 warning (OPT_Wattributes, "%qs attribute ignored", 5305 warning (OPT_Wattributes, "%qE attribute ignored",
4108 IDENTIFIER_POINTER (name)); 5306 name);
4109 return NULL_TREE; 5307 return NULL_TREE;
4110 } 5308 }
5309
5310 is_dllimport = is_attribute_p ("dllimport", name);
4111 5311
4112 /* Report error on dllimport ambiguities seen now before they cause 5312 /* Report error on dllimport ambiguities seen now before they cause
4113 any damage. */ 5313 any damage. */
4114 else if (is_attribute_p ("dllimport", name)) 5314 if (is_dllimport)
4115 { 5315 {
4116 /* Honor any target-specific overrides. */ 5316 /* Honor any target-specific overrides. */
4117 if (!targetm.valid_dllimport_attribute_p (node)) 5317 if (!targetm.valid_dllimport_attribute_p (node))
4118 *no_add_attrs = true; 5318 *no_add_attrs = true;
4119 5319
4120 else if (TREE_CODE (node) == FUNCTION_DECL 5320 else if (TREE_CODE (node) == FUNCTION_DECL
4121 && DECL_DECLARED_INLINE_P (node)) 5321 && DECL_DECLARED_INLINE_P (node))
4122 { 5322 {
4123 warning (OPT_Wattributes, "inline function %q+D declared as " 5323 warning (OPT_Wattributes, "inline function %q+D declared as "
4124 " dllimport: attribute ignored", node); 5324 " dllimport: attribute ignored", node);
4125 *no_add_attrs = true; 5325 *no_add_attrs = true;
4126 } 5326 }
4127 /* Like MS, treat definition of dllimported variables and 5327 /* Like MS, treat definition of dllimported variables and
4128 non-inlined functions on declaration as syntax errors. */ 5328 non-inlined functions on declaration as syntax errors. */
4129 else if (TREE_CODE (node) == FUNCTION_DECL && DECL_INITIAL (node)) 5329 else if (TREE_CODE (node) == FUNCTION_DECL && DECL_INITIAL (node))
4151 } 5351 }
4152 5352
4153 if (*no_add_attrs == false) 5353 if (*no_add_attrs == false)
4154 DECL_DLLIMPORT_P (node) = 1; 5354 DECL_DLLIMPORT_P (node) = 1;
4155 } 5355 }
5356 else if (TREE_CODE (node) == FUNCTION_DECL
5357 && DECL_DECLARED_INLINE_P (node))
5358 /* An exported function, even if inline, must be emitted. */
5359 DECL_EXTERNAL (node) = 0;
4156 5360
4157 /* Report error if symbol is not accessible at global scope. */ 5361 /* Report error if symbol is not accessible at global scope. */
4158 if (!TREE_PUBLIC (node) 5362 if (!TREE_PUBLIC (node)
4159 && (TREE_CODE (node) == VAR_DECL 5363 && (TREE_CODE (node) == VAR_DECL
4160 || TREE_CODE (node) == FUNCTION_DECL)) 5364 || TREE_CODE (node) == FUNCTION_DECL))
4161 { 5365 {
4162 error ("external linkage required for symbol %q+D because of " 5366 error ("external linkage required for symbol %q+D because of "
4163 "%qs attribute", node, IDENTIFIER_POINTER (name)); 5367 "%qE attribute", node, name);
4164 *no_add_attrs = true; 5368 *no_add_attrs = true;
4165 } 5369 }
4166 5370
4167 /* A dllexport'd entity must have default visibility so that other 5371 /* A dllexport'd entity must have default visibility so that other
4168 program units (shared libraries or the main executable) can see 5372 program units (shared libraries or the main executable) can see
4171 unit can be resolved by the dynamic linker. */ 5375 unit can be resolved by the dynamic linker. */
4172 if (!*no_add_attrs) 5376 if (!*no_add_attrs)
4173 { 5377 {
4174 if (DECL_VISIBILITY_SPECIFIED (node) 5378 if (DECL_VISIBILITY_SPECIFIED (node)
4175 && DECL_VISIBILITY (node) != VISIBILITY_DEFAULT) 5379 && DECL_VISIBILITY (node) != VISIBILITY_DEFAULT)
4176 error ("%qs implies default visibility, but %qD has already " 5380 error ("%qE implies default visibility, but %qD has already "
4177 "been declared with a different visibility", 5381 "been declared with a different visibility",
4178 IDENTIFIER_POINTER (name), node); 5382 name, node);
4179 DECL_VISIBILITY (node) = VISIBILITY_DEFAULT; 5383 DECL_VISIBILITY (node) = VISIBILITY_DEFAULT;
4180 DECL_VISIBILITY_SPECIFIED (node) = 1; 5384 DECL_VISIBILITY_SPECIFIED (node) = 1;
4181 } 5385 }
4182 5386
4183 return NULL_TREE; 5387 return NULL_TREE;
4192 set_type_quals (tree type, int type_quals) 5396 set_type_quals (tree type, int type_quals)
4193 { 5397 {
4194 TYPE_READONLY (type) = (type_quals & TYPE_QUAL_CONST) != 0; 5398 TYPE_READONLY (type) = (type_quals & TYPE_QUAL_CONST) != 0;
4195 TYPE_VOLATILE (type) = (type_quals & TYPE_QUAL_VOLATILE) != 0; 5399 TYPE_VOLATILE (type) = (type_quals & TYPE_QUAL_VOLATILE) != 0;
4196 TYPE_RESTRICT (type) = (type_quals & TYPE_QUAL_RESTRICT) != 0; 5400 TYPE_RESTRICT (type) = (type_quals & TYPE_QUAL_RESTRICT) != 0;
5401 TYPE_ADDR_SPACE (type) = DECODE_QUAL_ADDR_SPACE (type_quals);
4197 } 5402 }
4198 5403
4199 /* Returns true iff CAND is equivalent to BASE with TYPE_QUALS. */ 5404 /* Returns true iff CAND is equivalent to BASE with TYPE_QUALS. */
4200 5405
4201 bool 5406 bool
4257 TYPE_CANONICAL (t) = build_qualified_type (TYPE_CANONICAL (type), 5462 TYPE_CANONICAL (t) = build_qualified_type (TYPE_CANONICAL (type),
4258 type_quals); 5463 type_quals);
4259 else 5464 else
4260 /* T is its own canonical type. */ 5465 /* T is its own canonical type. */
4261 TYPE_CANONICAL (t) = t; 5466 TYPE_CANONICAL (t) = t;
4262 5467
4263 } 5468 }
4264 5469
4265 return t; 5470 return t;
4266 } 5471 }
4267 5472
4272 5477
4273 tree 5478 tree
4274 build_distinct_type_copy (tree type) 5479 build_distinct_type_copy (tree type)
4275 { 5480 {
4276 tree t = copy_node (type); 5481 tree t = copy_node (type);
4277 5482
4278 TYPE_POINTER_TO (t) = 0; 5483 TYPE_POINTER_TO (t) = 0;
4279 TYPE_REFERENCE_TO (t) = 0; 5484 TYPE_REFERENCE_TO (t) = 0;
4280 5485
4281 /* Set the canonical type either to a new equivalence class, or 5486 /* Set the canonical type either to a new equivalence class, or
4282 propagate the need for structural equality checks. */ 5487 propagate the need for structural equality checks. */
4310 t = build_distinct_type_copy (type); 5515 t = build_distinct_type_copy (type);
4311 5516
4312 /* Since we're building a variant, assume that it is a non-semantic 5517 /* Since we're building a variant, assume that it is a non-semantic
4313 variant. This also propagates TYPE_STRUCTURAL_EQUALITY_P. */ 5518 variant. This also propagates TYPE_STRUCTURAL_EQUALITY_P. */
4314 TYPE_CANONICAL (t) = TYPE_CANONICAL (type); 5519 TYPE_CANONICAL (t) = TYPE_CANONICAL (type);
4315 5520
4316 /* Add the new type to the chain of variants of TYPE. */ 5521 /* Add the new type to the chain of variants of TYPE. */
4317 TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m); 5522 TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
4318 TYPE_NEXT_VARIANT (m) = t; 5523 TYPE_NEXT_VARIANT (m) = t;
4319 TYPE_MAIN_VARIANT (t) = m; 5524 TYPE_MAIN_VARIANT (t) = m;
4320 5525
4417 struct tree_priority_map *h; 5622 struct tree_priority_map *h;
4418 5623
4419 gcc_assert (VAR_OR_FUNCTION_DECL_P (decl)); 5624 gcc_assert (VAR_OR_FUNCTION_DECL_P (decl));
4420 h = decl_priority_info (decl); 5625 h = decl_priority_info (decl);
4421 h->init = priority; 5626 h->init = priority;
4422 } 5627 }
4423 5628
4424 /* Set the finalization priority for DECL to PRIORITY. */ 5629 /* Set the finalization priority for DECL to PRIORITY. */
4425 5630
4426 void 5631 void
4427 decl_fini_priority_insert (tree decl, priority_type priority) 5632 decl_fini_priority_insert (tree decl, priority_type priority)
4429 struct tree_priority_map *h; 5634 struct tree_priority_map *h;
4430 5635
4431 gcc_assert (TREE_CODE (decl) == FUNCTION_DECL); 5636 gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
4432 h = decl_priority_info (decl); 5637 h = decl_priority_info (decl);
4433 h->fini = priority; 5638 h->fini = priority;
4434 }
4435
4436 /* Look up a restrict qualified base decl for FROM. */
4437
4438 tree
4439 decl_restrict_base_lookup (tree from)
4440 {
4441 struct tree_map *h;
4442 struct tree_map in;
4443
4444 in.base.from = from;
4445 h = (struct tree_map *) htab_find_with_hash (restrict_base_for_decl, &in,
4446 htab_hash_pointer (from));
4447 return h ? h->to : NULL_TREE;
4448 }
4449
4450 /* Record the restrict qualified base TO for FROM. */
4451
4452 void
4453 decl_restrict_base_insert (tree from, tree to)
4454 {
4455 struct tree_map *h;
4456 void **loc;
4457
4458 h = GGC_NEW (struct tree_map);
4459 h->hash = htab_hash_pointer (from);
4460 h->base.from = from;
4461 h->to = to;
4462 loc = htab_find_slot_with_hash (restrict_base_for_decl, h, h->hash, INSERT);
4463 *(struct tree_map **) loc = h;
4464 } 5639 }
4465 5640
4466 /* Print out the statistics for the DECL_DEBUG_EXPR hash table. */ 5641 /* Print out the statistics for the DECL_DEBUG_EXPR hash table. */
4467 5642
4468 static void 5643 static void
4483 (long) htab_size (value_expr_for_decl), 5658 (long) htab_size (value_expr_for_decl),
4484 (long) htab_elements (value_expr_for_decl), 5659 (long) htab_elements (value_expr_for_decl),
4485 htab_collisions (value_expr_for_decl)); 5660 htab_collisions (value_expr_for_decl));
4486 } 5661 }
4487 5662
4488 /* Print out statistics for the RESTRICT_BASE_FOR_DECL hash table, but
4489 don't print anything if the table is empty. */
4490
4491 static void
4492 print_restrict_base_statistics (void)
4493 {
4494 if (htab_elements (restrict_base_for_decl) != 0)
4495 fprintf (stderr,
4496 "RESTRICT_BASE hash: size %ld, %ld elements, %f collisions\n",
4497 (long) htab_size (restrict_base_for_decl),
4498 (long) htab_elements (restrict_base_for_decl),
4499 htab_collisions (restrict_base_for_decl));
4500 }
4501
4502 /* Lookup a debug expression for FROM, and return it if we find one. */ 5663 /* Lookup a debug expression for FROM, and return it if we find one. */
4503 5664
4504 tree 5665 tree
4505 decl_debug_expr_lookup (tree from) 5666 decl_debug_expr_lookup (tree from)
4506 { 5667 {
4507 struct tree_map *h, in; 5668 struct tree_map *h, in;
4508 in.base.from = from; 5669 in.base.from = from;
4509 5670
4526 h->hash = htab_hash_pointer (from); 5687 h->hash = htab_hash_pointer (from);
4527 h->base.from = from; 5688 h->base.from = from;
4528 h->to = to; 5689 h->to = to;
4529 loc = htab_find_slot_with_hash (debug_expr_for_decl, h, h->hash, INSERT); 5690 loc = htab_find_slot_with_hash (debug_expr_for_decl, h, h->hash, INSERT);
4530 *(struct tree_map **) loc = h; 5691 *(struct tree_map **) loc = h;
4531 } 5692 }
4532 5693
4533 /* Lookup a value expression for FROM, and return it if we find one. */ 5694 /* Lookup a value expression for FROM, and return it if we find one. */
4534 5695
4535 tree 5696 tree
4536 decl_value_expr_lookup (tree from) 5697 decl_value_expr_lookup (tree from)
4537 { 5698 {
4538 struct tree_map *h, in; 5699 struct tree_map *h, in;
4539 in.base.from = from; 5700 in.base.from = from;
4540 5701
4597 || TREE_TYPE (a->type) != TREE_TYPE (b->type) 5758 || TREE_TYPE (a->type) != TREE_TYPE (b->type)
4598 || !attribute_list_equal (TYPE_ATTRIBUTES (a->type), 5759 || !attribute_list_equal (TYPE_ATTRIBUTES (a->type),
4599 TYPE_ATTRIBUTES (b->type)) 5760 TYPE_ATTRIBUTES (b->type))
4600 || TYPE_ALIGN (a->type) != TYPE_ALIGN (b->type) 5761 || TYPE_ALIGN (a->type) != TYPE_ALIGN (b->type)
4601 || TYPE_MODE (a->type) != TYPE_MODE (b->type) 5762 || TYPE_MODE (a->type) != TYPE_MODE (b->type)
4602 || (TREE_CODE (a->type) != COMPLEX_TYPE 5763 || (TREE_CODE (a->type) != COMPLEX_TYPE
4603 && TYPE_NAME (a->type) != TYPE_NAME (b->type))) 5764 && TYPE_NAME (a->type) != TYPE_NAME (b->type)))
4604 return 0; 5765 return 0;
4605 5766
4606 switch (TREE_CODE (a->type)) 5767 switch (TREE_CODE (a->type))
4607 { 5768 {
4991 be represented in a single unsigned HOST_WIDE_INT. */ 6152 be represented in a single unsigned HOST_WIDE_INT. */
4992 6153
4993 int 6154 int
4994 host_integerp (const_tree t, int pos) 6155 host_integerp (const_tree t, int pos)
4995 { 6156 {
6157 if (t == NULL_TREE)
6158 return 0;
6159
4996 return (TREE_CODE (t) == INTEGER_CST 6160 return (TREE_CODE (t) == INTEGER_CST
4997 && ((TREE_INT_CST_HIGH (t) == 0 6161 && ((TREE_INT_CST_HIGH (t) == 0
4998 && (HOST_WIDE_INT) TREE_INT_CST_LOW (t) >= 0) 6162 && (HOST_WIDE_INT) TREE_INT_CST_LOW (t) >= 0)
4999 || (! pos && TREE_INT_CST_HIGH (t) == -1 6163 || (! pos && TREE_INT_CST_HIGH (t) == -1
5000 && (HOST_WIDE_INT) TREE_INT_CST_LOW (t) < 0 6164 && (HOST_WIDE_INT) TREE_INT_CST_LOW (t) < 0
5347 int i; 6511 int i;
5348 enum tree_code code; 6512 enum tree_code code;
5349 char tclass; 6513 char tclass;
5350 6514
5351 if (t == NULL_TREE) 6515 if (t == NULL_TREE)
5352 return iterative_hash_pointer (t, val); 6516 return iterative_hash_hashval_t (0, val);
5353 6517
5354 code = TREE_CODE (t); 6518 code = TREE_CODE (t);
5355 6519
5356 switch (code) 6520 switch (code)
5357 { 6521 {
5381 case VECTOR_CST: 6545 case VECTOR_CST:
5382 return iterative_hash_expr (TREE_VECTOR_CST_ELTS (t), val); 6546 return iterative_hash_expr (TREE_VECTOR_CST_ELTS (t), val);
5383 6547
5384 case SSA_NAME: 6548 case SSA_NAME:
5385 /* we can just compare by pointer. */ 6549 /* we can just compare by pointer. */
5386 return iterative_hash_pointer (t, val); 6550 return iterative_hash_host_wide_int (SSA_NAME_VERSION (t), val);
5387 6551
5388 case TREE_LIST: 6552 case TREE_LIST:
5389 /* A list of expressions, for a CALL_EXPR or as the elements of a 6553 /* A list of expressions, for a CALL_EXPR or as the elements of a
5390 VECTOR_CST. */ 6554 VECTOR_CST. */
5391 for (; t; t = TREE_CHAIN (t)) 6555 for (; t; t = TREE_CHAIN (t))
5401 val = iterative_hash_expr (value, val); 6565 val = iterative_hash_expr (value, val);
5402 } 6566 }
5403 return val; 6567 return val;
5404 } 6568 }
5405 case FUNCTION_DECL: 6569 case FUNCTION_DECL:
5406 /* When referring to a built-in FUNCTION_DECL, use the 6570 /* When referring to a built-in FUNCTION_DECL, use the __builtin__ form.
5407 __builtin__ form. Otherwise nodes that compare equal 6571 Otherwise nodes that compare equal according to operand_equal_p might
5408 according to operand_equal_p might get different 6572 get different hash codes. However, don't do this for machine specific
5409 hash codes. */ 6573 or front end builtins, since the function code is overloaded in those
5410 if (DECL_BUILT_IN (t)) 6574 cases. */
6575 if (DECL_BUILT_IN_CLASS (t) == BUILT_IN_NORMAL
6576 && built_in_decls[DECL_FUNCTION_CODE (t)])
5411 { 6577 {
5412 val = iterative_hash_pointer (built_in_decls[DECL_FUNCTION_CODE (t)], 6578 t = built_in_decls[DECL_FUNCTION_CODE (t)];
5413 val); 6579 code = TREE_CODE (t);
5414 return val;
5415 } 6580 }
5416 /* else FALL THROUGH */ 6581 /* FALL THROUGH */
5417 default: 6582 default:
5418 tclass = TREE_CODE_CLASS (code); 6583 tclass = TREE_CODE_CLASS (code);
5419 6584
5420 if (tclass == tcc_declaration) 6585 if (tclass == tcc_declaration)
5421 { 6586 {
5423 val = iterative_hash_host_wide_int (DECL_UID (t), val); 6588 val = iterative_hash_host_wide_int (DECL_UID (t), val);
5424 } 6589 }
5425 else 6590 else
5426 { 6591 {
5427 gcc_assert (IS_EXPR_CODE_CLASS (tclass)); 6592 gcc_assert (IS_EXPR_CODE_CLASS (tclass));
5428 6593
5429 val = iterative_hash_object (code, val); 6594 val = iterative_hash_object (code, val);
5430 6595
5431 /* Don't hash the type, that can lead to having nodes which 6596 /* Don't hash the type, that can lead to having nodes which
5432 compare equal according to operand_equal_p, but which 6597 compare equal according to operand_equal_p, but which
5433 have different hash codes. */ 6598 have different hash codes. */
5553 /* By default build pointers in ptr_mode. */ 6718 /* By default build pointers in ptr_mode. */
5554 6719
5555 tree 6720 tree
5556 build_pointer_type (tree to_type) 6721 build_pointer_type (tree to_type)
5557 { 6722 {
5558 return build_pointer_type_for_mode (to_type, ptr_mode, false); 6723 addr_space_t as = to_type == error_mark_node? ADDR_SPACE_GENERIC
6724 : TYPE_ADDR_SPACE (to_type);
6725 enum machine_mode pointer_mode = targetm.addr_space.pointer_mode (as);
6726 return build_pointer_type_for_mode (to_type, pointer_mode, false);
5559 } 6727 }
5560 6728
5561 /* Same as build_pointer_type_for_mode, but for REFERENCE_TYPE. */ 6729 /* Same as build_pointer_type_for_mode, but for REFERENCE_TYPE. */
5562 6730
5563 tree 6731 tree
5601 TYPE_REFERENCE_TO (to_type) = t; 6769 TYPE_REFERENCE_TO (to_type) = t;
5602 6770
5603 if (TYPE_STRUCTURAL_EQUALITY_P (to_type)) 6771 if (TYPE_STRUCTURAL_EQUALITY_P (to_type))
5604 SET_TYPE_STRUCTURAL_EQUALITY (t); 6772 SET_TYPE_STRUCTURAL_EQUALITY (t);
5605 else if (TYPE_CANONICAL (to_type) != to_type) 6773 else if (TYPE_CANONICAL (to_type) != to_type)
5606 TYPE_CANONICAL (t) 6774 TYPE_CANONICAL (t)
5607 = build_reference_type_for_mode (TYPE_CANONICAL (to_type), 6775 = build_reference_type_for_mode (TYPE_CANONICAL (to_type),
5608 mode, can_alias_all); 6776 mode, can_alias_all);
5609 6777
5610 layout_type (t); 6778 layout_type (t);
5611 6779
5617 in ptr_mode. */ 6785 in ptr_mode. */
5618 6786
5619 tree 6787 tree
5620 build_reference_type (tree to_type) 6788 build_reference_type (tree to_type)
5621 { 6789 {
5622 return build_reference_type_for_mode (to_type, ptr_mode, false); 6790 addr_space_t as = to_type == error_mark_node? ADDR_SPACE_GENERIC
6791 : TYPE_ADDR_SPACE (to_type);
6792 enum machine_mode pointer_mode = targetm.addr_space.pointer_mode (as);
6793 return build_reference_type_for_mode (to_type, pointer_mode, false);
5623 } 6794 }
5624 6795
5625 /* Build a type that is compatible with t but has no cv quals anywhere 6796 /* Build a type that is compatible with t but has no cv quals anywhere
5626 in its type, thus 6797 in its type, thus
5627 6798
5732 itype); 6903 itype);
5733 else 6904 else
5734 return itype; 6905 return itype;
5735 } 6906 }
5736 6907
6908 /* Return true if the debug information for TYPE, a subtype, should be emitted
6909 as a subrange type. If so, set LOWVAL to the low bound and HIGHVAL to the
6910 high bound, respectively. Sometimes doing so unnecessarily obfuscates the
6911 debug info and doesn't reflect the source code. */
6912
6913 bool
6914 subrange_type_for_debug_p (const_tree type, tree *lowval, tree *highval)
6915 {
6916 tree base_type = TREE_TYPE (type), low, high;
6917
6918 /* Subrange types have a base type which is an integral type. */
6919 if (!INTEGRAL_TYPE_P (base_type))
6920 return false;
6921
6922 /* Get the real bounds of the subtype. */
6923 if (lang_hooks.types.get_subrange_bounds)
6924 lang_hooks.types.get_subrange_bounds (type, &low, &high);
6925 else
6926 {
6927 low = TYPE_MIN_VALUE (type);
6928 high = TYPE_MAX_VALUE (type);
6929 }
6930
6931 /* If the type and its base type have the same representation and the same
6932 name, then the type is not a subrange but a copy of the base type. */
6933 if ((TREE_CODE (base_type) == INTEGER_TYPE
6934 || TREE_CODE (base_type) == BOOLEAN_TYPE)
6935 && int_size_in_bytes (type) == int_size_in_bytes (base_type)
6936 && tree_int_cst_equal (low, TYPE_MIN_VALUE (base_type))
6937 && tree_int_cst_equal (high, TYPE_MAX_VALUE (base_type)))
6938 {
6939 tree type_name = TYPE_NAME (type);
6940 tree base_type_name = TYPE_NAME (base_type);
6941
6942 if (type_name && TREE_CODE (type_name) == TYPE_DECL)
6943 type_name = DECL_NAME (type_name);
6944
6945 if (base_type_name && TREE_CODE (base_type_name) == TYPE_DECL)
6946 base_type_name = DECL_NAME (base_type_name);
6947
6948 if (type_name == base_type_name)
6949 return false;
6950 }
6951
6952 if (lowval)
6953 *lowval = low;
6954 if (highval)
6955 *highval = high;
6956 return true;
6957 }
6958
5737 /* Just like build_index_type, but takes lowval and highval instead 6959 /* Just like build_index_type, but takes lowval and highval instead
5738 of just highval (maxval). */ 6960 of just highval (maxval). */
5739 6961
5740 tree 6962 tree
5741 build_index_2_type (tree lowval, tree highval) 6963 build_index_2_type (tree lowval, tree highval)
5760 } 6982 }
5761 6983
5762 t = make_node (ARRAY_TYPE); 6984 t = make_node (ARRAY_TYPE);
5763 TREE_TYPE (t) = elt_type; 6985 TREE_TYPE (t) = elt_type;
5764 TYPE_DOMAIN (t) = index_type; 6986 TYPE_DOMAIN (t) = index_type;
5765 6987 TYPE_ADDR_SPACE (t) = TYPE_ADDR_SPACE (elt_type);
5766 if (index_type == 0) 6988 layout_type (t);
5767 { 6989
5768 tree save = t; 6990 /* If the element type is incomplete at this point we get marked for
5769 hashcode = iterative_hash_object (TYPE_HASH (elt_type), hashcode); 6991 structural equality. Do not record these types in the canonical
5770 t = type_hash_canon (hashcode, t); 6992 type hashtable. */
5771 if (save == t) 6993 if (TYPE_STRUCTURAL_EQUALITY_P (t))
5772 layout_type (t); 6994 return t;
5773
5774 if (TYPE_CANONICAL (t) == t)
5775 {
5776 if (TYPE_STRUCTURAL_EQUALITY_P (elt_type))
5777 SET_TYPE_STRUCTURAL_EQUALITY (t);
5778 else if (TYPE_CANONICAL (elt_type) != elt_type)
5779 TYPE_CANONICAL (t)
5780 = build_array_type (TYPE_CANONICAL (elt_type), index_type);
5781 }
5782
5783 return t;
5784 }
5785 6995
5786 hashcode = iterative_hash_object (TYPE_HASH (elt_type), hashcode); 6996 hashcode = iterative_hash_object (TYPE_HASH (elt_type), hashcode);
5787 hashcode = iterative_hash_object (TYPE_HASH (index_type), hashcode); 6997 if (index_type)
6998 hashcode = iterative_hash_object (TYPE_HASH (index_type), hashcode);
5788 t = type_hash_canon (hashcode, t); 6999 t = type_hash_canon (hashcode, t);
5789 7000
5790 if (!COMPLETE_TYPE_P (t))
5791 layout_type (t);
5792
5793 if (TYPE_CANONICAL (t) == t) 7001 if (TYPE_CANONICAL (t) == t)
5794 { 7002 {
5795 if (TYPE_STRUCTURAL_EQUALITY_P (elt_type) 7003 if (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
5796 || TYPE_STRUCTURAL_EQUALITY_P (index_type)) 7004 || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type)))
5797 SET_TYPE_STRUCTURAL_EQUALITY (t); 7005 SET_TYPE_STRUCTURAL_EQUALITY (t);
5798 else if (TYPE_CANONICAL (elt_type) != elt_type 7006 else if (TYPE_CANONICAL (elt_type) != elt_type
5799 || TYPE_CANONICAL (index_type) != index_type) 7007 || (index_type && TYPE_CANONICAL (index_type) != index_type))
5800 TYPE_CANONICAL (t) 7008 TYPE_CANONICAL (t)
5801 = build_array_type (TYPE_CANONICAL (elt_type), 7009 = build_array_type (TYPE_CANONICAL (elt_type),
5802 TYPE_CANONICAL (index_type)); 7010 index_type ? TYPE_CANONICAL (index_type) : NULL);
5803 } 7011 }
5804 7012
5805 return t; 7013 return t;
5806 } 7014 }
5807 7015
5816 7024
5817 return type; 7025 return type;
5818 } 7026 }
5819 7027
5820 /* Computes the canonical argument types from the argument type list 7028 /* Computes the canonical argument types from the argument type list
5821 ARGTYPES. 7029 ARGTYPES.
5822 7030
5823 Upon return, *ANY_STRUCTURAL_P will be true iff either it was true 7031 Upon return, *ANY_STRUCTURAL_P will be true iff either it was true
5824 on entry to this function, or if any of the ARGTYPES are 7032 on entry to this function, or if any of the ARGTYPES are
5825 structural. 7033 structural.
5826 7034
5830 7038
5831 Returns a canonical argument list, which may be ARGTYPES when the 7039 Returns a canonical argument list, which may be ARGTYPES when the
5832 canonical argument list is unneeded (i.e., *ANY_STRUCTURAL_P is 7040 canonical argument list is unneeded (i.e., *ANY_STRUCTURAL_P is
5833 true) or would not differ from ARGTYPES. */ 7041 true) or would not differ from ARGTYPES. */
5834 7042
5835 static tree 7043 static tree
5836 maybe_canonicalize_argtypes(tree argtypes, 7044 maybe_canonicalize_argtypes(tree argtypes,
5837 bool *any_structural_p, 7045 bool *any_structural_p,
5838 bool *any_noncanonical_p) 7046 bool *any_noncanonical_p)
5839 { 7047 {
5840 tree arg; 7048 tree arg;
5841 bool any_noncanonical_argtypes_p = false; 7049 bool any_noncanonical_argtypes_p = false;
5842 7050
5843 for (arg = argtypes; arg && !(*any_structural_p); arg = TREE_CHAIN (arg)) 7051 for (arg = argtypes; arg && !(*any_structural_p); arg = TREE_CHAIN (arg))
5844 { 7052 {
5845 if (!TREE_VALUE (arg) || TREE_VALUE (arg) == error_mark_node) 7053 if (!TREE_VALUE (arg) || TREE_VALUE (arg) == error_mark_node)
5846 /* Fail gracefully by stating that the type is structural. */ 7054 /* Fail gracefully by stating that the type is structural. */
5847 *any_structural_p = true; 7055 *any_structural_p = true;
5921 t = type_hash_canon (hashcode, t); 7129 t = type_hash_canon (hashcode, t);
5922 7130
5923 /* Set up the canonical type. */ 7131 /* Set up the canonical type. */
5924 any_structural_p = TYPE_STRUCTURAL_EQUALITY_P (value_type); 7132 any_structural_p = TYPE_STRUCTURAL_EQUALITY_P (value_type);
5925 any_noncanonical_p = TYPE_CANONICAL (value_type) != value_type; 7133 any_noncanonical_p = TYPE_CANONICAL (value_type) != value_type;
5926 canon_argtypes = maybe_canonicalize_argtypes (arg_types, 7134 canon_argtypes = maybe_canonicalize_argtypes (arg_types,
5927 &any_structural_p, 7135 &any_structural_p,
5928 &any_noncanonical_p); 7136 &any_noncanonical_p);
5929 if (any_structural_p) 7137 if (any_structural_p)
5930 SET_TYPE_STRUCTURAL_EQUALITY (t); 7138 SET_TYPE_STRUCTURAL_EQUALITY (t);
5931 else if (any_noncanonical_p) 7139 else if (any_noncanonical_p)
5932 TYPE_CANONICAL (t) = build_function_type (TYPE_CANONICAL (value_type), 7140 TYPE_CANONICAL (t) = build_function_type (TYPE_CANONICAL (value_type),
5933 canon_argtypes); 7141 canon_argtypes);
5934 7142
5935 if (!COMPLETE_TYPE_P (t)) 7143 if (!COMPLETE_TYPE_P (t))
5936 layout_type (t); 7144 layout_type (t);
5937 return t; 7145 return t;
5938 } 7146 }
5939 7147
5995 TYPE_NEXT_VARIANT (new_type) = NULL; 7203 TYPE_NEXT_VARIANT (new_type) = NULL;
5996 } 7204 }
5997 return new_type; 7205 return new_type;
5998 } 7206 }
5999 7207
6000 /* Build variant of function type ORIG_TYPE skipping ARGS_TO_SKIP. 7208 /* Build variant of function type ORIG_TYPE skipping ARGS_TO_SKIP.
6001 7209
6002 Arguments from DECL_ARGUMENTS list can't be removed now, since they are 7210 Arguments from DECL_ARGUMENTS list can't be removed now, since they are
6003 linked by TREE_CHAIN directly. It is caller responsibility to eliminate 7211 linked by TREE_CHAIN directly. It is caller responsibility to eliminate
6004 them when they are being duplicated (i.e. copy_arguments_for_versioning). */ 7212 them when they are being duplicated (i.e. copy_arguments_for_versioning). */
6005 7213
6006 tree 7214 tree
6134 &any_structural_p, 7342 &any_structural_p,
6135 &any_noncanonical_p); 7343 &any_noncanonical_p);
6136 if (any_structural_p) 7344 if (any_structural_p)
6137 SET_TYPE_STRUCTURAL_EQUALITY (t); 7345 SET_TYPE_STRUCTURAL_EQUALITY (t);
6138 else if (any_noncanonical_p) 7346 else if (any_noncanonical_p)
6139 TYPE_CANONICAL (t) 7347 TYPE_CANONICAL (t)
6140 = build_method_type_directly (TYPE_CANONICAL (basetype), 7348 = build_method_type_directly (TYPE_CANONICAL (basetype),
6141 TYPE_CANONICAL (rettype), 7349 TYPE_CANONICAL (rettype),
6142 canon_argtypes); 7350 canon_argtypes);
6143 if (!COMPLETE_TYPE_P (t)) 7351 if (!COMPLETE_TYPE_P (t))
6144 layout_type (t); 7352 layout_type (t);
6190 if (TYPE_STRUCTURAL_EQUALITY_P (basetype) 7398 if (TYPE_STRUCTURAL_EQUALITY_P (basetype)
6191 || TYPE_STRUCTURAL_EQUALITY_P (type)) 7399 || TYPE_STRUCTURAL_EQUALITY_P (type))
6192 SET_TYPE_STRUCTURAL_EQUALITY (t); 7400 SET_TYPE_STRUCTURAL_EQUALITY (t);
6193 else if (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype)) != basetype 7401 else if (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype)) != basetype
6194 || TYPE_CANONICAL (type) != type) 7402 || TYPE_CANONICAL (type) != type)
6195 TYPE_CANONICAL (t) 7403 TYPE_CANONICAL (t)
6196 = build_offset_type (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype)), 7404 = build_offset_type (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype)),
6197 TYPE_CANONICAL (type)); 7405 TYPE_CANONICAL (type));
6198 } 7406 }
6199 7407
6200 return t; 7408 return t;
6227 if (TYPE_CANONICAL (t) == t) 7435 if (TYPE_CANONICAL (t) == t)
6228 { 7436 {
6229 if (TYPE_STRUCTURAL_EQUALITY_P (component_type)) 7437 if (TYPE_STRUCTURAL_EQUALITY_P (component_type))
6230 SET_TYPE_STRUCTURAL_EQUALITY (t); 7438 SET_TYPE_STRUCTURAL_EQUALITY (t);
6231 else if (TYPE_CANONICAL (component_type) != component_type) 7439 else if (TYPE_CANONICAL (component_type) != component_type)
6232 TYPE_CANONICAL (t) 7440 TYPE_CANONICAL (t)
6233 = build_complex_type (TYPE_CANONICAL (component_type)); 7441 = build_complex_type (TYPE_CANONICAL (component_type));
6234 } 7442 }
6235 7443
6236 /* We need to create a name, since complex is a fundamental type. */ 7444 /* We need to create a name, since complex is a fundamental type. */
6237 if (! TYPE_NAME (t)) 7445 if (! TYPE_NAME (t))
6261 name = "complex long long unsigned int"; 7469 name = "complex long long unsigned int";
6262 else 7470 else
6263 name = 0; 7471 name = 0;
6264 7472
6265 if (name != 0) 7473 if (name != 0)
6266 TYPE_NAME (t) = build_decl (TYPE_DECL, get_identifier (name), t); 7474 TYPE_NAME (t) = build_decl (UNKNOWN_LOCATION, TYPE_DECL,
7475 get_identifier (name), t);
6267 } 7476 }
6268 7477
6269 return build_qualified_type (t, TYPE_QUALS (component_type)); 7478 return build_qualified_type (t, TYPE_QUALS (component_type));
7479 }
7480
7481 /* If TYPE is a real or complex floating-point type and the target
7482 does not directly support arithmetic on TYPE then return the wider
7483 type to be used for arithmetic on TYPE. Otherwise, return
7484 NULL_TREE. */
7485
7486 tree
7487 excess_precision_type (tree type)
7488 {
7489 if (flag_excess_precision != EXCESS_PRECISION_FAST)
7490 {
7491 int flt_eval_method = TARGET_FLT_EVAL_METHOD;
7492 switch (TREE_CODE (type))
7493 {
7494 case REAL_TYPE:
7495 switch (flt_eval_method)
7496 {
7497 case 1:
7498 if (TYPE_MODE (type) == TYPE_MODE (float_type_node))
7499 return double_type_node;
7500 break;
7501 case 2:
7502 if (TYPE_MODE (type) == TYPE_MODE (float_type_node)
7503 || TYPE_MODE (type) == TYPE_MODE (double_type_node))
7504 return long_double_type_node;
7505 break;
7506 default:
7507 gcc_unreachable ();
7508 }
7509 break;
7510 case COMPLEX_TYPE:
7511 if (TREE_CODE (TREE_TYPE (type)) != REAL_TYPE)
7512 return NULL_TREE;
7513 switch (flt_eval_method)
7514 {
7515 case 1:
7516 if (TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (float_type_node))
7517 return complex_double_type_node;
7518 break;
7519 case 2:
7520 if (TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (float_type_node)
7521 || (TYPE_MODE (TREE_TYPE (type))
7522 == TYPE_MODE (double_type_node)))
7523 return complex_long_double_type_node;
7524 break;
7525 default:
7526 gcc_unreachable ();
7527 }
7528 break;
7529 default:
7530 break;
7531 }
7532 }
7533 return NULL_TREE;
6270 } 7534 }
6271 7535
6272 /* Return OP, stripped of any conversions to wider types as much as is safe. 7536 /* Return OP, stripped of any conversions to wider types as much as is safe.
6273 Converting the value back to OP's type makes a value equivalent to OP. 7537 Converting the value back to OP's type makes a value equivalent to OP.
6274 7538
6600 TYPE_PRECISION (type)); 7864 TYPE_PRECISION (type));
6601 mpz_set_double_int (min, mn, false); 7865 mpz_set_double_int (min, mn, false);
6602 } 7866 }
6603 } 7867 }
6604 7868
6605 if (!POINTER_TYPE_P (type) && TYPE_MAX_VALUE (type) 7869 if (!POINTER_TYPE_P (type) && TYPE_MAX_VALUE (type)
6606 && TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST) 7870 && TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST)
6607 mpz_set_double_int (max, tree_to_double_int (TYPE_MAX_VALUE (type)), 7871 mpz_set_double_int (max, tree_to_double_int (TYPE_MAX_VALUE (type)),
6608 TYPE_UNSIGNED (type)); 7872 TYPE_UNSIGNED (type));
6609 else 7873 else
6610 { 7874 {
6899 fprintf (stderr, "(No per-node statistics)\n"); 8163 fprintf (stderr, "(No per-node statistics)\n");
6900 #endif 8164 #endif
6901 print_type_hash_statistics (); 8165 print_type_hash_statistics ();
6902 print_debug_expr_statistics (); 8166 print_debug_expr_statistics ();
6903 print_value_expr_statistics (); 8167 print_value_expr_statistics ();
6904 print_restrict_base_statistics ();
6905 lang_hooks.print_statistics (); 8168 lang_hooks.print_statistics ();
6906 } 8169 }
6907 8170
6908 #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s" 8171 #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s"
6909 8172
7050 buffer = tmp = (char *) alloca (length); 8313 buffer = tmp = (char *) alloca (length);
7051 length = 0; 8314 length = 0;
7052 while ((code = va_arg (args, int))) 8315 while ((code = va_arg (args, int)))
7053 { 8316 {
7054 const char *prefix = length ? " or " : "expected "; 8317 const char *prefix = length ? " or " : "expected ";
7055 8318
7056 strcpy (tmp + length, prefix); 8319 strcpy (tmp + length, prefix);
7057 length += strlen (prefix); 8320 length += strlen (prefix);
7058 strcpy (tmp + length, tree_code_name[code]); 8321 strcpy (tmp + length, tree_code_name[code]);
7059 length += strlen (tree_code_name[code]); 8322 length += strlen (tree_code_name[code]);
7060 } 8323 }
7127 const char *function, enum tree_code c1, 8390 const char *function, enum tree_code c1,
7128 enum tree_code c2) 8391 enum tree_code c2)
7129 { 8392 {
7130 char *buffer; 8393 char *buffer;
7131 unsigned length = 0; 8394 unsigned length = 0;
7132 enum tree_code c; 8395 unsigned int c;
7133 8396
7134 for (c = c1; c <= c2; ++c) 8397 for (c = c1; c <= c2; ++c)
7135 length += 4 + strlen (tree_code_name[c]); 8398 length += 4 + strlen (tree_code_name[c]);
7136 8399
7137 length += strlen ("expected "); 8400 length += strlen ("expected ");
7188 const char *function, enum omp_clause_code c1, 8451 const char *function, enum omp_clause_code c1,
7189 enum omp_clause_code c2) 8452 enum omp_clause_code c2)
7190 { 8453 {
7191 char *buffer; 8454 char *buffer;
7192 unsigned length = 0; 8455 unsigned length = 0;
7193 enum omp_clause_code c; 8456 unsigned int c;
7194 8457
7195 for (c = c1; c <= c2; ++c) 8458 for (c = c1; c <= c2; ++c)
7196 length += 4 + strlen (omp_clause_code_name[c]); 8459 length += 4 + strlen (omp_clause_code_name[c]);
7197 8460
7198 length += strlen ("expected "); 8461 length += strlen ("expected ");
7227 8490
7228 /* Similar to tree_class_check_failed, except that we check for 8491 /* Similar to tree_class_check_failed, except that we check for
7229 whether CODE contains the tree structure identified by EN. */ 8492 whether CODE contains the tree structure identified by EN. */
7230 8493
7231 void 8494 void
7232 tree_contains_struct_check_failed (const_tree node, 8495 tree_contains_struct_check_failed (const_tree node,
7233 const enum tree_node_structure_enum en, 8496 const enum tree_node_structure_enum en,
7234 const char *file, int line, 8497 const char *file, int line,
7235 const char *function) 8498 const char *function)
7236 { 8499 {
7237 internal_error 8500 internal_error
7238 ("tree check: expected tree that contains %qs structure, have %qs in %s, at %s:%d", 8501 ("tree check: expected tree that contains %qs structure, have %qs in %s, at %s:%d",
7239 TS_ENUM_NAME(en), 8502 TS_ENUM_NAME(en),
7290 make_vector_type (tree innertype, int nunits, enum machine_mode mode) 8553 make_vector_type (tree innertype, int nunits, enum machine_mode mode)
7291 { 8554 {
7292 tree t; 8555 tree t;
7293 hashval_t hashcode = 0; 8556 hashval_t hashcode = 0;
7294 8557
7295 /* Build a main variant, based on the main variant of the inner type, then
7296 use it to build the variant we return. */
7297 if ((TYPE_ATTRIBUTES (innertype) || TYPE_QUALS (innertype))
7298 && TYPE_MAIN_VARIANT (innertype) != innertype)
7299 return build_type_attribute_qual_variant (
7300 make_vector_type (TYPE_MAIN_VARIANT (innertype), nunits, mode),
7301 TYPE_ATTRIBUTES (innertype),
7302 TYPE_QUALS (innertype));
7303
7304 t = make_node (VECTOR_TYPE); 8558 t = make_node (VECTOR_TYPE);
7305 TREE_TYPE (t) = TYPE_MAIN_VARIANT (innertype); 8559 TREE_TYPE (t) = TYPE_MAIN_VARIANT (innertype);
7306 SET_TYPE_VECTOR_SUBPARTS (t, nunits); 8560 SET_TYPE_VECTOR_SUBPARTS (t, nunits);
7307 SET_TYPE_MODE (t, mode); 8561 SET_TYPE_MODE (t, mode);
7308 TYPE_READONLY (t) = TYPE_READONLY (innertype);
7309 TYPE_VOLATILE (t) = TYPE_VOLATILE (innertype);
7310 8562
7311 if (TYPE_STRUCTURAL_EQUALITY_P (innertype)) 8563 if (TYPE_STRUCTURAL_EQUALITY_P (innertype))
7312 SET_TYPE_STRUCTURAL_EQUALITY (t); 8564 SET_TYPE_STRUCTURAL_EQUALITY (t);
7313 else if (TYPE_CANONICAL (innertype) != innertype 8565 else if (TYPE_CANONICAL (innertype) != innertype
7314 || mode != VOIDmode) 8566 || mode != VOIDmode)
7315 TYPE_CANONICAL (t) 8567 TYPE_CANONICAL (t)
7316 = make_vector_type (TYPE_CANONICAL (innertype), nunits, VOIDmode); 8568 = make_vector_type (TYPE_CANONICAL (innertype), nunits, VOIDmode);
7317 8569
7318 layout_type (t); 8570 layout_type (t);
7319 8571
7320 { 8572 {
7321 tree index = build_int_cst (NULL_TREE, nunits - 1); 8573 tree index = build_int_cst (NULL_TREE, nunits - 1);
7322 tree array = build_array_type (innertype, build_index_type (index)); 8574 tree array = build_array_type (TYPE_MAIN_VARIANT (innertype),
8575 build_index_type (index));
7323 tree rt = make_node (RECORD_TYPE); 8576 tree rt = make_node (RECORD_TYPE);
7324 8577
7325 TYPE_FIELDS (rt) = build_decl (FIELD_DECL, get_identifier ("f"), array); 8578 TYPE_FIELDS (rt) = build_decl (UNKNOWN_LOCATION, FIELD_DECL,
8579 get_identifier ("f"), array);
7326 DECL_CONTEXT (TYPE_FIELDS (rt)) = rt; 8580 DECL_CONTEXT (TYPE_FIELDS (rt)) = rt;
7327 layout_type (rt); 8581 layout_type (rt);
7328 TYPE_DEBUG_REPRESENTATION_TYPE (t) = rt; 8582 TYPE_DEBUG_REPRESENTATION_TYPE (t) = rt;
7329 /* In dwarfout.c, type lookup uses TYPE_UID numbers. We want to output 8583 /* In dwarfout.c, type lookup uses TYPE_UID numbers. We want to output
7330 the representation type, and we want to find that die when looking up 8584 the representation type, and we want to find that die when looking up
7332 numbers equal. */ 8586 numbers equal. */
7333 TYPE_UID (rt) = TYPE_UID (t); 8587 TYPE_UID (rt) = TYPE_UID (t);
7334 } 8588 }
7335 8589
7336 hashcode = iterative_hash_host_wide_int (VECTOR_TYPE, hashcode); 8590 hashcode = iterative_hash_host_wide_int (VECTOR_TYPE, hashcode);
8591 hashcode = iterative_hash_host_wide_int (nunits, hashcode);
7337 hashcode = iterative_hash_host_wide_int (mode, hashcode); 8592 hashcode = iterative_hash_host_wide_int (mode, hashcode);
7338 hashcode = iterative_hash_object (TYPE_HASH (innertype), hashcode); 8593 hashcode = iterative_hash_object (TYPE_HASH (TREE_TYPE (t)), hashcode);
7339 return type_hash_canon (hashcode, t); 8594 t = type_hash_canon (hashcode, t);
8595
8596 /* We have built a main variant, based on the main variant of the
8597 inner type. Use it to build the variant we return. */
8598 if ((TYPE_ATTRIBUTES (innertype) || TYPE_QUALS (innertype))
8599 && TREE_TYPE (t) != innertype)
8600 return build_type_attribute_qual_variant (t,
8601 TYPE_ATTRIBUTES (innertype),
8602 TYPE_QUALS (innertype));
8603
8604 return t;
7340 } 8605 }
7341 8606
7342 static tree 8607 static tree
7343 make_or_reuse_type (unsigned size, int unsignedp) 8608 make_or_reuse_type (unsigned size, int unsignedp)
7344 { 8609 {
7557 uint32_type_node = build_nonstandard_integer_type (32, true); 8822 uint32_type_node = build_nonstandard_integer_type (32, true);
7558 uint64_type_node = build_nonstandard_integer_type (64, true); 8823 uint64_type_node = build_nonstandard_integer_type (64, true);
7559 8824
7560 /* Decimal float types. */ 8825 /* Decimal float types. */
7561 dfloat32_type_node = make_node (REAL_TYPE); 8826 dfloat32_type_node = make_node (REAL_TYPE);
7562 TYPE_PRECISION (dfloat32_type_node) = DECIMAL32_TYPE_SIZE; 8827 TYPE_PRECISION (dfloat32_type_node) = DECIMAL32_TYPE_SIZE;
7563 layout_type (dfloat32_type_node); 8828 layout_type (dfloat32_type_node);
7564 SET_TYPE_MODE (dfloat32_type_node, SDmode); 8829 SET_TYPE_MODE (dfloat32_type_node, SDmode);
7565 dfloat32_ptr_type_node = build_pointer_type (dfloat32_type_node); 8830 dfloat32_ptr_type_node = build_pointer_type (dfloat32_type_node);
7566 8831
7567 dfloat64_type_node = make_node (REAL_TYPE); 8832 dfloat64_type_node = make_node (REAL_TYPE);
7569 layout_type (dfloat64_type_node); 8834 layout_type (dfloat64_type_node);
7570 SET_TYPE_MODE (dfloat64_type_node, DDmode); 8835 SET_TYPE_MODE (dfloat64_type_node, DDmode);
7571 dfloat64_ptr_type_node = build_pointer_type (dfloat64_type_node); 8836 dfloat64_ptr_type_node = build_pointer_type (dfloat64_type_node);
7572 8837
7573 dfloat128_type_node = make_node (REAL_TYPE); 8838 dfloat128_type_node = make_node (REAL_TYPE);
7574 TYPE_PRECISION (dfloat128_type_node) = DECIMAL128_TYPE_SIZE; 8839 TYPE_PRECISION (dfloat128_type_node) = DECIMAL128_TYPE_SIZE;
7575 layout_type (dfloat128_type_node); 8840 layout_type (dfloat128_type_node);
7576 SET_TYPE_MODE (dfloat128_type_node, TDmode); 8841 SET_TYPE_MODE (dfloat128_type_node, TDmode);
7577 dfloat128_ptr_type_node = build_pointer_type (dfloat128_type_node); 8842 dfloat128_ptr_type_node = build_pointer_type (dfloat128_type_node);
7578 8843
7579 complex_integer_type_node = build_complex_type (integer_type_node); 8844 complex_integer_type_node = build_complex_type (integer_type_node);
7642 record type without a name. This breaks name mangling. So, 8907 record type without a name. This breaks name mangling. So,
7643 don't copy record types and let c_common_nodes_and_builtins() 8908 don't copy record types and let c_common_nodes_and_builtins()
7644 declare the type to be __builtin_va_list. */ 8909 declare the type to be __builtin_va_list. */
7645 if (TREE_CODE (t) != RECORD_TYPE) 8910 if (TREE_CODE (t) != RECORD_TYPE)
7646 t = build_variant_type_copy (t); 8911 t = build_variant_type_copy (t);
7647 8912
7648 va_list_type_node = t; 8913 va_list_type_node = t;
7649 } 8914 }
7650 } 8915 }
7651 8916
7652 /* A subroutine of build_common_builtin_nodes. Define a builtin function. */ 8917 /* A subroutine of build_common_builtin_nodes. Define a builtin function. */
7681 are relied upon by the tree optimizers and the middle-end. */ 8946 are relied upon by the tree optimizers and the middle-end. */
7682 8947
7683 void 8948 void
7684 build_common_builtin_nodes (void) 8949 build_common_builtin_nodes (void)
7685 { 8950 {
7686 tree tmp, ftype; 8951 tree tmp, tmp2, ftype;
7687 8952
7688 if (built_in_decls[BUILT_IN_MEMCPY] == NULL 8953 if (built_in_decls[BUILT_IN_MEMCPY] == NULL
7689 || built_in_decls[BUILT_IN_MEMMOVE] == NULL) 8954 || built_in_decls[BUILT_IN_MEMMOVE] == NULL)
7690 { 8955 {
7691 tmp = tree_cons (NULL_TREE, size_type_node, void_list_node); 8956 tmp = tree_cons (NULL_TREE, size_type_node, void_list_node);
7724 if (built_in_decls[BUILT_IN_ALLOCA] == NULL) 8989 if (built_in_decls[BUILT_IN_ALLOCA] == NULL)
7725 { 8990 {
7726 tmp = tree_cons (NULL_TREE, size_type_node, void_list_node); 8991 tmp = tree_cons (NULL_TREE, size_type_node, void_list_node);
7727 ftype = build_function_type (ptr_type_node, tmp); 8992 ftype = build_function_type (ptr_type_node, tmp);
7728 local_define_builtin ("__builtin_alloca", ftype, BUILT_IN_ALLOCA, 8993 local_define_builtin ("__builtin_alloca", ftype, BUILT_IN_ALLOCA,
7729 "alloca", ECF_NOTHROW | ECF_MALLOC); 8994 "alloca",
8995 ECF_MALLOC | (flag_stack_check ? 0 : ECF_NOTHROW));
7730 } 8996 }
7731 8997
7732 tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node); 8998 tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
7733 tmp = tree_cons (NULL_TREE, ptr_type_node, tmp); 8999 tmp = tree_cons (NULL_TREE, ptr_type_node, tmp);
7734 tmp = tree_cons (NULL_TREE, ptr_type_node, tmp); 9000 tmp = tree_cons (NULL_TREE, ptr_type_node, tmp);
7786 local_define_builtin ("__builtin_profile_func_enter", ftype, 9052 local_define_builtin ("__builtin_profile_func_enter", ftype,
7787 BUILT_IN_PROFILE_FUNC_ENTER, "profile_func_enter", 0); 9053 BUILT_IN_PROFILE_FUNC_ENTER, "profile_func_enter", 0);
7788 local_define_builtin ("__builtin_profile_func_exit", ftype, 9054 local_define_builtin ("__builtin_profile_func_exit", ftype,
7789 BUILT_IN_PROFILE_FUNC_EXIT, "profile_func_exit", 0); 9055 BUILT_IN_PROFILE_FUNC_EXIT, "profile_func_exit", 0);
7790 9056
9057 /* If there's a possibility that we might use the ARM EABI, build the
9058 alternate __cxa_end_cleanup node used to resume from C++ and Java. */
9059 if (targetm.arm_eabi_unwinder)
9060 {
9061 ftype = build_function_type (void_type_node, void_list_node);
9062 local_define_builtin ("__builtin_cxa_end_cleanup", ftype,
9063 BUILT_IN_CXA_END_CLEANUP,
9064 "__cxa_end_cleanup", ECF_NORETURN);
9065 }
9066
9067 tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
9068 ftype = build_function_type (void_type_node, tmp);
9069 local_define_builtin ("__builtin_unwind_resume", ftype,
9070 BUILT_IN_UNWIND_RESUME,
9071 (USING_SJLJ_EXCEPTIONS
9072 ? "_Unwind_SjLj_Resume" : "_Unwind_Resume"),
9073 ECF_NORETURN);
9074
9075 /* The exception object and filter values from the runtime. The argument
9076 must be zero before exception lowering, i.e. from the front end. After
9077 exception lowering, it will be the region number for the exception
9078 landing pad. These functions are PURE instead of CONST to prevent
9079 them from being hoisted past the exception edge that will initialize
9080 its value in the landing pad. */
9081 tmp = tree_cons (NULL_TREE, integer_type_node, void_list_node);
9082 ftype = build_function_type (ptr_type_node, tmp);
9083 local_define_builtin ("__builtin_eh_pointer", ftype, BUILT_IN_EH_POINTER,
9084 "__builtin_eh_pointer", ECF_PURE | ECF_NOTHROW);
9085
9086 tmp2 = lang_hooks.types.type_for_mode (targetm.eh_return_filter_mode (), 0);
9087 ftype = build_function_type (tmp2, tmp);
9088 local_define_builtin ("__builtin_eh_filter", ftype, BUILT_IN_EH_FILTER,
9089 "__builtin_eh_filter", ECF_PURE | ECF_NOTHROW);
9090
9091 tmp = tree_cons (NULL_TREE, integer_type_node, void_list_node);
9092 tmp = tree_cons (NULL_TREE, integer_type_node, tmp);
9093 ftype = build_function_type (void_type_node, tmp);
9094 local_define_builtin ("__builtin_eh_copy_values", ftype,
9095 BUILT_IN_EH_COPY_VALUES,
9096 "__builtin_eh_copy_values", ECF_NOTHROW);
9097
7791 /* Complex multiplication and division. These are handled as builtins 9098 /* Complex multiplication and division. These are handled as builtins
7792 rather than optabs because emit_library_call_value doesn't support 9099 rather than optabs because emit_library_call_value doesn't support
7793 complex. Further, we can do slightly better with folding these 9100 complex. Further, we can do slightly better with folding these
7794 beasties if the real and complex parts of the arguments are separate. */ 9101 beasties if the real and complex parts of the arguments are separate. */
7795 { 9102 {
7796 enum machine_mode mode; 9103 int mode;
7797 9104
7798 for (mode = MIN_MODE_COMPLEX_FLOAT; mode <= MAX_MODE_COMPLEX_FLOAT; ++mode) 9105 for (mode = MIN_MODE_COMPLEX_FLOAT; mode <= MAX_MODE_COMPLEX_FLOAT; ++mode)
7799 { 9106 {
7800 char mode_name_buf[4], *q; 9107 char mode_name_buf[4], *q;
7801 const char *p; 9108 const char *p;
7802 enum built_in_function mcode, dcode; 9109 enum built_in_function mcode, dcode;
7803 tree type, inner_type; 9110 tree type, inner_type;
7804 9111
7805 type = lang_hooks.types.type_for_mode (mode, 0); 9112 type = lang_hooks.types.type_for_mode ((enum machine_mode) mode, 0);
7806 if (type == NULL) 9113 if (type == NULL)
7807 continue; 9114 continue;
7808 inner_type = TREE_TYPE (type); 9115 inner_type = TREE_TYPE (type);
7809 9116
7810 tmp = tree_cons (NULL_TREE, inner_type, void_list_node); 9117 tmp = tree_cons (NULL_TREE, inner_type, void_list_node);
7811 tmp = tree_cons (NULL_TREE, inner_type, tmp); 9118 tmp = tree_cons (NULL_TREE, inner_type, tmp);
7812 tmp = tree_cons (NULL_TREE, inner_type, tmp); 9119 tmp = tree_cons (NULL_TREE, inner_type, tmp);
7813 tmp = tree_cons (NULL_TREE, inner_type, tmp); 9120 tmp = tree_cons (NULL_TREE, inner_type, tmp);
7814 ftype = build_function_type (type, tmp); 9121 ftype = build_function_type (type, tmp);
7815 9122
7816 mcode = BUILT_IN_COMPLEX_MUL_MIN + mode - MIN_MODE_COMPLEX_FLOAT; 9123 mcode = ((enum built_in_function)
7817 dcode = BUILT_IN_COMPLEX_DIV_MIN + mode - MIN_MODE_COMPLEX_FLOAT; 9124 (BUILT_IN_COMPLEX_MUL_MIN + mode - MIN_MODE_COMPLEX_FLOAT));
9125 dcode = ((enum built_in_function)
9126 (BUILT_IN_COMPLEX_DIV_MIN + mode - MIN_MODE_COMPLEX_FLOAT));
7818 9127
7819 for (p = GET_MODE_NAME (mode), q = mode_name_buf; *p; p++, q++) 9128 for (p = GET_MODE_NAME (mode), q = mode_name_buf; *p; p++, q++)
7820 *q = TOLOWER (*p); 9129 *q = TOLOWER (*p);
7821 *q = '\0'; 9130 *q = '\0';
7822 9131
7843 9152
7844 tree 9153 tree
7845 reconstruct_complex_type (tree type, tree bottom) 9154 reconstruct_complex_type (tree type, tree bottom)
7846 { 9155 {
7847 tree inner, outer; 9156 tree inner, outer;
7848 9157
7849 if (TREE_CODE (type) == POINTER_TYPE) 9158 if (TREE_CODE (type) == POINTER_TYPE)
7850 { 9159 {
7851 inner = reconstruct_complex_type (TREE_TYPE (type), bottom); 9160 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
7852 outer = build_pointer_type_for_mode (inner, TYPE_MODE (type), 9161 outer = build_pointer_type_for_mode (inner, TYPE_MODE (type),
7853 TYPE_REF_CAN_ALIAS_ALL (type)); 9162 TYPE_REF_CAN_ALIAS_ALL (type));
7871 else if (TREE_CODE (type) == METHOD_TYPE) 9180 else if (TREE_CODE (type) == METHOD_TYPE)
7872 { 9181 {
7873 inner = reconstruct_complex_type (TREE_TYPE (type), bottom); 9182 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
7874 /* The build_method_type_directly() routine prepends 'this' to argument list, 9183 /* The build_method_type_directly() routine prepends 'this' to argument list,
7875 so we must compensate by getting rid of it. */ 9184 so we must compensate by getting rid of it. */
7876 outer 9185 outer
7877 = build_method_type_directly 9186 = build_method_type_directly
7878 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (type))), 9187 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (type))),
7879 inner, 9188 inner,
7880 TREE_CHAIN (TYPE_ARG_TYPES (type))); 9189 TREE_CHAIN (TYPE_ARG_TYPES (type)));
7881 } 9190 }
7882 else if (TREE_CODE (type) == OFFSET_TYPE) 9191 else if (TREE_CODE (type) == OFFSET_TYPE)
7885 outer = build_offset_type (TYPE_OFFSET_BASETYPE (type), inner); 9194 outer = build_offset_type (TYPE_OFFSET_BASETYPE (type), inner);
7886 } 9195 }
7887 else 9196 else
7888 return bottom; 9197 return bottom;
7889 9198
7890 return build_qualified_type (outer, TYPE_QUALS (type)); 9199 return build_type_attribute_qual_variant (outer, TYPE_ATTRIBUTES (type),
9200 TYPE_QUALS (type));
7891 } 9201 }
7892 9202
7893 /* Returns a vector tree node given a mode (integer, vector, or BLKmode) and 9203 /* Returns a vector tree node given a mode (integer, vector, or BLKmode) and
7894 the inner type. */ 9204 the inner type. */
7895 tree 9205 tree
7931 build_vector_type (tree innertype, int nunits) 9241 build_vector_type (tree innertype, int nunits)
7932 { 9242 {
7933 return make_vector_type (innertype, nunits, VOIDmode); 9243 return make_vector_type (innertype, nunits, VOIDmode);
7934 } 9244 }
7935 9245
7936 9246 /* Similarly, but takes the inner type and number of units, which must be
7937 /* Build RESX_EXPR with given REGION_NUMBER. */ 9247 a power of two. */
7938 tree 9248
7939 build_resx (int region_number) 9249 tree
9250 build_opaque_vector_type (tree innertype, int nunits)
7940 { 9251 {
7941 tree t; 9252 tree t;
7942 t = build1 (RESX_EXPR, void_type_node, 9253 innertype = build_distinct_type_copy (innertype);
7943 build_int_cst (NULL_TREE, region_number)); 9254 t = make_vector_type (innertype, nunits, VOIDmode);
9255 TYPE_VECTOR_OPAQUE (t) = true;
7944 return t; 9256 return t;
7945 } 9257 }
9258
7946 9259
7947 /* Given an initializer INIT, return TRUE if INIT is zero or some 9260 /* Given an initializer INIT, return TRUE if INIT is zero or some
7948 aggregate of zeros. Otherwise return FALSE. */ 9261 aggregate of zeros. Otherwise return FALSE. */
7949 bool 9262 bool
7950 initializer_zerop (const_tree init) 9263 initializer_zerop (const_tree init)
7993 default: 9306 default:
7994 return false; 9307 return false;
7995 } 9308 }
7996 } 9309 }
7997 9310
7998 /* Build an empty statement. */ 9311 /* Build an empty statement at location LOC. */
7999 9312
8000 tree 9313 tree
8001 build_empty_stmt (void) 9314 build_empty_stmt (location_t loc)
8002 { 9315 {
8003 return build1 (NOP_EXPR, void_type_node, size_zero_node); 9316 tree t = build1 (NOP_EXPR, void_type_node, size_zero_node);
8004 } 9317 SET_EXPR_LOCATION (t, loc);
8005 9318 return t;
8006 9319 }
8007 /* Build an OpenMP clause with code CODE. */ 9320
8008 9321
8009 tree 9322 /* Build an OpenMP clause with code CODE. LOC is the location of the
8010 build_omp_clause (enum omp_clause_code code) 9323 clause. */
9324
9325 tree
9326 build_omp_clause (location_t loc, enum omp_clause_code code)
8011 { 9327 {
8012 tree t; 9328 tree t;
8013 int size, length; 9329 int size, length;
8014 9330
8015 length = omp_clause_num_ops[code]; 9331 length = omp_clause_num_ops[code];
8017 9333
8018 t = GGC_NEWVAR (union tree_node, size); 9334 t = GGC_NEWVAR (union tree_node, size);
8019 memset (t, 0, size); 9335 memset (t, 0, size);
8020 TREE_SET_CODE (t, OMP_CLAUSE); 9336 TREE_SET_CODE (t, OMP_CLAUSE);
8021 OMP_CLAUSE_SET_CODE (t, code); 9337 OMP_CLAUSE_SET_CODE (t, code);
9338 OMP_CLAUSE_LOCATION (t) = loc;
8022 9339
8023 #ifdef GATHER_STATISTICS 9340 #ifdef GATHER_STATISTICS
8024 tree_node_counts[(int) omp_clause_kind]++; 9341 tree_node_counts[(int) omp_clause_kind]++;
8025 tree_node_sizes[(int) omp_clause_kind] += size; 9342 tree_node_sizes[(int) omp_clause_kind] += size;
8026 #endif 9343 #endif
8027 9344
8028 return t; 9345 return t;
8029 }
8030
8031 /* Set various status flags when building a CALL_EXPR object T. */
8032
8033 static void
8034 process_call_operands (tree t)
8035 {
8036 bool side_effects;
8037
8038 side_effects = TREE_SIDE_EFFECTS (t);
8039 if (!side_effects)
8040 {
8041 int i, n;
8042 n = TREE_OPERAND_LENGTH (t);
8043 for (i = 1; i < n; i++)
8044 {
8045 tree op = TREE_OPERAND (t, i);
8046 if (op && TREE_SIDE_EFFECTS (op))
8047 {
8048 side_effects = 1;
8049 break;
8050 }
8051 }
8052 }
8053 if (!side_effects)
8054 {
8055 int i;
8056
8057 /* Calls have side-effects, except those to const or
8058 pure functions. */
8059 i = call_expr_flags (t);
8060 if ((i & ECF_LOOPING_CONST_OR_PURE) || !(i & (ECF_CONST | ECF_PURE)))
8061 side_effects = 1;
8062 }
8063 TREE_SIDE_EFFECTS (t) = side_effects;
8064 } 9346 }
8065 9347
8066 /* Build a tcc_vl_exp object with code CODE and room for LEN operands. LEN 9348 /* Build a tcc_vl_exp object with code CODE and room for LEN operands. LEN
8067 includes the implicit operand count in TREE_OPERAND 0, and so must be >= 1. 9349 includes the implicit operand count in TREE_OPERAND 0, and so must be >= 1.
8068 Except for the CODE and operand count field, other storage for the 9350 Except for the CODE and operand count field, other storage for the
8154 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and 9436 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
8155 FN and a null static chain slot. NARGS is the number of call arguments 9437 FN and a null static chain slot. NARGS is the number of call arguments
8156 which are specified as a tree array ARGS. */ 9438 which are specified as a tree array ARGS. */
8157 9439
8158 tree 9440 tree
8159 build_call_array (tree return_type, tree fn, int nargs, tree *args) 9441 build_call_array_loc (location_t loc, tree return_type, tree fn,
9442 int nargs, const tree *args)
8160 { 9443 {
8161 tree t; 9444 tree t;
8162 int i; 9445 int i;
8163 9446
8164 t = build_vl_exp (CALL_EXPR, nargs + 3); 9447 t = build_vl_exp (CALL_EXPR, nargs + 3);
8166 CALL_EXPR_FN (t) = fn; 9449 CALL_EXPR_FN (t) = fn;
8167 CALL_EXPR_STATIC_CHAIN (t) = NULL_TREE; 9450 CALL_EXPR_STATIC_CHAIN (t) = NULL_TREE;
8168 for (i = 0; i < nargs; i++) 9451 for (i = 0; i < nargs; i++)
8169 CALL_EXPR_ARG (t, i) = args[i]; 9452 CALL_EXPR_ARG (t, i) = args[i];
8170 process_call_operands (t); 9453 process_call_operands (t);
9454 SET_EXPR_LOCATION (t, loc);
8171 return t; 9455 return t;
9456 }
9457
9458 /* Like build_call_array, but takes a VEC. */
9459
9460 tree
9461 build_call_vec (tree return_type, tree fn, VEC(tree,gc) *args)
9462 {
9463 tree ret, t;
9464 unsigned int ix;
9465
9466 ret = build_vl_exp (CALL_EXPR, VEC_length (tree, args) + 3);
9467 TREE_TYPE (ret) = return_type;
9468 CALL_EXPR_FN (ret) = fn;
9469 CALL_EXPR_STATIC_CHAIN (ret) = NULL_TREE;
9470 for (ix = 0; VEC_iterate (tree, args, ix, t); ++ix)
9471 CALL_EXPR_ARG (ret, ix) = t;
9472 process_call_operands (ret);
9473 return ret;
8172 } 9474 }
8173 9475
8174 9476
8175 /* Returns true if it is possible to prove that the index of 9477 /* Returns true if it is possible to prove that the index of
8176 an array access REF (an ARRAY_REF expression) falls into the 9478 an array access REF (an ARRAY_REF expression) falls into the
8314 } 9616 }
8315 9617
8316 return val; 9618 return val;
8317 } 9619 }
8318 9620
9621 /* Return value of a constant X and sign-extend it. */
9622
9623 HOST_WIDEST_INT
9624 widest_int_cst_value (const_tree x)
9625 {
9626 unsigned bits = TYPE_PRECISION (TREE_TYPE (x));
9627 unsigned HOST_WIDEST_INT val = TREE_INT_CST_LOW (x);
9628
9629 #if HOST_BITS_PER_WIDEST_INT > HOST_BITS_PER_WIDE_INT
9630 gcc_assert (HOST_BITS_PER_WIDEST_INT >= 2 * HOST_BITS_PER_WIDE_INT);
9631 val |= (((unsigned HOST_WIDEST_INT) TREE_INT_CST_HIGH (x))
9632 << HOST_BITS_PER_WIDE_INT);
9633 #else
9634 /* Make sure the sign-extended value will fit in a HOST_WIDE_INT. */
9635 gcc_assert (TREE_INT_CST_HIGH (x) == 0
9636 || TREE_INT_CST_HIGH (x) == -1);
9637 #endif
9638
9639 if (bits < HOST_BITS_PER_WIDEST_INT)
9640 {
9641 bool negative = ((val >> (bits - 1)) & 1) != 0;
9642 if (negative)
9643 val |= (~(unsigned HOST_WIDEST_INT) 0) << (bits - 1) << 1;
9644 else
9645 val &= ~((~(unsigned HOST_WIDEST_INT) 0) << (bits - 1) << 1);
9646 }
9647
9648 return val;
9649 }
9650
8319 /* If TYPE is an integral type, return an equivalent type which is 9651 /* If TYPE is an integral type, return an equivalent type which is
8320 unsigned iff UNSIGNEDP is true. If TYPE is not an integral type, 9652 unsigned iff UNSIGNEDP is true. If TYPE is not an integral type,
8321 return TYPE itself. */ 9653 return TYPE itself. */
8322 9654
8323 tree 9655 tree
8324 signed_or_unsigned_type_for (int unsignedp, tree type) 9656 signed_or_unsigned_type_for (int unsignedp, tree type)
8325 { 9657 {
8326 tree t = type; 9658 tree t = type;
8327 if (POINTER_TYPE_P (type)) 9659 if (POINTER_TYPE_P (type))
8328 t = size_type_node; 9660 {
9661 /* If the pointer points to the normal address space, use the
9662 size_type_node. Otherwise use an appropriate size for the pointer
9663 based on the named address space it points to. */
9664 if (!TYPE_ADDR_SPACE (TREE_TYPE (t)))
9665 t = size_type_node;
9666 else
9667 return lang_hooks.types.type_for_size (TYPE_PRECISION (t), unsignedp);
9668 }
8329 9669
8330 if (!INTEGRAL_TYPE_P (t) || TYPE_UNSIGNED (t) == unsignedp) 9670 if (!INTEGRAL_TYPE_P (t) || TYPE_UNSIGNED (t) == unsignedp)
8331 return t; 9671 return t;
8332 9672
8333 return lang_hooks.types.type_for_size (TYPE_PRECISION (t), unsignedp); 9673 return lang_hooks.types.type_for_size (TYPE_PRECISION (t), unsignedp);
8334 } 9674 }
8335 9675
8336 /* Returns unsigned variant of TYPE. */ 9676 /* Returns unsigned variant of TYPE. */
8337 9677
8473 return 0; 9813 return 0;
8474 return operand_equal_p (arg0, arg1, 0); 9814 return operand_equal_p (arg0, arg1, 0);
8475 } 9815 }
8476 9816
8477 /* Returns number of zeros at the end of binary representation of X. 9817 /* Returns number of zeros at the end of binary representation of X.
8478 9818
8479 ??? Use ffs if available? */ 9819 ??? Use ffs if available? */
8480 9820
8481 tree 9821 tree
8482 num_ending_zeros (const_tree x) 9822 num_ending_zeros (const_tree x)
8483 { 9823 {
8801 for (i = 0; i < len; ++i) 10141 for (i = 0; i < len; ++i)
8802 WALK_SUBTREE (TREE_OPERAND (*tp, i)); 10142 WALK_SUBTREE (TREE_OPERAND (*tp, i));
8803 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp, len)); 10143 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp, len));
8804 } 10144 }
8805 10145
8806 case CHANGE_DYNAMIC_TYPE_EXPR:
8807 WALK_SUBTREE (CHANGE_DYNAMIC_TYPE_NEW_TYPE (*tp));
8808 WALK_SUBTREE_TAIL (CHANGE_DYNAMIC_TYPE_LOCATION (*tp));
8809
8810 case DECL_EXPR: 10146 case DECL_EXPR:
8811 /* If this is a TYPE_DECL, walk into the fields of the type that it's 10147 /* If this is a TYPE_DECL, walk into the fields of the type that it's
8812 defining. We only want to walk into these fields of a type in this 10148 defining. We only want to walk into these fields of a type in this
8813 case and not in the general case of a mere reference to the type. 10149 case and not in the general case of a mere reference to the type.
8814 10150
8815 The criterion is as follows: if the field can be an expression, it 10151 The criterion is as follows: if the field can be an expression, it
8816 must be walked only here. This should be in keeping with the fields 10152 must be walked only here. This should be in keeping with the fields
8817 that are directly gimplified in gimplify_type_sizes in order for the 10153 that are directly gimplified in gimplify_type_sizes in order for the
8818 mark/copy-if-shared/unmark machinery of the gimplifier to work with 10154 mark/copy-if-shared/unmark machinery of the gimplifier to work with
8819 variable-sized types. 10155 variable-sized types.
8820 10156
8821 Note that DECLs get walked as part of processing the BIND_EXPR. */ 10157 Note that DECLs get walked as part of processing the BIND_EXPR. */
8822 if (TREE_CODE (DECL_EXPR_DECL (*tp)) == TYPE_DECL) 10158 if (TREE_CODE (DECL_EXPR_DECL (*tp)) == TYPE_DECL)
8823 { 10159 {
8824 tree *type_p = &TREE_TYPE (DECL_EXPR_DECL (*tp)); 10160 tree *type_p = &TREE_TYPE (DECL_EXPR_DECL (*tp));
8825 if (TREE_CODE (*type_p) == ERROR_MARK) 10161 if (TREE_CODE (*type_p) == ERROR_MARK)
8835 result = walk_type_fields (*type_p, func, data, pset, lh); 10171 result = walk_type_fields (*type_p, func, data, pset, lh);
8836 if (result) 10172 if (result)
8837 return result; 10173 return result;
8838 10174
8839 /* If this is a record type, also walk the fields. */ 10175 /* If this is a record type, also walk the fields. */
8840 if (TREE_CODE (*type_p) == RECORD_TYPE 10176 if (RECORD_OR_UNION_TYPE_P (*type_p))
8841 || TREE_CODE (*type_p) == UNION_TYPE
8842 || TREE_CODE (*type_p) == QUAL_UNION_TYPE)
8843 { 10177 {
8844 tree field; 10178 tree field;
8845 10179
8846 for (field = TYPE_FIELDS (*type_p); field; 10180 for (field = TYPE_FIELDS (*type_p); field;
8847 field = TREE_CHAIN (field)) 10181 field = TREE_CHAIN (field))
8948 arglist = tree_cons (NULL_TREE, CALL_EXPR_ARG (exp, i), arglist); 10282 arglist = tree_cons (NULL_TREE, CALL_EXPR_ARG (exp, i), arglist);
8949 return arglist; 10283 return arglist;
8950 } 10284 }
8951 10285
8952 10286
8953 /* Create a nameless artificial label and put it in the current function 10287 /* Create a nameless artificial label and put it in the current
8954 context. Returns the newly created label. */ 10288 function context. The label has a location of LOC. Returns the
8955 10289 newly created label. */
8956 tree 10290
8957 create_artificial_label (void) 10291 tree
8958 { 10292 create_artificial_label (location_t loc)
8959 tree lab = build_decl (LABEL_DECL, NULL_TREE, void_type_node); 10293 {
10294 tree lab = build_decl (loc,
10295 LABEL_DECL, NULL_TREE, void_type_node);
8960 10296
8961 DECL_ARTIFICIAL (lab) = 1; 10297 DECL_ARTIFICIAL (lab) = 1;
8962 DECL_IGNORED_P (lab) = 1; 10298 DECL_IGNORED_P (lab) = 1;
8963 DECL_CONTEXT (lab) = current_function_decl; 10299 DECL_CONTEXT (lab) = current_function_decl;
8964 return lab; 10300 return lab;
9017 10353
9018 gcc_assert (fntype != NULL_TREE); 10354 gcc_assert (fntype != NULL_TREE);
9019 10355
9020 t = TYPE_ARG_TYPES (fntype); 10356 t = TYPE_ARG_TYPES (fntype);
9021 return (t != NULL_TREE); 10357 return (t != NULL_TREE);
9022 }
9023
9024 /* Return the number of arguments that a function has. */
9025
9026 int
9027 function_args_count (tree fntype)
9028 {
9029 function_args_iterator args_iter;
9030 tree t;
9031 int num = 0;
9032
9033 if (fntype)
9034 {
9035 FOREACH_FUNCTION_ARGS(fntype, t, args_iter)
9036 {
9037 num++;
9038 }
9039 }
9040
9041 return num;
9042 } 10358 }
9043 10359
9044 /* If BLOCK is inlined from an __attribute__((__artificial__)) 10360 /* If BLOCK is inlined from an __attribute__((__artificial__))
9045 routine, return pointer to location from where it has been 10361 routine, return pointer to location from where it has been
9046 called. */ 10362 called. */
9266 10582
9267 return ret_val; 10583 return ret_val;
9268 } 10584 }
9269 } 10585 }
9270 10586
10587 /* Return true if T1 and T2 are equivalent lists. */
10588
10589 bool
10590 list_equal_p (const_tree t1, const_tree t2)
10591 {
10592 for (; t1 && t2; t1 = TREE_CHAIN (t1) , t2 = TREE_CHAIN (t2))
10593 if (TREE_VALUE (t1) != TREE_VALUE (t2))
10594 return false;
10595 return !t1 && !t2;
10596 }
10597
10598 /* Return true iff conversion in EXP generates no instruction. Mark
10599 it inline so that we fully inline into the stripping functions even
10600 though we have two uses of this function. */
10601
10602 static inline bool
10603 tree_nop_conversion (const_tree exp)
10604 {
10605 tree outer_type, inner_type;
10606
10607 if (!CONVERT_EXPR_P (exp)
10608 && TREE_CODE (exp) != NON_LVALUE_EXPR)
10609 return false;
10610 if (TREE_OPERAND (exp, 0) == error_mark_node)
10611 return false;
10612
10613 outer_type = TREE_TYPE (exp);
10614 inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
10615
10616 /* Use precision rather then machine mode when we can, which gives
10617 the correct answer even for submode (bit-field) types. */
10618 if ((INTEGRAL_TYPE_P (outer_type)
10619 || POINTER_TYPE_P (outer_type)
10620 || TREE_CODE (outer_type) == OFFSET_TYPE)
10621 && (INTEGRAL_TYPE_P (inner_type)
10622 || POINTER_TYPE_P (inner_type)
10623 || TREE_CODE (inner_type) == OFFSET_TYPE))
10624 return TYPE_PRECISION (outer_type) == TYPE_PRECISION (inner_type);
10625
10626 /* Otherwise fall back on comparing machine modes (e.g. for
10627 aggregate types, floats). */
10628 return TYPE_MODE (outer_type) == TYPE_MODE (inner_type);
10629 }
10630
10631 /* Return true iff conversion in EXP generates no instruction. Don't
10632 consider conversions changing the signedness. */
10633
10634 static bool
10635 tree_sign_nop_conversion (const_tree exp)
10636 {
10637 tree outer_type, inner_type;
10638
10639 if (!tree_nop_conversion (exp))
10640 return false;
10641
10642 outer_type = TREE_TYPE (exp);
10643 inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
10644
10645 return (TYPE_UNSIGNED (outer_type) == TYPE_UNSIGNED (inner_type)
10646 && POINTER_TYPE_P (outer_type) == POINTER_TYPE_P (inner_type));
10647 }
10648
10649 /* Strip conversions from EXP according to tree_nop_conversion and
10650 return the resulting expression. */
10651
10652 tree
10653 tree_strip_nop_conversions (tree exp)
10654 {
10655 while (tree_nop_conversion (exp))
10656 exp = TREE_OPERAND (exp, 0);
10657 return exp;
10658 }
10659
10660 /* Strip conversions from EXP according to tree_sign_nop_conversion
10661 and return the resulting expression. */
10662
10663 tree
10664 tree_strip_sign_nop_conversions (tree exp)
10665 {
10666 while (tree_sign_nop_conversion (exp))
10667 exp = TREE_OPERAND (exp, 0);
10668 return exp;
10669 }
10670
10671 static GTY(()) tree gcc_eh_personality_decl;
10672
10673 /* Return the GCC personality function decl. */
10674
10675 tree
10676 lhd_gcc_personality (void)
10677 {
10678 if (!gcc_eh_personality_decl)
10679 gcc_eh_personality_decl
10680 = build_personality_function (USING_SJLJ_EXCEPTIONS
10681 ? "__gcc_personality_sj0"
10682 : "__gcc_personality_v0");
10683
10684 return gcc_eh_personality_decl;
10685 }
10686
9271 #include "gt-tree.h" 10687 #include "gt-tree.h"