xref: /openbsd/gnu/usr.bin/gcc/gcc/tree.c (revision 4e43c760)
1 /* Language-independent node constructors for parse phase of GNU compiler.
2    Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3    1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
4 
5 This file is part of GCC.
6 
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11 
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING.  If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA.  */
21 
22 /* This file contains the low level primitives for operating on tree nodes,
23    including allocation, list operations, interning of identifiers,
24    construction of data type nodes and statement nodes,
25    and construction of type conversion nodes.  It also contains
26    tables index by tree code that describe how to take apart
27    nodes of that code.
28 
29    It is intended to be language-independent, but occasionally
30    calls language-dependent routines defined (for C) in typecheck.c.  */
31 
32 #include "config.h"
33 #include "system.h"
34 #include "flags.h"
35 #include "tree.h"
36 #include "real.h"
37 #include "tm_p.h"
38 #include "function.h"
39 #include "obstack.h"
40 #include "toplev.h"
41 #include "ggc.h"
42 #include "hashtab.h"
43 #include "output.h"
44 #include "target.h"
45 #include "langhooks.h"
46 
47 /* obstack.[ch] explicitly declined to prototype this.  */
48 extern int _obstack_allocated_p PARAMS ((struct obstack *h, PTR obj));
49 
50 #ifdef GATHER_STATISTICS
51 /* Statistics-gathering stuff.  */
52 typedef enum
53 {
54   d_kind,
55   t_kind,
56   b_kind,
57   s_kind,
58   r_kind,
59   e_kind,
60   c_kind,
61   id_kind,
62   perm_list_kind,
63   temp_list_kind,
64   vec_kind,
65   x_kind,
66   lang_decl,
67   lang_type,
68   all_kinds
69 } tree_node_kind;
70 
71 int tree_node_counts[(int) all_kinds];
72 int tree_node_sizes[(int) all_kinds];
73 
74 static const char * const tree_node_kind_names[] = {
75   "decls",
76   "types",
77   "blocks",
78   "stmts",
79   "refs",
80   "exprs",
81   "constants",
82   "identifiers",
83   "perm_tree_lists",
84   "temp_tree_lists",
85   "vecs",
86   "random kinds",
87   "lang_decl kinds",
88   "lang_type kinds"
89 };
90 #endif /* GATHER_STATISTICS */
91 
92 /* Unique id for next decl created.  */
93 static int next_decl_uid;
94 /* Unique id for next type created.  */
95 static int next_type_uid = 1;
96 
97 /* Since we cannot rehash a type after it is in the table, we have to
98    keep the hash code.  */
99 
100 struct type_hash GTY(())
101 {
102   unsigned long hash;
103   tree type;
104 };
105 
106 /* Initial size of the hash table (rounded to next prime).  */
107 #define TYPE_HASH_INITIAL_SIZE 1000
108 
109 /* Now here is the hash table.  When recording a type, it is added to
110    the slot whose index is the hash code.  Note that the hash table is
111    used for several kinds of types (function types, array types and
112    array index range types, for now).  While all these live in the
113    same table, they are completely independent, and the hash code is
114    computed differently for each of these.  */
115 
116 static GTY ((if_marked ("type_hash_marked_p"), param_is (struct type_hash)))
117      htab_t type_hash_table;
118 
119 static void set_type_quals PARAMS ((tree, int));
120 static void append_random_chars PARAMS ((char *));
121 static int type_hash_eq PARAMS ((const void *, const void *));
122 static hashval_t type_hash_hash PARAMS ((const void *));
123 static void print_type_hash_statistics PARAMS((void));
124 static void finish_vector_type PARAMS((tree));
125 static tree make_vector PARAMS ((enum machine_mode, tree, int));
126 static int type_hash_marked_p PARAMS ((const void *));
127 
128 tree global_trees[TI_MAX];
129 tree integer_types[itk_none];
130 
131 /* Init tree.c.  */
132 
133 void
init_ttree()134 init_ttree ()
135 {
136   /* Initialize the hash table of types.  */
137   type_hash_table = htab_create (TYPE_HASH_INITIAL_SIZE, type_hash_hash,
138 				 type_hash_eq, 0);
139 }
140 
141 
142 /* The name of the object as the assembler will see it (but before any
143    translations made by ASM_OUTPUT_LABELREF).  Often this is the same
144    as DECL_NAME.  It is an IDENTIFIER_NODE.  */
145 tree
decl_assembler_name(decl)146 decl_assembler_name (decl)
147      tree decl;
148 {
149   if (!DECL_ASSEMBLER_NAME_SET_P (decl))
150     (*lang_hooks.set_decl_assembler_name) (decl);
151   return DECL_CHECK (decl)->decl.assembler_name;
152 }
153 
154 /* Compute the number of bytes occupied by 'node'.  This routine only
155    looks at TREE_CODE and, if the code is TREE_VEC, TREE_VEC_LENGTH.  */
156 size_t
tree_size(node)157 tree_size (node)
158      tree node;
159 {
160   enum tree_code code = TREE_CODE (node);
161 
162   switch (TREE_CODE_CLASS (code))
163     {
164     case 'd':  /* A decl node */
165       return sizeof (struct tree_decl);
166 
167     case 't':  /* a type node */
168       return sizeof (struct tree_type);
169 
170     case 'b':  /* a lexical block node */
171       return sizeof (struct tree_block);
172 
173     case 'r':  /* a reference */
174     case 'e':  /* an expression */
175     case 's':  /* an expression with side effects */
176     case '<':  /* a comparison expression */
177     case '1':  /* a unary arithmetic expression */
178     case '2':  /* a binary arithmetic expression */
179       return (sizeof (struct tree_exp)
180 	      + TREE_CODE_LENGTH (code) * sizeof (char *) - sizeof (char *));
181 
182     case 'c':  /* a constant */
183       /* We can't use TREE_CODE_LENGTH for INTEGER_CST, since the number of
184 	 words is machine-dependent due to varying length of HOST_WIDE_INT,
185 	 which might be wider than a pointer (e.g., long long).  Similarly
186 	 for REAL_CST, since the number of words is machine-dependent due
187 	 to varying size and alignment of `double'.  */
188       if (code == INTEGER_CST)
189 	return sizeof (struct tree_int_cst);
190       else if (code == REAL_CST)
191 	return sizeof (struct tree_real_cst);
192       else
193 	return (sizeof (struct tree_common)
194 		+ TREE_CODE_LENGTH (code) * sizeof (char *));
195 
196     case 'x':  /* something random, like an identifier.  */
197       {
198 	size_t length;
199 	length = (sizeof (struct tree_common)
200 		  + TREE_CODE_LENGTH (code) * sizeof (char *));
201 	if (code == TREE_VEC)
202 	  length += TREE_VEC_LENGTH (node) * sizeof (char *) - sizeof (char *);
203 	return length;
204       }
205 
206     default:
207       abort ();
208     }
209 }
210 
211 /* Return a newly allocated node of code CODE.
212    For decl and type nodes, some other fields are initialized.
213    The rest of the node is initialized to zero.
214 
215    Achoo!  I got a code in the node.  */
216 
217 tree
make_node(code)218 make_node (code)
219      enum tree_code code;
220 {
221   tree t;
222   int type = TREE_CODE_CLASS (code);
223   size_t length;
224 #ifdef GATHER_STATISTICS
225   tree_node_kind kind;
226 #endif
227   struct tree_common ttmp;
228 
229   /* We can't allocate a TREE_VEC without knowing how many elements
230      it will have.  */
231   if (code == TREE_VEC)
232     abort ();
233 
234   TREE_SET_CODE ((tree)&ttmp, code);
235   length = tree_size ((tree)&ttmp);
236 
237 #ifdef GATHER_STATISTICS
238   switch (type)
239     {
240     case 'd':  /* A decl node */
241       kind = d_kind;
242       break;
243 
244     case 't':  /* a type node */
245       kind = t_kind;
246       break;
247 
248     case 'b':  /* a lexical block */
249       kind = b_kind;
250       break;
251 
252     case 's':  /* an expression with side effects */
253       kind = s_kind;
254       break;
255 
256     case 'r':  /* a reference */
257       kind = r_kind;
258       break;
259 
260     case 'e':  /* an expression */
261     case '<':  /* a comparison expression */
262     case '1':  /* a unary arithmetic expression */
263     case '2':  /* a binary arithmetic expression */
264       kind = e_kind;
265       break;
266 
267     case 'c':  /* a constant */
268       kind = c_kind;
269       break;
270 
271     case 'x':  /* something random, like an identifier.  */
272       if (code == IDENTIFIER_NODE)
273 	kind = id_kind;
274       else if (code == TREE_VEC)
275 	kind = vec_kind;
276       else
277 	kind = x_kind;
278       break;
279 
280     default:
281       abort ();
282     }
283 
284   tree_node_counts[(int) kind]++;
285   tree_node_sizes[(int) kind] += length;
286 #endif
287 
288   t = ggc_alloc_tree (length);
289 
290   memset ((PTR) t, 0, length);
291 
292   TREE_SET_CODE (t, code);
293 
294   switch (type)
295     {
296     case 's':
297       TREE_SIDE_EFFECTS (t) = 1;
298       TREE_TYPE (t) = void_type_node;
299       break;
300 
301     case 'd':
302       if (code != FUNCTION_DECL)
303 	DECL_ALIGN (t) = 1;
304       DECL_USER_ALIGN (t) = 0;
305       DECL_IN_SYSTEM_HEADER (t) = in_system_header;
306       DECL_SOURCE_LINE (t) = lineno;
307       DECL_SOURCE_FILE (t) =
308 	(input_filename) ? input_filename : "<built-in>";
309       DECL_UID (t) = next_decl_uid++;
310 
311       /* We have not yet computed the alias set for this declaration.  */
312       DECL_POINTER_ALIAS_SET (t) = -1;
313       break;
314 
315     case 't':
316       TYPE_UID (t) = next_type_uid++;
317       TYPE_ALIGN (t) = char_type_node ? TYPE_ALIGN (char_type_node) : 0;
318       TYPE_USER_ALIGN (t) = 0;
319       TYPE_MAIN_VARIANT (t) = t;
320 
321       /* Default to no attributes for type, but let target change that.  */
322       TYPE_ATTRIBUTES (t) = NULL_TREE;
323       (*targetm.set_default_type_attributes) (t);
324 
325       /* We have not yet computed the alias set for this type.  */
326       TYPE_ALIAS_SET (t) = -1;
327       break;
328 
329     case 'c':
330       TREE_CONSTANT (t) = 1;
331       break;
332 
333     case 'e':
334       switch (code)
335 	{
336 	case INIT_EXPR:
337 	case MODIFY_EXPR:
338 	case VA_ARG_EXPR:
339 	case RTL_EXPR:
340 	case PREDECREMENT_EXPR:
341 	case PREINCREMENT_EXPR:
342 	case POSTDECREMENT_EXPR:
343 	case POSTINCREMENT_EXPR:
344 	  /* All of these have side-effects, no matter what their
345 	     operands are.  */
346 	  TREE_SIDE_EFFECTS (t) = 1;
347 	  break;
348 
349 	default:
350 	  break;
351 	}
352       break;
353     }
354 
355   return t;
356 }
357 
358 /* Return a new node with the same contents as NODE except that its
359    TREE_CHAIN is zero and it has a fresh uid.  */
360 
361 tree
copy_node(node)362 copy_node (node)
363      tree node;
364 {
365   tree t;
366   enum tree_code code = TREE_CODE (node);
367   size_t length;
368 
369   length = tree_size (node);
370   t = ggc_alloc_tree (length);
371   memcpy (t, node, length);
372 
373   TREE_CHAIN (t) = 0;
374   TREE_ASM_WRITTEN (t) = 0;
375 
376   if (TREE_CODE_CLASS (code) == 'd')
377     DECL_UID (t) = next_decl_uid++;
378   else if (TREE_CODE_CLASS (code) == 't')
379     {
380       TYPE_UID (t) = next_type_uid++;
381       /* The following is so that the debug code for
382 	 the copy is different from the original type.
383 	 The two statements usually duplicate each other
384 	 (because they clear fields of the same union),
385 	 but the optimizer should catch that.  */
386       TYPE_SYMTAB_POINTER (t) = 0;
387       TYPE_SYMTAB_ADDRESS (t) = 0;
388     }
389 
390   return t;
391 }
392 
393 /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
394    For example, this can copy a list made of TREE_LIST nodes.  */
395 
396 tree
copy_list(list)397 copy_list (list)
398      tree list;
399 {
400   tree head;
401   tree prev, next;
402 
403   if (list == 0)
404     return 0;
405 
406   head = prev = copy_node (list);
407   next = TREE_CHAIN (list);
408   while (next)
409     {
410       TREE_CHAIN (prev) = copy_node (next);
411       prev = TREE_CHAIN (prev);
412       next = TREE_CHAIN (next);
413     }
414   return head;
415 }
416 
417 
418 /* Return a newly constructed INTEGER_CST node whose constant value
419    is specified by the two ints LOW and HI.
420    The TREE_TYPE is set to `int'.
421 
422    This function should be used via the `build_int_2' macro.  */
423 
424 tree
build_int_2_wide(low,hi)425 build_int_2_wide (low, hi)
426      unsigned HOST_WIDE_INT low;
427      HOST_WIDE_INT hi;
428 {
429   tree t = make_node (INTEGER_CST);
430 
431   TREE_INT_CST_LOW (t) = low;
432   TREE_INT_CST_HIGH (t) = hi;
433   TREE_TYPE (t) = integer_type_node;
434   return t;
435 }
436 
437 /* Return a new VECTOR_CST node whose type is TYPE and whose values
438    are in a list pointed by VALS.  */
439 
440 tree
build_vector(type,vals)441 build_vector (type, vals)
442      tree type, vals;
443 {
444   tree v = make_node (VECTOR_CST);
445   int over1 = 0, over2 = 0;
446   tree link;
447 
448   TREE_VECTOR_CST_ELTS (v) = vals;
449   TREE_TYPE (v) = type;
450 
451   /* Iterate through elements and check for overflow.  */
452   for (link = vals; link; link = TREE_CHAIN (link))
453     {
454       tree value = TREE_VALUE (link);
455 
456       over1 |= TREE_OVERFLOW (value);
457       over2 |= TREE_CONSTANT_OVERFLOW (value);
458     }
459 
460   TREE_OVERFLOW (v) = over1;
461   TREE_CONSTANT_OVERFLOW (v) = over2;
462 
463   return v;
464 }
465 
466 /* Return a new REAL_CST node whose type is TYPE and value is D.  */
467 
468 tree
build_real(type,d)469 build_real (type, d)
470      tree type;
471      REAL_VALUE_TYPE d;
472 {
473   tree v;
474   REAL_VALUE_TYPE *dp;
475   int overflow = 0;
476 
477   /* ??? Used to check for overflow here via CHECK_FLOAT_TYPE.
478      Consider doing it via real_convert now.  */
479 
480   v = make_node (REAL_CST);
481   dp = ggc_alloc (sizeof (REAL_VALUE_TYPE));
482   memcpy (dp, &d, sizeof (REAL_VALUE_TYPE));
483 
484   TREE_TYPE (v) = type;
485   TREE_REAL_CST_PTR (v) = dp;
486   TREE_OVERFLOW (v) = TREE_CONSTANT_OVERFLOW (v) = overflow;
487   return v;
488 }
489 
490 /* Return a new REAL_CST node whose type is TYPE
491    and whose value is the integer value of the INTEGER_CST node I.  */
492 
493 REAL_VALUE_TYPE
real_value_from_int_cst(type,i)494 real_value_from_int_cst (type, i)
495      tree type ATTRIBUTE_UNUSED, i;
496 {
497   REAL_VALUE_TYPE d;
498 
499   /* Clear all bits of the real value type so that we can later do
500      bitwise comparisons to see if two values are the same.  */
501   memset ((char *) &d, 0, sizeof d);
502 
503   if (! TREE_UNSIGNED (TREE_TYPE (i)))
504     REAL_VALUE_FROM_INT (d, TREE_INT_CST_LOW (i), TREE_INT_CST_HIGH (i),
505 			 TYPE_MODE (type));
506   else
507     REAL_VALUE_FROM_UNSIGNED_INT (d, TREE_INT_CST_LOW (i),
508 				  TREE_INT_CST_HIGH (i), TYPE_MODE (type));
509   return d;
510 }
511 
512 /* Given a tree representing an integer constant I, return a tree
513    representing the same value as a floating-point constant of type TYPE.  */
514 
515 tree
build_real_from_int_cst(type,i)516 build_real_from_int_cst (type, i)
517      tree type;
518      tree i;
519 {
520   tree v;
521   int overflow = TREE_OVERFLOW (i);
522 
523   v = build_real (type, real_value_from_int_cst (type, i));
524 
525   TREE_OVERFLOW (v) |= overflow;
526   TREE_CONSTANT_OVERFLOW (v) |= overflow;
527   return v;
528 }
529 
530 /* Return a newly constructed STRING_CST node whose value is
531    the LEN characters at STR.
532    The TREE_TYPE is not initialized.  */
533 
534 tree
build_string(len,str)535 build_string (len, str)
536      int len;
537      const char *str;
538 {
539   tree s = make_node (STRING_CST);
540 
541   TREE_STRING_LENGTH (s) = len;
542   TREE_STRING_POINTER (s) = ggc_alloc_string (str, len);
543 
544   return s;
545 }
546 
547 /* Return a newly constructed COMPLEX_CST node whose value is
548    specified by the real and imaginary parts REAL and IMAG.
549    Both REAL and IMAG should be constant nodes.  TYPE, if specified,
550    will be the type of the COMPLEX_CST; otherwise a new type will be made.  */
551 
552 tree
build_complex(type,real,imag)553 build_complex (type, real, imag)
554      tree type;
555      tree real, imag;
556 {
557   tree t = make_node (COMPLEX_CST);
558 
559   TREE_REALPART (t) = real;
560   TREE_IMAGPART (t) = imag;
561   TREE_TYPE (t) = type ? type : build_complex_type (TREE_TYPE (real));
562   TREE_OVERFLOW (t) = TREE_OVERFLOW (real) | TREE_OVERFLOW (imag);
563   TREE_CONSTANT_OVERFLOW (t)
564     = TREE_CONSTANT_OVERFLOW (real) | TREE_CONSTANT_OVERFLOW (imag);
565   return t;
566 }
567 
568 /* Build a newly constructed TREE_VEC node of length LEN.  */
569 
570 tree
make_tree_vec(len)571 make_tree_vec (len)
572      int len;
573 {
574   tree t;
575   int length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
576 
577 #ifdef GATHER_STATISTICS
578   tree_node_counts[(int) vec_kind]++;
579   tree_node_sizes[(int) vec_kind] += length;
580 #endif
581 
582   t = ggc_alloc_tree (length);
583 
584   memset ((PTR) t, 0, length);
585   TREE_SET_CODE (t, TREE_VEC);
586   TREE_VEC_LENGTH (t) = len;
587 
588   return t;
589 }
590 
591 /* Return 1 if EXPR is the integer constant zero or a complex constant
592    of zero.  */
593 
594 int
integer_zerop(expr)595 integer_zerop (expr)
596      tree expr;
597 {
598   STRIP_NOPS (expr);
599 
600   return ((TREE_CODE (expr) == INTEGER_CST
601 	   && ! TREE_CONSTANT_OVERFLOW (expr)
602 	   && TREE_INT_CST_LOW (expr) == 0
603 	   && TREE_INT_CST_HIGH (expr) == 0)
604 	  || (TREE_CODE (expr) == COMPLEX_CST
605 	      && integer_zerop (TREE_REALPART (expr))
606 	      && integer_zerop (TREE_IMAGPART (expr))));
607 }
608 
609 /* Return 1 if EXPR is the integer constant one or the corresponding
610    complex constant.  */
611 
612 int
integer_onep(expr)613 integer_onep (expr)
614      tree expr;
615 {
616   STRIP_NOPS (expr);
617 
618   return ((TREE_CODE (expr) == INTEGER_CST
619 	   && ! TREE_CONSTANT_OVERFLOW (expr)
620 	   && TREE_INT_CST_LOW (expr) == 1
621 	   && TREE_INT_CST_HIGH (expr) == 0)
622 	  || (TREE_CODE (expr) == COMPLEX_CST
623 	      && integer_onep (TREE_REALPART (expr))
624 	      && integer_zerop (TREE_IMAGPART (expr))));
625 }
626 
627 /* Return 1 if EXPR is an integer containing all 1's in as much precision as
628    it contains.  Likewise for the corresponding complex constant.  */
629 
630 int
integer_all_onesp(expr)631 integer_all_onesp (expr)
632      tree expr;
633 {
634   int prec;
635   int uns;
636 
637   STRIP_NOPS (expr);
638 
639   if (TREE_CODE (expr) == COMPLEX_CST
640       && integer_all_onesp (TREE_REALPART (expr))
641       && integer_zerop (TREE_IMAGPART (expr)))
642     return 1;
643 
644   else if (TREE_CODE (expr) != INTEGER_CST
645 	   || TREE_CONSTANT_OVERFLOW (expr))
646     return 0;
647 
648   uns = TREE_UNSIGNED (TREE_TYPE (expr));
649   if (!uns)
650     return (TREE_INT_CST_LOW (expr) == ~(unsigned HOST_WIDE_INT) 0
651 	    && TREE_INT_CST_HIGH (expr) == -1);
652 
653   /* Note that using TYPE_PRECISION here is wrong.  We care about the
654      actual bits, not the (arbitrary) range of the type.  */
655   prec = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (expr)));
656   if (prec >= HOST_BITS_PER_WIDE_INT)
657     {
658       HOST_WIDE_INT high_value;
659       int shift_amount;
660 
661       shift_amount = prec - HOST_BITS_PER_WIDE_INT;
662 
663       if (shift_amount > HOST_BITS_PER_WIDE_INT)
664 	/* Can not handle precisions greater than twice the host int size.  */
665 	abort ();
666       else if (shift_amount == HOST_BITS_PER_WIDE_INT)
667 	/* Shifting by the host word size is undefined according to the ANSI
668 	   standard, so we must handle this as a special case.  */
669 	high_value = -1;
670       else
671 	high_value = ((HOST_WIDE_INT) 1 << shift_amount) - 1;
672 
673       return (TREE_INT_CST_LOW (expr) == ~(unsigned HOST_WIDE_INT) 0
674 	      && TREE_INT_CST_HIGH (expr) == high_value);
675     }
676   else
677     return TREE_INT_CST_LOW (expr) == ((unsigned HOST_WIDE_INT) 1 << prec) - 1;
678 }
679 
680 /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only
681    one bit on).  */
682 
683 int
integer_pow2p(expr)684 integer_pow2p (expr)
685      tree expr;
686 {
687   int prec;
688   HOST_WIDE_INT high, low;
689 
690   STRIP_NOPS (expr);
691 
692   if (TREE_CODE (expr) == COMPLEX_CST
693       && integer_pow2p (TREE_REALPART (expr))
694       && integer_zerop (TREE_IMAGPART (expr)))
695     return 1;
696 
697   if (TREE_CODE (expr) != INTEGER_CST || TREE_CONSTANT_OVERFLOW (expr))
698     return 0;
699 
700   prec = (POINTER_TYPE_P (TREE_TYPE (expr))
701 	  ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr)));
702   high = TREE_INT_CST_HIGH (expr);
703   low = TREE_INT_CST_LOW (expr);
704 
705   /* First clear all bits that are beyond the type's precision in case
706      we've been sign extended.  */
707 
708   if (prec == 2 * HOST_BITS_PER_WIDE_INT)
709     ;
710   else if (prec > HOST_BITS_PER_WIDE_INT)
711     high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
712   else
713     {
714       high = 0;
715       if (prec < HOST_BITS_PER_WIDE_INT)
716 	low &= ~((HOST_WIDE_INT) (-1) << prec);
717     }
718 
719   if (high == 0 && low == 0)
720     return 0;
721 
722   return ((high == 0 && (low & (low - 1)) == 0)
723 	  || (low == 0 && (high & (high - 1)) == 0));
724 }
725 
726 /* Return 1 if EXPR is an integer constant other than zero or a
727    complex constant other than zero.  */
728 
729 int
integer_nonzerop(expr)730 integer_nonzerop (expr)
731      tree expr;
732 {
733   STRIP_NOPS (expr);
734 
735   return ((TREE_CODE (expr) == INTEGER_CST
736 	   && ! TREE_CONSTANT_OVERFLOW (expr)
737 	   && (TREE_INT_CST_LOW (expr) != 0
738 	       || TREE_INT_CST_HIGH (expr) != 0))
739 	  || (TREE_CODE (expr) == COMPLEX_CST
740 	      && (integer_nonzerop (TREE_REALPART (expr))
741 		  || integer_nonzerop (TREE_IMAGPART (expr)))));
742 }
743 
744 /* Return the power of two represented by a tree node known to be a
745    power of two.  */
746 
747 int
tree_log2(expr)748 tree_log2 (expr)
749      tree expr;
750 {
751   int prec;
752   HOST_WIDE_INT high, low;
753 
754   STRIP_NOPS (expr);
755 
756   if (TREE_CODE (expr) == COMPLEX_CST)
757     return tree_log2 (TREE_REALPART (expr));
758 
759   prec = (POINTER_TYPE_P (TREE_TYPE (expr))
760 	  ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr)));
761 
762   high = TREE_INT_CST_HIGH (expr);
763   low = TREE_INT_CST_LOW (expr);
764 
765   /* First clear all bits that are beyond the type's precision in case
766      we've been sign extended.  */
767 
768   if (prec == 2 * HOST_BITS_PER_WIDE_INT)
769     ;
770   else if (prec > HOST_BITS_PER_WIDE_INT)
771     high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
772   else
773     {
774       high = 0;
775       if (prec < HOST_BITS_PER_WIDE_INT)
776 	low &= ~((HOST_WIDE_INT) (-1) << prec);
777     }
778 
779   return (high != 0 ? HOST_BITS_PER_WIDE_INT + exact_log2 (high)
780 	  : exact_log2 (low));
781 }
782 
783 /* Similar, but return the largest integer Y such that 2 ** Y is less
784    than or equal to EXPR.  */
785 
786 int
tree_floor_log2(expr)787 tree_floor_log2 (expr)
788      tree expr;
789 {
790   int prec;
791   HOST_WIDE_INT high, low;
792 
793   STRIP_NOPS (expr);
794 
795   if (TREE_CODE (expr) == COMPLEX_CST)
796     return tree_log2 (TREE_REALPART (expr));
797 
798   prec = (POINTER_TYPE_P (TREE_TYPE (expr))
799 	  ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr)));
800 
801   high = TREE_INT_CST_HIGH (expr);
802   low = TREE_INT_CST_LOW (expr);
803 
804   /* First clear all bits that are beyond the type's precision in case
805      we've been sign extended.  Ignore if type's precision hasn't been set
806      since what we are doing is setting it.  */
807 
808   if (prec == 2 * HOST_BITS_PER_WIDE_INT || prec == 0)
809     ;
810   else if (prec > HOST_BITS_PER_WIDE_INT)
811     high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
812   else
813     {
814       high = 0;
815       if (prec < HOST_BITS_PER_WIDE_INT)
816 	low &= ~((HOST_WIDE_INT) (-1) << prec);
817     }
818 
819   return (high != 0 ? HOST_BITS_PER_WIDE_INT + floor_log2 (high)
820 	  : floor_log2 (low));
821 }
822 
823 /* Return 1 if EXPR is the real constant zero.  */
824 
825 int
real_zerop(expr)826 real_zerop (expr)
827      tree expr;
828 {
829   STRIP_NOPS (expr);
830 
831   return ((TREE_CODE (expr) == REAL_CST
832 	   && ! TREE_CONSTANT_OVERFLOW (expr)
833 	   && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst0))
834 	  || (TREE_CODE (expr) == COMPLEX_CST
835 	      && real_zerop (TREE_REALPART (expr))
836 	      && real_zerop (TREE_IMAGPART (expr))));
837 }
838 
839 /* Return 1 if EXPR is the real constant one in real or complex form.  */
840 
841 int
real_onep(expr)842 real_onep (expr)
843      tree expr;
844 {
845   STRIP_NOPS (expr);
846 
847   return ((TREE_CODE (expr) == REAL_CST
848 	   && ! TREE_CONSTANT_OVERFLOW (expr)
849 	   && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst1))
850 	  || (TREE_CODE (expr) == COMPLEX_CST
851 	      && real_onep (TREE_REALPART (expr))
852 	      && real_zerop (TREE_IMAGPART (expr))));
853 }
854 
855 /* Return 1 if EXPR is the real constant two.  */
856 
857 int
real_twop(expr)858 real_twop (expr)
859      tree expr;
860 {
861   STRIP_NOPS (expr);
862 
863   return ((TREE_CODE (expr) == REAL_CST
864 	   && ! TREE_CONSTANT_OVERFLOW (expr)
865 	   && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst2))
866 	  || (TREE_CODE (expr) == COMPLEX_CST
867 	      && real_twop (TREE_REALPART (expr))
868 	      && real_zerop (TREE_IMAGPART (expr))));
869 }
870 
871 /* Return 1 if EXPR is the real constant minus one.  */
872 
873 int
real_minus_onep(expr)874 real_minus_onep (expr)
875      tree expr;
876 {
877   STRIP_NOPS (expr);
878 
879   return ((TREE_CODE (expr) == REAL_CST
880 	   && ! TREE_CONSTANT_OVERFLOW (expr)
881 	   && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconstm1))
882 	  || (TREE_CODE (expr) == COMPLEX_CST
883 	      && real_minus_onep (TREE_REALPART (expr))
884 	      && real_zerop (TREE_IMAGPART (expr))));
885 }
886 
887 /* Nonzero if EXP is a constant or a cast of a constant.  */
888 
889 int
really_constant_p(exp)890 really_constant_p (exp)
891      tree exp;
892 {
893   /* This is not quite the same as STRIP_NOPS.  It does more.  */
894   while (TREE_CODE (exp) == NOP_EXPR
895 	 || TREE_CODE (exp) == CONVERT_EXPR
896 	 || TREE_CODE (exp) == NON_LVALUE_EXPR)
897     exp = TREE_OPERAND (exp, 0);
898   return TREE_CONSTANT (exp);
899 }
900 
901 /* Return first list element whose TREE_VALUE is ELEM.
902    Return 0 if ELEM is not in LIST.  */
903 
904 tree
value_member(elem,list)905 value_member (elem, list)
906      tree elem, list;
907 {
908   while (list)
909     {
910       if (elem == TREE_VALUE (list))
911 	return list;
912       list = TREE_CHAIN (list);
913     }
914   return NULL_TREE;
915 }
916 
917 /* Return first list element whose TREE_PURPOSE is ELEM.
918    Return 0 if ELEM is not in LIST.  */
919 
920 tree
purpose_member(elem,list)921 purpose_member (elem, list)
922      tree elem, list;
923 {
924   while (list)
925     {
926       if (elem == TREE_PURPOSE (list))
927 	return list;
928       list = TREE_CHAIN (list);
929     }
930   return NULL_TREE;
931 }
932 
933 /* Return first list element whose BINFO_TYPE is ELEM.
934    Return 0 if ELEM is not in LIST.  */
935 
936 tree
binfo_member(elem,list)937 binfo_member (elem, list)
938      tree elem, list;
939 {
940   while (list)
941     {
942       if (elem == BINFO_TYPE (list))
943 	return list;
944       list = TREE_CHAIN (list);
945     }
946   return NULL_TREE;
947 }
948 
949 /* Return nonzero if ELEM is part of the chain CHAIN.  */
950 
951 int
chain_member(elem,chain)952 chain_member (elem, chain)
953      tree elem, chain;
954 {
955   while (chain)
956     {
957       if (elem == chain)
958 	return 1;
959       chain = TREE_CHAIN (chain);
960     }
961 
962   return 0;
963 }
964 
965 /* Return nonzero if ELEM is equal to TREE_VALUE (CHAIN) for any piece of
966    chain CHAIN.  This and the next function are currently unused, but
967    are retained for completeness.  */
968 
969 int
chain_member_value(elem,chain)970 chain_member_value (elem, chain)
971      tree elem, chain;
972 {
973   while (chain)
974     {
975       if (elem == TREE_VALUE (chain))
976 	return 1;
977       chain = TREE_CHAIN (chain);
978     }
979 
980   return 0;
981 }
982 
983 /* Return nonzero if ELEM is equal to TREE_PURPOSE (CHAIN)
984    for any piece of chain CHAIN.  */
985 
986 int
chain_member_purpose(elem,chain)987 chain_member_purpose (elem, chain)
988      tree elem, chain;
989 {
990   while (chain)
991     {
992       if (elem == TREE_PURPOSE (chain))
993 	return 1;
994       chain = TREE_CHAIN (chain);
995     }
996 
997   return 0;
998 }
999 
1000 /* Return the length of a chain of nodes chained through TREE_CHAIN.
1001    We expect a null pointer to mark the end of the chain.
1002    This is the Lisp primitive `length'.  */
1003 
1004 int
list_length(t)1005 list_length (t)
1006      tree t;
1007 {
1008   tree tail;
1009   int len = 0;
1010 
1011   for (tail = t; tail; tail = TREE_CHAIN (tail))
1012     len++;
1013 
1014   return len;
1015 }
1016 
1017 /* Returns the number of FIELD_DECLs in TYPE.  */
1018 
1019 int
fields_length(type)1020 fields_length (type)
1021      tree type;
1022 {
1023   tree t = TYPE_FIELDS (type);
1024   int count = 0;
1025 
1026   for (; t; t = TREE_CHAIN (t))
1027     if (TREE_CODE (t) == FIELD_DECL)
1028       ++count;
1029 
1030   return count;
1031 }
1032 
1033 /* Concatenate two chains of nodes (chained through TREE_CHAIN)
1034    by modifying the last node in chain 1 to point to chain 2.
1035    This is the Lisp primitive `nconc'.  */
1036 
1037 tree
chainon(op1,op2)1038 chainon (op1, op2)
1039      tree op1, op2;
1040 {
1041 
1042   if (op1)
1043     {
1044       tree t1;
1045 #ifdef ENABLE_TREE_CHECKING
1046       tree t2;
1047 #endif
1048 
1049       for (t1 = op1; TREE_CHAIN (t1); t1 = TREE_CHAIN (t1))
1050 	;
1051       TREE_CHAIN (t1) = op2;
1052 #ifdef ENABLE_TREE_CHECKING
1053       for (t2 = op2; t2; t2 = TREE_CHAIN (t2))
1054 	if (t2 == t1)
1055 	  abort ();  /* Circularity created.  */
1056 #endif
1057       return op1;
1058     }
1059   else
1060     return op2;
1061 }
1062 
1063 /* Return the last node in a chain of nodes (chained through TREE_CHAIN).  */
1064 
1065 tree
tree_last(chain)1066 tree_last (chain)
1067      tree chain;
1068 {
1069   tree next;
1070   if (chain)
1071     while ((next = TREE_CHAIN (chain)))
1072       chain = next;
1073   return chain;
1074 }
1075 
1076 /* Reverse the order of elements in the chain T,
1077    and return the new head of the chain (old last element).  */
1078 
1079 tree
nreverse(t)1080 nreverse (t)
1081      tree t;
1082 {
1083   tree prev = 0, decl, next;
1084   for (decl = t; decl; decl = next)
1085     {
1086       next = TREE_CHAIN (decl);
1087       TREE_CHAIN (decl) = prev;
1088       prev = decl;
1089     }
1090   return prev;
1091 }
1092 
1093 /* Given a chain CHAIN of tree nodes,
1094    construct and return a list of those nodes.  */
1095 
1096 tree
listify(chain)1097 listify (chain)
1098      tree chain;
1099 {
1100   tree result = NULL_TREE;
1101   tree in_tail = chain;
1102   tree out_tail = NULL_TREE;
1103 
1104   while (in_tail)
1105     {
1106       tree next = tree_cons (NULL_TREE, in_tail, NULL_TREE);
1107       if (out_tail)
1108 	TREE_CHAIN (out_tail) = next;
1109       else
1110 	result = next;
1111       out_tail = next;
1112       in_tail = TREE_CHAIN (in_tail);
1113     }
1114 
1115   return result;
1116 }
1117 
1118 /* Return a newly created TREE_LIST node whose
1119    purpose and value fields are PARM and VALUE.  */
1120 
1121 tree
build_tree_list(parm,value)1122 build_tree_list (parm, value)
1123      tree parm, value;
1124 {
1125   tree t = make_node (TREE_LIST);
1126   TREE_PURPOSE (t) = parm;
1127   TREE_VALUE (t) = value;
1128   return t;
1129 }
1130 
1131 /* Return a newly created TREE_LIST node whose
1132    purpose and value fields are PARM and VALUE
1133    and whose TREE_CHAIN is CHAIN.  */
1134 
1135 tree
tree_cons(purpose,value,chain)1136 tree_cons (purpose, value, chain)
1137      tree purpose, value, chain;
1138 {
1139   tree node;
1140 
1141   node = ggc_alloc_tree (sizeof (struct tree_list));
1142 
1143   memset (node, 0, sizeof (struct tree_common));
1144 
1145 #ifdef GATHER_STATISTICS
1146   tree_node_counts[(int) x_kind]++;
1147   tree_node_sizes[(int) x_kind] += sizeof (struct tree_list);
1148 #endif
1149 
1150   TREE_SET_CODE (node, TREE_LIST);
1151   TREE_CHAIN (node) = chain;
1152   TREE_PURPOSE (node) = purpose;
1153   TREE_VALUE (node) = value;
1154   return node;
1155 }
1156 
1157 
1158 /* Return the size nominally occupied by an object of type TYPE
1159    when it resides in memory.  The value is measured in units of bytes,
1160    and its data type is that normally used for type sizes
1161    (which is the first type created by make_signed_type or
1162    make_unsigned_type).  */
1163 
1164 tree
size_in_bytes(type)1165 size_in_bytes (type)
1166      tree type;
1167 {
1168   tree t;
1169 
1170   if (type == error_mark_node)
1171     return integer_zero_node;
1172 
1173   type = TYPE_MAIN_VARIANT (type);
1174   t = TYPE_SIZE_UNIT (type);
1175 
1176   if (t == 0)
1177     {
1178       (*lang_hooks.types.incomplete_type_error) (NULL_TREE, type);
1179       return size_zero_node;
1180     }
1181 
1182   if (TREE_CODE (t) == INTEGER_CST)
1183     force_fit_type (t, 0);
1184 
1185   return t;
1186 }
1187 
1188 /* Return the size of TYPE (in bytes) as a wide integer
1189    or return -1 if the size can vary or is larger than an integer.  */
1190 
1191 HOST_WIDE_INT
int_size_in_bytes(type)1192 int_size_in_bytes (type)
1193      tree type;
1194 {
1195   tree t;
1196 
1197   if (type == error_mark_node)
1198     return 0;
1199 
1200   type = TYPE_MAIN_VARIANT (type);
1201   t = TYPE_SIZE_UNIT (type);
1202   if (t == 0
1203       || TREE_CODE (t) != INTEGER_CST
1204       || TREE_OVERFLOW (t)
1205       || TREE_INT_CST_HIGH (t) != 0
1206       /* If the result would appear negative, it's too big to represent.  */
1207       || (HOST_WIDE_INT) TREE_INT_CST_LOW (t) < 0)
1208     return -1;
1209 
1210   return TREE_INT_CST_LOW (t);
1211 }
1212 
1213 /* Return the bit position of FIELD, in bits from the start of the record.
1214    This is a tree of type bitsizetype.  */
1215 
1216 tree
bit_position(field)1217 bit_position (field)
1218      tree field;
1219 {
1220 
1221   return bit_from_pos (DECL_FIELD_OFFSET (field),
1222 		       DECL_FIELD_BIT_OFFSET (field));
1223 }
1224 
1225 /* Likewise, but return as an integer.  Abort if it cannot be represented
1226    in that way (since it could be a signed value, we don't have the option
1227    of returning -1 like int_size_in_byte can.  */
1228 
1229 HOST_WIDE_INT
int_bit_position(field)1230 int_bit_position (field)
1231      tree field;
1232 {
1233   return tree_low_cst (bit_position (field), 0);
1234 }
1235 
1236 /* Return the byte position of FIELD, in bytes from the start of the record.
1237    This is a tree of type sizetype.  */
1238 
1239 tree
byte_position(field)1240 byte_position (field)
1241      tree field;
1242 {
1243   return byte_from_pos (DECL_FIELD_OFFSET (field),
1244 			DECL_FIELD_BIT_OFFSET (field));
1245 }
1246 
1247 /* Likewise, but return as an integer.  Abort if it cannot be represented
1248    in that way (since it could be a signed value, we don't have the option
1249    of returning -1 like int_size_in_byte can.  */
1250 
1251 HOST_WIDE_INT
int_byte_position(field)1252 int_byte_position (field)
1253      tree field;
1254 {
1255   return tree_low_cst (byte_position (field), 0);
1256 }
1257 
1258 /* Return the strictest alignment, in bits, that T is known to have.  */
1259 
1260 unsigned int
expr_align(t)1261 expr_align (t)
1262      tree t;
1263 {
1264   unsigned int align0, align1;
1265 
1266   switch (TREE_CODE (t))
1267     {
1268     case NOP_EXPR:  case CONVERT_EXPR:  case NON_LVALUE_EXPR:
1269       /* If we have conversions, we know that the alignment of the
1270 	 object must meet each of the alignments of the types.  */
1271       align0 = expr_align (TREE_OPERAND (t, 0));
1272       align1 = TYPE_ALIGN (TREE_TYPE (t));
1273       return MAX (align0, align1);
1274 
1275     case SAVE_EXPR:         case COMPOUND_EXPR:       case MODIFY_EXPR:
1276     case INIT_EXPR:         case TARGET_EXPR:         case WITH_CLEANUP_EXPR:
1277     case WITH_RECORD_EXPR:  case CLEANUP_POINT_EXPR:  case UNSAVE_EXPR:
1278       /* These don't change the alignment of an object.  */
1279       return expr_align (TREE_OPERAND (t, 0));
1280 
1281     case COND_EXPR:
1282       /* The best we can do is say that the alignment is the least aligned
1283 	 of the two arms.  */
1284       align0 = expr_align (TREE_OPERAND (t, 1));
1285       align1 = expr_align (TREE_OPERAND (t, 2));
1286       return MIN (align0, align1);
1287 
1288     case LABEL_DECL:     case CONST_DECL:
1289     case VAR_DECL:       case PARM_DECL:   case RESULT_DECL:
1290       if (DECL_ALIGN (t) != 0)
1291 	return DECL_ALIGN (t);
1292       break;
1293 
1294     case FUNCTION_DECL:
1295       return FUNCTION_BOUNDARY;
1296 
1297     default:
1298       break;
1299     }
1300 
1301   /* Otherwise take the alignment from that of the type.  */
1302   return TYPE_ALIGN (TREE_TYPE (t));
1303 }
1304 
1305 /* Return, as a tree node, the number of elements for TYPE (which is an
1306    ARRAY_TYPE) minus one. This counts only elements of the top array.  */
1307 
1308 tree
array_type_nelts(type)1309 array_type_nelts (type)
1310      tree type;
1311 {
1312   tree index_type, min, max;
1313 
1314   /* If they did it with unspecified bounds, then we should have already
1315      given an error about it before we got here.  */
1316   if (! TYPE_DOMAIN (type))
1317     return error_mark_node;
1318 
1319   index_type = TYPE_DOMAIN (type);
1320   min = TYPE_MIN_VALUE (index_type);
1321   max = TYPE_MAX_VALUE (index_type);
1322 
1323   return (integer_zerop (min)
1324 	  ? max
1325 	  : fold (build (MINUS_EXPR, TREE_TYPE (max), max, min)));
1326 }
1327 
1328 /* Return nonzero if arg is static -- a reference to an object in
1329    static storage.  This is not the same as the C meaning of `static'.  */
1330 
1331 int
staticp(arg)1332 staticp (arg)
1333      tree arg;
1334 {
1335   switch (TREE_CODE (arg))
1336     {
1337     case FUNCTION_DECL:
1338       /* Nested functions aren't static, since taking their address
1339 	 involves a trampoline.  */
1340       return ((decl_function_context (arg) == 0 || DECL_NO_STATIC_CHAIN (arg))
1341 	      && ! DECL_NON_ADDR_CONST_P (arg));
1342 
1343     case VAR_DECL:
1344       return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
1345 	      && ! DECL_THREAD_LOCAL (arg)
1346 	      && ! DECL_NON_ADDR_CONST_P (arg));
1347 
1348     case CONSTRUCTOR:
1349       return TREE_STATIC (arg);
1350 
1351     case LABEL_DECL:
1352     case STRING_CST:
1353       return 1;
1354 
1355       /* If we are referencing a bitfield, we can't evaluate an
1356 	 ADDR_EXPR at compile time and so it isn't a constant.  */
1357     case COMPONENT_REF:
1358       return (! DECL_BIT_FIELD (TREE_OPERAND (arg, 1))
1359 	      && staticp (TREE_OPERAND (arg, 0)));
1360 
1361     case BIT_FIELD_REF:
1362       return 0;
1363 
1364 #if 0
1365        /* This case is technically correct, but results in setting
1366 	  TREE_CONSTANT on ADDR_EXPRs that cannot be evaluated at
1367 	  compile time.  */
1368     case INDIRECT_REF:
1369       return TREE_CONSTANT (TREE_OPERAND (arg, 0));
1370 #endif
1371 
1372     case ARRAY_REF:
1373     case ARRAY_RANGE_REF:
1374       if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST
1375 	  && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST)
1376 	return staticp (TREE_OPERAND (arg, 0));
1377 
1378     default:
1379       if ((unsigned int) TREE_CODE (arg)
1380 	  >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
1381 	return (*lang_hooks.staticp) (arg);
1382       else
1383 	return 0;
1384     }
1385 }
1386 
1387 /* Wrap a SAVE_EXPR around EXPR, if appropriate.
1388    Do this to any expression which may be used in more than one place,
1389    but must be evaluated only once.
1390 
1391    Normally, expand_expr would reevaluate the expression each time.
1392    Calling save_expr produces something that is evaluated and recorded
1393    the first time expand_expr is called on it.  Subsequent calls to
1394    expand_expr just reuse the recorded value.
1395 
1396    The call to expand_expr that generates code that actually computes
1397    the value is the first call *at compile time*.  Subsequent calls
1398    *at compile time* generate code to use the saved value.
1399    This produces correct result provided that *at run time* control
1400    always flows through the insns made by the first expand_expr
1401    before reaching the other places where the save_expr was evaluated.
1402    You, the caller of save_expr, must make sure this is so.
1403 
1404    Constants, and certain read-only nodes, are returned with no
1405    SAVE_EXPR because that is safe.  Expressions containing placeholders
1406    are not touched; see tree.def for an explanation of what these
1407    are used for.  */
1408 
1409 tree
save_expr(expr)1410 save_expr (expr)
1411      tree expr;
1412 {
1413   tree t = fold (expr);
1414   tree inner;
1415 
1416   /* We don't care about whether this can be used as an lvalue in this
1417      context.  */
1418   while (TREE_CODE (t) == NON_LVALUE_EXPR)
1419     t = TREE_OPERAND (t, 0);
1420 
1421   /* If we have simple operations applied to a SAVE_EXPR or to a SAVE_EXPR and
1422      a constant, it will be more efficient to not make another SAVE_EXPR since
1423      it will allow better simplification and GCSE will be able to merge the
1424      computations if they actualy occur.  */
1425   for (inner = t;
1426        (TREE_CODE_CLASS (TREE_CODE (inner)) == '1'
1427 	|| (TREE_CODE_CLASS (TREE_CODE (inner)) == '2'
1428 	    && TREE_CONSTANT (TREE_OPERAND (inner, 1))));
1429        inner = TREE_OPERAND (inner, 0))
1430     ;
1431 
1432   /* If the tree evaluates to a constant, then we don't want to hide that
1433      fact (i.e. this allows further folding, and direct checks for constants).
1434      However, a read-only object that has side effects cannot be bypassed.
1435      Since it is no problem to reevaluate literals, we just return the
1436      literal node.  */
1437   if (TREE_CONSTANT (inner)
1438       || (TREE_READONLY (inner) && ! TREE_SIDE_EFFECTS (inner))
1439       || TREE_CODE (inner) == SAVE_EXPR || TREE_CODE (inner) == ERROR_MARK)
1440     return t;
1441 
1442   /* If T contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
1443      it means that the size or offset of some field of an object depends on
1444      the value within another field.
1445 
1446      Note that it must not be the case that T contains both a PLACEHOLDER_EXPR
1447      and some variable since it would then need to be both evaluated once and
1448      evaluated more than once.  Front-ends must assure this case cannot
1449      happen by surrounding any such subexpressions in their own SAVE_EXPR
1450      and forcing evaluation at the proper time.  */
1451   if (contains_placeholder_p (t))
1452     return t;
1453 
1454   t = build (SAVE_EXPR, TREE_TYPE (expr), t, current_function_decl, NULL_TREE);
1455 
1456   /* This expression might be placed ahead of a jump to ensure that the
1457      value was computed on both sides of the jump.  So make sure it isn't
1458      eliminated as dead.  */
1459   TREE_SIDE_EFFECTS (t) = 1;
1460   TREE_READONLY (t) = 1;
1461   return t;
1462 }
1463 
1464 /* Arrange for an expression to be expanded multiple independent
1465    times.  This is useful for cleanup actions, as the backend can
1466    expand them multiple times in different places.  */
1467 
1468 tree
unsave_expr(expr)1469 unsave_expr (expr)
1470      tree expr;
1471 {
1472   tree t;
1473 
1474   /* If this is already protected, no sense in protecting it again.  */
1475   if (TREE_CODE (expr) == UNSAVE_EXPR)
1476     return expr;
1477 
1478   t = build1 (UNSAVE_EXPR, TREE_TYPE (expr), expr);
1479   TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (expr);
1480   return t;
1481 }
1482 
1483 /* Returns the index of the first non-tree operand for CODE, or the number
1484    of operands if all are trees.  */
1485 
1486 int
first_rtl_op(code)1487 first_rtl_op (code)
1488      enum tree_code code;
1489 {
1490   switch (code)
1491     {
1492     case SAVE_EXPR:
1493       return 2;
1494     case GOTO_SUBROUTINE_EXPR:
1495     case RTL_EXPR:
1496       return 0;
1497     case WITH_CLEANUP_EXPR:
1498       return 2;
1499     case METHOD_CALL_EXPR:
1500       return 3;
1501     default:
1502       return TREE_CODE_LENGTH (code);
1503     }
1504 }
1505 
1506 /* Return which tree structure is used by T.  */
1507 
1508 enum tree_node_structure_enum
tree_node_structure(t)1509 tree_node_structure (t)
1510      tree t;
1511 {
1512   enum tree_code code = TREE_CODE (t);
1513 
1514   switch (TREE_CODE_CLASS (code))
1515     {
1516     case 'd':	return TS_DECL;
1517     case 't':	return TS_TYPE;
1518     case 'b':	return TS_BLOCK;
1519     case 'r': case '<': case '1': case '2': case 'e': case 's':
1520       return TS_EXP;
1521     default:  /* 'c' and 'x' */
1522       break;
1523     }
1524   switch (code)
1525     {
1526       /* 'c' cases.  */
1527     case INTEGER_CST:		return TS_INT_CST;
1528     case REAL_CST:		return TS_REAL_CST;
1529     case COMPLEX_CST:		return TS_COMPLEX;
1530     case VECTOR_CST:		return TS_VECTOR;
1531     case STRING_CST:		return TS_STRING;
1532       /* 'x' cases.  */
1533     case ERROR_MARK:		return TS_COMMON;
1534     case IDENTIFIER_NODE:	return TS_IDENTIFIER;
1535     case TREE_LIST:		return TS_LIST;
1536     case TREE_VEC:		return TS_VEC;
1537     case PLACEHOLDER_EXPR:	return TS_COMMON;
1538 
1539     default:
1540       abort ();
1541     }
1542 }
1543 
1544 /* Perform any modifications to EXPR required when it is unsaved.  Does
1545    not recurse into EXPR's subtrees.  */
1546 
1547 void
unsave_expr_1(expr)1548 unsave_expr_1 (expr)
1549      tree expr;
1550 {
1551   switch (TREE_CODE (expr))
1552     {
1553     case SAVE_EXPR:
1554       if (! SAVE_EXPR_PERSISTENT_P (expr))
1555 	SAVE_EXPR_RTL (expr) = 0;
1556       break;
1557 
1558     case TARGET_EXPR:
1559       /* Don't mess with a TARGET_EXPR that hasn't been expanded.
1560          It's OK for this to happen if it was part of a subtree that
1561          isn't immediately expanded, such as operand 2 of another
1562          TARGET_EXPR.  */
1563       if (TREE_OPERAND (expr, 1))
1564 	break;
1565 
1566       TREE_OPERAND (expr, 1) = TREE_OPERAND (expr, 3);
1567       TREE_OPERAND (expr, 3) = NULL_TREE;
1568       break;
1569 
1570     case RTL_EXPR:
1571       /* I don't yet know how to emit a sequence multiple times.  */
1572       if (RTL_EXPR_SEQUENCE (expr) != 0)
1573 	abort ();
1574       break;
1575 
1576     default:
1577       break;
1578     }
1579 }
1580 
1581 /* Default lang hook for "unsave_expr_now".  */
1582 
1583 tree
lhd_unsave_expr_now(expr)1584 lhd_unsave_expr_now (expr)
1585      tree expr;
1586 {
1587   enum tree_code code;
1588 
1589   /* There's nothing to do for NULL_TREE.  */
1590   if (expr == 0)
1591     return expr;
1592 
1593   unsave_expr_1 (expr);
1594 
1595   code = TREE_CODE (expr);
1596   switch (TREE_CODE_CLASS (code))
1597     {
1598     case 'c':  /* a constant */
1599     case 't':  /* a type node */
1600     case 'd':  /* A decl node */
1601     case 'b':  /* A block node */
1602       break;
1603 
1604     case 'x':  /* miscellaneous: e.g., identifier, TREE_LIST or ERROR_MARK.  */
1605       if (code == TREE_LIST)
1606 	{
1607 	  lhd_unsave_expr_now (TREE_VALUE (expr));
1608 	  lhd_unsave_expr_now (TREE_CHAIN (expr));
1609 	}
1610       break;
1611 
1612     case 'e':  /* an expression */
1613     case 'r':  /* a reference */
1614     case 's':  /* an expression with side effects */
1615     case '<':  /* a comparison expression */
1616     case '2':  /* a binary arithmetic expression */
1617     case '1':  /* a unary arithmetic expression */
1618       {
1619 	int i;
1620 
1621 	for (i = first_rtl_op (code) - 1; i >= 0; i--)
1622 	  lhd_unsave_expr_now (TREE_OPERAND (expr, i));
1623       }
1624       break;
1625 
1626     default:
1627       abort ();
1628     }
1629 
1630   return expr;
1631 }
1632 
1633 /* Return 0 if it is safe to evaluate EXPR multiple times,
1634    return 1 if it is safe if EXPR is unsaved afterward, or
1635    return 2 if it is completely unsafe.
1636 
1637    This assumes that CALL_EXPRs and TARGET_EXPRs are never replicated in
1638    an expression tree, so that it safe to unsave them and the surrounding
1639    context will be correct.
1640 
1641    SAVE_EXPRs basically *only* appear replicated in an expression tree,
1642    occasionally across the whole of a function.  It is therefore only
1643    safe to unsave a SAVE_EXPR if you know that all occurrences appear
1644    below the UNSAVE_EXPR.
1645 
1646    RTL_EXPRs consume their rtl during evaluation.  It is therefore
1647    never possible to unsave them.  */
1648 
1649 int
unsafe_for_reeval(expr)1650 unsafe_for_reeval (expr)
1651      tree expr;
1652 {
1653   int unsafeness = 0;
1654   enum tree_code code;
1655   int i, tmp, tmp2;
1656   tree exp;
1657   int first_rtl;
1658 
1659   if (expr == NULL_TREE)
1660     return 1;
1661 
1662   code = TREE_CODE (expr);
1663   first_rtl = first_rtl_op (code);
1664 
1665   switch (code)
1666     {
1667     case SAVE_EXPR:
1668     case RTL_EXPR:
1669       return 2;
1670 
1671     case TREE_LIST:
1672       for (exp = expr; exp != 0; exp = TREE_CHAIN (exp))
1673 	{
1674 	  tmp = unsafe_for_reeval (TREE_VALUE (exp));
1675 	  unsafeness = MAX (tmp, unsafeness);
1676 	}
1677 
1678       return unsafeness;
1679 
1680     case CALL_EXPR:
1681       tmp2 = unsafe_for_reeval (TREE_OPERAND (expr, 0));
1682       tmp = unsafe_for_reeval (TREE_OPERAND (expr, 1));
1683       return MAX (MAX (tmp, 1), tmp2);
1684 
1685     case TARGET_EXPR:
1686       unsafeness = 1;
1687       break;
1688 
1689     case EXIT_BLOCK_EXPR:
1690       /* EXIT_BLOCK_LABELED_BLOCK, a.k.a. TREE_OPERAND (expr, 0), holds
1691 	 a reference to an ancestor LABELED_BLOCK, so we need to avoid
1692 	 unbounded recursion in the 'e' traversal code below.  */
1693       exp = EXIT_BLOCK_RETURN (expr);
1694       return exp ? unsafe_for_reeval (exp) : 0;
1695 
1696     default:
1697       tmp = (*lang_hooks.unsafe_for_reeval) (expr);
1698       if (tmp >= 0)
1699 	return tmp;
1700       break;
1701     }
1702 
1703   switch (TREE_CODE_CLASS (code))
1704     {
1705     case 'c':  /* a constant */
1706     case 't':  /* a type node */
1707     case 'x':  /* something random, like an identifier or an ERROR_MARK.  */
1708     case 'd':  /* A decl node */
1709     case 'b':  /* A block node */
1710       return 0;
1711 
1712     case 'e':  /* an expression */
1713     case 'r':  /* a reference */
1714     case 's':  /* an expression with side effects */
1715     case '<':  /* a comparison expression */
1716     case '2':  /* a binary arithmetic expression */
1717     case '1':  /* a unary arithmetic expression */
1718       for (i = first_rtl - 1; i >= 0; i--)
1719 	{
1720 	  tmp = unsafe_for_reeval (TREE_OPERAND (expr, i));
1721 	  unsafeness = MAX (tmp, unsafeness);
1722 	}
1723 
1724       return unsafeness;
1725 
1726     default:
1727       return 2;
1728     }
1729 }
1730 
1731 /* Return 1 if EXP contains a PLACEHOLDER_EXPR; i.e., if it represents a size
1732    or offset that depends on a field within a record.  */
1733 
1734 int
contains_placeholder_p(exp)1735 contains_placeholder_p (exp)
1736      tree exp;
1737 {
1738   enum tree_code code;
1739   int result;
1740 
1741   if (!exp)
1742     return 0;
1743 
1744   /* If we have a WITH_RECORD_EXPR, it "cancels" any PLACEHOLDER_EXPR
1745      in it since it is supplying a value for it.  */
1746   code = TREE_CODE (exp);
1747   if (code == WITH_RECORD_EXPR)
1748     return 0;
1749   else if (code == PLACEHOLDER_EXPR)
1750     return 1;
1751 
1752   switch (TREE_CODE_CLASS (code))
1753     {
1754     case 'r':
1755       /* Don't look at any PLACEHOLDER_EXPRs that might be in index or bit
1756 	 position computations since they will be converted into a
1757 	 WITH_RECORD_EXPR involving the reference, which will assume
1758 	 here will be valid.  */
1759       return contains_placeholder_p (TREE_OPERAND (exp, 0));
1760 
1761     case 'x':
1762       if (code == TREE_LIST)
1763 	return (contains_placeholder_p (TREE_VALUE (exp))
1764 		|| (TREE_CHAIN (exp) != 0
1765 		    && contains_placeholder_p (TREE_CHAIN (exp))));
1766       break;
1767 
1768     case '1':
1769     case '2':  case '<':
1770     case 'e':
1771       switch (code)
1772 	{
1773 	case COMPOUND_EXPR:
1774 	  /* Ignoring the first operand isn't quite right, but works best.  */
1775 	  return contains_placeholder_p (TREE_OPERAND (exp, 1));
1776 
1777 	case RTL_EXPR:
1778 	case CONSTRUCTOR:
1779 	  return 0;
1780 
1781 	case COND_EXPR:
1782 	  return (contains_placeholder_p (TREE_OPERAND (exp, 0))
1783 		  || contains_placeholder_p (TREE_OPERAND (exp, 1))
1784 		  || contains_placeholder_p (TREE_OPERAND (exp, 2)));
1785 
1786 	case SAVE_EXPR:
1787 	  /* If we already know this doesn't have a placeholder, don't
1788 	     check again.  */
1789 	  if (SAVE_EXPR_NOPLACEHOLDER (exp) || SAVE_EXPR_RTL (exp) != 0)
1790 	    return 0;
1791 
1792 	  SAVE_EXPR_NOPLACEHOLDER (exp) = 1;
1793 	  result = contains_placeholder_p (TREE_OPERAND (exp, 0));
1794 	  if (result)
1795 	    SAVE_EXPR_NOPLACEHOLDER (exp) = 0;
1796 
1797 	  return result;
1798 
1799 	case CALL_EXPR:
1800 	  return (TREE_OPERAND (exp, 1) != 0
1801 		  && contains_placeholder_p (TREE_OPERAND (exp, 1)));
1802 
1803 	default:
1804 	  break;
1805 	}
1806 
1807       switch (TREE_CODE_LENGTH (code))
1808 	{
1809 	case 1:
1810 	  return contains_placeholder_p (TREE_OPERAND (exp, 0));
1811 	case 2:
1812 	  return (contains_placeholder_p (TREE_OPERAND (exp, 0))
1813 		  || contains_placeholder_p (TREE_OPERAND (exp, 1)));
1814 	default:
1815 	  return 0;
1816 	}
1817 
1818     default:
1819       return 0;
1820     }
1821   return 0;
1822 }
1823 
1824 /* Return 1 if EXP contains any expressions that produce cleanups for an
1825    outer scope to deal with.  Used by fold.  */
1826 
1827 int
has_cleanups(exp)1828 has_cleanups (exp)
1829      tree exp;
1830 {
1831   int i, nops, cmp;
1832 
1833   if (! TREE_SIDE_EFFECTS (exp))
1834     return 0;
1835 
1836   switch (TREE_CODE (exp))
1837     {
1838     case TARGET_EXPR:
1839     case GOTO_SUBROUTINE_EXPR:
1840     case WITH_CLEANUP_EXPR:
1841       return 1;
1842 
1843     case CLEANUP_POINT_EXPR:
1844       return 0;
1845 
1846     case CALL_EXPR:
1847       for (exp = TREE_OPERAND (exp, 1); exp; exp = TREE_CHAIN (exp))
1848 	{
1849 	  cmp = has_cleanups (TREE_VALUE (exp));
1850 	  if (cmp)
1851 	    return cmp;
1852 	}
1853       return 0;
1854 
1855     default:
1856       break;
1857     }
1858 
1859   /* This general rule works for most tree codes.  All exceptions should be
1860      handled above.  If this is a language-specific tree code, we can't
1861      trust what might be in the operand, so say we don't know
1862      the situation.  */
1863   if ((int) TREE_CODE (exp) >= (int) LAST_AND_UNUSED_TREE_CODE)
1864     return -1;
1865 
1866   nops = first_rtl_op (TREE_CODE (exp));
1867   for (i = 0; i < nops; i++)
1868     if (TREE_OPERAND (exp, i) != 0)
1869       {
1870 	int type = TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, i)));
1871 	if (type == 'e' || type == '<' || type == '1' || type == '2'
1872 	    || type == 'r' || type == 's')
1873 	  {
1874 	    cmp = has_cleanups (TREE_OPERAND (exp, i));
1875 	    if (cmp)
1876 	      return cmp;
1877 	  }
1878       }
1879 
1880   return 0;
1881 }
1882 
1883 /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
1884    return a tree with all occurrences of references to F in a
1885    PLACEHOLDER_EXPR replaced by R.   Note that we assume here that EXP
1886    contains only arithmetic expressions or a CALL_EXPR with a
1887    PLACEHOLDER_EXPR occurring only in its arglist.  */
1888 
1889 tree
substitute_in_expr(exp,f,r)1890 substitute_in_expr (exp, f, r)
1891      tree exp;
1892      tree f;
1893      tree r;
1894 {
1895   enum tree_code code = TREE_CODE (exp);
1896   tree op0, op1, op2;
1897   tree new;
1898   tree inner;
1899 
1900   switch (TREE_CODE_CLASS (code))
1901     {
1902     case 'c':
1903     case 'd':
1904       return exp;
1905 
1906     case 'x':
1907       if (code == PLACEHOLDER_EXPR)
1908 	return exp;
1909       else if (code == TREE_LIST)
1910 	{
1911 	  op0 = (TREE_CHAIN (exp) == 0
1912 		 ? 0 : substitute_in_expr (TREE_CHAIN (exp), f, r));
1913 	  op1 = substitute_in_expr (TREE_VALUE (exp), f, r);
1914 	  if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
1915 	    return exp;
1916 
1917 	  return tree_cons (TREE_PURPOSE (exp), op1, op0);
1918 	}
1919 
1920       abort ();
1921 
1922     case '1':
1923     case '2':
1924     case '<':
1925     case 'e':
1926       switch (TREE_CODE_LENGTH (code))
1927 	{
1928 	case 1:
1929 	  op0 = substitute_in_expr (TREE_OPERAND (exp, 0), f, r);
1930 	  if (op0 == TREE_OPERAND (exp, 0))
1931 	    return exp;
1932 
1933 	  if (code == NON_LVALUE_EXPR)
1934 	    return op0;
1935 
1936 	  new = fold (build1 (code, TREE_TYPE (exp), op0));
1937 	  break;
1938 
1939 	case 2:
1940 	  /* An RTL_EXPR cannot contain a PLACEHOLDER_EXPR; a CONSTRUCTOR
1941 	     could, but we don't support it.  */
1942 	  if (code == RTL_EXPR)
1943 	    return exp;
1944 	  else if (code == CONSTRUCTOR)
1945 	    abort ();
1946 
1947 	  op0 = substitute_in_expr (TREE_OPERAND (exp, 0), f, r);
1948 	  op1 = substitute_in_expr (TREE_OPERAND (exp, 1), f, r);
1949 	  if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
1950 	    return exp;
1951 
1952 	  new = fold (build (code, TREE_TYPE (exp), op0, op1));
1953 	  break;
1954 
1955 	case 3:
1956 	  /* It cannot be that anything inside a SAVE_EXPR contains a
1957 	     PLACEHOLDER_EXPR.  */
1958 	  if (code == SAVE_EXPR)
1959 	    return exp;
1960 
1961 	  else if (code == CALL_EXPR)
1962 	    {
1963 	      op1 = substitute_in_expr (TREE_OPERAND (exp, 1), f, r);
1964 	      if (op1 == TREE_OPERAND (exp, 1))
1965 		return exp;
1966 
1967 	      return build (code, TREE_TYPE (exp),
1968 			    TREE_OPERAND (exp, 0), op1, NULL_TREE);
1969 	    }
1970 
1971 	  else if (code != COND_EXPR)
1972 	    abort ();
1973 
1974 	  op0 = substitute_in_expr (TREE_OPERAND (exp, 0), f, r);
1975 	  op1 = substitute_in_expr (TREE_OPERAND (exp, 1), f, r);
1976 	  op2 = substitute_in_expr (TREE_OPERAND (exp, 2), f, r);
1977 	  if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
1978 	      && op2 == TREE_OPERAND (exp, 2))
1979 	    return exp;
1980 
1981 	  new = fold (build (code, TREE_TYPE (exp), op0, op1, op2));
1982 	  break;
1983 
1984 	default:
1985 	  abort ();
1986 	}
1987 
1988       break;
1989 
1990     case 'r':
1991       switch (code)
1992 	{
1993 	case COMPONENT_REF:
1994 	  /* If this expression is getting a value from a PLACEHOLDER_EXPR
1995 	     and it is the right field, replace it with R.  */
1996 	  for (inner = TREE_OPERAND (exp, 0);
1997 	       TREE_CODE_CLASS (TREE_CODE (inner)) == 'r';
1998 	       inner = TREE_OPERAND (inner, 0))
1999 	    ;
2000 	  if (TREE_CODE (inner) == PLACEHOLDER_EXPR
2001 	      && TREE_OPERAND (exp, 1) == f)
2002 	    return r;
2003 
2004 	  /* If this expression hasn't been completed let, leave it
2005 	     alone.  */
2006 	  if (TREE_CODE (inner) == PLACEHOLDER_EXPR
2007 	      && TREE_TYPE (inner) == 0)
2008 	    return exp;
2009 
2010 	  op0 = substitute_in_expr (TREE_OPERAND (exp, 0), f, r);
2011 	  if (op0 == TREE_OPERAND (exp, 0))
2012 	    return exp;
2013 
2014 	  new = fold (build (code, TREE_TYPE (exp), op0,
2015 			     TREE_OPERAND (exp, 1)));
2016 	  break;
2017 
2018 	case BIT_FIELD_REF:
2019 	  op0 = substitute_in_expr (TREE_OPERAND (exp, 0), f, r);
2020 	  op1 = substitute_in_expr (TREE_OPERAND (exp, 1), f, r);
2021 	  op2 = substitute_in_expr (TREE_OPERAND (exp, 2), f, r);
2022 	  if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
2023 	      && op2 == TREE_OPERAND (exp, 2))
2024 	    return exp;
2025 
2026 	  new = fold (build (code, TREE_TYPE (exp), op0, op1, op2));
2027 	  break;
2028 
2029 	case INDIRECT_REF:
2030 	case BUFFER_REF:
2031 	  op0 = substitute_in_expr (TREE_OPERAND (exp, 0), f, r);
2032 	  if (op0 == TREE_OPERAND (exp, 0))
2033 	    return exp;
2034 
2035 	  new = fold (build1 (code, TREE_TYPE (exp), op0));
2036 	  break;
2037 
2038 	default:
2039 	  abort ();
2040 	}
2041       break;
2042 
2043     default:
2044       abort ();
2045     }
2046 
2047   TREE_READONLY (new) = TREE_READONLY (exp);
2048   return new;
2049 }
2050 
2051 /* Stabilize a reference so that we can use it any number of times
2052    without causing its operands to be evaluated more than once.
2053    Returns the stabilized reference.  This works by means of save_expr,
2054    so see the caveats in the comments about save_expr.
2055 
2056    Also allows conversion expressions whose operands are references.
2057    Any other kind of expression is returned unchanged.  */
2058 
2059 tree
stabilize_reference(ref)2060 stabilize_reference (ref)
2061      tree ref;
2062 {
2063   tree result;
2064   enum tree_code code = TREE_CODE (ref);
2065 
2066   switch (code)
2067     {
2068     case VAR_DECL:
2069     case PARM_DECL:
2070     case RESULT_DECL:
2071       /* No action is needed in this case.  */
2072       return ref;
2073 
2074     case NOP_EXPR:
2075     case CONVERT_EXPR:
2076     case FLOAT_EXPR:
2077     case FIX_TRUNC_EXPR:
2078     case FIX_FLOOR_EXPR:
2079     case FIX_ROUND_EXPR:
2080     case FIX_CEIL_EXPR:
2081       result = build_nt (code, stabilize_reference (TREE_OPERAND (ref, 0)));
2082       break;
2083 
2084     case INDIRECT_REF:
2085       result = build_nt (INDIRECT_REF,
2086 			 stabilize_reference_1 (TREE_OPERAND (ref, 0)));
2087       break;
2088 
2089     case COMPONENT_REF:
2090       result = build_nt (COMPONENT_REF,
2091 			 stabilize_reference (TREE_OPERAND (ref, 0)),
2092 			 TREE_OPERAND (ref, 1));
2093       break;
2094 
2095     case BIT_FIELD_REF:
2096       result = build_nt (BIT_FIELD_REF,
2097 			 stabilize_reference (TREE_OPERAND (ref, 0)),
2098 			 stabilize_reference_1 (TREE_OPERAND (ref, 1)),
2099 			 stabilize_reference_1 (TREE_OPERAND (ref, 2)));
2100       break;
2101 
2102     case ARRAY_REF:
2103       result = build_nt (ARRAY_REF,
2104 			 stabilize_reference (TREE_OPERAND (ref, 0)),
2105 			 stabilize_reference_1 (TREE_OPERAND (ref, 1)));
2106       break;
2107 
2108     case ARRAY_RANGE_REF:
2109       result = build_nt (ARRAY_RANGE_REF,
2110 			 stabilize_reference (TREE_OPERAND (ref, 0)),
2111 			 stabilize_reference_1 (TREE_OPERAND (ref, 1)));
2112       break;
2113 
2114     case COMPOUND_EXPR:
2115       /* We cannot wrap the first expression in a SAVE_EXPR, as then
2116 	 it wouldn't be ignored.  This matters when dealing with
2117 	 volatiles.  */
2118       return stabilize_reference_1 (ref);
2119 
2120     case RTL_EXPR:
2121       result = build1 (INDIRECT_REF, TREE_TYPE (ref),
2122 		       save_expr (build1 (ADDR_EXPR,
2123 					  build_pointer_type (TREE_TYPE (ref)),
2124 					  ref)));
2125       break;
2126 
2127       /* If arg isn't a kind of lvalue we recognize, make no change.
2128 	 Caller should recognize the error for an invalid lvalue.  */
2129     default:
2130       return ref;
2131 
2132     case ERROR_MARK:
2133       return error_mark_node;
2134     }
2135 
2136   TREE_TYPE (result) = TREE_TYPE (ref);
2137   TREE_READONLY (result) = TREE_READONLY (ref);
2138   TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (ref);
2139   TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (ref);
2140 
2141   return result;
2142 }
2143 
2144 /* Subroutine of stabilize_reference; this is called for subtrees of
2145    references.  Any expression with side-effects must be put in a SAVE_EXPR
2146    to ensure that it is only evaluated once.
2147 
2148    We don't put SAVE_EXPR nodes around everything, because assigning very
2149    simple expressions to temporaries causes us to miss good opportunities
2150    for optimizations.  Among other things, the opportunity to fold in the
2151    addition of a constant into an addressing mode often gets lost, e.g.
2152    "y[i+1] += x;".  In general, we take the approach that we should not make
2153    an assignment unless we are forced into it - i.e., that any non-side effect
2154    operator should be allowed, and that cse should take care of coalescing
2155    multiple utterances of the same expression should that prove fruitful.  */
2156 
2157 tree
stabilize_reference_1(e)2158 stabilize_reference_1 (e)
2159      tree e;
2160 {
2161   tree result;
2162   enum tree_code code = TREE_CODE (e);
2163 
2164   /* We cannot ignore const expressions because it might be a reference
2165      to a const array but whose index contains side-effects.  But we can
2166      ignore things that are actual constant or that already have been
2167      handled by this function.  */
2168 
2169   if (TREE_CONSTANT (e) || code == SAVE_EXPR)
2170     return e;
2171 
2172   switch (TREE_CODE_CLASS (code))
2173     {
2174     case 'x':
2175     case 't':
2176     case 'd':
2177     case 'b':
2178     case '<':
2179     case 's':
2180     case 'e':
2181     case 'r':
2182       /* If the expression has side-effects, then encase it in a SAVE_EXPR
2183 	 so that it will only be evaluated once.  */
2184       /* The reference (r) and comparison (<) classes could be handled as
2185 	 below, but it is generally faster to only evaluate them once.  */
2186       if (TREE_SIDE_EFFECTS (e))
2187 	return save_expr (e);
2188       return e;
2189 
2190     case 'c':
2191       /* Constants need no processing.  In fact, we should never reach
2192 	 here.  */
2193       return e;
2194 
2195     case '2':
2196       /* Division is slow and tends to be compiled with jumps,
2197 	 especially the division by powers of 2 that is often
2198 	 found inside of an array reference.  So do it just once.  */
2199       if (code == TRUNC_DIV_EXPR || code == TRUNC_MOD_EXPR
2200 	  || code == FLOOR_DIV_EXPR || code == FLOOR_MOD_EXPR
2201 	  || code == CEIL_DIV_EXPR || code == CEIL_MOD_EXPR
2202 	  || code == ROUND_DIV_EXPR || code == ROUND_MOD_EXPR)
2203 	return save_expr (e);
2204       /* Recursively stabilize each operand.  */
2205       result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)),
2206 			 stabilize_reference_1 (TREE_OPERAND (e, 1)));
2207       break;
2208 
2209     case '1':
2210       /* Recursively stabilize each operand.  */
2211       result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)));
2212       break;
2213 
2214     default:
2215       abort ();
2216     }
2217 
2218   TREE_TYPE (result) = TREE_TYPE (e);
2219   TREE_READONLY (result) = TREE_READONLY (e);
2220   TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (e);
2221   TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (e);
2222 
2223   return result;
2224 }
2225 
2226 /* Low-level constructors for expressions.  */
2227 
2228 /* Build an expression of code CODE, data type TYPE,
2229    and operands as specified by the arguments ARG1 and following arguments.
2230    Expressions and reference nodes can be created this way.
2231    Constants, decls, types and misc nodes cannot be.  */
2232 
2233 tree
build(enum tree_code code,tree tt,...)2234 build VPARAMS ((enum tree_code code, tree tt, ...))
2235 {
2236   tree t;
2237   int length;
2238   int i;
2239   int fro;
2240   int constant;
2241 
2242   VA_OPEN (p, tt);
2243   VA_FIXEDARG (p, enum tree_code, code);
2244   VA_FIXEDARG (p, tree, tt);
2245 
2246   t = make_node (code);
2247   length = TREE_CODE_LENGTH (code);
2248   TREE_TYPE (t) = tt;
2249 
2250   /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_READONLY for the
2251      result based on those same flags for the arguments.  But if the
2252      arguments aren't really even `tree' expressions, we shouldn't be trying
2253      to do this.  */
2254   fro = first_rtl_op (code);
2255 
2256   /* Expressions without side effects may be constant if their
2257      arguments are as well.  */
2258   constant = (TREE_CODE_CLASS (code) == '<'
2259 	      || TREE_CODE_CLASS (code) == '1'
2260 	      || TREE_CODE_CLASS (code) == '2'
2261 	      || TREE_CODE_CLASS (code) == 'c');
2262 
2263   if (length == 2)
2264     {
2265       /* This is equivalent to the loop below, but faster.  */
2266       tree arg0 = va_arg (p, tree);
2267       tree arg1 = va_arg (p, tree);
2268 
2269       TREE_OPERAND (t, 0) = arg0;
2270       TREE_OPERAND (t, 1) = arg1;
2271       TREE_READONLY (t) = 1;
2272       if (arg0 && fro > 0)
2273 	{
2274 	  if (TREE_SIDE_EFFECTS (arg0))
2275 	    TREE_SIDE_EFFECTS (t) = 1;
2276 	  if (!TREE_READONLY (arg0))
2277 	    TREE_READONLY (t) = 0;
2278 	  if (!TREE_CONSTANT (arg0))
2279 	    constant = 0;
2280 	}
2281 
2282       if (arg1 && fro > 1)
2283 	{
2284 	  if (TREE_SIDE_EFFECTS (arg1))
2285 	    TREE_SIDE_EFFECTS (t) = 1;
2286 	  if (!TREE_READONLY (arg1))
2287 	    TREE_READONLY (t) = 0;
2288 	  if (!TREE_CONSTANT (arg1))
2289 	    constant = 0;
2290 	}
2291     }
2292   else if (length == 1)
2293     {
2294       tree arg0 = va_arg (p, tree);
2295 
2296       /* The only one-operand cases we handle here are those with side-effects.
2297 	 Others are handled with build1.  So don't bother checked if the
2298 	 arg has side-effects since we'll already have set it.
2299 
2300 	 ??? This really should use build1 too.  */
2301       if (TREE_CODE_CLASS (code) != 's')
2302 	abort ();
2303       TREE_OPERAND (t, 0) = arg0;
2304     }
2305   else
2306     {
2307       for (i = 0; i < length; i++)
2308 	{
2309 	  tree operand = va_arg (p, tree);
2310 
2311 	  TREE_OPERAND (t, i) = operand;
2312 	  if (operand && fro > i)
2313 	    {
2314 	      if (TREE_SIDE_EFFECTS (operand))
2315 		TREE_SIDE_EFFECTS (t) = 1;
2316 	      if (!TREE_CONSTANT (operand))
2317 		constant = 0;
2318 	    }
2319 	}
2320     }
2321   VA_CLOSE (p);
2322 
2323   TREE_CONSTANT (t) = constant;
2324   return t;
2325 }
2326 
2327 /* Same as above, but only builds for unary operators.
2328    Saves lions share of calls to `build'; cuts down use
2329    of varargs, which is expensive for RISC machines.  */
2330 
2331 tree
build1(code,type,node)2332 build1 (code, type, node)
2333      enum tree_code code;
2334      tree type;
2335      tree node;
2336 {
2337   int length;
2338 #ifdef GATHER_STATISTICS
2339   tree_node_kind kind;
2340 #endif
2341   tree t;
2342 
2343 #ifdef GATHER_STATISTICS
2344   if (TREE_CODE_CLASS (code) == 'r')
2345     kind = r_kind;
2346   else
2347     kind = e_kind;
2348 #endif
2349 
2350 #ifdef ENABLE_CHECKING
2351   if (TREE_CODE_CLASS (code) == '2'
2352       || TREE_CODE_CLASS (code) == '<'
2353       || TREE_CODE_LENGTH (code) != 1)
2354     abort ();
2355 #endif /* ENABLE_CHECKING */
2356 
2357   length = sizeof (struct tree_exp);
2358 
2359   t = ggc_alloc_tree (length);
2360 
2361   memset ((PTR) t, 0, sizeof (struct tree_common));
2362 
2363 #ifdef GATHER_STATISTICS
2364   tree_node_counts[(int) kind]++;
2365   tree_node_sizes[(int) kind] += length;
2366 #endif
2367 
2368   TREE_SET_CODE (t, code);
2369 
2370   TREE_TYPE (t) = type;
2371   TREE_COMPLEXITY (t) = 0;
2372   TREE_OPERAND (t, 0) = node;
2373   if (node && first_rtl_op (code) != 0)
2374     {
2375       TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (node);
2376       TREE_READONLY (t) = TREE_READONLY (node);
2377     }
2378 
2379   switch (code)
2380     {
2381     case INIT_EXPR:
2382     case MODIFY_EXPR:
2383     case VA_ARG_EXPR:
2384     case RTL_EXPR:
2385     case PREDECREMENT_EXPR:
2386     case PREINCREMENT_EXPR:
2387     case POSTDECREMENT_EXPR:
2388     case POSTINCREMENT_EXPR:
2389       /* All of these have side-effects, no matter what their
2390 	 operands are.  */
2391       TREE_SIDE_EFFECTS (t) = 1;
2392       TREE_READONLY (t) = 0;
2393       break;
2394 
2395     case INDIRECT_REF:
2396       /* Whether a dereference is readonly has nothing to do with whether
2397 	 its operand is readonly.  */
2398       TREE_READONLY (t) = 0;
2399       break;
2400 
2401     default:
2402       if (TREE_CODE_CLASS (code) == '1' && node && TREE_CONSTANT (node))
2403 	TREE_CONSTANT (t) = 1;
2404       break;
2405     }
2406 
2407   return t;
2408 }
2409 
2410 /* Similar except don't specify the TREE_TYPE
2411    and leave the TREE_SIDE_EFFECTS as 0.
2412    It is permissible for arguments to be null,
2413    or even garbage if their values do not matter.  */
2414 
2415 tree
build_nt(enum tree_code code,...)2416 build_nt VPARAMS ((enum tree_code code, ...))
2417 {
2418   tree t;
2419   int length;
2420   int i;
2421 
2422   VA_OPEN (p, code);
2423   VA_FIXEDARG (p, enum tree_code, code);
2424 
2425   t = make_node (code);
2426   length = TREE_CODE_LENGTH (code);
2427 
2428   for (i = 0; i < length; i++)
2429     TREE_OPERAND (t, i) = va_arg (p, tree);
2430 
2431   VA_CLOSE (p);
2432   return t;
2433 }
2434 
2435 /* Create a DECL_... node of code CODE, name NAME and data type TYPE.
2436    We do NOT enter this node in any sort of symbol table.
2437 
2438    layout_decl is used to set up the decl's storage layout.
2439    Other slots are initialized to 0 or null pointers.  */
2440 
2441 tree
build_decl(code,name,type)2442 build_decl (code, name, type)
2443      enum tree_code code;
2444      tree name, type;
2445 {
2446   tree t;
2447 
2448   t = make_node (code);
2449 
2450 /*  if (type == error_mark_node)
2451     type = integer_type_node; */
2452 /* That is not done, deliberately, so that having error_mark_node
2453    as the type can suppress useless errors in the use of this variable.  */
2454 
2455   DECL_NAME (t) = name;
2456   TREE_TYPE (t) = type;
2457 
2458   if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
2459     layout_decl (t, 0);
2460   else if (code == FUNCTION_DECL)
2461     DECL_MODE (t) = FUNCTION_MODE;
2462 
2463   return t;
2464 }
2465 
2466 /* BLOCK nodes are used to represent the structure of binding contours
2467    and declarations, once those contours have been exited and their contents
2468    compiled.  This information is used for outputting debugging info.  */
2469 
2470 tree
build_block(vars,tags,subblocks,supercontext,chain)2471 build_block (vars, tags, subblocks, supercontext, chain)
2472      tree vars, tags ATTRIBUTE_UNUSED, subblocks, supercontext, chain;
2473 {
2474   tree block = make_node (BLOCK);
2475 
2476   BLOCK_VARS (block) = vars;
2477   BLOCK_SUBBLOCKS (block) = subblocks;
2478   BLOCK_SUPERCONTEXT (block) = supercontext;
2479   BLOCK_CHAIN (block) = chain;
2480   return block;
2481 }
2482 
2483 /* EXPR_WITH_FILE_LOCATION are used to keep track of the exact
2484    location where an expression or an identifier were encountered. It
2485    is necessary for languages where the frontend parser will handle
2486    recursively more than one file (Java is one of them).  */
2487 
2488 tree
build_expr_wfl(node,file,line,col)2489 build_expr_wfl (node, file, line, col)
2490      tree node;
2491      const char *file;
2492      int line, col;
2493 {
2494   static const char *last_file = 0;
2495   static tree last_filenode = NULL_TREE;
2496   tree wfl = make_node (EXPR_WITH_FILE_LOCATION);
2497 
2498   EXPR_WFL_NODE (wfl) = node;
2499   EXPR_WFL_SET_LINECOL (wfl, line, col);
2500   if (file != last_file)
2501     {
2502       last_file = file;
2503       last_filenode = file ? get_identifier (file) : NULL_TREE;
2504     }
2505 
2506   EXPR_WFL_FILENAME_NODE (wfl) = last_filenode;
2507   if (node)
2508     {
2509       TREE_SIDE_EFFECTS (wfl) = TREE_SIDE_EFFECTS (node);
2510       TREE_TYPE (wfl) = TREE_TYPE (node);
2511     }
2512 
2513   return wfl;
2514 }
2515 
2516 /* Return a declaration like DDECL except that its DECL_ATTRIBUTES
2517    is ATTRIBUTE.  */
2518 
2519 tree
build_decl_attribute_variant(ddecl,attribute)2520 build_decl_attribute_variant (ddecl, attribute)
2521      tree ddecl, attribute;
2522 {
2523   DECL_ATTRIBUTES (ddecl) = attribute;
2524   return ddecl;
2525 }
2526 
2527 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
2528    is ATTRIBUTE.
2529 
2530    Record such modified types already made so we don't make duplicates.  */
2531 
2532 tree
build_type_attribute_variant(ttype,attribute)2533 build_type_attribute_variant (ttype, attribute)
2534      tree ttype, attribute;
2535 {
2536   if (! attribute_list_equal (TYPE_ATTRIBUTES (ttype), attribute))
2537     {
2538       unsigned int hashcode;
2539       tree ntype;
2540 
2541       ntype = copy_node (ttype);
2542 
2543       TYPE_POINTER_TO (ntype) = 0;
2544       TYPE_REFERENCE_TO (ntype) = 0;
2545       TYPE_ATTRIBUTES (ntype) = attribute;
2546 
2547       /* Create a new main variant of TYPE.  */
2548       TYPE_MAIN_VARIANT (ntype) = ntype;
2549       TYPE_NEXT_VARIANT (ntype) = 0;
2550       set_type_quals (ntype, TYPE_UNQUALIFIED);
2551 
2552       hashcode = (TYPE_HASH (TREE_CODE (ntype))
2553 		  + TYPE_HASH (TREE_TYPE (ntype))
2554 		  + attribute_hash_list (attribute));
2555 
2556       switch (TREE_CODE (ntype))
2557 	{
2558 	case FUNCTION_TYPE:
2559 	  hashcode += TYPE_HASH (TYPE_ARG_TYPES (ntype));
2560 	  break;
2561 	case ARRAY_TYPE:
2562 	  hashcode += TYPE_HASH (TYPE_DOMAIN (ntype));
2563 	  break;
2564 	case INTEGER_TYPE:
2565 	  hashcode += TYPE_HASH (TYPE_MAX_VALUE (ntype));
2566 	  break;
2567 	case REAL_TYPE:
2568 	  hashcode += TYPE_HASH (TYPE_PRECISION (ntype));
2569 	  break;
2570 	default:
2571 	  break;
2572 	}
2573 
2574       ntype = type_hash_canon (hashcode, ntype);
2575       ttype = build_qualified_type (ntype, TYPE_QUALS (ttype));
2576     }
2577 
2578   return ttype;
2579 }
2580 
2581 /* Return nonzero if IDENT is a valid name for attribute ATTR,
2582    or zero if not.
2583 
2584    We try both `text' and `__text__', ATTR may be either one.  */
2585 /* ??? It might be a reasonable simplification to require ATTR to be only
2586    `text'.  One might then also require attribute lists to be stored in
2587    their canonicalized form.  */
2588 
2589 int
is_attribute_p(attr,ident)2590 is_attribute_p (attr, ident)
2591      const char *attr;
2592      tree ident;
2593 {
2594   int ident_len, attr_len;
2595   const char *p;
2596 
2597   if (TREE_CODE (ident) != IDENTIFIER_NODE)
2598     return 0;
2599 
2600   if (strcmp (attr, IDENTIFIER_POINTER (ident)) == 0)
2601     return 1;
2602 
2603   p = IDENTIFIER_POINTER (ident);
2604   ident_len = strlen (p);
2605   attr_len = strlen (attr);
2606 
2607   /* If ATTR is `__text__', IDENT must be `text'; and vice versa.  */
2608   if (attr[0] == '_')
2609     {
2610       if (attr[1] != '_'
2611 	  || attr[attr_len - 2] != '_'
2612 	  || attr[attr_len - 1] != '_')
2613 	abort ();
2614       if (ident_len == attr_len - 4
2615 	  && strncmp (attr + 2, p, attr_len - 4) == 0)
2616 	return 1;
2617     }
2618   else
2619     {
2620       if (ident_len == attr_len + 4
2621 	  && p[0] == '_' && p[1] == '_'
2622 	  && p[ident_len - 2] == '_' && p[ident_len - 1] == '_'
2623 	  && strncmp (attr, p + 2, attr_len) == 0)
2624 	return 1;
2625     }
2626 
2627   return 0;
2628 }
2629 
2630 /* Given an attribute name and a list of attributes, return a pointer to the
2631    attribute's list element if the attribute is part of the list, or NULL_TREE
2632    if not found.  If the attribute appears more than once, this only
2633    returns the first occurrence; the TREE_CHAIN of the return value should
2634    be passed back in if further occurrences are wanted.  */
2635 
2636 tree
lookup_attribute(attr_name,list)2637 lookup_attribute (attr_name, list)
2638      const char *attr_name;
2639      tree list;
2640 {
2641   tree l;
2642 
2643   for (l = list; l; l = TREE_CHAIN (l))
2644     {
2645       if (TREE_CODE (TREE_PURPOSE (l)) != IDENTIFIER_NODE)
2646 	abort ();
2647       if (is_attribute_p (attr_name, TREE_PURPOSE (l)))
2648 	return l;
2649     }
2650 
2651   return NULL_TREE;
2652 }
2653 
2654 /* Return an attribute list that is the union of a1 and a2.  */
2655 
2656 tree
merge_attributes(a1,a2)2657 merge_attributes (a1, a2)
2658      tree a1, a2;
2659 {
2660   tree attributes;
2661 
2662   /* Either one unset?  Take the set one.  */
2663 
2664   if ((attributes = a1) == 0)
2665     attributes = a2;
2666 
2667   /* One that completely contains the other?  Take it.  */
2668 
2669   else if (a2 != 0 && ! attribute_list_contained (a1, a2))
2670     {
2671       if (attribute_list_contained (a2, a1))
2672 	attributes = a2;
2673       else
2674 	{
2675 	  /* Pick the longest list, and hang on the other list.  */
2676 
2677 	  if (list_length (a1) < list_length (a2))
2678 	    attributes = a2, a2 = a1;
2679 
2680 	  for (; a2 != 0; a2 = TREE_CHAIN (a2))
2681 	    {
2682 	      tree a;
2683 	      for (a = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2)),
2684 					 attributes);
2685 		   a != NULL_TREE;
2686 		   a = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2)),
2687 					 TREE_CHAIN (a)))
2688 		{
2689 		  if (simple_cst_equal (TREE_VALUE (a), TREE_VALUE (a2)) == 1)
2690 		    break;
2691 		}
2692 	      if (a == NULL_TREE)
2693 		{
2694 		  a1 = copy_node (a2);
2695 		  TREE_CHAIN (a1) = attributes;
2696 		  attributes = a1;
2697 		}
2698 	    }
2699 	}
2700     }
2701   return attributes;
2702 }
2703 
2704 /* Given types T1 and T2, merge their attributes and return
2705   the result.  */
2706 
2707 tree
merge_type_attributes(t1,t2)2708 merge_type_attributes (t1, t2)
2709      tree t1, t2;
2710 {
2711   return merge_attributes (TYPE_ATTRIBUTES (t1),
2712 			   TYPE_ATTRIBUTES (t2));
2713 }
2714 
2715 /* Given decls OLDDECL and NEWDECL, merge their attributes and return
2716    the result.  */
2717 
2718 tree
merge_decl_attributes(olddecl,newdecl)2719 merge_decl_attributes (olddecl, newdecl)
2720      tree olddecl, newdecl;
2721 {
2722   return merge_attributes (DECL_ATTRIBUTES (olddecl),
2723 			   DECL_ATTRIBUTES (newdecl));
2724 }
2725 
2726 #ifdef TARGET_DLLIMPORT_DECL_ATTRIBUTES
2727 
2728 /* Specialization of merge_decl_attributes for various Windows targets.
2729 
2730    This handles the following situation:
2731 
2732      __declspec (dllimport) int foo;
2733      int foo;
2734 
2735    The second instance of `foo' nullifies the dllimport.  */
2736 
2737 tree
merge_dllimport_decl_attributes(old,new)2738 merge_dllimport_decl_attributes (old, new)
2739      tree old;
2740      tree new;
2741 {
2742   tree a;
2743   int delete_dllimport_p;
2744 
2745   old = DECL_ATTRIBUTES (old);
2746   new = DECL_ATTRIBUTES (new);
2747 
2748   /* What we need to do here is remove from `old' dllimport if it doesn't
2749      appear in `new'.  dllimport behaves like extern: if a declaration is
2750      marked dllimport and a definition appears later, then the object
2751      is not dllimport'd.  */
2752   if (lookup_attribute ("dllimport", old) != NULL_TREE
2753       && lookup_attribute ("dllimport", new) == NULL_TREE)
2754     delete_dllimport_p = 1;
2755   else
2756     delete_dllimport_p = 0;
2757 
2758   a = merge_attributes (old, new);
2759 
2760   if (delete_dllimport_p)
2761     {
2762       tree prev, t;
2763 
2764       /* Scan the list for dllimport and delete it.  */
2765       for (prev = NULL_TREE, t = a; t; prev = t, t = TREE_CHAIN (t))
2766 	{
2767 	  if (is_attribute_p ("dllimport", TREE_PURPOSE (t)))
2768 	    {
2769 	      if (prev == NULL_TREE)
2770 		a = TREE_CHAIN (a);
2771 	      else
2772 		TREE_CHAIN (prev) = TREE_CHAIN (t);
2773 	      break;
2774 	    }
2775 	}
2776     }
2777 
2778   return a;
2779 }
2780 
2781 #endif /* TARGET_DLLIMPORT_DECL_ATTRIBUTES  */
2782 
2783 /* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask
2784    of the various TYPE_QUAL values.  */
2785 
2786 static void
set_type_quals(type,type_quals)2787 set_type_quals (type, type_quals)
2788      tree type;
2789      int type_quals;
2790 {
2791   TYPE_READONLY (type) = (type_quals & TYPE_QUAL_CONST) != 0;
2792   TYPE_VOLATILE (type) = (type_quals & TYPE_QUAL_VOLATILE) != 0;
2793   TYPE_RESTRICT (type) = (type_quals & TYPE_QUAL_RESTRICT) != 0;
2794 }
2795 
2796 /* Return a version of the TYPE, qualified as indicated by the
2797    TYPE_QUALS, if one exists.  If no qualified version exists yet,
2798    return NULL_TREE.  */
2799 
2800 tree
get_qualified_type(type,type_quals)2801 get_qualified_type (type, type_quals)
2802      tree type;
2803      int type_quals;
2804 {
2805   tree t;
2806 
2807   /* Search the chain of variants to see if there is already one there just
2808      like the one we need to have.  If so, use that existing one.  We must
2809      preserve the TYPE_NAME, since there is code that depends on this.  */
2810   for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
2811     if (TYPE_QUALS (t) == type_quals && TYPE_NAME (t) == TYPE_NAME (type)
2812         && TYPE_CONTEXT (t) == TYPE_CONTEXT (type))
2813       return t;
2814 
2815   return NULL_TREE;
2816 }
2817 
2818 /* Like get_qualified_type, but creates the type if it does not
2819    exist.  This function never returns NULL_TREE.  */
2820 
2821 tree
build_qualified_type(type,type_quals)2822 build_qualified_type (type, type_quals)
2823      tree type;
2824      int type_quals;
2825 {
2826   tree t;
2827 
2828   /* See if we already have the appropriate qualified variant.  */
2829   t = get_qualified_type (type, type_quals);
2830 
2831   /* If not, build it.  */
2832   if (!t)
2833     {
2834       t = build_type_copy (type);
2835       set_type_quals (t, type_quals);
2836     }
2837 
2838   return t;
2839 }
2840 
2841 /* Create a new variant of TYPE, equivalent but distinct.
2842    This is so the caller can modify it.  */
2843 
2844 tree
build_type_copy(type)2845 build_type_copy (type)
2846      tree type;
2847 {
2848   tree t, m = TYPE_MAIN_VARIANT (type);
2849 
2850   t = copy_node (type);
2851 
2852   TYPE_POINTER_TO (t) = 0;
2853   TYPE_REFERENCE_TO (t) = 0;
2854 
2855   /* Add this type to the chain of variants of TYPE.  */
2856   TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
2857   TYPE_NEXT_VARIANT (m) = t;
2858 
2859   return t;
2860 }
2861 
2862 /* Hashing of types so that we don't make duplicates.
2863    The entry point is `type_hash_canon'.  */
2864 
2865 /* Compute a hash code for a list of types (chain of TREE_LIST nodes
2866    with types in the TREE_VALUE slots), by adding the hash codes
2867    of the individual types.  */
2868 
2869 unsigned int
type_hash_list(list)2870 type_hash_list (list)
2871      tree list;
2872 {
2873   unsigned int hashcode;
2874   tree tail;
2875 
2876   for (hashcode = 0, tail = list; tail; tail = TREE_CHAIN (tail))
2877     hashcode += TYPE_HASH (TREE_VALUE (tail));
2878 
2879   return hashcode;
2880 }
2881 
2882 /* These are the Hashtable callback functions.  */
2883 
2884 /* Returns true if the types are equal.  */
2885 
2886 static int
type_hash_eq(va,vb)2887 type_hash_eq (va, vb)
2888      const void *va;
2889      const void *vb;
2890 {
2891   const struct type_hash *a = va, *b = vb;
2892   if (a->hash == b->hash
2893       && TREE_CODE (a->type) == TREE_CODE (b->type)
2894       && TREE_TYPE (a->type) == TREE_TYPE (b->type)
2895       && attribute_list_equal (TYPE_ATTRIBUTES (a->type),
2896 			       TYPE_ATTRIBUTES (b->type))
2897       && TYPE_ALIGN (a->type) == TYPE_ALIGN (b->type)
2898       && (TYPE_MAX_VALUE (a->type) == TYPE_MAX_VALUE (b->type)
2899 	  || tree_int_cst_equal (TYPE_MAX_VALUE (a->type),
2900 				 TYPE_MAX_VALUE (b->type)))
2901       && (TYPE_MIN_VALUE (a->type) == TYPE_MIN_VALUE (b->type)
2902 	  || tree_int_cst_equal (TYPE_MIN_VALUE (a->type),
2903 				 TYPE_MIN_VALUE (b->type)))
2904       /* Note that TYPE_DOMAIN is TYPE_ARG_TYPES for FUNCTION_TYPE.  */
2905       && (TYPE_DOMAIN (a->type) == TYPE_DOMAIN (b->type)
2906 	  || (TYPE_DOMAIN (a->type)
2907 	      && TREE_CODE (TYPE_DOMAIN (a->type)) == TREE_LIST
2908 	      && TYPE_DOMAIN (b->type)
2909 	      && TREE_CODE (TYPE_DOMAIN (b->type)) == TREE_LIST
2910 	      && type_list_equal (TYPE_DOMAIN (a->type),
2911 				  TYPE_DOMAIN (b->type)))))
2912     return 1;
2913   return 0;
2914 }
2915 
2916 /* Return the cached hash value.  */
2917 
2918 static hashval_t
type_hash_hash(item)2919 type_hash_hash (item)
2920      const void *item;
2921 {
2922   return ((const struct type_hash *) item)->hash;
2923 }
2924 
2925 /* Look in the type hash table for a type isomorphic to TYPE.
2926    If one is found, return it.  Otherwise return 0.  */
2927 
2928 tree
type_hash_lookup(hashcode,type)2929 type_hash_lookup (hashcode, type)
2930      unsigned int hashcode;
2931      tree type;
2932 {
2933   struct type_hash *h, in;
2934 
2935   /* The TYPE_ALIGN field of a type is set by layout_type(), so we
2936      must call that routine before comparing TYPE_ALIGNs.  */
2937   layout_type (type);
2938 
2939   in.hash = hashcode;
2940   in.type = type;
2941 
2942   h = htab_find_with_hash (type_hash_table, &in, hashcode);
2943   if (h)
2944     return h->type;
2945   return NULL_TREE;
2946 }
2947 
2948 /* Add an entry to the type-hash-table
2949    for a type TYPE whose hash code is HASHCODE.  */
2950 
2951 void
type_hash_add(hashcode,type)2952 type_hash_add (hashcode, type)
2953      unsigned int hashcode;
2954      tree type;
2955 {
2956   struct type_hash *h;
2957   void **loc;
2958 
2959   h = (struct type_hash *) ggc_alloc (sizeof (struct type_hash));
2960   h->hash = hashcode;
2961   h->type = type;
2962   loc = htab_find_slot_with_hash (type_hash_table, h, hashcode, INSERT);
2963   *(struct type_hash **) loc = h;
2964 }
2965 
2966 /* Given TYPE, and HASHCODE its hash code, return the canonical
2967    object for an identical type if one already exists.
2968    Otherwise, return TYPE, and record it as the canonical object
2969    if it is a permanent object.
2970 
2971    To use this function, first create a type of the sort you want.
2972    Then compute its hash code from the fields of the type that
2973    make it different from other similar types.
2974    Then call this function and use the value.
2975    This function frees the type you pass in if it is a duplicate.  */
2976 
2977 /* Set to 1 to debug without canonicalization.  Never set by program.  */
2978 int debug_no_type_hash = 0;
2979 
2980 tree
type_hash_canon(hashcode,type)2981 type_hash_canon (hashcode, type)
2982      unsigned int hashcode;
2983      tree type;
2984 {
2985   tree t1;
2986 
2987   if (debug_no_type_hash)
2988     return type;
2989 
2990   /* See if the type is in the hash table already.  If so, return it.
2991      Otherwise, add the type.  */
2992   t1 = type_hash_lookup (hashcode, type);
2993   if (t1 != 0)
2994     {
2995 #ifdef GATHER_STATISTICS
2996       tree_node_counts[(int) t_kind]--;
2997       tree_node_sizes[(int) t_kind] -= sizeof (struct tree_type);
2998 #endif
2999       return t1;
3000     }
3001   else
3002     {
3003       type_hash_add (hashcode, type);
3004       return type;
3005     }
3006 }
3007 
3008 /* See if the data pointed to by the type hash table is marked.  We consider
3009    it marked if the type is marked or if a debug type number or symbol
3010    table entry has been made for the type.  This reduces the amount of
3011    debugging output and eliminates that dependency of the debug output on
3012    the number of garbage collections.  */
3013 
3014 static int
type_hash_marked_p(p)3015 type_hash_marked_p (p)
3016      const void *p;
3017 {
3018   tree type = ((struct type_hash *) p)->type;
3019 
3020   return ggc_marked_p (type) || TYPE_SYMTAB_POINTER (type);
3021 }
3022 
3023 static void
print_type_hash_statistics()3024 print_type_hash_statistics ()
3025 {
3026   fprintf (stderr, "Type hash: size %ld, %ld elements, %f collisions\n",
3027 	   (long) htab_size (type_hash_table),
3028 	   (long) htab_elements (type_hash_table),
3029 	   htab_collisions (type_hash_table));
3030 }
3031 
3032 /* Compute a hash code for a list of attributes (chain of TREE_LIST nodes
3033    with names in the TREE_PURPOSE slots and args in the TREE_VALUE slots),
3034    by adding the hash codes of the individual attributes.  */
3035 
3036 unsigned int
attribute_hash_list(list)3037 attribute_hash_list (list)
3038      tree list;
3039 {
3040   unsigned int hashcode;
3041   tree tail;
3042 
3043   for (hashcode = 0, tail = list; tail; tail = TREE_CHAIN (tail))
3044     /* ??? Do we want to add in TREE_VALUE too? */
3045     hashcode += TYPE_HASH (TREE_PURPOSE (tail));
3046   return hashcode;
3047 }
3048 
3049 /* Given two lists of attributes, return true if list l2 is
3050    equivalent to l1.  */
3051 
3052 int
attribute_list_equal(l1,l2)3053 attribute_list_equal (l1, l2)
3054      tree l1, l2;
3055 {
3056   return attribute_list_contained (l1, l2)
3057 	 && attribute_list_contained (l2, l1);
3058 }
3059 
3060 /* Given two lists of attributes, return true if list L2 is
3061    completely contained within L1.  */
3062 /* ??? This would be faster if attribute names were stored in a canonicalized
3063    form.  Otherwise, if L1 uses `foo' and L2 uses `__foo__', the long method
3064    must be used to show these elements are equivalent (which they are).  */
3065 /* ??? It's not clear that attributes with arguments will always be handled
3066    correctly.  */
3067 
3068 int
attribute_list_contained(l1,l2)3069 attribute_list_contained (l1, l2)
3070      tree l1, l2;
3071 {
3072   tree t1, t2;
3073 
3074   /* First check the obvious, maybe the lists are identical.  */
3075   if (l1 == l2)
3076     return 1;
3077 
3078   /* Maybe the lists are similar.  */
3079   for (t1 = l1, t2 = l2;
3080        t1 != 0 && t2 != 0
3081         && TREE_PURPOSE (t1) == TREE_PURPOSE (t2)
3082         && TREE_VALUE (t1) == TREE_VALUE (t2);
3083        t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2));
3084 
3085   /* Maybe the lists are equal.  */
3086   if (t1 == 0 && t2 == 0)
3087     return 1;
3088 
3089   for (; t2 != 0; t2 = TREE_CHAIN (t2))
3090     {
3091       tree attr;
3092       for (attr = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2)), l1);
3093 	   attr != NULL_TREE;
3094 	   attr = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2)),
3095 				    TREE_CHAIN (attr)))
3096 	{
3097 	  if (simple_cst_equal (TREE_VALUE (t2), TREE_VALUE (attr)) == 1)
3098 	    break;
3099 	}
3100 
3101       if (attr == 0)
3102 	return 0;
3103 
3104       if (simple_cst_equal (TREE_VALUE (t2), TREE_VALUE (attr)) != 1)
3105 	return 0;
3106     }
3107 
3108   return 1;
3109 }
3110 
3111 /* Given two lists of types
3112    (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
3113    return 1 if the lists contain the same types in the same order.
3114    Also, the TREE_PURPOSEs must match.  */
3115 
3116 int
type_list_equal(l1,l2)3117 type_list_equal (l1, l2)
3118      tree l1, l2;
3119 {
3120   tree t1, t2;
3121 
3122   for (t1 = l1, t2 = l2; t1 && t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
3123     if (TREE_VALUE (t1) != TREE_VALUE (t2)
3124 	|| (TREE_PURPOSE (t1) != TREE_PURPOSE (t2)
3125 	    && ! (1 == simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2))
3126 		  && (TREE_TYPE (TREE_PURPOSE (t1))
3127 		      == TREE_TYPE (TREE_PURPOSE (t2))))))
3128       return 0;
3129 
3130   return t1 == t2;
3131 }
3132 
3133 /* Returns the number of arguments to the FUNCTION_TYPE or METHOD_TYPE
3134    given by TYPE.  If the argument list accepts variable arguments,
3135    then this function counts only the ordinary arguments.  */
3136 
3137 int
type_num_arguments(type)3138 type_num_arguments (type)
3139      tree type;
3140 {
3141   int i = 0;
3142   tree t;
3143 
3144   for (t = TYPE_ARG_TYPES (type); t; t = TREE_CHAIN (t))
3145     /* If the function does not take a variable number of arguments,
3146        the last element in the list will have type `void'.  */
3147     if (VOID_TYPE_P (TREE_VALUE (t)))
3148       break;
3149     else
3150       ++i;
3151 
3152   return i;
3153 }
3154 
3155 /* Nonzero if integer constants T1 and T2
3156    represent the same constant value.  */
3157 
3158 int
tree_int_cst_equal(t1,t2)3159 tree_int_cst_equal (t1, t2)
3160      tree t1, t2;
3161 {
3162   if (t1 == t2)
3163     return 1;
3164 
3165   if (t1 == 0 || t2 == 0)
3166     return 0;
3167 
3168   if (TREE_CODE (t1) == INTEGER_CST
3169       && TREE_CODE (t2) == INTEGER_CST
3170       && TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
3171       && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2))
3172     return 1;
3173 
3174   return 0;
3175 }
3176 
3177 /* Nonzero if integer constants T1 and T2 represent values that satisfy <.
3178    The precise way of comparison depends on their data type.  */
3179 
3180 int
tree_int_cst_lt(t1,t2)3181 tree_int_cst_lt (t1, t2)
3182      tree t1, t2;
3183 {
3184   if (t1 == t2)
3185     return 0;
3186 
3187   if (TREE_UNSIGNED (TREE_TYPE (t1)) != TREE_UNSIGNED (TREE_TYPE (t2)))
3188     {
3189       int t1_sgn = tree_int_cst_sgn (t1);
3190       int t2_sgn = tree_int_cst_sgn (t2);
3191 
3192       if (t1_sgn < t2_sgn)
3193 	return 1;
3194       else if (t1_sgn > t2_sgn)
3195 	return 0;
3196       /* Otherwise, both are non-negative, so we compare them as
3197 	 unsigned just in case one of them would overflow a signed
3198 	 type.  */
3199     }
3200   else if (! TREE_UNSIGNED (TREE_TYPE (t1)))
3201     return INT_CST_LT (t1, t2);
3202 
3203   return INT_CST_LT_UNSIGNED (t1, t2);
3204 }
3205 
3206 /* Returns -1 if T1 < T2, 0 if T1 == T2, and 1 if T1 > T2.  */
3207 
3208 int
tree_int_cst_compare(t1,t2)3209 tree_int_cst_compare (t1, t2)
3210      tree t1;
3211      tree t2;
3212 {
3213   if (tree_int_cst_lt (t1, t2))
3214     return -1;
3215   else if (tree_int_cst_lt (t2, t1))
3216     return 1;
3217   else
3218     return 0;
3219 }
3220 
3221 /* Return 1 if T is an INTEGER_CST that can be manipulated efficiently on
3222    the host.  If POS is zero, the value can be represented in a single
3223    HOST_WIDE_INT.  If POS is nonzero, the value must be positive and can
3224    be represented in a single unsigned HOST_WIDE_INT.  */
3225 
3226 int
host_integerp(t,pos)3227 host_integerp (t, pos)
3228      tree t;
3229      int pos;
3230 {
3231   return (TREE_CODE (t) == INTEGER_CST
3232 	  && ! TREE_OVERFLOW (t)
3233 	  && ((TREE_INT_CST_HIGH (t) == 0
3234 	       && (HOST_WIDE_INT) TREE_INT_CST_LOW (t) >= 0)
3235 	      || (! pos && TREE_INT_CST_HIGH (t) == -1
3236 		  && (HOST_WIDE_INT) TREE_INT_CST_LOW (t) < 0
3237 		  && ! TREE_UNSIGNED (TREE_TYPE (t)))
3238 	      || (pos && TREE_INT_CST_HIGH (t) == 0)));
3239 }
3240 
3241 /* Return the HOST_WIDE_INT least significant bits of T if it is an
3242    INTEGER_CST and there is no overflow.  POS is nonzero if the result must
3243    be positive.  Abort if we cannot satisfy the above conditions.  */
3244 
3245 HOST_WIDE_INT
tree_low_cst(t,pos)3246 tree_low_cst (t, pos)
3247      tree t;
3248      int pos;
3249 {
3250   if (host_integerp (t, pos))
3251     return TREE_INT_CST_LOW (t);
3252   else
3253     abort ();
3254 }
3255 
3256 /* Return the most significant bit of the integer constant T.  */
3257 
3258 int
tree_int_cst_msb(t)3259 tree_int_cst_msb (t)
3260      tree t;
3261 {
3262   int prec;
3263   HOST_WIDE_INT h;
3264   unsigned HOST_WIDE_INT l;
3265 
3266   /* Note that using TYPE_PRECISION here is wrong.  We care about the
3267      actual bits, not the (arbitrary) range of the type.  */
3268   prec = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (t))) - 1;
3269   rshift_double (TREE_INT_CST_LOW (t), TREE_INT_CST_HIGH (t), prec,
3270 		 2 * HOST_BITS_PER_WIDE_INT, &l, &h, 0);
3271   return (l & 1) == 1;
3272 }
3273 
3274 /* Return an indication of the sign of the integer constant T.
3275    The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0.
3276    Note that -1 will never be returned it T's type is unsigned.  */
3277 
3278 int
tree_int_cst_sgn(t)3279 tree_int_cst_sgn (t)
3280      tree t;
3281 {
3282   if (TREE_INT_CST_LOW (t) == 0 && TREE_INT_CST_HIGH (t) == 0)
3283     return 0;
3284   else if (TREE_UNSIGNED (TREE_TYPE (t)))
3285     return 1;
3286   else if (TREE_INT_CST_HIGH (t) < 0)
3287     return -1;
3288   else
3289     return 1;
3290 }
3291 
3292 /* Compare two constructor-element-type constants.  Return 1 if the lists
3293    are known to be equal; otherwise return 0.  */
3294 
3295 int
simple_cst_list_equal(l1,l2)3296 simple_cst_list_equal (l1, l2)
3297      tree l1, l2;
3298 {
3299   while (l1 != NULL_TREE && l2 != NULL_TREE)
3300     {
3301       if (simple_cst_equal (TREE_VALUE (l1), TREE_VALUE (l2)) != 1)
3302 	return 0;
3303 
3304       l1 = TREE_CHAIN (l1);
3305       l2 = TREE_CHAIN (l2);
3306     }
3307 
3308   return l1 == l2;
3309 }
3310 
3311 /* Return truthvalue of whether T1 is the same tree structure as T2.
3312    Return 1 if they are the same.
3313    Return 0 if they are understandably different.
3314    Return -1 if either contains tree structure not understood by
3315    this function.  */
3316 
3317 int
simple_cst_equal(t1,t2)3318 simple_cst_equal (t1, t2)
3319      tree t1, t2;
3320 {
3321   enum tree_code code1, code2;
3322   int cmp;
3323   int i;
3324 
3325   if (t1 == t2)
3326     return 1;
3327   if (t1 == 0 || t2 == 0)
3328     return 0;
3329 
3330   code1 = TREE_CODE (t1);
3331   code2 = TREE_CODE (t2);
3332 
3333   if (code1 == NOP_EXPR || code1 == CONVERT_EXPR || code1 == NON_LVALUE_EXPR)
3334     {
3335       if (code2 == NOP_EXPR || code2 == CONVERT_EXPR
3336 	  || code2 == NON_LVALUE_EXPR)
3337 	return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3338       else
3339 	return simple_cst_equal (TREE_OPERAND (t1, 0), t2);
3340     }
3341 
3342   else if (code2 == NOP_EXPR || code2 == CONVERT_EXPR
3343 	   || code2 == NON_LVALUE_EXPR)
3344     return simple_cst_equal (t1, TREE_OPERAND (t2, 0));
3345 
3346   if (code1 != code2)
3347     return 0;
3348 
3349   switch (code1)
3350     {
3351     case INTEGER_CST:
3352       return (TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
3353 	      && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2));
3354 
3355     case REAL_CST:
3356       return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
3357 
3358     case STRING_CST:
3359       return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
3360 	      && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
3361 			 TREE_STRING_LENGTH (t1)));
3362 
3363     case CONSTRUCTOR:
3364       if (CONSTRUCTOR_ELTS (t1) == CONSTRUCTOR_ELTS (t2))
3365 	return 1;
3366       else
3367 	abort ();
3368 
3369     case SAVE_EXPR:
3370       return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3371 
3372     case CALL_EXPR:
3373       cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3374       if (cmp <= 0)
3375 	return cmp;
3376       return
3377 	simple_cst_list_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
3378 
3379     case TARGET_EXPR:
3380       /* Special case: if either target is an unallocated VAR_DECL,
3381 	 it means that it's going to be unified with whatever the
3382 	 TARGET_EXPR is really supposed to initialize, so treat it
3383 	 as being equivalent to anything.  */
3384       if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL
3385 	   && DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE
3386 	   && !DECL_RTL_SET_P (TREE_OPERAND (t1, 0)))
3387 	  || (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL
3388 	      && DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE
3389 	      && !DECL_RTL_SET_P (TREE_OPERAND (t2, 0))))
3390 	cmp = 1;
3391       else
3392 	cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3393 
3394       if (cmp <= 0)
3395 	return cmp;
3396 
3397       return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
3398 
3399     case WITH_CLEANUP_EXPR:
3400       cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3401       if (cmp <= 0)
3402 	return cmp;
3403 
3404       return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t1, 1));
3405 
3406     case COMPONENT_REF:
3407       if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1))
3408 	return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3409 
3410       return 0;
3411 
3412     case VAR_DECL:
3413     case PARM_DECL:
3414     case CONST_DECL:
3415     case FUNCTION_DECL:
3416       return 0;
3417 
3418     default:
3419       break;
3420     }
3421 
3422   /* This general rule works for most tree codes.  All exceptions should be
3423      handled above.  If this is a language-specific tree code, we can't
3424      trust what might be in the operand, so say we don't know
3425      the situation.  */
3426   if ((int) code1 >= (int) LAST_AND_UNUSED_TREE_CODE)
3427     return -1;
3428 
3429   switch (TREE_CODE_CLASS (code1))
3430     {
3431     case '1':
3432     case '2':
3433     case '<':
3434     case 'e':
3435     case 'r':
3436     case 's':
3437       cmp = 1;
3438       for (i = 0; i < TREE_CODE_LENGTH (code1); i++)
3439 	{
3440 	  cmp = simple_cst_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i));
3441 	  if (cmp <= 0)
3442 	    return cmp;
3443 	}
3444 
3445       return cmp;
3446 
3447     default:
3448       return -1;
3449     }
3450 }
3451 
3452 /* Compare the value of T, an INTEGER_CST, with U, an unsigned integer value.
3453    Return -1, 0, or 1 if the value of T is less than, equal to, or greater
3454    than U, respectively.  */
3455 
3456 int
compare_tree_int(t,u)3457 compare_tree_int (t, u)
3458      tree t;
3459      unsigned HOST_WIDE_INT u;
3460 {
3461   if (tree_int_cst_sgn (t) < 0)
3462     return -1;
3463   else if (TREE_INT_CST_HIGH (t) != 0)
3464     return 1;
3465   else if (TREE_INT_CST_LOW (t) == u)
3466     return 0;
3467   else if (TREE_INT_CST_LOW (t) < u)
3468     return -1;
3469   else
3470     return 1;
3471 }
3472 
3473 /* Constructors for pointer, array and function types.
3474    (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
3475    constructed by language-dependent code, not here.)  */
3476 
3477 /* Construct, lay out and return the type of pointers to TO_TYPE.
3478    If such a type has already been constructed, reuse it.  */
3479 
3480 tree
build_pointer_type(to_type)3481 build_pointer_type (to_type)
3482      tree to_type;
3483 {
3484   tree t = TYPE_POINTER_TO (to_type);
3485 
3486   /* First, if we already have a type for pointers to TO_TYPE, use it.  */
3487 
3488   if (t != 0)
3489     return t;
3490 
3491   /* We need a new one.  */
3492   t = make_node (POINTER_TYPE);
3493 
3494   TREE_TYPE (t) = to_type;
3495 
3496   /* Record this type as the pointer to TO_TYPE.  */
3497   TYPE_POINTER_TO (to_type) = t;
3498 
3499   /* Lay out the type.  This function has many callers that are concerned
3500      with expression-construction, and this simplifies them all.
3501      Also, it guarantees the TYPE_SIZE is in the same obstack as the type.  */
3502   layout_type (t);
3503 
3504   return t;
3505 }
3506 
3507 /* Build the node for the type of references-to-TO_TYPE.  */
3508 
3509 tree
build_reference_type(to_type)3510 build_reference_type (to_type)
3511      tree to_type;
3512 {
3513   tree t = TYPE_REFERENCE_TO (to_type);
3514 
3515   /* First, if we already have a type for pointers to TO_TYPE, use it.  */
3516 
3517   if (t)
3518     return t;
3519 
3520   /* We need a new one.  */
3521   t = make_node (REFERENCE_TYPE);
3522 
3523   TREE_TYPE (t) = to_type;
3524 
3525   /* Record this type as the pointer to TO_TYPE.  */
3526   TYPE_REFERENCE_TO (to_type) = t;
3527 
3528   layout_type (t);
3529 
3530   return t;
3531 }
3532 
3533 /* Build a type that is compatible with t but has no cv quals anywhere
3534    in its type, thus
3535 
3536    const char *const *const *  ->  char ***.  */
3537 
3538 tree
build_type_no_quals(t)3539 build_type_no_quals (t)
3540      tree t;
3541 {
3542   switch (TREE_CODE (t))
3543     {
3544     case POINTER_TYPE:
3545       return build_pointer_type (build_type_no_quals (TREE_TYPE (t)));
3546     case REFERENCE_TYPE:
3547       return build_reference_type (build_type_no_quals (TREE_TYPE (t)));
3548     default:
3549       return TYPE_MAIN_VARIANT (t);
3550     }
3551 }
3552 
3553 /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
3554    MAXVAL should be the maximum value in the domain
3555    (one less than the length of the array).
3556 
3557    The maximum value that MAXVAL can have is INT_MAX for a HOST_WIDE_INT.
3558    We don't enforce this limit, that is up to caller (e.g. language front end).
3559    The limit exists because the result is a signed type and we don't handle
3560    sizes that use more than one HOST_WIDE_INT.  */
3561 
3562 tree
build_index_type(maxval)3563 build_index_type (maxval)
3564      tree maxval;
3565 {
3566   tree itype = make_node (INTEGER_TYPE);
3567 
3568   TREE_TYPE (itype) = sizetype;
3569   TYPE_PRECISION (itype) = TYPE_PRECISION (sizetype);
3570   TYPE_MIN_VALUE (itype) = size_zero_node;
3571   TYPE_MAX_VALUE (itype) = convert (sizetype, maxval);
3572   TYPE_MODE (itype) = TYPE_MODE (sizetype);
3573   TYPE_SIZE (itype) = TYPE_SIZE (sizetype);
3574   TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (sizetype);
3575   TYPE_ALIGN (itype) = TYPE_ALIGN (sizetype);
3576   TYPE_USER_ALIGN (itype) = TYPE_USER_ALIGN (sizetype);
3577 
3578   if (host_integerp (maxval, 1))
3579     return type_hash_canon (tree_low_cst (maxval, 1), itype);
3580   else
3581     return itype;
3582 }
3583 
3584 /* Create a range of some discrete type TYPE (an INTEGER_TYPE,
3585    ENUMERAL_TYPE, BOOLEAN_TYPE, or CHAR_TYPE), with
3586    low bound LOWVAL and high bound HIGHVAL.
3587    if TYPE==NULL_TREE, sizetype is used.  */
3588 
3589 tree
build_range_type(type,lowval,highval)3590 build_range_type (type, lowval, highval)
3591      tree type, lowval, highval;
3592 {
3593   tree itype = make_node (INTEGER_TYPE);
3594 
3595   TREE_TYPE (itype) = type;
3596   if (type == NULL_TREE)
3597     type = sizetype;
3598 
3599   TYPE_MIN_VALUE (itype) = convert (type, lowval);
3600   TYPE_MAX_VALUE (itype) = highval ? convert (type, highval) : NULL;
3601 
3602   TYPE_PRECISION (itype) = TYPE_PRECISION (type);
3603   TYPE_MODE (itype) = TYPE_MODE (type);
3604   TYPE_SIZE (itype) = TYPE_SIZE (type);
3605   TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (type);
3606   TYPE_ALIGN (itype) = TYPE_ALIGN (type);
3607   TYPE_USER_ALIGN (itype) = TYPE_USER_ALIGN (type);
3608 
3609   if (host_integerp (lowval, 0) && highval != 0 && host_integerp (highval, 0))
3610     return type_hash_canon (tree_low_cst (highval, 0)
3611 			    - tree_low_cst (lowval, 0),
3612 			    itype);
3613   else
3614     return itype;
3615 }
3616 
3617 /* Just like build_index_type, but takes lowval and highval instead
3618    of just highval (maxval).  */
3619 
3620 tree
build_index_2_type(lowval,highval)3621 build_index_2_type (lowval, highval)
3622      tree lowval, highval;
3623 {
3624   return build_range_type (sizetype, lowval, highval);
3625 }
3626 
3627 /* Return nonzero iff ITYPE1 and ITYPE2 are equal (in the LISP sense).
3628    Needed because when index types are not hashed, equal index types
3629    built at different times appear distinct, even though structurally,
3630    they are not.  */
3631 
3632 int
index_type_equal(itype1,itype2)3633 index_type_equal (itype1, itype2)
3634      tree itype1, itype2;
3635 {
3636   if (TREE_CODE (itype1) != TREE_CODE (itype2))
3637     return 0;
3638 
3639   if (TREE_CODE (itype1) == INTEGER_TYPE)
3640     {
3641       if (TYPE_PRECISION (itype1) != TYPE_PRECISION (itype2)
3642 	  || TYPE_MODE (itype1) != TYPE_MODE (itype2)
3643 	  || simple_cst_equal (TYPE_SIZE (itype1), TYPE_SIZE (itype2)) != 1
3644 	  || TYPE_ALIGN (itype1) != TYPE_ALIGN (itype2))
3645 	return 0;
3646 
3647       if (1 == simple_cst_equal (TYPE_MIN_VALUE (itype1),
3648 				 TYPE_MIN_VALUE (itype2))
3649 	  && 1 == simple_cst_equal (TYPE_MAX_VALUE (itype1),
3650 				    TYPE_MAX_VALUE (itype2)))
3651 	return 1;
3652     }
3653 
3654   return 0;
3655 }
3656 
3657 /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
3658    and number of elements specified by the range of values of INDEX_TYPE.
3659    If such a type has already been constructed, reuse it.  */
3660 
3661 tree
build_array_type(elt_type,index_type)3662 build_array_type (elt_type, index_type)
3663      tree elt_type, index_type;
3664 {
3665   tree t;
3666   unsigned int hashcode;
3667 
3668   if (TREE_CODE (elt_type) == FUNCTION_TYPE)
3669     {
3670       error ("arrays of functions are not meaningful");
3671       elt_type = integer_type_node;
3672     }
3673 
3674   /* Make sure TYPE_POINTER_TO (elt_type) is filled in.  */
3675   build_pointer_type (elt_type);
3676 
3677   /* Allocate the array after the pointer type,
3678      in case we free it in type_hash_canon.  */
3679   t = make_node (ARRAY_TYPE);
3680   TREE_TYPE (t) = elt_type;
3681   TYPE_DOMAIN (t) = index_type;
3682 
3683   if (index_type == 0)
3684     {
3685       return t;
3686     }
3687 
3688   hashcode = TYPE_HASH (elt_type) + TYPE_HASH (index_type);
3689   t = type_hash_canon (hashcode, t);
3690 
3691   if (!COMPLETE_TYPE_P (t))
3692     layout_type (t);
3693   return t;
3694 }
3695 
3696 /* Return the TYPE of the elements comprising
3697    the innermost dimension of ARRAY.  */
3698 
3699 tree
get_inner_array_type(array)3700 get_inner_array_type (array)
3701      tree array;
3702 {
3703   tree type = TREE_TYPE (array);
3704 
3705   while (TREE_CODE (type) == ARRAY_TYPE)
3706     type = TREE_TYPE (type);
3707 
3708   return type;
3709 }
3710 
3711 /* Construct, lay out and return
3712    the type of functions returning type VALUE_TYPE
3713    given arguments of types ARG_TYPES.
3714    ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
3715    are data type nodes for the arguments of the function.
3716    If such a type has already been constructed, reuse it.  */
3717 
3718 tree
build_function_type(value_type,arg_types)3719 build_function_type (value_type, arg_types)
3720      tree value_type, arg_types;
3721 {
3722   tree t;
3723   unsigned int hashcode;
3724 
3725   if (TREE_CODE (value_type) == FUNCTION_TYPE)
3726     {
3727       error ("function return type cannot be function");
3728       value_type = integer_type_node;
3729     }
3730 
3731   /* Make a node of the sort we want.  */
3732   t = make_node (FUNCTION_TYPE);
3733   TREE_TYPE (t) = value_type;
3734   TYPE_ARG_TYPES (t) = arg_types;
3735 
3736   /* If we already have such a type, use the old one and free this one.  */
3737   hashcode = TYPE_HASH (value_type) + type_hash_list (arg_types);
3738   t = type_hash_canon (hashcode, t);
3739 
3740   if (!COMPLETE_TYPE_P (t))
3741     layout_type (t);
3742   return t;
3743 }
3744 
3745 /* Build a function type.  The RETURN_TYPE is the type retured by the
3746    function.  If additional arguments are provided, they are
3747    additional argument types.  The list of argument types must always
3748    be terminated by NULL_TREE.  */
3749 
3750 tree
build_function_type_list(tree return_type,...)3751 build_function_type_list VPARAMS ((tree return_type, ...))
3752 {
3753   tree t, args, last;
3754 
3755   VA_OPEN (p, return_type);
3756   VA_FIXEDARG (p, tree, return_type);
3757 
3758   t = va_arg (p, tree);
3759   for (args = NULL_TREE; t != NULL_TREE; t = va_arg (p, tree))
3760     args = tree_cons (NULL_TREE, t, args);
3761 
3762   last = args;
3763   args = nreverse (args);
3764   TREE_CHAIN (last) = void_list_node;
3765   args = build_function_type (return_type, args);
3766 
3767   VA_CLOSE (p);
3768   return args;
3769 }
3770 
3771 /* Construct, lay out and return the type of methods belonging to class
3772    BASETYPE and whose arguments and values are described by TYPE.
3773    If that type exists already, reuse it.
3774    TYPE must be a FUNCTION_TYPE node.  */
3775 
3776 tree
build_method_type(basetype,type)3777 build_method_type (basetype, type)
3778      tree basetype, type;
3779 {
3780   tree t;
3781   unsigned int hashcode;
3782 
3783   /* Make a node of the sort we want.  */
3784   t = make_node (METHOD_TYPE);
3785 
3786   if (TREE_CODE (type) != FUNCTION_TYPE)
3787     abort ();
3788 
3789   TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
3790   TREE_TYPE (t) = TREE_TYPE (type);
3791 
3792   /* The actual arglist for this function includes a "hidden" argument
3793      which is "this".  Put it into the list of argument types.  */
3794 
3795   TYPE_ARG_TYPES (t)
3796     = tree_cons (NULL_TREE,
3797 		 build_pointer_type (basetype), TYPE_ARG_TYPES (type));
3798 
3799   /* If we already have such a type, use the old one and free this one.  */
3800   hashcode = TYPE_HASH (basetype) + TYPE_HASH (type);
3801   t = type_hash_canon (hashcode, t);
3802 
3803   if (!COMPLETE_TYPE_P (t))
3804     layout_type (t);
3805 
3806   return t;
3807 }
3808 
3809 /* Construct, lay out and return the type of offsets to a value
3810    of type TYPE, within an object of type BASETYPE.
3811    If a suitable offset type exists already, reuse it.  */
3812 
3813 tree
build_offset_type(basetype,type)3814 build_offset_type (basetype, type)
3815      tree basetype, type;
3816 {
3817   tree t;
3818   unsigned int hashcode;
3819 
3820   /* Make a node of the sort we want.  */
3821   t = make_node (OFFSET_TYPE);
3822 
3823   TYPE_OFFSET_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
3824   TREE_TYPE (t) = type;
3825 
3826   /* If we already have such a type, use the old one and free this one.  */
3827   hashcode = TYPE_HASH (basetype) + TYPE_HASH (type);
3828   t = type_hash_canon (hashcode, t);
3829 
3830   if (!COMPLETE_TYPE_P (t))
3831     layout_type (t);
3832 
3833   return t;
3834 }
3835 
3836 /* Create a complex type whose components are COMPONENT_TYPE.  */
3837 
3838 tree
build_complex_type(component_type)3839 build_complex_type (component_type)
3840      tree component_type;
3841 {
3842   tree t;
3843   unsigned int hashcode;
3844 
3845   /* Make a node of the sort we want.  */
3846   t = make_node (COMPLEX_TYPE);
3847 
3848   TREE_TYPE (t) = TYPE_MAIN_VARIANT (component_type);
3849   set_type_quals (t, TYPE_QUALS (component_type));
3850 
3851   /* If we already have such a type, use the old one and free this one.  */
3852   hashcode = TYPE_HASH (component_type);
3853   t = type_hash_canon (hashcode, t);
3854 
3855   if (!COMPLETE_TYPE_P (t))
3856     layout_type (t);
3857 
3858   /* If we are writing Dwarf2 output we need to create a name,
3859      since complex is a fundamental type.  */
3860   if ((write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
3861       && ! TYPE_NAME (t))
3862     {
3863       const char *name;
3864       if (component_type == char_type_node)
3865 	name = "complex char";
3866       else if (component_type == signed_char_type_node)
3867 	name = "complex signed char";
3868       else if (component_type == unsigned_char_type_node)
3869 	name = "complex unsigned char";
3870       else if (component_type == short_integer_type_node)
3871 	name = "complex short int";
3872       else if (component_type == short_unsigned_type_node)
3873 	name = "complex short unsigned int";
3874       else if (component_type == integer_type_node)
3875 	name = "complex int";
3876       else if (component_type == unsigned_type_node)
3877 	name = "complex unsigned int";
3878       else if (component_type == long_integer_type_node)
3879 	name = "complex long int";
3880       else if (component_type == long_unsigned_type_node)
3881 	name = "complex long unsigned int";
3882       else if (component_type == long_long_integer_type_node)
3883 	name = "complex long long int";
3884       else if (component_type == long_long_unsigned_type_node)
3885 	name = "complex long long unsigned int";
3886       else
3887 	name = 0;
3888 
3889       if (name != 0)
3890 	TYPE_NAME (t) = get_identifier (name);
3891     }
3892 
3893   return t;
3894 }
3895 
3896 /* Return OP, stripped of any conversions to wider types as much as is safe.
3897    Converting the value back to OP's type makes a value equivalent to OP.
3898 
3899    If FOR_TYPE is nonzero, we return a value which, if converted to
3900    type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
3901 
3902    If FOR_TYPE is nonzero, unaligned bit-field references may be changed to the
3903    narrowest type that can hold the value, even if they don't exactly fit.
3904    Otherwise, bit-field references are changed to a narrower type
3905    only if they can be fetched directly from memory in that type.
3906 
3907    OP must have integer, real or enumeral type.  Pointers are not allowed!
3908 
3909    There are some cases where the obvious value we could return
3910    would regenerate to OP if converted to OP's type,
3911    but would not extend like OP to wider types.
3912    If FOR_TYPE indicates such extension is contemplated, we eschew such values.
3913    For example, if OP is (unsigned short)(signed char)-1,
3914    we avoid returning (signed char)-1 if FOR_TYPE is int,
3915    even though extending that to an unsigned short would regenerate OP,
3916    since the result of extending (signed char)-1 to (int)
3917    is different from (int) OP.  */
3918 
3919 tree
get_unwidened(op,for_type)3920 get_unwidened (op, for_type)
3921      tree op;
3922      tree for_type;
3923 {
3924   /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension.  */
3925   tree type = TREE_TYPE (op);
3926   unsigned final_prec
3927     = TYPE_PRECISION (for_type != 0 ? for_type : type);
3928   int uns
3929     = (for_type != 0 && for_type != type
3930        && final_prec > TYPE_PRECISION (type)
3931        && TREE_UNSIGNED (type));
3932   tree win = op;
3933 
3934   while (TREE_CODE (op) == NOP_EXPR)
3935     {
3936       int bitschange
3937 	= TYPE_PRECISION (TREE_TYPE (op))
3938 	  - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
3939 
3940       /* Truncations are many-one so cannot be removed.
3941 	 Unless we are later going to truncate down even farther.  */
3942       if (bitschange < 0
3943 	  && final_prec > TYPE_PRECISION (TREE_TYPE (op)))
3944 	break;
3945 
3946       /* See what's inside this conversion.  If we decide to strip it,
3947 	 we will set WIN.  */
3948       op = TREE_OPERAND (op, 0);
3949 
3950       /* If we have not stripped any zero-extensions (uns is 0),
3951 	 we can strip any kind of extension.
3952 	 If we have previously stripped a zero-extension,
3953 	 only zero-extensions can safely be stripped.
3954 	 Any extension can be stripped if the bits it would produce
3955 	 are all going to be discarded later by truncating to FOR_TYPE.  */
3956 
3957       if (bitschange > 0)
3958 	{
3959 	  if (! uns || final_prec <= TYPE_PRECISION (TREE_TYPE (op)))
3960 	    win = op;
3961 	  /* TREE_UNSIGNED says whether this is a zero-extension.
3962 	     Let's avoid computing it if it does not affect WIN
3963 	     and if UNS will not be needed again.  */
3964 	  if ((uns || TREE_CODE (op) == NOP_EXPR)
3965 	      && TREE_UNSIGNED (TREE_TYPE (op)))
3966 	    {
3967 	      uns = 1;
3968 	      win = op;
3969 	    }
3970 	}
3971     }
3972 
3973   if (TREE_CODE (op) == COMPONENT_REF
3974       /* Since type_for_size always gives an integer type.  */
3975       && TREE_CODE (type) != REAL_TYPE
3976       /* Don't crash if field not laid out yet.  */
3977       && DECL_SIZE (TREE_OPERAND (op, 1)) != 0
3978       && host_integerp (DECL_SIZE (TREE_OPERAND (op, 1)), 1))
3979     {
3980       unsigned int innerprec
3981 	= tree_low_cst (DECL_SIZE (TREE_OPERAND (op, 1)), 1);
3982       int unsignedp = TREE_UNSIGNED (TREE_OPERAND (op, 1));
3983       type = (*lang_hooks.types.type_for_size) (innerprec, unsignedp);
3984 
3985       /* We can get this structure field in the narrowest type it fits in.
3986 	 If FOR_TYPE is 0, do this only for a field that matches the
3987 	 narrower type exactly and is aligned for it
3988 	 The resulting extension to its nominal type (a fullword type)
3989 	 must fit the same conditions as for other extensions.  */
3990 
3991       if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
3992 	  && (for_type || ! DECL_BIT_FIELD (TREE_OPERAND (op, 1)))
3993 	  && (! uns || final_prec <= innerprec || unsignedp)
3994 	  && type != 0)
3995 	{
3996 	  win = build (COMPONENT_REF, type, TREE_OPERAND (op, 0),
3997 		       TREE_OPERAND (op, 1));
3998 	  TREE_SIDE_EFFECTS (win) = TREE_SIDE_EFFECTS (op);
3999 	  TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
4000 	}
4001     }
4002 
4003   return win;
4004 }
4005 
4006 /* Return OP or a simpler expression for a narrower value
4007    which can be sign-extended or zero-extended to give back OP.
4008    Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
4009    or 0 if the value should be sign-extended.  */
4010 
4011 tree
get_narrower(op,unsignedp_ptr)4012 get_narrower (op, unsignedp_ptr)
4013      tree op;
4014      int *unsignedp_ptr;
4015 {
4016   int uns = 0;
4017   int first = 1;
4018   tree win = op;
4019 
4020   while (TREE_CODE (op) == NOP_EXPR)
4021     {
4022       int bitschange
4023 	= (TYPE_PRECISION (TREE_TYPE (op))
4024 	   - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0))));
4025 
4026       /* Truncations are many-one so cannot be removed.  */
4027       if (bitschange < 0)
4028 	break;
4029 
4030       /* See what's inside this conversion.  If we decide to strip it,
4031 	 we will set WIN.  */
4032 
4033       if (bitschange > 0)
4034 	{
4035 	  op = TREE_OPERAND (op, 0);
4036 	  /* An extension: the outermost one can be stripped,
4037 	     but remember whether it is zero or sign extension.  */
4038 	  if (first)
4039 	    uns = TREE_UNSIGNED (TREE_TYPE (op));
4040 	  /* Otherwise, if a sign extension has been stripped,
4041 	     only sign extensions can now be stripped;
4042 	     if a zero extension has been stripped, only zero-extensions.  */
4043 	  else if (uns != TREE_UNSIGNED (TREE_TYPE (op)))
4044 	    break;
4045 	  first = 0;
4046 	}
4047       else /* bitschange == 0 */
4048 	{
4049 	  /* A change in nominal type can always be stripped, but we must
4050 	     preserve the unsignedness.  */
4051 	  if (first)
4052 	    uns = TREE_UNSIGNED (TREE_TYPE (op));
4053 	  first = 0;
4054 	  op = TREE_OPERAND (op, 0);
4055 	}
4056 
4057       win = op;
4058     }
4059 
4060   if (TREE_CODE (op) == COMPONENT_REF
4061       /* Since type_for_size always gives an integer type.  */
4062       && TREE_CODE (TREE_TYPE (op)) != REAL_TYPE
4063       /* Ensure field is laid out already.  */
4064       && DECL_SIZE (TREE_OPERAND (op, 1)) != 0)
4065     {
4066       unsigned HOST_WIDE_INT innerprec
4067 	= tree_low_cst (DECL_SIZE (TREE_OPERAND (op, 1)), 1);
4068       tree type = (*lang_hooks.types.type_for_size) (innerprec,
4069 						     TREE_UNSIGNED (op));
4070 
4071       /* We can get this structure field in a narrower type that fits it,
4072 	 but the resulting extension to its nominal type (a fullword type)
4073 	 must satisfy the same conditions as for other extensions.
4074 
4075 	 Do this only for fields that are aligned (not bit-fields),
4076 	 because when bit-field insns will be used there is no
4077 	 advantage in doing this.  */
4078 
4079       if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
4080 	  && ! DECL_BIT_FIELD (TREE_OPERAND (op, 1))
4081 	  && (first || uns == TREE_UNSIGNED (TREE_OPERAND (op, 1)))
4082 	  && type != 0)
4083 	{
4084 	  if (first)
4085 	    uns = TREE_UNSIGNED (TREE_OPERAND (op, 1));
4086 	  win = build (COMPONENT_REF, type, TREE_OPERAND (op, 0),
4087 		       TREE_OPERAND (op, 1));
4088 	  TREE_SIDE_EFFECTS (win) = TREE_SIDE_EFFECTS (op);
4089 	  TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
4090 	}
4091     }
4092   *unsignedp_ptr = uns;
4093   return win;
4094 }
4095 
4096 /* Nonzero if integer constant C has a value that is permissible
4097    for type TYPE (an INTEGER_TYPE).  */
4098 
4099 int
int_fits_type_p(c,type)4100 int_fits_type_p (c, type)
4101      tree c, type;
4102 {
4103   /* If the bounds of the type are integers, we can check ourselves.
4104      If not, but this type is a subtype, try checking against that.
4105      Otherwise, use force_fit_type, which checks against the precision.  */
4106   if (TYPE_MAX_VALUE (type) != NULL_TREE
4107       && TYPE_MIN_VALUE (type) != NULL_TREE
4108       && TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST
4109       && TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST)
4110     {
4111       if (TREE_UNSIGNED (type))
4112 	return (! INT_CST_LT_UNSIGNED (TYPE_MAX_VALUE (type), c)
4113 		&& ! INT_CST_LT_UNSIGNED (c, TYPE_MIN_VALUE (type))
4114 		/* Negative ints never fit unsigned types.  */
4115 		&& ! (TREE_INT_CST_HIGH (c) < 0
4116 		      && ! TREE_UNSIGNED (TREE_TYPE (c))));
4117       else
4118 	return (! INT_CST_LT (TYPE_MAX_VALUE (type), c)
4119 		&& ! INT_CST_LT (c, TYPE_MIN_VALUE (type))
4120 		/* Unsigned ints with top bit set never fit signed types.  */
4121 		&& ! (TREE_INT_CST_HIGH (c) < 0
4122 		      && TREE_UNSIGNED (TREE_TYPE (c))));
4123     }
4124   else if (TREE_CODE (type) == INTEGER_TYPE && TREE_TYPE (type) != 0)
4125     return int_fits_type_p (c, TREE_TYPE (type));
4126   else
4127     {
4128       c = copy_node (c);
4129       TREE_TYPE (c) = type;
4130       return !force_fit_type (c, 0);
4131     }
4132 }
4133 
4134 /* Returns true if T is, contains, or refers to a type with variable
4135    size.  This concept is more general than that of C99 'variably
4136    modified types': in C99, a struct type is never variably modified
4137    because a VLA may not appear as a structure member.  However, in
4138    GNU C code like:
4139 
4140      struct S { int i[f()]; };
4141 
4142    is valid, and other languages may define similar constructs.  */
4143 
4144 bool
variably_modified_type_p(type)4145 variably_modified_type_p (type)
4146      tree type;
4147 {
4148   if (type == error_mark_node)
4149     return false;
4150 
4151   /* If TYPE itself has variable size, it is variably modified.
4152 
4153      We do not yet have a representation of the C99 '[*]' syntax.
4154      When a representation is chosen, this function should be modified
4155      to test for that case as well.  */
4156   if (TYPE_SIZE (type)
4157       && TYPE_SIZE (type) != error_mark_node
4158       && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
4159     return true;
4160 
4161   /* If TYPE is a pointer or reference, it is variably modified if
4162      the type pointed to is variably modified.  */
4163   if ((TREE_CODE (type) == POINTER_TYPE
4164        || TREE_CODE (type) == REFERENCE_TYPE)
4165       && variably_modified_type_p (TREE_TYPE (type)))
4166     return true;
4167 
4168   /* If TYPE is an array, it is variably modified if the array
4169      elements are.  (Note that the VLA case has already been checked
4170      above.)  */
4171   if (TREE_CODE (type) == ARRAY_TYPE
4172       && variably_modified_type_p (TREE_TYPE (type)))
4173     return true;
4174 
4175   /* If TYPE is a function type, it is variably modified if any of the
4176      parameters or the return type are variably modified.  */
4177   if (TREE_CODE (type) == FUNCTION_TYPE
4178       || TREE_CODE (type) == METHOD_TYPE)
4179     {
4180       tree parm;
4181 
4182       if (variably_modified_type_p (TREE_TYPE (type)))
4183 	return true;
4184       for (parm = TYPE_ARG_TYPES (type);
4185 	   parm && parm != void_list_node;
4186 	   parm = TREE_CHAIN (parm))
4187 	if (variably_modified_type_p (TREE_VALUE (parm)))
4188 	  return true;
4189     }
4190 
4191   /* The current language may have other cases to check, but in general,
4192      all other types are not variably modified.  */
4193   return (*lang_hooks.tree_inlining.var_mod_type_p) (type);
4194 }
4195 
4196 /* Given a DECL or TYPE, return the scope in which it was declared, or
4197    NULL_TREE if there is no containing scope.  */
4198 
4199 tree
get_containing_scope(t)4200 get_containing_scope (t)
4201      tree t;
4202 {
4203   return (TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t));
4204 }
4205 
4206 /* Return the innermost context enclosing DECL that is
4207    a FUNCTION_DECL, or zero if none.  */
4208 
4209 tree
decl_function_context(decl)4210 decl_function_context (decl)
4211      tree decl;
4212 {
4213   tree context;
4214 
4215   if (TREE_CODE (decl) == ERROR_MARK)
4216     return 0;
4217 
4218   if (TREE_CODE (decl) == SAVE_EXPR)
4219     context = SAVE_EXPR_CONTEXT (decl);
4220 
4221   /* C++ virtual functions use DECL_CONTEXT for the class of the vtable
4222      where we look up the function at runtime.  Such functions always take
4223      a first argument of type 'pointer to real context'.
4224 
4225      C++ should really be fixed to use DECL_CONTEXT for the real context,
4226      and use something else for the "virtual context".  */
4227   else if (TREE_CODE (decl) == FUNCTION_DECL && DECL_VINDEX (decl))
4228     context
4229       = TYPE_MAIN_VARIANT
4230 	(TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4231   else
4232     context = DECL_CONTEXT (decl);
4233 
4234   while (context && TREE_CODE (context) != FUNCTION_DECL)
4235     {
4236       if (TREE_CODE (context) == BLOCK)
4237 	context = BLOCK_SUPERCONTEXT (context);
4238       else
4239 	context = get_containing_scope (context);
4240     }
4241 
4242   return context;
4243 }
4244 
4245 /* Return the innermost context enclosing DECL that is
4246    a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
4247    TYPE_DECLs and FUNCTION_DECLs are transparent to this function.  */
4248 
4249 tree
decl_type_context(decl)4250 decl_type_context (decl)
4251      tree decl;
4252 {
4253   tree context = DECL_CONTEXT (decl);
4254 
4255   while (context)
4256     {
4257       if (TREE_CODE (context) == NAMESPACE_DECL)
4258 	return NULL_TREE;
4259 
4260       if (TREE_CODE (context) == RECORD_TYPE
4261 	  || TREE_CODE (context) == UNION_TYPE
4262 	  || TREE_CODE (context) == QUAL_UNION_TYPE)
4263 	return context;
4264 
4265       if (TREE_CODE (context) == TYPE_DECL
4266 	  || TREE_CODE (context) == FUNCTION_DECL)
4267 	context = DECL_CONTEXT (context);
4268 
4269       else if (TREE_CODE (context) == BLOCK)
4270 	context = BLOCK_SUPERCONTEXT (context);
4271 
4272       else
4273 	/* Unhandled CONTEXT!?  */
4274 	abort ();
4275     }
4276   return NULL_TREE;
4277 }
4278 
4279 /* CALL is a CALL_EXPR.  Return the declaration for the function
4280    called, or NULL_TREE if the called function cannot be
4281    determined.  */
4282 
4283 tree
get_callee_fndecl(call)4284 get_callee_fndecl (call)
4285      tree call;
4286 {
4287   tree addr;
4288 
4289   /* It's invalid to call this function with anything but a
4290      CALL_EXPR.  */
4291   if (TREE_CODE (call) != CALL_EXPR)
4292     abort ();
4293 
4294   /* The first operand to the CALL is the address of the function
4295      called.  */
4296   addr = TREE_OPERAND (call, 0);
4297 
4298   STRIP_NOPS (addr);
4299 
4300   /* If this is a readonly function pointer, extract its initial value.  */
4301   if (DECL_P (addr) && TREE_CODE (addr) != FUNCTION_DECL
4302       && TREE_READONLY (addr) && ! TREE_THIS_VOLATILE (addr)
4303       && DECL_INITIAL (addr))
4304     addr = DECL_INITIAL (addr);
4305 
4306   /* If the address is just `&f' for some function `f', then we know
4307      that `f' is being called.  */
4308   if (TREE_CODE (addr) == ADDR_EXPR
4309       && TREE_CODE (TREE_OPERAND (addr, 0)) == FUNCTION_DECL)
4310     return TREE_OPERAND (addr, 0);
4311 
4312   /* We couldn't figure out what was being called.  */
4313   return NULL_TREE;
4314 }
4315 
4316 /* Print debugging information about the obstack O, named STR.  */
4317 
4318 void
print_obstack_statistics(str,o)4319 print_obstack_statistics (str, o)
4320      const char *str;
4321      struct obstack *o;
4322 {
4323   struct _obstack_chunk *chunk = o->chunk;
4324   int n_chunks = 1;
4325   int n_alloc = 0;
4326 
4327   n_alloc += o->next_free - chunk->contents;
4328   chunk = chunk->prev;
4329   while (chunk)
4330     {
4331       n_chunks += 1;
4332       n_alloc += chunk->limit - &chunk->contents[0];
4333       chunk = chunk->prev;
4334     }
4335   fprintf (stderr, "obstack %s: %u bytes, %d chunks\n",
4336 	   str, n_alloc, n_chunks);
4337 }
4338 
4339 /* Print debugging information about tree nodes generated during the compile,
4340    and any language-specific information.  */
4341 
4342 void
dump_tree_statistics()4343 dump_tree_statistics ()
4344 {
4345 #ifdef GATHER_STATISTICS
4346   int i;
4347   int total_nodes, total_bytes;
4348 #endif
4349 
4350   fprintf (stderr, "\n??? tree nodes created\n\n");
4351 #ifdef GATHER_STATISTICS
4352   fprintf (stderr, "Kind                  Nodes     Bytes\n");
4353   fprintf (stderr, "-------------------------------------\n");
4354   total_nodes = total_bytes = 0;
4355   for (i = 0; i < (int) all_kinds; i++)
4356     {
4357       fprintf (stderr, "%-20s %6d %9d\n", tree_node_kind_names[i],
4358 	       tree_node_counts[i], tree_node_sizes[i]);
4359       total_nodes += tree_node_counts[i];
4360       total_bytes += tree_node_sizes[i];
4361     }
4362   fprintf (stderr, "-------------------------------------\n");
4363   fprintf (stderr, "%-20s %6d %9d\n", "Total", total_nodes, total_bytes);
4364   fprintf (stderr, "-------------------------------------\n");
4365 #else
4366   fprintf (stderr, "(No per-node statistics)\n");
4367 #endif
4368   print_type_hash_statistics ();
4369   (*lang_hooks.print_statistics) ();
4370 }
4371 
4372 #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s"
4373 
4374 const char *flag_random_seed;
4375 
4376 /* Set up a default flag_random_seed value, if there wasn't one already.  */
4377 
4378 void
default_flag_random_seed()4379 default_flag_random_seed ()
4380 {
4381   unsigned HOST_WIDE_INT value;
4382   char *new_random_seed;
4383 
4384   if (flag_random_seed != NULL)
4385     return;
4386 
4387   /* Get some more or less random data.  */
4388 #ifdef HAVE_GETTIMEOFDAY
4389  {
4390    struct timeval tv;
4391 
4392    gettimeofday (&tv, NULL);
4393    value = (((unsigned HOST_WIDE_INT) tv.tv_usec << 16)
4394 	    ^ tv.tv_sec ^ getpid ());
4395  }
4396 #else
4397   value = getpid ();
4398 #endif
4399 
4400   /* This slightly overestimates the space required.  */
4401   new_random_seed = xmalloc (HOST_BITS_PER_WIDE_INT / 3 + 2);
4402   sprintf (new_random_seed, HOST_WIDE_INT_PRINT_UNSIGNED, value);
4403   flag_random_seed = new_random_seed;
4404 }
4405 
4406 /* Appends 6 random characters to TEMPLATE to (hopefully) avoid name
4407    clashes in cases where we can't reliably choose a unique name.
4408 
4409    Derived from mkstemp.c in libiberty.  */
4410 
4411 static void
append_random_chars(template)4412 append_random_chars (template)
4413      char *template;
4414 {
4415   static const char letters[]
4416     = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
4417   unsigned HOST_WIDE_INT v;
4418   size_t i;
4419 
4420   default_flag_random_seed ();
4421 
4422   /* This isn't a very good hash, but it does guarantee no collisions
4423      when the random string is generated by the code above and the time
4424      delta is small.  */
4425   v = 0;
4426   for (i = 0; i < strlen (flag_random_seed); i++)
4427     v = (v << 4) ^ (v >> (HOST_BITS_PER_WIDE_INT - 4)) ^ flag_random_seed[i];
4428 
4429   template += strlen (template);
4430 
4431   /* Fill in the random bits.  */
4432   template[0] = letters[v % 62];
4433   v /= 62;
4434   template[1] = letters[v % 62];
4435   v /= 62;
4436   template[2] = letters[v % 62];
4437   v /= 62;
4438   template[3] = letters[v % 62];
4439   v /= 62;
4440   template[4] = letters[v % 62];
4441   v /= 62;
4442   template[5] = letters[v % 62];
4443 
4444   template[6] = '\0';
4445 }
4446 
4447 /* P is a string that will be used in a symbol.  Mask out any characters
4448    that are not valid in that context.  */
4449 
4450 void
clean_symbol_name(p)4451 clean_symbol_name (p)
4452      char *p;
4453 {
4454   for (; *p; p++)
4455     if (! (ISALNUM (*p)
4456 #ifndef NO_DOLLAR_IN_LABEL	/* this for `$'; unlikely, but... -- kr */
4457 	    || *p == '$'
4458 #endif
4459 #ifndef NO_DOT_IN_LABEL		/* this for `.'; unlikely, but...  */
4460 	    || *p == '.'
4461 #endif
4462 	   ))
4463       *p = '_';
4464 }
4465 
4466 /* Generate a name for a function unique to this translation unit.
4467    TYPE is some string to identify the purpose of this function to the
4468    linker or collect2.  */
4469 
4470 tree
get_file_function_name_long(type)4471 get_file_function_name_long (type)
4472      const char *type;
4473 {
4474   char *buf;
4475   const char *p;
4476   char *q;
4477 
4478   if (first_global_object_name)
4479     p = first_global_object_name;
4480   else
4481     {
4482       /* We don't have anything that we know to be unique to this translation
4483 	 unit, so use what we do have and throw in some randomness.  */
4484 
4485       const char *name = weak_global_object_name;
4486       const char *file = main_input_filename;
4487 
4488       if (! name)
4489 	name = "";
4490       if (! file)
4491 	file = input_filename;
4492 
4493       q = (char *) alloca (7 + strlen (name) + strlen (file));
4494 
4495       sprintf (q, "%s%s", name, file);
4496       append_random_chars (q);
4497       p = q;
4498     }
4499 
4500   buf = (char *) alloca (sizeof (FILE_FUNCTION_FORMAT) + strlen (p)
4501 			 + strlen (type));
4502 
4503   /* Set up the name of the file-level functions we may need.
4504      Use a global object (which is already required to be unique over
4505      the program) rather than the file name (which imposes extra
4506      constraints).  */
4507   sprintf (buf, FILE_FUNCTION_FORMAT, type, p);
4508 
4509   /* Don't need to pull weird characters out of global names.  */
4510   if (p != first_global_object_name)
4511     clean_symbol_name (buf + 11);
4512 
4513   return get_identifier (buf);
4514 }
4515 
4516 /* If KIND=='I', return a suitable global initializer (constructor) name.
4517    If KIND=='D', return a suitable global clean-up (destructor) name.  */
4518 
4519 tree
get_file_function_name(kind)4520 get_file_function_name (kind)
4521      int kind;
4522 {
4523   char p[2];
4524 
4525   p[0] = kind;
4526   p[1] = 0;
4527 
4528   return get_file_function_name_long (p);
4529 }
4530 
4531 /* Expand (the constant part of) a SET_TYPE CONSTRUCTOR node.
4532    The result is placed in BUFFER (which has length BIT_SIZE),
4533    with one bit in each char ('\000' or '\001').
4534 
4535    If the constructor is constant, NULL_TREE is returned.
4536    Otherwise, a TREE_LIST of the non-constant elements is emitted.  */
4537 
4538 tree
get_set_constructor_bits(init,buffer,bit_size)4539 get_set_constructor_bits (init, buffer, bit_size)
4540      tree init;
4541      char *buffer;
4542      int bit_size;
4543 {
4544   int i;
4545   tree vals;
4546   HOST_WIDE_INT domain_min
4547     = tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (init))), 0);
4548   tree non_const_bits = NULL_TREE;
4549 
4550   for (i = 0; i < bit_size; i++)
4551     buffer[i] = 0;
4552 
4553   for (vals = TREE_OPERAND (init, 1);
4554        vals != NULL_TREE; vals = TREE_CHAIN (vals))
4555     {
4556       if (!host_integerp (TREE_VALUE (vals), 0)
4557 	  || (TREE_PURPOSE (vals) != NULL_TREE
4558 	      && !host_integerp (TREE_PURPOSE (vals), 0)))
4559 	non_const_bits
4560 	  = tree_cons (TREE_PURPOSE (vals), TREE_VALUE (vals), non_const_bits);
4561       else if (TREE_PURPOSE (vals) != NULL_TREE)
4562 	{
4563 	  /* Set a range of bits to ones.  */
4564 	  HOST_WIDE_INT lo_index
4565 	    = tree_low_cst (TREE_PURPOSE (vals), 0) - domain_min;
4566 	  HOST_WIDE_INT hi_index
4567 	    = tree_low_cst (TREE_VALUE (vals), 0) - domain_min;
4568 
4569 	  if (lo_index < 0 || lo_index >= bit_size
4570 	      || hi_index < 0 || hi_index >= bit_size)
4571 	    abort ();
4572 	  for (; lo_index <= hi_index; lo_index++)
4573 	    buffer[lo_index] = 1;
4574 	}
4575       else
4576 	{
4577 	  /* Set a single bit to one.  */
4578 	  HOST_WIDE_INT index
4579 	    = tree_low_cst (TREE_VALUE (vals), 0) - domain_min;
4580 	  if (index < 0 || index >= bit_size)
4581 	    {
4582 	      error ("invalid initializer for bit string");
4583 	      return NULL_TREE;
4584 	    }
4585 	  buffer[index] = 1;
4586 	}
4587     }
4588   return non_const_bits;
4589 }
4590 
4591 /* Expand (the constant part of) a SET_TYPE CONSTRUCTOR node.
4592    The result is placed in BUFFER (which is an array of bytes).
4593    If the constructor is constant, NULL_TREE is returned.
4594    Otherwise, a TREE_LIST of the non-constant elements is emitted.  */
4595 
4596 tree
get_set_constructor_bytes(init,buffer,wd_size)4597 get_set_constructor_bytes (init, buffer, wd_size)
4598      tree init;
4599      unsigned char *buffer;
4600      int wd_size;
4601 {
4602   int i;
4603   int set_word_size = BITS_PER_UNIT;
4604   int bit_size = wd_size * set_word_size;
4605   int bit_pos = 0;
4606   unsigned char *bytep = buffer;
4607   char *bit_buffer = (char *) alloca (bit_size);
4608   tree non_const_bits = get_set_constructor_bits (init, bit_buffer, bit_size);
4609 
4610   for (i = 0; i < wd_size; i++)
4611     buffer[i] = 0;
4612 
4613   for (i = 0; i < bit_size; i++)
4614     {
4615       if (bit_buffer[i])
4616 	{
4617 	  if (BYTES_BIG_ENDIAN)
4618 	    *bytep |= (1 << (set_word_size - 1 - bit_pos));
4619 	  else
4620 	    *bytep |= 1 << bit_pos;
4621 	}
4622       bit_pos++;
4623       if (bit_pos >= set_word_size)
4624 	bit_pos = 0, bytep++;
4625     }
4626   return non_const_bits;
4627 }
4628 
4629 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
4630 /* Complain that the tree code of NODE does not match the expected CODE.
4631    FILE, LINE, and FUNCTION are of the caller.  */
4632 
4633 void
tree_check_failed(node,code,file,line,function)4634 tree_check_failed (node, code, file, line, function)
4635      const tree node;
4636      enum tree_code code;
4637      const char *file;
4638      int line;
4639      const char *function;
4640 {
4641   internal_error ("tree check: expected %s, have %s in %s, at %s:%d",
4642 		  tree_code_name[code], tree_code_name[TREE_CODE (node)],
4643 		  function, trim_filename (file), line);
4644 }
4645 
4646 /* Similar to above, except that we check for a class of tree
4647    code, given in CL.  */
4648 
4649 void
tree_class_check_failed(node,cl,file,line,function)4650 tree_class_check_failed (node, cl, file, line, function)
4651      const tree node;
4652      int cl;
4653      const char *file;
4654      int line;
4655      const char *function;
4656 {
4657   internal_error
4658     ("tree check: expected class '%c', have '%c' (%s) in %s, at %s:%d",
4659      cl, TREE_CODE_CLASS (TREE_CODE (node)),
4660      tree_code_name[TREE_CODE (node)], function, trim_filename (file), line);
4661 }
4662 
4663 /* Similar to above, except that the check is for the bounds of a TREE_VEC's
4664    (dynamically sized) vector.  */
4665 
4666 void
tree_vec_elt_check_failed(idx,len,file,line,function)4667 tree_vec_elt_check_failed (idx, len, file, line, function)
4668      int idx;
4669      int len;
4670      const char *file;
4671      int line;
4672      const char *function;
4673 {
4674   internal_error
4675     ("tree check: accessed elt %d of tree_vec with %d elts in %s, at %s:%d",
4676      idx + 1, len, function, trim_filename (file), line);
4677 }
4678 
4679 #endif /* ENABLE_TREE_CHECKING */
4680 
4681 /* For a new vector type node T, build the information necessary for
4682    debugging output.  */
4683 
4684 static void
finish_vector_type(t)4685 finish_vector_type (t)
4686      tree t;
4687 {
4688   layout_type (t);
4689 
4690   {
4691     tree index = build_int_2 (TYPE_VECTOR_SUBPARTS (t) - 1, 0);
4692     tree array = build_array_type (TREE_TYPE (t),
4693 				   build_index_type (index));
4694     tree rt = make_node (RECORD_TYPE);
4695 
4696     TYPE_FIELDS (rt) = build_decl (FIELD_DECL, get_identifier ("f"), array);
4697     DECL_CONTEXT (TYPE_FIELDS (rt)) = rt;
4698     layout_type (rt);
4699     TYPE_DEBUG_REPRESENTATION_TYPE (t) = rt;
4700     /* In dwarfout.c, type lookup uses TYPE_UID numbers.  We want to output
4701        the representation type, and we want to find that die when looking up
4702        the vector type.  This is most easily achieved by making the TYPE_UID
4703        numbers equal.  */
4704     TYPE_UID (rt) = TYPE_UID (t);
4705   }
4706 }
4707 
4708 /* Create nodes for all integer types (and error_mark_node) using the sizes
4709    of C datatypes.  The caller should call set_sizetype soon after calling
4710    this function to select one of the types as sizetype.  */
4711 
4712 void
build_common_tree_nodes(signed_char)4713 build_common_tree_nodes (signed_char)
4714      int signed_char;
4715 {
4716   error_mark_node = make_node (ERROR_MARK);
4717   TREE_TYPE (error_mark_node) = error_mark_node;
4718 
4719   initialize_sizetypes ();
4720 
4721   /* Define both `signed char' and `unsigned char'.  */
4722   signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE);
4723   unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
4724 
4725   /* Define `char', which is like either `signed char' or `unsigned char'
4726      but not the same as either.  */
4727   char_type_node
4728     = (signed_char
4729        ? make_signed_type (CHAR_TYPE_SIZE)
4730        : make_unsigned_type (CHAR_TYPE_SIZE));
4731 
4732   short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE);
4733   short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE);
4734   integer_type_node = make_signed_type (INT_TYPE_SIZE);
4735   unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);
4736   long_integer_type_node = make_signed_type (LONG_TYPE_SIZE);
4737   long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE);
4738   long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE);
4739   long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
4740 
4741   intQI_type_node = make_signed_type (GET_MODE_BITSIZE (QImode));
4742   intHI_type_node = make_signed_type (GET_MODE_BITSIZE (HImode));
4743   intSI_type_node = make_signed_type (GET_MODE_BITSIZE (SImode));
4744   intDI_type_node = make_signed_type (GET_MODE_BITSIZE (DImode));
4745   intTI_type_node = make_signed_type (GET_MODE_BITSIZE (TImode));
4746 
4747   unsigned_intQI_type_node = make_unsigned_type (GET_MODE_BITSIZE (QImode));
4748   unsigned_intHI_type_node = make_unsigned_type (GET_MODE_BITSIZE (HImode));
4749   unsigned_intSI_type_node = make_unsigned_type (GET_MODE_BITSIZE (SImode));
4750   unsigned_intDI_type_node = make_unsigned_type (GET_MODE_BITSIZE (DImode));
4751   unsigned_intTI_type_node = make_unsigned_type (GET_MODE_BITSIZE (TImode));
4752 }
4753 
4754 /* Call this function after calling build_common_tree_nodes and set_sizetype.
4755    It will create several other common tree nodes.  */
4756 
4757 void
build_common_tree_nodes_2(short_double)4758 build_common_tree_nodes_2 (short_double)
4759      int short_double;
4760 {
4761   /* Define these next since types below may used them.  */
4762   integer_zero_node = build_int_2 (0, 0);
4763   integer_one_node = build_int_2 (1, 0);
4764   integer_minus_one_node = build_int_2 (-1, -1);
4765 
4766   size_zero_node = size_int (0);
4767   size_one_node = size_int (1);
4768   bitsize_zero_node = bitsize_int (0);
4769   bitsize_one_node = bitsize_int (1);
4770   bitsize_unit_node = bitsize_int (BITS_PER_UNIT);
4771 
4772   void_type_node = make_node (VOID_TYPE);
4773   layout_type (void_type_node);
4774 
4775   /* We are not going to have real types in C with less than byte alignment,
4776      so we might as well not have any types that claim to have it.  */
4777   TYPE_ALIGN (void_type_node) = BITS_PER_UNIT;
4778   TYPE_USER_ALIGN (void_type_node) = 0;
4779 
4780   null_pointer_node = build_int_2 (0, 0);
4781   TREE_TYPE (null_pointer_node) = build_pointer_type (void_type_node);
4782   layout_type (TREE_TYPE (null_pointer_node));
4783 
4784   ptr_type_node = build_pointer_type (void_type_node);
4785   const_ptr_type_node
4786     = build_pointer_type (build_type_variant (void_type_node, 1, 0));
4787 
4788   float_type_node = make_node (REAL_TYPE);
4789   TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE;
4790   layout_type (float_type_node);
4791 
4792   double_type_node = make_node (REAL_TYPE);
4793   if (short_double)
4794     TYPE_PRECISION (double_type_node) = FLOAT_TYPE_SIZE;
4795   else
4796     TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE;
4797   layout_type (double_type_node);
4798 
4799   long_double_type_node = make_node (REAL_TYPE);
4800   TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE;
4801   layout_type (long_double_type_node);
4802 
4803   complex_integer_type_node = make_node (COMPLEX_TYPE);
4804   TREE_TYPE (complex_integer_type_node) = integer_type_node;
4805   layout_type (complex_integer_type_node);
4806 
4807   complex_float_type_node = make_node (COMPLEX_TYPE);
4808   TREE_TYPE (complex_float_type_node) = float_type_node;
4809   layout_type (complex_float_type_node);
4810 
4811   complex_double_type_node = make_node (COMPLEX_TYPE);
4812   TREE_TYPE (complex_double_type_node) = double_type_node;
4813   layout_type (complex_double_type_node);
4814 
4815   complex_long_double_type_node = make_node (COMPLEX_TYPE);
4816   TREE_TYPE (complex_long_double_type_node) = long_double_type_node;
4817   layout_type (complex_long_double_type_node);
4818 
4819   {
4820     tree t;
4821     BUILD_VA_LIST_TYPE (t);
4822 
4823     /* Many back-ends define record types without seting TYPE_NAME.
4824        If we copied the record type here, we'd keep the original
4825        record type without a name.  This breaks name mangling.  So,
4826        don't copy record types and let c_common_nodes_and_builtins()
4827        declare the type to be __builtin_va_list.  */
4828     if (TREE_CODE (t) != RECORD_TYPE)
4829       t = build_type_copy (t);
4830 
4831     va_list_type_node = t;
4832   }
4833 
4834   unsigned_V4SI_type_node
4835     = make_vector (V4SImode, unsigned_intSI_type_node, 1);
4836   unsigned_V2HI_type_node
4837     = make_vector (V2HImode, unsigned_intHI_type_node, 1);
4838   unsigned_V2SI_type_node
4839     = make_vector (V2SImode, unsigned_intSI_type_node, 1);
4840   unsigned_V2DI_type_node
4841     = make_vector (V2DImode, unsigned_intDI_type_node, 1);
4842   unsigned_V4HI_type_node
4843     = make_vector (V4HImode, unsigned_intHI_type_node, 1);
4844   unsigned_V8QI_type_node
4845     = make_vector (V8QImode, unsigned_intQI_type_node, 1);
4846   unsigned_V8HI_type_node
4847     = make_vector (V8HImode, unsigned_intHI_type_node, 1);
4848   unsigned_V16QI_type_node
4849     = make_vector (V16QImode, unsigned_intQI_type_node, 1);
4850   unsigned_V1DI_type_node
4851     = make_vector (V1DImode, unsigned_intDI_type_node, 1);
4852 
4853   V16SF_type_node = make_vector (V16SFmode, float_type_node, 0);
4854   V4SF_type_node = make_vector (V4SFmode, float_type_node, 0);
4855   V4SI_type_node = make_vector (V4SImode, intSI_type_node, 0);
4856   V2HI_type_node = make_vector (V2HImode, intHI_type_node, 0);
4857   V2SI_type_node = make_vector (V2SImode, intSI_type_node, 0);
4858   V2DI_type_node = make_vector (V2DImode, intDI_type_node, 0);
4859   V4HI_type_node = make_vector (V4HImode, intHI_type_node, 0);
4860   V8QI_type_node = make_vector (V8QImode, intQI_type_node, 0);
4861   V8HI_type_node = make_vector (V8HImode, intHI_type_node, 0);
4862   V2SF_type_node = make_vector (V2SFmode, float_type_node, 0);
4863   V2DF_type_node = make_vector (V2DFmode, double_type_node, 0);
4864   V16QI_type_node = make_vector (V16QImode, intQI_type_node, 0);
4865   V1DI_type_node = make_vector (V1DImode, intDI_type_node, 0);
4866 }
4867 
4868 /* Returns a vector tree node given a vector mode, the inner type, and
4869    the signness.  */
4870 
4871 static tree
make_vector(mode,innertype,unsignedp)4872 make_vector (mode, innertype, unsignedp)
4873      enum machine_mode mode;
4874      tree innertype;
4875      int unsignedp;
4876 {
4877   tree t;
4878 
4879   t = make_node (VECTOR_TYPE);
4880   TREE_TYPE (t) = innertype;
4881   TYPE_MODE (t) = mode;
4882   TREE_UNSIGNED (TREE_TYPE (t)) = unsignedp;
4883   finish_vector_type (t);
4884 
4885   return t;
4886 }
4887 
4888 /* Given an initializer INIT, return TRUE if INIT is zero or some
4889    aggregate of zeros.  Otherwise return FALSE.  */
4890 
4891 bool
initializer_zerop(init)4892 initializer_zerop (init)
4893      tree init;
4894 {
4895   STRIP_NOPS (init);
4896 
4897   switch (TREE_CODE (init))
4898     {
4899     case INTEGER_CST:
4900       return integer_zerop (init);
4901     case REAL_CST:
4902       return real_zerop (init)
4903 	&& ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (init));
4904     case COMPLEX_CST:
4905       return integer_zerop (init)
4906 	|| (real_zerop (init)
4907 	    && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_REALPART (init)))
4908 	    && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_IMAGPART (init))));
4909     case CONSTRUCTOR:
4910       {
4911 	if (AGGREGATE_TYPE_P (TREE_TYPE (init)))
4912 	  {
4913 	    tree aggr_init = TREE_OPERAND (init, 1);
4914 
4915 	    while (aggr_init)
4916 	      {
4917 		if (! initializer_zerop (TREE_VALUE (aggr_init)))
4918 		  return false;
4919 		aggr_init = TREE_CHAIN (aggr_init);
4920 	      }
4921 	    return true;
4922 	  }
4923 	return false;
4924       }
4925     default:
4926       return false;
4927     }
4928 }
4929 
4930 #include "gt-tree.h"
4931