1 /* Language-independent node constructors for parse phase of GNU compiler.
2 Copyright (C) 1987, 88, 92, 93, 94, 1995 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. */
48 #define obstack_chunk_alloc xmalloc
49 #define obstack_chunk_free free
51 /* Tree nodes of permanent duration are allocated in this obstack.
52 They are the identifier nodes, and everything outside of
53 the bodies and parameters of function definitions. */
55 struct obstack permanent_obstack;
57 /* The initial RTL, and all ..._TYPE nodes, in a function
58 are allocated in this obstack. Usually they are freed at the
59 end of the function, but if the function is inline they are saved.
60 For top-level functions, this is maybepermanent_obstack.
61 Separate obstacks are made for nested functions. */
63 struct obstack *function_maybepermanent_obstack;
65 /* This is the function_maybepermanent_obstack for top-level functions. */
67 struct obstack maybepermanent_obstack;
69 /* The contents of the current function definition are allocated
70 in this obstack, and all are freed at the end of the function.
71 For top-level functions, this is temporary_obstack.
72 Separate obstacks are made for nested functions. */
74 struct obstack *function_obstack;
76 /* This is used for reading initializers of global variables. */
78 struct obstack temporary_obstack;
80 /* The tree nodes of an expression are allocated
81 in this obstack, and all are freed at the end of the expression. */
83 struct obstack momentary_obstack;
85 /* The tree nodes of a declarator are allocated
86 in this obstack, and all are freed when the declarator
89 static struct obstack temp_decl_obstack;
91 /* This points at either permanent_obstack
92 or the current function_maybepermanent_obstack. */
94 struct obstack *saveable_obstack;
96 /* This is same as saveable_obstack during parse and expansion phase;
97 it points to the current function's obstack during optimization.
98 This is the obstack to be used for creating rtl objects. */
100 struct obstack *rtl_obstack;
102 /* This points at either permanent_obstack or the current function_obstack. */
104 struct obstack *current_obstack;
106 /* This points at either permanent_obstack or the current function_obstack
107 or momentary_obstack. */
109 struct obstack *expression_obstack;
111 /* Stack of obstack selections for push_obstacks and pop_obstacks. */
115 struct obstack_stack *next;
116 struct obstack *current;
117 struct obstack *saveable;
118 struct obstack *expression;
122 struct obstack_stack *obstack_stack;
124 /* Obstack for allocating struct obstack_stack entries. */
126 static struct obstack obstack_stack_obstack;
128 /* Addresses of first objects in some obstacks.
129 This is for freeing their entire contents. */
130 char *maybepermanent_firstobj;
131 char *temporary_firstobj;
132 char *momentary_firstobj;
133 char *temp_decl_firstobj;
135 /* This is used to preserve objects (mainly array initializers) that need to
136 live until the end of the current function, but no further. */
137 char *momentary_function_firstobj;
139 /* Nonzero means all ..._TYPE nodes should be allocated permanently. */
141 int all_types_permanent;
143 /* Stack of places to restore the momentary obstack back to. */
145 struct momentary_level
147 /* Pointer back to previous such level. */
148 struct momentary_level *prev;
149 /* First object allocated within this level. */
151 /* Value of expression_obstack saved at entry to this level. */
152 struct obstack *obstack;
155 struct momentary_level *momentary_stack;
157 /* Table indexed by tree code giving a string containing a character
158 classifying the tree code. Possibilities are
159 t, d, s, c, r, <, 1, 2 and e. See tree.def for details. */
161 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
163 char *standard_tree_code_type[] = {
168 /* Table indexed by tree code giving number of expression
169 operands beyond the fixed part of the node structure.
170 Not used for types or decls. */
172 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
174 int standard_tree_code_length[] = {
179 /* Names of tree components.
180 Used for printing out the tree and error messages. */
181 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
183 char *standard_tree_code_name[] = {
188 /* Table indexed by tree code giving a string containing a character
189 classifying the tree code. Possibilities are
190 t, d, s, c, r, e, <, 1 and 2. See tree.def for details. */
192 char **tree_code_type;
194 /* Table indexed by tree code giving number of expression
195 operands beyond the fixed part of the node structure.
196 Not used for types or decls. */
198 int *tree_code_length;
200 /* Table indexed by tree code giving name of tree code, as a string. */
202 char **tree_code_name;
204 /* Statistics-gathering stuff. */
225 int tree_node_counts[(int)all_kinds];
226 int tree_node_sizes[(int)all_kinds];
227 int id_string_size = 0;
229 char *tree_node_kind_names[] = {
247 /* Hash table for uniquizing IDENTIFIER_NODEs by name. */
249 #define MAX_HASH_TABLE 1009
250 static tree hash_table[MAX_HASH_TABLE]; /* id hash buckets */
252 /* 0 while creating built-in identifiers. */
253 static int do_identifier_warnings;
255 /* Unique id for next decl created. */
256 static int next_decl_uid;
257 /* Unique id for next type created. */
258 static int next_type_uid = 1;
260 /* Here is how primitive or already-canonicalized types' hash
262 #define TYPE_HASH(TYPE) ((HOST_WIDE_INT) (TYPE) & 0777777)
264 extern char *mode_name[];
266 void gcc_obstack_init ();
268 /* Init the principal obstacks. */
273 gcc_obstack_init (&obstack_stack_obstack);
274 gcc_obstack_init (&permanent_obstack);
276 gcc_obstack_init (&temporary_obstack);
277 temporary_firstobj = (char *) obstack_alloc (&temporary_obstack, 0);
278 gcc_obstack_init (&momentary_obstack);
279 momentary_firstobj = (char *) obstack_alloc (&momentary_obstack, 0);
280 momentary_function_firstobj = momentary_firstobj;
281 gcc_obstack_init (&maybepermanent_obstack);
282 maybepermanent_firstobj
283 = (char *) obstack_alloc (&maybepermanent_obstack, 0);
284 gcc_obstack_init (&temp_decl_obstack);
285 temp_decl_firstobj = (char *) obstack_alloc (&temp_decl_obstack, 0);
287 function_obstack = &temporary_obstack;
288 function_maybepermanent_obstack = &maybepermanent_obstack;
289 current_obstack = &permanent_obstack;
290 expression_obstack = &permanent_obstack;
291 rtl_obstack = saveable_obstack = &permanent_obstack;
293 /* Init the hash table of identifiers. */
294 bzero ((char *) hash_table, sizeof hash_table);
298 gcc_obstack_init (obstack)
299 struct obstack *obstack;
301 /* Let particular systems override the size of a chunk. */
302 #ifndef OBSTACK_CHUNK_SIZE
303 #define OBSTACK_CHUNK_SIZE 0
305 /* Let them override the alloc and free routines too. */
306 #ifndef OBSTACK_CHUNK_ALLOC
307 #define OBSTACK_CHUNK_ALLOC xmalloc
309 #ifndef OBSTACK_CHUNK_FREE
310 #define OBSTACK_CHUNK_FREE free
312 _obstack_begin (obstack, OBSTACK_CHUNK_SIZE, 0,
313 (void *(*) ()) OBSTACK_CHUNK_ALLOC,
314 (void (*) ()) OBSTACK_CHUNK_FREE);
317 /* Save all variables describing the current status into the structure *P.
318 This is used before starting a nested function. */
321 save_tree_status (p, toplevel)
325 p->all_types_permanent = all_types_permanent;
326 p->momentary_stack = momentary_stack;
327 p->maybepermanent_firstobj = maybepermanent_firstobj;
328 p->momentary_firstobj = momentary_firstobj;
329 p->momentary_function_firstobj = momentary_function_firstobj;
330 p->function_obstack = function_obstack;
331 p->function_maybepermanent_obstack = function_maybepermanent_obstack;
332 p->current_obstack = current_obstack;
333 p->expression_obstack = expression_obstack;
334 p->saveable_obstack = saveable_obstack;
335 p->rtl_obstack = rtl_obstack;
339 /* Objects that need to be saved in this function can be in the nonsaved
340 obstack of the enclosing function since they can't possibly be needed
341 once it has returned. */
342 function_maybepermanent_obstack = function_obstack;
343 maybepermanent_firstobj
344 = (char *) obstack_finish (function_maybepermanent_obstack);
347 function_obstack = (struct obstack *) xmalloc (sizeof (struct obstack));
348 gcc_obstack_init (function_obstack);
350 current_obstack = &permanent_obstack;
351 expression_obstack = &permanent_obstack;
352 rtl_obstack = saveable_obstack = &permanent_obstack;
354 momentary_firstobj = (char *) obstack_finish (&momentary_obstack);
355 momentary_function_firstobj = momentary_firstobj;
358 /* Restore all variables describing the current status from the structure *P.
359 This is used after a nested function. */
362 restore_tree_status (p, toplevel)
366 all_types_permanent = p->all_types_permanent;
367 momentary_stack = p->momentary_stack;
369 obstack_free (&momentary_obstack, momentary_function_firstobj);
373 /* Free saveable storage used by the function just compiled and not
376 CAUTION: This is in function_obstack of the containing function.
377 So we must be sure that we never allocate from that obstack during
378 the compilation of a nested function if we expect it to survive
379 past the nested function's end. */
380 obstack_free (function_maybepermanent_obstack, maybepermanent_firstobj);
383 obstack_free (function_obstack, 0);
384 free (function_obstack);
386 momentary_firstobj = p->momentary_firstobj;
387 momentary_function_firstobj = p->momentary_function_firstobj;
388 maybepermanent_firstobj = p->maybepermanent_firstobj;
389 function_obstack = p->function_obstack;
390 function_maybepermanent_obstack = p->function_maybepermanent_obstack;
391 current_obstack = p->current_obstack;
392 expression_obstack = p->expression_obstack;
393 saveable_obstack = p->saveable_obstack;
394 rtl_obstack = p->rtl_obstack;
397 /* Start allocating on the temporary (per function) obstack.
398 This is done in start_function before parsing the function body,
399 and before each initialization at top level, and to go back
400 to temporary allocation after doing permanent_allocation. */
403 temporary_allocation ()
405 /* Note that function_obstack at top level points to temporary_obstack.
406 But within a nested function context, it is a separate obstack. */
407 current_obstack = function_obstack;
408 expression_obstack = function_obstack;
409 rtl_obstack = saveable_obstack = function_maybepermanent_obstack;
413 /* Start allocating on the permanent obstack but don't
414 free the temporary data. After calling this, call
415 `permanent_allocation' to fully resume permanent allocation status. */
418 end_temporary_allocation ()
420 current_obstack = &permanent_obstack;
421 expression_obstack = &permanent_obstack;
422 rtl_obstack = saveable_obstack = &permanent_obstack;
425 /* Resume allocating on the temporary obstack, undoing
426 effects of `end_temporary_allocation'. */
429 resume_temporary_allocation ()
431 current_obstack = function_obstack;
432 expression_obstack = function_obstack;
433 rtl_obstack = saveable_obstack = function_maybepermanent_obstack;
436 /* While doing temporary allocation, switch to allocating in such a
437 way as to save all nodes if the function is inlined. Call
438 resume_temporary_allocation to go back to ordinary temporary
442 saveable_allocation ()
444 /* Note that function_obstack at top level points to temporary_obstack.
445 But within a nested function context, it is a separate obstack. */
446 expression_obstack = current_obstack = saveable_obstack;
449 /* Switch to current obstack CURRENT and maybepermanent obstack SAVEABLE,
450 recording the previously current obstacks on a stack.
451 This does not free any storage in any obstack. */
454 push_obstacks (current, saveable)
455 struct obstack *current, *saveable;
457 struct obstack_stack *p
458 = (struct obstack_stack *) obstack_alloc (&obstack_stack_obstack,
459 (sizeof (struct obstack_stack)));
461 p->current = current_obstack;
462 p->saveable = saveable_obstack;
463 p->expression = expression_obstack;
464 p->rtl = rtl_obstack;
465 p->next = obstack_stack;
468 current_obstack = current;
469 expression_obstack = current;
470 rtl_obstack = saveable_obstack = saveable;
473 /* Save the current set of obstacks, but don't change them. */
476 push_obstacks_nochange ()
478 struct obstack_stack *p
479 = (struct obstack_stack *) obstack_alloc (&obstack_stack_obstack,
480 (sizeof (struct obstack_stack)));
482 p->current = current_obstack;
483 p->saveable = saveable_obstack;
484 p->expression = expression_obstack;
485 p->rtl = rtl_obstack;
486 p->next = obstack_stack;
490 /* Pop the obstack selection stack. */
495 struct obstack_stack *p = obstack_stack;
496 obstack_stack = p->next;
498 current_obstack = p->current;
499 saveable_obstack = p->saveable;
500 expression_obstack = p->expression;
501 rtl_obstack = p->rtl;
503 obstack_free (&obstack_stack_obstack, p);
506 /* Nonzero if temporary allocation is currently in effect.
507 Zero if currently doing permanent allocation. */
510 allocation_temporary_p ()
512 return current_obstack != &permanent_obstack;
515 /* Go back to allocating on the permanent obstack
516 and free everything in the temporary obstack.
518 FUNCTION_END is true only if we have just finished compiling a function.
519 In that case, we also free preserved initial values on the momentary
523 permanent_allocation (function_end)
526 /* Free up previous temporary obstack data */
527 obstack_free (&temporary_obstack, temporary_firstobj);
530 obstack_free (&momentary_obstack, momentary_function_firstobj);
531 momentary_firstobj = momentary_function_firstobj;
534 obstack_free (&momentary_obstack, momentary_firstobj);
535 obstack_free (function_maybepermanent_obstack, maybepermanent_firstobj);
536 obstack_free (&temp_decl_obstack, temp_decl_firstobj);
538 current_obstack = &permanent_obstack;
539 expression_obstack = &permanent_obstack;
540 rtl_obstack = saveable_obstack = &permanent_obstack;
543 /* Save permanently everything on the maybepermanent_obstack. */
548 maybepermanent_firstobj
549 = (char *) obstack_alloc (function_maybepermanent_obstack, 0);
553 preserve_initializer ()
555 struct momentary_level *tem;
559 = (char *) obstack_alloc (&temporary_obstack, 0);
560 maybepermanent_firstobj
561 = (char *) obstack_alloc (function_maybepermanent_obstack, 0);
563 old_momentary = momentary_firstobj;
565 = (char *) obstack_alloc (&momentary_obstack, 0);
566 if (momentary_firstobj != old_momentary)
567 for (tem = momentary_stack; tem; tem = tem->prev)
568 tem->base = momentary_firstobj;
571 /* Start allocating new rtl in current_obstack.
572 Use resume_temporary_allocation
573 to go back to allocating rtl in saveable_obstack. */
576 rtl_in_current_obstack ()
578 rtl_obstack = current_obstack;
581 /* Start allocating rtl from saveable_obstack. Intended to be used after
582 a call to push_obstacks_nochange. */
585 rtl_in_saveable_obstack ()
587 rtl_obstack = saveable_obstack;
590 /* Allocate SIZE bytes in the current obstack
591 and return a pointer to them.
592 In practice the current obstack is always the temporary one. */
598 return (char *) obstack_alloc (current_obstack, size);
601 /* Free the object PTR in the current obstack
602 as well as everything allocated since PTR.
603 In practice the current obstack is always the temporary one. */
609 obstack_free (current_obstack, ptr);
612 /* Allocate SIZE bytes in the permanent obstack
613 and return a pointer to them. */
619 return (char *) obstack_alloc (&permanent_obstack, size);
622 /* Allocate NELEM items of SIZE bytes in the permanent obstack
623 and return a pointer to them. The storage is cleared before
624 returning the value. */
627 perm_calloc (nelem, size)
631 char *rval = (char *) obstack_alloc (&permanent_obstack, nelem * size);
632 bzero (rval, nelem * size);
636 /* Allocate SIZE bytes in the saveable obstack
637 and return a pointer to them. */
643 return (char *) obstack_alloc (saveable_obstack, size);
646 /* Print out which obstack an object is in. */
649 print_obstack_name (object, file, prefix)
654 struct obstack *obstack = NULL;
655 char *obstack_name = NULL;
658 for (p = outer_function_chain; p; p = p->next)
660 if (_obstack_allocated_p (p->function_obstack, object))
662 obstack = p->function_obstack;
663 obstack_name = "containing function obstack";
665 if (_obstack_allocated_p (p->function_maybepermanent_obstack, object))
667 obstack = p->function_maybepermanent_obstack;
668 obstack_name = "containing function maybepermanent obstack";
672 if (_obstack_allocated_p (&obstack_stack_obstack, object))
674 obstack = &obstack_stack_obstack;
675 obstack_name = "obstack_stack_obstack";
677 else if (_obstack_allocated_p (function_obstack, object))
679 obstack = function_obstack;
680 obstack_name = "function obstack";
682 else if (_obstack_allocated_p (&permanent_obstack, object))
684 obstack = &permanent_obstack;
685 obstack_name = "permanent_obstack";
687 else if (_obstack_allocated_p (&momentary_obstack, object))
689 obstack = &momentary_obstack;
690 obstack_name = "momentary_obstack";
692 else if (_obstack_allocated_p (function_maybepermanent_obstack, object))
694 obstack = function_maybepermanent_obstack;
695 obstack_name = "function maybepermanent obstack";
697 else if (_obstack_allocated_p (&temp_decl_obstack, object))
699 obstack = &temp_decl_obstack;
700 obstack_name = "temp_decl_obstack";
703 /* Check to see if the object is in the free area of the obstack. */
706 if (object >= obstack->next_free
707 && object < obstack->chunk_limit)
708 fprintf (file, "%s in free portion of obstack %s",
709 prefix, obstack_name);
711 fprintf (file, "%s allocated from %s", prefix, obstack_name);
714 fprintf (file, "%s not allocated from any obstack", prefix);
718 debug_obstack (object)
721 print_obstack_name (object, stderr, "object");
722 fprintf (stderr, ".\n");
725 /* Return 1 if OBJ is in the permanent obstack.
726 This is slow, and should be used only for debugging.
727 Use TREE_PERMANENT for other purposes. */
730 object_permanent_p (obj)
733 return _obstack_allocated_p (&permanent_obstack, obj);
736 /* Start a level of momentary allocation.
737 In C, each compound statement has its own level
738 and that level is freed at the end of each statement.
739 All expression nodes are allocated in the momentary allocation level. */
744 struct momentary_level *tem
745 = (struct momentary_level *) obstack_alloc (&momentary_obstack,
746 sizeof (struct momentary_level));
747 tem->prev = momentary_stack;
748 tem->base = (char *) obstack_base (&momentary_obstack);
749 tem->obstack = expression_obstack;
750 momentary_stack = tem;
751 expression_obstack = &momentary_obstack;
754 /* Set things up so the next clear_momentary will only clear memory
755 past our present position in momentary_obstack. */
758 preserve_momentary ()
760 momentary_stack->base = (char *) obstack_base (&momentary_obstack);
763 /* Free all the storage in the current momentary-allocation level.
764 In C, this happens at the end of each statement. */
769 obstack_free (&momentary_obstack, momentary_stack->base);
772 /* Discard a level of momentary allocation.
773 In C, this happens at the end of each compound statement.
774 Restore the status of expression node allocation
775 that was in effect before this level was created. */
780 struct momentary_level *tem = momentary_stack;
781 momentary_stack = tem->prev;
782 expression_obstack = tem->obstack;
783 /* We can't free TEM from the momentary_obstack, because there might
784 be objects above it which have been saved. We can free back to the
785 stack of the level we are popping off though. */
786 obstack_free (&momentary_obstack, tem->base);
789 /* Pop back to the previous level of momentary allocation,
790 but don't free any momentary data just yet. */
793 pop_momentary_nofree ()
795 struct momentary_level *tem = momentary_stack;
796 momentary_stack = tem->prev;
797 expression_obstack = tem->obstack;
800 /* Call when starting to parse a declaration:
801 make expressions in the declaration last the length of the function.
802 Returns an argument that should be passed to resume_momentary later. */
807 register int tem = expression_obstack == &momentary_obstack;
808 expression_obstack = saveable_obstack;
812 /* Call when finished parsing a declaration:
813 restore the treatment of node-allocation that was
814 in effect before the suspension.
815 YES should be the value previously returned by suspend_momentary. */
818 resume_momentary (yes)
822 expression_obstack = &momentary_obstack;
825 /* Init the tables indexed by tree code.
826 Note that languages can add to these tables to define their own codes. */
831 tree_code_type = (char **) xmalloc (sizeof (standard_tree_code_type));
832 tree_code_length = (int *) xmalloc (sizeof (standard_tree_code_length));
833 tree_code_name = (char **) xmalloc (sizeof (standard_tree_code_name));
834 bcopy ((char *) standard_tree_code_type, (char *) tree_code_type,
835 sizeof (standard_tree_code_type));
836 bcopy ((char *) standard_tree_code_length, (char *) tree_code_length,
837 sizeof (standard_tree_code_length));
838 bcopy ((char *) standard_tree_code_name, (char *) tree_code_name,
839 sizeof (standard_tree_code_name));
842 /* Return a newly allocated node of code CODE.
843 Initialize the node's unique id and its TREE_PERMANENT flag.
844 For decl and type nodes, some other fields are initialized.
845 The rest of the node is initialized to zero.
847 Achoo! I got a code in the node. */
854 register int type = TREE_CODE_CLASS (code);
856 register struct obstack *obstack = current_obstack;
858 register tree_node_kind kind;
862 case 'd': /* A decl node */
863 #ifdef GATHER_STATISTICS
866 length = sizeof (struct tree_decl);
867 /* All decls in an inline function need to be saved. */
868 if (obstack != &permanent_obstack)
869 obstack = saveable_obstack;
871 /* PARM_DECLs go on the context of the parent. If this is a nested
872 function, then we must allocate the PARM_DECL on the parent's
873 obstack, so that they will live to the end of the parent's
874 closing brace. This is neccesary in case we try to inline the
875 function into its parent.
877 PARM_DECLs of top-level functions do not have this problem. However,
878 we allocate them where we put the FUNCTION_DECL for languauges such as
879 Ada that need to consult some flags in the PARM_DECLs of the function
882 See comment in restore_tree_status for why we can't put this
883 in function_obstack. */
884 if (code == PARM_DECL && obstack != &permanent_obstack)
887 if (current_function_decl)
888 context = decl_function_context (current_function_decl);
892 = find_function_data (context)->function_maybepermanent_obstack;
896 case 't': /* a type node */
897 #ifdef GATHER_STATISTICS
900 length = sizeof (struct tree_type);
901 /* All data types are put where we can preserve them if nec. */
902 if (obstack != &permanent_obstack)
903 obstack = all_types_permanent ? &permanent_obstack : saveable_obstack;
906 case 'b': /* a lexical block */
907 #ifdef GATHER_STATISTICS
910 length = sizeof (struct tree_block);
911 /* All BLOCK nodes are put where we can preserve them if nec. */
912 if (obstack != &permanent_obstack)
913 obstack = saveable_obstack;
916 case 's': /* an expression with side effects */
917 #ifdef GATHER_STATISTICS
921 case 'r': /* a reference */
922 #ifdef GATHER_STATISTICS
926 case 'e': /* an expression */
927 case '<': /* a comparison expression */
928 case '1': /* a unary arithmetic expression */
929 case '2': /* a binary arithmetic expression */
930 #ifdef GATHER_STATISTICS
934 obstack = expression_obstack;
935 /* All BIND_EXPR nodes are put where we can preserve them if nec. */
936 if (code == BIND_EXPR && obstack != &permanent_obstack)
937 obstack = saveable_obstack;
938 length = sizeof (struct tree_exp)
939 + (tree_code_length[(int) code] - 1) * sizeof (char *);
942 case 'c': /* a constant */
943 #ifdef GATHER_STATISTICS
946 obstack = expression_obstack;
948 /* We can't use tree_code_length for INTEGER_CST, since the number of
949 words is machine-dependent due to varying length of HOST_WIDE_INT,
950 which might be wider than a pointer (e.g., long long). Similarly
951 for REAL_CST, since the number of words is machine-dependent due
952 to varying size and alignment of `double'. */
954 if (code == INTEGER_CST)
955 length = sizeof (struct tree_int_cst);
956 else if (code == REAL_CST)
957 length = sizeof (struct tree_real_cst);
959 length = sizeof (struct tree_common)
960 + tree_code_length[(int) code] * sizeof (char *);
963 case 'x': /* something random, like an identifier. */
964 #ifdef GATHER_STATISTICS
965 if (code == IDENTIFIER_NODE)
967 else if (code == OP_IDENTIFIER)
969 else if (code == TREE_VEC)
974 length = sizeof (struct tree_common)
975 + tree_code_length[(int) code] * sizeof (char *);
976 /* Identifier nodes are always permanent since they are
977 unique in a compiler run. */
978 if (code == IDENTIFIER_NODE) obstack = &permanent_obstack;
985 t = (tree) obstack_alloc (obstack, length);
987 #ifdef GATHER_STATISTICS
988 tree_node_counts[(int)kind]++;
989 tree_node_sizes[(int)kind] += length;
992 /* Clear a word at a time. */
993 for (i = (length / sizeof (int)) - 1; i >= 0; i--)
995 /* Clear any extra bytes. */
996 for (i = length / sizeof (int) * sizeof (int); i < length; i++)
999 TREE_SET_CODE (t, code);
1000 if (obstack == &permanent_obstack)
1001 TREE_PERMANENT (t) = 1;
1006 TREE_SIDE_EFFECTS (t) = 1;
1007 TREE_TYPE (t) = void_type_node;
1011 if (code != FUNCTION_DECL)
1013 DECL_IN_SYSTEM_HEADER (t)
1014 = in_system_header && (obstack == &permanent_obstack);
1015 DECL_SOURCE_LINE (t) = lineno;
1016 DECL_SOURCE_FILE (t) = (input_filename) ? input_filename : "<built-in>";
1017 DECL_UID (t) = next_decl_uid++;
1021 TYPE_UID (t) = next_type_uid++;
1023 TYPE_MAIN_VARIANT (t) = t;
1024 TYPE_OBSTACK (t) = obstack;
1025 TYPE_ATTRIBUTES (t) = NULL_TREE;
1026 #ifdef SET_DEFAULT_TYPE_ATTRIBUTES
1027 SET_DEFAULT_TYPE_ATTRIBUTES (t);
1032 TREE_CONSTANT (t) = 1;
1039 /* Return a new node with the same contents as NODE
1040 except that its TREE_CHAIN is zero and it has a fresh uid. */
1047 register enum tree_code code = TREE_CODE (node);
1048 register int length;
1051 switch (TREE_CODE_CLASS (code))
1053 case 'd': /* A decl node */
1054 length = sizeof (struct tree_decl);
1057 case 't': /* a type node */
1058 length = sizeof (struct tree_type);
1061 case 'b': /* a lexical block node */
1062 length = sizeof (struct tree_block);
1065 case 'r': /* a reference */
1066 case 'e': /* an expression */
1067 case 's': /* an expression with side effects */
1068 case '<': /* a comparison expression */
1069 case '1': /* a unary arithmetic expression */
1070 case '2': /* a binary arithmetic expression */
1071 length = sizeof (struct tree_exp)
1072 + (tree_code_length[(int) code] - 1) * sizeof (char *);
1075 case 'c': /* a constant */
1076 /* We can't use tree_code_length for INTEGER_CST, since the number of
1077 words is machine-dependent due to varying length of HOST_WIDE_INT,
1078 which might be wider than a pointer (e.g., long long). Similarly
1079 for REAL_CST, since the number of words is machine-dependent due
1080 to varying size and alignment of `double'. */
1081 if (code == INTEGER_CST)
1083 length = sizeof (struct tree_int_cst);
1086 else if (code == REAL_CST)
1088 length = sizeof (struct tree_real_cst);
1092 case 'x': /* something random, like an identifier. */
1093 length = sizeof (struct tree_common)
1094 + tree_code_length[(int) code] * sizeof (char *);
1095 if (code == TREE_VEC)
1096 length += (TREE_VEC_LENGTH (node) - 1) * sizeof (char *);
1099 t = (tree) obstack_alloc (current_obstack, length);
1101 for (i = (length / sizeof (int)) - 1; i >= 0; i--)
1102 ((int *) t)[i] = ((int *) node)[i];
1103 /* Clear any extra bytes. */
1104 for (i = length / sizeof (int) * sizeof (int); i < length; i++)
1105 ((char *) t)[i] = ((char *) node)[i];
1109 if (TREE_CODE_CLASS (code) == 'd')
1110 DECL_UID (t) = next_decl_uid++;
1111 else if (TREE_CODE_CLASS (code) == 't')
1113 TYPE_UID (t) = next_type_uid++;
1114 TYPE_OBSTACK (t) = current_obstack;
1117 TREE_PERMANENT (t) = (current_obstack == &permanent_obstack);
1122 /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
1123 For example, this can copy a list made of TREE_LIST nodes. */
1130 register tree prev, next;
1135 head = prev = copy_node (list);
1136 next = TREE_CHAIN (list);
1139 TREE_CHAIN (prev) = copy_node (next);
1140 prev = TREE_CHAIN (prev);
1141 next = TREE_CHAIN (next);
1148 /* Return an IDENTIFIER_NODE whose name is TEXT (a null-terminated string).
1149 If an identifier with that name has previously been referred to,
1150 the same node is returned this time. */
1153 get_identifier (text)
1154 register char *text;
1159 register int len, hash_len;
1161 /* Compute length of text in len. */
1162 for (len = 0; text[len]; len++);
1164 /* Decide how much of that length to hash on */
1166 if (warn_id_clash && len > id_clash_len)
1167 hash_len = id_clash_len;
1169 /* Compute hash code */
1170 hi = hash_len * 613 + (unsigned)text[0];
1171 for (i = 1; i < hash_len; i += 2)
1172 hi = ((hi * 613) + (unsigned)(text[i]));
1174 hi &= (1 << HASHBITS) - 1;
1175 hi %= MAX_HASH_TABLE;
1177 /* Search table for identifier */
1178 for (idp = hash_table[hi]; idp; idp = TREE_CHAIN (idp))
1179 if (IDENTIFIER_LENGTH (idp) == len
1180 && IDENTIFIER_POINTER (idp)[0] == text[0]
1181 && !bcmp (IDENTIFIER_POINTER (idp), text, len))
1182 return idp; /* <-- return if found */
1184 /* Not found; optionally warn about a similar identifier */
1185 if (warn_id_clash && do_identifier_warnings && len >= id_clash_len)
1186 for (idp = hash_table[hi]; idp; idp = TREE_CHAIN (idp))
1187 if (!strncmp (IDENTIFIER_POINTER (idp), text, id_clash_len))
1189 warning ("`%s' and `%s' identical in first %d characters",
1190 IDENTIFIER_POINTER (idp), text, id_clash_len);
1194 if (tree_code_length[(int) IDENTIFIER_NODE] < 0)
1195 abort (); /* set_identifier_size hasn't been called. */
1197 /* Not found, create one, add to chain */
1198 idp = make_node (IDENTIFIER_NODE);
1199 IDENTIFIER_LENGTH (idp) = len;
1200 #ifdef GATHER_STATISTICS
1201 id_string_size += len;
1204 IDENTIFIER_POINTER (idp) = obstack_copy0 (&permanent_obstack, text, len);
1206 TREE_CHAIN (idp) = hash_table[hi];
1207 hash_table[hi] = idp;
1208 return idp; /* <-- return if created */
1211 /* Enable warnings on similar identifiers (if requested).
1212 Done after the built-in identifiers are created. */
1215 start_identifier_warnings ()
1217 do_identifier_warnings = 1;
1220 /* Record the size of an identifier node for the language in use.
1221 SIZE is the total size in bytes.
1222 This is called by the language-specific files. This must be
1223 called before allocating any identifiers. */
1226 set_identifier_size (size)
1229 tree_code_length[(int) IDENTIFIER_NODE]
1230 = (size - sizeof (struct tree_common)) / sizeof (tree);
1233 /* Return a newly constructed INTEGER_CST node whose constant value
1234 is specified by the two ints LOW and HI.
1235 The TREE_TYPE is set to `int'.
1237 This function should be used via the `build_int_2' macro. */
1240 build_int_2_wide (low, hi)
1241 HOST_WIDE_INT low, hi;
1243 register tree t = make_node (INTEGER_CST);
1244 TREE_INT_CST_LOW (t) = low;
1245 TREE_INT_CST_HIGH (t) = hi;
1246 TREE_TYPE (t) = integer_type_node;
1250 /* Return a new REAL_CST node whose type is TYPE and value is D. */
1253 build_real (type, d)
1260 /* Check for valid float value for this type on this target machine;
1261 if not, can print error message and store a valid value in D. */
1262 #ifdef CHECK_FLOAT_VALUE
1263 CHECK_FLOAT_VALUE (TYPE_MODE (type), d, overflow);
1266 v = make_node (REAL_CST);
1267 TREE_TYPE (v) = type;
1268 TREE_REAL_CST (v) = d;
1269 TREE_OVERFLOW (v) = TREE_CONSTANT_OVERFLOW (v) = overflow;
1273 /* Return a new REAL_CST node whose type is TYPE
1274 and whose value is the integer value of the INTEGER_CST node I. */
1276 #if !defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC)
1279 real_value_from_int_cst (i)
1284 /* Some 386 compilers mishandle unsigned int to float conversions,
1285 so introduce a temporary variable E to avoid those bugs. */
1287 #ifdef REAL_ARITHMETIC
1288 if (! TREE_UNSIGNED (TREE_TYPE (i)))
1289 REAL_VALUE_FROM_INT (d, TREE_INT_CST_LOW (i), TREE_INT_CST_HIGH (i));
1291 REAL_VALUE_FROM_UNSIGNED_INT (d, TREE_INT_CST_LOW (i), TREE_INT_CST_HIGH (i));
1292 #else /* not REAL_ARITHMETIC */
1293 if (TREE_INT_CST_HIGH (i) < 0 && ! TREE_UNSIGNED (TREE_TYPE (i)))
1295 d = (double) (~ TREE_INT_CST_HIGH (i));
1296 e = ((double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2))
1297 * (double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2)));
1299 e = (double) (unsigned HOST_WIDE_INT) (~ TREE_INT_CST_LOW (i));
1305 d = (double) (unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (i);
1306 e = ((double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2))
1307 * (double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2)));
1309 e = (double) (unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (i);
1312 #endif /* not REAL_ARITHMETIC */
1316 /* This function can't be implemented if we can't do arithmetic
1317 on the float representation. */
1320 build_real_from_int_cst (type, i)
1325 int overflow = TREE_OVERFLOW (i);
1327 jmp_buf float_error;
1329 v = make_node (REAL_CST);
1330 TREE_TYPE (v) = type;
1332 if (setjmp (float_error))
1339 set_float_handler (float_error);
1341 d = REAL_VALUE_TRUNCATE (TYPE_MODE (type), real_value_from_int_cst (i));
1343 /* Check for valid float value for this type on this target machine. */
1346 set_float_handler (NULL_PTR);
1348 #ifdef CHECK_FLOAT_VALUE
1349 CHECK_FLOAT_VALUE (TYPE_MODE (type), d, overflow);
1352 TREE_REAL_CST (v) = d;
1353 TREE_OVERFLOW (v) = TREE_CONSTANT_OVERFLOW (v) = overflow;
1357 #endif /* not REAL_IS_NOT_DOUBLE, or REAL_ARITHMETIC */
1359 /* Return a newly constructed STRING_CST node whose value is
1360 the LEN characters at STR.
1361 The TREE_TYPE is not initialized. */
1364 build_string (len, str)
1368 /* Put the string in saveable_obstack since it will be placed in the RTL
1369 for an "asm" statement and will also be kept around a while if
1370 deferring constant output in varasm.c. */
1372 register tree s = make_node (STRING_CST);
1373 TREE_STRING_LENGTH (s) = len;
1374 TREE_STRING_POINTER (s) = obstack_copy0 (saveable_obstack, str, len);
1378 /* Return a newly constructed COMPLEX_CST node whose value is
1379 specified by the real and imaginary parts REAL and IMAG.
1380 Both REAL and IMAG should be constant nodes.
1381 The TREE_TYPE is not initialized. */
1384 build_complex (real, imag)
1387 register tree t = make_node (COMPLEX_CST);
1389 TREE_REALPART (t) = real;
1390 TREE_IMAGPART (t) = imag;
1391 TREE_TYPE (t) = build_complex_type (TREE_TYPE (real));
1392 TREE_OVERFLOW (t) = TREE_OVERFLOW (real) | TREE_OVERFLOW (imag);
1393 TREE_CONSTANT_OVERFLOW (t)
1394 = TREE_CONSTANT_OVERFLOW (real) | TREE_CONSTANT_OVERFLOW (imag);
1398 /* Build a newly constructed TREE_VEC node of length LEN. */
1404 register int length = (len-1) * sizeof (tree) + sizeof (struct tree_vec);
1405 register struct obstack *obstack = current_obstack;
1408 #ifdef GATHER_STATISTICS
1409 tree_node_counts[(int)vec_kind]++;
1410 tree_node_sizes[(int)vec_kind] += length;
1413 t = (tree) obstack_alloc (obstack, length);
1415 for (i = (length / sizeof (int)) - 1; i >= 0; i--)
1418 TREE_SET_CODE (t, TREE_VEC);
1419 TREE_VEC_LENGTH (t) = len;
1420 if (obstack == &permanent_obstack)
1421 TREE_PERMANENT (t) = 1;
1426 /* Return 1 if EXPR is the integer constant zero or a complex constant
1430 integer_zerop (expr)
1435 return ((TREE_CODE (expr) == INTEGER_CST
1436 && TREE_INT_CST_LOW (expr) == 0
1437 && TREE_INT_CST_HIGH (expr) == 0)
1438 || (TREE_CODE (expr) == COMPLEX_CST
1439 && integer_zerop (TREE_REALPART (expr))
1440 && integer_zerop (TREE_IMAGPART (expr))));
1443 /* Return 1 if EXPR is the integer constant one or the corresponding
1444 complex constant. */
1452 return ((TREE_CODE (expr) == INTEGER_CST
1453 && TREE_INT_CST_LOW (expr) == 1
1454 && TREE_INT_CST_HIGH (expr) == 0)
1455 || (TREE_CODE (expr) == COMPLEX_CST
1456 && integer_onep (TREE_REALPART (expr))
1457 && integer_zerop (TREE_IMAGPART (expr))));
1460 /* Return 1 if EXPR is an integer containing all 1's in as much precision as
1461 it contains. Likewise for the corresponding complex constant. */
1464 integer_all_onesp (expr)
1472 if (TREE_CODE (expr) == COMPLEX_CST
1473 && integer_all_onesp (TREE_REALPART (expr))
1474 && integer_zerop (TREE_IMAGPART (expr)))
1477 else if (TREE_CODE (expr) != INTEGER_CST)
1480 uns = TREE_UNSIGNED (TREE_TYPE (expr));
1482 return TREE_INT_CST_LOW (expr) == -1 && TREE_INT_CST_HIGH (expr) == -1;
1484 prec = TYPE_PRECISION (TREE_TYPE (expr));
1485 if (prec >= HOST_BITS_PER_WIDE_INT)
1487 int high_value, shift_amount;
1489 shift_amount = prec - HOST_BITS_PER_WIDE_INT;
1491 if (shift_amount > HOST_BITS_PER_WIDE_INT)
1492 /* Can not handle precisions greater than twice the host int size. */
1494 else if (shift_amount == HOST_BITS_PER_WIDE_INT)
1495 /* Shifting by the host word size is undefined according to the ANSI
1496 standard, so we must handle this as a special case. */
1499 high_value = ((HOST_WIDE_INT) 1 << shift_amount) - 1;
1501 return TREE_INT_CST_LOW (expr) == -1
1502 && TREE_INT_CST_HIGH (expr) == high_value;
1505 return TREE_INT_CST_LOW (expr) == ((HOST_WIDE_INT) 1 << prec) - 1;
1508 /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only
1512 integer_pow2p (expr)
1515 HOST_WIDE_INT high, low;
1519 if (TREE_CODE (expr) == COMPLEX_CST
1520 && integer_pow2p (TREE_REALPART (expr))
1521 && integer_zerop (TREE_IMAGPART (expr)))
1524 if (TREE_CODE (expr) != INTEGER_CST)
1527 high = TREE_INT_CST_HIGH (expr);
1528 low = TREE_INT_CST_LOW (expr);
1530 if (high == 0 && low == 0)
1533 return ((high == 0 && (low & (low - 1)) == 0)
1534 || (low == 0 && (high & (high - 1)) == 0));
1537 /* Return 1 if EXPR is the real constant zero. */
1545 return ((TREE_CODE (expr) == REAL_CST
1546 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst0))
1547 || (TREE_CODE (expr) == COMPLEX_CST
1548 && real_zerop (TREE_REALPART (expr))
1549 && real_zerop (TREE_IMAGPART (expr))));
1552 /* Return 1 if EXPR is the real constant one in real or complex form. */
1560 return ((TREE_CODE (expr) == REAL_CST
1561 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst1))
1562 || (TREE_CODE (expr) == COMPLEX_CST
1563 && real_onep (TREE_REALPART (expr))
1564 && real_zerop (TREE_IMAGPART (expr))));
1567 /* Return 1 if EXPR is the real constant two. */
1575 return ((TREE_CODE (expr) == REAL_CST
1576 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst2))
1577 || (TREE_CODE (expr) == COMPLEX_CST
1578 && real_twop (TREE_REALPART (expr))
1579 && real_zerop (TREE_IMAGPART (expr))));
1582 /* Nonzero if EXP is a constant or a cast of a constant. */
1585 really_constant_p (exp)
1588 /* This is not quite the same as STRIP_NOPS. It does more. */
1589 while (TREE_CODE (exp) == NOP_EXPR
1590 || TREE_CODE (exp) == CONVERT_EXPR
1591 || TREE_CODE (exp) == NON_LVALUE_EXPR)
1592 exp = TREE_OPERAND (exp, 0);
1593 return TREE_CONSTANT (exp);
1596 /* Return first list element whose TREE_VALUE is ELEM.
1597 Return 0 if ELEM is not it LIST. */
1600 value_member (elem, list)
1605 if (elem == TREE_VALUE (list))
1607 list = TREE_CHAIN (list);
1612 /* Return first list element whose TREE_PURPOSE is ELEM.
1613 Return 0 if ELEM is not it LIST. */
1616 purpose_member (elem, list)
1621 if (elem == TREE_PURPOSE (list))
1623 list = TREE_CHAIN (list);
1628 /* Return first list element whose BINFO_TYPE is ELEM.
1629 Return 0 if ELEM is not it LIST. */
1632 binfo_member (elem, list)
1637 if (elem == BINFO_TYPE (list))
1639 list = TREE_CHAIN (list);
1644 /* Return nonzero if ELEM is part of the chain CHAIN. */
1647 chain_member (elem, chain)
1654 chain = TREE_CHAIN (chain);
1660 /* Return nonzero if ELEM is equal to TREE_VALUE (CHAIN) for any piece of
1664 chain_member_value (elem, chain)
1669 if (elem == TREE_VALUE (chain))
1671 chain = TREE_CHAIN (chain);
1677 /* Return the length of a chain of nodes chained through TREE_CHAIN.
1678 We expect a null pointer to mark the end of the chain.
1679 This is the Lisp primitive `length'. */
1686 register int len = 0;
1688 for (tail = t; tail; tail = TREE_CHAIN (tail))
1694 /* Concatenate two chains of nodes (chained through TREE_CHAIN)
1695 by modifying the last node in chain 1 to point to chain 2.
1696 This is the Lisp primitive `nconc'. */
1708 for (t1 = op1; TREE_CHAIN (t1); t1 = TREE_CHAIN (t1))
1710 TREE_CHAIN (t1) = op2;
1711 for (t2 = op2; t2; t2 = TREE_CHAIN (t2))
1713 abort (); /* Circularity created. */
1719 /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
1723 register tree chain;
1727 while (next = TREE_CHAIN (chain))
1732 /* Reverse the order of elements in the chain T,
1733 and return the new head of the chain (old last element). */
1739 register tree prev = 0, decl, next;
1740 for (decl = t; decl; decl = next)
1742 next = TREE_CHAIN (decl);
1743 TREE_CHAIN (decl) = prev;
1749 /* Given a chain CHAIN of tree nodes,
1750 construct and return a list of those nodes. */
1756 tree result = NULL_TREE;
1757 tree in_tail = chain;
1758 tree out_tail = NULL_TREE;
1762 tree next = tree_cons (NULL_TREE, in_tail, NULL_TREE);
1764 TREE_CHAIN (out_tail) = next;
1768 in_tail = TREE_CHAIN (in_tail);
1774 /* Return a newly created TREE_LIST node whose
1775 purpose and value fields are PARM and VALUE. */
1778 build_tree_list (parm, value)
1781 register tree t = make_node (TREE_LIST);
1782 TREE_PURPOSE (t) = parm;
1783 TREE_VALUE (t) = value;
1787 /* Similar, but build on the temp_decl_obstack. */
1790 build_decl_list (parm, value)
1794 register struct obstack *ambient_obstack = current_obstack;
1795 current_obstack = &temp_decl_obstack;
1796 node = build_tree_list (parm, value);
1797 current_obstack = ambient_obstack;
1801 /* Return a newly created TREE_LIST node whose
1802 purpose and value fields are PARM and VALUE
1803 and whose TREE_CHAIN is CHAIN. */
1806 tree_cons (purpose, value, chain)
1807 tree purpose, value, chain;
1810 register tree node = make_node (TREE_LIST);
1813 register tree node = (tree) obstack_alloc (current_obstack, sizeof (struct tree_list));
1814 #ifdef GATHER_STATISTICS
1815 tree_node_counts[(int)x_kind]++;
1816 tree_node_sizes[(int)x_kind] += sizeof (struct tree_list);
1819 for (i = (sizeof (struct tree_common) / sizeof (int)) - 1; i >= 0; i--)
1820 ((int *) node)[i] = 0;
1822 TREE_SET_CODE (node, TREE_LIST);
1823 if (current_obstack == &permanent_obstack)
1824 TREE_PERMANENT (node) = 1;
1827 TREE_CHAIN (node) = chain;
1828 TREE_PURPOSE (node) = purpose;
1829 TREE_VALUE (node) = value;
1833 /* Similar, but build on the temp_decl_obstack. */
1836 decl_tree_cons (purpose, value, chain)
1837 tree purpose, value, chain;
1840 register struct obstack *ambient_obstack = current_obstack;
1841 current_obstack = &temp_decl_obstack;
1842 node = tree_cons (purpose, value, chain);
1843 current_obstack = ambient_obstack;
1847 /* Same as `tree_cons' but make a permanent object. */
1850 perm_tree_cons (purpose, value, chain)
1851 tree purpose, value, chain;
1854 register struct obstack *ambient_obstack = current_obstack;
1855 current_obstack = &permanent_obstack;
1857 node = tree_cons (purpose, value, chain);
1858 current_obstack = ambient_obstack;
1862 /* Same as `tree_cons', but make this node temporary, regardless. */
1865 temp_tree_cons (purpose, value, chain)
1866 tree purpose, value, chain;
1869 register struct obstack *ambient_obstack = current_obstack;
1870 current_obstack = &temporary_obstack;
1872 node = tree_cons (purpose, value, chain);
1873 current_obstack = ambient_obstack;
1877 /* Same as `tree_cons', but save this node if the function's RTL is saved. */
1880 saveable_tree_cons (purpose, value, chain)
1881 tree purpose, value, chain;
1884 register struct obstack *ambient_obstack = current_obstack;
1885 current_obstack = saveable_obstack;
1887 node = tree_cons (purpose, value, chain);
1888 current_obstack = ambient_obstack;
1892 /* Return the size nominally occupied by an object of type TYPE
1893 when it resides in memory. The value is measured in units of bytes,
1894 and its data type is that normally used for type sizes
1895 (which is the first type created by make_signed_type or
1896 make_unsigned_type). */
1899 size_in_bytes (type)
1904 if (type == error_mark_node)
1905 return integer_zero_node;
1906 type = TYPE_MAIN_VARIANT (type);
1907 if (TYPE_SIZE (type) == 0)
1909 incomplete_type_error (NULL_TREE, type);
1910 return integer_zero_node;
1912 t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type),
1913 size_int (BITS_PER_UNIT));
1914 if (TREE_CODE (t) == INTEGER_CST)
1915 force_fit_type (t, 0);
1919 /* Return the size of TYPE (in bytes) as an integer,
1920 or return -1 if the size can vary. */
1923 int_size_in_bytes (type)
1927 if (type == error_mark_node)
1929 type = TYPE_MAIN_VARIANT (type);
1930 if (TYPE_SIZE (type) == 0)
1932 if (TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
1934 if (TREE_INT_CST_HIGH (TYPE_SIZE (type)) != 0)
1936 tree t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type),
1937 size_int (BITS_PER_UNIT));
1938 return TREE_INT_CST_LOW (t);
1940 size = TREE_INT_CST_LOW (TYPE_SIZE (type));
1941 return (size + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
1944 /* Return, as a tree node, the number of elements for TYPE (which is an
1945 ARRAY_TYPE) minus one. This counts only elements of the top array. */
1948 array_type_nelts (type)
1951 tree index_type = TYPE_DOMAIN (type);
1953 return (integer_zerop (TYPE_MIN_VALUE (index_type))
1954 ? TYPE_MAX_VALUE (index_type)
1955 : fold (build (MINUS_EXPR, TREE_TYPE (TYPE_MAX_VALUE (index_type)),
1956 TYPE_MAX_VALUE (index_type),
1957 TYPE_MIN_VALUE (index_type))));
1960 /* Return nonzero if arg is static -- a reference to an object in
1961 static storage. This is not the same as the C meaning of `static'. */
1967 switch (TREE_CODE (arg))
1970 /* Nested functions aren't static, since taking their address
1971 involves a trampoline. */
1972 return ! FUNCTION_NEEDS_STATIC_CHAIN (arg);
1974 return TREE_STATIC (arg) || DECL_EXTERNAL (arg);
1977 return TREE_STATIC (arg);
1984 return staticp (TREE_OPERAND (arg, 0));
1987 return TREE_CONSTANT (TREE_OPERAND (arg, 0));
1990 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST
1991 && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST)
1992 return staticp (TREE_OPERAND (arg, 0));
1998 /* Wrap a SAVE_EXPR around EXPR, if appropriate.
1999 Do this to any expression which may be used in more than one place,
2000 but must be evaluated only once.
2002 Normally, expand_expr would reevaluate the expression each time.
2003 Calling save_expr produces something that is evaluated and recorded
2004 the first time expand_expr is called on it. Subsequent calls to
2005 expand_expr just reuse the recorded value.
2007 The call to expand_expr that generates code that actually computes
2008 the value is the first call *at compile time*. Subsequent calls
2009 *at compile time* generate code to use the saved value.
2010 This produces correct result provided that *at run time* control
2011 always flows through the insns made by the first expand_expr
2012 before reaching the other places where the save_expr was evaluated.
2013 You, the caller of save_expr, must make sure this is so.
2015 Constants, and certain read-only nodes, are returned with no
2016 SAVE_EXPR because that is safe. Expressions containing placeholders
2017 are not touched; see tree.def for an explanation of what these
2024 register tree t = fold (expr);
2026 /* We don't care about whether this can be used as an lvalue in this
2028 while (TREE_CODE (t) == NON_LVALUE_EXPR)
2029 t = TREE_OPERAND (t, 0);
2031 /* If the tree evaluates to a constant, then we don't want to hide that
2032 fact (i.e. this allows further folding, and direct checks for constants).
2033 However, a read-only object that has side effects cannot be bypassed.
2034 Since it is no problem to reevaluate literals, we just return the
2037 if (TREE_CONSTANT (t) || (TREE_READONLY (t) && ! TREE_SIDE_EFFECTS (t))
2038 || TREE_CODE (t) == SAVE_EXPR)
2041 /* If T contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
2042 it means that the size or offset of some field of an object depends on
2043 the value within another field.
2045 Note that it must not be the case that T contains both a PLACEHOLDER_EXPR
2046 and some variable since it would then need to be both evaluated once and
2047 evaluated more than once. Front-ends must assure this case cannot
2048 happen by surrounding any such subexpressions in their own SAVE_EXPR
2049 and forcing evaluation at the proper time. */
2050 if (contains_placeholder_p (t))
2053 t = build (SAVE_EXPR, TREE_TYPE (expr), t, current_function_decl, NULL_TREE);
2055 /* This expression might be placed ahead of a jump to ensure that the
2056 value was computed on both sides of the jump. So make sure it isn't
2057 eliminated as dead. */
2058 TREE_SIDE_EFFECTS (t) = 1;
2062 /* Return 1 if EXP contains a PLACEHOLDER_EXPR; i.e., if it represents a size
2063 or offset that depends on a field within a record.
2065 Note that we only allow such expressions within simple arithmetic
2069 contains_placeholder_p (exp)
2072 register enum tree_code code = TREE_CODE (exp);
2075 /* If we have a WITH_RECORD_EXPR, it "cancels" any PLACEHOLDER_EXPR
2076 in it since it is supplying a value for it. */
2077 if (code == WITH_RECORD_EXPR)
2080 switch (TREE_CODE_CLASS (code))
2083 for (inner = TREE_OPERAND (exp, 0);
2084 TREE_CODE_CLASS (TREE_CODE (inner)) == 'r';
2085 inner = TREE_OPERAND (inner, 0))
2087 return TREE_CODE (inner) == PLACEHOLDER_EXPR;
2092 switch (tree_code_length[(int) code])
2095 return contains_placeholder_p (TREE_OPERAND (exp, 0));
2097 return (code != RTL_EXPR
2098 && code != CONSTRUCTOR
2099 && ! (code == SAVE_EXPR && SAVE_EXPR_RTL (exp) != 0)
2100 && code != WITH_RECORD_EXPR
2101 && (contains_placeholder_p (TREE_OPERAND (exp, 0))
2102 || contains_placeholder_p (TREE_OPERAND (exp, 1))));
2104 return (code == COND_EXPR
2105 && (contains_placeholder_p (TREE_OPERAND (exp, 0))
2106 || contains_placeholder_p (TREE_OPERAND (exp, 1))
2107 || contains_placeholder_p (TREE_OPERAND (exp, 2))));
2114 /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
2115 return a tree with all occurrences of references to F in a
2116 PLACEHOLDER_EXPR replaced by R. Note that we assume here that EXP
2117 contains only arithmetic expressions. */
2120 substitute_in_expr (exp, f, r)
2125 enum tree_code code = TREE_CODE (exp);
2128 switch (TREE_CODE_CLASS (code))
2135 if (code == PLACEHOLDER_EXPR)
2143 switch (tree_code_length[(int) code])
2146 return fold (build1 (code, TREE_TYPE (exp),
2147 substitute_in_expr (TREE_OPERAND (exp, 0),
2151 /* An RTL_EXPR cannot contain a PLACEHOLDER_EXPR; a CONSTRUCTOR
2152 could, but we don't support it. */
2153 if (code == RTL_EXPR)
2155 else if (code == CONSTRUCTOR)
2158 return fold (build (code, TREE_TYPE (exp),
2159 substitute_in_expr (TREE_OPERAND (exp, 0), f, r),
2160 substitute_in_expr (TREE_OPERAND (exp, 1),
2164 /* It cannot be that anything inside a SAVE_EXPR contains a
2165 PLACEHOLDER_EXPR. */
2166 if (code == SAVE_EXPR)
2169 if (code != COND_EXPR)
2172 return fold (build (code, TREE_TYPE (exp),
2173 substitute_in_expr (TREE_OPERAND (exp, 0), f, r),
2174 substitute_in_expr (TREE_OPERAND (exp, 1), f, r),
2175 substitute_in_expr (TREE_OPERAND (exp, 2),
2185 /* If this expression is getting a value from a PLACEHOLDER_EXPR
2186 and it is the right field, replace it with R. */
2187 for (inner = TREE_OPERAND (exp, 0);
2188 TREE_CODE_CLASS (TREE_CODE (inner)) == 'r';
2189 inner = TREE_OPERAND (inner, 0))
2191 if (TREE_CODE (inner) == PLACEHOLDER_EXPR
2192 && TREE_OPERAND (exp, 1) == f)
2195 return fold (build (code, TREE_TYPE (exp),
2196 substitute_in_expr (TREE_OPERAND (exp, 0), f, r),
2197 TREE_OPERAND (exp, 1)));
2199 return fold (build (code, TREE_TYPE (exp),
2200 substitute_in_expr (TREE_OPERAND (exp, 0), f, r),
2201 substitute_in_expr (TREE_OPERAND (exp, 1), f, r),
2202 substitute_in_expr (TREE_OPERAND (exp, 2), f, r)));
2205 return fold (build1 (code, TREE_TYPE (exp),
2206 substitute_in_expr (TREE_OPERAND (exp, 0),
2209 return fold (build (code, TREE_TYPE (exp),
2210 substitute_in_expr (TREE_OPERAND (exp, 0), f, r),
2211 substitute_in_expr (TREE_OPERAND (exp, 1), f, r)));
2215 /* If it wasn't one of the cases we handle, give up. */
2220 /* Given a type T, a FIELD_DECL F, and a replacement value R,
2221 return a new type with all size expressions that contain F
2222 updated by replacing F with R. */
2225 substitute_in_type (t, f, r)
2228 switch (TREE_CODE (t))
2237 if ((TREE_CODE (TYPE_MIN_VALUE (t)) != INTEGER_CST
2238 && contains_placeholder_p (TYPE_MIN_VALUE (t)))
2239 || (TREE_CODE (TYPE_MAX_VALUE (t)) != INTEGER_CST
2240 && contains_placeholder_p (TYPE_MAX_VALUE (t))))
2241 return build_range_type (t,
2242 substitute_in_expr (TYPE_MIN_VALUE (t), f, r),
2243 substitute_in_expr (TYPE_MAX_VALUE (t), f, r));
2247 if ((TYPE_MIN_VALUE (t) != 0
2248 && TREE_CODE (TYPE_MIN_VALUE (t)) != REAL_CST
2249 && contains_placeholder_p (TYPE_MIN_VALUE (t)))
2250 || (TYPE_MAX_VALUE (t) != 0
2251 && TREE_CODE (TYPE_MAX_VALUE (t)) != REAL_CST
2252 && contains_placeholder_p (TYPE_MAX_VALUE (t))))
2254 t = build_type_copy (t);
2256 if (TYPE_MIN_VALUE (t))
2257 TYPE_MIN_VALUE (t) = substitute_in_expr (TYPE_MIN_VALUE (t), f, r);
2258 if (TYPE_MAX_VALUE (t))
2259 TYPE_MAX_VALUE (t) = substitute_in_expr (TYPE_MAX_VALUE (t), f, r);
2264 return build_complex_type (substitute_in_type (TREE_TYPE (t), f, r));
2268 case REFERENCE_TYPE:
2273 /* Don't know how to do these yet. */
2277 t = build_array_type (substitute_in_type (TREE_TYPE (t), f, r),
2278 substitute_in_type (TYPE_DOMAIN (t), f, r));
2285 case QUAL_UNION_TYPE:
2287 tree new = copy_node (t);
2289 tree last_field = 0;
2291 /* Start out with no fields, make new fields, and chain them
2294 TYPE_FIELDS (new) = 0;
2295 TYPE_SIZE (new) = 0;
2297 for (field = TYPE_FIELDS (t); field;
2298 field = TREE_CHAIN (field))
2300 tree new_field = copy_node (field);
2302 TREE_TYPE (new_field)
2303 = substitute_in_type (TREE_TYPE (new_field), f, r);
2305 /* If this is an anonymous field and the type of this field is
2306 a UNION_TYPE or RECORD_TYPE with no elements, ignore it. If
2307 the type just has one element, treat that as the field.
2308 But don't do this if we are processing a QUAL_UNION_TYPE. */
2309 if (TREE_CODE (t) != QUAL_UNION_TYPE && DECL_NAME (new_field) == 0
2310 && (TREE_CODE (TREE_TYPE (new_field)) == UNION_TYPE
2311 || TREE_CODE (TREE_TYPE (new_field)) == RECORD_TYPE))
2313 if (TYPE_FIELDS (TREE_TYPE (new_field)) == 0)
2316 if (TREE_CHAIN (TYPE_FIELDS (TREE_TYPE (new_field))) == 0)
2317 new_field = TYPE_FIELDS (TREE_TYPE (new_field));
2320 DECL_CONTEXT (new_field) = new;
2321 DECL_SIZE (new_field) = 0;
2323 if (TREE_CODE (t) == QUAL_UNION_TYPE)
2325 /* Do the substitution inside the qualifier and if we find
2326 that this field will not be present, omit it. */
2327 DECL_QUALIFIER (new_field)
2328 = substitute_in_expr (DECL_QUALIFIER (field), f, r);
2329 if (integer_zerop (DECL_QUALIFIER (new_field)))
2333 if (last_field == 0)
2334 TYPE_FIELDS (new) = new_field;
2336 TREE_CHAIN (last_field) = new_field;
2338 last_field = new_field;
2340 /* If this is a qualified type and this field will always be
2341 present, we are done. */
2342 if (TREE_CODE (t) == QUAL_UNION_TYPE
2343 && integer_onep (DECL_QUALIFIER (new_field)))
2347 /* If this used to be a qualified union type, but we now know what
2348 field will be present, make this a normal union. */
2349 if (TREE_CODE (new) == QUAL_UNION_TYPE
2350 && (TYPE_FIELDS (new) == 0
2351 || integer_onep (DECL_QUALIFIER (TYPE_FIELDS (new)))))
2352 TREE_SET_CODE (new, UNION_TYPE);
2360 /* Stabilize a reference so that we can use it any number of times
2361 without causing its operands to be evaluated more than once.
2362 Returns the stabilized reference. This works by means of save_expr,
2363 so see the caveats in the comments about save_expr.
2365 Also allows conversion expressions whose operands are references.
2366 Any other kind of expression is returned unchanged. */
2369 stabilize_reference (ref)
2372 register tree result;
2373 register enum tree_code code = TREE_CODE (ref);
2380 /* No action is needed in this case. */
2386 case FIX_TRUNC_EXPR:
2387 case FIX_FLOOR_EXPR:
2388 case FIX_ROUND_EXPR:
2390 result = build_nt (code, stabilize_reference (TREE_OPERAND (ref, 0)));
2394 result = build_nt (INDIRECT_REF,
2395 stabilize_reference_1 (TREE_OPERAND (ref, 0)));
2399 result = build_nt (COMPONENT_REF,
2400 stabilize_reference (TREE_OPERAND (ref, 0)),
2401 TREE_OPERAND (ref, 1));
2405 result = build_nt (BIT_FIELD_REF,
2406 stabilize_reference (TREE_OPERAND (ref, 0)),
2407 stabilize_reference_1 (TREE_OPERAND (ref, 1)),
2408 stabilize_reference_1 (TREE_OPERAND (ref, 2)));
2412 result = build_nt (ARRAY_REF,
2413 stabilize_reference (TREE_OPERAND (ref, 0)),
2414 stabilize_reference_1 (TREE_OPERAND (ref, 1)));
2418 result = build_nt (COMPOUND_EXPR,
2419 stabilize_reference_1 (TREE_OPERAND (ref, 0)),
2420 stabilize_reference (TREE_OPERAND (ref, 1)));
2424 result = build1 (INDIRECT_REF, TREE_TYPE (ref),
2425 save_expr (build1 (ADDR_EXPR,
2426 build_pointer_type (TREE_TYPE (ref)),
2431 /* If arg isn't a kind of lvalue we recognize, make no change.
2432 Caller should recognize the error for an invalid lvalue. */
2437 return error_mark_node;
2440 TREE_TYPE (result) = TREE_TYPE (ref);
2441 TREE_READONLY (result) = TREE_READONLY (ref);
2442 TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (ref);
2443 TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (ref);
2444 TREE_RAISES (result) = TREE_RAISES (ref);
2449 /* Subroutine of stabilize_reference; this is called for subtrees of
2450 references. Any expression with side-effects must be put in a SAVE_EXPR
2451 to ensure that it is only evaluated once.
2453 We don't put SAVE_EXPR nodes around everything, because assigning very
2454 simple expressions to temporaries causes us to miss good opportunities
2455 for optimizations. Among other things, the opportunity to fold in the
2456 addition of a constant into an addressing mode often gets lost, e.g.
2457 "y[i+1] += x;". In general, we take the approach that we should not make
2458 an assignment unless we are forced into it - i.e., that any non-side effect
2459 operator should be allowed, and that cse should take care of coalescing
2460 multiple utterances of the same expression should that prove fruitful. */
2463 stabilize_reference_1 (e)
2466 register tree result;
2467 register enum tree_code code = TREE_CODE (e);
2469 /* We cannot ignore const expressions because it might be a reference
2470 to a const array but whose index contains side-effects. But we can
2471 ignore things that are actual constant or that already have been
2472 handled by this function. */
2474 if (TREE_CONSTANT (e) || code == SAVE_EXPR)
2477 switch (TREE_CODE_CLASS (code))
2487 /* If the expression has side-effects, then encase it in a SAVE_EXPR
2488 so that it will only be evaluated once. */
2489 /* The reference (r) and comparison (<) classes could be handled as
2490 below, but it is generally faster to only evaluate them once. */
2491 if (TREE_SIDE_EFFECTS (e))
2492 return save_expr (e);
2496 /* Constants need no processing. In fact, we should never reach
2501 /* Division is slow and tends to be compiled with jumps,
2502 especially the division by powers of 2 that is often
2503 found inside of an array reference. So do it just once. */
2504 if (code == TRUNC_DIV_EXPR || code == TRUNC_MOD_EXPR
2505 || code == FLOOR_DIV_EXPR || code == FLOOR_MOD_EXPR
2506 || code == CEIL_DIV_EXPR || code == CEIL_MOD_EXPR
2507 || code == ROUND_DIV_EXPR || code == ROUND_MOD_EXPR)
2508 return save_expr (e);
2509 /* Recursively stabilize each operand. */
2510 result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)),
2511 stabilize_reference_1 (TREE_OPERAND (e, 1)));
2515 /* Recursively stabilize each operand. */
2516 result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)));
2523 TREE_TYPE (result) = TREE_TYPE (e);
2524 TREE_READONLY (result) = TREE_READONLY (e);
2525 TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (e);
2526 TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (e);
2527 TREE_RAISES (result) = TREE_RAISES (e);
2532 /* Low-level constructors for expressions. */
2534 /* Build an expression of code CODE, data type TYPE,
2535 and operands as specified by the arguments ARG1 and following arguments.
2536 Expressions and reference nodes can be created this way.
2537 Constants, decls, types and misc nodes cannot be. */
2540 build VPROTO((enum tree_code code, tree tt, ...))
2543 enum tree_code code;
2548 register int length;
2554 code = va_arg (p, enum tree_code);
2555 tt = va_arg (p, tree);
2558 t = make_node (code);
2559 length = tree_code_length[(int) code];
2564 /* This is equivalent to the loop below, but faster. */
2565 register tree arg0 = va_arg (p, tree);
2566 register tree arg1 = va_arg (p, tree);
2567 TREE_OPERAND (t, 0) = arg0;
2568 TREE_OPERAND (t, 1) = arg1;
2569 if ((arg0 && TREE_SIDE_EFFECTS (arg0))
2570 || (arg1 && TREE_SIDE_EFFECTS (arg1)))
2571 TREE_SIDE_EFFECTS (t) = 1;
2573 = (arg0 && TREE_RAISES (arg0)) || (arg1 && TREE_RAISES (arg1));
2575 else if (length == 1)
2577 register tree arg0 = va_arg (p, tree);
2579 /* Call build1 for this! */
2580 if (TREE_CODE_CLASS (code) != 's')
2582 TREE_OPERAND (t, 0) = arg0;
2583 if (arg0 && TREE_SIDE_EFFECTS (arg0))
2584 TREE_SIDE_EFFECTS (t) = 1;
2585 TREE_RAISES (t) = (arg0 && TREE_RAISES (arg0));
2589 for (i = 0; i < length; i++)
2591 register tree operand = va_arg (p, tree);
2592 TREE_OPERAND (t, i) = operand;
2595 if (TREE_SIDE_EFFECTS (operand))
2596 TREE_SIDE_EFFECTS (t) = 1;
2597 if (TREE_RAISES (operand))
2598 TREE_RAISES (t) = 1;
2606 /* Same as above, but only builds for unary operators.
2607 Saves lions share of calls to `build'; cuts down use
2608 of varargs, which is expensive for RISC machines. */
2610 build1 (code, type, node)
2611 enum tree_code code;
2615 register struct obstack *obstack = current_obstack;
2616 register int i, length;
2617 register tree_node_kind kind;
2620 #ifdef GATHER_STATISTICS
2621 if (TREE_CODE_CLASS (code) == 'r')
2627 obstack = expression_obstack;
2628 length = sizeof (struct tree_exp);
2630 t = (tree) obstack_alloc (obstack, length);
2632 #ifdef GATHER_STATISTICS
2633 tree_node_counts[(int)kind]++;
2634 tree_node_sizes[(int)kind] += length;
2637 for (i = (length / sizeof (int)) - 1; i >= 0; i--)
2640 TREE_TYPE (t) = type;
2641 TREE_SET_CODE (t, code);
2643 if (obstack == &permanent_obstack)
2644 TREE_PERMANENT (t) = 1;
2646 TREE_OPERAND (t, 0) = node;
2649 if (TREE_SIDE_EFFECTS (node))
2650 TREE_SIDE_EFFECTS (t) = 1;
2651 if (TREE_RAISES (node))
2652 TREE_RAISES (t) = 1;
2658 /* Similar except don't specify the TREE_TYPE
2659 and leave the TREE_SIDE_EFFECTS as 0.
2660 It is permissible for arguments to be null,
2661 or even garbage if their values do not matter. */
2664 build_nt VPROTO((enum tree_code code, ...))
2667 enum tree_code code;
2671 register int length;
2677 code = va_arg (p, enum tree_code);
2680 t = make_node (code);
2681 length = tree_code_length[(int) code];
2683 for (i = 0; i < length; i++)
2684 TREE_OPERAND (t, i) = va_arg (p, tree);
2690 /* Similar to `build_nt', except we build
2691 on the temp_decl_obstack, regardless. */
2694 build_parse_node VPROTO((enum tree_code code, ...))
2697 enum tree_code code;
2699 register struct obstack *ambient_obstack = expression_obstack;
2702 register int length;
2708 code = va_arg (p, enum tree_code);
2711 expression_obstack = &temp_decl_obstack;
2713 t = make_node (code);
2714 length = tree_code_length[(int) code];
2716 for (i = 0; i < length; i++)
2717 TREE_OPERAND (t, i) = va_arg (p, tree);
2720 expression_obstack = ambient_obstack;
2725 /* Commented out because this wants to be done very
2726 differently. See cp-lex.c. */
2728 build_op_identifier (op1, op2)
2731 register tree t = make_node (OP_IDENTIFIER);
2732 TREE_PURPOSE (t) = op1;
2733 TREE_VALUE (t) = op2;
2738 /* Create a DECL_... node of code CODE, name NAME and data type TYPE.
2739 We do NOT enter this node in any sort of symbol table.
2741 layout_decl is used to set up the decl's storage layout.
2742 Other slots are initialized to 0 or null pointers. */
2745 build_decl (code, name, type)
2746 enum tree_code code;
2751 t = make_node (code);
2753 /* if (type == error_mark_node)
2754 type = integer_type_node; */
2755 /* That is not done, deliberately, so that having error_mark_node
2756 as the type can suppress useless errors in the use of this variable. */
2758 DECL_NAME (t) = name;
2759 DECL_ASSEMBLER_NAME (t) = name;
2760 TREE_TYPE (t) = type;
2762 if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
2764 else if (code == FUNCTION_DECL)
2765 DECL_MODE (t) = FUNCTION_MODE;
2770 /* BLOCK nodes are used to represent the structure of binding contours
2771 and declarations, once those contours have been exited and their contents
2772 compiled. This information is used for outputting debugging info. */
2775 build_block (vars, tags, subblocks, supercontext, chain)
2776 tree vars, tags, subblocks, supercontext, chain;
2778 register tree block = make_node (BLOCK);
2779 BLOCK_VARS (block) = vars;
2780 BLOCK_TYPE_TAGS (block) = tags;
2781 BLOCK_SUBBLOCKS (block) = subblocks;
2782 BLOCK_SUPERCONTEXT (block) = supercontext;
2783 BLOCK_CHAIN (block) = chain;
2787 /* Return a declaration like DDECL except that its DECL_MACHINE_ATTRIBUTE
2791 build_decl_attribute_variant (ddecl, attribute)
2792 tree ddecl, attribute;
2794 DECL_MACHINE_ATTRIBUTES (ddecl) = attribute;
2798 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
2801 Record such modified types already made so we don't make duplicates. */
2804 build_type_attribute_variant (ttype, attribute)
2805 tree ttype, attribute;
2807 if ( ! attribute_list_equal (TYPE_ATTRIBUTES (ttype), attribute))
2809 register int hashcode;
2810 register struct obstack *ambient_obstack = current_obstack;
2813 if (ambient_obstack != &permanent_obstack)
2814 current_obstack = TYPE_OBSTACK (ttype);
2816 ntype = copy_node (ttype);
2817 current_obstack = ambient_obstack;
2819 TYPE_POINTER_TO (ntype) = 0;
2820 TYPE_REFERENCE_TO (ntype) = 0;
2821 TYPE_ATTRIBUTES (ntype) = attribute;
2823 /* Create a new main variant of TYPE. */
2824 TYPE_MAIN_VARIANT (ntype) = ntype;
2825 TYPE_NEXT_VARIANT (ntype) = 0;
2826 TYPE_READONLY (ntype) = TYPE_VOLATILE (ntype) = 0;
2828 hashcode = TYPE_HASH (TREE_CODE (ntype))
2829 + TYPE_HASH (TREE_TYPE (ntype))
2830 + type_hash_list (attribute);
2832 switch (TREE_CODE (ntype))
2835 hashcode += TYPE_HASH (TYPE_ARG_TYPES (ntype));
2838 hashcode += TYPE_HASH (TYPE_DOMAIN (ntype));
2841 hashcode += TYPE_HASH (TYPE_MAX_VALUE (ntype));
2844 hashcode += TYPE_HASH (TYPE_PRECISION (ntype));
2848 ntype = type_hash_canon (hashcode, ntype);
2849 ttype = build_type_variant (ntype, TYPE_READONLY (ttype),
2850 TYPE_VOLATILE (ttype));
2856 /* Return a 1 if NEW_ATTR is valid for either declaration DECL or type TYPE
2857 and 0 otherwise. Validity is determined the configuration macros
2858 VALID_MACHINE_DECL_ATTRIBUTE and VALID_MACHINE_TYPE_ATTRIBUTE. */
2861 valid_machine_attribute (new_attr, decl, type)
2867 tree decl_attr_list = DECL_MACHINE_ATTRIBUTES (decl);
2868 tree type_attr_list = TYPE_ATTRIBUTES (type);
2870 #ifdef VALID_MACHINE_DECL_ATTRIBUTE
2871 if (VALID_MACHINE_DECL_ATTRIBUTE (decl, decl_attr_list, new_attr))
2876 for (attr_list = decl_attr_list;
2878 attr_list = TREE_CHAIN (attr_list))
2879 if (TREE_VALUE (attr_list) == new_attr)
2883 decl_attr_list = tree_cons (NULL_TREE, new_attr, decl_attr_list);
2885 decl = build_decl_attribute_variant (decl, decl_attr_list);
2890 #ifdef VALID_MACHINE_TYPE_ATTRIBUTE
2891 if (VALID_MACHINE_TYPE_ATTRIBUTE (type, type_attr_list, new_attr))
2896 for (attr_list = type_attr_list;
2898 attr_list = TREE_CHAIN (attr_list))
2899 if (TREE_VALUE (attr_list) == new_attr)
2903 type_attr_list = tree_cons (NULL_TREE, new_attr, type_attr_list);
2905 decl = build_type_attribute_variant (type, type_attr_list);
2913 /* Return a type like TYPE except that its TYPE_READONLY is CONSTP
2914 and its TYPE_VOLATILE is VOLATILEP.
2916 Such variant types already made are recorded so that duplicates
2919 A variant types should never be used as the type of an expression.
2920 Always copy the variant information into the TREE_READONLY
2921 and TREE_THIS_VOLATILE of the expression, and then give the expression
2922 as its type the "main variant", the variant whose TYPE_READONLY
2923 and TYPE_VOLATILE are zero. Use TYPE_MAIN_VARIANT to find the
2927 build_type_variant (type, constp, volatilep)
2929 int constp, volatilep;
2933 /* Treat any nonzero argument as 1. */
2935 volatilep = !!volatilep;
2937 /* Search the chain of variants to see if there is already one there just
2938 like the one we need to have. If so, use that existing one. We must
2939 preserve the TYPE_NAME, since there is code that depends on this. */
2941 for (t = TYPE_MAIN_VARIANT(type); t; t = TYPE_NEXT_VARIANT (t))
2942 if (constp == TYPE_READONLY (t) && volatilep == TYPE_VOLATILE (t)
2943 && TYPE_NAME (t) == TYPE_NAME (type))
2946 /* We need a new one. */
2948 t = build_type_copy (type);
2949 TYPE_READONLY (t) = constp;
2950 TYPE_VOLATILE (t) = volatilep;
2955 /* Give TYPE a new main variant: NEW_MAIN.
2956 This is the right thing to do only when something else
2957 about TYPE is modified in place. */
2960 change_main_variant (type, new_main)
2961 tree type, new_main;
2964 tree omain = TYPE_MAIN_VARIANT (type);
2966 /* Remove TYPE from the TYPE_NEXT_VARIANT chain of its main variant. */
2967 if (TYPE_NEXT_VARIANT (omain) == type)
2968 TYPE_NEXT_VARIANT (omain) = TYPE_NEXT_VARIANT (type);
2970 for (t = TYPE_NEXT_VARIANT (omain); t && TYPE_NEXT_VARIANT (t);
2971 t = TYPE_NEXT_VARIANT (t))
2972 if (TYPE_NEXT_VARIANT (t) == type)
2974 TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (type);
2978 TYPE_MAIN_VARIANT (type) = new_main;
2979 TYPE_NEXT_VARIANT (type) = TYPE_NEXT_VARIANT (new_main);
2980 TYPE_NEXT_VARIANT (new_main) = type;
2983 /* Create a new variant of TYPE, equivalent but distinct.
2984 This is so the caller can modify it. */
2987 build_type_copy (type)
2990 register tree t, m = TYPE_MAIN_VARIANT (type);
2991 register struct obstack *ambient_obstack = current_obstack;
2993 current_obstack = TYPE_OBSTACK (type);
2994 t = copy_node (type);
2995 current_obstack = ambient_obstack;
2997 TYPE_POINTER_TO (t) = 0;
2998 TYPE_REFERENCE_TO (t) = 0;
3000 /* Add this type to the chain of variants of TYPE. */
3001 TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
3002 TYPE_NEXT_VARIANT (m) = t;
3007 /* Hashing of types so that we don't make duplicates.
3008 The entry point is `type_hash_canon'. */
3010 /* Each hash table slot is a bucket containing a chain
3011 of these structures. */
3015 struct type_hash *next; /* Next structure in the bucket. */
3016 int hashcode; /* Hash code of this type. */
3017 tree type; /* The type recorded here. */
3020 /* Now here is the hash table. When recording a type, it is added
3021 to the slot whose index is the hash code mod the table size.
3022 Note that the hash table is used for several kinds of types
3023 (function types, array types and array index range types, for now).
3024 While all these live in the same table, they are completely independent,
3025 and the hash code is computed differently for each of these. */
3027 #define TYPE_HASH_SIZE 59
3028 struct type_hash *type_hash_table[TYPE_HASH_SIZE];
3030 /* Compute a hash code for a list of types (chain of TREE_LIST nodes
3031 with types in the TREE_VALUE slots), by adding the hash codes
3032 of the individual types. */
3035 type_hash_list (list)
3038 register int hashcode;
3040 for (hashcode = 0, tail = list; tail; tail = TREE_CHAIN (tail))
3041 hashcode += TYPE_HASH (TREE_VALUE (tail));
3045 /* Look in the type hash table for a type isomorphic to TYPE.
3046 If one is found, return it. Otherwise return 0. */
3049 type_hash_lookup (hashcode, type)
3053 register struct type_hash *h;
3054 for (h = type_hash_table[hashcode % TYPE_HASH_SIZE]; h; h = h->next)
3055 if (h->hashcode == hashcode
3056 && TREE_CODE (h->type) == TREE_CODE (type)
3057 && TREE_TYPE (h->type) == TREE_TYPE (type)
3058 && attribute_list_equal (TYPE_ATTRIBUTES (h->type),
3059 TYPE_ATTRIBUTES (type))
3060 && (TYPE_MAX_VALUE (h->type) == TYPE_MAX_VALUE (type)
3061 || tree_int_cst_equal (TYPE_MAX_VALUE (h->type),
3062 TYPE_MAX_VALUE (type)))
3063 && (TYPE_MIN_VALUE (h->type) == TYPE_MIN_VALUE (type)
3064 || tree_int_cst_equal (TYPE_MIN_VALUE (h->type),
3065 TYPE_MIN_VALUE (type)))
3066 && (TYPE_DOMAIN (h->type) == TYPE_DOMAIN (type)
3067 || (TYPE_DOMAIN (h->type)
3068 && TREE_CODE (TYPE_DOMAIN (h->type)) == TREE_LIST
3069 && TYPE_DOMAIN (type)
3070 && TREE_CODE (TYPE_DOMAIN (type)) == TREE_LIST
3071 && type_list_equal (TYPE_DOMAIN (h->type), TYPE_DOMAIN (type)))))
3076 /* Add an entry to the type-hash-table
3077 for a type TYPE whose hash code is HASHCODE. */
3080 type_hash_add (hashcode, type)
3084 register struct type_hash *h;
3086 h = (struct type_hash *) oballoc (sizeof (struct type_hash));
3087 h->hashcode = hashcode;
3089 h->next = type_hash_table[hashcode % TYPE_HASH_SIZE];
3090 type_hash_table[hashcode % TYPE_HASH_SIZE] = h;
3093 /* Given TYPE, and HASHCODE its hash code, return the canonical
3094 object for an identical type if one already exists.
3095 Otherwise, return TYPE, and record it as the canonical object
3096 if it is a permanent object.
3098 To use this function, first create a type of the sort you want.
3099 Then compute its hash code from the fields of the type that
3100 make it different from other similar types.
3101 Then call this function and use the value.
3102 This function frees the type you pass in if it is a duplicate. */
3104 /* Set to 1 to debug without canonicalization. Never set by program. */
3105 int debug_no_type_hash = 0;
3108 type_hash_canon (hashcode, type)
3114 if (debug_no_type_hash)
3117 t1 = type_hash_lookup (hashcode, type);
3120 obstack_free (TYPE_OBSTACK (type), type);
3121 #ifdef GATHER_STATISTICS
3122 tree_node_counts[(int)t_kind]--;
3123 tree_node_sizes[(int)t_kind] -= sizeof (struct tree_type);
3128 /* If this is a permanent type, record it for later reuse. */
3129 if (TREE_PERMANENT (type))
3130 type_hash_add (hashcode, type);
3135 /* Given two lists of attributes, return true if list l2 is
3136 equivalent to l1. */
3139 attribute_list_equal (l1, l2)
3142 return attribute_list_contained (l1, l2)
3143 && attribute_list_contained (l2, l1);
3146 /* Given two lists of attributes, return true if list l2 is
3147 completely contained within l1. */
3150 attribute_list_contained (l1, l2)
3153 register tree t1, t2;
3155 /* First check the obvious, maybe the lists are identical. */
3159 /* Then check the obvious, maybe the lists are similar. */
3160 for (t1 = l1, t2 = l2;
3162 && TREE_VALUE (t1) == TREE_VALUE (t2);
3163 t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2));
3165 /* Maybe the lists are equal. */
3166 if (t1 == 0 && t2 == 0)
3169 for (; t2; t2 = TREE_CHAIN (t2))
3170 if (!value_member (l1, t2))
3175 /* Given two lists of types
3176 (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
3177 return 1 if the lists contain the same types in the same order.
3178 Also, the TREE_PURPOSEs must match. */
3181 type_list_equal (l1, l2)
3184 register tree t1, t2;
3185 for (t1 = l1, t2 = l2; t1 && t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
3187 if (TREE_VALUE (t1) != TREE_VALUE (t2))
3189 if (TREE_PURPOSE (t1) != TREE_PURPOSE (t2))
3191 int cmp = simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2));
3195 || TREE_TYPE (TREE_PURPOSE (t1))
3196 != TREE_TYPE (TREE_PURPOSE (t2)))
3204 /* Nonzero if integer constants T1 and T2
3205 represent the same constant value. */
3208 tree_int_cst_equal (t1, t2)
3213 if (t1 == 0 || t2 == 0)
3215 if (TREE_CODE (t1) == INTEGER_CST
3216 && TREE_CODE (t2) == INTEGER_CST
3217 && TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
3218 && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2))
3223 /* Nonzero if integer constants T1 and T2 represent values that satisfy <.
3224 The precise way of comparison depends on their data type. */
3227 tree_int_cst_lt (t1, t2)
3233 if (!TREE_UNSIGNED (TREE_TYPE (t1)))
3234 return INT_CST_LT (t1, t2);
3235 return INT_CST_LT_UNSIGNED (t1, t2);
3238 /* Return an indication of the sign of the integer constant T.
3239 The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0.
3240 Note that -1 will never be returned it T's type is unsigned. */
3243 tree_int_cst_sgn (t)
3246 if (TREE_INT_CST_LOW (t) == 0 && TREE_INT_CST_HIGH (t) == 0)
3248 else if (TREE_UNSIGNED (TREE_TYPE (t)))
3250 else if (TREE_INT_CST_HIGH (t) < 0)
3256 /* Compare two constructor-element-type constants. */
3258 simple_cst_list_equal (l1, l2)
3261 while (l1 != NULL_TREE && l2 != NULL_TREE)
3263 int cmp = simple_cst_equal (TREE_VALUE (l1), TREE_VALUE (l2));
3268 l1 = TREE_CHAIN (l1);
3269 l2 = TREE_CHAIN (l2);
3274 /* Return truthvalue of whether T1 is the same tree structure as T2.
3275 Return 1 if they are the same.
3276 Return 0 if they are understandably different.
3277 Return -1 if either contains tree structure not understood by
3281 simple_cst_equal (t1, t2)
3284 register enum tree_code code1, code2;
3289 if (t1 == 0 || t2 == 0)
3292 code1 = TREE_CODE (t1);
3293 code2 = TREE_CODE (t2);
3295 if (code1 == NOP_EXPR || code1 == CONVERT_EXPR || code1 == NON_LVALUE_EXPR)
3296 if (code2 == NOP_EXPR || code2 == CONVERT_EXPR || code2 == NON_LVALUE_EXPR)
3297 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3299 return simple_cst_equal (TREE_OPERAND (t1, 0), t2);
3300 else if (code2 == NOP_EXPR || code2 == CONVERT_EXPR
3301 || code2 == NON_LVALUE_EXPR)
3302 return simple_cst_equal (t1, TREE_OPERAND (t2, 0));
3310 return TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
3311 && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2);
3314 return REAL_VALUES_EQUAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
3317 return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
3318 && !bcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
3319 TREE_STRING_LENGTH (t1));
3325 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3328 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3331 return simple_cst_list_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
3334 /* Special case: if either target is an unallocated VAR_DECL,
3335 it means that it's going to be unified with whatever the
3336 TARGET_EXPR is really supposed to initialize, so treat it
3337 as being equivalent to anything. */
3338 if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL
3339 && DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE
3340 && DECL_RTL (TREE_OPERAND (t1, 0)) == 0)
3341 || (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL
3342 && DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE
3343 && DECL_RTL (TREE_OPERAND (t2, 0)) == 0))
3346 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3349 return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
3351 case WITH_CLEANUP_EXPR:
3352 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3355 return simple_cst_equal (TREE_OPERAND (t1, 2), TREE_OPERAND (t1, 2));
3358 if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1))
3359 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3369 /* This general rule works for most tree codes.
3370 All exceptions should be handled above. */
3372 switch (TREE_CODE_CLASS (code1))
3382 for (i=0; i<tree_code_length[(int) code1]; ++i)
3384 cmp = simple_cst_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i));
3394 /* Constructors for pointer, array and function types.
3395 (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
3396 constructed by language-dependent code, not here.) */
3398 /* Construct, lay out and return the type of pointers to TO_TYPE.
3399 If such a type has already been constructed, reuse it. */
3402 build_pointer_type (to_type)
3405 register tree t = TYPE_POINTER_TO (to_type);
3407 /* First, if we already have a type for pointers to TO_TYPE, use it. */
3412 /* We need a new one. Put this in the same obstack as TO_TYPE. */
3413 push_obstacks (TYPE_OBSTACK (to_type), TYPE_OBSTACK (to_type));
3414 t = make_node (POINTER_TYPE);
3417 TREE_TYPE (t) = to_type;
3419 /* Record this type as the pointer to TO_TYPE. */
3420 TYPE_POINTER_TO (to_type) = t;
3422 /* Lay out the type. This function has many callers that are concerned
3423 with expression-construction, and this simplifies them all.
3424 Also, it guarantees the TYPE_SIZE is in the same obstack as the type. */
3430 /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
3431 MAXVAL should be the maximum value in the domain
3432 (one less than the length of the array). */
3435 build_index_type (maxval)
3438 register tree itype = make_node (INTEGER_TYPE);
3439 TYPE_PRECISION (itype) = TYPE_PRECISION (sizetype);
3440 TYPE_MIN_VALUE (itype) = build_int_2 (0, 0);
3441 TREE_TYPE (TYPE_MIN_VALUE (itype)) = sizetype;
3442 TYPE_MAX_VALUE (itype) = convert (sizetype, maxval);
3443 TYPE_MODE (itype) = TYPE_MODE (sizetype);
3444 TYPE_SIZE (itype) = TYPE_SIZE (sizetype);
3445 TYPE_ALIGN (itype) = TYPE_ALIGN (sizetype);
3446 if (TREE_CODE (maxval) == INTEGER_CST)
3448 int maxint = (int) TREE_INT_CST_LOW (maxval);
3449 /* If the domain should be empty, make sure the maxval
3450 remains -1 and is not spoiled by truncation. */
3451 if (INT_CST_LT (maxval, integer_zero_node))
3453 TYPE_MAX_VALUE (itype) = build_int_2 (-1, -1);
3454 TREE_TYPE (TYPE_MAX_VALUE (itype)) = sizetype;
3456 return type_hash_canon (maxint < 0 ? ~maxint : maxint, itype);
3462 /* Create a range of some discrete type TYPE (an INTEGER_TYPE,
3463 ENUMERAL_TYPE, BOOLEAN_TYPE, or CHAR_TYPE), with
3464 low bound LOWVAL and high bound HIGHVAL.
3465 if TYPE==NULL_TREE, sizetype is used. */
3468 build_range_type (type, lowval, highval)
3469 tree type, lowval, highval;
3471 register tree itype = make_node (INTEGER_TYPE);
3472 TREE_TYPE (itype) = type;
3473 if (type == NULL_TREE)
3475 TYPE_PRECISION (itype) = TYPE_PRECISION (type);
3476 TYPE_MIN_VALUE (itype) = convert (type, lowval);
3477 TYPE_MAX_VALUE (itype) = convert (type, highval);
3478 TYPE_MODE (itype) = TYPE_MODE (type);
3479 TYPE_SIZE (itype) = TYPE_SIZE (type);
3480 TYPE_ALIGN (itype) = TYPE_ALIGN (type);
3481 if ((TREE_CODE (lowval) == INTEGER_CST)
3482 && (TREE_CODE (highval) == INTEGER_CST))
3484 HOST_WIDE_INT highint = TREE_INT_CST_LOW (highval);
3485 HOST_WIDE_INT lowint = TREE_INT_CST_LOW (lowval);
3486 int maxint = (int) (highint - lowint);
3487 return type_hash_canon (maxint < 0 ? ~maxint : maxint, itype);
3493 /* Just like build_index_type, but takes lowval and highval instead
3494 of just highval (maxval). */
3497 build_index_2_type (lowval,highval)
3498 tree lowval, highval;
3500 return build_range_type (NULL_TREE, lowval, highval);
3503 /* Return nonzero iff ITYPE1 and ITYPE2 are equal (in the LISP sense).
3504 Needed because when index types are not hashed, equal index types
3505 built at different times appear distinct, even though structurally,
3509 index_type_equal (itype1, itype2)
3510 tree itype1, itype2;
3512 if (TREE_CODE (itype1) != TREE_CODE (itype2))
3514 if (TREE_CODE (itype1) == INTEGER_TYPE)
3516 if (TYPE_PRECISION (itype1) != TYPE_PRECISION (itype2)
3517 || TYPE_MODE (itype1) != TYPE_MODE (itype2)
3518 || ! simple_cst_equal (TYPE_SIZE (itype1), TYPE_SIZE (itype2))
3519 || TYPE_ALIGN (itype1) != TYPE_ALIGN (itype2))
3521 if (simple_cst_equal (TYPE_MIN_VALUE (itype1), TYPE_MIN_VALUE (itype2))
3522 && simple_cst_equal (TYPE_MAX_VALUE (itype1), TYPE_MAX_VALUE (itype2)))
3528 /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
3529 and number of elements specified by the range of values of INDEX_TYPE.
3530 If such a type has already been constructed, reuse it. */
3533 build_array_type (elt_type, index_type)
3534 tree elt_type, index_type;
3539 if (TREE_CODE (elt_type) == FUNCTION_TYPE)
3541 error ("arrays of functions are not meaningful");
3542 elt_type = integer_type_node;
3545 /* Make sure TYPE_POINTER_TO (elt_type) is filled in. */
3546 build_pointer_type (elt_type);
3548 /* Allocate the array after the pointer type,
3549 in case we free it in type_hash_canon. */
3550 t = make_node (ARRAY_TYPE);
3551 TREE_TYPE (t) = elt_type;
3552 TYPE_DOMAIN (t) = index_type;
3554 if (index_type == 0)
3559 hashcode = TYPE_HASH (elt_type) + TYPE_HASH (index_type);
3560 t = type_hash_canon (hashcode, t);
3562 #if 0 /* This led to crashes, because it could put a temporary node
3563 on the TYPE_NEXT_VARIANT chain of a permanent one. */
3564 /* The main variant of an array type should always
3565 be an array whose element type is the main variant. */
3566 if (elt_type != TYPE_MAIN_VARIANT (elt_type))
3567 change_main_variant (t, build_array_type (TYPE_MAIN_VARIANT (elt_type),
3571 if (TYPE_SIZE (t) == 0)
3576 /* Construct, lay out and return
3577 the type of functions returning type VALUE_TYPE
3578 given arguments of types ARG_TYPES.
3579 ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
3580 are data type nodes for the arguments of the function.
3581 If such a type has already been constructed, reuse it. */
3584 build_function_type (value_type, arg_types)
3585 tree value_type, arg_types;
3590 if (TREE_CODE (value_type) == FUNCTION_TYPE)
3592 error ("function return type cannot be function");
3593 value_type = integer_type_node;
3596 /* Make a node of the sort we want. */
3597 t = make_node (FUNCTION_TYPE);
3598 TREE_TYPE (t) = value_type;
3599 TYPE_ARG_TYPES (t) = arg_types;
3601 /* If we already have such a type, use the old one and free this one. */
3602 hashcode = TYPE_HASH (value_type) + type_hash_list (arg_types);
3603 t = type_hash_canon (hashcode, t);
3605 if (TYPE_SIZE (t) == 0)
3610 /* Build the node for the type of references-to-TO_TYPE. */
3613 build_reference_type (to_type)
3616 register tree t = TYPE_REFERENCE_TO (to_type);
3617 register struct obstack *ambient_obstack = current_obstack;
3618 register struct obstack *ambient_saveable_obstack = saveable_obstack;
3620 /* First, if we already have a type for pointers to TO_TYPE, use it. */
3625 /* We need a new one. If TO_TYPE is permanent, make this permanent too. */
3626 if (TREE_PERMANENT (to_type))
3628 current_obstack = &permanent_obstack;
3629 saveable_obstack = &permanent_obstack;
3632 t = make_node (REFERENCE_TYPE);
3633 TREE_TYPE (t) = to_type;
3635 /* Record this type as the pointer to TO_TYPE. */
3636 TYPE_REFERENCE_TO (to_type) = t;
3640 current_obstack = ambient_obstack;
3641 saveable_obstack = ambient_saveable_obstack;
3645 /* Construct, lay out and return the type of methods belonging to class
3646 BASETYPE and whose arguments and values are described by TYPE.
3647 If that type exists already, reuse it.
3648 TYPE must be a FUNCTION_TYPE node. */
3651 build_method_type (basetype, type)
3652 tree basetype, type;
3657 /* Make a node of the sort we want. */
3658 t = make_node (METHOD_TYPE);
3660 if (TREE_CODE (type) != FUNCTION_TYPE)
3663 TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
3664 TREE_TYPE (t) = TREE_TYPE (type);
3666 /* The actual arglist for this function includes a "hidden" argument
3667 which is "this". Put it into the list of argument types. */
3670 = tree_cons (NULL_TREE,
3671 build_pointer_type (basetype), TYPE_ARG_TYPES (type));
3673 /* If we already have such a type, use the old one and free this one. */
3674 hashcode = TYPE_HASH (basetype) + TYPE_HASH (type);
3675 t = type_hash_canon (hashcode, t);
3677 if (TYPE_SIZE (t) == 0)
3683 /* Construct, lay out and return the type of offsets to a value
3684 of type TYPE, within an object of type BASETYPE.
3685 If a suitable offset type exists already, reuse it. */
3688 build_offset_type (basetype, type)
3689 tree basetype, type;
3694 /* Make a node of the sort we want. */
3695 t = make_node (OFFSET_TYPE);
3697 TYPE_OFFSET_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
3698 TREE_TYPE (t) = type;
3700 /* If we already have such a type, use the old one and free this one. */
3701 hashcode = TYPE_HASH (basetype) + TYPE_HASH (type);
3702 t = type_hash_canon (hashcode, t);
3704 if (TYPE_SIZE (t) == 0)
3710 /* Create a complex type whose components are COMPONENT_TYPE. */
3713 build_complex_type (component_type)
3714 tree component_type;
3719 /* Make a node of the sort we want. */
3720 t = make_node (COMPLEX_TYPE);
3722 TREE_TYPE (t) = TYPE_MAIN_VARIANT (component_type);
3723 TYPE_VOLATILE (t) = TYPE_VOLATILE (component_type);
3724 TYPE_READONLY (t) = TYPE_READONLY (component_type);
3726 /* If we already have such a type, use the old one and free this one. */
3727 hashcode = TYPE_HASH (component_type);
3728 t = type_hash_canon (hashcode, t);
3730 if (TYPE_SIZE (t) == 0)
3736 /* Return OP, stripped of any conversions to wider types as much as is safe.
3737 Converting the value back to OP's type makes a value equivalent to OP.
3739 If FOR_TYPE is nonzero, we return a value which, if converted to
3740 type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
3742 If FOR_TYPE is nonzero, unaligned bit-field references may be changed to the
3743 narrowest type that can hold the value, even if they don't exactly fit.
3744 Otherwise, bit-field references are changed to a narrower type
3745 only if they can be fetched directly from memory in that type.
3747 OP must have integer, real or enumeral type. Pointers are not allowed!
3749 There are some cases where the obvious value we could return
3750 would regenerate to OP if converted to OP's type,
3751 but would not extend like OP to wider types.
3752 If FOR_TYPE indicates such extension is contemplated, we eschew such values.
3753 For example, if OP is (unsigned short)(signed char)-1,
3754 we avoid returning (signed char)-1 if FOR_TYPE is int,
3755 even though extending that to an unsigned short would regenerate OP,
3756 since the result of extending (signed char)-1 to (int)
3757 is different from (int) OP. */
3760 get_unwidened (op, for_type)
3764 /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */
3765 /* TYPE_PRECISION is safe in place of type_precision since
3766 pointer types are not allowed. */
3767 register tree type = TREE_TYPE (op);
3768 register unsigned final_prec
3769 = TYPE_PRECISION (for_type != 0 ? for_type : type);
3771 = (for_type != 0 && for_type != type
3772 && final_prec > TYPE_PRECISION (type)
3773 && TREE_UNSIGNED (type));
3774 register tree win = op;
3776 while (TREE_CODE (op) == NOP_EXPR)
3778 register int bitschange
3779 = TYPE_PRECISION (TREE_TYPE (op))
3780 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
3782 /* Truncations are many-one so cannot be removed.
3783 Unless we are later going to truncate down even farther. */
3785 && final_prec > TYPE_PRECISION (TREE_TYPE (op)))
3788 /* See what's inside this conversion. If we decide to strip it,
3790 op = TREE_OPERAND (op, 0);
3792 /* If we have not stripped any zero-extensions (uns is 0),
3793 we can strip any kind of extension.
3794 If we have previously stripped a zero-extension,
3795 only zero-extensions can safely be stripped.
3796 Any extension can be stripped if the bits it would produce
3797 are all going to be discarded later by truncating to FOR_TYPE. */
3801 if (! uns || final_prec <= TYPE_PRECISION (TREE_TYPE (op)))
3803 /* TREE_UNSIGNED says whether this is a zero-extension.
3804 Let's avoid computing it if it does not affect WIN
3805 and if UNS will not be needed again. */
3806 if ((uns || TREE_CODE (op) == NOP_EXPR)
3807 && TREE_UNSIGNED (TREE_TYPE (op)))
3815 if (TREE_CODE (op) == COMPONENT_REF
3816 /* Since type_for_size always gives an integer type. */
3817 && TREE_CODE (type) != REAL_TYPE)
3819 unsigned innerprec = TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (op, 1)));
3820 type = type_for_size (innerprec, TREE_UNSIGNED (TREE_OPERAND (op, 1)));
3822 /* We can get this structure field in the narrowest type it fits in.
3823 If FOR_TYPE is 0, do this only for a field that matches the
3824 narrower type exactly and is aligned for it
3825 The resulting extension to its nominal type (a fullword type)
3826 must fit the same conditions as for other extensions. */
3828 if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
3829 && (for_type || ! DECL_BIT_FIELD (TREE_OPERAND (op, 1)))
3830 && (! uns || final_prec <= innerprec
3831 || TREE_UNSIGNED (TREE_OPERAND (op, 1)))
3834 win = build (COMPONENT_REF, type, TREE_OPERAND (op, 0),
3835 TREE_OPERAND (op, 1));
3836 TREE_SIDE_EFFECTS (win) = TREE_SIDE_EFFECTS (op);
3837 TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
3838 TREE_RAISES (win) = TREE_RAISES (op);
3844 /* Return OP or a simpler expression for a narrower value
3845 which can be sign-extended or zero-extended to give back OP.
3846 Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
3847 or 0 if the value should be sign-extended. */
3850 get_narrower (op, unsignedp_ptr)
3854 register int uns = 0;
3856 register tree win = op;
3858 while (TREE_CODE (op) == NOP_EXPR)
3860 register int bitschange
3861 = TYPE_PRECISION (TREE_TYPE (op))
3862 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
3864 /* Truncations are many-one so cannot be removed. */
3868 /* See what's inside this conversion. If we decide to strip it,
3870 op = TREE_OPERAND (op, 0);
3874 /* An extension: the outermost one can be stripped,
3875 but remember whether it is zero or sign extension. */
3877 uns = TREE_UNSIGNED (TREE_TYPE (op));
3878 /* Otherwise, if a sign extension has been stripped,
3879 only sign extensions can now be stripped;
3880 if a zero extension has been stripped, only zero-extensions. */
3881 else if (uns != TREE_UNSIGNED (TREE_TYPE (op)))
3885 else /* bitschange == 0 */
3887 /* A change in nominal type can always be stripped, but we must
3888 preserve the unsignedness. */
3890 uns = TREE_UNSIGNED (TREE_TYPE (op));
3897 if (TREE_CODE (op) == COMPONENT_REF
3898 /* Since type_for_size always gives an integer type. */
3899 && TREE_CODE (TREE_TYPE (op)) != REAL_TYPE)
3901 unsigned innerprec = TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (op, 1)));
3902 tree type = type_for_size (innerprec, TREE_UNSIGNED (op));
3904 /* We can get this structure field in a narrower type that fits it,
3905 but the resulting extension to its nominal type (a fullword type)
3906 must satisfy the same conditions as for other extensions.
3908 Do this only for fields that are aligned (not bit-fields),
3909 because when bit-field insns will be used there is no
3910 advantage in doing this. */
3912 if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
3913 && ! DECL_BIT_FIELD (TREE_OPERAND (op, 1))
3914 && (first || uns == TREE_UNSIGNED (TREE_OPERAND (op, 1)))
3918 uns = TREE_UNSIGNED (TREE_OPERAND (op, 1));
3919 win = build (COMPONENT_REF, type, TREE_OPERAND (op, 0),
3920 TREE_OPERAND (op, 1));
3921 TREE_SIDE_EFFECTS (win) = TREE_SIDE_EFFECTS (op);
3922 TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
3923 TREE_RAISES (win) = TREE_RAISES (op);
3926 *unsignedp_ptr = uns;
3930 /* Return the precision of a type, for arithmetic purposes.
3931 Supports all types on which arithmetic is possible
3932 (including pointer types).
3933 It's not clear yet what will be right for complex types. */
3936 type_precision (type)
3939 return ((TREE_CODE (type) == INTEGER_TYPE
3940 || TREE_CODE (type) == ENUMERAL_TYPE
3941 || TREE_CODE (type) == REAL_TYPE)
3942 ? TYPE_PRECISION (type) : POINTER_SIZE);
3945 /* Nonzero if integer constant C has a value that is permissible
3946 for type TYPE (an INTEGER_TYPE). */
3949 int_fits_type_p (c, type)
3952 if (TREE_UNSIGNED (type))
3953 return (! (TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST
3954 && INT_CST_LT_UNSIGNED (TYPE_MAX_VALUE (type), c))
3955 && ! (TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST
3956 && INT_CST_LT_UNSIGNED (c, TYPE_MIN_VALUE (type))));
3958 return (! (TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST
3959 && INT_CST_LT (TYPE_MAX_VALUE (type), c))
3960 && ! (TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST
3961 && INT_CST_LT (c, TYPE_MIN_VALUE (type))));
3964 /* Return the innermost context enclosing DECL that is
3965 a FUNCTION_DECL, or zero if none. */
3968 decl_function_context (decl)
3973 if (TREE_CODE (decl) == ERROR_MARK)
3976 if (TREE_CODE (decl) == SAVE_EXPR)
3977 context = SAVE_EXPR_CONTEXT (decl);
3979 context = DECL_CONTEXT (decl);
3981 while (context && TREE_CODE (context) != FUNCTION_DECL)
3983 if (TREE_CODE (context) == RECORD_TYPE
3984 || TREE_CODE (context) == UNION_TYPE)
3985 context = NULL_TREE;
3986 else if (TREE_CODE (context) == TYPE_DECL)
3987 context = DECL_CONTEXT (context);
3988 else if (TREE_CODE (context) == BLOCK)
3989 context = BLOCK_SUPERCONTEXT (context);
3991 /* Unhandled CONTEXT !? */
3998 /* Return the innermost context enclosing DECL that is
3999 a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
4000 TYPE_DECLs and FUNCTION_DECLs are transparent to this function. */
4003 decl_type_context (decl)
4006 tree context = DECL_CONTEXT (decl);
4010 if (TREE_CODE (context) == RECORD_TYPE
4011 || TREE_CODE (context) == UNION_TYPE
4012 || TREE_CODE (context) == QUAL_UNION_TYPE)
4014 if (TREE_CODE (context) == TYPE_DECL
4015 || TREE_CODE (context) == FUNCTION_DECL)
4016 context = DECL_CONTEXT (context);
4017 else if (TREE_CODE (context) == BLOCK)
4018 context = BLOCK_SUPERCONTEXT (context);
4020 /* Unhandled CONTEXT!? */
4027 print_obstack_statistics (str, o)
4031 struct _obstack_chunk *chunk = o->chunk;
4038 n_alloc += chunk->limit - &chunk->contents[0];
4039 chunk = chunk->prev;
4041 fprintf (stderr, "obstack %s: %d bytes, %d chunks\n",
4042 str, n_alloc, n_chunks);
4045 dump_tree_statistics ()
4048 int total_nodes, total_bytes;
4050 fprintf (stderr, "\n??? tree nodes created\n\n");
4051 #ifdef GATHER_STATISTICS
4052 fprintf (stderr, "Kind Nodes Bytes\n");
4053 fprintf (stderr, "-------------------------------------\n");
4054 total_nodes = total_bytes = 0;
4055 for (i = 0; i < (int) all_kinds; i++)
4057 fprintf (stderr, "%-20s %6d %9d\n", tree_node_kind_names[i],
4058 tree_node_counts[i], tree_node_sizes[i]);
4059 total_nodes += tree_node_counts[i];
4060 total_bytes += tree_node_sizes[i];
4062 fprintf (stderr, "%-20s %9d\n", "identifier names", id_string_size);
4063 fprintf (stderr, "-------------------------------------\n");
4064 fprintf (stderr, "%-20s %6d %9d\n", "Total", total_nodes, total_bytes);
4065 fprintf (stderr, "-------------------------------------\n");
4067 fprintf (stderr, "(No per-node statistics)\n");
4069 print_lang_statistics ();
4072 #define FILE_FUNCTION_PREFIX_LEN 9
4074 #ifndef NO_DOLLAR_IN_LABEL
4075 #define FILE_FUNCTION_FORMAT "_GLOBAL_$D$%s"
4076 #else /* NO_DOLLAR_IN_LABEL */
4077 #ifndef NO_DOT_IN_LABEL
4078 #define FILE_FUNCTION_FORMAT "_GLOBAL_.D.%s"
4079 #else /* NO_DOT_IN_LABEL */
4080 #define FILE_FUNCTION_FORMAT "_GLOBAL__D_%s"
4081 #endif /* NO_DOT_IN_LABEL */
4082 #endif /* NO_DOLLAR_IN_LABEL */
4084 extern char * first_global_object_name;
4086 /* If KIND=='I', return a suitable global initializer (constructor) name.
4087 If KIND=='D', return a suitable global clean-up (destructor) name. */
4090 get_file_function_name (kind)
4096 if (first_global_object_name)
4097 p = first_global_object_name;
4098 else if (main_input_filename)
4099 p = main_input_filename;
4103 buf = (char *) alloca (sizeof (FILE_FUNCTION_FORMAT) + strlen (p));
4105 /* Set up the name of the file-level functions we may need. */
4106 /* Use a global object (which is already required to be unique over
4107 the program) rather than the file name (which imposes extra
4108 constraints). -- Raeburn@MIT.EDU, 10 Jan 1990. */
4109 sprintf (buf, FILE_FUNCTION_FORMAT, p);
4111 /* Don't need to pull wierd characters out of global names. */
4112 if (p != first_global_object_name)
4114 for (p = buf+11; *p; p++)
4115 if (! ((*p >= '0' && *p <= '9')
4116 #if 0 /* we always want labels, which are valid C++ identifiers (+ `$') */
4117 #ifndef ASM_IDENTIFY_GCC /* this is required if `.' is invalid -- k. raeburn */
4121 #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
4124 #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */
4127 || (*p >= 'A' && *p <= 'Z')
4128 || (*p >= 'a' && *p <= 'z')))
4132 buf[FILE_FUNCTION_PREFIX_LEN] = kind;
4134 return get_identifier (buf);
4137 /* Expand (the constant part of) a SET_TYPE CONTRUCTOR node.
4138 The result is placed in BUFFER (which has length BIT_SIZE),
4139 with one bit in each char ('\000' or '\001').
4141 If the constructor is constant, NULL_TREE is returned.
4142 Otherwise, a TREE_LIST of the non-constant elements is emitted. */
4145 get_set_constructor_bits (init, buffer, bit_size)
4152 HOST_WIDE_INT domain_min
4153 = TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (init))));
4154 tree non_const_bits = NULL_TREE;
4155 for (i = 0; i < bit_size; i++)
4158 for (vals = TREE_OPERAND (init, 1);
4159 vals != NULL_TREE; vals = TREE_CHAIN (vals))
4161 if (TREE_CODE (TREE_VALUE (vals)) != INTEGER_CST
4162 || (TREE_PURPOSE (vals) != NULL_TREE
4163 && TREE_CODE (TREE_PURPOSE (vals)) != INTEGER_CST))
4165 tree_cons (TREE_PURPOSE (vals), TREE_VALUE (vals), non_const_bits);
4166 else if (TREE_PURPOSE (vals) != NULL_TREE)
4168 /* Set a range of bits to ones. */
4169 HOST_WIDE_INT lo_index
4170 = TREE_INT_CST_LOW (TREE_PURPOSE (vals)) - domain_min;
4171 HOST_WIDE_INT hi_index
4172 = TREE_INT_CST_LOW (TREE_VALUE (vals)) - domain_min;
4173 if (lo_index < 0 || lo_index >= bit_size
4174 || hi_index < 0 || hi_index >= bit_size)
4176 for ( ; lo_index <= hi_index; lo_index++)
4177 buffer[lo_index] = 1;
4181 /* Set a single bit to one. */
4183 = TREE_INT_CST_LOW (TREE_VALUE (vals)) - domain_min;
4184 if (index < 0 || index >= bit_size)
4186 error ("invalid initializer for bit string");
4192 return non_const_bits;
4195 /* Expand (the constant part of) a SET_TYPE CONTRUCTOR node.
4196 The result is placed in BUFFER (which is an array of bytes).
4197 If the constructor is constant, NULL_TREE is returned.
4198 Otherwise, a TREE_LIST of the non-constant elements is emitted. */
4201 get_set_constructor_bytes (init, buffer, wd_size)
4203 unsigned char *buffer;
4207 tree vals = TREE_OPERAND (init, 1);
4208 int set_word_size = BITS_PER_UNIT;
4209 int bit_size = wd_size * set_word_size;
4211 unsigned char *bytep = buffer;
4212 char *bit_buffer = (char*)alloca(bit_size);
4213 tree non_const_bits = get_set_constructor_bits (init, bit_buffer, bit_size);
4215 for (i = 0; i < wd_size; i++)
4218 for (i = 0; i < bit_size; i++)
4222 if (BITS_BIG_ENDIAN)
4223 *bytep |= (1 << (set_word_size - 1 - bit_pos));
4225 *bytep |= 1 << bit_pos;
4228 if (bit_pos >= set_word_size)
4229 bit_pos = 0, bytep++;
4231 return non_const_bits;