1 /* Language-independent node constructors for parse phase of GNU compiler.
2 Copyright (C) 1987, 1988, 1992, 1993, 1994 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* This file contains the low level primitives for operating on tree nodes,
22 including allocation, list operations, interning of identifiers,
23 construction of data type nodes and statement nodes,
24 and construction of type conversion nodes. It also contains
25 tables index by tree code that describe how to take apart
28 It is intended to be language-independent, but occasionally
29 calls language-dependent routines defined (for C) in typecheck.c.
31 The low-level allocation routines oballoc and permalloc
32 are used also for allocating many other kinds of objects
33 by all passes of the compiler. */
43 #define obstack_chunk_alloc xmalloc
44 #define obstack_chunk_free free
46 /* Tree nodes of permanent duration are allocated in this obstack.
47 They are the identifier nodes, and everything outside of
48 the bodies and parameters of function definitions. */
50 struct obstack permanent_obstack;
52 /* The initial RTL, and all ..._TYPE nodes, in a function
53 are allocated in this obstack. Usually they are freed at the
54 end of the function, but if the function is inline they are saved.
55 For top-level functions, this is maybepermanent_obstack.
56 Separate obstacks are made for nested functions. */
58 struct obstack *function_maybepermanent_obstack;
60 /* This is the function_maybepermanent_obstack for top-level functions. */
62 struct obstack maybepermanent_obstack;
64 /* The contents of the current function definition are allocated
65 in this obstack, and all are freed at the end of the function.
66 For top-level functions, this is temporary_obstack.
67 Separate obstacks are made for nested functions. */
69 struct obstack *function_obstack;
71 /* This is used for reading initializers of global variables. */
73 struct obstack temporary_obstack;
75 /* The tree nodes of an expression are allocated
76 in this obstack, and all are freed at the end of the expression. */
78 struct obstack momentary_obstack;
80 /* The tree nodes of a declarator are allocated
81 in this obstack, and all are freed when the declarator
84 static struct obstack temp_decl_obstack;
86 /* This points at either permanent_obstack
87 or the current function_maybepermanent_obstack. */
89 struct obstack *saveable_obstack;
91 /* This is same as saveable_obstack during parse and expansion phase;
92 it points to the current function's obstack during optimization.
93 This is the obstack to be used for creating rtl objects. */
95 struct obstack *rtl_obstack;
97 /* This points at either permanent_obstack or the current function_obstack. */
99 struct obstack *current_obstack;
101 /* This points at either permanent_obstack or the current function_obstack
102 or momentary_obstack. */
104 struct obstack *expression_obstack;
106 /* Stack of obstack selections for push_obstacks and pop_obstacks. */
110 struct obstack_stack *next;
111 struct obstack *current;
112 struct obstack *saveable;
113 struct obstack *expression;
117 struct obstack_stack *obstack_stack;
119 /* Obstack for allocating struct obstack_stack entries. */
121 static struct obstack obstack_stack_obstack;
123 /* Addresses of first objects in some obstacks.
124 This is for freeing their entire contents. */
125 char *maybepermanent_firstobj;
126 char *temporary_firstobj;
127 char *momentary_firstobj;
128 char *temp_decl_firstobj;
130 /* Nonzero means all ..._TYPE nodes should be allocated permanently. */
132 int all_types_permanent;
134 /* Stack of places to restore the momentary obstack back to. */
136 struct momentary_level
138 /* Pointer back to previous such level. */
139 struct momentary_level *prev;
140 /* First object allocated within this level. */
142 /* Value of expression_obstack saved at entry to this level. */
143 struct obstack *obstack;
146 struct momentary_level *momentary_stack;
148 /* Table indexed by tree code giving a string containing a character
149 classifying the tree code. Possibilities are
150 t, d, s, c, r, <, 1, 2 and e. See tree.def for details. */
152 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
154 char *standard_tree_code_type[] = {
159 /* Table indexed by tree code giving number of expression
160 operands beyond the fixed part of the node structure.
161 Not used for types or decls. */
163 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
165 int standard_tree_code_length[] = {
170 /* Names of tree components.
171 Used for printing out the tree and error messages. */
172 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
174 char *standard_tree_code_name[] = {
179 /* Table indexed by tree code giving a string containing a character
180 classifying the tree code. Possibilities are
181 t, d, s, c, r, e, <, 1 and 2. See tree.def for details. */
183 char **tree_code_type;
185 /* Table indexed by tree code giving number of expression
186 operands beyond the fixed part of the node structure.
187 Not used for types or decls. */
189 int *tree_code_length;
191 /* Table indexed by tree code giving name of tree code, as a string. */
193 char **tree_code_name;
195 /* Statistics-gathering stuff. */
216 int tree_node_counts[(int)all_kinds];
217 int tree_node_sizes[(int)all_kinds];
218 int id_string_size = 0;
220 char *tree_node_kind_names[] = {
238 /* Hash table for uniquizing IDENTIFIER_NODEs by name. */
240 #define MAX_HASH_TABLE 1009
241 static tree hash_table[MAX_HASH_TABLE]; /* id hash buckets */
243 /* 0 while creating built-in identifiers. */
244 static int do_identifier_warnings;
246 /* Unique id for next decl created. */
247 static int next_decl_uid;
248 /* Unique id for next type created. */
249 static int next_type_uid = 1;
251 extern char *mode_name[];
253 void gcc_obstack_init ();
254 static tree stabilize_reference_1 ();
256 /* Init the principal obstacks. */
261 gcc_obstack_init (&obstack_stack_obstack);
262 gcc_obstack_init (&permanent_obstack);
264 gcc_obstack_init (&temporary_obstack);
265 temporary_firstobj = (char *) obstack_alloc (&temporary_obstack, 0);
266 gcc_obstack_init (&momentary_obstack);
267 momentary_firstobj = (char *) obstack_alloc (&momentary_obstack, 0);
268 gcc_obstack_init (&maybepermanent_obstack);
269 maybepermanent_firstobj
270 = (char *) obstack_alloc (&maybepermanent_obstack, 0);
271 gcc_obstack_init (&temp_decl_obstack);
272 temp_decl_firstobj = (char *) obstack_alloc (&temp_decl_obstack, 0);
274 function_obstack = &temporary_obstack;
275 function_maybepermanent_obstack = &maybepermanent_obstack;
276 current_obstack = &permanent_obstack;
277 expression_obstack = &permanent_obstack;
278 rtl_obstack = saveable_obstack = &permanent_obstack;
280 /* Init the hash table of identifiers. */
281 bzero (hash_table, sizeof hash_table);
285 gcc_obstack_init (obstack)
286 struct obstack *obstack;
288 /* Let particular systems override the size of a chunk. */
289 #ifndef OBSTACK_CHUNK_SIZE
290 #define OBSTACK_CHUNK_SIZE 0
292 /* Let them override the alloc and free routines too. */
293 #ifndef OBSTACK_CHUNK_ALLOC
294 #define OBSTACK_CHUNK_ALLOC xmalloc
296 #ifndef OBSTACK_CHUNK_FREE
297 #define OBSTACK_CHUNK_FREE free
299 _obstack_begin (obstack, OBSTACK_CHUNK_SIZE, 0,
300 (void *(*) ()) OBSTACK_CHUNK_ALLOC,
301 (void (*) ()) OBSTACK_CHUNK_FREE);
304 /* Save all variables describing the current status into the structure *P.
305 This is used before starting a nested function. */
311 p->all_types_permanent = all_types_permanent;
312 p->momentary_stack = momentary_stack;
313 p->maybepermanent_firstobj = maybepermanent_firstobj;
314 p->momentary_firstobj = momentary_firstobj;
315 p->function_obstack = function_obstack;
316 p->function_maybepermanent_obstack = function_maybepermanent_obstack;
317 p->current_obstack = current_obstack;
318 p->expression_obstack = expression_obstack;
319 p->saveable_obstack = saveable_obstack;
320 p->rtl_obstack = rtl_obstack;
322 /* Objects that need to be saved in this function can be in the nonsaved
323 obstack of the enclosing function since they can't possibly be needed
324 once it has returned. */
325 function_maybepermanent_obstack = function_obstack;
327 function_obstack = (struct obstack *) xmalloc (sizeof (struct obstack));
328 gcc_obstack_init (function_obstack);
330 current_obstack = &permanent_obstack;
331 expression_obstack = &permanent_obstack;
332 rtl_obstack = saveable_obstack = &permanent_obstack;
334 momentary_firstobj = (char *) obstack_finish (&momentary_obstack);
335 maybepermanent_firstobj
336 = (char *) obstack_finish (function_maybepermanent_obstack);
339 /* Restore all variables describing the current status from the structure *P.
340 This is used after a nested function. */
343 restore_tree_status (p)
346 all_types_permanent = p->all_types_permanent;
347 momentary_stack = p->momentary_stack;
349 obstack_free (&momentary_obstack, momentary_firstobj);
351 /* Free saveable storage used by the function just compiled and not
354 CAUTION: This is in function_obstack of the containing function. So
355 we must be sure that we never allocate from that obstack during
356 the compilation of a nested function if we expect it to survive past the
357 nested function's end. */
358 obstack_free (function_maybepermanent_obstack, maybepermanent_firstobj);
360 obstack_free (function_obstack, 0);
361 free (function_obstack);
363 momentary_firstobj = p->momentary_firstobj;
364 maybepermanent_firstobj = p->maybepermanent_firstobj;
365 function_obstack = p->function_obstack;
366 function_maybepermanent_obstack = p->function_maybepermanent_obstack;
367 current_obstack = p->current_obstack;
368 expression_obstack = p->expression_obstack;
369 saveable_obstack = p->saveable_obstack;
370 rtl_obstack = p->rtl_obstack;
373 /* Start allocating on the temporary (per function) obstack.
374 This is done in start_function before parsing the function body,
375 and before each initialization at top level, and to go back
376 to temporary allocation after doing permanent_allocation. */
379 temporary_allocation ()
381 /* Note that function_obstack at top level points to temporary_obstack.
382 But within a nested function context, it is a separate obstack. */
383 current_obstack = function_obstack;
384 expression_obstack = function_obstack;
385 rtl_obstack = saveable_obstack = function_maybepermanent_obstack;
389 /* Start allocating on the permanent obstack but don't
390 free the temporary data. After calling this, call
391 `permanent_allocation' to fully resume permanent allocation status. */
394 end_temporary_allocation ()
396 current_obstack = &permanent_obstack;
397 expression_obstack = &permanent_obstack;
398 rtl_obstack = saveable_obstack = &permanent_obstack;
401 /* Resume allocating on the temporary obstack, undoing
402 effects of `end_temporary_allocation'. */
405 resume_temporary_allocation ()
407 current_obstack = function_obstack;
408 expression_obstack = function_obstack;
409 rtl_obstack = saveable_obstack = function_maybepermanent_obstack;
412 /* While doing temporary allocation, switch to allocating in such a
413 way as to save all nodes if the function is inlined. Call
414 resume_temporary_allocation to go back to ordinary temporary
418 saveable_allocation ()
420 /* Note that function_obstack at top level points to temporary_obstack.
421 But within a nested function context, it is a separate obstack. */
422 expression_obstack = current_obstack = saveable_obstack;
425 /* Switch to current obstack CURRENT and maybepermanent obstack SAVEABLE,
426 recording the previously current obstacks on a stack.
427 This does not free any storage in any obstack. */
430 push_obstacks (current, saveable)
431 struct obstack *current, *saveable;
433 struct obstack_stack *p
434 = (struct obstack_stack *) obstack_alloc (&obstack_stack_obstack,
435 (sizeof (struct obstack_stack)));
437 p->current = current_obstack;
438 p->saveable = saveable_obstack;
439 p->expression = expression_obstack;
440 p->rtl = rtl_obstack;
441 p->next = obstack_stack;
444 current_obstack = current;
445 expression_obstack = current;
446 rtl_obstack = saveable_obstack = saveable;
449 /* Save the current set of obstacks, but don't change them. */
452 push_obstacks_nochange ()
454 struct obstack_stack *p
455 = (struct obstack_stack *) obstack_alloc (&obstack_stack_obstack,
456 (sizeof (struct obstack_stack)));
458 p->current = current_obstack;
459 p->saveable = saveable_obstack;
460 p->expression = expression_obstack;
461 p->rtl = rtl_obstack;
462 p->next = obstack_stack;
466 /* Pop the obstack selection stack. */
471 struct obstack_stack *p = obstack_stack;
472 obstack_stack = p->next;
474 current_obstack = p->current;
475 saveable_obstack = p->saveable;
476 expression_obstack = p->expression;
477 rtl_obstack = p->rtl;
479 obstack_free (&obstack_stack_obstack, p);
482 /* Nonzero if temporary allocation is currently in effect.
483 Zero if currently doing permanent allocation. */
486 allocation_temporary_p ()
488 return current_obstack != &permanent_obstack;
491 /* Go back to allocating on the permanent obstack
492 and free everything in the temporary obstack.
493 This is done in finish_function after fully compiling a function. */
496 permanent_allocation ()
498 /* Free up previous temporary obstack data */
499 obstack_free (&temporary_obstack, temporary_firstobj);
500 obstack_free (&momentary_obstack, momentary_firstobj);
501 obstack_free (&maybepermanent_obstack, maybepermanent_firstobj);
502 obstack_free (&temp_decl_obstack, temp_decl_firstobj);
504 current_obstack = &permanent_obstack;
505 expression_obstack = &permanent_obstack;
506 rtl_obstack = saveable_obstack = &permanent_obstack;
509 /* Save permanently everything on the maybepermanent_obstack. */
514 maybepermanent_firstobj
515 = (char *) obstack_alloc (function_maybepermanent_obstack, 0);
519 preserve_initializer ()
522 = (char *) obstack_alloc (&temporary_obstack, 0);
524 = (char *) obstack_alloc (&momentary_obstack, 0);
525 maybepermanent_firstobj
526 = (char *) obstack_alloc (function_maybepermanent_obstack, 0);
529 /* Start allocating new rtl in current_obstack.
530 Use resume_temporary_allocation
531 to go back to allocating rtl in saveable_obstack. */
534 rtl_in_current_obstack ()
536 rtl_obstack = current_obstack;
539 /* Start allocating rtl from saveable_obstack. Intended to be used after
540 a call to push_obstacks_nochange. */
543 rtl_in_saveable_obstack ()
545 rtl_obstack = saveable_obstack;
548 /* Allocate SIZE bytes in the current obstack
549 and return a pointer to them.
550 In practice the current obstack is always the temporary one. */
556 return (char *) obstack_alloc (current_obstack, size);
559 /* Free the object PTR in the current obstack
560 as well as everything allocated since PTR.
561 In practice the current obstack is always the temporary one. */
567 obstack_free (current_obstack, ptr);
570 /* Allocate SIZE bytes in the permanent obstack
571 and return a pointer to them. */
577 return (char *) obstack_alloc (&permanent_obstack, size);
580 /* Allocate NELEM items of SIZE bytes in the permanent obstack
581 and return a pointer to them. The storage is cleared before
582 returning the value. */
585 perm_calloc (nelem, size)
589 char *rval = (char *) obstack_alloc (&permanent_obstack, nelem * size);
590 bzero (rval, nelem * size);
594 /* Allocate SIZE bytes in the saveable obstack
595 and return a pointer to them. */
601 return (char *) obstack_alloc (saveable_obstack, size);
604 /* Print out which obstack an object is in. */
607 print_obstack_name (object, file, prefix)
612 struct obstack *obstack = NULL;
613 char *obstack_name = NULL;
616 for (p = outer_function_chain; p; p = p->next)
618 if (_obstack_allocated_p (p->function_obstack, object))
620 obstack = p->function_obstack;
621 obstack_name = "containing function obstack";
623 if (_obstack_allocated_p (p->function_maybepermanent_obstack, object))
625 obstack = p->function_maybepermanent_obstack;
626 obstack_name = "containing function maybepermanent obstack";
630 if (_obstack_allocated_p (&obstack_stack_obstack, object))
632 obstack = &obstack_stack_obstack;
633 obstack_name = "obstack_stack_obstack";
635 else if (_obstack_allocated_p (function_obstack, object))
637 obstack = function_obstack;
638 obstack_name = "function obstack";
640 else if (_obstack_allocated_p (&permanent_obstack, object))
642 obstack = &permanent_obstack;
643 obstack_name = "permanent_obstack";
645 else if (_obstack_allocated_p (&momentary_obstack, object))
647 obstack = &momentary_obstack;
648 obstack_name = "momentary_obstack";
650 else if (_obstack_allocated_p (function_maybepermanent_obstack, object))
652 obstack = function_maybepermanent_obstack;
653 obstack_name = "function maybepermanent obstack";
655 else if (_obstack_allocated_p (&temp_decl_obstack, object))
657 obstack = &temp_decl_obstack;
658 obstack_name = "temp_decl_obstack";
661 /* Check to see if the object is in the free area of the obstack. */
664 if (object >= obstack->next_free
665 && object < obstack->chunk_limit)
666 fprintf (file, "%s in free portion of obstack %s",
667 prefix, obstack_name);
669 fprintf (file, "%s allocated from %s", prefix, obstack_name);
672 fprintf (file, "%s not allocated from any obstack", prefix);
676 debug_obstack (object)
679 print_obstack_name (object, stderr, "object");
680 fprintf (stderr, ".\n");
683 /* Return 1 if OBJ is in the permanent obstack.
684 This is slow, and should be used only for debugging.
685 Use TREE_PERMANENT for other purposes. */
688 object_permanent_p (obj)
691 return _obstack_allocated_p (&permanent_obstack, obj);
694 /* Start a level of momentary allocation.
695 In C, each compound statement has its own level
696 and that level is freed at the end of each statement.
697 All expression nodes are allocated in the momentary allocation level. */
702 struct momentary_level *tem
703 = (struct momentary_level *) obstack_alloc (&momentary_obstack,
704 sizeof (struct momentary_level));
705 tem->prev = momentary_stack;
706 tem->base = (char *) obstack_base (&momentary_obstack);
707 tem->obstack = expression_obstack;
708 momentary_stack = tem;
709 expression_obstack = &momentary_obstack;
712 /* Free all the storage in the current momentary-allocation level.
713 In C, this happens at the end of each statement. */
718 obstack_free (&momentary_obstack, momentary_stack->base);
721 /* Discard a level of momentary allocation.
722 In C, this happens at the end of each compound statement.
723 Restore the status of expression node allocation
724 that was in effect before this level was created. */
729 struct momentary_level *tem = momentary_stack;
730 momentary_stack = tem->prev;
731 expression_obstack = tem->obstack;
732 obstack_free (&momentary_obstack, tem);
735 /* Pop back to the previous level of momentary allocation,
736 but don't free any momentary data just yet. */
739 pop_momentary_nofree ()
741 struct momentary_level *tem = momentary_stack;
742 momentary_stack = tem->prev;
743 expression_obstack = tem->obstack;
746 /* Call when starting to parse a declaration:
747 make expressions in the declaration last the length of the function.
748 Returns an argument that should be passed to resume_momentary later. */
753 register int tem = expression_obstack == &momentary_obstack;
754 expression_obstack = saveable_obstack;
758 /* Call when finished parsing a declaration:
759 restore the treatment of node-allocation that was
760 in effect before the suspension.
761 YES should be the value previously returned by suspend_momentary. */
764 resume_momentary (yes)
768 expression_obstack = &momentary_obstack;
771 /* Init the tables indexed by tree code.
772 Note that languages can add to these tables to define their own codes. */
777 tree_code_type = (char **) xmalloc (sizeof (standard_tree_code_type));
778 tree_code_length = (int *) xmalloc (sizeof (standard_tree_code_length));
779 tree_code_name = (char **) xmalloc (sizeof (standard_tree_code_name));
780 bcopy (standard_tree_code_type, tree_code_type,
781 sizeof (standard_tree_code_type));
782 bcopy (standard_tree_code_length, tree_code_length,
783 sizeof (standard_tree_code_length));
784 bcopy (standard_tree_code_name, tree_code_name,
785 sizeof (standard_tree_code_name));
788 /* Return a newly allocated node of code CODE.
789 Initialize the node's unique id and its TREE_PERMANENT flag.
790 For decl and type nodes, some other fields are initialized.
791 The rest of the node is initialized to zero.
793 Achoo! I got a code in the node. */
800 register int type = TREE_CODE_CLASS (code);
802 register struct obstack *obstack = current_obstack;
804 register tree_node_kind kind;
808 case 'd': /* A decl node */
809 #ifdef GATHER_STATISTICS
812 length = sizeof (struct tree_decl);
813 /* All decls in an inline function need to be saved. */
814 if (obstack != &permanent_obstack)
815 obstack = saveable_obstack;
817 /* PARM_DECLs go on the context of the parent. If this is a nested
818 function, then we must allocate the PARM_DECL on the parent's
819 obstack, so that they will live to the end of the parent's
820 closing brace. This is neccesary in case we try to inline the
821 function into its parent.
823 PARM_DECLs of top-level functions do not have this problem. However,
824 we allocate them where we put the FUNCTION_DECL for languauges such as
825 Ada that need to consult some flags in the PARM_DECLs of the function
828 See comment in restore_tree_status for why we can't put this
829 in function_obstack. */
830 if (code == PARM_DECL && obstack != &permanent_obstack)
833 if (current_function_decl)
834 context = decl_function_context (current_function_decl);
838 = find_function_data (context)->function_maybepermanent_obstack;
842 case 't': /* a type node */
843 #ifdef GATHER_STATISTICS
846 length = sizeof (struct tree_type);
847 /* All data types are put where we can preserve them if nec. */
848 if (obstack != &permanent_obstack)
849 obstack = all_types_permanent ? &permanent_obstack : saveable_obstack;
852 case 'b': /* a lexical block */
853 #ifdef GATHER_STATISTICS
856 length = sizeof (struct tree_block);
857 /* All BLOCK nodes are put where we can preserve them if nec. */
858 if (obstack != &permanent_obstack)
859 obstack = saveable_obstack;
862 case 's': /* an expression with side effects */
863 #ifdef GATHER_STATISTICS
867 case 'r': /* a reference */
868 #ifdef GATHER_STATISTICS
872 case 'e': /* an expression */
873 case '<': /* a comparison expression */
874 case '1': /* a unary arithmetic expression */
875 case '2': /* a binary arithmetic expression */
876 #ifdef GATHER_STATISTICS
880 obstack = expression_obstack;
881 /* All BIND_EXPR nodes are put where we can preserve them if nec. */
882 if (code == BIND_EXPR && obstack != &permanent_obstack)
883 obstack = saveable_obstack;
884 length = sizeof (struct tree_exp)
885 + (tree_code_length[(int) code] - 1) * sizeof (char *);
888 case 'c': /* a constant */
889 #ifdef GATHER_STATISTICS
892 obstack = expression_obstack;
894 /* We can't use tree_code_length for INTEGER_CST, since the number of
895 words is machine-dependent due to varying length of HOST_WIDE_INT,
896 which might be wider than a pointer (e.g., long long). Similarly
897 for REAL_CST, since the number of words is machine-dependent due
898 to varying size and alignment of `double'. */
900 if (code == INTEGER_CST)
901 length = sizeof (struct tree_int_cst);
902 else if (code == REAL_CST)
903 length = sizeof (struct tree_real_cst);
905 length = sizeof (struct tree_common)
906 + tree_code_length[(int) code] * sizeof (char *);
909 case 'x': /* something random, like an identifier. */
910 #ifdef GATHER_STATISTICS
911 if (code == IDENTIFIER_NODE)
913 else if (code == OP_IDENTIFIER)
915 else if (code == TREE_VEC)
920 length = sizeof (struct tree_common)
921 + tree_code_length[(int) code] * sizeof (char *);
922 /* Identifier nodes are always permanent since they are
923 unique in a compiler run. */
924 if (code == IDENTIFIER_NODE) obstack = &permanent_obstack;
927 t = (tree) obstack_alloc (obstack, length);
929 #ifdef GATHER_STATISTICS
930 tree_node_counts[(int)kind]++;
931 tree_node_sizes[(int)kind] += length;
934 /* Clear a word at a time. */
935 for (i = (length / sizeof (int)) - 1; i >= 0; i--)
937 /* Clear any extra bytes. */
938 for (i = length / sizeof (int) * sizeof (int); i < length; i++)
941 TREE_SET_CODE (t, code);
942 if (obstack == &permanent_obstack)
943 TREE_PERMANENT (t) = 1;
948 TREE_SIDE_EFFECTS (t) = 1;
949 TREE_TYPE (t) = void_type_node;
953 if (code != FUNCTION_DECL)
955 DECL_IN_SYSTEM_HEADER (t)
956 = in_system_header && (obstack == &permanent_obstack);
957 DECL_SOURCE_LINE (t) = lineno;
958 DECL_SOURCE_FILE (t) = (input_filename) ? input_filename : "<built-in>";
959 DECL_UID (t) = next_decl_uid++;
963 TYPE_UID (t) = next_type_uid++;
965 TYPE_MAIN_VARIANT (t) = t;
966 TYPE_OBSTACK (t) = obstack;
970 TREE_CONSTANT (t) = 1;
977 /* Return a new node with the same contents as NODE
978 except that its TREE_CHAIN is zero and it has a fresh uid. */
985 register enum tree_code code = TREE_CODE (node);
989 switch (TREE_CODE_CLASS (code))
991 case 'd': /* A decl node */
992 length = sizeof (struct tree_decl);
995 case 't': /* a type node */
996 length = sizeof (struct tree_type);
999 case 'b': /* a lexical block node */
1000 length = sizeof (struct tree_block);
1003 case 'r': /* a reference */
1004 case 'e': /* an expression */
1005 case 's': /* an expression with side effects */
1006 case '<': /* a comparison expression */
1007 case '1': /* a unary arithmetic expression */
1008 case '2': /* a binary arithmetic expression */
1009 length = sizeof (struct tree_exp)
1010 + (tree_code_length[(int) code] - 1) * sizeof (char *);
1013 case 'c': /* a constant */
1014 /* We can't use tree_code_length for INTEGER_CST, since the number of
1015 words is machine-dependent due to varying length of HOST_WIDE_INT,
1016 which might be wider than a pointer (e.g., long long). Similarly
1017 for REAL_CST, since the number of words is machine-dependent due
1018 to varying size and alignment of `double'. */
1019 if (code == INTEGER_CST)
1021 length = sizeof (struct tree_int_cst);
1024 else if (code == REAL_CST)
1026 length = sizeof (struct tree_real_cst);
1030 case 'x': /* something random, like an identifier. */
1031 length = sizeof (struct tree_common)
1032 + tree_code_length[(int) code] * sizeof (char *);
1033 if (code == TREE_VEC)
1034 length += (TREE_VEC_LENGTH (node) - 1) * sizeof (char *);
1037 t = (tree) obstack_alloc (current_obstack, length);
1039 for (i = (length / sizeof (int)) - 1; i >= 0; i--)
1040 ((int *) t)[i] = ((int *) node)[i];
1041 /* Clear any extra bytes. */
1042 for (i = length / sizeof (int) * sizeof (int); i < length; i++)
1043 ((char *) t)[i] = ((char *) node)[i];
1047 if (TREE_CODE_CLASS (code) == 'd')
1048 DECL_UID (t) = next_decl_uid++;
1049 else if (TREE_CODE_CLASS (code) == 't')
1051 TYPE_UID (t) = next_type_uid++;
1052 TYPE_OBSTACK (t) = current_obstack;
1055 TREE_PERMANENT (t) = (current_obstack == &permanent_obstack);
1060 /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
1061 For example, this can copy a list made of TREE_LIST nodes. */
1068 register tree prev, next;
1073 head = prev = copy_node (list);
1074 next = TREE_CHAIN (list);
1077 TREE_CHAIN (prev) = copy_node (next);
1078 prev = TREE_CHAIN (prev);
1079 next = TREE_CHAIN (next);
1086 /* Return an IDENTIFIER_NODE whose name is TEXT (a null-terminated string).
1087 If an identifier with that name has previously been referred to,
1088 the same node is returned this time. */
1091 get_identifier (text)
1092 register char *text;
1097 register int len, hash_len;
1099 /* Compute length of text in len. */
1100 for (len = 0; text[len]; len++);
1102 /* Decide how much of that length to hash on */
1104 if (warn_id_clash && len > id_clash_len)
1105 hash_len = id_clash_len;
1107 /* Compute hash code */
1108 hi = hash_len * 613 + (unsigned)text[0];
1109 for (i = 1; i < hash_len; i += 2)
1110 hi = ((hi * 613) + (unsigned)(text[i]));
1112 hi &= (1 << HASHBITS) - 1;
1113 hi %= MAX_HASH_TABLE;
1115 /* Search table for identifier */
1116 for (idp = hash_table[hi]; idp; idp = TREE_CHAIN (idp))
1117 if (IDENTIFIER_LENGTH (idp) == len
1118 && IDENTIFIER_POINTER (idp)[0] == text[0]
1119 && !bcmp (IDENTIFIER_POINTER (idp), text, len))
1120 return idp; /* <-- return if found */
1122 /* Not found; optionally warn about a similar identifier */
1123 if (warn_id_clash && do_identifier_warnings && len >= id_clash_len)
1124 for (idp = hash_table[hi]; idp; idp = TREE_CHAIN (idp))
1125 if (!strncmp (IDENTIFIER_POINTER (idp), text, id_clash_len))
1127 warning ("`%s' and `%s' identical in first %d characters",
1128 IDENTIFIER_POINTER (idp), text, id_clash_len);
1132 if (tree_code_length[(int) IDENTIFIER_NODE] < 0)
1133 abort (); /* set_identifier_size hasn't been called. */
1135 /* Not found, create one, add to chain */
1136 idp = make_node (IDENTIFIER_NODE);
1137 IDENTIFIER_LENGTH (idp) = len;
1138 #ifdef GATHER_STATISTICS
1139 id_string_size += len;
1142 IDENTIFIER_POINTER (idp) = obstack_copy0 (&permanent_obstack, text, len);
1144 TREE_CHAIN (idp) = hash_table[hi];
1145 hash_table[hi] = idp;
1146 return idp; /* <-- return if created */
1149 /* Enable warnings on similar identifiers (if requested).
1150 Done after the built-in identifiers are created. */
1153 start_identifier_warnings ()
1155 do_identifier_warnings = 1;
1158 /* Record the size of an identifier node for the language in use.
1159 SIZE is the total size in bytes.
1160 This is called by the language-specific files. This must be
1161 called before allocating any identifiers. */
1164 set_identifier_size (size)
1167 tree_code_length[(int) IDENTIFIER_NODE]
1168 = (size - sizeof (struct tree_common)) / sizeof (tree);
1171 /* Return a newly constructed INTEGER_CST node whose constant value
1172 is specified by the two ints LOW and HI.
1173 The TREE_TYPE is set to `int'.
1175 This function should be used via the `build_int_2' macro. */
1178 build_int_2_wide (low, hi)
1179 HOST_WIDE_INT low, hi;
1181 register tree t = make_node (INTEGER_CST);
1182 TREE_INT_CST_LOW (t) = low;
1183 TREE_INT_CST_HIGH (t) = hi;
1184 TREE_TYPE (t) = integer_type_node;
1188 /* Return a new REAL_CST node whose type is TYPE and value is D. */
1191 build_real (type, d)
1197 /* Check for valid float value for this type on this target machine;
1198 if not, can print error message and store a valid value in D. */
1199 #ifdef CHECK_FLOAT_VALUE
1200 CHECK_FLOAT_VALUE (TYPE_MODE (type), d);
1203 v = make_node (REAL_CST);
1204 TREE_TYPE (v) = type;
1205 TREE_REAL_CST (v) = d;
1209 /* Return a new REAL_CST node whose type is TYPE
1210 and whose value is the integer value of the INTEGER_CST node I. */
1212 #if !defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC)
1215 real_value_from_int_cst (i)
1220 /* Some 386 compilers mishandle unsigned int to float conversions,
1221 so introduce a temporary variable E to avoid those bugs. */
1223 #ifdef REAL_ARITHMETIC
1224 if (! TREE_UNSIGNED (TREE_TYPE (i)))
1225 REAL_VALUE_FROM_INT (d, TREE_INT_CST_LOW (i), TREE_INT_CST_HIGH (i));
1227 REAL_VALUE_FROM_UNSIGNED_INT (d, TREE_INT_CST_LOW (i), TREE_INT_CST_HIGH (i));
1228 #else /* not REAL_ARITHMETIC */
1229 if (TREE_INT_CST_HIGH (i) < 0 && ! TREE_UNSIGNED (TREE_TYPE (i)))
1231 d = (double) (~ TREE_INT_CST_HIGH (i));
1232 e = ((double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2))
1233 * (double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2)));
1235 e = (double) (unsigned HOST_WIDE_INT) (~ TREE_INT_CST_LOW (i));
1241 d = (double) (unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (i);
1242 e = ((double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2))
1243 * (double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2)));
1245 e = (double) (unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (i);
1248 #endif /* not REAL_ARITHMETIC */
1252 /* This function can't be implemented if we can't do arithmetic
1253 on the float representation. */
1256 build_real_from_int_cst (type, i)
1263 v = make_node (REAL_CST);
1264 TREE_TYPE (v) = type;
1266 d = REAL_VALUE_TRUNCATE (TYPE_MODE (type), real_value_from_int_cst (i));
1267 /* Check for valid float value for this type on this target machine;
1268 if not, can print error message and store a valid value in D. */
1269 #ifdef CHECK_FLOAT_VALUE
1270 CHECK_FLOAT_VALUE (TYPE_MODE (type), d);
1273 TREE_REAL_CST (v) = d;
1277 #endif /* not REAL_IS_NOT_DOUBLE, or REAL_ARITHMETIC */
1279 /* Return a newly constructed STRING_CST node whose value is
1280 the LEN characters at STR.
1281 The TREE_TYPE is not initialized. */
1284 build_string (len, str)
1288 /* Put the string in saveable_obstack since it will be placed in the RTL
1289 for an "asm" statement and will also be kept around a while if
1290 deferring constant output in varasm.c. */
1292 register tree s = make_node (STRING_CST);
1293 TREE_STRING_LENGTH (s) = len;
1294 TREE_STRING_POINTER (s) = obstack_copy0 (saveable_obstack, str, len);
1298 /* Return a newly constructed COMPLEX_CST node whose value is
1299 specified by the real and imaginary parts REAL and IMAG.
1300 Both REAL and IMAG should be constant nodes.
1301 The TREE_TYPE is not initialized. */
1304 build_complex (real, imag)
1307 register tree t = make_node (COMPLEX_CST);
1308 TREE_REALPART (t) = real;
1309 TREE_IMAGPART (t) = imag;
1310 TREE_TYPE (t) = build_complex_type (TREE_TYPE (real));
1314 /* Build a newly constructed TREE_VEC node of length LEN. */
1320 register int length = (len-1) * sizeof (tree) + sizeof (struct tree_vec);
1321 register struct obstack *obstack = current_obstack;
1324 #ifdef GATHER_STATISTICS
1325 tree_node_counts[(int)vec_kind]++;
1326 tree_node_sizes[(int)vec_kind] += length;
1329 t = (tree) obstack_alloc (obstack, length);
1331 for (i = (length / sizeof (int)) - 1; i >= 0; i--)
1334 TREE_SET_CODE (t, TREE_VEC);
1335 TREE_VEC_LENGTH (t) = len;
1336 if (obstack == &permanent_obstack)
1337 TREE_PERMANENT (t) = 1;
1342 /* Return 1 if EXPR is the integer constant zero. */
1345 integer_zerop (expr)
1350 return (TREE_CODE (expr) == INTEGER_CST
1351 && TREE_INT_CST_LOW (expr) == 0
1352 && TREE_INT_CST_HIGH (expr) == 0);
1355 /* Return 1 if EXPR is the integer constant one. */
1363 return (TREE_CODE (expr) == INTEGER_CST
1364 && TREE_INT_CST_LOW (expr) == 1
1365 && TREE_INT_CST_HIGH (expr) == 0);
1368 /* Return 1 if EXPR is an integer containing all 1's
1369 in as much precision as it contains. */
1372 integer_all_onesp (expr)
1380 if (TREE_CODE (expr) != INTEGER_CST)
1383 uns = TREE_UNSIGNED (TREE_TYPE (expr));
1385 return TREE_INT_CST_LOW (expr) == -1 && TREE_INT_CST_HIGH (expr) == -1;
1387 prec = TYPE_PRECISION (TREE_TYPE (expr));
1388 if (prec >= HOST_BITS_PER_WIDE_INT)
1390 int high_value, shift_amount;
1392 shift_amount = prec - HOST_BITS_PER_WIDE_INT;
1394 if (shift_amount > HOST_BITS_PER_WIDE_INT)
1395 /* Can not handle precisions greater than twice the host int size. */
1397 else if (shift_amount == HOST_BITS_PER_WIDE_INT)
1398 /* Shifting by the host word size is undefined according to the ANSI
1399 standard, so we must handle this as a special case. */
1402 high_value = ((HOST_WIDE_INT) 1 << shift_amount) - 1;
1404 return TREE_INT_CST_LOW (expr) == -1
1405 && TREE_INT_CST_HIGH (expr) == high_value;
1408 return TREE_INT_CST_LOW (expr) == ((HOST_WIDE_INT) 1 << prec) - 1;
1411 /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only
1415 integer_pow2p (expr)
1418 HOST_WIDE_INT high, low;
1422 if (TREE_CODE (expr) != INTEGER_CST)
1425 high = TREE_INT_CST_HIGH (expr);
1426 low = TREE_INT_CST_LOW (expr);
1428 if (high == 0 && low == 0)
1431 return ((high == 0 && (low & (low - 1)) == 0)
1432 || (low == 0 && (high & (high - 1)) == 0));
1435 /* Return 1 if EXPR is the real constant zero. */
1443 return (TREE_CODE (expr) == REAL_CST
1444 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst0));
1447 /* Return 1 if EXPR is the real constant one. */
1455 return (TREE_CODE (expr) == REAL_CST
1456 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst1));
1459 /* Return 1 if EXPR is the real constant two. */
1467 return (TREE_CODE (expr) == REAL_CST
1468 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst2));
1471 /* Nonzero if EXP is a constant or a cast of a constant. */
1474 really_constant_p (exp)
1477 /* This is not quite the same as STRIP_NOPS. It does more. */
1478 while (TREE_CODE (exp) == NOP_EXPR
1479 || TREE_CODE (exp) == CONVERT_EXPR
1480 || TREE_CODE (exp) == NON_LVALUE_EXPR)
1481 exp = TREE_OPERAND (exp, 0);
1482 return TREE_CONSTANT (exp);
1485 /* Return first list element whose TREE_VALUE is ELEM.
1486 Return 0 if ELEM is not it LIST. */
1489 value_member (elem, list)
1494 if (elem == TREE_VALUE (list))
1496 list = TREE_CHAIN (list);
1501 /* Return first list element whose TREE_PURPOSE is ELEM.
1502 Return 0 if ELEM is not it LIST. */
1505 purpose_member (elem, list)
1510 if (elem == TREE_PURPOSE (list))
1512 list = TREE_CHAIN (list);
1517 /* Return first list element whose BINFO_TYPE is ELEM.
1518 Return 0 if ELEM is not it LIST. */
1521 binfo_member (elem, list)
1526 if (elem == BINFO_TYPE (list))
1528 list = TREE_CHAIN (list);
1533 /* Return nonzero if ELEM is part of the chain CHAIN. */
1536 chain_member (elem, chain)
1543 chain = TREE_CHAIN (chain);
1549 /* Return the length of a chain of nodes chained through TREE_CHAIN.
1550 We expect a null pointer to mark the end of the chain.
1551 This is the Lisp primitive `length'. */
1558 register int len = 0;
1560 for (tail = t; tail; tail = TREE_CHAIN (tail))
1566 /* Concatenate two chains of nodes (chained through TREE_CHAIN)
1567 by modifying the last node in chain 1 to point to chain 2.
1568 This is the Lisp primitive `nconc'. */
1580 for (t1 = op1; TREE_CHAIN (t1); t1 = TREE_CHAIN (t1))
1582 TREE_CHAIN (t1) = op2;
1583 for (t2 = op2; t2; t2 = TREE_CHAIN (t2))
1585 abort (); /* Circularity created. */
1591 /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
1595 register tree chain;
1599 while (next = TREE_CHAIN (chain))
1604 /* Reverse the order of elements in the chain T,
1605 and return the new head of the chain (old last element). */
1611 register tree prev = 0, decl, next;
1612 for (decl = t; decl; decl = next)
1614 next = TREE_CHAIN (decl);
1615 TREE_CHAIN (decl) = prev;
1621 /* Given a chain CHAIN of tree nodes,
1622 construct and return a list of those nodes. */
1628 tree result = NULL_TREE;
1629 tree in_tail = chain;
1630 tree out_tail = NULL_TREE;
1634 tree next = tree_cons (NULL_TREE, in_tail, NULL_TREE);
1636 TREE_CHAIN (out_tail) = next;
1640 in_tail = TREE_CHAIN (in_tail);
1646 /* Return a newly created TREE_LIST node whose
1647 purpose and value fields are PARM and VALUE. */
1650 build_tree_list (parm, value)
1653 register tree t = make_node (TREE_LIST);
1654 TREE_PURPOSE (t) = parm;
1655 TREE_VALUE (t) = value;
1659 /* Similar, but build on the temp_decl_obstack. */
1662 build_decl_list (parm, value)
1666 register struct obstack *ambient_obstack = current_obstack;
1667 current_obstack = &temp_decl_obstack;
1668 node = build_tree_list (parm, value);
1669 current_obstack = ambient_obstack;
1673 /* Return a newly created TREE_LIST node whose
1674 purpose and value fields are PARM and VALUE
1675 and whose TREE_CHAIN is CHAIN. */
1678 tree_cons (purpose, value, chain)
1679 tree purpose, value, chain;
1682 register tree node = make_node (TREE_LIST);
1685 register tree node = (tree) obstack_alloc (current_obstack, sizeof (struct tree_list));
1686 #ifdef GATHER_STATISTICS
1687 tree_node_counts[(int)x_kind]++;
1688 tree_node_sizes[(int)x_kind] += sizeof (struct tree_list);
1691 for (i = (sizeof (struct tree_common) / sizeof (int)) - 1; i >= 0; i--)
1692 ((int *) node)[i] = 0;
1694 TREE_SET_CODE (node, TREE_LIST);
1695 if (current_obstack == &permanent_obstack)
1696 TREE_PERMANENT (node) = 1;
1699 TREE_CHAIN (node) = chain;
1700 TREE_PURPOSE (node) = purpose;
1701 TREE_VALUE (node) = value;
1705 /* Similar, but build on the temp_decl_obstack. */
1708 decl_tree_cons (purpose, value, chain)
1709 tree purpose, value, chain;
1712 register struct obstack *ambient_obstack = current_obstack;
1713 current_obstack = &temp_decl_obstack;
1714 node = tree_cons (purpose, value, chain);
1715 current_obstack = ambient_obstack;
1719 /* Same as `tree_cons' but make a permanent object. */
1722 perm_tree_cons (purpose, value, chain)
1723 tree purpose, value, chain;
1726 register struct obstack *ambient_obstack = current_obstack;
1727 current_obstack = &permanent_obstack;
1729 node = tree_cons (purpose, value, chain);
1730 current_obstack = ambient_obstack;
1734 /* Same as `tree_cons', but make this node temporary, regardless. */
1737 temp_tree_cons (purpose, value, chain)
1738 tree purpose, value, chain;
1741 register struct obstack *ambient_obstack = current_obstack;
1742 current_obstack = &temporary_obstack;
1744 node = tree_cons (purpose, value, chain);
1745 current_obstack = ambient_obstack;
1749 /* Same as `tree_cons', but save this node if the function's RTL is saved. */
1752 saveable_tree_cons (purpose, value, chain)
1753 tree purpose, value, chain;
1756 register struct obstack *ambient_obstack = current_obstack;
1757 current_obstack = saveable_obstack;
1759 node = tree_cons (purpose, value, chain);
1760 current_obstack = ambient_obstack;
1764 /* Return the size nominally occupied by an object of type TYPE
1765 when it resides in memory. The value is measured in units of bytes,
1766 and its data type is that normally used for type sizes
1767 (which is the first type created by make_signed_type or
1768 make_unsigned_type). */
1771 size_in_bytes (type)
1776 if (type == error_mark_node)
1777 return integer_zero_node;
1778 type = TYPE_MAIN_VARIANT (type);
1779 if (TYPE_SIZE (type) == 0)
1781 incomplete_type_error (NULL_TREE, type);
1782 return integer_zero_node;
1784 t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type),
1785 size_int (BITS_PER_UNIT));
1786 if (TREE_CODE (t) == INTEGER_CST)
1787 force_fit_type (t, 0);
1791 /* Return the size of TYPE (in bytes) as an integer,
1792 or return -1 if the size can vary. */
1795 int_size_in_bytes (type)
1799 if (type == error_mark_node)
1801 type = TYPE_MAIN_VARIANT (type);
1802 if (TYPE_SIZE (type) == 0)
1804 if (TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
1806 if (TREE_INT_CST_HIGH (TYPE_SIZE (type)) != 0)
1808 tree t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type),
1809 size_int (BITS_PER_UNIT));
1810 return TREE_INT_CST_LOW (t);
1812 size = TREE_INT_CST_LOW (TYPE_SIZE (type));
1813 return (size + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
1816 /* Return, as a tree node, the number of elements for TYPE (which is an
1817 ARRAY_TYPE) minus one. This counts only elements of the top array. */
1820 array_type_nelts (type)
1823 tree index_type = TYPE_DOMAIN (type);
1825 return (integer_zerop (TYPE_MIN_VALUE (index_type))
1826 ? TYPE_MAX_VALUE (index_type)
1827 : fold (build (MINUS_EXPR, TREE_TYPE (TYPE_MAX_VALUE (index_type)),
1828 TYPE_MAX_VALUE (index_type),
1829 TYPE_MIN_VALUE (index_type))));
1832 /* Return nonzero if arg is static -- a reference to an object in
1833 static storage. This is not the same as the C meaning of `static'. */
1839 switch (TREE_CODE (arg))
1843 return TREE_STATIC (arg) || DECL_EXTERNAL (arg);
1846 return TREE_STATIC (arg);
1853 return staticp (TREE_OPERAND (arg, 0));
1856 return TREE_CONSTANT (TREE_OPERAND (arg, 0));
1859 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST
1860 && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST)
1861 return staticp (TREE_OPERAND (arg, 0));
1867 /* Wrap a SAVE_EXPR around EXPR, if appropriate.
1868 Do this to any expression which may be used in more than one place,
1869 but must be evaluated only once.
1871 Normally, expand_expr would reevaluate the expression each time.
1872 Calling save_expr produces something that is evaluated and recorded
1873 the first time expand_expr is called on it. Subsequent calls to
1874 expand_expr just reuse the recorded value.
1876 The call to expand_expr that generates code that actually computes
1877 the value is the first call *at compile time*. Subsequent calls
1878 *at compile time* generate code to use the saved value.
1879 This produces correct result provided that *at run time* control
1880 always flows through the insns made by the first expand_expr
1881 before reaching the other places where the save_expr was evaluated.
1882 You, the caller of save_expr, must make sure this is so.
1884 Constants, and certain read-only nodes, are returned with no
1885 SAVE_EXPR because that is safe. Expressions containing placeholders
1886 are not touched; see tree.def for an explanation of what these
1893 register tree t = fold (expr);
1895 /* We don't care about whether this can be used as an lvalue in this
1897 while (TREE_CODE (t) == NON_LVALUE_EXPR)
1898 t = TREE_OPERAND (t, 0);
1900 /* If the tree evaluates to a constant, then we don't want to hide that
1901 fact (i.e. this allows further folding, and direct checks for constants).
1902 However, a read-only object that has side effects cannot be bypassed.
1903 Since it is no problem to reevaluate literals, we just return the
1906 if (TREE_CONSTANT (t) || (TREE_READONLY (t) && ! TREE_SIDE_EFFECTS (t))
1907 || TREE_CODE (t) == SAVE_EXPR)
1910 /* If T contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
1911 it means that the size or offset of some field of an object depends on
1912 the value within another field.
1914 Note that it must not be the case that T contains both a PLACEHOLDER_EXPR
1915 and some variable since it would then need to be both evaluated once and
1916 evaluated more than once. Front-ends must assure this case cannot
1917 happen by surrounding any such subexpressions in their own SAVE_EXPR
1918 and forcing evaluation at the proper time. */
1919 if (contains_placeholder_p (t))
1922 t = build (SAVE_EXPR, TREE_TYPE (expr), t, current_function_decl, NULL_TREE);
1924 /* This expression might be placed ahead of a jump to ensure that the
1925 value was computed on both sides of the jump. So make sure it isn't
1926 eliminated as dead. */
1927 TREE_SIDE_EFFECTS (t) = 1;
1931 /* Return 1 if EXP contains a PLACEHOLDER_EXPR; i.e., if it represents a size
1932 or offset that depends on a field within a record.
1934 Note that we only allow such expressions within simple arithmetic
1938 contains_placeholder_p (exp)
1941 register enum tree_code code = TREE_CODE (exp);
1944 /* If we have a WITH_RECORD_EXPR, it "cancels" any PLACEHOLDER_EXPR
1945 in it since it is supplying a value for it. */
1946 if (code == WITH_RECORD_EXPR)
1949 switch (TREE_CODE_CLASS (code))
1952 for (inner = TREE_OPERAND (exp, 0);
1953 TREE_CODE_CLASS (TREE_CODE (inner)) == 'r';
1954 inner = TREE_OPERAND (inner, 0))
1956 return TREE_CODE (inner) == PLACEHOLDER_EXPR;
1961 switch (tree_code_length[(int) code])
1964 return contains_placeholder_p (TREE_OPERAND (exp, 0));
1966 return (code != RTL_EXPR
1967 && code != CONSTRUCTOR
1968 && ! (code == SAVE_EXPR && SAVE_EXPR_RTL (exp) != 0)
1969 && code != WITH_RECORD_EXPR
1970 && (contains_placeholder_p (TREE_OPERAND (exp, 0))
1971 || contains_placeholder_p (TREE_OPERAND (exp, 1))));
1973 return (code == COND_EXPR
1974 && (contains_placeholder_p (TREE_OPERAND (exp, 0))
1975 || contains_placeholder_p (TREE_OPERAND (exp, 1))
1976 || contains_placeholder_p (TREE_OPERAND (exp, 2))));
1983 /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
1984 return a tree with all occurrences of references to F in a
1985 PLACEHOLDER_EXPR replaced by R. Note that we assume here that EXP
1986 contains only arithmetic expressions. */
1989 substitute_in_expr (exp, f, r)
1994 enum tree_code code = TREE_CODE (exp);
1997 switch (TREE_CODE_CLASS (code))
2004 if (code == PLACEHOLDER_EXPR)
2012 switch (tree_code_length[(int) code])
2015 return fold (build1 (code, TREE_TYPE (exp),
2016 substitute_in_expr (TREE_OPERAND (exp, 0),
2020 /* An RTL_EXPR cannot contain a PLACEHOLDER_EXPR; a CONSTRUCTOR
2021 could, but we don't support it. */
2022 if (code == RTL_EXPR)
2024 else if (code == CONSTRUCTOR)
2027 return fold (build (code, TREE_TYPE (exp),
2028 substitute_in_expr (TREE_OPERAND (exp, 0), f, r),
2029 substitute_in_expr (TREE_OPERAND (exp, 1),
2033 /* It cannot be that anything inside a SAVE_EXPR contains a
2034 PLACEHOLDER_EXPR. */
2035 if (code == SAVE_EXPR)
2038 if (code != COND_EXPR)
2041 return fold (build (code, TREE_TYPE (exp),
2042 substitute_in_expr (TREE_OPERAND (exp, 0), f, r),
2043 substitute_in_expr (TREE_OPERAND (exp, 1), f, r),
2044 substitute_in_expr (TREE_OPERAND (exp, 2),
2054 /* If this expression is getting a value from a PLACEHOLDER_EXPR
2055 and it is the right field, replace it with R. */
2056 for (inner = TREE_OPERAND (exp, 0);
2057 TREE_CODE_CLASS (TREE_CODE (inner)) == 'r';
2058 inner = TREE_OPERAND (inner, 0))
2060 if (TREE_CODE (inner) == PLACEHOLDER_EXPR
2061 && TREE_OPERAND (exp, 1) == f)
2064 return fold (build (code, TREE_TYPE (exp),
2065 substitute_in_expr (TREE_OPERAND (exp, 0), f, r),
2066 TREE_OPERAND (exp, 1)));
2068 return fold (build (code, TREE_TYPE (exp),
2069 substitute_in_expr (TREE_OPERAND (exp, 0), f, r),
2070 substitute_in_expr (TREE_OPERAND (exp, 1), f, r),
2071 substitute_in_expr (TREE_OPERAND (exp, 2), f, r)));
2074 return fold (build1 (code, TREE_TYPE (exp),
2075 substitute_in_expr (TREE_OPERAND (exp, 0),
2078 return fold (build (code, TREE_TYPE (exp),
2079 substitute_in_expr (TREE_OPERAND (exp, 0), f, r),
2080 substitute_in_expr (TREE_OPERAND (exp, 1), f, r)));
2084 /* If it wasn't one of the cases we handle, give up. */
2089 /* Given a type T, a FIELD_DECL F, and a replacement value R,
2090 return a new type with all size expressions that contain F
2091 updated by replacing F with R. */
2094 substitute_in_type (t, f, r)
2097 switch (TREE_CODE (t))
2106 if ((TREE_CODE (TYPE_MIN_VALUE (t)) != INTEGER_CST
2107 && contains_placeholder_p (TYPE_MIN_VALUE (t)))
2108 || (TREE_CODE (TYPE_MAX_VALUE (t)) != INTEGER_CST
2109 && contains_placeholder_p (TYPE_MAX_VALUE (t))))
2110 return build_range_type (t,
2111 substitute_in_expr (TYPE_MIN_VALUE (t), f, r),
2112 substitute_in_expr (TYPE_MAX_VALUE (t), f, r));
2116 if ((TREE_CODE (TYPE_MIN_VALUE (t)) != INTEGER_CST
2117 && contains_placeholder_p (TYPE_MIN_VALUE (t)))
2118 || (TREE_CODE (TYPE_MAX_VALUE (t)) != INTEGER_CST
2119 && contains_placeholder_p (TYPE_MAX_VALUE (t))))
2121 t = build_type_copy (t);
2122 TYPE_MIN_VALUE (t) = substitute_in_expr (TYPE_MIN_VALUE (t), f, r);
2123 TYPE_MAX_VALUE (t) = substitute_in_expr (TYPE_MAX_VALUE (t), f, r);
2128 return build_complex_type (substitute_in_type (TREE_TYPE (t), f, r));
2132 case REFERENCE_TYPE:
2138 /* Don't know how to do these yet. */
2142 t = build_array_type (substitute_in_type (TREE_TYPE (t), f, r),
2143 substitute_in_type (TYPE_DOMAIN (t), f, r));
2150 case QUAL_UNION_TYPE:
2152 tree new = copy_node (t);
2154 tree last_field = 0;
2156 /* Start out with no fields, make new fields, and chain them
2159 TYPE_FIELDS (new) = 0;
2160 TYPE_SIZE (new) = 0;
2162 for (field = TYPE_FIELDS (t); field;
2163 field = TREE_CHAIN (field))
2165 tree new_field = copy_node (field);
2167 TREE_TYPE (new_field)
2168 = substitute_in_type (TREE_TYPE (new_field), f, r);
2170 /* If this is an anonymous field and the type of this field is
2171 a UNION_TYPE or RECORD_TYPE with no elements, ignore it. If
2172 the type just has one element, treat that as the field.
2173 But don't do this if we are processing a QUAL_UNION_TYPE. */
2174 if (TREE_CODE (t) != QUAL_UNION_TYPE && DECL_NAME (new_field) == 0
2175 && (TREE_CODE (TREE_TYPE (new_field)) == UNION_TYPE
2176 || TREE_CODE (TREE_TYPE (new_field)) == RECORD_TYPE))
2178 if (TYPE_FIELDS (TREE_TYPE (new_field)) == 0)
2181 if (TREE_CHAIN (TYPE_FIELDS (TREE_TYPE (new_field))) == 0)
2182 new_field = TYPE_FIELDS (TREE_TYPE (new_field));
2185 DECL_CONTEXT (new_field) = new;
2186 DECL_SIZE (new_field) = 0;
2188 if (TREE_CODE (t) == QUAL_UNION_TYPE)
2190 /* Do the substitution inside the qualifier and if we find
2191 that this field will not be present, omit it. */
2192 DECL_QUALIFIER (new_field)
2193 = substitute_in_expr (DECL_QUALIFIER (field), f, r);
2194 if (integer_zerop (DECL_QUALIFIER (new_field)))
2198 if (last_field == 0)
2199 TYPE_FIELDS (new) = new_field;
2201 TREE_CHAIN (last_field) = new_field;
2203 last_field = new_field;
2205 /* If this is a qualified type and this field will always be
2206 present, we are done. */
2207 if (TREE_CODE (t) == QUAL_UNION_TYPE
2208 && integer_onep (DECL_QUALIFIER (new_field)))
2212 /* If this used to be a qualified union type, but we now know what
2213 field will be present, make this a normal union. */
2214 if (TREE_CODE (new) == QUAL_UNION_TYPE
2215 && (TYPE_FIELDS (new) == 0
2216 || integer_onep (DECL_QUALIFIER (TYPE_FIELDS (new)))))
2217 TREE_SET_CODE (new, UNION_TYPE);
2225 /* Stabilize a reference so that we can use it any number of times
2226 without causing its operands to be evaluated more than once.
2227 Returns the stabilized reference. This works by means of save_expr,
2228 so see the caveats in the comments about save_expr.
2230 Also allows conversion expressions whose operands are references.
2231 Any other kind of expression is returned unchanged. */
2234 stabilize_reference (ref)
2237 register tree result;
2238 register enum tree_code code = TREE_CODE (ref);
2245 /* No action is needed in this case. */
2251 case FIX_TRUNC_EXPR:
2252 case FIX_FLOOR_EXPR:
2253 case FIX_ROUND_EXPR:
2255 result = build_nt (code, stabilize_reference (TREE_OPERAND (ref, 0)));
2259 result = build_nt (INDIRECT_REF,
2260 stabilize_reference_1 (TREE_OPERAND (ref, 0)));
2264 result = build_nt (COMPONENT_REF,
2265 stabilize_reference (TREE_OPERAND (ref, 0)),
2266 TREE_OPERAND (ref, 1));
2270 result = build_nt (BIT_FIELD_REF,
2271 stabilize_reference (TREE_OPERAND (ref, 0)),
2272 stabilize_reference_1 (TREE_OPERAND (ref, 1)),
2273 stabilize_reference_1 (TREE_OPERAND (ref, 2)));
2277 result = build_nt (ARRAY_REF,
2278 stabilize_reference (TREE_OPERAND (ref, 0)),
2279 stabilize_reference_1 (TREE_OPERAND (ref, 1)));
2282 /* If arg isn't a kind of lvalue we recognize, make no change.
2283 Caller should recognize the error for an invalid lvalue. */
2288 return error_mark_node;
2291 TREE_TYPE (result) = TREE_TYPE (ref);
2292 TREE_READONLY (result) = TREE_READONLY (ref);
2293 TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (ref);
2294 TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (ref);
2295 TREE_RAISES (result) = TREE_RAISES (ref);
2300 /* Subroutine of stabilize_reference; this is called for subtrees of
2301 references. Any expression with side-effects must be put in a SAVE_EXPR
2302 to ensure that it is only evaluated once.
2304 We don't put SAVE_EXPR nodes around everything, because assigning very
2305 simple expressions to temporaries causes us to miss good opportunities
2306 for optimizations. Among other things, the opportunity to fold in the
2307 addition of a constant into an addressing mode often gets lost, e.g.
2308 "y[i+1] += x;". In general, we take the approach that we should not make
2309 an assignment unless we are forced into it - i.e., that any non-side effect
2310 operator should be allowed, and that cse should take care of coalescing
2311 multiple utterances of the same expression should that prove fruitful. */
2314 stabilize_reference_1 (e)
2317 register tree result;
2318 register int length;
2319 register enum tree_code code = TREE_CODE (e);
2321 /* We cannot ignore const expressions because it might be a reference
2322 to a const array but whose index contains side-effects. But we can
2323 ignore things that are actual constant or that already have been
2324 handled by this function. */
2326 if (TREE_CONSTANT (e) || code == SAVE_EXPR)
2329 switch (TREE_CODE_CLASS (code))
2339 /* If the expression has side-effects, then encase it in a SAVE_EXPR
2340 so that it will only be evaluated once. */
2341 /* The reference (r) and comparison (<) classes could be handled as
2342 below, but it is generally faster to only evaluate them once. */
2343 if (TREE_SIDE_EFFECTS (e))
2344 return save_expr (e);
2348 /* Constants need no processing. In fact, we should never reach
2353 /* Division is slow and tends to be compiled with jumps,
2354 especially the division by powers of 2 that is often
2355 found inside of an array reference. So do it just once. */
2356 if (code == TRUNC_DIV_EXPR || code == TRUNC_MOD_EXPR
2357 || code == FLOOR_DIV_EXPR || code == FLOOR_MOD_EXPR
2358 || code == CEIL_DIV_EXPR || code == CEIL_MOD_EXPR
2359 || code == ROUND_DIV_EXPR || code == ROUND_MOD_EXPR)
2360 return save_expr (e);
2361 /* Recursively stabilize each operand. */
2362 result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)),
2363 stabilize_reference_1 (TREE_OPERAND (e, 1)));
2367 /* Recursively stabilize each operand. */
2368 result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)));
2372 TREE_TYPE (result) = TREE_TYPE (e);
2373 TREE_READONLY (result) = TREE_READONLY (e);
2374 TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (e);
2375 TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (e);
2376 TREE_RAISES (result) = TREE_RAISES (e);
2381 /* Low-level constructors for expressions. */
2383 /* Build an expression of code CODE, data type TYPE,
2384 and operands as specified by the arguments ARG1 and following arguments.
2385 Expressions and reference nodes can be created this way.
2386 Constants, decls, types and misc nodes cannot be. */
2393 enum tree_code code;
2395 register int length;
2400 code = va_arg (p, enum tree_code);
2401 t = make_node (code);
2402 length = tree_code_length[(int) code];
2403 TREE_TYPE (t) = va_arg (p, tree);
2407 /* This is equivalent to the loop below, but faster. */
2408 register tree arg0 = va_arg (p, tree);
2409 register tree arg1 = va_arg (p, tree);
2410 TREE_OPERAND (t, 0) = arg0;
2411 TREE_OPERAND (t, 1) = arg1;
2412 if ((arg0 && TREE_SIDE_EFFECTS (arg0))
2413 || (arg1 && TREE_SIDE_EFFECTS (arg1)))
2414 TREE_SIDE_EFFECTS (t) = 1;
2416 = (arg0 && TREE_RAISES (arg0)) || (arg1 && TREE_RAISES (arg1));
2418 else if (length == 1)
2420 register tree arg0 = va_arg (p, tree);
2422 /* Call build1 for this! */
2423 if (TREE_CODE_CLASS (code) != 's')
2425 TREE_OPERAND (t, 0) = arg0;
2426 if (arg0 && TREE_SIDE_EFFECTS (arg0))
2427 TREE_SIDE_EFFECTS (t) = 1;
2428 TREE_RAISES (t) = (arg0 && TREE_RAISES (arg0));
2432 for (i = 0; i < length; i++)
2434 register tree operand = va_arg (p, tree);
2435 TREE_OPERAND (t, i) = operand;
2438 if (TREE_SIDE_EFFECTS (operand))
2439 TREE_SIDE_EFFECTS (t) = 1;
2440 if (TREE_RAISES (operand))
2441 TREE_RAISES (t) = 1;
2449 /* Same as above, but only builds for unary operators.
2450 Saves lions share of calls to `build'; cuts down use
2451 of varargs, which is expensive for RISC machines. */
2453 build1 (code, type, node)
2454 enum tree_code code;
2458 register struct obstack *obstack = current_obstack;
2459 register int i, length;
2460 register tree_node_kind kind;
2463 #ifdef GATHER_STATISTICS
2464 if (TREE_CODE_CLASS (code) == 'r')
2470 obstack = expression_obstack;
2471 length = sizeof (struct tree_exp);
2473 t = (tree) obstack_alloc (obstack, length);
2475 #ifdef GATHER_STATISTICS
2476 tree_node_counts[(int)kind]++;
2477 tree_node_sizes[(int)kind] += length;
2480 for (i = (length / sizeof (int)) - 1; i >= 0; i--)
2483 TREE_TYPE (t) = type;
2484 TREE_SET_CODE (t, code);
2486 if (obstack == &permanent_obstack)
2487 TREE_PERMANENT (t) = 1;
2489 TREE_OPERAND (t, 0) = node;
2492 if (TREE_SIDE_EFFECTS (node))
2493 TREE_SIDE_EFFECTS (t) = 1;
2494 if (TREE_RAISES (node))
2495 TREE_RAISES (t) = 1;
2501 /* Similar except don't specify the TREE_TYPE
2502 and leave the TREE_SIDE_EFFECTS as 0.
2503 It is permissible for arguments to be null,
2504 or even garbage if their values do not matter. */
2511 register enum tree_code code;
2513 register int length;
2518 code = va_arg (p, enum tree_code);
2519 t = make_node (code);
2520 length = tree_code_length[(int) code];
2522 for (i = 0; i < length; i++)
2523 TREE_OPERAND (t, i) = va_arg (p, tree);
2529 /* Similar to `build_nt', except we build
2530 on the temp_decl_obstack, regardless. */
2533 build_parse_node (va_alist)
2536 register struct obstack *ambient_obstack = expression_obstack;
2538 register enum tree_code code;
2540 register int length;
2543 expression_obstack = &temp_decl_obstack;
2547 code = va_arg (p, enum tree_code);
2548 t = make_node (code);
2549 length = tree_code_length[(int) code];
2551 for (i = 0; i < length; i++)
2552 TREE_OPERAND (t, i) = va_arg (p, tree);
2555 expression_obstack = ambient_obstack;
2560 /* Commented out because this wants to be done very
2561 differently. See cp-lex.c. */
2563 build_op_identifier (op1, op2)
2566 register tree t = make_node (OP_IDENTIFIER);
2567 TREE_PURPOSE (t) = op1;
2568 TREE_VALUE (t) = op2;
2573 /* Create a DECL_... node of code CODE, name NAME and data type TYPE.
2574 We do NOT enter this node in any sort of symbol table.
2576 layout_decl is used to set up the decl's storage layout.
2577 Other slots are initialized to 0 or null pointers. */
2580 build_decl (code, name, type)
2581 enum tree_code code;
2586 t = make_node (code);
2588 /* if (type == error_mark_node)
2589 type = integer_type_node; */
2590 /* That is not done, deliberately, so that having error_mark_node
2591 as the type can suppress useless errors in the use of this variable. */
2593 DECL_NAME (t) = name;
2594 DECL_ASSEMBLER_NAME (t) = name;
2595 TREE_TYPE (t) = type;
2597 if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
2599 else if (code == FUNCTION_DECL)
2600 DECL_MODE (t) = FUNCTION_MODE;
2605 /* BLOCK nodes are used to represent the structure of binding contours
2606 and declarations, once those contours have been exited and their contents
2607 compiled. This information is used for outputting debugging info. */
2610 build_block (vars, tags, subblocks, supercontext, chain)
2611 tree vars, tags, subblocks, supercontext, chain;
2613 register tree block = make_node (BLOCK);
2614 BLOCK_VARS (block) = vars;
2615 BLOCK_TYPE_TAGS (block) = tags;
2616 BLOCK_SUBBLOCKS (block) = subblocks;
2617 BLOCK_SUPERCONTEXT (block) = supercontext;
2618 BLOCK_CHAIN (block) = chain;
2622 /* Return a type like TYPE except that its TYPE_READONLY is CONSTP
2623 and its TYPE_VOLATILE is VOLATILEP.
2625 Such variant types already made are recorded so that duplicates
2628 A variant types should never be used as the type of an expression.
2629 Always copy the variant information into the TREE_READONLY
2630 and TREE_THIS_VOLATILE of the expression, and then give the expression
2631 as its type the "main variant", the variant whose TYPE_READONLY
2632 and TYPE_VOLATILE are zero. Use TYPE_MAIN_VARIANT to find the
2636 build_type_variant (type, constp, volatilep)
2638 int constp, volatilep;
2642 /* Treat any nonzero argument as 1. */
2644 volatilep = !!volatilep;
2646 /* If not generating auxiliary info, search the chain of variants to see
2647 if there is already one there just like the one we need to have. If so,
2648 use that existing one.
2650 We don't do this in the case where we are generating aux info because
2651 in that case we want each typedef names to get it's own distinct type
2652 node, even if the type of this new typedef is the same as some other
2655 if (!flag_gen_aux_info)
2656 for (t = TYPE_MAIN_VARIANT(type); t; t = TYPE_NEXT_VARIANT (t))
2657 if (constp == TYPE_READONLY (t) && volatilep == TYPE_VOLATILE (t))
2660 /* We need a new one. */
2662 t = build_type_copy (type);
2663 TYPE_READONLY (t) = constp;
2664 TYPE_VOLATILE (t) = volatilep;
2669 /* Give TYPE a new main variant: NEW_MAIN.
2670 This is the right thing to do only when something else
2671 about TYPE is modified in place. */
2674 change_main_variant (type, new_main)
2675 tree type, new_main;
2678 tree omain = TYPE_MAIN_VARIANT (type);
2680 /* Remove TYPE from the TYPE_NEXT_VARIANT chain of its main variant. */
2681 if (TYPE_NEXT_VARIANT (omain) == type)
2682 TYPE_NEXT_VARIANT (omain) = TYPE_NEXT_VARIANT (type);
2684 for (t = TYPE_NEXT_VARIANT (omain); t && TYPE_NEXT_VARIANT (t);
2685 t = TYPE_NEXT_VARIANT (t))
2686 if (TYPE_NEXT_VARIANT (t) == type)
2688 TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (type);
2692 TYPE_MAIN_VARIANT (type) = new_main;
2693 TYPE_NEXT_VARIANT (type) = TYPE_NEXT_VARIANT (new_main);
2694 TYPE_NEXT_VARIANT (new_main) = type;
2697 /* Create a new variant of TYPE, equivalent but distinct.
2698 This is so the caller can modify it. */
2701 build_type_copy (type)
2704 register tree t, m = TYPE_MAIN_VARIANT (type);
2705 register struct obstack *ambient_obstack = current_obstack;
2707 current_obstack = TYPE_OBSTACK (type);
2708 t = copy_node (type);
2709 current_obstack = ambient_obstack;
2711 TYPE_POINTER_TO (t) = 0;
2712 TYPE_REFERENCE_TO (t) = 0;
2714 /* Add this type to the chain of variants of TYPE. */
2715 TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
2716 TYPE_NEXT_VARIANT (m) = t;
2721 /* Hashing of types so that we don't make duplicates.
2722 The entry point is `type_hash_canon'. */
2724 /* Each hash table slot is a bucket containing a chain
2725 of these structures. */
2729 struct type_hash *next; /* Next structure in the bucket. */
2730 int hashcode; /* Hash code of this type. */
2731 tree type; /* The type recorded here. */
2734 /* Now here is the hash table. When recording a type, it is added
2735 to the slot whose index is the hash code mod the table size.
2736 Note that the hash table is used for several kinds of types
2737 (function types, array types and array index range types, for now).
2738 While all these live in the same table, they are completely independent,
2739 and the hash code is computed differently for each of these. */
2741 #define TYPE_HASH_SIZE 59
2742 struct type_hash *type_hash_table[TYPE_HASH_SIZE];
2744 /* Here is how primitive or already-canonicalized types' hash
2746 #define TYPE_HASH(TYPE) ((HOST_WIDE_INT) (TYPE) & 0777777)
2748 /* Compute a hash code for a list of types (chain of TREE_LIST nodes
2749 with types in the TREE_VALUE slots), by adding the hash codes
2750 of the individual types. */
2753 type_hash_list (list)
2756 register int hashcode;
2758 for (hashcode = 0, tail = list; tail; tail = TREE_CHAIN (tail))
2759 hashcode += TYPE_HASH (TREE_VALUE (tail));
2763 /* Look in the type hash table for a type isomorphic to TYPE.
2764 If one is found, return it. Otherwise return 0. */
2767 type_hash_lookup (hashcode, type)
2771 register struct type_hash *h;
2772 for (h = type_hash_table[hashcode % TYPE_HASH_SIZE]; h; h = h->next)
2773 if (h->hashcode == hashcode
2774 && TREE_CODE (h->type) == TREE_CODE (type)
2775 && TREE_TYPE (h->type) == TREE_TYPE (type)
2776 && (TYPE_MAX_VALUE (h->type) == TYPE_MAX_VALUE (type)
2777 || tree_int_cst_equal (TYPE_MAX_VALUE (h->type),
2778 TYPE_MAX_VALUE (type)))
2779 && (TYPE_MIN_VALUE (h->type) == TYPE_MIN_VALUE (type)
2780 || tree_int_cst_equal (TYPE_MIN_VALUE (h->type),
2781 TYPE_MIN_VALUE (type)))
2782 && (TYPE_DOMAIN (h->type) == TYPE_DOMAIN (type)
2783 || (TYPE_DOMAIN (h->type)
2784 && TREE_CODE (TYPE_DOMAIN (h->type)) == TREE_LIST
2785 && TYPE_DOMAIN (type)
2786 && TREE_CODE (TYPE_DOMAIN (type)) == TREE_LIST
2787 && type_list_equal (TYPE_DOMAIN (h->type), TYPE_DOMAIN (type)))))
2792 /* Add an entry to the type-hash-table
2793 for a type TYPE whose hash code is HASHCODE. */
2796 type_hash_add (hashcode, type)
2800 register struct type_hash *h;
2802 h = (struct type_hash *) oballoc (sizeof (struct type_hash));
2803 h->hashcode = hashcode;
2805 h->next = type_hash_table[hashcode % TYPE_HASH_SIZE];
2806 type_hash_table[hashcode % TYPE_HASH_SIZE] = h;
2809 /* Given TYPE, and HASHCODE its hash code, return the canonical
2810 object for an identical type if one already exists.
2811 Otherwise, return TYPE, and record it as the canonical object
2812 if it is a permanent object.
2814 To use this function, first create a type of the sort you want.
2815 Then compute its hash code from the fields of the type that
2816 make it different from other similar types.
2817 Then call this function and use the value.
2818 This function frees the type you pass in if it is a duplicate. */
2820 /* Set to 1 to debug without canonicalization. Never set by program. */
2821 int debug_no_type_hash = 0;
2824 type_hash_canon (hashcode, type)
2830 if (debug_no_type_hash)
2833 t1 = type_hash_lookup (hashcode, type);
2836 obstack_free (TYPE_OBSTACK (type), type);
2837 #ifdef GATHER_STATISTICS
2838 tree_node_counts[(int)t_kind]--;
2839 tree_node_sizes[(int)t_kind] -= sizeof (struct tree_type);
2844 /* If this is a permanent type, record it for later reuse. */
2845 if (TREE_PERMANENT (type))
2846 type_hash_add (hashcode, type);
2851 /* Given two lists of types
2852 (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
2853 return 1 if the lists contain the same types in the same order.
2854 Also, the TREE_PURPOSEs must match. */
2857 type_list_equal (l1, l2)
2860 register tree t1, t2;
2861 for (t1 = l1, t2 = l2; t1 && t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
2863 if (TREE_VALUE (t1) != TREE_VALUE (t2))
2865 if (TREE_PURPOSE (t1) != TREE_PURPOSE (t2))
2867 int cmp = simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2));
2878 /* Nonzero if integer constants T1 and T2
2879 represent the same constant value. */
2882 tree_int_cst_equal (t1, t2)
2887 if (t1 == 0 || t2 == 0)
2889 if (TREE_CODE (t1) == INTEGER_CST
2890 && TREE_CODE (t2) == INTEGER_CST
2891 && TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
2892 && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2))
2897 /* Nonzero if integer constants T1 and T2 represent values that satisfy <.
2898 The precise way of comparison depends on their data type. */
2901 tree_int_cst_lt (t1, t2)
2907 if (!TREE_UNSIGNED (TREE_TYPE (t1)))
2908 return INT_CST_LT (t1, t2);
2909 return INT_CST_LT_UNSIGNED (t1, t2);
2912 /* Compare two constructor-element-type constants. */
2914 simple_cst_list_equal (l1, l2)
2917 while (l1 != NULL_TREE && l2 != NULL_TREE)
2919 int cmp = simple_cst_equal (TREE_VALUE (l1), TREE_VALUE (l2));
2924 l1 = TREE_CHAIN (l1);
2925 l2 = TREE_CHAIN (l2);
2930 /* Return truthvalue of whether T1 is the same tree structure as T2.
2931 Return 1 if they are the same.
2932 Return 0 if they are understandably different.
2933 Return -1 if either contains tree structure not understood by
2937 simple_cst_equal (t1, t2)
2940 register enum tree_code code1, code2;
2945 if (t1 == 0 || t2 == 0)
2948 code1 = TREE_CODE (t1);
2949 code2 = TREE_CODE (t2);
2951 if (code1 == NOP_EXPR || code1 == CONVERT_EXPR || code1 == NON_LVALUE_EXPR)
2952 if (code2 == NOP_EXPR || code2 == CONVERT_EXPR || code2 == NON_LVALUE_EXPR)
2953 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2955 return simple_cst_equal (TREE_OPERAND (t1, 0), t2);
2956 else if (code2 == NOP_EXPR || code2 == CONVERT_EXPR
2957 || code2 == NON_LVALUE_EXPR)
2958 return simple_cst_equal (t1, TREE_OPERAND (t2, 0));
2966 return TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
2967 && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2);
2970 return REAL_VALUES_EQUAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
2973 return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
2974 && !bcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
2975 TREE_STRING_LENGTH (t1));
2981 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2984 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2987 return simple_cst_list_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
2990 /* Special case: if either target is an unallocated VAR_DECL,
2991 it means that it's going to be unified with whatever the
2992 TARGET_EXPR is really supposed to initialize, so treat it
2993 as being equivalent to anything. */
2994 if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL
2995 && DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE
2996 && DECL_RTL (TREE_OPERAND (t1, 0)) == 0)
2997 || (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL
2998 && DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE
2999 && DECL_RTL (TREE_OPERAND (t2, 0)) == 0))
3002 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3005 return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
3007 case WITH_CLEANUP_EXPR:
3008 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3011 return simple_cst_equal (TREE_OPERAND (t1, 2), TREE_OPERAND (t1, 2));
3014 if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1))
3015 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3025 /* This general rule works for most tree codes.
3026 All exceptions should be handled above. */
3028 switch (TREE_CODE_CLASS (code1))
3038 for (i=0; i<tree_code_length[(int) code1]; ++i)
3040 cmp = simple_cst_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i));
3050 /* Constructors for pointer, array and function types.
3051 (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
3052 constructed by language-dependent code, not here.) */
3054 /* Construct, lay out and return the type of pointers to TO_TYPE.
3055 If such a type has already been constructed, reuse it. */
3058 build_pointer_type (to_type)
3061 register tree t = TYPE_POINTER_TO (to_type);
3063 /* First, if we already have a type for pointers to TO_TYPE, use it. */
3068 /* We need a new one. Put this in the same obstack as TO_TYPE. */
3069 push_obstacks (TYPE_OBSTACK (to_type), TYPE_OBSTACK (to_type));
3070 t = make_node (POINTER_TYPE);
3073 TREE_TYPE (t) = to_type;
3075 /* Record this type as the pointer to TO_TYPE. */
3076 TYPE_POINTER_TO (to_type) = t;
3078 /* Lay out the type. This function has many callers that are concerned
3079 with expression-construction, and this simplifies them all.
3080 Also, it guarantees the TYPE_SIZE is in the same obstack as the type. */
3086 /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
3087 MAXVAL should be the maximum value in the domain
3088 (one less than the length of the array). */
3091 build_index_type (maxval)
3094 register tree itype = make_node (INTEGER_TYPE);
3095 TYPE_PRECISION (itype) = TYPE_PRECISION (sizetype);
3096 TYPE_MIN_VALUE (itype) = build_int_2 (0, 0);
3097 TREE_TYPE (TYPE_MIN_VALUE (itype)) = sizetype;
3098 TYPE_MAX_VALUE (itype) = convert (sizetype, maxval);
3099 TYPE_MODE (itype) = TYPE_MODE (sizetype);
3100 TYPE_SIZE (itype) = TYPE_SIZE (sizetype);
3101 TYPE_ALIGN (itype) = TYPE_ALIGN (sizetype);
3102 if (TREE_CODE (maxval) == INTEGER_CST)
3104 int maxint = (int) TREE_INT_CST_LOW (maxval);
3105 /* If the domain should be empty, make sure the maxval
3106 remains -1 and is not spoiled by truncation. */
3107 if (INT_CST_LT (maxval, integer_zero_node))
3109 TYPE_MAX_VALUE (itype) = build_int_2 (-1, -1);
3110 TREE_TYPE (TYPE_MAX_VALUE (itype)) = sizetype;
3112 return type_hash_canon (maxint < 0 ? ~maxint : maxint, itype);
3118 /* Create a range of some discrete type TYPE (an INTEGER_TYPE,
3119 ENUMERAL_TYPE, BOOLEAN_TYPE, or CHAR_TYPE), with
3120 low bound LOWVAL and high bound HIGHVAL.
3121 if TYPE==NULL_TREE, sizetype is used. */
3124 build_range_type (type, lowval, highval)
3125 tree type, lowval, highval;
3127 register tree itype = make_node (INTEGER_TYPE);
3128 TREE_TYPE (itype) = type;
3129 if (type == NULL_TREE)
3131 TYPE_PRECISION (itype) = TYPE_PRECISION (type);
3132 TYPE_MIN_VALUE (itype) = convert (type, lowval);
3133 TYPE_MAX_VALUE (itype) = convert (type, highval);
3134 TYPE_MODE (itype) = TYPE_MODE (type);
3135 TYPE_SIZE (itype) = TYPE_SIZE (type);
3136 TYPE_ALIGN (itype) = TYPE_ALIGN (type);
3137 if ((TREE_CODE (lowval) == INTEGER_CST)
3138 && (TREE_CODE (highval) == INTEGER_CST))
3140 HOST_WIDE_INT highint = TREE_INT_CST_LOW (highval);
3141 HOST_WIDE_INT lowint = TREE_INT_CST_LOW (lowval);
3142 int maxint = (int) (highint - lowint);
3143 return type_hash_canon (maxint < 0 ? ~maxint : maxint, itype);
3149 /* Just like build_index_type, but takes lowval and highval instead
3150 of just highval (maxval). */
3153 build_index_2_type (lowval,highval)
3154 tree lowval, highval;
3156 return build_range_type (NULL_TREE, lowval, highval);
3159 /* Return nonzero iff ITYPE1 and ITYPE2 are equal (in the LISP sense).
3160 Needed because when index types are not hashed, equal index types
3161 built at different times appear distinct, even though structurally,
3165 index_type_equal (itype1, itype2)
3166 tree itype1, itype2;
3168 if (TREE_CODE (itype1) != TREE_CODE (itype2))
3170 if (TREE_CODE (itype1) == INTEGER_TYPE)
3172 if (TYPE_PRECISION (itype1) != TYPE_PRECISION (itype2)
3173 || TYPE_MODE (itype1) != TYPE_MODE (itype2)
3174 || ! simple_cst_equal (TYPE_SIZE (itype1), TYPE_SIZE (itype2))
3175 || TYPE_ALIGN (itype1) != TYPE_ALIGN (itype2))
3177 if (simple_cst_equal (TYPE_MIN_VALUE (itype1), TYPE_MIN_VALUE (itype2))
3178 && simple_cst_equal (TYPE_MAX_VALUE (itype1), TYPE_MAX_VALUE (itype2)))
3184 /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
3185 and number of elements specified by the range of values of INDEX_TYPE.
3186 If such a type has already been constructed, reuse it. */
3189 build_array_type (elt_type, index_type)
3190 tree elt_type, index_type;
3195 if (TREE_CODE (elt_type) == FUNCTION_TYPE)
3197 error ("arrays of functions are not meaningful");
3198 elt_type = integer_type_node;
3201 /* Make sure TYPE_POINTER_TO (elt_type) is filled in. */
3202 build_pointer_type (elt_type);
3204 /* Allocate the array after the pointer type,
3205 in case we free it in type_hash_canon. */
3206 t = make_node (ARRAY_TYPE);
3207 TREE_TYPE (t) = elt_type;
3208 TYPE_DOMAIN (t) = index_type;
3210 if (index_type == 0)
3215 hashcode = TYPE_HASH (elt_type) + TYPE_HASH (index_type);
3216 t = type_hash_canon (hashcode, t);
3218 #if 0 /* This led to crashes, because it could put a temporary node
3219 on the TYPE_NEXT_VARIANT chain of a permanent one. */
3220 /* The main variant of an array type should always
3221 be an array whose element type is the main variant. */
3222 if (elt_type != TYPE_MAIN_VARIANT (elt_type))
3223 change_main_variant (t, build_array_type (TYPE_MAIN_VARIANT (elt_type),
3227 if (TYPE_SIZE (t) == 0)
3232 /* Construct, lay out and return
3233 the type of functions returning type VALUE_TYPE
3234 given arguments of types ARG_TYPES.
3235 ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
3236 are data type nodes for the arguments of the function.
3237 If such a type has already been constructed, reuse it. */
3240 build_function_type (value_type, arg_types)
3241 tree value_type, arg_types;
3246 if (TREE_CODE (value_type) == FUNCTION_TYPE)
3248 error ("function return type cannot be function");
3249 value_type = integer_type_node;
3252 /* Make a node of the sort we want. */
3253 t = make_node (FUNCTION_TYPE);
3254 TREE_TYPE (t) = value_type;
3255 TYPE_ARG_TYPES (t) = arg_types;
3257 /* If we already have such a type, use the old one and free this one. */
3258 hashcode = TYPE_HASH (value_type) + type_hash_list (arg_types);
3259 t = type_hash_canon (hashcode, t);
3261 if (TYPE_SIZE (t) == 0)
3266 /* Build the node for the type of references-to-TO_TYPE. */
3269 build_reference_type (to_type)
3272 register tree t = TYPE_REFERENCE_TO (to_type);
3273 register struct obstack *ambient_obstack = current_obstack;
3274 register struct obstack *ambient_saveable_obstack = saveable_obstack;
3276 /* First, if we already have a type for pointers to TO_TYPE, use it. */
3281 /* We need a new one. If TO_TYPE is permanent, make this permanent too. */
3282 if (TREE_PERMANENT (to_type))
3284 current_obstack = &permanent_obstack;
3285 saveable_obstack = &permanent_obstack;
3288 t = make_node (REFERENCE_TYPE);
3289 TREE_TYPE (t) = to_type;
3291 /* Record this type as the pointer to TO_TYPE. */
3292 TYPE_REFERENCE_TO (to_type) = t;
3296 current_obstack = ambient_obstack;
3297 saveable_obstack = ambient_saveable_obstack;
3301 /* Construct, lay out and return the type of methods belonging to class
3302 BASETYPE and whose arguments and values are described by TYPE.
3303 If that type exists already, reuse it.
3304 TYPE must be a FUNCTION_TYPE node. */
3307 build_method_type (basetype, type)
3308 tree basetype, type;
3313 /* Make a node of the sort we want. */
3314 t = make_node (METHOD_TYPE);
3316 if (TREE_CODE (type) != FUNCTION_TYPE)
3319 TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
3320 TREE_TYPE (t) = TREE_TYPE (type);
3322 /* The actual arglist for this function includes a "hidden" argument
3323 which is "this". Put it into the list of argument types. */
3326 = tree_cons (NULL_TREE,
3327 build_pointer_type (basetype), TYPE_ARG_TYPES (type));
3329 /* If we already have such a type, use the old one and free this one. */
3330 hashcode = TYPE_HASH (basetype) + TYPE_HASH (type);
3331 t = type_hash_canon (hashcode, t);
3333 if (TYPE_SIZE (t) == 0)
3339 /* Construct, lay out and return the type of offsets to a value
3340 of type TYPE, within an object of type BASETYPE.
3341 If a suitable offset type exists already, reuse it. */
3344 build_offset_type (basetype, type)
3345 tree basetype, type;
3350 /* Make a node of the sort we want. */
3351 t = make_node (OFFSET_TYPE);
3353 TYPE_OFFSET_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
3354 TREE_TYPE (t) = type;
3356 /* If we already have such a type, use the old one and free this one. */
3357 hashcode = TYPE_HASH (basetype) + TYPE_HASH (type);
3358 t = type_hash_canon (hashcode, t);
3360 if (TYPE_SIZE (t) == 0)
3366 /* Create a complex type whose components are COMPONENT_TYPE. */
3369 build_complex_type (component_type)
3370 tree component_type;
3375 /* Make a node of the sort we want. */
3376 t = make_node (COMPLEX_TYPE);
3378 TREE_TYPE (t) = TYPE_MAIN_VARIANT (component_type);
3379 TYPE_VOLATILE (t) = TYPE_VOLATILE (component_type);
3380 TYPE_READONLY (t) = TYPE_READONLY (component_type);
3382 /* If we already have such a type, use the old one and free this one. */
3383 hashcode = TYPE_HASH (component_type);
3384 t = type_hash_canon (hashcode, t);
3386 if (TYPE_SIZE (t) == 0)
3392 /* Return OP, stripped of any conversions to wider types as much as is safe.
3393 Converting the value back to OP's type makes a value equivalent to OP.
3395 If FOR_TYPE is nonzero, we return a value which, if converted to
3396 type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
3398 If FOR_TYPE is nonzero, unaligned bit-field references may be changed to the
3399 narrowest type that can hold the value, even if they don't exactly fit.
3400 Otherwise, bit-field references are changed to a narrower type
3401 only if they can be fetched directly from memory in that type.
3403 OP must have integer, real or enumeral type. Pointers are not allowed!
3405 There are some cases where the obvious value we could return
3406 would regenerate to OP if converted to OP's type,
3407 but would not extend like OP to wider types.
3408 If FOR_TYPE indicates such extension is contemplated, we eschew such values.
3409 For example, if OP is (unsigned short)(signed char)-1,
3410 we avoid returning (signed char)-1 if FOR_TYPE is int,
3411 even though extending that to an unsigned short would regenerate OP,
3412 since the result of extending (signed char)-1 to (int)
3413 is different from (int) OP. */
3416 get_unwidened (op, for_type)
3420 /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */
3421 /* TYPE_PRECISION is safe in place of type_precision since
3422 pointer types are not allowed. */
3423 register tree type = TREE_TYPE (op);
3424 register unsigned final_prec
3425 = TYPE_PRECISION (for_type != 0 ? for_type : type);
3427 = (for_type != 0 && for_type != type
3428 && final_prec > TYPE_PRECISION (type)
3429 && TREE_UNSIGNED (type));
3430 register tree win = op;
3432 while (TREE_CODE (op) == NOP_EXPR)
3434 register int bitschange
3435 = TYPE_PRECISION (TREE_TYPE (op))
3436 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
3438 /* Truncations are many-one so cannot be removed.
3439 Unless we are later going to truncate down even farther. */
3441 && final_prec > TYPE_PRECISION (TREE_TYPE (op)))
3444 /* See what's inside this conversion. If we decide to strip it,
3446 op = TREE_OPERAND (op, 0);
3448 /* If we have not stripped any zero-extensions (uns is 0),
3449 we can strip any kind of extension.
3450 If we have previously stripped a zero-extension,
3451 only zero-extensions can safely be stripped.
3452 Any extension can be stripped if the bits it would produce
3453 are all going to be discarded later by truncating to FOR_TYPE. */
3457 if (! uns || final_prec <= TYPE_PRECISION (TREE_TYPE (op)))
3459 /* TREE_UNSIGNED says whether this is a zero-extension.
3460 Let's avoid computing it if it does not affect WIN
3461 and if UNS will not be needed again. */
3462 if ((uns || TREE_CODE (op) == NOP_EXPR)
3463 && TREE_UNSIGNED (TREE_TYPE (op)))
3471 if (TREE_CODE (op) == COMPONENT_REF
3472 /* Since type_for_size always gives an integer type. */
3473 && TREE_CODE (type) != REAL_TYPE)
3475 unsigned innerprec = TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (op, 1)));
3476 type = type_for_size (innerprec, TREE_UNSIGNED (TREE_OPERAND (op, 1)));
3478 /* We can get this structure field in the narrowest type it fits in.
3479 If FOR_TYPE is 0, do this only for a field that matches the
3480 narrower type exactly and is aligned for it
3481 The resulting extension to its nominal type (a fullword type)
3482 must fit the same conditions as for other extensions. */
3484 if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
3485 && (for_type || ! DECL_BIT_FIELD (TREE_OPERAND (op, 1)))
3486 && (! uns || final_prec <= innerprec
3487 || TREE_UNSIGNED (TREE_OPERAND (op, 1)))
3490 win = build (COMPONENT_REF, type, TREE_OPERAND (op, 0),
3491 TREE_OPERAND (op, 1));
3492 TREE_SIDE_EFFECTS (win) = TREE_SIDE_EFFECTS (op);
3493 TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
3494 TREE_RAISES (win) = TREE_RAISES (op);
3500 /* Return OP or a simpler expression for a narrower value
3501 which can be sign-extended or zero-extended to give back OP.
3502 Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
3503 or 0 if the value should be sign-extended. */
3506 get_narrower (op, unsignedp_ptr)
3510 register int uns = 0;
3512 register tree win = op;
3514 while (TREE_CODE (op) == NOP_EXPR)
3516 register int bitschange
3517 = TYPE_PRECISION (TREE_TYPE (op))
3518 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
3520 /* Truncations are many-one so cannot be removed. */
3524 /* See what's inside this conversion. If we decide to strip it,
3526 op = TREE_OPERAND (op, 0);
3530 /* An extension: the outermost one can be stripped,
3531 but remember whether it is zero or sign extension. */
3533 uns = TREE_UNSIGNED (TREE_TYPE (op));
3534 /* Otherwise, if a sign extension has been stripped,
3535 only sign extensions can now be stripped;
3536 if a zero extension has been stripped, only zero-extensions. */
3537 else if (uns != TREE_UNSIGNED (TREE_TYPE (op)))
3541 else /* bitschange == 0 */
3543 /* A change in nominal type can always be stripped, but we must
3544 preserve the unsignedness. */
3546 uns = TREE_UNSIGNED (TREE_TYPE (op));
3553 if (TREE_CODE (op) == COMPONENT_REF
3554 /* Since type_for_size always gives an integer type. */
3555 && TREE_CODE (TREE_TYPE (op)) != REAL_TYPE)
3557 unsigned innerprec = TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (op, 1)));
3558 tree type = type_for_size (innerprec, TREE_UNSIGNED (op));
3560 /* We can get this structure field in a narrower type that fits it,
3561 but the resulting extension to its nominal type (a fullword type)
3562 must satisfy the same conditions as for other extensions.
3564 Do this only for fields that are aligned (not bit-fields),
3565 because when bit-field insns will be used there is no
3566 advantage in doing this. */
3568 if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
3569 && ! DECL_BIT_FIELD (TREE_OPERAND (op, 1))
3570 && (first || uns == TREE_UNSIGNED (TREE_OPERAND (op, 1)))
3574 uns = TREE_UNSIGNED (TREE_OPERAND (op, 1));
3575 win = build (COMPONENT_REF, type, TREE_OPERAND (op, 0),
3576 TREE_OPERAND (op, 1));
3577 TREE_SIDE_EFFECTS (win) = TREE_SIDE_EFFECTS (op);
3578 TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
3579 TREE_RAISES (win) = TREE_RAISES (op);
3582 *unsignedp_ptr = uns;
3586 /* Return the precision of a type, for arithmetic purposes.
3587 Supports all types on which arithmetic is possible
3588 (including pointer types).
3589 It's not clear yet what will be right for complex types. */
3592 type_precision (type)
3595 return ((TREE_CODE (type) == INTEGER_TYPE
3596 || TREE_CODE (type) == ENUMERAL_TYPE
3597 || TREE_CODE (type) == REAL_TYPE)
3598 ? TYPE_PRECISION (type) : POINTER_SIZE);
3601 /* Nonzero if integer constant C has a value that is permissible
3602 for type TYPE (an INTEGER_TYPE). */
3605 int_fits_type_p (c, type)
3608 if (TREE_UNSIGNED (type))
3609 return (! (TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST
3610 && INT_CST_LT_UNSIGNED (TYPE_MAX_VALUE (type), c))
3611 && ! (TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST
3612 && INT_CST_LT_UNSIGNED (c, TYPE_MIN_VALUE (type))));
3614 return (! (TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST
3615 && INT_CST_LT (TYPE_MAX_VALUE (type), c))
3616 && ! (TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST
3617 && INT_CST_LT (c, TYPE_MIN_VALUE (type))));
3620 /* Return the innermost context enclosing DECL that is
3621 a FUNCTION_DECL, or zero if none. */
3624 decl_function_context (decl)
3629 if (TREE_CODE (decl) == ERROR_MARK)
3632 if (TREE_CODE (decl) == SAVE_EXPR)
3633 context = SAVE_EXPR_CONTEXT (decl);
3635 context = DECL_CONTEXT (decl);
3637 while (context && TREE_CODE (context) != FUNCTION_DECL)
3639 if (TREE_CODE (context) == RECORD_TYPE
3640 || TREE_CODE (context) == UNION_TYPE)
3641 context = TYPE_CONTEXT (context);
3642 else if (TREE_CODE (context) == TYPE_DECL)
3643 context = DECL_CONTEXT (context);
3644 else if (TREE_CODE (context) == BLOCK)
3645 context = BLOCK_SUPERCONTEXT (context);
3647 /* Unhandled CONTEXT !? */
3654 /* Return the innermost context enclosing DECL that is
3655 a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
3656 TYPE_DECLs and FUNCTION_DECLs are transparent to this function. */
3659 decl_type_context (decl)
3662 tree context = DECL_CONTEXT (decl);
3666 if (TREE_CODE (context) == RECORD_TYPE
3667 || TREE_CODE (context) == UNION_TYPE
3668 || TREE_CODE (context) == QUAL_UNION_TYPE)
3670 if (TREE_CODE (context) == TYPE_DECL
3671 || TREE_CODE (context) == FUNCTION_DECL)
3672 context = DECL_CONTEXT (context);
3673 else if (TREE_CODE (context) == BLOCK)
3674 context = BLOCK_SUPERCONTEXT (context);
3676 /* Unhandled CONTEXT!? */
3683 print_obstack_statistics (str, o)
3687 struct _obstack_chunk *chunk = o->chunk;
3694 n_alloc += chunk->limit - &chunk->contents[0];
3695 chunk = chunk->prev;
3697 fprintf (stderr, "obstack %s: %d bytes, %d chunks\n",
3698 str, n_alloc, n_chunks);
3701 dump_tree_statistics ()
3704 int total_nodes, total_bytes;
3706 fprintf (stderr, "\n??? tree nodes created\n\n");
3707 #ifdef GATHER_STATISTICS
3708 fprintf (stderr, "Kind Nodes Bytes\n");
3709 fprintf (stderr, "-------------------------------------\n");
3710 total_nodes = total_bytes = 0;
3711 for (i = 0; i < (int) all_kinds; i++)
3713 fprintf (stderr, "%-20s %6d %9d\n", tree_node_kind_names[i],
3714 tree_node_counts[i], tree_node_sizes[i]);
3715 total_nodes += tree_node_counts[i];
3716 total_bytes += tree_node_sizes[i];
3718 fprintf (stderr, "%-20s %9d\n", "identifier names", id_string_size);
3719 fprintf (stderr, "-------------------------------------\n");
3720 fprintf (stderr, "%-20s %6d %9d\n", "Total", total_nodes, total_bytes);
3721 fprintf (stderr, "-------------------------------------\n");
3723 fprintf (stderr, "(No per-node statistics)\n");
3725 print_lang_statistics ();
3728 #define FILE_FUNCTION_PREFIX_LEN 9
3730 #ifndef NO_DOLLAR_IN_LABEL
3731 #define FILE_FUNCTION_FORMAT "_GLOBAL_$D$%s"
3732 #else /* NO_DOLLAR_IN_LABEL */
3733 #ifndef NO_DOT_IN_LABEL
3734 #define FILE_FUNCTION_FORMAT "_GLOBAL_.D.%s"
3735 #else /* NO_DOT_IN_LABEL */
3736 #define FILE_FUNCTION_FORMAT "_GLOBAL__D_%s"
3737 #endif /* NO_DOT_IN_LABEL */
3738 #endif /* NO_DOLLAR_IN_LABEL */
3740 extern char * first_global_object_name;
3742 /* If KIND=='I', return a suitable global initializer (constructor) name.
3743 If KIND=='D', return a suitable global clean-up (destructor) name. */
3746 get_file_function_name (kind)
3752 if (first_global_object_name)
3753 p = first_global_object_name;
3754 else if (main_input_filename)
3755 p = main_input_filename;
3759 buf = (char *) alloca (sizeof (FILE_FUNCTION_FORMAT) + strlen (p));
3761 /* Set up the name of the file-level functions we may need. */
3762 /* Use a global object (which is already required to be unique over
3763 the program) rather than the file name (which imposes extra
3764 constraints). -- Raeburn@MIT.EDU, 10 Jan 1990. */
3765 sprintf (buf, FILE_FUNCTION_FORMAT, p);
3767 /* Don't need to pull wierd characters out of global names. */
3768 if (p != first_global_object_name)
3770 for (p = buf+11; *p; p++)
3771 if (! ((*p >= '0' && *p <= '9')
3772 #if 0 /* we always want labels, which are valid C++ identifiers (+ `$') */
3773 #ifndef ASM_IDENTIFY_GCC /* this is required if `.' is invalid -- k. raeburn */
3777 #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
3780 #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */
3783 || (*p >= 'A' && *p <= 'Z')
3784 || (*p >= 'a' && *p <= 'z')))
3788 buf[FILE_FUNCTION_PREFIX_LEN] = kind;
3790 return get_identifier (buf);