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