• Main Page
  • Modules
  • Data Types
  • Files

osprey-gcc-4.2.0/gcc/tree.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2007. PathScale, LLC.  All rights reserved.
00003  */
00004 /*
00005  * Copyright (C) 2007. QLogic Corporation. All Rights Reserved.
00006  */
00007 /* Language-independent node constructors for parse phase of GNU compiler.
00008    Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
00009    1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
00010    Free Software Foundation, Inc.
00011 
00012 This file is part of GCC.
00013 
00014 GCC is free software; you can redistribute it and/or modify it under
00015 the terms of the GNU General Public License as published by the Free
00016 Software Foundation; either version 2, or (at your option) any later
00017 version.
00018 
00019 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
00020 WARRANTY; without even the implied warranty of MERCHANTABILITY or
00021 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00022 for more details.
00023 
00024 You should have received a copy of the GNU General Public License
00025 along with GCC; see the file COPYING.  If not, write to the Free
00026 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
00027 02110-1301, USA.  */
00028 
00029 /* This file contains the low level primitives for operating on tree nodes,
00030    including allocation, list operations, interning of identifiers,
00031    construction of data type nodes and statement nodes,
00032    and construction of type conversion nodes.  It also contains
00033    tables index by tree code that describe how to take apart
00034    nodes of that code.
00035 
00036    It is intended to be language-independent, but occasionally
00037    calls language-dependent routines defined (for C) in typecheck.c.  */
00038 
00039 #include "config.h"
00040 #include "system.h"
00041 #include "coretypes.h"
00042 #include "tm.h"
00043 #include "flags.h"
00044 #include "tree.h"
00045 #include "real.h"
00046 #include "tm_p.h"
00047 #include "function.h"
00048 #include "obstack.h"
00049 #include "toplev.h"
00050 #include "ggc.h"
00051 #include "hashtab.h"
00052 #include "output.h"
00053 #include "target.h"
00054 #include "langhooks.h"
00055 #include "tree-iterator.h"
00056 #include "basic-block.h"
00057 #include "tree-flow.h"
00058 #include "params.h"
00059 #include "pointer-set.h"
00060 
00061 #ifdef KEY
00062 #include "dwarf2.h"
00063 
00064 extern tree cplus_expand_constant (tree);
00065 extern void mangle_decl (const tree decl);
00066 #endif
00067 
00068 /* Each tree code class has an associated string representation.
00069    These must correspond to the tree_code_class entries.  */
00070 
00071 const char *const tree_code_class_strings[] =
00072 {
00073   "exceptional",
00074   "constant",
00075   "type",
00076   "declaration",
00077   "reference",
00078   "comparison",
00079   "unary",
00080   "binary",
00081   "statement",
00082   "expression",
00083 };
00084 
00085 /* obstack.[ch] explicitly declined to prototype this.  */
00086 extern int _obstack_allocated_p (struct obstack *h, void *obj);
00087 
00088 #ifdef GATHER_STATISTICS
00089 /* Statistics-gathering stuff.  */
00090 
00091 int tree_node_counts[(int) all_kinds];
00092 int tree_node_sizes[(int) all_kinds];
00093 
00094 /* Keep in sync with tree.h:enum tree_node_kind.  */
00095 static const char * const tree_node_kind_names[] = {
00096   "decls",
00097   "types",
00098   "blocks",
00099   "stmts",
00100   "refs",
00101   "exprs",
00102   "constants",
00103   "identifiers",
00104   "perm_tree_lists",
00105   "temp_tree_lists",
00106   "vecs",
00107   "binfos",
00108   "phi_nodes",
00109   "ssa names",
00110   "constructors",
00111   "random kinds",
00112   "lang_decl kinds",
00113   "lang_type kinds",
00114   "omp clauses"
00115 };
00116 #endif /* GATHER_STATISTICS */
00117 
00118 /* Unique id for next decl created.  */
00119 static GTY(()) int next_decl_uid;
00120 /* Unique id for next type created.  */
00121 static GTY(()) int next_type_uid = 1;
00122 
00123 /* Since we cannot rehash a type after it is in the table, we have to
00124    keep the hash code.  */
00125 
00126 struct type_hash GTY(())
00127 {
00128   unsigned long hash;
00129   tree type;
00130 };
00131 
00132 /* Initial size of the hash table (rounded to next prime).  */
00133 #define TYPE_HASH_INITIAL_SIZE 1000
00134 
00135 /* Now here is the hash table.  When recording a type, it is added to
00136    the slot whose index is the hash code.  Note that the hash table is
00137    used for several kinds of types (function types, array types and
00138    array index range types, for now).  While all these live in the
00139    same table, they are completely independent, and the hash code is
00140    computed differently for each of these.  */
00141 
00142 static GTY ((if_marked ("type_hash_marked_p"), param_is (struct type_hash)))
00143      htab_t type_hash_table;
00144 
00145 /* Hash table and temporary node for larger integer const values.  */
00146 static GTY (()) tree int_cst_node;
00147 static GTY ((if_marked ("ggc_marked_p"), param_is (union tree_node)))
00148      htab_t int_cst_hash_table;
00149 
00150 /* General tree->tree mapping  structure for use in hash tables.  */
00151 
00152 
00153 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map))) 
00154      htab_t debug_expr_for_decl;
00155 
00156 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map))) 
00157      htab_t value_expr_for_decl;
00158 
00159 static GTY ((if_marked ("tree_int_map_marked_p"), param_is (struct tree_int_map)))
00160   htab_t init_priority_for_decl;
00161 
00162 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map)))
00163   htab_t restrict_base_for_decl;
00164 
00165 struct tree_int_map GTY(())
00166 {
00167   tree from;
00168   unsigned short to;
00169 };
00170 static unsigned int tree_int_map_hash (const void *);
00171 static int tree_int_map_eq (const void *, const void *);
00172 static int tree_int_map_marked_p (const void *);
00173 static void set_type_quals (tree, int);
00174 static int type_hash_eq (const void *, const void *);
00175 static hashval_t type_hash_hash (const void *);
00176 static hashval_t int_cst_hash_hash (const void *);
00177 static int int_cst_hash_eq (const void *, const void *);
00178 static void print_type_hash_statistics (void);
00179 static void print_debug_expr_statistics (void);
00180 static void print_value_expr_statistics (void);
00181 static int type_hash_marked_p (const void *);
00182 static unsigned int type_hash_list (tree, hashval_t);
00183 static unsigned int attribute_hash_list (tree, hashval_t);
00184 
00185 tree global_trees[TI_MAX];
00186 tree integer_types[itk_none];
00187 
00188 unsigned char tree_contains_struct[256][64];
00189 
00190 /* Number of operands for each OpenMP clause.  */
00191 unsigned const char omp_clause_num_ops[] =
00192 {
00193   0, /* OMP_CLAUSE_ERROR  */
00194   1, /* OMP_CLAUSE_PRIVATE  */
00195   1, /* OMP_CLAUSE_SHARED  */
00196   1, /* OMP_CLAUSE_FIRSTPRIVATE  */
00197   1, /* OMP_CLAUSE_LASTPRIVATE  */
00198   4, /* OMP_CLAUSE_REDUCTION  */
00199   1, /* OMP_CLAUSE_COPYIN  */
00200   1, /* OMP_CLAUSE_COPYPRIVATE  */
00201   1, /* OMP_CLAUSE_IF  */
00202   1, /* OMP_CLAUSE_NUM_THREADS  */
00203   1, /* OMP_CLAUSE_SCHEDULE  */
00204   0, /* OMP_CLAUSE_NOWAIT  */
00205   0, /* OMP_CLAUSE_ORDERED  */
00206   0  /* OMP_CLAUSE_DEFAULT  */
00207 };
00208 
00209 const char * const omp_clause_code_name[] =
00210 {
00211   "error_clause",
00212   "private",
00213   "shared",
00214   "firstprivate",
00215   "lastprivate",
00216   "reduction",
00217   "copyin",
00218   "copyprivate",
00219   "if",
00220   "num_threads",
00221   "schedule",
00222   "nowait",
00223   "ordered",
00224   "default"
00225 };
00226 
00227 /* Init tree.c.  */
00228 
00229 void
00230 init_ttree (void)
00231 {
00232   /* Initialize the hash table of types.  */
00233   type_hash_table = htab_create_ggc (TYPE_HASH_INITIAL_SIZE, type_hash_hash,
00234              type_hash_eq, 0);
00235 
00236   debug_expr_for_decl = htab_create_ggc (512, tree_map_hash,
00237            tree_map_eq, 0);
00238 
00239   value_expr_for_decl = htab_create_ggc (512, tree_map_hash,
00240            tree_map_eq, 0);
00241   init_priority_for_decl = htab_create_ggc (512, tree_int_map_hash,
00242               tree_int_map_eq, 0);
00243   restrict_base_for_decl = htab_create_ggc (256, tree_map_hash,
00244               tree_map_eq, 0);
00245 
00246   int_cst_hash_table = htab_create_ggc (1024, int_cst_hash_hash,
00247           int_cst_hash_eq, NULL);
00248   
00249   int_cst_node = make_node (INTEGER_CST);
00250 
00251   tree_contains_struct[FUNCTION_DECL][TS_DECL_NON_COMMON] = 1;
00252   tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_NON_COMMON] = 1;
00253   tree_contains_struct[TYPE_DECL][TS_DECL_NON_COMMON] = 1;
00254   
00255 
00256   tree_contains_struct[CONST_DECL][TS_DECL_COMMON] = 1;
00257   tree_contains_struct[VAR_DECL][TS_DECL_COMMON] = 1;
00258   tree_contains_struct[PARM_DECL][TS_DECL_COMMON] = 1;
00259   tree_contains_struct[RESULT_DECL][TS_DECL_COMMON] = 1;
00260   tree_contains_struct[FUNCTION_DECL][TS_DECL_COMMON] = 1;
00261   tree_contains_struct[TYPE_DECL][TS_DECL_COMMON] = 1;
00262   tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_COMMON] = 1;
00263   tree_contains_struct[LABEL_DECL][TS_DECL_COMMON] = 1;
00264   tree_contains_struct[FIELD_DECL][TS_DECL_COMMON] = 1;
00265 
00266 
00267   tree_contains_struct[CONST_DECL][TS_DECL_WRTL] = 1;
00268   tree_contains_struct[VAR_DECL][TS_DECL_WRTL] = 1;
00269   tree_contains_struct[PARM_DECL][TS_DECL_WRTL] = 1;
00270   tree_contains_struct[RESULT_DECL][TS_DECL_WRTL] = 1;
00271   tree_contains_struct[FUNCTION_DECL][TS_DECL_WRTL] = 1;
00272   tree_contains_struct[LABEL_DECL][TS_DECL_WRTL] = 1; 
00273 
00274   tree_contains_struct[CONST_DECL][TS_DECL_MINIMAL] = 1;
00275   tree_contains_struct[VAR_DECL][TS_DECL_MINIMAL] = 1;
00276   tree_contains_struct[PARM_DECL][TS_DECL_MINIMAL] = 1;
00277   tree_contains_struct[RESULT_DECL][TS_DECL_MINIMAL] = 1;
00278   tree_contains_struct[FUNCTION_DECL][TS_DECL_MINIMAL] = 1;
00279   tree_contains_struct[TYPE_DECL][TS_DECL_MINIMAL] = 1;
00280   tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_MINIMAL] = 1;
00281   tree_contains_struct[LABEL_DECL][TS_DECL_MINIMAL] = 1;
00282   tree_contains_struct[FIELD_DECL][TS_DECL_MINIMAL] = 1;
00283   tree_contains_struct[STRUCT_FIELD_TAG][TS_DECL_MINIMAL] = 1;
00284   tree_contains_struct[NAME_MEMORY_TAG][TS_DECL_MINIMAL] = 1;
00285   tree_contains_struct[SYMBOL_MEMORY_TAG][TS_DECL_MINIMAL] = 1;
00286 
00287   tree_contains_struct[STRUCT_FIELD_TAG][TS_MEMORY_TAG] = 1;
00288   tree_contains_struct[NAME_MEMORY_TAG][TS_MEMORY_TAG] = 1;
00289   tree_contains_struct[SYMBOL_MEMORY_TAG][TS_MEMORY_TAG] = 1;
00290 
00291   tree_contains_struct[STRUCT_FIELD_TAG][TS_STRUCT_FIELD_TAG] = 1;
00292 
00293   tree_contains_struct[VAR_DECL][TS_DECL_WITH_VIS] = 1;
00294   tree_contains_struct[FUNCTION_DECL][TS_DECL_WITH_VIS] = 1;
00295   tree_contains_struct[TYPE_DECL][TS_DECL_WITH_VIS] = 1;
00296   tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_WITH_VIS] = 1;
00297   
00298   tree_contains_struct[VAR_DECL][TS_VAR_DECL] = 1;
00299   tree_contains_struct[FIELD_DECL][TS_FIELD_DECL] = 1;
00300   tree_contains_struct[PARM_DECL][TS_PARM_DECL] = 1;
00301   tree_contains_struct[LABEL_DECL][TS_LABEL_DECL] = 1;
00302   tree_contains_struct[RESULT_DECL][TS_RESULT_DECL] = 1;
00303   tree_contains_struct[CONST_DECL][TS_CONST_DECL] = 1;
00304   tree_contains_struct[TYPE_DECL][TS_TYPE_DECL] = 1;
00305   tree_contains_struct[FUNCTION_DECL][TS_FUNCTION_DECL] = 1;
00306 
00307   lang_hooks.init_ts ();
00308 }
00309 
00310 
00311 /* The name of the object as the assembler will see it (but before any
00312    translations made by ASM_OUTPUT_LABELREF).  Often this is the same
00313    as DECL_NAME.  It is an IDENTIFIER_NODE.  */
00314 tree
00315 decl_assembler_name (tree decl)
00316 {
00317   if (!DECL_ASSEMBLER_NAME_SET_P (decl))
00318     lang_hooks.set_decl_assembler_name (decl);
00319   return DECL_WITH_VIS_CHECK (decl)->decl_with_vis.assembler_name;
00320 }
00321 
00322 /* Compute the number of bytes occupied by a tree with code CODE.
00323    This function cannot be used for TREE_VEC, PHI_NODE, or STRING_CST
00324    codes, which are of variable length.  */
00325 size_t
00326 tree_code_size (enum tree_code code)
00327 {
00328   switch (TREE_CODE_CLASS (code))
00329     {
00330     case tcc_declaration:  /* A decl node */
00331       {
00332   switch (code)
00333     {
00334     case FIELD_DECL:
00335       return sizeof (struct tree_field_decl);
00336     case PARM_DECL:
00337       return sizeof (struct tree_parm_decl);
00338     case VAR_DECL:
00339       return sizeof (struct tree_var_decl);
00340     case LABEL_DECL:
00341       return sizeof (struct tree_label_decl);
00342     case RESULT_DECL:
00343       return sizeof (struct tree_result_decl);
00344     case CONST_DECL:
00345       return sizeof (struct tree_const_decl);
00346     case TYPE_DECL:
00347       return sizeof (struct tree_type_decl);
00348     case FUNCTION_DECL:
00349       return sizeof (struct tree_function_decl);
00350     case NAME_MEMORY_TAG:
00351     case SYMBOL_MEMORY_TAG:
00352       return sizeof (struct tree_memory_tag);
00353     case STRUCT_FIELD_TAG:
00354       return sizeof (struct tree_struct_field_tag);
00355     default:
00356       return sizeof (struct tree_decl_non_common);
00357     }
00358       }
00359 
00360     case tcc_type:  /* a type node */
00361       return sizeof (struct tree_type);
00362 
00363     case tcc_reference:   /* a reference */
00364     case tcc_expression:  /* an expression */
00365     case tcc_statement:   /* an expression with side effects */
00366     case tcc_comparison:  /* a comparison expression */
00367     case tcc_unary:       /* a unary arithmetic expression */
00368     case tcc_binary:      /* a binary arithmetic expression */
00369       return (sizeof (struct tree_exp)
00370         + (TREE_CODE_LENGTH (code) - 1) * sizeof (char *));
00371 
00372     case tcc_constant:  /* a constant */
00373       switch (code)
00374   {
00375   case INTEGER_CST: return sizeof (struct tree_int_cst);
00376   case REAL_CST:    return sizeof (struct tree_real_cst);
00377   case COMPLEX_CST: return sizeof (struct tree_complex);
00378   case VECTOR_CST:  return sizeof (struct tree_vector);
00379   case STRING_CST:  gcc_unreachable ();
00380   default:
00381     return lang_hooks.tree_size (code);
00382   }
00383 
00384     case tcc_exceptional:  /* something random, like an identifier.  */
00385       switch (code)
00386   {
00387   case IDENTIFIER_NODE: return lang_hooks.identifier_size;
00388   case TREE_LIST:   return sizeof (struct tree_list);
00389 
00390   case ERROR_MARK:
00391   case PLACEHOLDER_EXPR:  return sizeof (struct tree_common);
00392 
00393   case TREE_VEC:
00394   case OMP_CLAUSE:
00395   case PHI_NODE:    gcc_unreachable ();
00396 
00397   case SSA_NAME:    return sizeof (struct tree_ssa_name);
00398 
00399   case STATEMENT_LIST:  return sizeof (struct tree_statement_list);
00400   case BLOCK:   return sizeof (struct tree_block);
00401   case VALUE_HANDLE:  return sizeof (struct tree_value_handle);
00402   case CONSTRUCTOR: return sizeof (struct tree_constructor);
00403 
00404   default:
00405     return lang_hooks.tree_size (code);
00406   }
00407 
00408     default:
00409       gcc_unreachable ();
00410     }
00411 }
00412 
00413 /* Compute the number of bytes occupied by NODE.  This routine only
00414    looks at TREE_CODE, except for PHI_NODE and TREE_VEC nodes.  */
00415 size_t
00416 tree_size (tree node)
00417 {
00418   enum tree_code code = TREE_CODE (node);
00419   switch (code)
00420     {
00421     case PHI_NODE:
00422       return (sizeof (struct tree_phi_node)
00423         + (PHI_ARG_CAPACITY (node) - 1) * sizeof (struct phi_arg_d));
00424 
00425     case TREE_BINFO:
00426       return (offsetof (struct tree_binfo, base_binfos)
00427         + VEC_embedded_size (tree, BINFO_N_BASE_BINFOS (node)));
00428 
00429     case TREE_VEC:
00430       return (sizeof (struct tree_vec)
00431         + (TREE_VEC_LENGTH (node) - 1) * sizeof(char *));
00432 
00433     case STRING_CST:
00434       return TREE_STRING_LENGTH (node) + offsetof (struct tree_string, str) + 1;
00435 
00436     case OMP_CLAUSE:
00437       return (sizeof (struct tree_omp_clause)
00438         + (omp_clause_num_ops[OMP_CLAUSE_CODE (node)] - 1)
00439           * sizeof (tree));
00440 
00441     default:
00442       return tree_code_size (code);
00443     }
00444 }
00445 
00446 /* Return a newly allocated node of code CODE.  For decl and type
00447    nodes, some other fields are initialized.  The rest of the node is
00448    initialized to zero.  This function cannot be used for PHI_NODE,
00449    TREE_VEC or OMP_CLAUSE nodes, which is enforced by asserts in
00450    tree_code_size.
00451 
00452    Achoo!  I got a code in the node.  */
00453 
00454 tree
00455 make_node_stat (enum tree_code code MEM_STAT_DECL)
00456 {
00457   tree t;
00458   enum tree_code_class type = TREE_CODE_CLASS (code);
00459   size_t length = tree_code_size (code);
00460 #ifdef GATHER_STATISTICS
00461   tree_node_kind kind;
00462 
00463   switch (type)
00464     {
00465     case tcc_declaration:  /* A decl node */
00466       kind = d_kind;
00467       break;
00468 
00469     case tcc_type:  /* a type node */
00470       kind = t_kind;
00471       break;
00472 
00473     case tcc_statement:  /* an expression with side effects */
00474       kind = s_kind;
00475       break;
00476 
00477     case tcc_reference:  /* a reference */
00478       kind = r_kind;
00479       break;
00480 
00481     case tcc_expression:  /* an expression */
00482     case tcc_comparison:  /* a comparison expression */
00483     case tcc_unary:  /* a unary arithmetic expression */
00484     case tcc_binary:  /* a binary arithmetic expression */
00485       kind = e_kind;
00486       break;
00487 
00488     case tcc_constant:  /* a constant */
00489       kind = c_kind;
00490       break;
00491 
00492     case tcc_exceptional:  /* something random, like an identifier.  */
00493       switch (code)
00494   {
00495   case IDENTIFIER_NODE:
00496     kind = id_kind;
00497     break;
00498 
00499   case TREE_VEC:
00500     kind = vec_kind;
00501     break;
00502 
00503   case TREE_BINFO:
00504     kind = binfo_kind;
00505     break;
00506 
00507   case PHI_NODE:
00508     kind = phi_kind;
00509     break;
00510 
00511   case SSA_NAME:
00512     kind = ssa_name_kind;
00513     break;
00514 
00515   case BLOCK:
00516     kind = b_kind;
00517     break;
00518 
00519   case CONSTRUCTOR:
00520     kind = constr_kind;
00521     break;
00522 
00523   default:
00524     kind = x_kind;
00525     break;
00526   }
00527       break;
00528       
00529     default:
00530       gcc_unreachable ();
00531     }
00532 
00533   tree_node_counts[(int) kind]++;
00534   tree_node_sizes[(int) kind] += length;
00535 #endif
00536 
00537   if (code == IDENTIFIER_NODE)
00538     t = ggc_alloc_zone_pass_stat (length, &tree_id_zone);
00539   else
00540     t = ggc_alloc_zone_pass_stat (length, &tree_zone);
00541 
00542   memset (t, 0, length);
00543 
00544   TREE_SET_CODE (t, code);
00545 
00546   switch (type)
00547     {
00548     case tcc_statement:
00549       TREE_SIDE_EFFECTS (t) = 1;
00550       break;
00551 
00552     case tcc_declaration:
00553       if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
00554   DECL_IN_SYSTEM_HEADER (t) = in_system_header;
00555       if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
00556   {
00557     if (code != FUNCTION_DECL)
00558       DECL_ALIGN (t) = 1;
00559     DECL_USER_ALIGN (t) = 0;    
00560     /* We have not yet computed the alias set for this declaration.  */
00561     DECL_POINTER_ALIAS_SET (t) = -1;
00562   }
00563       DECL_SOURCE_LOCATION (t) = input_location;
00564       DECL_UID (t) = next_decl_uid++;
00565 
00566       break;
00567 
00568     case tcc_type:
00569       TYPE_UID (t) = next_type_uid++;
00570       TYPE_ALIGN (t) = BITS_PER_UNIT;
00571       TYPE_USER_ALIGN (t) = 0;
00572       TYPE_MAIN_VARIANT (t) = t;
00573 
00574       /* Default to no attributes for type, but let target change that.  */
00575       TYPE_ATTRIBUTES (t) = NULL_TREE;
00576       targetm.set_default_type_attributes (t);
00577 
00578       /* We have not yet computed the alias set for this type.  */
00579       TYPE_ALIAS_SET (t) = -1;
00580       break;
00581 
00582     case tcc_constant:
00583       TREE_CONSTANT (t) = 1;
00584       TREE_INVARIANT (t) = 1;
00585       break;
00586 
00587     case tcc_expression:
00588       switch (code)
00589   {
00590   case INIT_EXPR:
00591   case MODIFY_EXPR:
00592   case VA_ARG_EXPR:
00593   case PREDECREMENT_EXPR:
00594   case PREINCREMENT_EXPR:
00595   case POSTDECREMENT_EXPR:
00596   case POSTINCREMENT_EXPR:
00597     /* All of these have side-effects, no matter what their
00598        operands are.  */
00599     TREE_SIDE_EFFECTS (t) = 1;
00600     break;
00601 
00602   default:
00603     break;
00604   }
00605       break;
00606 
00607     default:
00608       /* Other classes need no special treatment.  */
00609       break;
00610     }
00611 
00612   return t;
00613 }
00614 
00615 /* Return a new node with the same contents as NODE except that its
00616    TREE_CHAIN is zero and it has a fresh uid.  */
00617 
00618 /* KEY: Also gs_node translation related fields are 0, so that this new
00619    node is again translated to gs_t. */
00620 
00621 tree
00622 copy_node_stat (tree node MEM_STAT_DECL)
00623 {
00624   tree t;
00625   enum tree_code code = TREE_CODE (node);
00626   size_t length;
00627 
00628   gcc_assert (code != STATEMENT_LIST);
00629 
00630   length = tree_size (node);
00631   t = ggc_alloc_zone_pass_stat (length, &tree_zone);
00632   memcpy (t, node, length);
00633 
00634   TREE_CHAIN (t) = 0;
00635   TREE_ASM_WRITTEN (t) = 0;
00636   TREE_VISITED (t) = 0;
00637   t->common.ann = 0;
00638 #ifdef KEY
00639   if (flag_spin_file)
00640     TREE_TO_TRANSLATED_GS (t) = 0;
00641 #endif
00642 
00643   if (TREE_CODE_CLASS (code) == tcc_declaration)
00644     {
00645       DECL_UID (t) = next_decl_uid++;
00646       if ((TREE_CODE (node) == PARM_DECL || TREE_CODE (node) == VAR_DECL)
00647     && DECL_HAS_VALUE_EXPR_P (node))
00648   {
00649     SET_DECL_VALUE_EXPR (t, DECL_VALUE_EXPR (node));
00650     DECL_HAS_VALUE_EXPR_P (t) = 1;
00651   }
00652       if (TREE_CODE (node) == VAR_DECL && DECL_HAS_INIT_PRIORITY_P (node))
00653   {
00654     SET_DECL_INIT_PRIORITY (t, DECL_INIT_PRIORITY (node));
00655     DECL_HAS_INIT_PRIORITY_P (t) = 1;
00656   }
00657       if (TREE_CODE (node) == VAR_DECL && DECL_BASED_ON_RESTRICT_P (node))
00658   {
00659     SET_DECL_RESTRICT_BASE (t, DECL_GET_RESTRICT_BASE (node));
00660     DECL_BASED_ON_RESTRICT_P (t) = 1;
00661   }
00662     }
00663   else if (TREE_CODE_CLASS (code) == tcc_type)
00664     {
00665       TYPE_UID (t) = next_type_uid++;
00666       /* The following is so that the debug code for
00667    the copy is different from the original type.
00668    The two statements usually duplicate each other
00669    (because they clear fields of the same union),
00670    but the optimizer should catch that.  */
00671       TYPE_SYMTAB_POINTER (t) = 0;
00672       TYPE_SYMTAB_ADDRESS (t) = 0;
00673       
00674       /* Do not copy the values cache.  */
00675       if (TYPE_CACHED_VALUES_P(t))
00676   {
00677     TYPE_CACHED_VALUES_P (t) = 0;
00678     TYPE_CACHED_VALUES (t) = NULL_TREE;
00679   }
00680     }
00681 
00682   return t;
00683 }
00684 
00685 /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
00686    For example, this can copy a list made of TREE_LIST nodes.  */
00687 
00688 tree
00689 copy_list (tree list)
00690 {
00691   tree head;
00692   tree prev, next;
00693 
00694   if (list == 0)
00695     return 0;
00696 
00697   head = prev = copy_node (list);
00698   next = TREE_CHAIN (list);
00699   while (next)
00700     {
00701       TREE_CHAIN (prev) = copy_node (next);
00702       prev = TREE_CHAIN (prev);
00703       next = TREE_CHAIN (next);
00704     }
00705   return head;
00706 }
00707 
00708 
00709 /* Create an INT_CST node with a LOW value sign extended.  */
00710 
00711 tree
00712 build_int_cst (tree type, HOST_WIDE_INT low)
00713 {
00714   return build_int_cst_wide (type, low, low < 0 ? -1 : 0);
00715 }
00716 
00717 /* Create an INT_CST node with a LOW value zero extended.  */
00718 
00719 tree
00720 build_int_cstu (tree type, unsigned HOST_WIDE_INT low)
00721 {
00722   return build_int_cst_wide (type, low, 0);
00723 }
00724 
00725 /* Create an INT_CST node with a LOW value in TYPE.  The value is sign extended
00726    if it is negative.  This function is similar to build_int_cst, but
00727    the extra bits outside of the type precision are cleared.  Constants
00728    with these extra bits may confuse the fold so that it detects overflows
00729    even in cases when they do not occur, and in general should be avoided.
00730    We cannot however make this a default behavior of build_int_cst without
00731    more intrusive changes, since there are parts of gcc that rely on the extra
00732    precision of the integer constants.  */
00733 
00734 tree
00735 build_int_cst_type (tree type, HOST_WIDE_INT low)
00736 {
00737   unsigned HOST_WIDE_INT val = (unsigned HOST_WIDE_INT) low;
00738   unsigned HOST_WIDE_INT hi, mask;
00739   unsigned bits;
00740   bool signed_p;
00741   bool negative;
00742 
00743   if (!type)
00744     type = integer_type_node;
00745 
00746   bits = TYPE_PRECISION (type);
00747   signed_p = !TYPE_UNSIGNED (type);
00748 
00749   if (bits >= HOST_BITS_PER_WIDE_INT)
00750     negative = (low < 0);
00751   else
00752     {
00753       /* If the sign bit is inside precision of LOW, use it to determine
00754    the sign of the constant.  */
00755       negative = ((val >> (bits - 1)) & 1) != 0;
00756 
00757       /* Mask out the bits outside of the precision of the constant.  */
00758       mask = (((unsigned HOST_WIDE_INT) 2) << (bits - 1)) - 1;
00759 
00760       if (signed_p && negative)
00761   val |= ~mask;
00762       else
00763   val &= mask;
00764     }
00765 
00766   /* Determine the high bits.  */
00767   hi = (negative ? ~(unsigned HOST_WIDE_INT) 0 : 0);
00768 
00769   /* For unsigned type we need to mask out the bits outside of the type
00770      precision.  */
00771   if (!signed_p)
00772     {
00773       if (bits <= HOST_BITS_PER_WIDE_INT)
00774   hi = 0;
00775       else
00776   {
00777     bits -= HOST_BITS_PER_WIDE_INT;
00778     mask = (((unsigned HOST_WIDE_INT) 2) << (bits - 1)) - 1;
00779     hi &= mask;
00780   }
00781     }
00782 
00783   return build_int_cst_wide (type, val, hi);
00784 }
00785 
00786 /* These are the hash table functions for the hash table of INTEGER_CST
00787    nodes of a sizetype.  */
00788 
00789 /* Return the hash code code X, an INTEGER_CST.  */
00790 
00791 static hashval_t
00792 int_cst_hash_hash (const void *x)
00793 {
00794   tree t = (tree) x;
00795 
00796   return (TREE_INT_CST_HIGH (t) ^ TREE_INT_CST_LOW (t)
00797     ^ htab_hash_pointer (TREE_TYPE (t)));
00798 }
00799 
00800 /* Return nonzero if the value represented by *X (an INTEGER_CST tree node)
00801    is the same as that given by *Y, which is the same.  */
00802 
00803 static int
00804 int_cst_hash_eq (const void *x, const void *y)
00805 {
00806   tree xt = (tree) x;
00807   tree yt = (tree) y;
00808 
00809   return (TREE_TYPE (xt) == TREE_TYPE (yt)
00810     && TREE_INT_CST_HIGH (xt) == TREE_INT_CST_HIGH (yt)
00811     && TREE_INT_CST_LOW (xt) == TREE_INT_CST_LOW (yt));
00812 }
00813 
00814 /* Create an INT_CST node of TYPE and value HI:LOW.  If TYPE is NULL,
00815    integer_type_node is used.  The returned node is always shared.
00816    For small integers we use a per-type vector cache, for larger ones
00817    we use a single hash table.  */
00818 
00819 tree
00820 build_int_cst_wide (tree type, unsigned HOST_WIDE_INT low, HOST_WIDE_INT hi)
00821 {
00822   tree t;
00823   int ix = -1;
00824   int limit = 0;
00825 
00826   if (!type)
00827     type = integer_type_node;
00828 
00829   switch (TREE_CODE (type))
00830     {
00831     case POINTER_TYPE:
00832     case REFERENCE_TYPE:
00833       /* Cache NULL pointer.  */
00834       if (!hi && !low)
00835   {
00836     limit = 1;
00837     ix = 0;
00838   }
00839       break;
00840 
00841     case BOOLEAN_TYPE:
00842       /* Cache false or true.  */
00843       limit = 2;
00844       if (!hi && low < 2)
00845   ix = low;
00846       break;
00847 
00848     case INTEGER_TYPE:
00849     case OFFSET_TYPE:
00850       if (TYPE_UNSIGNED (type))
00851   {
00852     /* Cache 0..N */
00853     limit = INTEGER_SHARE_LIMIT;
00854     if (!hi && low < (unsigned HOST_WIDE_INT)INTEGER_SHARE_LIMIT)
00855       ix = low;
00856   }
00857       else
00858   {
00859     /* Cache -1..N */
00860     limit = INTEGER_SHARE_LIMIT + 1;
00861     if (!hi && low < (unsigned HOST_WIDE_INT)INTEGER_SHARE_LIMIT)
00862       ix = low + 1;
00863     else if (hi == -1 && low == -(unsigned HOST_WIDE_INT)1)
00864       ix = 0;
00865   }
00866       break;
00867     default:
00868       break;
00869     }
00870 
00871   if (ix >= 0)
00872     {
00873       /* Look for it in the type's vector of small shared ints.  */
00874       if (!TYPE_CACHED_VALUES_P (type))
00875   {
00876     TYPE_CACHED_VALUES_P (type) = 1;
00877     TYPE_CACHED_VALUES (type) = make_tree_vec (limit);
00878   }
00879 
00880       t = TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix);
00881       if (t)
00882   {
00883     /* Make sure no one is clobbering the shared constant.  */
00884     gcc_assert (TREE_TYPE (t) == type);
00885     gcc_assert (TREE_INT_CST_LOW (t) == low);
00886     gcc_assert (TREE_INT_CST_HIGH (t) == hi);
00887   }
00888       else
00889   {
00890     /* Create a new shared int.  */
00891     t = make_node (INTEGER_CST);
00892 
00893     TREE_INT_CST_LOW (t) = low;
00894     TREE_INT_CST_HIGH (t) = hi;
00895     TREE_TYPE (t) = type;
00896     
00897     TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix) = t;
00898   }
00899     }
00900   else
00901     {
00902       /* Use the cache of larger shared ints.  */
00903       void **slot;
00904 
00905       TREE_INT_CST_LOW (int_cst_node) = low;
00906       TREE_INT_CST_HIGH (int_cst_node) = hi;
00907       TREE_TYPE (int_cst_node) = type;
00908 
00909       slot = htab_find_slot (int_cst_hash_table, int_cst_node, INSERT);
00910       t = *slot;
00911       if (!t)
00912   {
00913     /* Insert this one into the hash table.  */
00914     t = int_cst_node;
00915     *slot = t;
00916     /* Make a new node for next time round.  */
00917     int_cst_node = make_node (INTEGER_CST);
00918   }
00919     }
00920 
00921   return t;
00922 }
00923 
00924 /* Builds an integer constant in TYPE such that lowest BITS bits are ones
00925    and the rest are zeros.  */
00926 
00927 tree
00928 build_low_bits_mask (tree type, unsigned bits)
00929 {
00930   unsigned HOST_WIDE_INT low;
00931   HOST_WIDE_INT high;
00932   unsigned HOST_WIDE_INT all_ones = ~(unsigned HOST_WIDE_INT) 0;
00933 
00934   gcc_assert (bits <= TYPE_PRECISION (type));
00935 
00936   if (bits == TYPE_PRECISION (type)
00937       && !TYPE_UNSIGNED (type))
00938     {
00939       /* Sign extended all-ones mask.  */
00940       low = all_ones;
00941       high = -1;
00942     }
00943   else if (bits <= HOST_BITS_PER_WIDE_INT)
00944     {
00945       low = all_ones >> (HOST_BITS_PER_WIDE_INT - bits);
00946       high = 0;
00947     }
00948   else
00949     {
00950       bits -= HOST_BITS_PER_WIDE_INT;
00951       low = all_ones;
00952       high = all_ones >> (HOST_BITS_PER_WIDE_INT - bits);
00953     }
00954 
00955   return build_int_cst_wide (type, low, high);
00956 }
00957 
00958 /* Checks that X is integer constant that can be expressed in (unsigned)
00959    HOST_WIDE_INT without loss of precision.  */
00960 
00961 bool
00962 cst_and_fits_in_hwi (tree x)
00963 {
00964   if (TREE_CODE (x) != INTEGER_CST)
00965     return false;
00966 
00967   if (TYPE_PRECISION (TREE_TYPE (x)) > HOST_BITS_PER_WIDE_INT)
00968     return false;
00969 
00970   return (TREE_INT_CST_HIGH (x) == 0
00971     || TREE_INT_CST_HIGH (x) == -1);
00972 }
00973 
00974 /* Return a new VECTOR_CST node whose type is TYPE and whose values
00975    are in a list pointed to by VALS.  */
00976 
00977 tree
00978 build_vector (tree type, tree vals)
00979 {
00980   tree v = make_node (VECTOR_CST);
00981   int over1 = 0, over2 = 0;
00982   tree link;
00983 
00984   TREE_VECTOR_CST_ELTS (v) = vals;
00985   TREE_TYPE (v) = type;
00986 
00987   /* Iterate through elements and check for overflow.  */
00988   for (link = vals; link; link = TREE_CHAIN (link))
00989     {
00990       tree value = TREE_VALUE (link);
00991 
00992       /* Don't crash if we get an address constant.  */
00993       if (!CONSTANT_CLASS_P (value))
00994   continue;
00995 
00996       over1 |= TREE_OVERFLOW (value);
00997       over2 |= TREE_CONSTANT_OVERFLOW (value);
00998     }
00999 
01000   TREE_OVERFLOW (v) = over1;
01001   TREE_CONSTANT_OVERFLOW (v) = over2;
01002 
01003   return v;
01004 }
01005 
01006 /* Return a new VECTOR_CST node whose type is TYPE and whose values
01007    are extracted from V, a vector of CONSTRUCTOR_ELT.  */
01008 
01009 tree
01010 build_vector_from_ctor (tree type, VEC(constructor_elt,gc) *v)
01011 {
01012   tree list = NULL_TREE;
01013   unsigned HOST_WIDE_INT idx;
01014   tree value;
01015 
01016   FOR_EACH_CONSTRUCTOR_VALUE (v, idx, value)
01017     list = tree_cons (NULL_TREE, value, list);
01018   return build_vector (type, nreverse (list));
01019 }
01020 
01021 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
01022    are in the VEC pointed to by VALS.  */
01023 tree
01024 build_constructor (tree type, VEC(constructor_elt,gc) *vals)
01025 {
01026   tree c = make_node (CONSTRUCTOR);
01027   TREE_TYPE (c) = type;
01028   CONSTRUCTOR_ELTS (c) = vals;
01029   return c;
01030 }
01031 
01032 /* Build a CONSTRUCTOR node made of a single initializer, with the specified
01033    INDEX and VALUE.  */
01034 tree
01035 build_constructor_single (tree type, tree index, tree value)
01036 {
01037   VEC(constructor_elt,gc) *v;
01038   constructor_elt *elt;
01039   tree t;
01040 
01041   v = VEC_alloc (constructor_elt, gc, 1);
01042   elt = VEC_quick_push (constructor_elt, v, NULL);
01043   elt->index = index;
01044   elt->value = value;
01045 
01046   t = build_constructor (type, v);
01047   TREE_CONSTANT (t) = TREE_CONSTANT (value);
01048   return t;
01049 }
01050 
01051 
01052 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
01053    are in a list pointed to by VALS.  */
01054 tree
01055 build_constructor_from_list (tree type, tree vals)
01056 {
01057   tree t, val;
01058   VEC(constructor_elt,gc) *v = NULL;
01059   bool constant_p = true;
01060 
01061   if (vals)
01062     {
01063       v = VEC_alloc (constructor_elt, gc, list_length (vals));
01064       for (t = vals; t; t = TREE_CHAIN (t))
01065   {
01066     constructor_elt *elt = VEC_quick_push (constructor_elt, v, NULL);
01067     val = TREE_VALUE (t);
01068     elt->index = TREE_PURPOSE (t);
01069     elt->value = val;
01070     if (!TREE_CONSTANT (val))
01071       constant_p = false;
01072   }
01073     }
01074 
01075   t = build_constructor (type, v);
01076   TREE_CONSTANT (t) = constant_p;
01077   return t;
01078 }
01079 
01080 
01081 /* Return a new REAL_CST node whose type is TYPE and value is D.  */
01082 
01083 tree
01084 build_real (tree type, REAL_VALUE_TYPE d)
01085 {
01086   tree v;
01087   REAL_VALUE_TYPE *dp;
01088   int overflow = 0;
01089 
01090   /* ??? Used to check for overflow here via CHECK_FLOAT_TYPE.
01091      Consider doing it via real_convert now.  */
01092 
01093   v = make_node (REAL_CST);
01094   dp = ggc_alloc (sizeof (REAL_VALUE_TYPE));
01095   memcpy (dp, &d, sizeof (REAL_VALUE_TYPE));
01096 
01097   TREE_TYPE (v) = type;
01098   TREE_REAL_CST_PTR (v) = dp;
01099   TREE_OVERFLOW (v) = TREE_CONSTANT_OVERFLOW (v) = overflow;
01100   return v;
01101 }
01102 
01103 /* Return a new REAL_CST node whose type is TYPE
01104    and whose value is the integer value of the INTEGER_CST node I.  */
01105 
01106 REAL_VALUE_TYPE
01107 real_value_from_int_cst (tree type, tree i)
01108 {
01109   REAL_VALUE_TYPE d;
01110 
01111   /* Clear all bits of the real value type so that we can later do
01112      bitwise comparisons to see if two values are the same.  */
01113   memset (&d, 0, sizeof d);
01114 
01115   real_from_integer (&d, type ? TYPE_MODE (type) : VOIDmode,
01116          TREE_INT_CST_LOW (i), TREE_INT_CST_HIGH (i),
01117          TYPE_UNSIGNED (TREE_TYPE (i)));
01118   return d;
01119 }
01120 
01121 /* Given a tree representing an integer constant I, return a tree
01122    representing the same value as a floating-point constant of type TYPE.  */
01123 
01124 tree
01125 build_real_from_int_cst (tree type, tree i)
01126 {
01127   tree v;
01128   int overflow = TREE_OVERFLOW (i);
01129 
01130   v = build_real (type, real_value_from_int_cst (type, i));
01131 
01132   TREE_OVERFLOW (v) |= overflow;
01133   TREE_CONSTANT_OVERFLOW (v) |= overflow;
01134   return v;
01135 }
01136 
01137 /* Return a newly constructed STRING_CST node whose value is
01138    the LEN characters at STR.
01139    The TREE_TYPE is not initialized.  */
01140 
01141 tree
01142 build_string (int len, const char *str)
01143 {
01144   tree s;
01145   size_t length;
01146 
01147   /* Do not waste bytes provided by padding of struct tree_string.  */
01148   length = len + offsetof (struct tree_string, str) + 1;
01149 
01150 #ifdef GATHER_STATISTICS
01151   tree_node_counts[(int) c_kind]++;
01152   tree_node_sizes[(int) c_kind] += length;
01153 #endif  
01154 
01155   s = ggc_alloc_tree (length);
01156 
01157   memset (s, 0, sizeof (struct tree_common));
01158   TREE_SET_CODE (s, STRING_CST);
01159   TREE_CONSTANT (s) = 1;
01160   TREE_INVARIANT (s) = 1;
01161   TREE_STRING_LENGTH (s) = len;
01162   memcpy ((char *) TREE_STRING_POINTER (s), str, len);
01163   ((char *) TREE_STRING_POINTER (s))[len] = '\0';
01164 
01165   return s;
01166 }
01167 
01168 /* Return a newly constructed COMPLEX_CST node whose value is
01169    specified by the real and imaginary parts REAL and IMAG.
01170    Both REAL and IMAG should be constant nodes.  TYPE, if specified,
01171    will be the type of the COMPLEX_CST; otherwise a new type will be made.  */
01172 
01173 tree
01174 build_complex (tree type, tree real, tree imag)
01175 {
01176   tree t = make_node (COMPLEX_CST);
01177 
01178   TREE_REALPART (t) = real;
01179   TREE_IMAGPART (t) = imag;
01180   TREE_TYPE (t) = type ? type : build_complex_type (TREE_TYPE (real));
01181   TREE_OVERFLOW (t) = TREE_OVERFLOW (real) | TREE_OVERFLOW (imag);
01182   TREE_CONSTANT_OVERFLOW (t)
01183     = TREE_CONSTANT_OVERFLOW (real) | TREE_CONSTANT_OVERFLOW (imag);
01184   return t;
01185 }
01186 
01187 /* Return a constant of arithmetic type TYPE which is the
01188    multiplicative identity of the set TYPE.  */
01189 
01190 tree
01191 build_one_cst (tree type)
01192 {
01193   switch (TREE_CODE (type))
01194     {
01195     case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
01196     case POINTER_TYPE: case REFERENCE_TYPE:
01197     case OFFSET_TYPE:
01198       return build_int_cst (type, 1);
01199 
01200     case REAL_TYPE:
01201       return build_real (type, dconst1);
01202 
01203     case VECTOR_TYPE:
01204       {
01205   tree scalar, cst;
01206   int i;
01207 
01208   scalar = build_one_cst (TREE_TYPE (type));
01209 
01210   /* Create 'vect_cst_ = {cst,cst,...,cst}'  */
01211   cst = NULL_TREE;
01212   for (i = TYPE_VECTOR_SUBPARTS (type); --i >= 0; )
01213     cst = tree_cons (NULL_TREE, scalar, cst);
01214 
01215   return build_vector (type, cst);
01216       }
01217 
01218     case COMPLEX_TYPE:
01219       return build_complex (type,
01220           build_one_cst (TREE_TYPE (type)),
01221           fold_convert (TREE_TYPE (type), integer_zero_node));
01222 
01223     default:
01224       gcc_unreachable ();
01225     }
01226 }
01227 
01228 /* Build a BINFO with LEN language slots.  */
01229 
01230 tree
01231 make_tree_binfo_stat (unsigned base_binfos MEM_STAT_DECL)
01232 {
01233   tree t;
01234   size_t length = (offsetof (struct tree_binfo, base_binfos)
01235        + VEC_embedded_size (tree, base_binfos));
01236 
01237 #ifdef GATHER_STATISTICS
01238   tree_node_counts[(int) binfo_kind]++;
01239   tree_node_sizes[(int) binfo_kind] += length;
01240 #endif
01241 
01242   t = ggc_alloc_zone_pass_stat (length, &tree_zone);
01243 
01244   memset (t, 0, offsetof (struct tree_binfo, base_binfos));
01245 
01246   TREE_SET_CODE (t, TREE_BINFO);
01247 
01248   VEC_embedded_init (tree, BINFO_BASE_BINFOS (t), base_binfos);
01249 
01250   return t;
01251 }
01252 
01253 
01254 /* Build a newly constructed TREE_VEC node of length LEN.  */
01255 
01256 tree
01257 make_tree_vec_stat (int len MEM_STAT_DECL)
01258 {
01259   tree t;
01260   int length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
01261 
01262 #ifdef GATHER_STATISTICS
01263   tree_node_counts[(int) vec_kind]++;
01264   tree_node_sizes[(int) vec_kind] += length;
01265 #endif
01266 
01267   t = ggc_alloc_zone_pass_stat (length, &tree_zone);
01268 
01269   memset (t, 0, length);
01270 
01271   TREE_SET_CODE (t, TREE_VEC);
01272   TREE_VEC_LENGTH (t) = len;
01273 
01274   return t;
01275 }
01276 
01277 /* Return 1 if EXPR is the integer constant zero or a complex constant
01278    of zero.  */
01279 
01280 int
01281 integer_zerop (tree expr)
01282 {
01283   STRIP_NOPS (expr);
01284 
01285   return ((TREE_CODE (expr) == INTEGER_CST
01286      && TREE_INT_CST_LOW (expr) == 0
01287      && TREE_INT_CST_HIGH (expr) == 0)
01288     || (TREE_CODE (expr) == COMPLEX_CST
01289         && integer_zerop (TREE_REALPART (expr))
01290         && integer_zerop (TREE_IMAGPART (expr))));
01291 }
01292 
01293 /* Return 1 if EXPR is the integer constant one or the corresponding
01294    complex constant.  */
01295 
01296 int
01297 integer_onep (tree expr)
01298 {
01299   STRIP_NOPS (expr);
01300 
01301   return ((TREE_CODE (expr) == INTEGER_CST
01302      && TREE_INT_CST_LOW (expr) == 1
01303      && TREE_INT_CST_HIGH (expr) == 0)
01304     || (TREE_CODE (expr) == COMPLEX_CST
01305         && integer_onep (TREE_REALPART (expr))
01306         && integer_zerop (TREE_IMAGPART (expr))));
01307 }
01308 
01309 /* Return 1 if EXPR is an integer containing all 1's in as much precision as
01310    it contains.  Likewise for the corresponding complex constant.  */
01311 
01312 int
01313 integer_all_onesp (tree expr)
01314 {
01315   int prec;
01316   int uns;
01317 
01318   STRIP_NOPS (expr);
01319 
01320   if (TREE_CODE (expr) == COMPLEX_CST
01321       && integer_all_onesp (TREE_REALPART (expr))
01322       && integer_zerop (TREE_IMAGPART (expr)))
01323     return 1;
01324 
01325   else if (TREE_CODE (expr) != INTEGER_CST)
01326     return 0;
01327 
01328   uns = TYPE_UNSIGNED (TREE_TYPE (expr));
01329   if (TREE_INT_CST_LOW (expr) == ~(unsigned HOST_WIDE_INT) 0
01330       && TREE_INT_CST_HIGH (expr) == -1)
01331     return 1;
01332   if (!uns)
01333     return 0;
01334 
01335   /* Note that using TYPE_PRECISION here is wrong.  We care about the
01336      actual bits, not the (arbitrary) range of the type.  */
01337   prec = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (expr)));
01338   if (prec >= HOST_BITS_PER_WIDE_INT)
01339     {
01340       HOST_WIDE_INT high_value;
01341       int shift_amount;
01342 
01343       shift_amount = prec - HOST_BITS_PER_WIDE_INT;
01344 
01345       /* Can not handle precisions greater than twice the host int size.  */
01346       gcc_assert (shift_amount <= HOST_BITS_PER_WIDE_INT);
01347       if (shift_amount == HOST_BITS_PER_WIDE_INT)
01348   /* Shifting by the host word size is undefined according to the ANSI
01349      standard, so we must handle this as a special case.  */
01350   high_value = -1;
01351       else
01352   high_value = ((HOST_WIDE_INT) 1 << shift_amount) - 1;
01353 
01354       return (TREE_INT_CST_LOW (expr) == ~(unsigned HOST_WIDE_INT) 0
01355         && TREE_INT_CST_HIGH (expr) == high_value);
01356     }
01357   else
01358     return TREE_INT_CST_LOW (expr) == ((unsigned HOST_WIDE_INT) 1 << prec) - 1;
01359 }
01360 
01361 /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only
01362    one bit on).  */
01363 
01364 int
01365 integer_pow2p (tree expr)
01366 {
01367   int prec;
01368   HOST_WIDE_INT high, low;
01369 
01370   STRIP_NOPS (expr);
01371 
01372   if (TREE_CODE (expr) == COMPLEX_CST
01373       && integer_pow2p (TREE_REALPART (expr))
01374       && integer_zerop (TREE_IMAGPART (expr)))
01375     return 1;
01376 
01377   if (TREE_CODE (expr) != INTEGER_CST)
01378     return 0;
01379 
01380   prec = (POINTER_TYPE_P (TREE_TYPE (expr))
01381     ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr)));
01382   high = TREE_INT_CST_HIGH (expr);
01383   low = TREE_INT_CST_LOW (expr);
01384 
01385   /* First clear all bits that are beyond the type's precision in case
01386      we've been sign extended.  */
01387 
01388   if (prec == 2 * HOST_BITS_PER_WIDE_INT)
01389     ;
01390   else if (prec > HOST_BITS_PER_WIDE_INT)
01391     high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
01392   else
01393     {
01394       high = 0;
01395       if (prec < HOST_BITS_PER_WIDE_INT)
01396   low &= ~((HOST_WIDE_INT) (-1) << prec);
01397     }
01398 
01399   if (high == 0 && low == 0)
01400     return 0;
01401 
01402   return ((high == 0 && (low & (low - 1)) == 0)
01403     || (low == 0 && (high & (high - 1)) == 0));
01404 }
01405 
01406 /* Return 1 if EXPR is an integer constant other than zero or a
01407    complex constant other than zero.  */
01408 
01409 int
01410 integer_nonzerop (tree expr)
01411 {
01412   STRIP_NOPS (expr);
01413 
01414   return ((TREE_CODE (expr) == INTEGER_CST
01415      && (TREE_INT_CST_LOW (expr) != 0
01416          || TREE_INT_CST_HIGH (expr) != 0))
01417     || (TREE_CODE (expr) == COMPLEX_CST
01418         && (integer_nonzerop (TREE_REALPART (expr))
01419       || integer_nonzerop (TREE_IMAGPART (expr)))));
01420 }
01421 
01422 /* Return the power of two represented by a tree node known to be a
01423    power of two.  */
01424 
01425 int
01426 tree_log2 (tree expr)
01427 {
01428   int prec;
01429   HOST_WIDE_INT high, low;
01430 
01431   STRIP_NOPS (expr);
01432 
01433   if (TREE_CODE (expr) == COMPLEX_CST)
01434     return tree_log2 (TREE_REALPART (expr));
01435 
01436   prec = (POINTER_TYPE_P (TREE_TYPE (expr))
01437     ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr)));
01438 
01439   high = TREE_INT_CST_HIGH (expr);
01440   low = TREE_INT_CST_LOW (expr);
01441 
01442   /* First clear all bits that are beyond the type's precision in case
01443      we've been sign extended.  */
01444 
01445   if (prec == 2 * HOST_BITS_PER_WIDE_INT)
01446     ;
01447   else if (prec > HOST_BITS_PER_WIDE_INT)
01448     high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
01449   else
01450     {
01451       high = 0;
01452       if (prec < HOST_BITS_PER_WIDE_INT)
01453   low &= ~((HOST_WIDE_INT) (-1) << prec);
01454     }
01455 
01456   return (high != 0 ? HOST_BITS_PER_WIDE_INT + exact_log2 (high)
01457     : exact_log2 (low));
01458 }
01459 
01460 /* Similar, but return the largest integer Y such that 2 ** Y is less
01461    than or equal to EXPR.  */
01462 
01463 int
01464 tree_floor_log2 (tree expr)
01465 {
01466   int prec;
01467   HOST_WIDE_INT high, low;
01468 
01469   STRIP_NOPS (expr);
01470 
01471   if (TREE_CODE (expr) == COMPLEX_CST)
01472     return tree_log2 (TREE_REALPART (expr));
01473 
01474   prec = (POINTER_TYPE_P (TREE_TYPE (expr))
01475     ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr)));
01476 
01477   high = TREE_INT_CST_HIGH (expr);
01478   low = TREE_INT_CST_LOW (expr);
01479 
01480   /* First clear all bits that are beyond the type's precision in case
01481      we've been sign extended.  Ignore if type's precision hasn't been set
01482      since what we are doing is setting it.  */
01483 
01484   if (prec == 2 * HOST_BITS_PER_WIDE_INT || prec == 0)
01485     ;
01486   else if (prec > HOST_BITS_PER_WIDE_INT)
01487     high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
01488   else
01489     {
01490       high = 0;
01491       if (prec < HOST_BITS_PER_WIDE_INT)
01492   low &= ~((HOST_WIDE_INT) (-1) << prec);
01493     }
01494 
01495   return (high != 0 ? HOST_BITS_PER_WIDE_INT + floor_log2 (high)
01496     : floor_log2 (low));
01497 }
01498 
01499 /* Return 1 if EXPR is the real constant zero.  */
01500 
01501 int
01502 real_zerop (tree expr)
01503 {
01504   STRIP_NOPS (expr);
01505 
01506   return ((TREE_CODE (expr) == REAL_CST
01507      && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst0))
01508     || (TREE_CODE (expr) == COMPLEX_CST
01509         && real_zerop (TREE_REALPART (expr))
01510         && real_zerop (TREE_IMAGPART (expr))));
01511 }
01512 
01513 /* Return 1 if EXPR is the real constant one in real or complex form.  */
01514 
01515 int
01516 real_onep (tree expr)
01517 {
01518   STRIP_NOPS (expr);
01519 
01520   return ((TREE_CODE (expr) == REAL_CST
01521      && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst1))
01522     || (TREE_CODE (expr) == COMPLEX_CST
01523         && real_onep (TREE_REALPART (expr))
01524         && real_zerop (TREE_IMAGPART (expr))));
01525 }
01526 
01527 /* Return 1 if EXPR is the real constant two.  */
01528 
01529 int
01530 real_twop (tree expr)
01531 {
01532   STRIP_NOPS (expr);
01533 
01534   return ((TREE_CODE (expr) == REAL_CST
01535      && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst2))
01536     || (TREE_CODE (expr) == COMPLEX_CST
01537         && real_twop (TREE_REALPART (expr))
01538         && real_zerop (TREE_IMAGPART (expr))));
01539 }
01540 
01541 /* Return 1 if EXPR is the real constant minus one.  */
01542 
01543 int
01544 real_minus_onep (tree expr)
01545 {
01546   STRIP_NOPS (expr);
01547 
01548   return ((TREE_CODE (expr) == REAL_CST
01549      && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconstm1))
01550     || (TREE_CODE (expr) == COMPLEX_CST
01551         && real_minus_onep (TREE_REALPART (expr))
01552         && real_zerop (TREE_IMAGPART (expr))));
01553 }
01554 
01555 /* Nonzero if EXP is a constant or a cast of a constant.  */
01556 
01557 int
01558 really_constant_p (tree exp)
01559 {
01560   /* This is not quite the same as STRIP_NOPS.  It does more.  */
01561   while (TREE_CODE (exp) == NOP_EXPR
01562    || TREE_CODE (exp) == CONVERT_EXPR
01563    || TREE_CODE (exp) == NON_LVALUE_EXPR)
01564     exp = TREE_OPERAND (exp, 0);
01565   return TREE_CONSTANT (exp);
01566 }
01567 
01568 /* Return first list element whose TREE_VALUE is ELEM.
01569    Return 0 if ELEM is not in LIST.  */
01570 
01571 tree
01572 value_member (tree elem, tree list)
01573 {
01574   while (list)
01575     {
01576       if (elem == TREE_VALUE (list))
01577   return list;
01578       list = TREE_CHAIN (list);
01579     }
01580   return NULL_TREE;
01581 }
01582 
01583 /* Return first list element whose TREE_PURPOSE is ELEM.
01584    Return 0 if ELEM is not in LIST.  */
01585 
01586 tree
01587 purpose_member (tree elem, tree list)
01588 {
01589   while (list)
01590     {
01591       if (elem == TREE_PURPOSE (list))
01592   return list;
01593       list = TREE_CHAIN (list);
01594     }
01595   return NULL_TREE;
01596 }
01597 
01598 /* Return nonzero if ELEM is part of the chain CHAIN.  */
01599 
01600 int
01601 chain_member (tree elem, tree chain)
01602 {
01603   while (chain)
01604     {
01605       if (elem == chain)
01606   return 1;
01607       chain = TREE_CHAIN (chain);
01608     }
01609 
01610   return 0;
01611 }
01612 
01613 /* Return the length of a chain of nodes chained through TREE_CHAIN.
01614    We expect a null pointer to mark the end of the chain.
01615    This is the Lisp primitive `length'.  */
01616 
01617 int
01618 list_length (tree t)
01619 {
01620   tree p = t;
01621 #ifdef ENABLE_TREE_CHECKING
01622   tree q = t;
01623 #endif
01624   int len = 0;
01625 
01626   while (p)
01627     {
01628       p = TREE_CHAIN (p);
01629 #ifdef ENABLE_TREE_CHECKING
01630       if (len % 2)
01631   q = TREE_CHAIN (q);
01632       gcc_assert (p != q);
01633 #endif
01634       len++;
01635     }
01636 
01637   return len;
01638 }
01639 
01640 /* Returns the number of FIELD_DECLs in TYPE.  */
01641 
01642 int
01643 fields_length (tree type)
01644 {
01645   tree t = TYPE_FIELDS (type);
01646   int count = 0;
01647 
01648   for (; t; t = TREE_CHAIN (t))
01649     if (TREE_CODE (t) == FIELD_DECL)
01650       ++count;
01651 
01652   return count;
01653 }
01654 
01655 /* Concatenate two chains of nodes (chained through TREE_CHAIN)
01656    by modifying the last node in chain 1 to point to chain 2.
01657    This is the Lisp primitive `nconc'.  */
01658 
01659 tree
01660 chainon (tree op1, tree op2)
01661 {
01662   tree t1;
01663 
01664   if (!op1)
01665     return op2;
01666   if (!op2)
01667     return op1;
01668 
01669   for (t1 = op1; TREE_CHAIN (t1); t1 = TREE_CHAIN (t1))
01670     continue;
01671   TREE_CHAIN (t1) = op2;
01672 
01673 #ifdef ENABLE_TREE_CHECKING
01674   {
01675     tree t2;
01676     for (t2 = op2; t2; t2 = TREE_CHAIN (t2))
01677       gcc_assert (t2 != t1);
01678   }
01679 #endif
01680 
01681   return op1;
01682 }
01683 
01684 /* Return the last node in a chain of nodes (chained through TREE_CHAIN).  */
01685 
01686 tree
01687 tree_last (tree chain)
01688 {
01689   tree next;
01690   if (chain)
01691     while ((next = TREE_CHAIN (chain)))
01692       chain = next;
01693   return chain;
01694 }
01695 
01696 /* Reverse the order of elements in the chain T,
01697    and return the new head of the chain (old last element).  */
01698 
01699 tree
01700 nreverse (tree t)
01701 {
01702   tree prev = 0, decl, next;
01703   for (decl = t; decl; decl = next)
01704     {
01705       next = TREE_CHAIN (decl);
01706       TREE_CHAIN (decl) = prev;
01707       prev = decl;
01708     }
01709   return prev;
01710 }
01711 
01712 /* Return a newly created TREE_LIST node whose
01713    purpose and value fields are PARM and VALUE.  */
01714 
01715 tree
01716 build_tree_list_stat (tree parm, tree value MEM_STAT_DECL)
01717 {
01718   tree t = make_node_stat (TREE_LIST PASS_MEM_STAT);
01719   TREE_PURPOSE (t) = parm;
01720   TREE_VALUE (t) = value;
01721   return t;
01722 }
01723 
01724 /* Return a newly created TREE_LIST node whose
01725    purpose and value fields are PURPOSE and VALUE
01726    and whose TREE_CHAIN is CHAIN.  */
01727 
01728 tree
01729 tree_cons_stat (tree purpose, tree value, tree chain MEM_STAT_DECL)
01730 {
01731   tree node;
01732 
01733   node = ggc_alloc_zone_pass_stat (sizeof (struct tree_list), &tree_zone);
01734 
01735   memset (node, 0, sizeof (struct tree_common));
01736 
01737 #ifdef GATHER_STATISTICS
01738   tree_node_counts[(int) x_kind]++;
01739   tree_node_sizes[(int) x_kind] += sizeof (struct tree_list);
01740 #endif
01741 
01742   TREE_SET_CODE (node, TREE_LIST);
01743   TREE_CHAIN (node) = chain;
01744   TREE_PURPOSE (node) = purpose;
01745   TREE_VALUE (node) = value;
01746   return node;
01747 }
01748 
01749 
01750 /* Return the size nominally occupied by an object of type TYPE
01751    when it resides in memory.  The value is measured in units of bytes,
01752    and its data type is that normally used for type sizes
01753    (which is the first type created by make_signed_type or
01754    make_unsigned_type).  */
01755 
01756 tree
01757 size_in_bytes (tree type)
01758 {
01759   tree t;
01760 
01761   if (type == error_mark_node)
01762     return integer_zero_node;
01763 
01764   type = TYPE_MAIN_VARIANT (type);
01765   t = TYPE_SIZE_UNIT (type);
01766 
01767   if (t == 0)
01768     {
01769       lang_hooks.types.incomplete_type_error (NULL_TREE, type);
01770       return size_zero_node;
01771     }
01772 
01773   if (TREE_CODE (t) == INTEGER_CST)
01774     t = force_fit_type (t, 0, false, false);
01775 
01776   return t;
01777 }
01778 
01779 /* Return the size of TYPE (in bytes) as a wide integer
01780    or return -1 if the size can vary or is larger than an integer.  */
01781 
01782 HOST_WIDE_INT
01783 int_size_in_bytes (tree type)
01784 {
01785   tree t;
01786 
01787   if (type == error_mark_node)
01788     return 0;
01789 
01790   type = TYPE_MAIN_VARIANT (type);
01791   t = TYPE_SIZE_UNIT (type);
01792   if (t == 0
01793       || TREE_CODE (t) != INTEGER_CST
01794       || TREE_INT_CST_HIGH (t) != 0
01795       /* If the result would appear negative, it's too big to represent.  */
01796       || (HOST_WIDE_INT) TREE_INT_CST_LOW (t) < 0)
01797     return -1;
01798 
01799   return TREE_INT_CST_LOW (t);
01800 }
01801 
01802 /* Return the maximum size of TYPE (in bytes) as a wide integer
01803    or return -1 if the size can vary or is larger than an integer.  */
01804 
01805 HOST_WIDE_INT
01806 max_int_size_in_bytes (tree type)
01807 {
01808   HOST_WIDE_INT size = -1;
01809   tree size_tree;
01810 
01811   /* If this is an array type, check for a possible MAX_SIZE attached.  */
01812 
01813   if (TREE_CODE (type) == ARRAY_TYPE)
01814     {
01815       size_tree = TYPE_ARRAY_MAX_SIZE (type);
01816 
01817       if (size_tree && host_integerp (size_tree, 1))
01818   size = tree_low_cst (size_tree, 1);
01819     }
01820 
01821   /* If we still haven't been able to get a size, see if the language
01822      can compute a maximum size.  */
01823 
01824   if (size == -1)
01825     {
01826       size_tree = lang_hooks.types.max_size (type);
01827 
01828       if (size_tree && host_integerp (size_tree, 1))
01829   size = tree_low_cst (size_tree, 1);
01830     }
01831 
01832   return size;
01833 }
01834 
01835 /* Return the bit position of FIELD, in bits from the start of the record.
01836    This is a tree of type bitsizetype.  */
01837 
01838 tree
01839 bit_position (tree field)
01840 {
01841   return bit_from_pos (DECL_FIELD_OFFSET (field),
01842            DECL_FIELD_BIT_OFFSET (field));
01843 }
01844 
01845 /* Likewise, but return as an integer.  It must be representable in
01846    that way (since it could be a signed value, we don't have the
01847    option of returning -1 like int_size_in_byte can.  */
01848 
01849 HOST_WIDE_INT
01850 int_bit_position (tree field)
01851 {
01852   return tree_low_cst (bit_position (field), 0);
01853 }
01854 
01855 /* Return the byte position of FIELD, in bytes from the start of the record.
01856    This is a tree of type sizetype.  */
01857 
01858 tree
01859 byte_position (tree field)
01860 {
01861   return byte_from_pos (DECL_FIELD_OFFSET (field),
01862       DECL_FIELD_BIT_OFFSET (field));
01863 }
01864 
01865 /* Likewise, but return as an integer.  It must be representable in
01866    that way (since it could be a signed value, we don't have the
01867    option of returning -1 like int_size_in_byte can.  */
01868 
01869 HOST_WIDE_INT
01870 int_byte_position (tree field)
01871 {
01872   return tree_low_cst (byte_position (field), 0);
01873 }
01874 
01875 /* Return the strictest alignment, in bits, that T is known to have.  */
01876 
01877 unsigned int
01878 expr_align (tree t)
01879 {
01880   unsigned int align0, align1;
01881 
01882   switch (TREE_CODE (t))
01883     {
01884     case NOP_EXPR:  case CONVERT_EXPR:  case NON_LVALUE_EXPR:
01885       /* If we have conversions, we know that the alignment of the
01886    object must meet each of the alignments of the types.  */
01887       align0 = expr_align (TREE_OPERAND (t, 0));
01888       align1 = TYPE_ALIGN (TREE_TYPE (t));
01889       return MAX (align0, align1);
01890 
01891     case SAVE_EXPR:         case COMPOUND_EXPR:       case MODIFY_EXPR:
01892     case INIT_EXPR:         case TARGET_EXPR:         case WITH_CLEANUP_EXPR:
01893     case CLEANUP_POINT_EXPR:
01894       /* These don't change the alignment of an object.  */
01895       return expr_align (TREE_OPERAND (t, 0));
01896 
01897     case COND_EXPR:
01898       /* The best we can do is say that the alignment is the least aligned
01899    of the two arms.  */
01900       align0 = expr_align (TREE_OPERAND (t, 1));
01901       align1 = expr_align (TREE_OPERAND (t, 2));
01902       return MIN (align0, align1);
01903 
01904     case LABEL_DECL:     case CONST_DECL:
01905     case VAR_DECL:       case PARM_DECL:   case RESULT_DECL:
01906       if (DECL_ALIGN (t) != 0)
01907   return DECL_ALIGN (t);
01908       break;
01909 
01910     case FUNCTION_DECL:
01911       return FUNCTION_BOUNDARY;
01912 
01913     default:
01914       break;
01915     }
01916 
01917   /* Otherwise take the alignment from that of the type.  */
01918   return TYPE_ALIGN (TREE_TYPE (t));
01919 }
01920 
01921 /* Return, as a tree node, the number of elements for TYPE (which is an
01922    ARRAY_TYPE) minus one. This counts only elements of the top array.  */
01923 
01924 tree
01925 array_type_nelts (tree type)
01926 {
01927   tree index_type, min, max;
01928 
01929   /* If they did it with unspecified bounds, then we should have already
01930      given an error about it before we got here.  */
01931   if (! TYPE_DOMAIN (type))
01932     return error_mark_node;
01933 
01934   index_type = TYPE_DOMAIN (type);
01935   min = TYPE_MIN_VALUE (index_type);
01936   max = TYPE_MAX_VALUE (index_type);
01937 
01938   return (integer_zerop (min)
01939     ? max
01940     : fold_build2 (MINUS_EXPR, TREE_TYPE (max), max, min));
01941 }
01942 
01943 /* If arg is static -- a reference to an object in static storage -- then
01944    return the object.  This is not the same as the C meaning of `static'.
01945    If arg isn't static, return NULL.  */
01946 
01947 tree
01948 staticp (tree arg)
01949 {
01950   switch (TREE_CODE (arg))
01951     {
01952     case FUNCTION_DECL:
01953       /* Nested functions are static, even though taking their address will
01954    involve a trampoline as we unnest the nested function and create
01955    the trampoline on the tree level.  */
01956       return arg;
01957 
01958     case VAR_DECL:
01959       return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
01960         && ! DECL_THREAD_LOCAL_P (arg)
01961         && ! DECL_DLLIMPORT_P (arg)
01962         ? arg : NULL);
01963 
01964     case CONST_DECL:
01965       return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
01966         ? arg : NULL);
01967 
01968     case CONSTRUCTOR:
01969       return TREE_STATIC (arg) ? arg : NULL;
01970 
01971     case LABEL_DECL:
01972     case STRING_CST:
01973       return arg;
01974 
01975     case COMPONENT_REF:
01976       /* If the thing being referenced is not a field, then it is
01977    something language specific.  */
01978       if (TREE_CODE (TREE_OPERAND (arg, 1)) != FIELD_DECL)
01979   return (*lang_hooks.staticp) (arg);
01980 
01981       /* If we are referencing a bitfield, we can't evaluate an
01982    ADDR_EXPR at compile time and so it isn't a constant.  */
01983       if (DECL_BIT_FIELD (TREE_OPERAND (arg, 1)))
01984   return NULL;
01985 
01986       return staticp (TREE_OPERAND (arg, 0));
01987 
01988     case BIT_FIELD_REF:
01989       return NULL;
01990 
01991     case MISALIGNED_INDIRECT_REF:
01992     case ALIGN_INDIRECT_REF:
01993     case INDIRECT_REF:
01994       return TREE_CONSTANT (TREE_OPERAND (arg, 0)) ? arg : NULL;
01995 
01996     case ARRAY_REF:
01997     case ARRAY_RANGE_REF:
01998       if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST
01999     && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST)
02000   return staticp (TREE_OPERAND (arg, 0));
02001       else
02002   return false;
02003 
02004     default:
02005       if ((unsigned int) TREE_CODE (arg)
02006     >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
02007   return lang_hooks.staticp (arg);
02008       else
02009   return NULL;
02010     }
02011 }
02012 
02013 /* Wrap a SAVE_EXPR around EXPR, if appropriate.
02014    Do this to any expression which may be used in more than one place,
02015    but must be evaluated only once.
02016 
02017    Normally, expand_expr would reevaluate the expression each time.
02018    Calling save_expr produces something that is evaluated and recorded
02019    the first time expand_expr is called on it.  Subsequent calls to
02020    expand_expr just reuse the recorded value.
02021 
02022    The call to expand_expr that generates code that actually computes
02023    the value is the first call *at compile time*.  Subsequent calls
02024    *at compile time* generate code to use the saved value.
02025    This produces correct result provided that *at run time* control
02026    always flows through the insns made by the first expand_expr
02027    before reaching the other places where the save_expr was evaluated.
02028    You, the caller of save_expr, must make sure this is so.
02029 
02030    Constants, and certain read-only nodes, are returned with no
02031    SAVE_EXPR because that is safe.  Expressions containing placeholders
02032    are not touched; see tree.def for an explanation of what these
02033    are used for.  */
02034 
02035 tree
02036 save_expr (tree expr)
02037 {
02038   tree t = fold (expr);
02039   tree inner;
02040 
02041   /* If the tree evaluates to a constant, then we don't want to hide that
02042      fact (i.e. this allows further folding, and direct checks for constants).
02043      However, a read-only object that has side effects cannot be bypassed.
02044      Since it is no problem to reevaluate literals, we just return the
02045      literal node.  */
02046   inner = skip_simple_arithmetic (t);
02047 
02048   if (TREE_INVARIANT (inner)
02049       || (TREE_READONLY (inner) && ! TREE_SIDE_EFFECTS (inner))
02050       || TREE_CODE (inner) == SAVE_EXPR
02051       || TREE_CODE (inner) == ERROR_MARK)
02052     return t;
02053 
02054   /* If INNER contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
02055      it means that the size or offset of some field of an object depends on
02056      the value within another field.
02057 
02058      Note that it must not be the case that T contains both a PLACEHOLDER_EXPR
02059      and some variable since it would then need to be both evaluated once and
02060      evaluated more than once.  Front-ends must assure this case cannot
02061      happen by surrounding any such subexpressions in their own SAVE_EXPR
02062      and forcing evaluation at the proper time.  */
02063   if (contains_placeholder_p (inner))
02064     return t;
02065 
02066   t = build1 (SAVE_EXPR, TREE_TYPE (expr), t);
02067 
02068   /* This expression might be placed ahead of a jump to ensure that the
02069      value was computed on both sides of the jump.  So make sure it isn't
02070      eliminated as dead.  */
02071   TREE_SIDE_EFFECTS (t) = 1;
02072   TREE_INVARIANT (t) = 1;
02073   return t;
02074 }
02075 
02076 /* Look inside EXPR and into any simple arithmetic operations.  Return
02077    the innermost non-arithmetic node.  */
02078 
02079 tree
02080 skip_simple_arithmetic (tree expr)
02081 {
02082   tree inner;
02083 
02084   /* We don't care about whether this can be used as an lvalue in this
02085      context.  */
02086   while (TREE_CODE (expr) == NON_LVALUE_EXPR)
02087     expr = TREE_OPERAND (expr, 0);
02088 
02089   /* If we have simple operations applied to a SAVE_EXPR or to a SAVE_EXPR and
02090      a constant, it will be more efficient to not make another SAVE_EXPR since
02091      it will allow better simplification and GCSE will be able to merge the
02092      computations if they actually occur.  */
02093   inner = expr;
02094   while (1)
02095     {
02096       if (UNARY_CLASS_P (inner))
02097   inner = TREE_OPERAND (inner, 0);
02098       else if (BINARY_CLASS_P (inner))
02099   {
02100     if (TREE_INVARIANT (TREE_OPERAND (inner, 1)))
02101       inner = TREE_OPERAND (inner, 0);
02102     else if (TREE_INVARIANT (TREE_OPERAND (inner, 0)))
02103       inner = TREE_OPERAND (inner, 1);
02104     else
02105       break;
02106   }
02107       else
02108   break;
02109     }
02110 
02111   return inner;
02112 }
02113 
02114 /* Return which tree structure is used by T.  */
02115 
02116 enum tree_node_structure_enum
02117 tree_node_structure (tree t)
02118 {
02119   enum tree_code code = TREE_CODE (t);
02120 
02121   switch (TREE_CODE_CLASS (code))
02122     {      
02123     case tcc_declaration:
02124       {
02125   switch (code)
02126     {
02127     case FIELD_DECL:
02128       return TS_FIELD_DECL;
02129     case PARM_DECL:
02130       return TS_PARM_DECL;
02131     case VAR_DECL:
02132       return TS_VAR_DECL;
02133     case LABEL_DECL:
02134       return TS_LABEL_DECL;
02135     case RESULT_DECL:
02136       return TS_RESULT_DECL;
02137     case CONST_DECL:
02138       return TS_CONST_DECL;
02139     case TYPE_DECL:
02140       return TS_TYPE_DECL;
02141     case FUNCTION_DECL:
02142       return TS_FUNCTION_DECL;
02143     case SYMBOL_MEMORY_TAG:
02144     case NAME_MEMORY_TAG:
02145     case STRUCT_FIELD_TAG:
02146       return TS_MEMORY_TAG;
02147     default:
02148       return TS_DECL_NON_COMMON;
02149     }
02150       }
02151     case tcc_type:
02152       return TS_TYPE;
02153     case tcc_reference:
02154     case tcc_comparison:
02155     case tcc_unary:
02156     case tcc_binary:
02157     case tcc_expression:
02158     case tcc_statement:
02159       return TS_EXP;
02160     default:  /* tcc_constant and tcc_exceptional */
02161       break;
02162     }
02163   switch (code)
02164     {
02165       /* tcc_constant cases.  */
02166     case INTEGER_CST:   return TS_INT_CST;
02167     case REAL_CST:    return TS_REAL_CST;
02168     case COMPLEX_CST:   return TS_COMPLEX;
02169     case VECTOR_CST:    return TS_VECTOR;
02170     case STRING_CST:    return TS_STRING;
02171       /* tcc_exceptional cases.  */
02172     case ERROR_MARK:    return TS_COMMON;
02173     case IDENTIFIER_NODE: return TS_IDENTIFIER;
02174     case TREE_LIST:   return TS_LIST;
02175     case TREE_VEC:    return TS_VEC;
02176     case PHI_NODE:    return TS_PHI_NODE;
02177     case SSA_NAME:    return TS_SSA_NAME;
02178     case PLACEHOLDER_EXPR:  return TS_COMMON;
02179     case STATEMENT_LIST:  return TS_STATEMENT_LIST;
02180     case BLOCK:     return TS_BLOCK;
02181     case CONSTRUCTOR:   return TS_CONSTRUCTOR;
02182     case TREE_BINFO:    return TS_BINFO;
02183     case VALUE_HANDLE:    return TS_VALUE_HANDLE;
02184     case OMP_CLAUSE:    return TS_OMP_CLAUSE;
02185 
02186     default:
02187       gcc_unreachable ();
02188     }
02189 }
02190 
02191 /* Return 1 if EXP contains a PLACEHOLDER_EXPR; i.e., if it represents a size
02192    or offset that depends on a field within a record.  */
02193 
02194 bool
02195 contains_placeholder_p (tree exp)
02196 {
02197   enum tree_code code;
02198 
02199   if (!exp)
02200     return 0;
02201 
02202   code = TREE_CODE (exp);
02203   if (code == PLACEHOLDER_EXPR)
02204     return 1;
02205 
02206   switch (TREE_CODE_CLASS (code))
02207     {
02208     case tcc_reference:
02209       /* Don't look at any PLACEHOLDER_EXPRs that might be in index or bit
02210    position computations since they will be converted into a
02211    WITH_RECORD_EXPR involving the reference, which will assume
02212    here will be valid.  */
02213       return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
02214 
02215     case tcc_exceptional:
02216       if (code == TREE_LIST)
02217   return (CONTAINS_PLACEHOLDER_P (TREE_VALUE (exp))
02218     || CONTAINS_PLACEHOLDER_P (TREE_CHAIN (exp)));
02219       break;
02220 
02221     case tcc_unary:
02222     case tcc_binary:
02223     case tcc_comparison:
02224     case tcc_expression:
02225       switch (code)
02226   {
02227   case COMPOUND_EXPR:
02228     /* Ignoring the first operand isn't quite right, but works best.  */
02229     return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1));
02230 
02231   case COND_EXPR:
02232     return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0))
02233       || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1))
02234       || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 2)));
02235 
02236   case CALL_EXPR:
02237     return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1));
02238 
02239   default:
02240     break;
02241   }
02242 
02243       switch (TREE_CODE_LENGTH (code))
02244   {
02245   case 1:
02246     return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
02247   case 2:
02248     return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0))
02249       || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1)));
02250   default:
02251     return 0;
02252   }
02253 
02254     default:
02255       return 0;
02256     }
02257   return 0;
02258 }
02259 
02260 /* Return true if any part of the computation of TYPE involves a
02261    PLACEHOLDER_EXPR.  This includes size, bounds, qualifiers
02262    (for QUAL_UNION_TYPE) and field positions.  */
02263 
02264 static bool
02265 type_contains_placeholder_1 (tree type)
02266 {
02267   /* If the size contains a placeholder or the parent type (component type in
02268      the case of arrays) type involves a placeholder, this type does.  */
02269   if (CONTAINS_PLACEHOLDER_P (TYPE_SIZE (type))
02270       || CONTAINS_PLACEHOLDER_P (TYPE_SIZE_UNIT (type))
02271       || (TREE_TYPE (type) != 0
02272     && type_contains_placeholder_p (TREE_TYPE (type))))
02273     return true;
02274 
02275   /* Now do type-specific checks.  Note that the last part of the check above
02276      greatly limits what we have to do below.  */
02277   switch (TREE_CODE (type))
02278     {
02279     case VOID_TYPE:
02280     case COMPLEX_TYPE:
02281     case ENUMERAL_TYPE:
02282     case BOOLEAN_TYPE:
02283     case POINTER_TYPE:
02284     case OFFSET_TYPE:
02285     case REFERENCE_TYPE:
02286     case METHOD_TYPE:
02287     case FUNCTION_TYPE:
02288     case VECTOR_TYPE:
02289       return false;
02290 
02291     case INTEGER_TYPE:
02292     case REAL_TYPE:
02293       /* Here we just check the bounds.  */
02294       return (CONTAINS_PLACEHOLDER_P (TYPE_MIN_VALUE (type))
02295         || CONTAINS_PLACEHOLDER_P (TYPE_MAX_VALUE (type)));
02296 
02297     case ARRAY_TYPE:
02298       /* We're already checked the component type (TREE_TYPE), so just check
02299    the index type.  */
02300       return type_contains_placeholder_p (TYPE_DOMAIN (type));
02301 
02302     case RECORD_TYPE:
02303     case UNION_TYPE:
02304     case QUAL_UNION_TYPE:
02305       {
02306   tree field;
02307 
02308   for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
02309     if (TREE_CODE (field) == FIELD_DECL
02310         && (CONTAINS_PLACEHOLDER_P (DECL_FIELD_OFFSET (field))
02311       || (TREE_CODE (type) == QUAL_UNION_TYPE
02312           && CONTAINS_PLACEHOLDER_P (DECL_QUALIFIER (field)))
02313       || type_contains_placeholder_p (TREE_TYPE (field))))
02314       return true;
02315 
02316   return false;
02317       }
02318 
02319     default:
02320       gcc_unreachable ();
02321     }
02322 }
02323 
02324 bool
02325 type_contains_placeholder_p (tree type)
02326 {
02327   bool result;
02328 
02329   /* If the contains_placeholder_bits field has been initialized,
02330      then we know the answer.  */
02331   if (TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) > 0)
02332     return TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) - 1;
02333 
02334   /* Indicate that we've seen this type node, and the answer is false.
02335      This is what we want to return if we run into recursion via fields.  */
02336   TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = 1;
02337 
02338   /* Compute the real value.  */
02339   result = type_contains_placeholder_1 (type);
02340 
02341   /* Store the real value.  */
02342   TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = result + 1;
02343 
02344   return result;
02345 }
02346 
02347 /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
02348    return a tree with all occurrences of references to F in a
02349    PLACEHOLDER_EXPR replaced by R.   Note that we assume here that EXP
02350    contains only arithmetic expressions or a CALL_EXPR with a
02351    PLACEHOLDER_EXPR occurring only in its arglist.  */
02352 
02353 tree
02354 substitute_in_expr (tree exp, tree f, tree r)
02355 {
02356   enum tree_code code = TREE_CODE (exp);
02357   tree op0, op1, op2, op3;
02358   tree new;
02359   tree inner;
02360 
02361   /* We handle TREE_LIST and COMPONENT_REF separately.  */
02362   if (code == TREE_LIST)
02363     {
02364       op0 = SUBSTITUTE_IN_EXPR (TREE_CHAIN (exp), f, r);
02365       op1 = SUBSTITUTE_IN_EXPR (TREE_VALUE (exp), f, r);
02366       if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
02367   return exp;
02368 
02369       return tree_cons (TREE_PURPOSE (exp), op1, op0);
02370     }
02371   else if (code == COMPONENT_REF)
02372    {
02373      /* If this expression is getting a value from a PLACEHOLDER_EXPR
02374   and it is the right field, replace it with R.  */
02375      for (inner = TREE_OPERAND (exp, 0);
02376     REFERENCE_CLASS_P (inner);
02377     inner = TREE_OPERAND (inner, 0))
02378        ;
02379      if (TREE_CODE (inner) == PLACEHOLDER_EXPR
02380    && TREE_OPERAND (exp, 1) == f)
02381        return r;
02382 
02383      /* If this expression hasn't been completed let, leave it alone.  */
02384      if (TREE_CODE (inner) == PLACEHOLDER_EXPR && TREE_TYPE (inner) == 0)
02385        return exp;
02386 
02387      op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
02388      if (op0 == TREE_OPERAND (exp, 0))
02389        return exp;
02390 
02391      new = fold_build3 (COMPONENT_REF, TREE_TYPE (exp),
02392       op0, TREE_OPERAND (exp, 1), NULL_TREE);
02393    }
02394   else
02395     switch (TREE_CODE_CLASS (code))
02396       {
02397       case tcc_constant:
02398       case tcc_declaration:
02399   return exp;
02400 
02401       case tcc_exceptional:
02402       case tcc_unary:
02403       case tcc_binary:
02404       case tcc_comparison:
02405       case tcc_expression:
02406       case tcc_reference:
02407   switch (TREE_CODE_LENGTH (code))
02408     {
02409     case 0:
02410       return exp;
02411 
02412     case 1:
02413       op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
02414       if (op0 == TREE_OPERAND (exp, 0))
02415         return exp;
02416 
02417       new = fold_build1 (code, TREE_TYPE (exp), op0);
02418       break;
02419 
02420     case 2:
02421       op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
02422       op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
02423 
02424       if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
02425         return exp;
02426 
02427       new = fold_build2 (code, TREE_TYPE (exp), op0, op1);
02428       break;
02429 
02430     case 3:
02431       op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
02432       op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
02433       op2 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 2), f, r);
02434 
02435       if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
02436     && op2 == TREE_OPERAND (exp, 2))
02437         return exp;
02438 
02439       new = fold_build3 (code, TREE_TYPE (exp), op0, op1, op2);
02440       break;
02441 
02442     case 4:
02443       op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
02444       op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
02445       op2 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 2), f, r);
02446       op3 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 3), f, r);
02447 
02448       if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
02449     && op2 == TREE_OPERAND (exp, 2)
02450     && op3 == TREE_OPERAND (exp, 3))
02451         return exp;
02452 
02453       new = fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3));
02454       break;
02455 
02456     default:
02457       gcc_unreachable ();
02458     }
02459   break;
02460 
02461       default:
02462   gcc_unreachable ();
02463       }
02464 
02465   TREE_READONLY (new) = TREE_READONLY (exp);
02466   return new;
02467 }
02468 
02469 /* Similar, but look for a PLACEHOLDER_EXPR in EXP and find a replacement
02470    for it within OBJ, a tree that is an object or a chain of references.  */
02471 
02472 tree
02473 substitute_placeholder_in_expr (tree exp, tree obj)
02474 {
02475   enum tree_code code = TREE_CODE (exp);
02476   tree op0, op1, op2, op3;
02477 
02478   /* If this is a PLACEHOLDER_EXPR, see if we find a corresponding type
02479      in the chain of OBJ.  */
02480   if (code == PLACEHOLDER_EXPR)
02481     {
02482       tree need_type = TYPE_MAIN_VARIANT (TREE_TYPE (exp));
02483       tree elt;
02484 
02485       for (elt = obj; elt != 0;
02486      elt = ((TREE_CODE (elt) == COMPOUND_EXPR
02487        || TREE_CODE (elt) == COND_EXPR)
02488       ? TREE_OPERAND (elt, 1)
02489       : (REFERENCE_CLASS_P (elt)
02490          || UNARY_CLASS_P (elt)
02491          || BINARY_CLASS_P (elt)
02492          || EXPRESSION_CLASS_P (elt))
02493       ? TREE_OPERAND (elt, 0) : 0))
02494   if (TYPE_MAIN_VARIANT (TREE_TYPE (elt)) == need_type)
02495     return elt;
02496 
02497       for (elt = obj; elt != 0;
02498      elt = ((TREE_CODE (elt) == COMPOUND_EXPR
02499        || TREE_CODE (elt) == COND_EXPR)
02500       ? TREE_OPERAND (elt, 1)
02501       : (REFERENCE_CLASS_P (elt)
02502          || UNARY_CLASS_P (elt)
02503          || BINARY_CLASS_P (elt)
02504          || EXPRESSION_CLASS_P (elt))
02505       ? TREE_OPERAND (elt, 0) : 0))
02506   if (POINTER_TYPE_P (TREE_TYPE (elt))
02507       && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (elt)))
02508     == need_type))
02509     return fold_build1 (INDIRECT_REF, need_type, elt);
02510 
02511       /* If we didn't find it, return the original PLACEHOLDER_EXPR.  If it
02512    survives until RTL generation, there will be an error.  */
02513       return exp;
02514     }
02515 
02516   /* TREE_LIST is special because we need to look at TREE_VALUE
02517      and TREE_CHAIN, not TREE_OPERANDS.  */
02518   else if (code == TREE_LIST)
02519     {
02520       op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp), obj);
02521       op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp), obj);
02522       if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
02523   return exp;
02524 
02525       return tree_cons (TREE_PURPOSE (exp), op1, op0);
02526     }
02527   else
02528     switch (TREE_CODE_CLASS (code))
02529       {
02530       case tcc_constant:
02531       case tcc_declaration:
02532   return exp;
02533 
02534       case tcc_exceptional:
02535       case tcc_unary:
02536       case tcc_binary:
02537       case tcc_comparison:
02538       case tcc_expression:
02539       case tcc_reference:
02540       case tcc_statement:
02541   switch (TREE_CODE_LENGTH (code))
02542     {
02543     case 0:
02544       return exp;
02545 
02546     case 1:
02547       op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
02548       if (op0 == TREE_OPERAND (exp, 0))
02549         return exp;
02550       else
02551         return fold_build1 (code, TREE_TYPE (exp), op0);
02552 
02553     case 2:
02554       op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
02555       op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
02556 
02557       if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
02558         return exp;
02559       else
02560         return fold_build2 (code, TREE_TYPE (exp), op0, op1);
02561 
02562     case 3:
02563       op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
02564       op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
02565       op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj);
02566 
02567       if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
02568     && op2 == TREE_OPERAND (exp, 2))
02569         return exp;
02570       else
02571         return fold_build3 (code, TREE_TYPE (exp), op0, op1, op2);
02572 
02573     case 4:
02574       op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
02575       op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
02576       op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj);
02577       op3 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 3), obj);
02578 
02579       if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
02580     && op2 == TREE_OPERAND (exp, 2)
02581     && op3 == TREE_OPERAND (exp, 3))
02582         return exp;
02583       else
02584         return fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3));
02585 
02586     default:
02587       gcc_unreachable ();
02588     }
02589   break;
02590 
02591       default:
02592   gcc_unreachable ();
02593       }
02594 }
02595 
02596 /* Stabilize a reference so that we can use it any number of times
02597    without causing its operands to be evaluated more than once.
02598    Returns the stabilized reference.  This works by means of save_expr,
02599    so see the caveats in the comments about save_expr.
02600 
02601    Also allows conversion expressions whose operands are references.
02602    Any other kind of expression is returned unchanged.  */
02603 
02604 tree
02605 stabilize_reference (tree ref)
02606 {
02607   tree result;
02608   enum tree_code code = TREE_CODE (ref);
02609 
02610   switch (code)
02611     {
02612     case VAR_DECL:
02613     case PARM_DECL:
02614     case RESULT_DECL:
02615       /* No action is needed in this case.  */
02616       return ref;
02617 
02618     case NOP_EXPR:
02619     case CONVERT_EXPR:
02620     case FLOAT_EXPR:
02621     case FIX_TRUNC_EXPR:
02622     case FIX_FLOOR_EXPR:
02623     case FIX_ROUND_EXPR:
02624     case FIX_CEIL_EXPR:
02625       result = build_nt (code, stabilize_reference (TREE_OPERAND (ref, 0)));
02626       break;
02627 
02628     case INDIRECT_REF:
02629       result = build_nt (INDIRECT_REF,
02630        stabilize_reference_1 (TREE_OPERAND (ref, 0)));
02631       break;
02632 
02633     case COMPONENT_REF:
02634       result = build_nt (COMPONENT_REF,
02635        stabilize_reference (TREE_OPERAND (ref, 0)),
02636        TREE_OPERAND (ref, 1), NULL_TREE);
02637       break;
02638 
02639     case BIT_FIELD_REF:
02640       result = build_nt (BIT_FIELD_REF,
02641        stabilize_reference (TREE_OPERAND (ref, 0)),
02642        stabilize_reference_1 (TREE_OPERAND (ref, 1)),
02643        stabilize_reference_1 (TREE_OPERAND (ref, 2)));
02644       break;
02645 
02646     case ARRAY_REF:
02647       result = build_nt (ARRAY_REF,
02648        stabilize_reference (TREE_OPERAND (ref, 0)),
02649        stabilize_reference_1 (TREE_OPERAND (ref, 1)),
02650        TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3));
02651       break;
02652 
02653     case ARRAY_RANGE_REF:
02654       result = build_nt (ARRAY_RANGE_REF,
02655        stabilize_reference (TREE_OPERAND (ref, 0)),
02656        stabilize_reference_1 (TREE_OPERAND (ref, 1)),
02657        TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3));
02658       break;
02659 
02660     case COMPOUND_EXPR:
02661       /* We cannot wrap the first expression in a SAVE_EXPR, as then
02662    it wouldn't be ignored.  This matters when dealing with
02663    volatiles.  */
02664       return stabilize_reference_1 (ref);
02665 
02666       /* If arg isn't a kind of lvalue we recognize, make no change.
02667    Caller should recognize the error for an invalid lvalue.  */
02668     default:
02669       return ref;
02670 
02671     case ERROR_MARK:
02672       return error_mark_node;
02673     }
02674 
02675   TREE_TYPE (result) = TREE_TYPE (ref);
02676   TREE_READONLY (result) = TREE_READONLY (ref);
02677   TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (ref);
02678   TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (ref);
02679 
02680   return result;
02681 }
02682 
02683 /* Subroutine of stabilize_reference; this is called for subtrees of
02684    references.  Any expression with side-effects must be put in a SAVE_EXPR
02685    to ensure that it is only evaluated once.
02686 
02687    We don't put SAVE_EXPR nodes around everything, because assigning very
02688    simple expressions to temporaries causes us to miss good opportunities
02689    for optimizations.  Among other things, the opportunity to fold in the
02690    addition of a constant into an addressing mode often gets lost, e.g.
02691    "y[i+1] += x;".  In general, we take the approach that we should not make
02692    an assignment unless we are forced into it - i.e., that any non-side effect
02693    operator should be allowed, and that cse should take care of coalescing
02694    multiple utterances of the same expression should that prove fruitful.  */
02695 
02696 tree
02697 stabilize_reference_1 (tree e)
02698 {
02699   tree result;
02700   enum tree_code code = TREE_CODE (e);
02701 
02702   /* We cannot ignore const expressions because it might be a reference
02703      to a const array but whose index contains side-effects.  But we can
02704      ignore things that are actual constant or that already have been
02705      handled by this function.  */
02706 
02707   if (TREE_INVARIANT (e))
02708     return e;
02709 
02710   switch (TREE_CODE_CLASS (code))
02711     {
02712     case tcc_exceptional:
02713     case tcc_type:
02714     case tcc_declaration:
02715     case tcc_comparison:
02716     case tcc_statement:
02717     case tcc_expression:
02718     case tcc_reference:
02719       /* If the expression has side-effects, then encase it in a SAVE_EXPR
02720    so that it will only be evaluated once.  */
02721       /* The reference (r) and comparison (<) classes could be handled as
02722    below, but it is generally faster to only evaluate them once.  */
02723       if (TREE_SIDE_EFFECTS (e))
02724   return save_expr (e);
02725       return e;
02726 
02727     case tcc_constant:
02728       /* Constants need no processing.  In fact, we should never reach
02729    here.  */
02730       return e;
02731 
02732     case tcc_binary:
02733       /* Division is slow and tends to be compiled with jumps,
02734    especially the division by powers of 2 that is often
02735    found inside of an array reference.  So do it just once.  */
02736       if (code == TRUNC_DIV_EXPR || code == TRUNC_MOD_EXPR
02737     || code == FLOOR_DIV_EXPR || code == FLOOR_MOD_EXPR
02738     || code == CEIL_DIV_EXPR || code == CEIL_MOD_EXPR
02739     || code == ROUND_DIV_EXPR || code == ROUND_MOD_EXPR)
02740   return save_expr (e);
02741       /* Recursively stabilize each operand.  */
02742       result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)),
02743        stabilize_reference_1 (TREE_OPERAND (e, 1)));
02744       break;
02745 
02746     case tcc_unary:
02747       /* Recursively stabilize each operand.  */
02748       result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)));
02749       break;
02750 
02751     default:
02752       gcc_unreachable ();
02753     }
02754 
02755   TREE_TYPE (result) = TREE_TYPE (e);
02756   TREE_READONLY (result) = TREE_READONLY (e);
02757   TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (e);
02758   TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (e);
02759   TREE_INVARIANT (result) = 1;
02760 
02761   return result;
02762 }
02763 
02764 /* Low-level constructors for expressions.  */
02765 
02766 /* A helper function for build1 and constant folders.  Set TREE_CONSTANT,
02767    TREE_INVARIANT, and TREE_SIDE_EFFECTS for an ADDR_EXPR.  */
02768 
02769 void
02770 recompute_tree_invariant_for_addr_expr (tree t)
02771 {
02772   tree node;
02773   bool tc = true, ti = true, se = false;
02774 
02775   /* We started out assuming this address is both invariant and constant, but
02776      does not have side effects.  Now go down any handled components and see if
02777      any of them involve offsets that are either non-constant or non-invariant.
02778      Also check for side-effects.
02779 
02780      ??? Note that this code makes no attempt to deal with the case where
02781      taking the address of something causes a copy due to misalignment.  */
02782 
02783 #define UPDATE_TITCSE(NODE)  \
02784 do { tree _node = (NODE); \
02785      if (_node && !TREE_INVARIANT (_node)) ti = false; \
02786      if (_node && !TREE_CONSTANT (_node)) tc = false; \
02787      if (_node && TREE_SIDE_EFFECTS (_node)) se = true; } while (0)
02788 
02789   for (node = TREE_OPERAND (t, 0); handled_component_p (node);
02790        node = TREE_OPERAND (node, 0))
02791     {
02792       /* If the first operand doesn't have an ARRAY_TYPE, this is a bogus
02793    array reference (probably made temporarily by the G++ front end),
02794    so ignore all the operands.  */
02795       if ((TREE_CODE (node) == ARRAY_REF
02796      || TREE_CODE (node) == ARRAY_RANGE_REF)
02797     && TREE_CODE (TREE_TYPE (TREE_OPERAND (node, 0))) == ARRAY_TYPE)
02798   {
02799     UPDATE_TITCSE (TREE_OPERAND (node, 1));
02800     if (TREE_OPERAND (node, 2))
02801       UPDATE_TITCSE (TREE_OPERAND (node, 2));
02802     if (TREE_OPERAND (node, 3))
02803       UPDATE_TITCSE (TREE_OPERAND (node, 3));
02804   }
02805       /* Likewise, just because this is a COMPONENT_REF doesn't mean we have a
02806    FIELD_DECL, apparently.  The G++ front end can put something else
02807    there, at least temporarily.  */
02808       else if (TREE_CODE (node) == COMPONENT_REF
02809          && TREE_CODE (TREE_OPERAND (node, 1)) == FIELD_DECL)
02810   {
02811     if (TREE_OPERAND (node, 2))
02812       UPDATE_TITCSE (TREE_OPERAND (node, 2));
02813   }
02814       else if (TREE_CODE (node) == BIT_FIELD_REF)
02815   UPDATE_TITCSE (TREE_OPERAND (node, 2));
02816     }
02817 
02818   node = lang_hooks.expr_to_decl (node, &tc, &ti, &se);
02819 
02820   /* Now see what's inside.  If it's an INDIRECT_REF, copy our properties from
02821      the address, since &(*a)->b is a form of addition.  If it's a decl, it's
02822      invariant and constant if the decl is static.  It's also invariant if it's
02823      a decl in the current function.  Taking the address of a volatile variable
02824      is not volatile.  If it's a constant, the address is both invariant and
02825      constant.  Otherwise it's neither.  */
02826   if (TREE_CODE (node) == INDIRECT_REF)
02827     UPDATE_TITCSE (TREE_OPERAND (node, 0));
02828   else if (DECL_P (node))
02829     {
02830       if (staticp (node))
02831   ;
02832       else if (decl_function_context (node) == current_function_decl
02833          /* Addresses of thread-local variables are invariant.  */
02834          || (TREE_CODE (node) == VAR_DECL
02835        && DECL_THREAD_LOCAL_P (node)))
02836   tc = false;
02837       else
02838   ti = tc = false;
02839     }
02840   else if (CONSTANT_CLASS_P (node))
02841     ;
02842   else
02843     {
02844       ti = tc = false;
02845       se |= TREE_SIDE_EFFECTS (node);
02846     }
02847 
02848   TREE_CONSTANT (t) = tc;
02849   TREE_INVARIANT (t) = ti;
02850   TREE_SIDE_EFFECTS (t) = se;
02851 #undef UPDATE_TITCSE
02852 }
02853 
02854 /* Build an expression of code CODE, data type TYPE, and operands as
02855    specified.  Expressions and reference nodes can be created this way.
02856    Constants, decls, types and misc nodes cannot be.
02857 
02858    We define 5 non-variadic functions, from 0 to 4 arguments.  This is
02859    enough for all extant tree codes.  */
02860 
02861 tree
02862 build0_stat (enum tree_code code, tree tt MEM_STAT_DECL)
02863 {
02864   tree t;
02865 
02866   gcc_assert (TREE_CODE_LENGTH (code) == 0);
02867 
02868   t = make_node_stat (code PASS_MEM_STAT);
02869   TREE_TYPE (t) = tt;
02870 
02871   return t;
02872 }
02873 
02874 tree
02875 build1_stat (enum tree_code code, tree type, tree node MEM_STAT_DECL)
02876 {
02877   int length = sizeof (struct tree_exp);
02878 #ifdef GATHER_STATISTICS
02879   tree_node_kind kind;
02880 #endif
02881   tree t;
02882 
02883 #ifdef GATHER_STATISTICS
02884   switch (TREE_CODE_CLASS (code))
02885     {
02886     case tcc_statement:  /* an expression with side effects */
02887       kind = s_kind;
02888       break;
02889     case tcc_reference:  /* a reference */
02890       kind = r_kind;
02891       break;
02892     default:
02893       kind = e_kind;
02894       break;
02895     }
02896 
02897   tree_node_counts[(int) kind]++;
02898   tree_node_sizes[(int) kind] += length;
02899 #endif
02900 
02901   gcc_assert (TREE_CODE_LENGTH (code) == 1);
02902 
02903   t = ggc_alloc_zone_pass_stat (length, &tree_zone);
02904 
02905   memset (t, 0, sizeof (struct tree_common));
02906 
02907   TREE_SET_CODE (t, code);
02908 
02909   TREE_TYPE (t) = type;
02910 #ifdef USE_MAPPED_LOCATION
02911   SET_EXPR_LOCATION (t, UNKNOWN_LOCATION);
02912 #else
02913   SET_EXPR_LOCUS (t, NULL);
02914 #endif
02915   TREE_COMPLEXITY (t) = 0;
02916   TREE_OPERAND (t, 0) = node;
02917   TREE_BLOCK (t) = NULL_TREE;
02918   if (node && !TYPE_P (node))
02919     {
02920       TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (node);
02921       TREE_READONLY (t) = TREE_READONLY (node);
02922     }
02923 
02924   if (TREE_CODE_CLASS (code) == tcc_statement)
02925     TREE_SIDE_EFFECTS (t) = 1;
02926   else switch (code)
02927     {
02928     case VA_ARG_EXPR:
02929       /* All of these have side-effects, no matter what their
02930    operands are.  */
02931       TREE_SIDE_EFFECTS (t) = 1;
02932       TREE_READONLY (t) = 0;
02933       break;
02934 
02935     case MISALIGNED_INDIRECT_REF:
02936     case ALIGN_INDIRECT_REF:
02937     case INDIRECT_REF:
02938       /* Whether a dereference is readonly has nothing to do with whether
02939    its operand is readonly.  */
02940       TREE_READONLY (t) = 0;
02941       break;
02942 
02943     case ADDR_EXPR:
02944       if (node)
02945   recompute_tree_invariant_for_addr_expr (t);
02946       break;
02947 
02948     default:
02949       if ((TREE_CODE_CLASS (code) == tcc_unary || code == VIEW_CONVERT_EXPR)
02950     && node && !TYPE_P (node)
02951     && TREE_CONSTANT (node))
02952   TREE_CONSTANT (t) = 1;
02953       if ((TREE_CODE_CLASS (code) == tcc_unary || code == VIEW_CONVERT_EXPR)
02954     && node && TREE_INVARIANT (node))
02955   TREE_INVARIANT (t) = 1;
02956       if (TREE_CODE_CLASS (code) == tcc_reference
02957     && node && TREE_THIS_VOLATILE (node))
02958   TREE_THIS_VOLATILE (t) = 1;
02959       break;
02960     }
02961 
02962   return t;
02963 }
02964 
02965 #define PROCESS_ARG(N)      \
02966   do {          \
02967     TREE_OPERAND (t, N) = arg##N; \
02968     if (arg##N &&!TYPE_P (arg##N))  \
02969       {         \
02970         if (TREE_SIDE_EFFECTS (arg##N)) \
02971     side_effects = 1;   \
02972         if (!TREE_READONLY (arg##N))  \
02973     read_only = 0;    \
02974         if (!TREE_CONSTANT (arg##N))  \
02975     constant = 0;     \
02976   if (!TREE_INVARIANT (arg##N)) \
02977     invariant = 0;    \
02978       }         \
02979   } while (0)
02980 
02981 tree
02982 build2_stat (enum tree_code code, tree tt, tree arg0, tree arg1 MEM_STAT_DECL)
02983 {
02984   bool constant, read_only, side_effects, invariant;
02985   tree t;
02986 
02987   gcc_assert (TREE_CODE_LENGTH (code) == 2);
02988 
02989   t = make_node_stat (code PASS_MEM_STAT);
02990   TREE_TYPE (t) = tt;
02991 
02992   /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_READONLY for the
02993      result based on those same flags for the arguments.  But if the
02994      arguments aren't really even `tree' expressions, we shouldn't be trying
02995      to do this.  */
02996 
02997   /* Expressions without side effects may be constant if their
02998      arguments are as well.  */
02999   constant = (TREE_CODE_CLASS (code) == tcc_comparison
03000         || TREE_CODE_CLASS (code) == tcc_binary);
03001   read_only = 1;
03002   side_effects = TREE_SIDE_EFFECTS (t);
03003   invariant = constant;
03004 
03005   PROCESS_ARG(0);
03006   PROCESS_ARG(1);
03007 
03008   TREE_READONLY (t) = read_only;
03009   TREE_CONSTANT (t) = constant;
03010   TREE_INVARIANT (t) = invariant;
03011   TREE_SIDE_EFFECTS (t) = side_effects;
03012   TREE_THIS_VOLATILE (t)
03013     = (TREE_CODE_CLASS (code) == tcc_reference
03014        && arg0 && TREE_THIS_VOLATILE (arg0));
03015 
03016   return t;
03017 }
03018 
03019 tree
03020 build3_stat (enum tree_code code, tree tt, tree arg0, tree arg1,
03021        tree arg2 MEM_STAT_DECL)
03022 {
03023   bool constant, read_only, side_effects, invariant;
03024   tree t;
03025 
03026   gcc_assert (TREE_CODE_LENGTH (code) == 3);
03027 
03028   t = make_node_stat (code PASS_MEM_STAT);
03029   TREE_TYPE (t) = tt;
03030 
03031   side_effects = TREE_SIDE_EFFECTS (t);
03032 
03033   PROCESS_ARG(0);
03034   PROCESS_ARG(1);
03035   PROCESS_ARG(2);
03036 
03037   if (code == CALL_EXPR && !side_effects)
03038     {
03039       tree node;
03040       int i;
03041 
03042       /* Calls have side-effects, except those to const or
03043    pure functions.  */
03044       i = call_expr_flags (t);
03045       if (!(i & (ECF_CONST | ECF_PURE)))
03046   side_effects = 1;
03047 
03048       /* And even those have side-effects if their arguments do.  */
03049       else for (node = arg1; node; node = TREE_CHAIN (node))
03050   if (TREE_SIDE_EFFECTS (TREE_VALUE (node)))
03051     {
03052       side_effects = 1;
03053       break;
03054     }
03055     }
03056 
03057   TREE_SIDE_EFFECTS (t) = side_effects;
03058   TREE_THIS_VOLATILE (t)
03059     = (TREE_CODE_CLASS (code) == tcc_reference
03060        && arg0 && TREE_THIS_VOLATILE (arg0));
03061 
03062   return t;
03063 }
03064 
03065 tree
03066 build4_stat (enum tree_code code, tree tt, tree arg0, tree arg1,
03067        tree arg2, tree arg3 MEM_STAT_DECL)
03068 {
03069   bool constant, read_only, side_effects, invariant;
03070   tree t;
03071 
03072   gcc_assert (TREE_CODE_LENGTH (code) == 4);
03073 
03074   t = make_node_stat (code PASS_MEM_STAT);
03075   TREE_TYPE (t) = tt;
03076 
03077   side_effects = TREE_SIDE_EFFECTS (t);
03078 
03079   PROCESS_ARG(0);
03080   PROCESS_ARG(1);
03081   PROCESS_ARG(2);
03082   PROCESS_ARG(3);
03083 
03084   TREE_SIDE_EFFECTS (t) = side_effects;
03085   TREE_THIS_VOLATILE (t)
03086     = (TREE_CODE_CLASS (code) == tcc_reference
03087        && arg0 && TREE_THIS_VOLATILE (arg0));
03088 
03089   return t;
03090 }
03091 
03092 tree
03093 build5_stat (enum tree_code code, tree tt, tree arg0, tree arg1,
03094        tree arg2, tree arg3, tree arg4 MEM_STAT_DECL)
03095 {
03096   bool constant, read_only, side_effects, invariant;
03097   tree t;
03098 
03099   gcc_assert (TREE_CODE_LENGTH (code) == 5);
03100 
03101   t = make_node_stat (code PASS_MEM_STAT);
03102   TREE_TYPE (t) = tt;
03103 
03104   side_effects = TREE_SIDE_EFFECTS (t);
03105 
03106   PROCESS_ARG(0);
03107   PROCESS_ARG(1);
03108   PROCESS_ARG(2);
03109   PROCESS_ARG(3);
03110   PROCESS_ARG(4);
03111 
03112   TREE_SIDE_EFFECTS (t) = side_effects;
03113   TREE_THIS_VOLATILE (t)
03114     = (TREE_CODE_CLASS (code) == tcc_reference
03115        && arg0 && TREE_THIS_VOLATILE (arg0));
03116 
03117   return t;
03118 }
03119 
03120 tree
03121 build7_stat (enum tree_code code, tree tt, tree arg0, tree arg1,
03122        tree arg2, tree arg3, tree arg4, tree arg5,
03123        tree arg6 MEM_STAT_DECL)
03124 {
03125   bool constant, read_only, side_effects, invariant;
03126   tree t;
03127 
03128   gcc_assert (code == TARGET_MEM_REF);
03129 
03130   t = make_node_stat (code PASS_MEM_STAT);
03131   TREE_TYPE (t) = tt;
03132 
03133   side_effects = TREE_SIDE_EFFECTS (t);
03134 
03135   PROCESS_ARG(0);
03136   PROCESS_ARG(1);
03137   PROCESS_ARG(2);
03138   PROCESS_ARG(3);
03139   PROCESS_ARG(4);
03140   PROCESS_ARG(5);
03141   PROCESS_ARG(6);
03142 
03143   TREE_SIDE_EFFECTS (t) = side_effects;
03144   TREE_THIS_VOLATILE (t) = 0;
03145 
03146   return t;
03147 }
03148 
03149 /* Similar except don't specify the TREE_TYPE
03150    and leave the TREE_SIDE_EFFECTS as 0.
03151    It is permissible for arguments to be null,
03152    or even garbage if their values do not matter.  */
03153 
03154 tree
03155 build_nt (enum tree_code code, ...)
03156 {
03157   tree t;
03158   int length;
03159   int i;
03160   va_list p;
03161 
03162   va_start (p, code);
03163 
03164   t = make_node (code);
03165   length = TREE_CODE_LENGTH (code);
03166 
03167   for (i = 0; i < length; i++)
03168     TREE_OPERAND (t, i) = va_arg (p, tree);
03169 
03170   va_end (p);
03171   return t;
03172 }
03173 
03174 /* Create a DECL_... node of code CODE, name NAME and data type TYPE.
03175    We do NOT enter this node in any sort of symbol table.
03176 
03177    layout_decl is used to set up the decl's storage layout.
03178    Other slots are initialized to 0 or null pointers.  */
03179 
03180 tree
03181 build_decl_stat (enum tree_code code, tree name, tree type MEM_STAT_DECL)
03182 {
03183   tree t;
03184 
03185   t = make_node_stat (code PASS_MEM_STAT);
03186 
03187 /*  if (type == error_mark_node)
03188     type = integer_type_node; */
03189 /* That is not done, deliberately, so that having error_mark_node
03190    as the type can suppress useless errors in the use of this variable.  */
03191 
03192   DECL_NAME (t) = name;
03193   TREE_TYPE (t) = type;
03194 
03195   if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
03196     layout_decl (t, 0);
03197   else if (code == FUNCTION_DECL)
03198     DECL_MODE (t) = FUNCTION_MODE;
03199 
03200   return t;
03201 }
03202 
03203 /* Builds and returns function declaration with NAME and TYPE.  */
03204 
03205 tree
03206 build_fn_decl (const char *name, tree type)
03207 {
03208   tree id = get_identifier (name);
03209   tree decl = build_decl (FUNCTION_DECL, id, type);
03210 
03211   DECL_EXTERNAL (decl) = 1;
03212   TREE_PUBLIC (decl) = 1;
03213   DECL_ARTIFICIAL (decl) = 1;
03214   TREE_NOTHROW (decl) = 1;
03215 
03216   return decl;
03217 }
03218 
03219 
03220 /* BLOCK nodes are used to represent the structure of binding contours
03221    and declarations, once those contours have been exited and their contents
03222    compiled.  This information is used for outputting debugging info.  */
03223 
03224 tree
03225 build_block (tree vars, tree subblocks, tree supercontext, tree chain)
03226 {
03227   tree block = make_node (BLOCK);
03228 
03229   BLOCK_VARS (block) = vars;
03230   BLOCK_SUBBLOCKS (block) = subblocks;
03231   BLOCK_SUPERCONTEXT (block) = supercontext;
03232   BLOCK_CHAIN (block) = chain;
03233   return block;
03234 }
03235 
03236 #if 1 /* ! defined(USE_MAPPED_LOCATION) */
03237 /* ??? gengtype doesn't handle conditionals */
03238 static GTY(()) source_locus last_annotated_node;
03239 #endif
03240 
03241 #ifdef USE_MAPPED_LOCATION
03242 
03243 expanded_location
03244 expand_location (source_location loc)
03245 {
03246   expanded_location xloc;
03247   if (loc == 0) { xloc.file = NULL; xloc.line = 0;  xloc.column = 0; }
03248   else
03249     {
03250       const struct line_map *map = linemap_lookup (&line_table, loc);
03251       xloc.file = map->to_file;
03252       xloc.line = SOURCE_LINE (map, loc);
03253       xloc.column = SOURCE_COLUMN (map, loc);
03254     };
03255   return xloc;
03256 }
03257 
03258 #else
03259 
03260 /* Record the exact location where an expression or an identifier were
03261    encountered.  */
03262 
03263 void
03264 annotate_with_file_line (tree node, const char *file, int line)
03265 {
03266   /* Roughly one percent of the calls to this function are to annotate
03267      a node with the same information already attached to that node!
03268      Just return instead of wasting memory.  */
03269   if (EXPR_LOCUS (node)
03270       && EXPR_LINENO (node) == line
03271       && (EXPR_FILENAME (node) == file
03272     || !strcmp (EXPR_FILENAME (node), file)))
03273     {
03274       last_annotated_node = EXPR_LOCUS (node);
03275       return;
03276     }
03277 
03278   /* In heavily macroized code (such as GCC itself) this single
03279      entry cache can reduce the number of allocations by more
03280      than half.  */
03281   if (last_annotated_node
03282       && last_annotated_node->line == line
03283       && (last_annotated_node->file == file
03284     || !strcmp (last_annotated_node->file, file)))
03285     {
03286       SET_EXPR_LOCUS (node, last_annotated_node);
03287       return;
03288     }
03289 
03290   SET_EXPR_LOCUS (node, ggc_alloc (sizeof (location_t)));
03291   EXPR_LINENO (node) = line;
03292   EXPR_FILENAME (node) = file;
03293   last_annotated_node = EXPR_LOCUS (node);
03294 }
03295 
03296 void
03297 annotate_with_locus (tree node, location_t locus)
03298 {
03299   annotate_with_file_line (node, locus.file, locus.line);
03300 }
03301 #endif
03302 
03303 /* Return a declaration like DDECL except that its DECL_ATTRIBUTES
03304    is ATTRIBUTE.  */
03305 
03306 tree
03307 build_decl_attribute_variant (tree ddecl, tree attribute)
03308 {
03309   DECL_ATTRIBUTES (ddecl) = attribute;
03310   return ddecl;
03311 }
03312 
03313 /* Borrowed from hashtab.c iterative_hash implementation.  */
03314 #define mix(a,b,c) \
03315 { \
03316   a -= b; a -= c; a ^= (c>>13); \
03317   b -= c; b -= a; b ^= (a<< 8); \
03318   c -= a; c -= b; c ^= ((b&0xffffffff)>>13); \
03319   a -= b; a -= c; a ^= ((c&0xffffffff)>>12); \
03320   b -= c; b -= a; b = (b ^ (a<<16)) & 0xffffffff; \
03321   c -= a; c -= b; c = (c ^ (b>> 5)) & 0xffffffff; \
03322   a -= b; a -= c; a = (a ^ (c>> 3)) & 0xffffffff; \
03323   b -= c; b -= a; b = (b ^ (a<<10)) & 0xffffffff; \
03324   c -= a; c -= b; c = (c ^ (b>>15)) & 0xffffffff; \
03325 }
03326 
03327 
03328 /* Produce good hash value combining VAL and VAL2.  */
03329 static inline hashval_t
03330 iterative_hash_hashval_t (hashval_t val, hashval_t val2)
03331 {
03332   /* the golden ratio; an arbitrary value.  */
03333   hashval_t a = 0x9e3779b9;
03334 
03335   mix (a, val, val2);
03336   return val2;
03337 }
03338 
03339 /* Produce good hash value combining PTR and VAL2.  */
03340 static inline hashval_t
03341 iterative_hash_pointer (void *ptr, hashval_t val2)
03342 {
03343   if (sizeof (ptr) == sizeof (hashval_t))
03344     return iterative_hash_hashval_t ((size_t) ptr, val2);
03345   else
03346     {
03347       hashval_t a = (hashval_t) (size_t) ptr;
03348       /* Avoid warnings about shifting of more than the width of the type on
03349          hosts that won't execute this path.  */
03350       int zero = 0;
03351       hashval_t b = (hashval_t) ((size_t) ptr >> (sizeof (hashval_t) * 8 + zero));
03352       mix (a, b, val2);
03353       return val2;
03354     }
03355 }
03356 
03357 /* Produce good hash value combining VAL and VAL2.  */
03358 static inline hashval_t
03359 iterative_hash_host_wide_int (HOST_WIDE_INT val, hashval_t val2)
03360 {
03361   if (sizeof (HOST_WIDE_INT) == sizeof (hashval_t))
03362     return iterative_hash_hashval_t (val, val2);
03363   else
03364     {
03365       hashval_t a = (hashval_t) val;
03366       /* Avoid warnings about shifting of more than the width of the type on
03367          hosts that won't execute this path.  */
03368       int zero = 0;
03369       hashval_t b = (hashval_t) (val >> (sizeof (hashval_t) * 8 + zero));
03370       mix (a, b, val2);
03371       if (sizeof (HOST_WIDE_INT) > 2 * sizeof (hashval_t))
03372   {
03373     hashval_t a = (hashval_t) (val >> (sizeof (hashval_t) * 16 + zero));
03374     hashval_t b = (hashval_t) (val >> (sizeof (hashval_t) * 24 + zero));
03375     mix (a, b, val2);
03376   }
03377       return val2;
03378     }
03379 }
03380 
03381 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
03382    is ATTRIBUTE and its qualifiers are QUALS.
03383 
03384    Record such modified types already made so we don't make duplicates.  */
03385 
03386 static tree
03387 build_type_attribute_qual_variant (tree ttype, tree attribute, int quals)
03388 {
03389   if (! attribute_list_equal (TYPE_ATTRIBUTES (ttype), attribute))
03390     {
03391       hashval_t hashcode = 0;
03392       tree ntype;
03393       enum tree_code code = TREE_CODE (ttype);
03394 
03395       ntype = copy_node (ttype);
03396 
03397       TYPE_POINTER_TO (ntype) = 0;
03398       TYPE_REFERENCE_TO (ntype) = 0;
03399       TYPE_ATTRIBUTES (ntype) = attribute;
03400 
03401       /* Create a new main variant of TYPE.  */
03402       TYPE_MAIN_VARIANT (ntype) = ntype;
03403       TYPE_NEXT_VARIANT (ntype) = 0;
03404       set_type_quals (ntype, TYPE_UNQUALIFIED);
03405 
03406       hashcode = iterative_hash_object (code, hashcode);
03407       if (TREE_TYPE (ntype))
03408   hashcode = iterative_hash_object (TYPE_HASH (TREE_TYPE (ntype)),
03409             hashcode);
03410       hashcode = attribute_hash_list (attribute, hashcode);
03411 
03412       switch (TREE_CODE (ntype))
03413   {
03414   case FUNCTION_TYPE:
03415     hashcode = type_hash_list (TYPE_ARG_TYPES (ntype), hashcode);
03416     break;
03417   case ARRAY_TYPE:
03418     hashcode = iterative_hash_object (TYPE_HASH (TYPE_DOMAIN (ntype)),
03419               hashcode);
03420     break;
03421   case INTEGER_TYPE:
03422     hashcode = iterative_hash_object
03423       (TREE_INT_CST_LOW (TYPE_MAX_VALUE (ntype)), hashcode);
03424     hashcode = iterative_hash_object
03425       (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (ntype)), hashcode);
03426     break;
03427   case REAL_TYPE:
03428     {
03429       unsigned int precision = TYPE_PRECISION (ntype);
03430       hashcode = iterative_hash_object (precision, hashcode);
03431     }
03432     break;
03433   default:
03434     break;
03435   }
03436 
03437       ntype = type_hash_canon (hashcode, ntype);
03438       ttype = build_qualified_type (ntype, quals);
03439     }
03440 
03441   return ttype;
03442 }
03443 
03444 
03445 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
03446    is ATTRIBUTE.
03447 
03448    Record such modified types already made so we don't make duplicates.  */
03449 
03450 tree
03451 build_type_attribute_variant (tree ttype, tree attribute)
03452 {
03453   return build_type_attribute_qual_variant (ttype, attribute,
03454               TYPE_QUALS (ttype));
03455 }
03456 
03457 /* Return nonzero if IDENT is a valid name for attribute ATTR,
03458    or zero if not.
03459 
03460    We try both `text' and `__text__', ATTR may be either one.  */
03461 /* ??? It might be a reasonable simplification to require ATTR to be only
03462    `text'.  One might then also require attribute lists to be stored in
03463    their canonicalized form.  */
03464 
03465 static int
03466 is_attribute_with_length_p (const char *attr, int attr_len, tree ident)
03467 {
03468   int ident_len;
03469   const char *p;
03470 
03471   if (TREE_CODE (ident) != IDENTIFIER_NODE)
03472     return 0;
03473   
03474   p = IDENTIFIER_POINTER (ident);
03475   ident_len = IDENTIFIER_LENGTH (ident);
03476   
03477   if (ident_len == attr_len
03478       && strcmp (attr, p) == 0)
03479     return 1;
03480 
03481   /* If ATTR is `__text__', IDENT must be `text'; and vice versa.  */
03482   if (attr[0] == '_')
03483     {
03484       gcc_assert (attr[1] == '_');
03485       gcc_assert (attr[attr_len - 2] == '_');
03486       gcc_assert (attr[attr_len - 1] == '_');
03487       if (ident_len == attr_len - 4
03488     && strncmp (attr + 2, p, attr_len - 4) == 0)
03489   return 1;
03490     }
03491   else
03492     {
03493       if (ident_len == attr_len + 4
03494     && p[0] == '_' && p[1] == '_'
03495     && p[ident_len - 2] == '_' && p[ident_len - 1] == '_'
03496     && strncmp (attr, p + 2, attr_len) == 0)
03497   return 1;
03498     }
03499 
03500   return 0;
03501 }
03502 
03503 /* Return nonzero if IDENT is a valid name for attribute ATTR,
03504    or zero if not.
03505 
03506    We try both `text' and `__text__', ATTR may be either one.  */
03507 
03508 int
03509 is_attribute_p (const char *attr, tree ident)
03510 {
03511   return is_attribute_with_length_p (attr, strlen (attr), ident);
03512 }
03513 
03514 /* Given an attribute name and a list of attributes, return a pointer to the
03515    attribute's list element if the attribute is part of the list, or NULL_TREE
03516    if not found.  If the attribute appears more than once, this only
03517    returns the first occurrence; the TREE_CHAIN of the return value should
03518    be passed back in if further occurrences are wanted.  */
03519 
03520 tree
03521 lookup_attribute (const char *attr_name, tree list)
03522 {
03523   tree l;
03524   size_t attr_len = strlen (attr_name);
03525 
03526   for (l = list; l; l = TREE_CHAIN (l))
03527     {
03528       gcc_assert (TREE_CODE (TREE_PURPOSE (l)) == IDENTIFIER_NODE);
03529       if (is_attribute_with_length_p (attr_name, attr_len, TREE_PURPOSE (l)))
03530   return l;
03531     }
03532 
03533   return NULL_TREE;
03534 }
03535 
03536 /* Remove any instances of attribute ATTR_NAME in LIST and return the
03537    modified list.  */
03538 
03539 tree
03540 remove_attribute (const char *attr_name, tree list)
03541 {
03542   tree *p;
03543   size_t attr_len = strlen (attr_name);
03544 
03545   for (p = &list; *p; )
03546     {
03547       tree l = *p;
03548       gcc_assert (TREE_CODE (TREE_PURPOSE (l)) == IDENTIFIER_NODE);
03549       if (is_attribute_with_length_p (attr_name, attr_len, TREE_PURPOSE (l)))
03550   *p = TREE_CHAIN (l);
03551       else
03552   p = &TREE_CHAIN (l);
03553     }
03554 
03555   return list;
03556 }
03557 
03558 /* Return an attribute list that is the union of a1 and a2.  */
03559 
03560 tree
03561 merge_attributes (tree a1, tree a2)
03562 {
03563   tree attributes;
03564 
03565   /* Either one unset?  Take the set one.  */
03566 
03567   if ((attributes = a1) == 0)
03568     attributes = a2;
03569 
03570   /* One that completely contains the other?  Take it.  */
03571 
03572   else if (a2 != 0 && ! attribute_list_contained (a1, a2))
03573     {
03574       if (attribute_list_contained (a2, a1))
03575   attributes = a2;
03576       else
03577   {
03578     /* Pick the longest list, and hang on the other list.  */
03579 
03580     if (list_length (a1) < list_length (a2))
03581       attributes = a2, a2 = a1;
03582 
03583     for (; a2 != 0; a2 = TREE_CHAIN (a2))
03584       {
03585         tree a;
03586         for (a = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2)),
03587            attributes);
03588        a != NULL_TREE;
03589        a = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2)),
03590            TREE_CHAIN (a)))
03591     {
03592       if (TREE_VALUE (a) != NULL
03593           && TREE_CODE (TREE_VALUE (a)) == TREE_LIST
03594           && TREE_VALUE (a2) != NULL
03595           && TREE_CODE (TREE_VALUE (a2)) == TREE_LIST)
03596         {
03597           if (simple_cst_list_equal (TREE_VALUE (a),
03598              TREE_VALUE (a2)) == 1)
03599       break;
03600         }
03601       else if (simple_cst_equal (TREE_VALUE (a),
03602                TREE_VALUE (a2)) == 1)
03603         break;
03604     }
03605         if (a == NULL_TREE)
03606     {
03607       a1 = copy_node (a2);
03608       TREE_CHAIN (a1) = attributes;
03609       attributes = a1;
03610     }
03611       }
03612   }
03613     }
03614   return attributes;
03615 }
03616 
03617 /* Given types T1 and T2, merge their attributes and return
03618   the result.  */
03619 
03620 tree
03621 merge_type_attributes (tree t1, tree t2)
03622 {
03623   return merge_attributes (TYPE_ATTRIBUTES (t1),
03624          TYPE_ATTRIBUTES (t2));
03625 }
03626 
03627 /* Given decls OLDDECL and NEWDECL, merge their attributes and return
03628    the result.  */
03629 
03630 tree
03631 merge_decl_attributes (tree olddecl, tree newdecl)
03632 {
03633   return merge_attributes (DECL_ATTRIBUTES (olddecl),
03634          DECL_ATTRIBUTES (newdecl));
03635 }
03636 
03637 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
03638 
03639 /* Specialization of merge_decl_attributes for various Windows targets.
03640 
03641    This handles the following situation:
03642 
03643      __declspec (dllimport) int foo;
03644      int foo;
03645 
03646    The second instance of `foo' nullifies the dllimport.  */
03647 
03648 tree
03649 merge_dllimport_decl_attributes (tree old, tree new)
03650 {
03651   tree a;
03652   int delete_dllimport_p = 1;
03653 
03654   /* What we need to do here is remove from `old' dllimport if it doesn't
03655      appear in `new'.  dllimport behaves like extern: if a declaration is
03656      marked dllimport and a definition appears later, then the object
03657      is not dllimport'd.  We also remove a `new' dllimport if the old list
03658      contains dllexport:  dllexport always overrides dllimport, regardless
03659      of the order of declaration.  */     
03660   if (!VAR_OR_FUNCTION_DECL_P (new))
03661     delete_dllimport_p = 0;
03662   else if (DECL_DLLIMPORT_P (new)
03663          && lookup_attribute ("dllexport", DECL_ATTRIBUTES (old)))
03664     { 
03665       DECL_DLLIMPORT_P (new) = 0;
03666       warning (OPT_Wattributes, "%q+D already declared with dllexport attribute: "
03667         "dllimport ignored", new);
03668     }
03669   else if (DECL_DLLIMPORT_P (old) && !DECL_DLLIMPORT_P (new))
03670     {
03671       /* Warn about overriding a symbol that has already been used. eg:
03672            extern int __attribute__ ((dllimport)) foo;
03673      int* bar () {return &foo;}
03674      int foo;
03675       */
03676       if (TREE_USED (old))
03677   {
03678     warning (0, "%q+D redeclared without dllimport attribute "
03679        "after being referenced with dll linkage", new);
03680     /* If we have used a variable's address with dllimport linkage,
03681         keep the old DECL_DLLIMPORT_P flag: the ADDR_EXPR using the
03682         decl may already have had TREE_INVARIANT and TREE_CONSTANT
03683         computed.
03684         We still remove the attribute so that assembler code refers
03685         to '&foo rather than '_imp__foo'.  */
03686     if (TREE_CODE (old) == VAR_DECL && TREE_ADDRESSABLE (old))
03687       DECL_DLLIMPORT_P (new) = 1;
03688   }
03689 
03690       /* Let an inline definition silently override the external reference,
03691    but otherwise warn about attribute inconsistency.  */ 
03692       else if (TREE_CODE (new) == VAR_DECL
03693          || !DECL_DECLARED_INLINE_P (new))
03694   warning (OPT_Wattributes, "%q+D redeclared without dllimport attribute: "
03695       "previous dllimport ignored", new);
03696     }
03697   else
03698     delete_dllimport_p = 0;
03699 
03700   a = merge_attributes (DECL_ATTRIBUTES (old), DECL_ATTRIBUTES (new));
03701 
03702   if (delete_dllimport_p) 
03703     {
03704       tree prev, t;
03705       const size_t attr_len = strlen ("dllimport"); 
03706      
03707       /* Scan the list for dllimport and delete it.  */
03708       for (prev = NULL_TREE, t = a; t; prev = t, t = TREE_CHAIN (t))
03709   {
03710     if (is_attribute_with_length_p ("dllimport", attr_len,
03711             TREE_PURPOSE (t)))
03712       {
03713         if (prev == NULL_TREE)
03714     a = TREE_CHAIN (a);
03715         else
03716     TREE_CHAIN (prev) = TREE_CHAIN (t);
03717         break;
03718       }
03719   }
03720     }
03721 
03722   return a;
03723 }
03724 
03725 /* Handle a "dllimport" or "dllexport" attribute; arguments as in
03726    struct attribute_spec.handler.  */
03727 
03728 tree
03729 handle_dll_attribute (tree * pnode, tree name, tree args, int flags,
03730           bool *no_add_attrs)
03731 {
03732   tree node = *pnode;
03733 
03734   /* These attributes may apply to structure and union types being created,
03735      but otherwise should pass to the declaration involved.  */
03736   if (!DECL_P (node))
03737     {
03738       if (flags & ((int) ATTR_FLAG_DECL_NEXT | (int) ATTR_FLAG_FUNCTION_NEXT
03739        | (int) ATTR_FLAG_ARRAY_NEXT))
03740   {
03741     *no_add_attrs = true;
03742     return tree_cons (name, args, NULL_TREE);
03743   }
03744       if (TREE_CODE (node) != RECORD_TYPE && TREE_CODE (node) != UNION_TYPE)
03745   {
03746     warning (OPT_Wattributes, "%qs attribute ignored",
03747        IDENTIFIER_POINTER (name));
03748     *no_add_attrs = true;
03749   }
03750 
03751       return NULL_TREE;
03752     }
03753 
03754   if (TREE_CODE (node) != FUNCTION_DECL
03755       && TREE_CODE (node) != VAR_DECL)
03756     {
03757       *no_add_attrs = true;
03758       warning (OPT_Wattributes, "%qs attribute ignored",
03759          IDENTIFIER_POINTER (name));
03760       return NULL_TREE;
03761     }
03762 
03763   /* Report error on dllimport ambiguities seen now before they cause
03764      any damage.  */
03765   else if (is_attribute_p ("dllimport", name))
03766     {
03767       /* Honor any target-specific overrides. */ 
03768       if (!targetm.valid_dllimport_attribute_p (node))
03769   *no_add_attrs = true;
03770 
03771      else if (TREE_CODE (node) == FUNCTION_DECL
03772           && DECL_DECLARED_INLINE_P (node))
03773   {
03774     warning (OPT_Wattributes, "inline function %q+D declared as "
03775       " dllimport: attribute ignored", node); 
03776     *no_add_attrs = true;
03777   }
03778       /* Like MS, treat definition of dllimported variables and
03779    non-inlined functions on declaration as syntax errors. */
03780      else if (TREE_CODE (node) == FUNCTION_DECL && DECL_INITIAL (node))
03781   {
03782     error ("function %q+D definition is marked dllimport", node);
03783     *no_add_attrs = true;
03784   }
03785 
03786      else if (TREE_CODE (node) == VAR_DECL)
03787   {
03788     if (DECL_INITIAL (node))
03789       {
03790         error ("variable %q+D definition is marked dllimport",
03791          node);
03792         *no_add_attrs = true;
03793       }
03794 
03795     /* `extern' needn't be specified with dllimport.
03796        Specify `extern' now and hope for the best.  Sigh.  */
03797     DECL_EXTERNAL (node) = 1;
03798     /* Also, implicitly give dllimport'd variables declared within
03799        a function global scope, unless declared static.  */
03800     if (current_function_decl != NULL_TREE && !TREE_STATIC (node))
03801       TREE_PUBLIC (node) = 1;
03802   }
03803 
03804       if (*no_add_attrs == false)
03805         DECL_DLLIMPORT_P (node) = 1;
03806     }
03807 
03808   /*  Report error if symbol is not accessible at global scope.  */
03809   if (!TREE_PUBLIC (node)
03810       && (TREE_CODE (node) == VAR_DECL
03811     || TREE_CODE (node) == FUNCTION_DECL))
03812     {
03813       error ("external linkage required for symbol %q+D because of "
03814        "%qs attribute", node, IDENTIFIER_POINTER (name));
03815       *no_add_attrs = true;
03816     }
03817 
03818   return NULL_TREE;
03819 }
03820 
03821 #endif /* TARGET_DLLIMPORT_DECL_ATTRIBUTES  */
03822 
03823 /* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask
03824    of the various TYPE_QUAL values.  */
03825 
03826 static void
03827 set_type_quals (tree type, int type_quals)
03828 {
03829   TYPE_READONLY (type) = (type_quals & TYPE_QUAL_CONST) != 0;
03830   TYPE_VOLATILE (type) = (type_quals & TYPE_QUAL_VOLATILE) != 0;
03831   TYPE_RESTRICT (type) = (type_quals & TYPE_QUAL_RESTRICT) != 0;
03832 }
03833 
03834 /* Returns true iff cand is equivalent to base with type_quals.  */
03835 
03836 bool
03837 check_qualified_type (tree cand, tree base, int type_quals)
03838 {
03839   return (TYPE_QUALS (cand) == type_quals
03840     && TYPE_NAME (cand) == TYPE_NAME (base)
03841     /* Apparently this is needed for Objective-C.  */
03842     && TYPE_CONTEXT (cand) == TYPE_CONTEXT (base)
03843     && attribute_list_equal (TYPE_ATTRIBUTES (cand),
03844            TYPE_ATTRIBUTES (base)));
03845 }
03846 
03847 /* Return a version of the TYPE, qualified as indicated by the
03848    TYPE_QUALS, if one exists.  If no qualified version exists yet,
03849    return NULL_TREE.  */
03850 
03851 tree
03852 get_qualified_type (tree type, int type_quals)
03853 {
03854   tree t;
03855 
03856   if (TYPE_QUALS (type) == type_quals)
03857     return type;
03858 
03859   /* Search the chain of variants to see if there is already one there just
03860      like the one we need to have.  If so, use that existing one.  We must
03861      preserve the TYPE_NAME, since there is code that depends on this.  */
03862   for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
03863     if (check_qualified_type (t, type, type_quals))
03864       return t;
03865 
03866   return NULL_TREE;
03867 }
03868 
03869 /* Like get_qualified_type, but creates the type if it does not
03870    exist.  This function never returns NULL_TREE.  */
03871 
03872 tree
03873 build_qualified_type (tree type, int type_quals)
03874 {
03875   tree t;
03876 
03877   /* See if we already have the appropriate qualified variant.  */
03878   t = get_qualified_type (type, type_quals);
03879 
03880   /* If not, build it.  */
03881   if (!t)
03882     {
03883       t = build_variant_type_copy (type);
03884       set_type_quals (t, type_quals);
03885     }
03886 
03887   return t;
03888 }
03889 
03890 /* Create a new distinct copy of TYPE.  The new type is made its own
03891    MAIN_VARIANT.  */
03892 
03893 tree
03894 build_distinct_type_copy (tree type)
03895 {
03896   tree t = copy_node (type);
03897   
03898   TYPE_POINTER_TO (t) = 0;
03899   TYPE_REFERENCE_TO (t) = 0;
03900 
03901   /* Make it its own variant.  */
03902   TYPE_MAIN_VARIANT (t) = t;
03903   TYPE_NEXT_VARIANT (t) = 0;
03904 
03905   /* Note that it is now possible for TYPE_MIN_VALUE to be a value
03906      whose TREE_TYPE is not t.  This can also happen in the Ada
03907      frontend when using subtypes.  */
03908 
03909   return t;
03910 }
03911 
03912 /* Create a new variant of TYPE, equivalent but distinct.
03913    This is so the caller can modify it.  */
03914 
03915 tree
03916 build_variant_type_copy (tree type)
03917 {
03918   tree t, m = TYPE_MAIN_VARIANT (type);
03919 
03920   t = build_distinct_type_copy (type);
03921   
03922   /* Add the new type to the chain of variants of TYPE.  */
03923   TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
03924   TYPE_NEXT_VARIANT (m) = t;
03925   TYPE_MAIN_VARIANT (t) = m;
03926 
03927   return t;
03928 }
03929 
03930 /* Return true if the from tree in both tree maps are equal.  */
03931 
03932 int
03933 tree_map_eq (const void *va, const void *vb)
03934 {
03935   const struct tree_map  *a = va, *b = vb;
03936   return (a->from == b->from);
03937 }
03938 
03939 /* Hash a from tree in a tree_map.  */
03940 
03941 unsigned int
03942 tree_map_hash (const void *item)
03943 {
03944   return (((const struct tree_map *) item)->hash);
03945 }
03946 
03947 /* Return true if this tree map structure is marked for garbage collection
03948    purposes.  We simply return true if the from tree is marked, so that this
03949    structure goes away when the from tree goes away.  */
03950 
03951 int
03952 tree_map_marked_p (const void *p)
03953 {
03954   tree from = ((struct tree_map *) p)->from;
03955 
03956   return ggc_marked_p (from);
03957 }
03958 
03959 /* Return true if the trees in the tree_int_map *'s VA and VB are equal.  */
03960 
03961 static int
03962 tree_int_map_eq (const void *va, const void *vb)
03963 {
03964   const struct tree_int_map  *a = va, *b = vb;
03965   return (a->from == b->from);
03966 }
03967 
03968 /* Hash a from tree in the tree_int_map * ITEM.  */
03969 
03970 static unsigned int
03971 tree_int_map_hash (const void *item)
03972 {
03973   return htab_hash_pointer (((const struct tree_int_map *)item)->from);
03974 }
03975 
03976 /* Return true if this tree int map structure is marked for garbage collection
03977    purposes.  We simply return true if the from tree_int_map *P's from tree is marked, so that this
03978    structure goes away when the from tree goes away.  */
03979 
03980 static int
03981 tree_int_map_marked_p (const void *p)
03982 {
03983   tree from = ((struct tree_int_map *) p)->from;
03984 
03985   return ggc_marked_p (from);
03986 }
03987 /* Lookup an init priority for FROM, and return it if we find one.  */
03988 
03989 unsigned short
03990 decl_init_priority_lookup (tree from)
03991 {
03992   struct tree_int_map *h, in;
03993   in.from = from;
03994 
03995   h = htab_find_with_hash (init_priority_for_decl, 
03996          &in, htab_hash_pointer (from));
03997   if (h)
03998     return h->to;
03999   return 0;
04000 }
04001 
04002 /* Insert a mapping FROM->TO in the init priority hashtable.  */
04003 
04004 void
04005 decl_init_priority_insert (tree from, unsigned short to)
04006 {
04007   struct tree_int_map *h;
04008   void **loc;
04009 
04010   h = ggc_alloc (sizeof (struct tree_int_map));
04011   h->from = from;
04012   h->to = to;
04013   loc = htab_find_slot_with_hash (init_priority_for_decl, h, 
04014           htab_hash_pointer (from), INSERT);
04015   *(struct tree_int_map **) loc = h;
04016 }  
04017 
04018 /* Look up a restrict qualified base decl for FROM.  */
04019 
04020 tree
04021 decl_restrict_base_lookup (tree from)
04022 {
04023   struct tree_map *h;
04024   struct tree_map in;
04025 
04026   in.from = from;
04027   h = htab_find_with_hash (restrict_base_for_decl, &in,
04028          htab_hash_pointer (from));
04029   return h ? h->to : NULL_TREE;
04030 }
04031 
04032 /* Record the restrict qualified base TO for FROM.  */
04033 
04034 void
04035 decl_restrict_base_insert (tree from, tree to)
04036 {
04037   struct tree_map *h;
04038   void **loc;
04039 
04040   h = ggc_alloc (sizeof (struct tree_map));
04041   h->hash = htab_hash_pointer (from);
04042   h->from = from;
04043   h->to = to;
04044   loc = htab_find_slot_with_hash (restrict_base_for_decl, h, h->hash, INSERT);
04045   *(struct tree_map **) loc = h;
04046 }
04047 
04048 /* Print out the statistics for the DECL_DEBUG_EXPR hash table.  */
04049 
04050 static void
04051 print_debug_expr_statistics (void)
04052 {
04053   fprintf (stderr, "DECL_DEBUG_EXPR  hash: size %ld, %ld elements, %f collisions\n",
04054      (long) htab_size (debug_expr_for_decl),
04055      (long) htab_elements (debug_expr_for_decl),
04056      htab_collisions (debug_expr_for_decl));
04057 }
04058 
04059 /* Print out the statistics for the DECL_VALUE_EXPR hash table.  */
04060 
04061 static void
04062 print_value_expr_statistics (void)
04063 {
04064   fprintf (stderr, "DECL_VALUE_EXPR  hash: size %ld, %ld elements, %f collisions\n",
04065      (long) htab_size (value_expr_for_decl),
04066      (long) htab_elements (value_expr_for_decl),
04067      htab_collisions (value_expr_for_decl));
04068 }
04069 
04070 /* Print out statistics for the RESTRICT_BASE_FOR_DECL hash table, but
04071    don't print anything if the table is empty.  */
04072 
04073 static void
04074 print_restrict_base_statistics (void)
04075 {
04076   if (htab_elements (restrict_base_for_decl) != 0)
04077     fprintf (stderr,
04078        "RESTRICT_BASE    hash: size %ld, %ld elements, %f collisions\n",
04079        (long) htab_size (restrict_base_for_decl),
04080        (long) htab_elements (restrict_base_for_decl),
04081        htab_collisions (restrict_base_for_decl));
04082 }
04083 
04084 /* Lookup a debug expression for FROM, and return it if we find one.  */
04085 
04086 tree 
04087 decl_debug_expr_lookup (tree from)
04088 {
04089   struct tree_map *h, in;
04090   in.from = from;
04091 
04092   h = htab_find_with_hash (debug_expr_for_decl, &in, htab_hash_pointer (from));
04093   if (h)
04094     return h->to;
04095   return NULL_TREE;
04096 }
04097 
04098 /* Insert a mapping FROM->TO in the debug expression hashtable.  */
04099 
04100 void
04101 decl_debug_expr_insert (tree from, tree to)
04102 {
04103   struct tree_map *h;
04104   void **loc;
04105 
04106   h = ggc_alloc (sizeof (struct tree_map));
04107   h->hash = htab_hash_pointer (from);
04108   h->from = from;
04109   h->to = to;
04110   loc = htab_find_slot_with_hash (debug_expr_for_decl, h, h->hash, INSERT);
04111   *(struct tree_map **) loc = h;
04112 }  
04113 
04114 /* Lookup a value expression for FROM, and return it if we find one.  */
04115 
04116 tree 
04117 decl_value_expr_lookup (tree from)
04118 {
04119   struct tree_map *h, in;
04120   in.from = from;
04121 
04122   h = htab_find_with_hash (value_expr_for_decl, &in, htab_hash_pointer (from));
04123   if (h)
04124     return h->to;
04125   return NULL_TREE;
04126 }
04127 
04128 /* Insert a mapping FROM->TO in the value expression hashtable.  */
04129 
04130 void
04131 decl_value_expr_insert (tree from, tree to)
04132 {
04133   struct tree_map *h;
04134   void **loc;
04135 
04136   h = ggc_alloc (sizeof (struct tree_map));
04137   h->hash = htab_hash_pointer (from);
04138   h->from = from;
04139   h->to = to;
04140   loc = htab_find_slot_with_hash (value_expr_for_decl, h, h->hash, INSERT);
04141   *(struct tree_map **) loc = h;
04142 }
04143 
04144 /* Hashing of types so that we don't make duplicates.
04145    The entry point is `type_hash_canon'.  */
04146 
04147 /* Compute a hash code for a list of types (chain of TREE_LIST nodes
04148    with types in the TREE_VALUE slots), by adding the hash codes
04149    of the individual types.  */
04150 
04151 unsigned int
04152 type_hash_list (tree list, hashval_t hashcode)
04153 {
04154   tree tail;
04155 
04156   for (tail = list; tail; tail = TREE_CHAIN (tail))
04157     if (TREE_VALUE (tail) != error_mark_node)
04158       hashcode = iterative_hash_object (TYPE_HASH (TREE_VALUE (tail)),
04159           hashcode);
04160 
04161   return hashcode;
04162 }
04163 
04164 /* These are the Hashtable callback functions.  */
04165 
04166 /* Returns true iff the types are equivalent.  */
04167 
04168 static int
04169 type_hash_eq (const void *va, const void *vb)
04170 {
04171   const struct type_hash *a = va, *b = vb;
04172 
04173   /* First test the things that are the same for all types.  */
04174   if (a->hash != b->hash
04175       || TREE_CODE (a->type) != TREE_CODE (b->type)
04176       || TREE_TYPE (a->type) != TREE_TYPE (b->type)
04177       || !attribute_list_equal (TYPE_ATTRIBUTES (a->type),
04178          TYPE_ATTRIBUTES (b->type))
04179       || TYPE_ALIGN (a->type) != TYPE_ALIGN (b->type)
04180       || TYPE_MODE (a->type) != TYPE_MODE (b->type))
04181     return 0;
04182 
04183   switch (TREE_CODE (a->type))
04184     {
04185     case VOID_TYPE:
04186     case COMPLEX_TYPE:
04187     case POINTER_TYPE:
04188     case REFERENCE_TYPE:
04189       return 1;
04190 
04191     case VECTOR_TYPE:
04192       return TYPE_VECTOR_SUBPARTS (a->type) == TYPE_VECTOR_SUBPARTS (b->type);
04193 
04194     case ENUMERAL_TYPE:
04195       if (TYPE_VALUES (a->type) != TYPE_VALUES (b->type)
04196     && !(TYPE_VALUES (a->type)
04197          && TREE_CODE (TYPE_VALUES (a->type)) == TREE_LIST
04198          && TYPE_VALUES (b->type)
04199          && TREE_CODE (TYPE_VALUES (b->type)) == TREE_LIST
04200          && type_list_equal (TYPE_VALUES (a->type),
04201            TYPE_VALUES (b->type))))
04202   return 0;
04203 
04204       /* ... fall through ... */
04205 
04206     case INTEGER_TYPE:
04207     case REAL_TYPE:
04208     case BOOLEAN_TYPE:
04209       return ((TYPE_MAX_VALUE (a->type) == TYPE_MAX_VALUE (b->type)
04210          || tree_int_cst_equal (TYPE_MAX_VALUE (a->type),
04211               TYPE_MAX_VALUE (b->type)))
04212         && (TYPE_MIN_VALUE (a->type) == TYPE_MIN_VALUE (b->type)
04213       || tree_int_cst_equal (TYPE_MIN_VALUE (a->type),
04214            TYPE_MIN_VALUE (b->type))));
04215 
04216     case OFFSET_TYPE:
04217       return TYPE_OFFSET_BASETYPE (a->type) == TYPE_OFFSET_BASETYPE (b->type);
04218 
04219     case METHOD_TYPE:
04220       return (TYPE_METHOD_BASETYPE (a->type) == TYPE_METHOD_BASETYPE (b->type)
04221         && (TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type)
04222       || (TYPE_ARG_TYPES (a->type)
04223           && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST
04224           && TYPE_ARG_TYPES (b->type)
04225           && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST
04226           && type_list_equal (TYPE_ARG_TYPES (a->type),
04227             TYPE_ARG_TYPES (b->type)))));
04228 
04229     case ARRAY_TYPE:
04230       return TYPE_DOMAIN (a->type) == TYPE_DOMAIN (b->type);
04231 
04232     case RECORD_TYPE:
04233     case UNION_TYPE:
04234     case QUAL_UNION_TYPE:
04235       return (TYPE_FIELDS (a->type) == TYPE_FIELDS (b->type)
04236         || (TYPE_FIELDS (a->type)
04237       && TREE_CODE (TYPE_FIELDS (a->type)) == TREE_LIST
04238       && TYPE_FIELDS (b->type)
04239       && TREE_CODE (TYPE_FIELDS (b->type)) == TREE_LIST
04240       && type_list_equal (TYPE_FIELDS (a->type),
04241               TYPE_FIELDS (b->type))));
04242 
04243     case FUNCTION_TYPE:
04244       return (TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type)
04245         || (TYPE_ARG_TYPES (a->type)
04246       && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST
04247       && TYPE_ARG_TYPES (b->type)
04248       && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST
04249       && type_list_equal (TYPE_ARG_TYPES (a->type),
04250               TYPE_ARG_TYPES (b->type))));
04251 
04252     default:
04253       return 0;
04254     }
04255 }
04256 
04257 /* Return the cached hash value.  */
04258 
04259 static hashval_t
04260 type_hash_hash (const void *item)
04261 {
04262   return ((const struct type_hash *) item)->hash;
04263 }
04264 
04265 /* Look in the type hash table for a type isomorphic to TYPE.
04266    If one is found, return it.  Otherwise return 0.  */
04267 
04268 tree
04269 type_hash_lookup (hashval_t hashcode, tree type)
04270 {
04271   struct type_hash *h, in;
04272 
04273   /* The TYPE_ALIGN field of a type is set by layout_type(), so we
04274      must call that routine before comparing TYPE_ALIGNs.  */
04275   layout_type (type);
04276 
04277   in.hash = hashcode;
04278   in.type = type;
04279 
04280   h = htab_find_with_hash (type_hash_table, &in, hashcode);
04281   if (h)
04282     return h->type;
04283   return NULL_TREE;
04284 }
04285 
04286 /* Add an entry to the type-hash-table
04287    for a type TYPE whose hash code is HASHCODE.  */
04288 
04289 void
04290 type_hash_add (hashval_t hashcode, tree type)
04291 {
04292   struct type_hash *h;
04293   void **loc;
04294 
04295   h = ggc_alloc (sizeof (struct type_hash));
04296   h->hash = hashcode;
04297   h->type = type;
04298   loc = htab_find_slot_with_hash (type_hash_table, h, hashcode, INSERT);
04299   *(struct type_hash **) loc = h;
04300 }
04301 
04302 /* Given TYPE, and HASHCODE its hash code, return the canonical
04303    object for an identical type if one already exists.
04304    Otherwise, return TYPE, and record it as the canonical object.
04305 
04306    To use this function, first create a type of the sort you want.
04307    Then compute its hash code from the fields of the type that
04308    make it different from other similar types.
04309    Then call this function and use the value.  */
04310 
04311 tree
04312 type_hash_canon (unsigned int hashcode, tree type)
04313 {
04314   tree t1;
04315 
04316   /* The hash table only contains main variants, so ensure that's what we're
04317      being passed.  */
04318   gcc_assert (TYPE_MAIN_VARIANT (type) == type);
04319 
04320   if (!lang_hooks.types.hash_types)
04321     return type;
04322 
04323   /* See if the type is in the hash table already.  If so, return it.
04324      Otherwise, add the type.  */
04325   t1 = type_hash_lookup (hashcode, type);
04326   if (t1 != 0)
04327     {
04328 #ifdef GATHER_STATISTICS
04329       tree_node_counts[(int) t_kind]--;
04330       tree_node_sizes[(int) t_kind] -= sizeof (struct tree_type);
04331 #endif
04332       return t1;
04333     }
04334   else
04335     {
04336       type_hash_add (hashcode, type);
04337       return type;
04338     }
04339 }
04340 
04341 /* See if the data pointed to by the type hash table is marked.  We consider
04342    it marked if the type is marked or if a debug type number or symbol
04343    table entry has been made for the type.  This reduces the amount of
04344    debugging output and eliminates that dependency of the debug output on
04345    the number of garbage collections.  */
04346 
04347 static int
04348 type_hash_marked_p (const void *p)
04349 {
04350   tree type = ((struct type_hash *) p)->type;
04351 
04352   return ggc_marked_p (type) || TYPE_SYMTAB_POINTER (type);
04353 }
04354 
04355 static void
04356 print_type_hash_statistics (void)
04357 {
04358   fprintf (stderr, "Type hash: size %ld, %ld elements, %f collisions\n",
04359      (long) htab_size (type_hash_table),
04360      (long) htab_elements (type_hash_table),
04361      htab_collisions (type_hash_table));
04362 }
04363 
04364 /* Compute a hash code for a list of attributes (chain of TREE_LIST nodes
04365    with names in the TREE_PURPOSE slots and args in the TREE_VALUE slots),
04366    by adding the hash codes of the individual attributes.  */
04367 
04368 unsigned int
04369 attribute_hash_list (tree list, hashval_t hashcode)
04370 {
04371   tree tail;
04372 
04373   for (tail = list; tail; tail = TREE_CHAIN (tail))
04374     /* ??? Do we want to add in TREE_VALUE too? */
04375     hashcode = iterative_hash_object
04376       (IDENTIFIER_HASH_VALUE (TREE_PURPOSE (tail)), hashcode);
04377   return hashcode;
04378 }
04379 
04380 /* Given two lists of attributes, return true if list l2 is
04381    equivalent to l1.  */
04382 
04383 int
04384 attribute_list_equal (tree l1, tree l2)
04385 {
04386   return attribute_list_contained (l1, l2)
04387    && attribute_list_contained (l2, l1);
04388 }
04389 
04390 /* Given two lists of attributes, return true if list L2 is
04391    completely contained within L1.  */
04392 /* ??? This would be faster if attribute names were stored in a canonicalized
04393    form.  Otherwise, if L1 uses `foo' and L2 uses `__foo__', the long method
04394    must be used to show these elements are equivalent (which they are).  */
04395 /* ??? It's not clear that attributes with arguments will always be handled
04396    correctly.  */
04397 
04398 int
04399 attribute_list_contained (tree l1, tree l2)
04400 {
04401   tree t1, t2;
04402 
04403   /* First check the obvious, maybe the lists are identical.  */
04404   if (l1 == l2)
04405     return 1;
04406 
04407   /* Maybe the lists are similar.  */
04408   for (t1 = l1, t2 = l2;
04409        t1 != 0 && t2 != 0
04410         && TREE_PURPOSE (t1) == TREE_PURPOSE (t2)
04411         && TREE_VALUE (t1) == TREE_VALUE (t2);
04412        t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2));
04413 
04414   /* Maybe the lists are equal.  */
04415   if (t1 == 0 && t2 == 0)
04416     return 1;
04417 
04418   for (; t2 != 0; t2 = TREE_CHAIN (t2))
04419     {
04420       tree attr;
04421       for (attr = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2)), l1);
04422      attr != NULL_TREE;
04423      attr = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2)),
04424             TREE_CHAIN (attr)))
04425   {
04426     if (TREE_VALUE (t2) != NULL
04427         && TREE_CODE (TREE_VALUE (t2)) == TREE_LIST
04428         && TREE_VALUE (attr) != NULL
04429         && TREE_CODE (TREE_VALUE (attr)) == TREE_LIST)
04430       {
04431         if (simple_cst_list_equal (TREE_VALUE (t2),
04432            TREE_VALUE (attr)) == 1)
04433     break;
04434       }
04435     else if (simple_cst_equal (TREE_VALUE (t2), TREE_VALUE (attr)) == 1)
04436       break;
04437   }
04438 
04439       if (attr == 0)
04440   return 0;
04441     }
04442 
04443   return 1;
04444 }
04445 
04446 /* Given two lists of types
04447    (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
04448    return 1 if the lists contain the same types in the same order.
04449    Also, the TREE_PURPOSEs must match.  */
04450 
04451 int
04452 type_list_equal (tree l1, tree l2)
04453 {
04454   tree t1, t2;
04455 
04456   for (t1 = l1, t2 = l2; t1 && t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
04457     if (TREE_VALUE (t1) != TREE_VALUE (t2)
04458   || (TREE_PURPOSE (t1) != TREE_PURPOSE (t2)
04459       && ! (1 == simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2))
04460       && (TREE_TYPE (TREE_PURPOSE (t1))
04461           == TREE_TYPE (TREE_PURPOSE (t2))))))
04462       return 0;
04463 
04464   return t1 == t2;
04465 }
04466 
04467 /* Returns the number of arguments to the FUNCTION_TYPE or METHOD_TYPE
04468    given by TYPE.  If the argument list accepts variable arguments,
04469    then this function counts only the ordinary arguments.  */
04470 
04471 int
04472 type_num_arguments (tree type)
04473 {
04474   int i = 0;
04475   tree t;
04476 
04477   for (t = TYPE_ARG_TYPES (type); t; t = TREE_CHAIN (t))
04478     /* If the function does not take a variable number of arguments,
04479        the last element in the list will have type `void'.  */
04480     if (VOID_TYPE_P (TREE_VALUE (t)))
04481       break;
04482     else
04483       ++i;
04484 
04485   return i;
04486 }
04487 
04488 /* Nonzero if integer constants T1 and T2
04489    represent the same constant value.  */
04490 
04491 int
04492 tree_int_cst_equal (tree t1, tree t2)
04493 {
04494   if (t1 == t2)
04495     return 1;
04496 
04497   if (t1 == 0 || t2 == 0)
04498     return 0;
04499 
04500   if (TREE_CODE (t1) == INTEGER_CST
04501       && TREE_CODE (t2) == INTEGER_CST
04502       && TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
04503       && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2))
04504     return 1;
04505 
04506   return 0;
04507 }
04508 
04509 /* Nonzero if integer constants T1 and T2 represent values that satisfy <.
04510    The precise way of comparison depends on their data type.  */
04511 
04512 int
04513 tree_int_cst_lt (tree t1, tree t2)
04514 {
04515   if (t1 == t2)
04516     return 0;
04517 
04518   if (TYPE_UNSIGNED (TREE_TYPE (t1)) != TYPE_UNSIGNED (TREE_TYPE (t2)))
04519     {
04520       int t1_sgn = tree_int_cst_sgn (t1);
04521       int t2_sgn = tree_int_cst_sgn (t2);
04522 
04523       if (t1_sgn < t2_sgn)
04524   return 1;
04525       else if (t1_sgn > t2_sgn)
04526   return 0;
04527       /* Otherwise, both are non-negative, so we compare them as
04528    unsigned just in case one of them would overflow a signed
04529    type.  */
04530     }
04531   else if (!TYPE_UNSIGNED (TREE_TYPE (t1)))
04532     return INT_CST_LT (t1, t2);
04533 
04534   return INT_CST_LT_UNSIGNED (t1, t2);
04535 }
04536 
04537 /* Returns -1 if T1 < T2, 0 if T1 == T2, and 1 if T1 > T2.  */
04538 
04539 int
04540 tree_int_cst_compare (tree t1, tree t2)
04541 {
04542   if (tree_int_cst_lt (t1, t2))
04543     return -1;
04544   else if (tree_int_cst_lt (t2, t1))
04545     return 1;
04546   else
04547     return 0;
04548 }
04549 
04550 /* Return 1 if T is an INTEGER_CST that can be manipulated efficiently on
04551    the host.  If POS is zero, the value can be represented in a single
04552    HOST_WIDE_INT.  If POS is nonzero, the value must be non-negative and can
04553    be represented in a single unsigned HOST_WIDE_INT.  */
04554 
04555 int
04556 host_integerp (tree t, int pos)
04557 {
04558   return (TREE_CODE (t) == INTEGER_CST
04559     && ((TREE_INT_CST_HIGH (t) == 0
04560          && (HOST_WIDE_INT) TREE_INT_CST_LOW (t) >= 0)
04561         || (! pos && TREE_INT_CST_HIGH (t) == -1
04562       && (HOST_WIDE_INT) TREE_INT_CST_LOW (t) < 0
04563       && !TYPE_UNSIGNED (TREE_TYPE (t)))
04564         || (pos && TREE_INT_CST_HIGH (t) == 0)));
04565 }
04566 
04567 /* Return the HOST_WIDE_INT least significant bits of T if it is an
04568    INTEGER_CST and there is no overflow.  POS is nonzero if the result must
04569    be non-negative.  We must be able to satisfy the above conditions.  */
04570 
04571 HOST_WIDE_INT
04572 tree_low_cst (tree t, int pos)
04573 {
04574   gcc_assert (host_integerp (t, pos));
04575   return TREE_INT_CST_LOW (t);
04576 }
04577 
04578 /* Return the most significant bit of the integer constant T.  */
04579 
04580 int
04581 tree_int_cst_msb (tree t)
04582 {
04583   int prec;
04584   HOST_WIDE_INT h;
04585   unsigned HOST_WIDE_INT l;
04586 
04587   /* Note that using TYPE_PRECISION here is wrong.  We care about the
04588      actual bits, not the (arbitrary) range of the type.  */
04589   prec = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (t))) - 1;
04590   rshift_double (TREE_INT_CST_LOW (t), TREE_INT_CST_HIGH (t), prec,
04591      2 * HOST_BITS_PER_WIDE_INT, &l, &h, 0);
04592   return (l & 1) == 1;
04593 }
04594 
04595 /* Return an indication of the sign of the integer constant T.
04596    The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0.
04597    Note that -1 will never be returned if T's type is unsigned.  */
04598 
04599 int
04600 tree_int_cst_sgn (tree t)
04601 {
04602   if (TREE_INT_CST_LOW (t) == 0 && TREE_INT_CST_HIGH (t) == 0)
04603     return 0;
04604   else if (TYPE_UNSIGNED (TREE_TYPE (t)))
04605     return 1;
04606   else if (TREE_INT_CST_HIGH (t) < 0)
04607     return -1;
04608   else
04609     return 1;
04610 }
04611 
04612 /* Compare two constructor-element-type constants.  Return 1 if the lists
04613    are known to be equal; otherwise return 0.  */
04614 
04615 int
04616 simple_cst_list_equal (tree l1, tree l2)
04617 {
04618   while (l1 != NULL_TREE && l2 != NULL_TREE)
04619     {
04620       if (simple_cst_equal (TREE_VALUE (l1), TREE_VALUE (l2)) != 1)
04621   return 0;
04622 
04623       l1 = TREE_CHAIN (l1);
04624       l2 = TREE_CHAIN (l2);
04625     }
04626 
04627   return l1 == l2;
04628 }
04629 
04630 /* Return truthvalue of whether T1 is the same tree structure as T2.
04631    Return 1 if they are the same.
04632    Return 0 if they are understandably different.
04633    Return -1 if either contains tree structure not understood by
04634    this function.  */
04635 
04636 int
04637 simple_cst_equal (tree t1, tree t2)
04638 {
04639   enum tree_code code1, code2;
04640   int cmp;
04641   int i;
04642 
04643   if (t1 == t2)
04644     return 1;
04645   if (t1 == 0 || t2 == 0)
04646     return 0;
04647 
04648   code1 = TREE_CODE (t1);
04649   code2 = TREE_CODE (t2);
04650 
04651   if (code1 == NOP_EXPR || code1 == CONVERT_EXPR || code1 == NON_LVALUE_EXPR)
04652     {
04653       if (code2 == NOP_EXPR || code2 == CONVERT_EXPR
04654     || code2 == NON_LVALUE_EXPR)
04655   return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
04656       else
04657   return simple_cst_equal (TREE_OPERAND (t1, 0), t2);
04658     }
04659 
04660   else if (code2 == NOP_EXPR || code2 == CONVERT_EXPR
04661      || code2 == NON_LVALUE_EXPR)
04662     return simple_cst_equal (t1, TREE_OPERAND (t2, 0));
04663 
04664   if (code1 != code2)
04665     return 0;
04666 
04667   switch (code1)
04668     {
04669     case INTEGER_CST:
04670       return (TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
04671         && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2));
04672 
04673     case REAL_CST:
04674       return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
04675 
04676     case STRING_CST:
04677       return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
04678         && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
04679        TREE_STRING_LENGTH (t1)));
04680 
04681     case CONSTRUCTOR:
04682       {
04683   unsigned HOST_WIDE_INT idx;
04684   VEC(constructor_elt, gc) *v1 = CONSTRUCTOR_ELTS (t1);
04685   VEC(constructor_elt, gc) *v2 = CONSTRUCTOR_ELTS (t2);
04686 
04687   if (VEC_length (constructor_elt, v1) != VEC_length (constructor_elt, v2))
04688     return false;
04689 
04690         for (idx = 0; idx < VEC_length (constructor_elt, v1); ++idx)
04691     /* ??? Should we handle also fields here? */
04692     if (!simple_cst_equal (VEC_index (constructor_elt, v1, idx)->value,
04693          VEC_index (constructor_elt, v2, idx)->value))
04694       return false;
04695   return true;
04696       }
04697 
04698     case SAVE_EXPR:
04699       return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
04700 
04701     case CALL_EXPR:
04702       cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
04703       if (cmp <= 0)
04704   return cmp;
04705       return
04706   simple_cst_list_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
04707 
04708     case TARGET_EXPR:
04709       /* Special case: if either target is an unallocated VAR_DECL,
04710    it means that it's going to be unified with whatever the
04711    TARGET_EXPR is really supposed to initialize, so treat it
04712    as being equivalent to anything.  */
04713       if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL
04714      && DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE
04715      && !DECL_RTL_SET_P (TREE_OPERAND (t1, 0)))
04716     || (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL
04717         && DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE
04718         && !DECL_RTL_SET_P (TREE_OPERAND (t2, 0))))
04719   cmp = 1;
04720       else
04721   cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
04722 
04723       if (cmp <= 0)
04724   return cmp;
04725 
04726       return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
04727 
04728     case WITH_CLEANUP_EXPR:
04729       cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
04730       if (cmp <= 0)
04731   return cmp;
04732 
04733       return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t1, 1));
04734 
04735     case COMPONENT_REF:
04736       if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1))
04737   return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
04738 
04739       return 0;
04740 
04741     case VAR_DECL:
04742     case PARM_DECL:
04743     case CONST_DECL:
04744     case FUNCTION_DECL:
04745       return 0;
04746 
04747     default:
04748       break;
04749     }
04750 
04751   /* This general rule works for most tree codes.  All exceptions should be
04752      handled above.  If this is a language-specific tree code, we can't
04753      trust what might be in the operand, so say we don't know
04754      the situation.  */
04755   if ((int) code1 >= (int) LAST_AND_UNUSED_TREE_CODE)
04756     return -1;
04757 
04758   switch (TREE_CODE_CLASS (code1))
04759     {
04760     case tcc_unary:
04761     case tcc_binary:
04762     case tcc_comparison:
04763     case tcc_expression:
04764     case tcc_reference:
04765     case tcc_statement:
04766       cmp = 1;
04767       for (i = 0; i < TREE_CODE_LENGTH (code1); i++)
04768   {
04769     cmp = simple_cst_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i));
04770     if (cmp <= 0)
04771       return cmp;
04772   }
04773 
04774       return cmp;
04775 
04776     default:
04777       return -1;
04778     }
04779 }
04780 
04781 /* Compare the value of T, an INTEGER_CST, with U, an unsigned integer value.
04782    Return -1, 0, or 1 if the value of T is less than, equal to, or greater
04783    than U, respectively.  */
04784 
04785 int
04786 compare_tree_int (tree t, unsigned HOST_WIDE_INT u)
04787 {
04788   if (tree_int_cst_sgn (t) < 0)
04789     return -1;
04790   else if (TREE_INT_CST_HIGH (t) != 0)
04791     return 1;
04792   else if (TREE_INT_CST_LOW (t) == u)
04793     return 0;
04794   else if (TREE_INT_CST_LOW (t) < u)
04795     return -1;
04796   else
04797     return 1;
04798 }
04799 
04800 /* Return true if CODE represents an associative tree code.  Otherwise
04801    return false.  */
04802 bool
04803 associative_tree_code (enum tree_code code)
04804 {
04805   switch (code)
04806     {
04807     case BIT_IOR_EXPR:
04808     case BIT_AND_EXPR:
04809     case BIT_XOR_EXPR:
04810     case PLUS_EXPR:
04811     case MULT_EXPR:
04812     case MIN_EXPR:
04813     case MAX_EXPR:
04814       return true;
04815 
04816     default:
04817       break;
04818     }
04819   return false;
04820 }
04821 
04822 /* Return true if CODE represents a commutative tree code.  Otherwise
04823    return false.  */
04824 bool
04825 commutative_tree_code (enum tree_code code)
04826 {
04827   switch (code)
04828     {
04829     case PLUS_EXPR:
04830     case MULT_EXPR:
04831     case MIN_EXPR:
04832     case MAX_EXPR:
04833     case BIT_IOR_EXPR:
04834     case BIT_XOR_EXPR:
04835     case BIT_AND_EXPR:
04836     case NE_EXPR:
04837     case EQ_EXPR:
04838     case UNORDERED_EXPR:
04839     case ORDERED_EXPR:
04840     case UNEQ_EXPR:
04841     case LTGT_EXPR:
04842     case TRUTH_AND_EXPR:
04843     case TRUTH_XOR_EXPR:
04844     case TRUTH_OR_EXPR:
04845       return true;
04846 
04847     default:
04848       break;
04849     }
04850   return false;
04851 }
04852 
04853 /* Generate a hash value for an expression.  This can be used iteratively
04854    by passing a previous result as the "val" argument.
04855 
04856    This function is intended to produce the same hash for expressions which
04857    would compare equal using operand_equal_p.  */
04858 
04859 hashval_t
04860 iterative_hash_expr (tree t, hashval_t val)
04861 {
04862   int i;
04863   enum tree_code code;
04864   char class;
04865 
04866   if (t == NULL_TREE)
04867     return iterative_hash_pointer (t, val);
04868 
04869   code = TREE_CODE (t);
04870 
04871   switch (code)
04872     {
04873     /* Alas, constants aren't shared, so we can't rely on pointer
04874        identity.  */
04875     case INTEGER_CST:
04876       val = iterative_hash_host_wide_int (TREE_INT_CST_LOW (t), val);
04877       return iterative_hash_host_wide_int (TREE_INT_CST_HIGH (t), val);
04878     case REAL_CST:
04879       {
04880   unsigned int val2 = real_hash (TREE_REAL_CST_PTR (t));
04881 
04882   return iterative_hash_hashval_t (val2, val);
04883       }
04884     case STRING_CST:
04885       return iterative_hash (TREE_STRING_POINTER (t),
04886            TREE_STRING_LENGTH (t), val);
04887     case COMPLEX_CST:
04888       val = iterative_hash_expr (TREE_REALPART (t), val);
04889       return iterative_hash_expr (TREE_IMAGPART (t), val);
04890     case VECTOR_CST:
04891       return iterative_hash_expr (TREE_VECTOR_CST_ELTS (t), val);
04892 
04893     case SSA_NAME:
04894     case VALUE_HANDLE:
04895       /* we can just compare by pointer.  */
04896       return iterative_hash_pointer (t, val);
04897 
04898     case TREE_LIST:
04899       /* A list of expressions, for a CALL_EXPR or as the elements of a
04900    VECTOR_CST.  */
04901       for (; t; t = TREE_CHAIN (t))
04902   val = iterative_hash_expr (TREE_VALUE (t), val);
04903       return val;
04904     case CONSTRUCTOR:
04905       {
04906   unsigned HOST_WIDE_INT idx;
04907   tree field, value;
04908   FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t), idx, field, value)
04909     {
04910       val = iterative_hash_expr (field, val);
04911       val = iterative_hash_expr (value, val);
04912     }
04913   return val;
04914       }
04915     case FUNCTION_DECL:
04916       /* When referring to a built-in FUNCTION_DECL, use the
04917    __builtin__ form.  Otherwise nodes that compare equal
04918    according to operand_equal_p might get different
04919    hash codes.  */
04920       if (DECL_BUILT_IN (t))
04921   {
04922     val = iterative_hash_pointer (built_in_decls[DECL_FUNCTION_CODE (t)], 
04923               val);
04924     return val;
04925   }
04926       /* else FALL THROUGH */
04927     default:
04928       class = TREE_CODE_CLASS (code);
04929 
04930       if (class == tcc_declaration)
04931   {
04932     /* DECL's have a unique ID */
04933     val = iterative_hash_host_wide_int (DECL_UID (t), val);
04934   }
04935       else
04936   {
04937     gcc_assert (IS_EXPR_CODE_CLASS (class));
04938     
04939     val = iterative_hash_object (code, val);
04940 
04941     /* Don't hash the type, that can lead to having nodes which
04942        compare equal according to operand_equal_p, but which
04943        have different hash codes.  */
04944     if (code == NOP_EXPR
04945         || code == CONVERT_EXPR
04946         || code == NON_LVALUE_EXPR)
04947       {
04948         /* Make sure to include signness in the hash computation.  */
04949         val += TYPE_UNSIGNED (TREE_TYPE (t));
04950         val = iterative_hash_expr (TREE_OPERAND (t, 0), val);
04951       }
04952 
04953     else if (commutative_tree_code (code))
04954       {
04955         /* It's a commutative expression.  We want to hash it the same
04956      however it appears.  We do this by first hashing both operands
04957      and then rehashing based on the order of their independent
04958      hashes.  */
04959         hashval_t one = iterative_hash_expr (TREE_OPERAND (t, 0), 0);
04960         hashval_t two = iterative_hash_expr (TREE_OPERAND (t, 1), 0);
04961         hashval_t t;
04962 
04963         if (one > two)
04964     t = one, one = two, two = t;
04965 
04966         val = iterative_hash_hashval_t (one, val);
04967         val = iterative_hash_hashval_t (two, val);
04968       }
04969     else
04970       for (i = TREE_CODE_LENGTH (code) - 1; i >= 0; --i)
04971         val = iterative_hash_expr (TREE_OPERAND (t, i), val);
04972   }
04973       return val;
04974       break;
04975     }
04976 }
04977 
04978 /* Constructors for pointer, array and function types.
04979    (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
04980    constructed by language-dependent code, not here.)  */
04981 
04982 /* Construct, lay out and return the type of pointers to TO_TYPE with
04983    mode MODE.  If CAN_ALIAS_ALL is TRUE, indicate this type can
04984    reference all of memory. If such a type has already been
04985    constructed, reuse it.  */
04986 
04987 tree
04988 build_pointer_type_for_mode (tree to_type, enum machine_mode mode,
04989            bool can_alias_all)
04990 {
04991   tree t;
04992 
04993   if (to_type == error_mark_node)
04994     return error_mark_node;
04995 
04996   /* In some cases, languages will have things that aren't a POINTER_TYPE
04997      (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_POINTER_TO.
04998      In that case, return that type without regard to the rest of our
04999      operands.
05000 
05001      ??? This is a kludge, but consistent with the way this function has
05002      always operated and there doesn't seem to be a good way to avoid this
05003      at the moment.  */
05004   if (TYPE_POINTER_TO (to_type) != 0
05005       && TREE_CODE (TYPE_POINTER_TO (to_type)) != POINTER_TYPE)
05006     return TYPE_POINTER_TO (to_type);
05007 
05008   /* First, if we already have a type for pointers to TO_TYPE and it's
05009      the proper mode, use it.  */
05010   for (t = TYPE_POINTER_TO (to_type); t; t = TYPE_NEXT_PTR_TO (t))
05011     if (TYPE_MODE (t) == mode && TYPE_REF_CAN_ALIAS_ALL (t) == can_alias_all)
05012       return t;
05013 
05014   t = make_node (POINTER_TYPE);
05015 
05016   TREE_TYPE (t) = to_type;
05017   TYPE_MODE (t) = mode;
05018   TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all;
05019   TYPE_NEXT_PTR_TO (t) = TYPE_POINTER_TO (to_type);
05020   TYPE_POINTER_TO (to_type) = t;
05021 
05022   /* Lay out the type.  This function has many callers that are concerned
05023      with expression-construction, and this simplifies them all.  */
05024   layout_type (t);
05025 
05026   return t;
05027 }
05028 
05029 /* By default build pointers in ptr_mode.  */
05030 
05031 tree
05032 build_pointer_type (tree to_type)
05033 {
05034   return build_pointer_type_for_mode (to_type, ptr_mode, false);
05035 }
05036 
05037 /* Same as build_pointer_type_for_mode, but for REFERENCE_TYPE.  */
05038 
05039 tree
05040 build_reference_type_for_mode (tree to_type, enum machine_mode mode,
05041              bool can_alias_all)
05042 {
05043   tree t;
05044 
05045   /* In some cases, languages will have things that aren't a REFERENCE_TYPE
05046      (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_REFERENCE_TO.
05047      In that case, return that type without regard to the rest of our
05048      operands.
05049 
05050      ??? This is a kludge, but consistent with the way this function has
05051      always operated and there doesn't seem to be a good way to avoid this
05052      at the moment.  */
05053   if (TYPE_REFERENCE_TO (to_type) != 0
05054       && TREE_CODE (TYPE_REFERENCE_TO (to_type)) != REFERENCE_TYPE)
05055     return TYPE_REFERENCE_TO (to_type);
05056 
05057   /* First, if we already have a type for pointers to TO_TYPE and it's
05058      the proper mode, use it.  */
05059   for (t = TYPE_REFERENCE_TO (to_type); t; t = TYPE_NEXT_REF_TO (t))
05060     if (TYPE_MODE (t) == mode && TYPE_REF_CAN_ALIAS_ALL (t) == can_alias_all)
05061       return t;
05062 
05063   t = make_node (REFERENCE_TYPE);
05064 
05065   TREE_TYPE (t) = to_type;
05066   TYPE_MODE (t) = mode;
05067   TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all;
05068   TYPE_NEXT_REF_TO (t) = TYPE_REFERENCE_TO (to_type);
05069   TYPE_REFERENCE_TO (to_type) = t;
05070 
05071   layout_type (t);
05072 
05073   return t;
05074 }
05075 
05076 
05077 /* Build the node for the type of references-to-TO_TYPE by default
05078    in ptr_mode.  */
05079 
05080 tree
05081 build_reference_type (tree to_type)
05082 {
05083   return build_reference_type_for_mode (to_type, ptr_mode, false);
05084 }
05085 
05086 /* Build a type that is compatible with t but has no cv quals anywhere
05087    in its type, thus
05088 
05089    const char *const *const *  ->  char ***.  */
05090 
05091 tree
05092 build_type_no_quals (tree t)
05093 {
05094   switch (TREE_CODE (t))
05095     {
05096     case POINTER_TYPE:
05097       return build_pointer_type_for_mode (build_type_no_quals (TREE_TYPE (t)),
05098             TYPE_MODE (t),
05099             TYPE_REF_CAN_ALIAS_ALL (t));
05100     case REFERENCE_TYPE:
05101       return
05102   build_reference_type_for_mode (build_type_no_quals (TREE_TYPE (t)),
05103                TYPE_MODE (t),
05104                TYPE_REF_CAN_ALIAS_ALL (t));
05105     default:
05106       return TYPE_MAIN_VARIANT (t);
05107     }
05108 }
05109 
05110 /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
05111    MAXVAL should be the maximum value in the domain
05112    (one less than the length of the array).
05113 
05114    The maximum value that MAXVAL can have is INT_MAX for a HOST_WIDE_INT.
05115    We don't enforce this limit, that is up to caller (e.g. language front end).
05116    The limit exists because the result is a signed type and we don't handle
05117    sizes that use more than one HOST_WIDE_INT.  */
05118 
05119 tree
05120 build_index_type (tree maxval)
05121 {
05122   tree itype = make_node (INTEGER_TYPE);
05123 
05124   TREE_TYPE (itype) = sizetype;
05125   TYPE_PRECISION (itype) = TYPE_PRECISION (sizetype);
05126   TYPE_MIN_VALUE (itype) = size_zero_node;
05127   TYPE_MAX_VALUE (itype) = fold_convert (sizetype, maxval);
05128   TYPE_MODE (itype) = TYPE_MODE (sizetype);
05129   TYPE_SIZE (itype) = TYPE_SIZE (sizetype);
05130   TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (sizetype);
05131   TYPE_ALIGN (itype) = TYPE_ALIGN (sizetype);
05132   TYPE_USER_ALIGN (itype) = TYPE_USER_ALIGN (sizetype);
05133 
05134   if (host_integerp (maxval, 1))
05135     return type_hash_canon (tree_low_cst (maxval, 1), itype);
05136   else
05137     return itype;
05138 }
05139 
05140 /* Builds a signed or unsigned integer type of precision PRECISION.
05141    Used for C bitfields whose precision does not match that of
05142    built-in target types.  */
05143 tree
05144 build_nonstandard_integer_type (unsigned HOST_WIDE_INT precision,
05145         int unsignedp)
05146 {
05147   tree itype = make_node (INTEGER_TYPE);
05148 
05149   TYPE_PRECISION (itype) = precision;
05150 
05151   if (unsignedp)
05152     fixup_unsigned_type (itype);
05153   else
05154     fixup_signed_type (itype);
05155 
05156   if (host_integerp (TYPE_MAX_VALUE (itype), 1))
05157     return type_hash_canon (tree_low_cst (TYPE_MAX_VALUE (itype), 1), itype);
05158 
05159   return itype;
05160 }
05161 
05162 /* Create a range of some discrete type TYPE (an INTEGER_TYPE,
05163    ENUMERAL_TYPE or BOOLEAN_TYPE), with low bound LOWVAL and
05164    high bound HIGHVAL.  If TYPE is NULL, sizetype is used.  */
05165 
05166 tree
05167 build_range_type (tree type, tree lowval, tree highval)
05168 {
05169   tree itype = make_node (INTEGER_TYPE);
05170 
05171   TREE_TYPE (itype) = type;
05172   if (type == NULL_TREE)
05173     type = sizetype;
05174 
05175   TYPE_MIN_VALUE (itype) = fold_convert (type, lowval);
05176   TYPE_MAX_VALUE (itype) = highval ? fold_convert (type, highval) : NULL;
05177 
05178   TYPE_PRECISION (itype) = TYPE_PRECISION (type);
05179   TYPE_MODE (itype) = TYPE_MODE (type);
05180   TYPE_SIZE (itype) = TYPE_SIZE (type);
05181   TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (type);
05182   TYPE_ALIGN (itype) = TYPE_ALIGN (type);
05183   TYPE_USER_ALIGN (itype) = TYPE_USER_ALIGN (type);
05184 
05185   if (host_integerp (lowval, 0) && highval != 0 && host_integerp (highval, 0))
05186     return type_hash_canon (tree_low_cst (highval, 0)
05187           - tree_low_cst (lowval, 0),
05188           itype);
05189   else
05190     return itype;
05191 }
05192 
05193 /* Just like build_index_type, but takes lowval and highval instead
05194    of just highval (maxval).  */
05195 
05196 tree
05197 build_index_2_type (tree lowval, tree highval)
05198 {
05199   return build_range_type (sizetype, lowval, highval);
05200 }
05201 
05202 /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
05203    and number of elements specified by the range of values of INDEX_TYPE.
05204    If such a type has already been constructed, reuse it.  */
05205 
05206 tree
05207 build_array_type (tree elt_type, tree index_type)
05208 {
05209   tree t;
05210   hashval_t hashcode = 0;
05211 
05212   if (TREE_CODE (elt_type) == FUNCTION_TYPE)
05213     {
05214       error ("arrays of functions are not meaningful");
05215       elt_type = integer_type_node;
05216     }
05217 
05218   t = make_node (ARRAY_TYPE);
05219   TREE_TYPE (t) = elt_type;
05220   TYPE_DOMAIN (t) = index_type;
05221   
05222   if (index_type == 0)
05223     {
05224       tree save = t;
05225       hashcode = iterative_hash_object (TYPE_HASH (elt_type), hashcode);
05226       t = type_hash_canon (hashcode, t);
05227       if (save == t)
05228   layout_type (t);
05229       return t;
05230     }
05231 
05232   hashcode = iterative_hash_object (TYPE_HASH (elt_type), hashcode);
05233   hashcode = iterative_hash_object (TYPE_HASH (index_type), hashcode);
05234   t = type_hash_canon (hashcode, t);
05235 
05236   if (!COMPLETE_TYPE_P (t))
05237     layout_type (t);
05238   return t;
05239 }
05240 
05241 /* Return the TYPE of the elements comprising
05242    the innermost dimension of ARRAY.  */
05243 
05244 tree
05245 get_inner_array_type (tree array)
05246 {
05247   tree type = TREE_TYPE (array);
05248 
05249   while (TREE_CODE (type) == ARRAY_TYPE)
05250     type = TREE_TYPE (type);
05251 
05252   return type;
05253 }
05254 
05255 /* Construct, lay out and return
05256    the type of functions returning type VALUE_TYPE
05257    given arguments of types ARG_TYPES.
05258    ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
05259    are data type nodes for the arguments of the function.
05260    If such a type has already been constructed, reuse it.  */
05261 
05262 tree
05263 build_function_type (tree value_type, tree arg_types)
05264 {
05265   tree t;
05266   hashval_t hashcode = 0;
05267 
05268   if (TREE_CODE (value_type) == FUNCTION_TYPE)
05269     {
05270       error ("function return type cannot be function");
05271       value_type = integer_type_node;
05272     }
05273 
05274   /* Make a node of the sort we want.  */
05275   t = make_node (FUNCTION_TYPE);
05276   TREE_TYPE (t) = value_type;
05277   TYPE_ARG_TYPES (t) = arg_types;
05278 
05279   /* If we already have such a type, use the old one.  */
05280   hashcode = iterative_hash_object (TYPE_HASH (value_type), hashcode);
05281   hashcode = type_hash_list (arg_types, hashcode);
05282   t = type_hash_canon (hashcode, t);
05283 
05284   if (!COMPLETE_TYPE_P (t))
05285     layout_type (t);
05286   return t;
05287 }
05288 
05289 /* Build a function type.  The RETURN_TYPE is the type returned by the
05290    function.  If additional arguments are provided, they are
05291    additional argument types.  The list of argument types must always
05292    be terminated by NULL_TREE.  */
05293 
05294 tree
05295 build_function_type_list (tree return_type, ...)
05296 {
05297   tree t, args, last;
05298   va_list p;
05299 
05300   va_start (p, return_type);
05301 
05302   t = va_arg (p, tree);
05303   for (args = NULL_TREE; t != NULL_TREE; t = va_arg (p, tree))
05304     args = tree_cons (NULL_TREE, t, args);
05305 
05306   if (args == NULL_TREE)
05307     args = void_list_node;
05308   else
05309     {
05310       last = args;
05311       args = nreverse (args);
05312       TREE_CHAIN (last) = void_list_node;
05313     }
05314   args = build_function_type (return_type, args);
05315 
05316   va_end (p);
05317   return args;
05318 }
05319 
05320 /* Build a METHOD_TYPE for a member of BASETYPE.  The RETTYPE (a TYPE)
05321    and ARGTYPES (a TREE_LIST) are the return type and arguments types
05322    for the method.  An implicit additional parameter (of type
05323    pointer-to-BASETYPE) is added to the ARGTYPES.  */
05324 
05325 tree
05326 build_method_type_directly (tree basetype,
05327           tree rettype,
05328           tree argtypes)
05329 {
05330   tree t;
05331   tree ptype;
05332   int hashcode = 0;
05333 
05334   /* Make a node of the sort we want.  */
05335   t = make_node (METHOD_TYPE);
05336 
05337   TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
05338   TREE_TYPE (t) = rettype;
05339   ptype = build_pointer_type (basetype);
05340 
05341   /* The actual arglist for this function includes a "hidden" argument
05342      which is "this".  Put it into the list of argument types.  */
05343   argtypes = tree_cons (NULL_TREE, ptype, argtypes);
05344   TYPE_ARG_TYPES (t) = argtypes;
05345 
05346   /* If we already have such a type, use the old one.  */
05347   hashcode = iterative_hash_object (TYPE_HASH (basetype), hashcode);
05348   hashcode = iterative_hash_object (TYPE_HASH (rettype), hashcode);
05349   hashcode = type_hash_list (argtypes, hashcode);
05350   t = type_hash_canon (hashcode, t);
05351 
05352   if (!COMPLETE_TYPE_P (t))
05353     layout_type (t);
05354 
05355   return t;
05356 }
05357 
05358 /* Construct, lay out and return the type of methods belonging to class
05359    BASETYPE and whose arguments and values are described by TYPE.
05360    If that type exists already, reuse it.
05361    TYPE must be a FUNCTION_TYPE node.  */
05362 
05363 tree
05364 build_method_type (tree basetype, tree type)
05365 {
05366   gcc_assert (TREE_CODE (type) == FUNCTION_TYPE);
05367 
05368   return build_method_type_directly (basetype,
05369              TREE_TYPE (type),
05370              TYPE_ARG_TYPES (type));
05371 }
05372 
05373 /* Construct, lay out and return the type of offsets to a value
05374    of type TYPE, within an object of type BASETYPE.
05375    If a suitable offset type exists already, reuse it.  */
05376 
05377 tree
05378 build_offset_type (tree basetype, tree type)
05379 {
05380   tree t;
05381   hashval_t hashcode = 0;
05382 
05383   /* Make a node of the sort we want.  */
05384   t = make_node (OFFSET_TYPE);
05385 
05386   TYPE_OFFSET_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
05387   TREE_TYPE (t) = type;
05388 
05389   /* If we already have such a type, use the old one.  */
05390   hashcode = iterative_hash_object (TYPE_HASH (basetype), hashcode);
05391   hashcode = iterative_hash_object (TYPE_HASH (type), hashcode);
05392   t = type_hash_canon (hashcode, t);
05393 
05394   if (!COMPLETE_TYPE_P (t))
05395     layout_type (t);
05396 
05397   return t;
05398 }
05399 
05400 /* Create a complex type whose components are COMPONENT_TYPE.  */
05401 
05402 tree
05403 build_complex_type (tree component_type)
05404 {
05405   tree t;
05406   hashval_t hashcode;
05407 
05408   /* Make a node of the sort we want.  */
05409   t = make_node (COMPLEX_TYPE);
05410 
05411   TREE_TYPE (t) = TYPE_MAIN_VARIANT (component_type);
05412 
05413   /* If we already have such a type, use the old one.  */
05414   hashcode = iterative_hash_object (TYPE_HASH (component_type), 0);
05415   t = type_hash_canon (hashcode, t);
05416 
05417   if (!COMPLETE_TYPE_P (t))
05418     layout_type (t);
05419 
05420   /* If we are writing Dwarf2 output we need to create a name,
05421      since complex is a fundamental type.  */
05422   if ((write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
05423       && ! TYPE_NAME (t))
05424     {
05425       const char *name;
05426       if (component_type == char_type_node)
05427   name = "complex char";
05428       else if (component_type == signed_char_type_node)
05429   name = "complex signed char";
05430       else if (component_type == unsigned_char_type_node)
05431   name = "complex unsigned char";
05432       else if (component_type == short_integer_type_node)
05433   name = "complex short int";
05434       else if (component_type == short_unsigned_type_node)
05435   name = "complex short unsigned int";
05436       else if (component_type == integer_type_node)
05437   name = "complex int";
05438       else if (component_type == unsigned_type_node)
05439   name = "complex unsigned int";
05440       else if (component_type == long_integer_type_node)
05441   name = "complex long int";
05442       else if (component_type == long_unsigned_type_node)
05443   name = "complex long unsigned int";
05444       else if (component_type == long_long_integer_type_node)
05445   name = "complex long long int";
05446       else if (component_type == long_long_unsigned_type_node)
05447   name = "complex long long unsigned int";
05448       else
05449   name = 0;
05450 
05451       if (name != 0)
05452   TYPE_NAME (t) = get_identifier (name);
05453     }
05454 
05455   return build_qualified_type (t, TYPE_QUALS (component_type));
05456 }
05457 
05458 /* Return OP, stripped of any conversions to wider types as much as is safe.
05459    Converting the value back to OP's type makes a value equivalent to OP.
05460 
05461    If FOR_TYPE is nonzero, we return a value which, if converted to
05462    type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
05463 
05464    If FOR_TYPE is nonzero, unaligned bit-field references may be changed to the
05465    narrowest type that can hold the value, even if they don't exactly fit.
05466    Otherwise, bit-field references are changed to a narrower type
05467    only if they can be fetched directly from memory in that type.
05468 
05469    OP must have integer, real or enumeral type.  Pointers are not allowed!
05470 
05471    There are some cases where the obvious value we could return
05472    would regenerate to OP if converted to OP's type,
05473    but would not extend like OP to wider types.
05474    If FOR_TYPE indicates such extension is contemplated, we eschew such values.
05475    For example, if OP is (unsigned short)(signed char)-1,
05476    we avoid returning (signed char)-1 if FOR_TYPE is int,
05477    even though extending that to an unsigned short would regenerate OP,
05478    since the result of extending (signed char)-1 to (int)
05479    is different from (int) OP.  */
05480 
05481 tree
05482 get_unwidened (tree op, tree for_type)
05483 {
05484   /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension.  */
05485   tree type = TREE_TYPE (op);
05486   unsigned final_prec
05487     = TYPE_PRECISION (for_type != 0 ? for_type : type);
05488   int uns
05489     = (for_type != 0 && for_type != type
05490        && final_prec > TYPE_PRECISION (type)
05491        && TYPE_UNSIGNED (type));
05492   tree win = op;
05493 
05494   while (TREE_CODE (op) == NOP_EXPR
05495    || TREE_CODE (op) == CONVERT_EXPR)
05496     {
05497       int bitschange;
05498 
05499       /* TYPE_PRECISION on vector types has different meaning
05500    (TYPE_VECTOR_SUBPARTS) and casts from vectors are view conversions,
05501    so avoid them here.  */
05502       if (TREE_CODE (TREE_TYPE (TREE_OPERAND (op, 0))) == VECTOR_TYPE)
05503   break;
05504 
05505       bitschange = TYPE_PRECISION (TREE_TYPE (op))
05506        - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
05507 
05508       /* Truncations are many-one so cannot be removed.
05509    Unless we are later going to truncate down even farther.  */
05510       if (bitschange < 0
05511     && final_prec > TYPE_PRECISION (TREE_TYPE (op)))
05512   break;
05513 
05514       /* See what's inside this conversion.  If we decide to strip it,
05515    we will set WIN.  */
05516       op = TREE_OPERAND (op, 0);
05517 
05518       /* If we have not stripped any zero-extensions (uns is 0),
05519    we can strip any kind of extension.
05520    If we have previously stripped a zero-extension,
05521    only zero-extensions can safely be stripped.
05522    Any extension can be stripped if the bits it would produce
05523    are all going to be discarded later by truncating to FOR_TYPE.  */
05524 
05525       if (bitschange > 0)
05526   {
05527     if (! uns || final_prec <= TYPE_PRECISION (TREE_TYPE (op)))
05528       win = op;
05529     /* TYPE_UNSIGNED says whether this is a zero-extension.
05530        Let's avoid computing it if it does not affect WIN
05531        and if UNS will not be needed again.  */
05532     if ((uns
05533          || TREE_CODE (op) == NOP_EXPR
05534          || TREE_CODE (op) == CONVERT_EXPR)
05535         && TYPE_UNSIGNED (TREE_TYPE (op)))
05536       {
05537         uns = 1;
05538         win = op;
05539       }
05540   }
05541     }
05542 
05543   if (TREE_CODE (op) == COMPONENT_REF
05544       /* Since type_for_size always gives an integer type.  */
05545       && TREE_CODE (type) != REAL_TYPE
05546       /* Don't crash if field not laid out yet.  */
05547       && DECL_SIZE (TREE_OPERAND (op, 1)) != 0
05548       && host_integerp (DECL_SIZE (TREE_OPERAND (op, 1)), 1))
05549     {
05550       unsigned int innerprec
05551   = tree_low_cst (DECL_SIZE (TREE_OPERAND (op, 1)), 1);
05552       int unsignedp = (DECL_UNSIGNED (TREE_OPERAND (op, 1))
05553            || TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op, 1))));
05554       type = lang_hooks.types.type_for_size (innerprec, unsignedp);
05555 
05556       /* We can get this structure field in the narrowest type it fits in.
05557    If FOR_TYPE is 0, do this only for a field that matches the
05558    narrower type exactly and is aligned for it
05559    The resulting extension to its nominal type (a fullword type)
05560    must fit the same conditions as for other extensions.  */
05561 
05562       if (type != 0
05563     && INT_CST_LT_UNSIGNED (TYPE_SIZE (type), TYPE_SIZE (TREE_TYPE (op)))
05564     && (for_type || ! DECL_BIT_FIELD (TREE_OPERAND (op, 1)))
05565     && (! uns || final_prec <= innerprec || unsignedp))
05566   {
05567     win = build3 (COMPONENT_REF, type, TREE_OPERAND (op, 0),
05568       TREE_OPERAND (op, 1), NULL_TREE);
05569     TREE_SIDE_EFFECTS (win) = TREE_SIDE_EFFECTS (op);
05570     TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
05571   }
05572     }
05573 
05574   return win;
05575 }
05576 
05577 /* Return OP or a simpler expression for a narrower value
05578    which can be sign-extended or zero-extended to give back OP.
05579    Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
05580    or 0 if the value should be sign-extended.  */
05581 
05582 tree
05583 get_narrower (tree op, int *unsignedp_ptr)
05584 {
05585   int uns = 0;
05586   int first = 1;
05587   tree win = op;
05588   bool integral_p = INTEGRAL_TYPE_P (TREE_TYPE (op));
05589 
05590   while (TREE_CODE (op) == NOP_EXPR)
05591     {
05592       int bitschange
05593   = (TYPE_PRECISION (TREE_TYPE (op))
05594      - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0))));
05595 
05596       /* Truncations are many-one so cannot be removed.  */
05597       if (bitschange < 0)
05598   break;
05599 
05600       /* See what's inside this conversion.  If we decide to strip it,
05601    we will set WIN.  */
05602 
05603       if (bitschange > 0)
05604   {
05605     op = TREE_OPERAND (op, 0);
05606     /* An extension: the outermost one can be stripped,
05607        but remember whether it is zero or sign extension.  */
05608     if (first)
05609       uns = TYPE_UNSIGNED (TREE_TYPE (op));
05610     /* Otherwise, if a sign extension has been stripped,
05611        only sign extensions can now be stripped;
05612        if a zero extension has been stripped, only zero-extensions.  */
05613     else if (uns != TYPE_UNSIGNED (TREE_TYPE (op)))
05614       break;
05615     first = 0;
05616   }
05617       else /* bitschange == 0 */
05618   {
05619     /* A change in nominal type can always be stripped, but we must
05620        preserve the unsignedness.  */
05621     if (first)
05622       uns = TYPE_UNSIGNED (TREE_TYPE (op));
05623     first = 0;
05624     op = TREE_OPERAND (op, 0);
05625     /* Keep trying to narrow, but don't assign op to win if it
05626        would turn an integral type into something else.  */
05627     if (INTEGRAL_TYPE_P (TREE_TYPE (op)) != integral_p)
05628       continue;
05629   }
05630 
05631       win = op;
05632     }
05633 
05634   if (TREE_CODE (op) == COMPONENT_REF
05635       /* Since type_for_size always gives an integer type.  */
05636       && TREE_CODE (TREE_TYPE (op)) != REAL_TYPE
05637       /* Ensure field is laid out already.  */
05638       && DECL_SIZE (TREE_OPERAND (op, 1)) != 0
05639       && host_integerp (DECL_SIZE (TREE_OPERAND (op, 1)), 1))
05640     {
05641       unsigned HOST_WIDE_INT innerprec
05642   = tree_low_cst (DECL_SIZE (TREE_OPERAND (op, 1)), 1);
05643       int unsignedp = (DECL_UNSIGNED (TREE_OPERAND (op, 1))
05644            || TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op, 1))));
05645       tree type = lang_hooks.types.type_for_size (innerprec, unsignedp);
05646 
05647       /* We can get this structure field in a narrower type that fits it,
05648    but the resulting extension to its nominal type (a fullword type)
05649    must satisfy the same conditions as for other extensions.
05650 
05651    Do this only for fields that are aligned (not bit-fields),
05652    because when bit-field insns will be used there is no
05653    advantage in doing this.  */
05654 
05655       if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
05656     && ! DECL_BIT_FIELD (TREE_OPERAND (op, 1))
05657     && (first || uns == DECL_UNSIGNED (TREE_OPERAND (op, 1)))
05658     && type != 0)
05659   {
05660     if (first)
05661       uns = DECL_UNSIGNED (TREE_OPERAND (op, 1));
05662     win = fold_convert (type, op);
05663   }
05664     }
05665 
05666   *unsignedp_ptr = uns;
05667   return win;
05668 }
05669 
05670 /* Nonzero if integer constant C has a value that is permissible
05671    for type TYPE (an INTEGER_TYPE).  */
05672 
05673 int
05674 int_fits_type_p (tree c, tree type)
05675 {
05676   tree type_low_bound = TYPE_MIN_VALUE (type);
05677   tree type_high_bound = TYPE_MAX_VALUE (type);
05678   bool ok_for_low_bound, ok_for_high_bound;
05679   tree tmp;
05680 
05681   /* If at least one bound of the type is a constant integer, we can check
05682      ourselves and maybe make a decision. If no such decision is possible, but
05683      this type is a subtype, try checking against that.  Otherwise, use
05684      force_fit_type, which checks against the precision.
05685 
05686      Compute the status for each possibly constant bound, and return if we see
05687      one does not match. Use ok_for_xxx_bound for this purpose, assigning -1
05688      for "unknown if constant fits", 0 for "constant known *not* to fit" and 1
05689      for "constant known to fit".  */
05690 
05691   /* Check if C >= type_low_bound.  */
05692   if (type_low_bound && TREE_CODE (type_low_bound) == INTEGER_CST)
05693     {
05694       if (tree_int_cst_lt (c, type_low_bound))
05695   return 0;
05696       ok_for_low_bound = true;
05697     }
05698   else
05699     ok_for_low_bound = false;
05700 
05701   /* Check if c <= type_high_bound.  */
05702   if (type_high_bound && TREE_CODE (type_high_bound) == INTEGER_CST)
05703     {
05704       if (tree_int_cst_lt (type_high_bound, c))
05705   return 0;
05706       ok_for_high_bound = true;
05707     }
05708   else
05709     ok_for_high_bound = false;
05710 
05711   /* If the constant fits both bounds, the result is known.  */
05712   if (ok_for_low_bound && ok_for_high_bound)
05713     return 1;
05714 
05715   /* Perform some generic filtering which may allow making a decision
05716      even if the bounds are not constant.  First, negative integers
05717      never fit in unsigned types, */
05718   if (TYPE_UNSIGNED (type) && tree_int_cst_sgn (c) < 0)
05719     return 0;
05720 
05721   /* Second, narrower types always fit in wider ones.  */
05722   if (TYPE_PRECISION (type) > TYPE_PRECISION (TREE_TYPE (c)))
05723     return 1;
05724 
05725   /* Third, unsigned integers with top bit set never fit signed types.  */
05726   if (! TYPE_UNSIGNED (type)
05727       && TYPE_UNSIGNED (TREE_TYPE (c))
05728       && tree_int_cst_msb (c))
05729     return 0;
05730 
05731   /* If we haven't been able to decide at this point, there nothing more we
05732      can check ourselves here.  Look at the base type if we have one and it
05733      has the same precision.  */
05734   if (TREE_CODE (type) == INTEGER_TYPE
05735       && TREE_TYPE (type) != 0
05736       && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (type)))
05737     return int_fits_type_p (c, TREE_TYPE (type));
05738 
05739   /* Or to force_fit_type, if nothing else.  */
05740   tmp = copy_node (c);
05741   TREE_TYPE (tmp) = type;
05742   tmp = force_fit_type (tmp, -1, false, false);
05743   return TREE_INT_CST_HIGH (tmp) == TREE_INT_CST_HIGH (c)
05744          && TREE_INT_CST_LOW (tmp) == TREE_INT_CST_LOW (c);
05745 }
05746 
05747 /* Subprogram of following function.  Called by walk_tree.
05748 
05749    Return *TP if it is an automatic variable or parameter of the
05750    function passed in as DATA.  */
05751 
05752 static tree
05753 find_var_from_fn (tree *tp, int *walk_subtrees, void *data)
05754 {
05755   tree fn = (tree) data;
05756 
05757   if (TYPE_P (*tp))
05758     *walk_subtrees = 0;
05759 
05760   else if (DECL_P (*tp)
05761      && lang_hooks.tree_inlining.auto_var_in_fn_p (*tp, fn))
05762     return *tp;
05763 
05764   return NULL_TREE;
05765 }
05766 
05767 /* Returns true if T is, contains, or refers to a type with variable
05768    size.  For METHOD_TYPEs and FUNCTION_TYPEs we exclude the
05769    arguments, but not the return type.  If FN is nonzero, only return
05770    true if a modifier of the type or position of FN is a variable or
05771    parameter inside FN.
05772 
05773    This concept is more general than that of C99 'variably modified types':
05774    in C99, a struct type is never variably modified because a VLA may not
05775    appear as a structure member.  However, in GNU C code like:
05776 
05777      struct S { int i[f()]; };
05778 
05779    is valid, and other languages may define similar constructs.  */
05780 
05781 bool
05782 variably_modified_type_p (tree type, tree fn)
05783 {
05784   tree t;
05785 
05786 /* Test if T is either variable (if FN is zero) or an expression containing
05787    a variable in FN.  */
05788 #define RETURN_TRUE_IF_VAR(T)           \
05789   do { tree _t = (T);             \
05790     if (_t && _t != error_mark_node && TREE_CODE (_t) != INTEGER_CST  \
05791         && (!fn || walk_tree (&_t, find_var_from_fn, fn, NULL)))  \
05792       return true;  } while (0)
05793 
05794   if (type == error_mark_node)
05795     return false;
05796 
05797   /* If TYPE itself has variable size, it is variably modified.  */
05798   RETURN_TRUE_IF_VAR (TYPE_SIZE (type));
05799   RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (type));
05800 
05801   switch (TREE_CODE (type))
05802     {
05803     case POINTER_TYPE:
05804     case REFERENCE_TYPE:
05805     case VECTOR_TYPE:
05806       if (variably_modified_type_p (TREE_TYPE (type), fn))
05807   return true;
05808       break;
05809 
05810     case FUNCTION_TYPE:
05811     case METHOD_TYPE:
05812       /* If TYPE is a function type, it is variably modified if the
05813    return type is variably modified.  */
05814       if (variably_modified_type_p (TREE_TYPE (type), fn))
05815     return true;
05816       break;
05817 
05818     case INTEGER_TYPE:
05819     case REAL_TYPE:
05820     case ENUMERAL_TYPE:
05821     case BOOLEAN_TYPE:
05822       /* Scalar types are variably modified if their end points
05823    aren't constant.  */
05824       RETURN_TRUE_IF_VAR (TYPE_MIN_VALUE (type));
05825       RETURN_TRUE_IF_VAR (TYPE_MAX_VALUE (type));
05826       break;
05827 
05828     case RECORD_TYPE:
05829     case UNION_TYPE:
05830     case QUAL_UNION_TYPE:
05831       /* We can't see if any of the fields are variably-modified by the
05832    definition we normally use, since that would produce infinite
05833    recursion via pointers.  */
05834       /* This is variably modified if some field's type is.  */
05835       for (t = TYPE_FIELDS (type); t; t = TREE_CHAIN (t))
05836   if (TREE_CODE (t) == FIELD_DECL)
05837     {
05838       RETURN_TRUE_IF_VAR (DECL_FIELD_OFFSET (t));
05839       RETURN_TRUE_IF_VAR (DECL_SIZE (t));
05840       RETURN_TRUE_IF_VAR (DECL_SIZE_UNIT (t));
05841 
05842       if (TREE_CODE (type) == QUAL_UNION_TYPE)
05843         RETURN_TRUE_IF_VAR (DECL_QUALIFIER (t));
05844     }
05845   break;
05846 
05847     case ARRAY_TYPE:
05848       /* Do not call ourselves to avoid infinite recursion.  This is
05849    variably modified if the element type is.  */
05850       RETURN_TRUE_IF_VAR (TYPE_SIZE (TREE_TYPE (type)));
05851       RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (TREE_TYPE (type)));
05852       break;
05853 
05854     default:
05855       break;
05856     }
05857 
05858   /* The current language may have other cases to check, but in general,
05859      all other types are not variably modified.  */
05860   return lang_hooks.tree_inlining.var_mod_type_p (type, fn);
05861 
05862 #undef RETURN_TRUE_IF_VAR
05863 }
05864 
05865 /* Given a DECL or TYPE, return the scope in which it was declared, or
05866    NULL_TREE if there is no containing scope.  */
05867 
05868 tree
05869 get_containing_scope (tree t)
05870 {
05871   return (TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t));
05872 }
05873 
05874 /* Return the innermost context enclosing DECL that is
05875    a FUNCTION_DECL, or zero if none.  */
05876 
05877 tree
05878 decl_function_context (tree decl)
05879 {
05880   tree context;
05881 
05882   if (TREE_CODE (decl) == ERROR_MARK)
05883     return 0;
05884 
05885   /* C++ virtual functions use DECL_CONTEXT for the class of the vtable
05886      where we look up the function at runtime.  Such functions always take
05887      a first argument of type 'pointer to real context'.
05888 
05889      C++ should really be fixed to use DECL_CONTEXT for the real context,
05890      and use something else for the "virtual context".  */
05891   else if (TREE_CODE (decl) == FUNCTION_DECL && DECL_VINDEX (decl))
05892     context
05893       = TYPE_MAIN_VARIANT
05894   (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
05895   else
05896     context = DECL_CONTEXT (decl);
05897 
05898   while (context && TREE_CODE (context) != FUNCTION_DECL)
05899     {
05900       if (TREE_CODE (context) == BLOCK)
05901   context = BLOCK_SUPERCONTEXT (context);
05902       else
05903   context = get_containing_scope (context);
05904     }
05905 
05906   return context;
05907 }
05908 
05909 /* Return the innermost context enclosing DECL that is
05910    a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
05911    TYPE_DECLs and FUNCTION_DECLs are transparent to this function.  */
05912 
05913 tree
05914 decl_type_context (tree decl)
05915 {
05916   tree context = DECL_CONTEXT (decl);
05917 
05918   while (context)
05919     switch (TREE_CODE (context))
05920       {
05921       case NAMESPACE_DECL:
05922       case TRANSLATION_UNIT_DECL:
05923   return NULL_TREE;
05924 
05925       case RECORD_TYPE:
05926       case UNION_TYPE:
05927       case QUAL_UNION_TYPE:
05928   return context;
05929 
05930       case TYPE_DECL:
05931       case FUNCTION_DECL:
05932   context = DECL_CONTEXT (context);
05933   break;
05934 
05935       case BLOCK:
05936   context = BLOCK_SUPERCONTEXT (context);
05937   break;
05938 
05939       default:
05940   gcc_unreachable ();
05941       }
05942 
05943   return NULL_TREE;
05944 }
05945 
05946 /* CALL is a CALL_EXPR.  Return the declaration for the function
05947    called, or NULL_TREE if the called function cannot be
05948    determined.  */
05949 
05950 tree
05951 get_callee_fndecl (tree call)
05952 {
05953   tree addr;
05954 
05955   if (call == error_mark_node)
05956     return call;
05957 
05958   /* It's invalid to call this function with anything but a
05959      CALL_EXPR.  */
05960   gcc_assert (TREE_CODE (call) == CALL_EXPR);
05961 
05962   /* The first operand to the CALL is the address of the function
05963      called.  */
05964   addr = TREE_OPERAND (call, 0);
05965 
05966   STRIP_NOPS (addr);
05967 
05968   /* If this is a readonly function pointer, extract its initial value.  */
05969   if (DECL_P (addr) && TREE_CODE (addr) != FUNCTION_DECL
05970       && TREE_READONLY (addr) && ! TREE_THIS_VOLATILE (addr)
05971       && DECL_INITIAL (addr))
05972     addr = DECL_INITIAL (addr);
05973 
05974   /* If the address is just `&f' for some function `f', then we know
05975      that `f' is being called.  */
05976   if (TREE_CODE (addr) == ADDR_EXPR
05977       && TREE_CODE (TREE_OPERAND (addr, 0)) == FUNCTION_DECL)
05978     return TREE_OPERAND (addr, 0);
05979 
05980   /* We couldn't figure out what was being called.  Maybe the front
05981      end has some idea.  */
05982   return lang_hooks.lang_get_callee_fndecl (call);
05983 }
05984 
05985 /* Print debugging information about tree nodes generated during the compile,
05986    and any language-specific information.  */
05987 
05988 void
05989 dump_tree_statistics (void)
05990 {
05991 #ifdef GATHER_STATISTICS
05992   int i;
05993   int total_nodes, total_bytes;
05994 #endif
05995 
05996   fprintf (stderr, "\n??? tree nodes created\n\n");
05997 #ifdef GATHER_STATISTICS
05998   fprintf (stderr, "Kind                   Nodes      Bytes\n");
05999   fprintf (stderr, "---------------------------------------\n");
06000   total_nodes = total_bytes = 0;
06001   for (i = 0; i < (int) all_kinds; i++)
06002     {
06003       fprintf (stderr, "%-20s %7d %10d\n", tree_node_kind_names[i],
06004          tree_node_counts[i], tree_node_sizes[i]);
06005       total_nodes += tree_node_counts[i];
06006       total_bytes += tree_node_sizes[i];
06007     }
06008   fprintf (stderr, "---------------------------------------\n");
06009   fprintf (stderr, "%-20s %7d %10d\n", "Total", total_nodes, total_bytes);
06010   fprintf (stderr, "---------------------------------------\n");
06011   ssanames_print_statistics ();
06012   phinodes_print_statistics ();
06013 #else
06014   fprintf (stderr, "(No per-node statistics)\n");
06015 #endif
06016   print_type_hash_statistics ();
06017   print_debug_expr_statistics ();
06018   print_value_expr_statistics ();
06019   print_restrict_base_statistics ();
06020   lang_hooks.print_statistics ();
06021 }
06022 
06023 #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s"
06024 
06025 /* Generate a crc32 of a string.  */
06026 
06027 unsigned
06028 crc32_string (unsigned chksum, const char *string)
06029 {
06030   do
06031     {
06032       unsigned value = *string << 24;
06033       unsigned ix;
06034 
06035       for (ix = 8; ix--; value <<= 1)
06036     {
06037       unsigned feedback;
06038 
06039       feedback = (value ^ chksum) & 0x80000000 ? 0x04c11db7 : 0;
06040     chksum <<= 1;
06041     chksum ^= feedback;
06042     }
06043     }
06044   while (*string++);
06045   return chksum;
06046 }
06047 
06048 /* P is a string that will be used in a symbol.  Mask out any characters
06049    that are not valid in that context.  */
06050 
06051 void
06052 clean_symbol_name (char *p)
06053 {
06054   for (; *p; p++)
06055     if (! (ISALNUM (*p)
06056 #ifndef NO_DOLLAR_IN_LABEL  /* this for `$'; unlikely, but... -- kr */
06057       || *p == '$'
06058 #endif
06059 #ifndef NO_DOT_IN_LABEL   /* this for `.'; unlikely, but...  */
06060       || *p == '.'
06061 #endif
06062      ))
06063       *p = '_';
06064 }
06065 
06066 /* Generate a name for a function unique to this translation unit.
06067    TYPE is some string to identify the purpose of this function to the
06068    linker or collect2.  */
06069 
06070 tree
06071 get_file_function_name_long (const char *type)
06072 {
06073   char *buf;
06074   const char *p;
06075   char *q;
06076 
06077   if (first_global_object_name)
06078     {
06079       p = first_global_object_name;
06080 
06081       /* For type 'F', the generated name must be unique not only to this
06082    translation unit but also to any given link.  Since global names
06083    can be overloaded, we concatenate the first global object name
06084    with a string derived from the file name of this object.  */
06085       if (!strcmp (type, "F"))
06086   {
06087     const char *file = main_input_filename;
06088 
06089     if (! file)
06090       file = input_filename;
06091 
06092     q = alloca (strlen (p) + 10);
06093     sprintf (q, "%s_%08X", p, crc32_string (0, file));
06094 
06095     p = q;
06096   }
06097     }
06098   else
06099     {
06100       /* We don't have anything that we know to be unique to this translation
06101    unit, so use what we do have and throw in some randomness.  */
06102       unsigned len;
06103       const char *name = weak_global_object_name;
06104       const char *file = main_input_filename;
06105 
06106       if (! name)
06107   name = "";
06108       if (! file)
06109   file = input_filename;
06110 
06111       len = strlen (file);
06112       q = alloca (9 * 2 + len + 1);
06113       memcpy (q, file, len + 1);
06114       clean_symbol_name (q);
06115 
06116       sprintf (q + len, "_%08X_%08X", crc32_string (0, name),
06117          crc32_string (0, flag_random_seed));
06118 
06119       p = q;
06120     }
06121 
06122   buf = alloca (sizeof (FILE_FUNCTION_FORMAT) + strlen (p) + strlen (type));
06123 
06124   /* Set up the name of the file-level functions we may need.
06125      Use a global object (which is already required to be unique over
06126      the program) rather than the file name (which imposes extra
06127      constraints).  */
06128   sprintf (buf, FILE_FUNCTION_FORMAT, type, p);
06129 
06130   return get_identifier (buf);
06131 }
06132 
06133 /* If KIND=='I', return a suitable global initializer (constructor) name.
06134    If KIND=='D', return a suitable global clean-up (destructor) name.  */
06135 
06136 tree
06137 get_file_function_name (int kind)
06138 {
06139   char p[2];
06140 
06141   p[0] = kind;
06142   p[1] = 0;
06143 
06144   return get_file_function_name_long (p);
06145 }
06146 
06147 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
06148 
06149 /* Complain that the tree code of NODE does not match the expected 0
06150    terminated list of trailing codes. The trailing code list can be
06151    empty, for a more vague error message.  FILE, LINE, and FUNCTION
06152    are of the caller.  */
06153 
06154 void
06155 tree_check_failed (const tree node, const char *file,
06156        int line, const char *function, ...)
06157 {
06158   va_list args;
06159   char *buffer;
06160   unsigned length = 0;
06161   int code;
06162 
06163   va_start (args, function);
06164   while ((code = va_arg (args, int)))
06165     length += 4 + strlen (tree_code_name[code]);
06166   va_end (args);
06167   if (length)
06168     {
06169       va_start (args, function);
06170       length += strlen ("expected ");
06171       buffer = alloca (length);
06172       length = 0;
06173       while ((code = va_arg (args, int)))
06174   {
06175     const char *prefix = length ? " or " : "expected ";
06176     
06177     strcpy (buffer + length, prefix);
06178     length += strlen (prefix);
06179     strcpy (buffer + length, tree_code_name[code]);
06180     length += strlen (tree_code_name[code]);
06181   }
06182       va_end (args);
06183     }
06184   else
06185     buffer = (char *)"unexpected node";
06186 
06187   internal_error ("tree check: %s, have %s in %s, at %s:%d",
06188       buffer, tree_code_name[TREE_CODE (node)],
06189       function, trim_filename (file), line);
06190 }
06191 
06192 /* Complain that the tree code of NODE does match the expected 0
06193    terminated list of trailing codes. FILE, LINE, and FUNCTION are of
06194    the caller.  */
06195 
06196 void
06197 tree_not_check_failed (const tree node, const char *file,
06198            int line, const char *function, ...)
06199 {
06200   va_list args;
06201   char *buffer;
06202   unsigned length = 0;
06203   int code;
06204 
06205   va_start (args, function);
06206   while ((code = va_arg (args, int)))
06207     length += 4 + strlen (tree_code_name[code]);
06208   va_end (args);
06209   va_start (args, function);
06210   buffer = alloca (length);
06211   length = 0;
06212   while ((code = va_arg (args, int)))
06213     {
06214       if (length)
06215   {
06216     strcpy (buffer + length, " or ");
06217     length += 4;
06218   }
06219       strcpy (buffer + length, tree_code_name[code]);
06220       length += strlen (tree_code_name[code]);
06221     }
06222   va_end (args);
06223 
06224   internal_error ("tree check: expected none of %s, have %s in %s, at %s:%d",
06225       buffer, tree_code_name[TREE_CODE (node)],
06226       function, trim_filename (file), line);
06227 }
06228 
06229 /* Similar to tree_check_failed, except that we check for a class of tree
06230    code, given in CL.  */
06231 
06232 void
06233 tree_class_check_failed (const tree node, const enum tree_code_class cl,
06234        const char *file, int line, const char *function)
06235 {
06236   internal_error
06237     ("tree check: expected class %qs, have %qs (%s) in %s, at %s:%d",
06238      TREE_CODE_CLASS_STRING (cl),
06239      TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node))),
06240      tree_code_name[TREE_CODE (node)], function, trim_filename (file), line);
06241 }
06242 
06243 /* Similar to tree_check_failed, except that instead of specifying a
06244    dozen codes, use the knowledge that they're all sequential.  */
06245 
06246 void
06247 tree_range_check_failed (const tree node, const char *file, int line,
06248        const char *function, enum tree_code c1,
06249        enum tree_code c2)
06250 {
06251   char *buffer;
06252   unsigned length = 0;
06253   enum tree_code c;
06254 
06255   for (c = c1; c <= c2; ++c)
06256     length += 4 + strlen (tree_code_name[c]);
06257 
06258   length += strlen ("expected ");
06259   buffer = alloca (length);
06260   length = 0;
06261 
06262   for (c = c1; c <= c2; ++c)
06263     {
06264       const char *prefix = length ? " or " : "expected ";
06265 
06266       strcpy (buffer + length, prefix);
06267       length += strlen (prefix);
06268       strcpy (buffer + length, tree_code_name[c]);
06269       length += strlen (tree_code_name[c]);
06270     }
06271 
06272   internal_error ("tree check: %s, have %s in %s, at %s:%d",
06273       buffer, tree_code_name[TREE_CODE (node)],
06274       function, trim_filename (file), line);
06275 }
06276 
06277 
06278 /* Similar to tree_check_failed, except that we check that a tree does
06279    not have the specified code, given in CL.  */
06280 
06281 void
06282 tree_not_class_check_failed (const tree node, const enum tree_code_class cl,
06283            const char *file, int line, const char *function)
06284 {
06285   internal_error
06286     ("tree check: did not expect class %qs, have %qs (%s) in %s, at %s:%d",
06287      TREE_CODE_CLASS_STRING (cl),
06288      TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node))),
06289      tree_code_name[TREE_CODE (node)], function, trim_filename (file), line);
06290 }
06291 
06292 
06293 /* Similar to tree_check_failed but applied to OMP_CLAUSE codes.  */
06294 
06295 void
06296 omp_clause_check_failed (const tree node, const char *file, int line,
06297                          const char *function, enum omp_clause_code code)
06298 {
06299   internal_error ("tree check: expected omp_clause %s, have %s in %s, at %s:%d",
06300       omp_clause_code_name[code], tree_code_name[TREE_CODE (node)],
06301       function, trim_filename (file), line);
06302 }
06303 
06304 
06305 /* Similar to tree_range_check_failed but applied to OMP_CLAUSE codes.  */
06306 
06307 void
06308 omp_clause_range_check_failed (const tree node, const char *file, int line,
06309              const char *function, enum omp_clause_code c1,
06310              enum omp_clause_code c2)
06311 {
06312   char *buffer;
06313   unsigned length = 0;
06314   enum omp_clause_code c;
06315 
06316   for (c = c1; c <= c2; ++c)
06317     length += 4 + strlen (omp_clause_code_name[c]);
06318 
06319   length += strlen ("expected ");
06320   buffer = alloca (length);
06321   length = 0;
06322 
06323   for (c = c1; c <= c2; ++c)
06324     {
06325       const char *prefix = length ? " or " : "expected ";
06326 
06327       strcpy (buffer + length, prefix);
06328       length += strlen (prefix);
06329       strcpy (buffer + length, omp_clause_code_name[c]);
06330       length += strlen (omp_clause_code_name[c]);
06331     }
06332 
06333   internal_error ("tree check: %s, have %s in %s, at %s:%d",
06334       buffer, omp_clause_code_name[TREE_CODE (node)],
06335       function, trim_filename (file), line);
06336 }
06337 
06338 
06339 #undef DEFTREESTRUCT
06340 #define DEFTREESTRUCT(VAL, NAME) NAME,
06341 
06342 static const char *ts_enum_names[] = {
06343 #include "treestruct.def"
06344 };
06345 #undef DEFTREESTRUCT
06346 
06347 #define TS_ENUM_NAME(EN) (ts_enum_names[(EN)])
06348 
06349 /* Similar to tree_class_check_failed, except that we check for
06350    whether CODE contains the tree structure identified by EN.  */
06351 
06352 void
06353 tree_contains_struct_check_failed (const tree node, 
06354            const enum tree_node_structure_enum en,
06355            const char *file, int line, 
06356            const char *function)
06357 {
06358   internal_error
06359     ("tree check: expected tree that contains %qs structure, have %qs  in %s, at %s:%d",
06360      TS_ENUM_NAME(en),
06361      tree_code_name[TREE_CODE (node)], function, trim_filename (file), line);
06362 }
06363 
06364 
06365 /* Similar to above, except that the check is for the bounds of a TREE_VEC's
06366    (dynamically sized) vector.  */
06367 
06368 void
06369 tree_vec_elt_check_failed (int idx, int len, const char *file, int line,
06370          const char *function)
06371 {
06372   internal_error
06373     ("tree check: accessed elt %d of tree_vec with %d elts in %s, at %s:%d",
06374      idx + 1, len, function, trim_filename (file), line);
06375 }
06376 
06377 /* Similar to above, except that the check is for the bounds of a PHI_NODE's
06378    (dynamically sized) vector.  */
06379 
06380 void
06381 phi_node_elt_check_failed (int idx, int len, const char *file, int line,
06382           const char *function)
06383 {
06384   internal_error
06385     ("tree check: accessed elt %d of phi_node with %d elts in %s, at %s:%d",
06386      idx + 1, len, function, trim_filename (file), line);
06387 }
06388 
06389 /* Similar to above, except that the check is for the bounds of the operand
06390    vector of an expression node.  */
06391 
06392 void
06393 tree_operand_check_failed (int idx, enum tree_code code, const char *file,
06394          int line, const char *function)
06395 {
06396   internal_error
06397     ("tree check: accessed operand %d of %s with %d operands in %s, at %s:%d",
06398      idx + 1, tree_code_name[code], TREE_CODE_LENGTH (code),
06399      function, trim_filename (file), line);
06400 }
06401 
06402 /* Similar to above, except that the check is for the number of
06403    operands of an OMP_CLAUSE node.  */
06404 
06405 void
06406 omp_clause_operand_check_failed (int idx, tree t, const char *file,
06407                int line, const char *function)
06408 {
06409   internal_error
06410     ("tree check: accessed operand %d of omp_clause %s with %d operands "
06411      "in %s, at %s:%d", idx + 1, omp_clause_code_name[OMP_CLAUSE_CODE (t)],
06412      omp_clause_num_ops [OMP_CLAUSE_CODE (t)], function,
06413      trim_filename (file), line);
06414 }
06415 #endif /* ENABLE_TREE_CHECKING */
06416 
06417 /* Create a new vector type node holding SUBPARTS units of type INNERTYPE,
06418    and mapped to the machine mode MODE.  Initialize its fields and build
06419    the information necessary for debugging output.  */
06420 
06421 static tree
06422 make_vector_type (tree innertype, int nunits, enum machine_mode mode)
06423 {
06424   tree t;
06425   hashval_t hashcode = 0;
06426 
06427   /* Build a main variant, based on the main variant of the inner type, then
06428      use it to build the variant we return.  */
06429   if ((TYPE_ATTRIBUTES (innertype) || TYPE_QUALS (innertype))
06430       && TYPE_MAIN_VARIANT (innertype) != innertype)
06431     return build_type_attribute_qual_variant (
06432       make_vector_type (TYPE_MAIN_VARIANT (innertype), nunits, mode),
06433       TYPE_ATTRIBUTES (innertype),
06434       TYPE_QUALS (innertype));
06435 
06436   t = make_node (VECTOR_TYPE);
06437   TREE_TYPE (t) = TYPE_MAIN_VARIANT (innertype);
06438   SET_TYPE_VECTOR_SUBPARTS (t, nunits);
06439   TYPE_MODE (t) = mode;
06440   TYPE_READONLY (t) = TYPE_READONLY (innertype);
06441   TYPE_VOLATILE (t) = TYPE_VOLATILE (innertype);
06442 
06443   layout_type (t);
06444 
06445   {
06446     tree index = build_int_cst (NULL_TREE, nunits - 1);
06447     tree array = build_array_type (innertype, build_index_type (index));
06448     tree rt = make_node (RECORD_TYPE);
06449 
06450     TYPE_FIELDS (rt) = build_decl (FIELD_DECL, get_identifier ("f"), array);
06451     DECL_CONTEXT (TYPE_FIELDS (rt)) = rt;
06452     layout_type (rt);
06453     TYPE_DEBUG_REPRESENTATION_TYPE (t) = rt;
06454     /* In dwarfout.c, type lookup uses TYPE_UID numbers.  We want to output
06455        the representation type, and we want to find that die when looking up
06456        the vector type.  This is most easily achieved by making the TYPE_UID
06457        numbers equal.  */
06458     TYPE_UID (rt) = TYPE_UID (t);
06459   }
06460 
06461   hashcode = iterative_hash_host_wide_int (VECTOR_TYPE, hashcode);
06462   hashcode = iterative_hash_host_wide_int (mode, hashcode);
06463   hashcode = iterative_hash_object (TYPE_HASH (innertype), hashcode);
06464   return type_hash_canon (hashcode, t);
06465 }
06466 
06467 static tree
06468 make_or_reuse_type (unsigned size, int unsignedp)
06469 {
06470   if (size == INT_TYPE_SIZE)
06471     return unsignedp ? unsigned_type_node : integer_type_node;
06472   if (size == CHAR_TYPE_SIZE)
06473     return unsignedp ? unsigned_char_type_node : signed_char_type_node;
06474   if (size == SHORT_TYPE_SIZE)
06475     return unsignedp ? short_unsigned_type_node : short_integer_type_node;
06476   if (size == LONG_TYPE_SIZE)
06477     return unsignedp ? long_unsigned_type_node : long_integer_type_node;
06478   if (size == LONG_LONG_TYPE_SIZE)
06479     return (unsignedp ? long_long_unsigned_type_node
06480             : long_long_integer_type_node);
06481 
06482   if (unsignedp)
06483     return make_unsigned_type (size);
06484   else
06485     return make_signed_type (size);
06486 }
06487 
06488 /* Create nodes for all integer types (and error_mark_node) using the sizes
06489    of C datatypes.  The caller should call set_sizetype soon after calling
06490    this function to select one of the types as sizetype.  */
06491 
06492 void
06493 build_common_tree_nodes (bool signed_char, bool signed_sizetype)
06494 {
06495   error_mark_node = make_node (ERROR_MARK);
06496   TREE_TYPE (error_mark_node) = error_mark_node;
06497 
06498   initialize_sizetypes (signed_sizetype);
06499 
06500   /* Define both `signed char' and `unsigned char'.  */
06501   signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE);
06502   TYPE_STRING_FLAG (signed_char_type_node) = 1;
06503   unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
06504   TYPE_STRING_FLAG (unsigned_char_type_node) = 1;
06505 
06506   /* Define `char', which is like either `signed char' or `unsigned char'
06507      but not the same as either.  */
06508   char_type_node
06509     = (signed_char
06510        ? make_signed_type (CHAR_TYPE_SIZE)
06511        : make_unsigned_type (CHAR_TYPE_SIZE));
06512   TYPE_STRING_FLAG (char_type_node) = 1;
06513 
06514   short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE);
06515   short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE);
06516   integer_type_node = make_signed_type (INT_TYPE_SIZE);
06517   unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);
06518   long_integer_type_node = make_signed_type (LONG_TYPE_SIZE);
06519   long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE);
06520   long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE);
06521   long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
06522 
06523   /* Define a boolean type.  This type only represents boolean values but
06524      may be larger than char depending on the value of BOOL_TYPE_SIZE.
06525      Front ends which want to override this size (i.e. Java) can redefine
06526      boolean_type_node before calling build_common_tree_nodes_2.  */
06527   boolean_type_node = make_unsigned_type (BOOL_TYPE_SIZE);
06528   TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE);
06529   TYPE_MAX_VALUE (boolean_type_node) = build_int_cst (boolean_type_node, 1);
06530   TYPE_PRECISION (boolean_type_node) = 1;
06531 
06532   /* Fill in the rest of the sized types.  Reuse existing type nodes
06533      when possible.  */
06534   intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 0);
06535   intHI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (HImode), 0);
06536   intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 0);
06537   intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 0);
06538   intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 0);
06539 
06540   unsigned_intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 1);
06541   unsigned_intHI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (HImode), 1);
06542   unsigned_intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 1);
06543   unsigned_intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 1);
06544   unsigned_intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 1);
06545 
06546   access_public_node = get_identifier ("public");
06547   access_protected_node = get_identifier ("protected");
06548   access_private_node = get_identifier ("private");
06549 }
06550 
06551 /* Call this function after calling build_common_tree_nodes and set_sizetype.
06552    It will create several other common tree nodes.  */
06553 
06554 void
06555 build_common_tree_nodes_2 (int short_double)
06556 {
06557   /* Define these next since types below may used them.  */
06558   integer_zero_node = build_int_cst (NULL_TREE, 0);
06559   integer_one_node = build_int_cst (NULL_TREE, 1);
06560   integer_minus_one_node = build_int_cst (NULL_TREE, -1);
06561 
06562   size_zero_node = size_int (0);
06563   size_one_node = size_int (1);
06564   bitsize_zero_node = bitsize_int (0);
06565   bitsize_one_node = bitsize_int (1);
06566   bitsize_unit_node = bitsize_int (BITS_PER_UNIT);
06567 
06568   boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
06569   boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
06570 
06571   void_type_node = make_node (VOID_TYPE);
06572   layout_type (void_type_node);
06573 
06574   /* We are not going to have real types in C with less than byte alignment,
06575      so we might as well not have any types that claim to have it.  */
06576   TYPE_ALIGN (void_type_node) = BITS_PER_UNIT;
06577   TYPE_USER_ALIGN (void_type_node) = 0;
06578 
06579   null_pointer_node = build_int_cst (build_pointer_type (void_type_node), 0);
06580   layout_type (TREE_TYPE (null_pointer_node));
06581 
06582   ptr_type_node = build_pointer_type (void_type_node);
06583   const_ptr_type_node
06584     = build_pointer_type (build_type_variant (void_type_node, 1, 0));
06585   fileptr_type_node = ptr_type_node;
06586 
06587   float_type_node = make_node (REAL_TYPE);
06588   TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE;
06589   layout_type (float_type_node);
06590 
06591   double_type_node = make_node (REAL_TYPE);
06592   if (short_double)
06593     TYPE_PRECISION (double_type_node) = FLOAT_TYPE_SIZE;
06594   else
06595     TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE;
06596   layout_type (double_type_node);
06597 
06598   long_double_type_node = make_node (REAL_TYPE);
06599   TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE;
06600   layout_type (long_double_type_node);
06601 
06602   float_ptr_type_node = build_pointer_type (float_type_node);
06603   double_ptr_type_node = build_pointer_type (double_type_node);
06604   long_double_ptr_type_node = build_pointer_type (long_double_type_node);
06605   integer_ptr_type_node = build_pointer_type (integer_type_node);
06606 
06607   /* Decimal float types. */
06608   dfloat32_type_node = make_node (REAL_TYPE);
06609   TYPE_PRECISION (dfloat32_type_node) = DECIMAL32_TYPE_SIZE; 
06610   layout_type (dfloat32_type_node);
06611   TYPE_MODE (dfloat32_type_node) = SDmode;
06612   dfloat32_ptr_type_node = build_pointer_type (dfloat32_type_node);
06613 
06614   dfloat64_type_node = make_node (REAL_TYPE);
06615   TYPE_PRECISION (dfloat64_type_node) = DECIMAL64_TYPE_SIZE;
06616   layout_type (dfloat64_type_node);
06617   TYPE_MODE (dfloat64_type_node) = DDmode;
06618   dfloat64_ptr_type_node = build_pointer_type (dfloat64_type_node);
06619 
06620   dfloat128_type_node = make_node (REAL_TYPE);
06621   TYPE_PRECISION (dfloat128_type_node) = DECIMAL128_TYPE_SIZE; 
06622   layout_type (dfloat128_type_node);
06623   TYPE_MODE (dfloat128_type_node) = TDmode;
06624   dfloat128_ptr_type_node = build_pointer_type (dfloat128_type_node);
06625 
06626   complex_integer_type_node = make_node (COMPLEX_TYPE);
06627   TREE_TYPE (complex_integer_type_node) = integer_type_node;
06628   layout_type (complex_integer_type_node);
06629 
06630   complex_float_type_node = make_node (COMPLEX_TYPE);
06631   TREE_TYPE (complex_float_type_node) = float_type_node;
06632   layout_type (complex_float_type_node);
06633 
06634   complex_double_type_node = make_node (COMPLEX_TYPE);
06635   TREE_TYPE (complex_double_type_node) = double_type_node;
06636   layout_type (complex_double_type_node);
06637 
06638   complex_long_double_type_node = make_node (COMPLEX_TYPE);
06639   TREE_TYPE (complex_long_double_type_node) = long_double_type_node;
06640   layout_type (complex_long_double_type_node);
06641 
06642   {
06643     tree t = targetm.build_builtin_va_list ();
06644 
06645     /* Many back-ends define record types without setting TYPE_NAME.
06646        If we copied the record type here, we'd keep the original
06647        record type without a name.  This breaks name mangling.  So,
06648        don't copy record types and let c_common_nodes_and_builtins()
06649        declare the type to be __builtin_va_list.  */
06650     if (TREE_CODE (t) != RECORD_TYPE)
06651       t = build_variant_type_copy (t);
06652 
06653     va_list_type_node = t;
06654   }
06655 }
06656 
06657 /* A subroutine of build_common_builtin_nodes.  Define a builtin function.  */
06658 
06659 static void
06660 local_define_builtin (const char *name, tree type, enum built_in_function code,
06661                       const char *library_name, int ecf_flags)
06662 {
06663   tree decl;
06664 
06665   decl = lang_hooks.builtin_function (name, type, code, BUILT_IN_NORMAL,
06666               library_name, NULL_TREE);
06667   if (ecf_flags & ECF_CONST)
06668     TREE_READONLY (decl) = 1;
06669   if (ecf_flags & ECF_PURE)
06670     DECL_IS_PURE (decl) = 1;
06671   if (ecf_flags & ECF_NORETURN)
06672     TREE_THIS_VOLATILE (decl) = 1;
06673   if (ecf_flags & ECF_NOTHROW)
06674     TREE_NOTHROW (decl) = 1;
06675   if (ecf_flags & ECF_MALLOC)
06676     DECL_IS_MALLOC (decl) = 1;
06677 
06678   built_in_decls[code] = decl;
06679   implicit_built_in_decls[code] = decl;
06680 }
06681 
06682 /* Call this function after instantiating all builtins that the language
06683    front end cares about.  This will build the rest of the builtins that
06684    are relied upon by the tree optimizers and the middle-end.  */
06685 
06686 void
06687 build_common_builtin_nodes (void)
06688 {
06689   tree tmp, ftype;
06690 
06691   if (built_in_decls[BUILT_IN_MEMCPY] == NULL
06692       || built_in_decls[BUILT_IN_MEMMOVE] == NULL)
06693     {
06694       tmp = tree_cons (NULL_TREE, size_type_node, void_list_node);
06695       tmp = tree_cons (NULL_TREE, const_ptr_type_node, tmp);
06696       tmp = tree_cons (NULL_TREE, ptr_type_node, tmp);
06697       ftype = build_function_type (ptr_type_node, tmp);
06698 
06699       if (built_in_decls[BUILT_IN_MEMCPY] == NULL)
06700   local_define_builtin ("__builtin_memcpy", ftype, BUILT_IN_MEMCPY,
06701             "memcpy", ECF_NOTHROW);
06702       if (built_in_decls[BUILT_IN_MEMMOVE] == NULL)
06703   local_define_builtin ("__builtin_memmove", ftype, BUILT_IN_MEMMOVE,
06704             "memmove", ECF_NOTHROW);
06705     }
06706 
06707   if (built_in_decls[BUILT_IN_MEMCMP] == NULL)
06708     {
06709       tmp = tree_cons (NULL_TREE, size_type_node, void_list_node);
06710       tmp = tree_cons (NULL_TREE, const_ptr_type_node, tmp);
06711       tmp = tree_cons (NULL_TREE, const_ptr_type_node, tmp);
06712       ftype = build_function_type (integer_type_node, tmp);
06713       local_define_builtin ("__builtin_memcmp", ftype, BUILT_IN_MEMCMP,
06714           "memcmp", ECF_PURE | ECF_NOTHROW);
06715     }
06716 
06717   if (built_in_decls[BUILT_IN_MEMSET] == NULL)
06718     {
06719       tmp = tree_cons (NULL_TREE, size_type_node, void_list_node);
06720       tmp = tree_cons (NULL_TREE, integer_type_node, tmp);
06721       tmp = tree_cons (NULL_TREE, ptr_type_node, tmp);
06722       ftype = build_function_type (ptr_type_node, tmp);
06723       local_define_builtin ("__builtin_memset", ftype, BUILT_IN_MEMSET,
06724           "memset", ECF_NOTHROW);
06725     }
06726 
06727   if (built_in_decls[BUILT_IN_ALLOCA] == NULL)
06728     {
06729       tmp = tree_cons (NULL_TREE, size_type_node, void_list_node);
06730       ftype = build_function_type (ptr_type_node, tmp);
06731       local_define_builtin ("__builtin_alloca", ftype, BUILT_IN_ALLOCA,
06732           "alloca", ECF_NOTHROW | ECF_MALLOC);
06733     }
06734 
06735   tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
06736   tmp = tree_cons (NULL_TREE, ptr_type_node, tmp);
06737   tmp = tree_cons (NULL_TREE, ptr_type_node, tmp);
06738   ftype = build_function_type (void_type_node, tmp);
06739   local_define_builtin ("__builtin_init_trampoline", ftype,
06740       BUILT_IN_INIT_TRAMPOLINE,
06741       "__builtin_init_trampoline", ECF_NOTHROW);
06742 
06743   tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
06744   ftype = build_function_type (ptr_type_node, tmp);
06745   local_define_builtin ("__builtin_adjust_trampoline", ftype,
06746       BUILT_IN_ADJUST_TRAMPOLINE,
06747       "__builtin_adjust_trampoline",
06748       ECF_CONST | ECF_NOTHROW);
06749 
06750   tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
06751   tmp = tree_cons (NULL_TREE, ptr_type_node, tmp);
06752   ftype = build_function_type (void_type_node, tmp);
06753   local_define_builtin ("__builtin_nonlocal_goto", ftype,
06754       BUILT_IN_NONLOCAL_GOTO,
06755       "__builtin_nonlocal_goto",
06756       ECF_NORETURN | ECF_NOTHROW);
06757 
06758   tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
06759   tmp = tree_cons (NULL_TREE, ptr_type_node, tmp);
06760   ftype = build_function_type (void_type_node, tmp);
06761   local_define_builtin ("__builtin_setjmp_setup", ftype,
06762       BUILT_IN_SETJMP_SETUP,
06763       "__builtin_setjmp_setup", ECF_NOTHROW);
06764 
06765   tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
06766   ftype = build_function_type (ptr_type_node, tmp);
06767   local_define_builtin ("__builtin_setjmp_dispatcher", ftype,
06768       BUILT_IN_SETJMP_DISPATCHER,
06769       "__builtin_setjmp_dispatcher",
06770       ECF_PURE | ECF_NOTHROW);
06771 
06772   tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
06773   ftype = build_function_type (void_type_node, tmp);
06774   local_define_builtin ("__builtin_setjmp_receiver", ftype,
06775       BUILT_IN_SETJMP_RECEIVER,
06776       "__builtin_setjmp_receiver", ECF_NOTHROW);
06777 
06778   ftype = build_function_type (ptr_type_node, void_list_node);
06779   local_define_builtin ("__builtin_stack_save", ftype, BUILT_IN_STACK_SAVE,
06780       "__builtin_stack_save", ECF_NOTHROW);
06781 
06782   tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
06783   ftype = build_function_type (void_type_node, tmp);
06784   local_define_builtin ("__builtin_stack_restore", ftype,
06785       BUILT_IN_STACK_RESTORE,
06786       "__builtin_stack_restore", ECF_NOTHROW);
06787 
06788   ftype = build_function_type (void_type_node, void_list_node);
06789   local_define_builtin ("__builtin_profile_func_enter", ftype,
06790       BUILT_IN_PROFILE_FUNC_ENTER, "profile_func_enter", 0);
06791   local_define_builtin ("__builtin_profile_func_exit", ftype,
06792       BUILT_IN_PROFILE_FUNC_EXIT, "profile_func_exit", 0);
06793 
06794   /* Complex multiplication and division.  These are handled as builtins
06795      rather than optabs because emit_library_call_value doesn't support
06796      complex.  Further, we can do slightly better with folding these 
06797      beasties if the real and complex parts of the arguments are separate.  */
06798   {
06799     enum machine_mode mode;
06800 
06801     for (mode = MIN_MODE_COMPLEX_FLOAT; mode <= MAX_MODE_COMPLEX_FLOAT; ++mode)
06802       {
06803   char mode_name_buf[4], *q;
06804   const char *p;
06805   enum built_in_function mcode, dcode;
06806   tree type, inner_type;
06807 
06808   type = lang_hooks.types.type_for_mode (mode, 0);
06809   if (type == NULL)
06810     continue;
06811   inner_type = TREE_TYPE (type);
06812 
06813   tmp = tree_cons (NULL_TREE, inner_type, void_list_node);
06814   tmp = tree_cons (NULL_TREE, inner_type, tmp);
06815   tmp = tree_cons (NULL_TREE, inner_type, tmp);
06816   tmp = tree_cons (NULL_TREE, inner_type, tmp);
06817   ftype = build_function_type (type, tmp);
06818 
06819         mcode = BUILT_IN_COMPLEX_MUL_MIN + mode - MIN_MODE_COMPLEX_FLOAT;
06820         dcode = BUILT_IN_COMPLEX_DIV_MIN + mode - MIN_MODE_COMPLEX_FLOAT;
06821 
06822         for (p = GET_MODE_NAME (mode), q = mode_name_buf; *p; p++, q++)
06823     *q = TOLOWER (*p);
06824   *q = '\0';
06825 
06826   built_in_names[mcode] = concat ("__mul", mode_name_buf, "3", NULL);
06827         local_define_builtin (built_in_names[mcode], ftype, mcode,
06828             built_in_names[mcode], ECF_CONST | ECF_NOTHROW);
06829 
06830   built_in_names[dcode] = concat ("__div", mode_name_buf, "3", NULL);
06831         local_define_builtin (built_in_names[dcode], ftype, dcode,
06832             built_in_names[dcode], ECF_CONST | ECF_NOTHROW);
06833       }
06834   }
06835 }
06836 
06837 /* HACK.  GROSS.  This is absolutely disgusting.  I wish there was a
06838    better way.
06839 
06840    If we requested a pointer to a vector, build up the pointers that
06841    we stripped off while looking for the inner type.  Similarly for
06842    return values from functions.
06843 
06844    The argument TYPE is the top of the chain, and BOTTOM is the
06845    new type which we will point to.  */
06846 
06847 tree
06848 reconstruct_complex_type (tree type, tree bottom)
06849 {
06850   tree inner, outer;
06851 
06852   if (POINTER_TYPE_P (type))
06853     {
06854       inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
06855       outer = build_pointer_type (inner);
06856     }
06857   else if (TREE_CODE (type) == ARRAY_TYPE)
06858     {
06859       inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
06860       outer = build_array_type (inner, TYPE_DOMAIN (type));
06861     }
06862   else if (TREE_CODE (type) == FUNCTION_TYPE)
06863     {
06864       inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
06865       outer = build_function_type (inner, TYPE_ARG_TYPES (type));
06866     }
06867   else if (TREE_CODE (type) == METHOD_TYPE)
06868     {
06869       tree argtypes;
06870       inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
06871       /* The build_method_type_directly() routine prepends 'this' to argument list,
06872          so we must compensate by getting rid of it.  */
06873       argtypes = TYPE_ARG_TYPES (type);
06874       outer = build_method_type_directly (TYPE_METHOD_BASETYPE (type),
06875             inner,
06876             TYPE_ARG_TYPES (type));
06877       TYPE_ARG_TYPES (outer) = argtypes;
06878     }
06879   else
06880     return bottom;
06881 
06882   TYPE_READONLY (outer) = TYPE_READONLY (type);
06883   TYPE_VOLATILE (outer) = TYPE_VOLATILE (type);
06884 
06885   return outer;
06886 }
06887 
06888 /* Returns a vector tree node given a mode (integer, vector, or BLKmode) and
06889    the inner type.  */
06890 tree
06891 build_vector_type_for_mode (tree innertype, enum machine_mode mode)
06892 {
06893   int nunits;
06894 
06895   switch (GET_MODE_CLASS (mode))
06896     {
06897     case MODE_VECTOR_INT:
06898     case MODE_VECTOR_FLOAT:
06899       nunits = GET_MODE_NUNITS (mode);
06900       break;
06901 
06902     case MODE_INT:
06903       /* Check that there are no leftover bits.  */
06904       gcc_assert (GET_MODE_BITSIZE (mode)
06905       % TREE_INT_CST_LOW (TYPE_SIZE (innertype)) == 0);
06906 
06907       nunits = GET_MODE_BITSIZE (mode)
06908          / TREE_INT_CST_LOW (TYPE_SIZE (innertype));
06909       break;
06910 
06911     default:
06912       gcc_unreachable ();
06913     }
06914 
06915   return make_vector_type (innertype, nunits, mode);
06916 }
06917 
06918 /* Similarly, but takes the inner type and number of units, which must be
06919    a power of two.  */
06920 
06921 tree
06922 build_vector_type (tree innertype, int nunits)
06923 {
06924   return make_vector_type (innertype, nunits, VOIDmode);
06925 }
06926 
06927 
06928 /* Build RESX_EXPR with given REGION_NUMBER.  */
06929 tree
06930 build_resx (int region_number)
06931 {
06932   tree t;
06933   t = build1 (RESX_EXPR, void_type_node,
06934         build_int_cst (NULL_TREE, region_number));
06935   return t;
06936 }
06937 
06938 /* Given an initializer INIT, return TRUE if INIT is zero or some
06939    aggregate of zeros.  Otherwise return FALSE.  */
06940 bool
06941 initializer_zerop (tree init)
06942 {
06943   tree elt;
06944 
06945   STRIP_NOPS (init);
06946 
06947   switch (TREE_CODE (init))
06948     {
06949     case INTEGER_CST:
06950       return integer_zerop (init);
06951 
06952     case REAL_CST:
06953       /* ??? Note that this is not correct for C4X float formats.  There,
06954    a bit pattern of all zeros is 1.0; 0.0 is encoded with the most
06955    negative exponent.  */
06956       return real_zerop (init)
06957   && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (init));
06958 
06959     case COMPLEX_CST:
06960       return integer_zerop (init)
06961   || (real_zerop (init)
06962       && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_REALPART (init)))
06963       && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_IMAGPART (init))));
06964 
06965     case VECTOR_CST:
06966       for (elt = TREE_VECTOR_CST_ELTS (init); elt; elt = TREE_CHAIN (elt))
06967   if (!initializer_zerop (TREE_VALUE (elt)))
06968     return false;
06969       return true;
06970 
06971     case CONSTRUCTOR:
06972       {
06973   unsigned HOST_WIDE_INT idx;
06974 
06975   FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (init), idx, elt)
06976     if (!initializer_zerop (elt))
06977       return false;
06978   return true;
06979       }
06980 
06981     default:
06982       return false;
06983     }
06984 }
06985 
06986 /* Build an empty statement.  */
06987 
06988 tree
06989 build_empty_stmt (void)
06990 {
06991   return build1 (NOP_EXPR, void_type_node, size_zero_node);
06992 }
06993 
06994 
06995 /* Build an OpenMP clause with code CODE.  */
06996 
06997 tree
06998 build_omp_clause (enum omp_clause_code code)
06999 {
07000   tree t;
07001   int size, length;
07002 
07003   length = omp_clause_num_ops[code];
07004   size = (sizeof (struct tree_omp_clause) + (length - 1) * sizeof (tree));
07005 
07006   t = ggc_alloc (size);
07007   memset (t, 0, size);
07008   TREE_SET_CODE (t, OMP_CLAUSE);
07009   OMP_CLAUSE_SET_CODE (t, code);
07010 
07011 #ifdef GATHER_STATISTICS
07012   tree_node_counts[(int) omp_clause_kind]++;
07013   tree_node_sizes[(int) omp_clause_kind] += size;
07014 #endif
07015   
07016   return t;
07017 }
07018 
07019 
07020 /* Returns true if it is possible to prove that the index of
07021    an array access REF (an ARRAY_REF expression) falls into the
07022    array bounds.  */
07023 
07024 bool
07025 in_array_bounds_p (tree ref)
07026 {
07027   tree idx = TREE_OPERAND (ref, 1);
07028   tree min, max;
07029 
07030   if (TREE_CODE (idx) != INTEGER_CST)
07031     return false;
07032 
07033   min = array_ref_low_bound (ref);
07034   max = array_ref_up_bound (ref);
07035   if (!min
07036       || !max
07037       || TREE_CODE (min) != INTEGER_CST
07038       || TREE_CODE (max) != INTEGER_CST)
07039     return false;
07040 
07041   if (tree_int_cst_lt (idx, min)
07042       || tree_int_cst_lt (max, idx))
07043     return false;
07044 
07045   return true;
07046 }
07047 
07048 /* Returns true if it is possible to prove that the range of
07049    an array access REF (an ARRAY_RANGE_REF expression) falls
07050    into the array bounds.  */
07051 
07052 bool
07053 range_in_array_bounds_p (tree ref)
07054 {
07055   tree domain_type = TYPE_DOMAIN (TREE_TYPE (ref));
07056   tree range_min, range_max, min, max;
07057 
07058   range_min = TYPE_MIN_VALUE (domain_type);
07059   range_max = TYPE_MAX_VALUE (domain_type);
07060   if (!range_min
07061       || !range_max
07062       || TREE_CODE (range_min) != INTEGER_CST
07063       || TREE_CODE (range_max) != INTEGER_CST)
07064     return false;
07065 
07066   min = array_ref_low_bound (ref);
07067   max = array_ref_up_bound (ref);
07068   if (!min
07069       || !max
07070       || TREE_CODE (min) != INTEGER_CST
07071       || TREE_CODE (max) != INTEGER_CST)
07072     return false;
07073 
07074   if (tree_int_cst_lt (range_min, min)
07075       || tree_int_cst_lt (max, range_max))
07076     return false;
07077 
07078   return true;
07079 }
07080 
07081 /* Return true if T (assumed to be a DECL) is a global variable.  */
07082 
07083 bool
07084 is_global_var (tree t)
07085 {
07086   if (MTAG_P (t))
07087     return (TREE_STATIC (t) || MTAG_GLOBAL (t));
07088   else
07089     return (TREE_STATIC (t) || DECL_EXTERNAL (t));
07090 }
07091 
07092 /* Return true if T (assumed to be a DECL) must be assigned a memory
07093    location.  */
07094 
07095 bool
07096 needs_to_live_in_memory (tree t)
07097 {
07098   return (TREE_ADDRESSABLE (t)
07099     || is_global_var (t)
07100     || (TREE_CODE (t) == RESULT_DECL
07101         && aggregate_value_p (t, current_function_decl)));
07102 }
07103 
07104 /* There are situations in which a language considers record types
07105    compatible which have different field lists.  Decide if two fields
07106    are compatible.  It is assumed that the parent records are compatible.  */
07107 
07108 bool
07109 fields_compatible_p (tree f1, tree f2)
07110 {
07111   if (!operand_equal_p (DECL_FIELD_BIT_OFFSET (f1),
07112       DECL_FIELD_BIT_OFFSET (f2), OEP_ONLY_CONST))
07113     return false;
07114 
07115   if (!operand_equal_p (DECL_FIELD_OFFSET (f1),
07116                         DECL_FIELD_OFFSET (f2), OEP_ONLY_CONST))
07117     return false;
07118 
07119   if (!lang_hooks.types_compatible_p (TREE_TYPE (f1), TREE_TYPE (f2)))
07120     return false;
07121 
07122   return true;
07123 }
07124 
07125 /* Locate within RECORD a field that is compatible with ORIG_FIELD.  */
07126 
07127 tree
07128 find_compatible_field (tree record, tree orig_field)
07129 {
07130   tree f;
07131 
07132   for (f = TYPE_FIELDS (record); f ; f = TREE_CHAIN (f))
07133     if (TREE_CODE (f) == FIELD_DECL
07134   && fields_compatible_p (f, orig_field))
07135       return f;
07136 
07137   /* ??? Why isn't this on the main fields list?  */
07138   f = TYPE_VFIELD (record);
07139   if (f && TREE_CODE (f) == FIELD_DECL
07140       && fields_compatible_p (f, orig_field))
07141     return f;
07142 
07143   /* ??? We should abort here, but Java appears to do Bad Things
07144      with inherited fields.  */
07145   return orig_field;
07146 }
07147 
07148 /* Return value of a constant X.  */
07149 
07150 HOST_WIDE_INT
07151 int_cst_value (tree x)
07152 {
07153   unsigned bits = TYPE_PRECISION (TREE_TYPE (x));
07154   unsigned HOST_WIDE_INT val = TREE_INT_CST_LOW (x);
07155   bool negative = ((val >> (bits - 1)) & 1) != 0;
07156 
07157   gcc_assert (bits <= HOST_BITS_PER_WIDE_INT);
07158 
07159   if (negative)
07160     val |= (~(unsigned HOST_WIDE_INT) 0) << (bits - 1) << 1;
07161   else
07162     val &= ~((~(unsigned HOST_WIDE_INT) 0) << (bits - 1) << 1);
07163 
07164   return val;
07165 }
07166 
07167 /* Returns the greatest common divisor of A and B, which must be
07168    INTEGER_CSTs.  */
07169 
07170 tree
07171 tree_fold_gcd (tree a, tree b)
07172 {
07173   tree a_mod_b;
07174   tree type = TREE_TYPE (a);
07175 
07176   gcc_assert (TREE_CODE (a) == INTEGER_CST);
07177   gcc_assert (TREE_CODE (b) == INTEGER_CST);
07178 
07179   if (integer_zerop (a))
07180     return b;
07181 
07182   if (integer_zerop (b))
07183     return a;
07184 
07185   if (tree_int_cst_sgn (a) == -1)
07186     a = fold_build2 (MULT_EXPR, type, a,
07187          build_int_cst (type, -1));
07188 
07189   if (tree_int_cst_sgn (b) == -1)
07190     b = fold_build2 (MULT_EXPR, type, b,
07191          build_int_cst (type, -1));
07192 
07193   while (1)
07194     {
07195       a_mod_b = fold_build2 (FLOOR_MOD_EXPR, type, a, b);
07196 
07197       if (!TREE_INT_CST_LOW (a_mod_b)
07198     && !TREE_INT_CST_HIGH (a_mod_b))
07199   return b;
07200 
07201       a = b;
07202       b = a_mod_b;
07203     }
07204 }
07205 
07206 /* Returns unsigned variant of TYPE.  */
07207 
07208 tree
07209 unsigned_type_for (tree type)
07210 {
07211   if (POINTER_TYPE_P (type))
07212     return lang_hooks.types.unsigned_type (size_type_node);
07213   return lang_hooks.types.unsigned_type (type);
07214 }
07215 
07216 /* Returns signed variant of TYPE.  */
07217 
07218 tree
07219 signed_type_for (tree type)
07220 {
07221   if (POINTER_TYPE_P (type))
07222     return lang_hooks.types.signed_type (size_type_node);
07223   return lang_hooks.types.signed_type (type);
07224 }
07225 
07226 /* Returns the largest value obtainable by casting something in INNER type to
07227    OUTER type.  */
07228 
07229 tree
07230 upper_bound_in_type (tree outer, tree inner)
07231 {
07232   unsigned HOST_WIDE_INT lo, hi;
07233   unsigned int det = 0;
07234   unsigned oprec = TYPE_PRECISION (outer);
07235   unsigned iprec = TYPE_PRECISION (inner);
07236   unsigned prec;
07237 
07238   /* Compute a unique number for every combination.  */
07239   det |= (oprec > iprec) ? 4 : 0;
07240   det |= TYPE_UNSIGNED (outer) ? 2 : 0;
07241   det |= TYPE_UNSIGNED (inner) ? 1 : 0;
07242 
07243   /* Determine the exponent to use.  */
07244   switch (det)
07245     {
07246     case 0:
07247     case 1:
07248       /* oprec <= iprec, outer: signed, inner: don't care.  */
07249       prec = oprec - 1;
07250       break;
07251     case 2:
07252     case 3:
07253       /* oprec <= iprec, outer: unsigned, inner: don't care.  */
07254       prec = oprec;
07255       break;
07256     case 4:
07257       /* oprec > iprec, outer: signed, inner: signed.  */
07258       prec = iprec - 1;
07259       break;
07260     case 5:
07261       /* oprec > iprec, outer: signed, inner: unsigned.  */
07262       prec = iprec;
07263       break;
07264     case 6:
07265       /* oprec > iprec, outer: unsigned, inner: signed.  */
07266       prec = oprec;
07267       break;
07268     case 7:
07269       /* oprec > iprec, outer: unsigned, inner: unsigned.  */
07270       prec = iprec;
07271       break;
07272     default:
07273       gcc_unreachable ();
07274     }
07275 
07276   /* Compute 2^^prec - 1.  */
07277   if (prec <= HOST_BITS_PER_WIDE_INT)
07278     {
07279       hi = 0;
07280       lo = ((~(unsigned HOST_WIDE_INT) 0)
07281       >> (HOST_BITS_PER_WIDE_INT - prec));
07282     }
07283   else
07284     {
07285       hi = ((~(unsigned HOST_WIDE_INT) 0)
07286       >> (2 * HOST_BITS_PER_WIDE_INT - prec));
07287       lo = ~(unsigned HOST_WIDE_INT) 0;
07288     }
07289 
07290   return build_int_cst_wide (outer, lo, hi);
07291 }
07292 
07293 /* Returns the smallest value obtainable by casting something in INNER type to
07294    OUTER type.  */
07295 
07296 tree
07297 lower_bound_in_type (tree outer, tree inner)
07298 {
07299   unsigned HOST_WIDE_INT lo, hi;
07300   unsigned oprec = TYPE_PRECISION (outer);
07301   unsigned iprec = TYPE_PRECISION (inner);
07302 
07303   /* If OUTER type is unsigned, we can definitely cast 0 to OUTER type
07304      and obtain 0.  */
07305   if (TYPE_UNSIGNED (outer)
07306       /* If we are widening something of an unsigned type, OUTER type
07307    contains all values of INNER type.  In particular, both INNER
07308    and OUTER types have zero in common.  */
07309       || (oprec > iprec && TYPE_UNSIGNED (inner)))
07310     lo = hi = 0;
07311   else
07312     {
07313       /* If we are widening a signed type to another signed type, we
07314    want to obtain -2^^(iprec-1).  If we are keeping the
07315    precision or narrowing to a signed type, we want to obtain
07316    -2^(oprec-1).  */
07317       unsigned prec = oprec > iprec ? iprec : oprec;
07318 
07319       if (prec <= HOST_BITS_PER_WIDE_INT)
07320   {
07321     hi = ~(unsigned HOST_WIDE_INT) 0;
07322     lo = (~(unsigned HOST_WIDE_INT) 0) << (prec - 1);
07323   }
07324       else
07325   {
07326     hi = ((~(unsigned HOST_WIDE_INT) 0)
07327     << (prec - HOST_BITS_PER_WIDE_INT - 1));
07328     lo = 0;
07329   }
07330     }
07331 
07332   return build_int_cst_wide (outer, lo, hi);
07333 }
07334 
07335 /* Return nonzero if two operands that are suitable for PHI nodes are
07336    necessarily equal.  Specifically, both ARG0 and ARG1 must be either
07337    SSA_NAME or invariant.  Note that this is strictly an optimization.
07338    That is, callers of this function can directly call operand_equal_p
07339    and get the same result, only slower.  */
07340 
07341 int
07342 operand_equal_for_phi_arg_p (tree arg0, tree arg1)
07343 {
07344   if (arg0 == arg1)
07345     return 1;
07346   if (TREE_CODE (arg0) == SSA_NAME || TREE_CODE (arg1) == SSA_NAME)
07347     return 0;
07348   return operand_equal_p (arg0, arg1, 0);
07349 }
07350 
07351 /* Returns number of zeros at the end of binary representation of X.
07352    
07353    ??? Use ffs if available?  */
07354 
07355 tree
07356 num_ending_zeros (tree x)
07357 {
07358   unsigned HOST_WIDE_INT fr, nfr;
07359   unsigned num, abits;
07360   tree type = TREE_TYPE (x);
07361 
07362   if (TREE_INT_CST_LOW (x) == 0)
07363     {
07364       num = HOST_BITS_PER_WIDE_INT;
07365       fr = TREE_INT_CST_HIGH (x);
07366     }
07367   else
07368     {
07369       num = 0;
07370       fr = TREE_INT_CST_LOW (x);
07371     }
07372 
07373   for (abits = HOST_BITS_PER_WIDE_INT / 2; abits; abits /= 2)
07374     {
07375       nfr = fr >> abits;
07376       if (nfr << abits == fr)
07377   {
07378     num += abits;
07379     fr = nfr;
07380   }
07381     }
07382 
07383   if (num > TYPE_PRECISION (type))
07384     num = TYPE_PRECISION (type);
07385 
07386   return build_int_cst_type (type, num);
07387 }
07388 
07389 
07390 #define WALK_SUBTREE(NODE)        \
07391   do              \
07392     {             \
07393       result = walk_tree (&(NODE), func, data, pset); \
07394       if (result)         \
07395   return result;          \
07396     }             \
07397   while (0)
07398 
07399 /* This is a subroutine of walk_tree that walks field of TYPE that are to
07400    be walked whenever a type is seen in the tree.  Rest of operands and return
07401    value are as for walk_tree.  */
07402 
07403 static tree
07404 walk_type_fields (tree type, walk_tree_fn func, void *data,
07405       struct pointer_set_t *pset)
07406 {
07407   tree result = NULL_TREE;
07408 
07409   switch (TREE_CODE (type))
07410     {
07411     case POINTER_TYPE:
07412     case REFERENCE_TYPE:
07413       /* We have to worry about mutually recursive pointers.  These can't
07414    be written in C.  They can in Ada.  It's pathological, but
07415    there's an ACATS test (c38102a) that checks it.  Deal with this
07416    by checking if we're pointing to another pointer, that one
07417    points to another pointer, that one does too, and we have no htab.
07418    If so, get a hash table.  We check three levels deep to avoid
07419    the cost of the hash table if we don't need one.  */
07420       if (POINTER_TYPE_P (TREE_TYPE (type))
07421     && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (type)))
07422     && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (TREE_TYPE (type))))
07423     && !pset)
07424   {
07425     result = walk_tree_without_duplicates (&TREE_TYPE (type),
07426              func, data);
07427     if (result)
07428       return result;
07429 
07430     break;
07431   }
07432 
07433       /* ... fall through ... */
07434 
07435     case COMPLEX_TYPE:
07436       WALK_SUBTREE (TREE_TYPE (type));
07437       break;
07438 
07439     case METHOD_TYPE:
07440       WALK_SUBTREE (TYPE_METHOD_BASETYPE (type));
07441 
07442       /* Fall through.  */
07443 
07444     case FUNCTION_TYPE:
07445       WALK_SUBTREE (TREE_TYPE (type));
07446       {
07447   tree arg;
07448 
07449   /* We never want to walk into default arguments.  */
07450   for (arg = TYPE_ARG_TYPES (type); arg; arg = TREE_CHAIN (arg))
07451     WALK_SUBTREE (TREE_VALUE (arg));
07452       }
07453       break;
07454 
07455     case ARRAY_TYPE:
07456       /* Don't follow this nodes's type if a pointer for fear that
07457    we'll have infinite recursion.  If we have a PSET, then we
07458    need not fear.  */
07459       if (pset
07460     || (!POINTER_TYPE_P (TREE_TYPE (type))
07461         && TREE_CODE (TREE_TYPE (type)) != OFFSET_TYPE))
07462   WALK_SUBTREE (TREE_TYPE (type));
07463       WALK_SUBTREE (TYPE_DOMAIN (type));
07464       break;
07465 
07466     case BOOLEAN_TYPE:
07467     case ENUMERAL_TYPE:
07468     case INTEGER_TYPE:
07469     case REAL_TYPE:
07470       WALK_SUBTREE (TYPE_MIN_VALUE (type));
07471       WALK_SUBTREE (TYPE_MAX_VALUE (type));
07472       break;
07473 
07474     case OFFSET_TYPE:
07475       WALK_SUBTREE (TREE_TYPE (type));
07476       WALK_SUBTREE (TYPE_OFFSET_BASETYPE (type));
07477       break;
07478 
07479     default:
07480       break;
07481     }
07482 
07483   return NULL_TREE;
07484 }
07485 
07486 /* Apply FUNC to all the sub-trees of TP in a pre-order traversal.  FUNC is
07487    called with the DATA and the address of each sub-tree.  If FUNC returns a
07488    non-NULL value, the traversal is stopped, and the value returned by FUNC
07489    is returned.  If PSET is non-NULL it is used to record the nodes visited,
07490    and to avoid visiting a node more than once.  */
07491 
07492 tree
07493 walk_tree (tree *tp, walk_tree_fn func, void *data, struct pointer_set_t *pset)
07494 {
07495   enum tree_code code;
07496   int walk_subtrees;
07497   tree result;
07498 
07499 #define WALK_SUBTREE_TAIL(NODE)       \
07500   do              \
07501     {             \
07502        tp = & (NODE);         \
07503        goto tail_recurse;       \
07504     }             \
07505   while (0)
07506 
07507  tail_recurse:
07508   /* Skip empty subtrees.  */
07509   if (!*tp)
07510     return NULL_TREE;
07511 
07512   /* Don't walk the same tree twice, if the user has requested
07513      that we avoid doing so.  */
07514   if (pset && pointer_set_insert (pset, *tp))
07515     return NULL_TREE;
07516 
07517   /* Call the function.  */
07518   walk_subtrees = 1;
07519   result = (*func) (tp, &walk_subtrees, data);
07520 
07521   /* If we found something, return it.  */
07522   if (result)
07523     return result;
07524 
07525   code = TREE_CODE (*tp);
07526 
07527   /* Even if we didn't, FUNC may have decided that there was nothing
07528      interesting below this point in the tree.  */
07529   if (!walk_subtrees)
07530     {
07531       /* But we still need to check our siblings.  */
07532       if (code == TREE_LIST)
07533   WALK_SUBTREE_TAIL (TREE_CHAIN (*tp));
07534       else if (code == OMP_CLAUSE)
07535   WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp));
07536       else
07537   return NULL_TREE;
07538     }
07539 
07540   result = lang_hooks.tree_inlining.walk_subtrees (tp, &walk_subtrees, func,
07541                data, pset);
07542   if (result || ! walk_subtrees)
07543     return result;
07544 
07545   switch (code)
07546     {
07547     case ERROR_MARK:
07548     case IDENTIFIER_NODE:
07549     case INTEGER_CST:
07550     case REAL_CST:
07551     case VECTOR_CST:
07552     case STRING_CST:
07553     case BLOCK:
07554     case PLACEHOLDER_EXPR:
07555     case SSA_NAME:
07556     case FIELD_DECL:
07557     case RESULT_DECL:
07558       /* None of these have subtrees other than those already walked
07559    above.  */
07560       break;
07561 
07562     case TREE_LIST:
07563       WALK_SUBTREE (TREE_VALUE (*tp));
07564       WALK_SUBTREE_TAIL (TREE_CHAIN (*tp));
07565       break;
07566 
07567     case TREE_VEC:
07568       {
07569   int len = TREE_VEC_LENGTH (*tp);
07570 
07571   if (len == 0)
07572     break;
07573 
07574   /* Walk all elements but the first.  */
07575   while (--len)
07576     WALK_SUBTREE (TREE_VEC_ELT (*tp, len));
07577 
07578   /* Now walk the first one as a tail call.  */
07579   WALK_SUBTREE_TAIL (TREE_VEC_ELT (*tp, 0));
07580       }
07581 
07582     case COMPLEX_CST:
07583       WALK_SUBTREE (TREE_REALPART (*tp));
07584       WALK_SUBTREE_TAIL (TREE_IMAGPART (*tp));
07585 
07586     case CONSTRUCTOR:
07587       {
07588   unsigned HOST_WIDE_INT idx;
07589   constructor_elt *ce;
07590 
07591   for (idx = 0;
07592        VEC_iterate(constructor_elt, CONSTRUCTOR_ELTS (*tp), idx, ce);
07593        idx++)
07594     WALK_SUBTREE (ce->value);
07595       }
07596       break;
07597 
07598     case SAVE_EXPR:
07599       WALK_SUBTREE_TAIL (TREE_OPERAND (*tp, 0));
07600 
07601     case BIND_EXPR:
07602       {
07603   tree decl;
07604   for (decl = BIND_EXPR_VARS (*tp); decl; decl = TREE_CHAIN (decl))
07605     {
07606       /* Walk the DECL_INITIAL and DECL_SIZE.  We don't want to walk
07607          into declarations that are just mentioned, rather than
07608          declared; they don't really belong to this part of the tree.
07609          And, we can see cycles: the initializer for a declaration
07610          can refer to the declaration itself.  */
07611       WALK_SUBTREE (DECL_INITIAL (decl));
07612       WALK_SUBTREE (DECL_SIZE (decl));
07613       WALK_SUBTREE (DECL_SIZE_UNIT (decl));
07614     }
07615   WALK_SUBTREE_TAIL (BIND_EXPR_BODY (*tp));
07616       }
07617 
07618     case STATEMENT_LIST:
07619       {
07620   tree_stmt_iterator i;
07621   for (i = tsi_start (*tp); !tsi_end_p (i); tsi_next (&i))
07622     WALK_SUBTREE (*tsi_stmt_ptr (i));
07623       }
07624       break;
07625 
07626     case OMP_CLAUSE:
07627       switch (OMP_CLAUSE_CODE (*tp))
07628   {
07629   case OMP_CLAUSE_PRIVATE:
07630   case OMP_CLAUSE_SHARED:
07631   case OMP_CLAUSE_FIRSTPRIVATE:
07632   case OMP_CLAUSE_LASTPRIVATE:
07633   case OMP_CLAUSE_COPYIN:
07634   case OMP_CLAUSE_COPYPRIVATE:
07635   case OMP_CLAUSE_IF:
07636   case OMP_CLAUSE_NUM_THREADS:
07637   case OMP_CLAUSE_SCHEDULE:
07638     WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp, 0));
07639     /* FALLTHRU */
07640 
07641   case OMP_CLAUSE_NOWAIT:
07642   case OMP_CLAUSE_ORDERED:
07643   case OMP_CLAUSE_DEFAULT:
07644     WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp));
07645 
07646   case OMP_CLAUSE_REDUCTION:
07647     {
07648       int i;
07649       for (i = 0; i < 4; i++)
07650         WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp, i));
07651       WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp));
07652     }
07653 
07654   default:
07655     gcc_unreachable ();
07656   }
07657       break;
07658 
07659     case TARGET_EXPR:
07660       {
07661   int i, len;
07662 
07663   /* TARGET_EXPRs are peculiar: operands 1 and 3 can be the same.
07664      But, we only want to walk once.  */
07665   len = (TREE_OPERAND (*tp, 3) == TREE_OPERAND (*tp, 1)) ? 2 : 3;
07666   for (i = 0; i < len; ++i)
07667     WALK_SUBTREE (TREE_OPERAND (*tp, i));
07668   WALK_SUBTREE_TAIL (TREE_OPERAND (*tp, len));
07669       }
07670 
07671     case DECL_EXPR:
07672       /* Walk into various fields of the type that it's defining.  We only
07673    want to walk into these fields of a type in this case.  Note that
07674    decls get walked as part of the processing of a BIND_EXPR.
07675 
07676    ??? Precisely which fields of types that we are supposed to walk in
07677    this case vs. the normal case aren't well defined.  */
07678       if (TREE_CODE (DECL_EXPR_DECL (*tp)) == TYPE_DECL
07679     && TREE_CODE (TREE_TYPE (DECL_EXPR_DECL (*tp))) != ERROR_MARK)
07680   {
07681     tree *type_p = &TREE_TYPE (DECL_EXPR_DECL (*tp));
07682 
07683     /* Call the function for the type.  See if it returns anything or
07684        doesn't want us to continue.  If we are to continue, walk both
07685        the normal fields and those for the declaration case.  */
07686     result = (*func) (type_p, &walk_subtrees, data);
07687     if (result || !walk_subtrees)
07688       return NULL_TREE;
07689 
07690     result = walk_type_fields (*type_p, func, data, pset);
07691     if (result)
07692       return result;
07693 
07694     /* If this is a record type, also walk the fields.  */
07695     if (TREE_CODE (*type_p) == RECORD_TYPE
07696         || TREE_CODE (*type_p) == UNION_TYPE
07697         || TREE_CODE (*type_p) == QUAL_UNION_TYPE)
07698       {
07699         tree field;
07700 
07701         for (field =