00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
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
00069
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
00086 extern int _obstack_allocated_p (struct obstack *h, void *obj);
00087
00088 #ifdef GATHER_STATISTICS
00089
00090
00091 int tree_node_counts[(int) all_kinds];
00092 int tree_node_sizes[(int) all_kinds];
00093
00094
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
00117
00118
00119 static GTY(()) int next_decl_uid;
00120
00121 static GTY(()) int next_type_uid = 1;
00122
00123
00124
00125
00126 struct type_hash GTY(())
00127 {
00128 unsigned long hash;
00129 tree type;
00130 };
00131
00132
00133 #define TYPE_HASH_INITIAL_SIZE 1000
00134
00135
00136
00137
00138
00139
00140
00141
00142 static GTY ((if_marked ("type_hash_marked_p"), param_is (struct type_hash)))
00143 htab_t type_hash_table;
00144
00145
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
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
00191 unsigned const char omp_clause_num_ops[] =
00192 {
00193 0,
00194 1,
00195 1,
00196 1,
00197 1,
00198 4,
00199 1,
00200 1,
00201 1,
00202 1,
00203 1,
00204 0,
00205 0,
00206 0
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
00228
00229 void
00230 init_ttree (void)
00231 {
00232
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
00312
00313
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
00323
00324
00325 size_t
00326 tree_code_size (enum tree_code code)
00327 {
00328 switch (TREE_CODE_CLASS (code))
00329 {
00330 case tcc_declaration:
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:
00361 return sizeof (struct tree_type);
00362
00363 case tcc_reference:
00364 case tcc_expression:
00365 case tcc_statement:
00366 case tcc_comparison:
00367 case tcc_unary:
00368 case tcc_binary:
00369 return (sizeof (struct tree_exp)
00370 + (TREE_CODE_LENGTH (code) - 1) * sizeof (char *));
00371
00372 case tcc_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:
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
00414
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
00447
00448
00449
00450
00451
00452
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:
00466 kind = d_kind;
00467 break;
00468
00469 case tcc_type:
00470 kind = t_kind;
00471 break;
00472
00473 case tcc_statement:
00474 kind = s_kind;
00475 break;
00476
00477 case tcc_reference:
00478 kind = r_kind;
00479 break;
00480
00481 case tcc_expression:
00482 case tcc_comparison:
00483 case tcc_unary:
00484 case tcc_binary:
00485 kind = e_kind;
00486 break;
00487
00488 case tcc_constant:
00489 kind = c_kind;
00490 break;
00491
00492 case tcc_exceptional:
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
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
00575 TYPE_ATTRIBUTES (t) = NULL_TREE;
00576 targetm.set_default_type_attributes (t);
00577
00578
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
00598
00599 TREE_SIDE_EFFECTS (t) = 1;
00600 break;
00601
00602 default:
00603 break;
00604 }
00605 break;
00606
00607 default:
00608
00609 break;
00610 }
00611
00612 return t;
00613 }
00614
00615
00616
00617
00618
00619
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
00667
00668
00669
00670
00671 TYPE_SYMTAB_POINTER (t) = 0;
00672 TYPE_SYMTAB_ADDRESS (t) = 0;
00673
00674
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
00686
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
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
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
00726
00727
00728
00729
00730
00731
00732
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
00754
00755 negative = ((val >> (bits - 1)) & 1) != 0;
00756
00757
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
00767 hi = (negative ? ~(unsigned HOST_WIDE_INT) 0 : 0);
00768
00769
00770
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
00787
00788
00789
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
00801
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
00815
00816
00817
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
00834 if (!hi && !low)
00835 {
00836 limit = 1;
00837 ix = 0;
00838 }
00839 break;
00840
00841 case BOOLEAN_TYPE:
00842
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
00853 limit = INTEGER_SHARE_LIMIT;
00854 if (!hi && low < (unsigned HOST_WIDE_INT)INTEGER_SHARE_LIMIT)
00855 ix = low;
00856 }
00857 else
00858 {
00859
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
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
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
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
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
00914 t = int_cst_node;
00915 *slot = t;
00916
00917 int_cst_node = make_node (INTEGER_CST);
00918 }
00919 }
00920
00921 return t;
00922 }
00923
00924
00925
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
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
00959
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
00975
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
00988 for (link = vals; link; link = TREE_CHAIN (link))
00989 {
00990 tree value = TREE_VALUE (link);
00991
00992
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
01007
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
01022
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
01033
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
01053
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
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
01091
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
01104
01105
01106 REAL_VALUE_TYPE
01107 real_value_from_int_cst (tree type, tree i)
01108 {
01109 REAL_VALUE_TYPE d;
01110
01111
01112
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
01122
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
01138
01139
01140
01141 tree
01142 build_string (int len, const char *str)
01143 {
01144 tree s;
01145 size_t length;
01146
01147
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
01169
01170
01171
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
01188
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
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
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
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
01278
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
01294
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
01310
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
01336
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
01346 gcc_assert (shift_amount <= HOST_BITS_PER_WIDE_INT);
01347 if (shift_amount == HOST_BITS_PER_WIDE_INT)
01348
01349
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
01362
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
01386
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
01407
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
01423
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
01443
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
01461
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
01481
01482
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
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
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
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
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
01556
01557 int
01558 really_constant_p (tree exp)
01559 {
01560
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
01569
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
01584
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
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
01614
01615
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
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
01656
01657
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
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
01697
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
01713
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
01725
01726
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
01751
01752
01753
01754
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
01780
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
01796 || (HOST_WIDE_INT) TREE_INT_CST_LOW (t) < 0)
01797 return -1;
01798
01799 return TREE_INT_CST_LOW (t);
01800 }
01801
01802
01803
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
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
01822
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
01836
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
01846
01847
01848
01849 HOST_WIDE_INT
01850 int_bit_position (tree field)
01851 {
01852 return tree_low_cst (bit_position (field), 0);
01853 }
01854
01855
01856
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
01866
01867
01868
01869 HOST_WIDE_INT
01870 int_byte_position (tree field)
01871 {
01872 return tree_low_cst (byte_position (field), 0);
01873 }
01874
01875
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
01886
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
01895 return expr_align (TREE_OPERAND (t, 0));
01896
01897 case COND_EXPR:
01898
01899
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
01918 return TYPE_ALIGN (TREE_TYPE (t));
01919 }
01920
01921
01922
01923
01924 tree
01925 array_type_nelts (tree type)
01926 {
01927 tree index_type, min, max;
01928
01929
01930
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
01944
01945
01946
01947 tree
01948 staticp (tree arg)
01949 {
01950 switch (TREE_CODE (arg))
01951 {
01952 case FUNCTION_DECL:
01953
01954
01955
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
01977
01978 if (TREE_CODE (TREE_OPERAND (arg, 1)) != FIELD_DECL)
01979 return (*lang_hooks.staticp) (arg);
01980
01981
01982
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
02014
02015
02016
02017
02018
02019
02020
02021
02022
02023
02024
02025
02026
02027
02028
02029
02030
02031
02032
02033
02034
02035 tree
02036 save_expr (tree expr)
02037 {
02038 tree t = fold (expr);
02039 tree inner;
02040
02041
02042
02043
02044
02045
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
02055
02056
02057
02058
02059
02060
02061
02062
02063 if (contains_placeholder_p (inner))
02064 return t;
02065
02066 t = build1 (SAVE_EXPR, TREE_TYPE (expr), t);
02067
02068
02069
02070
02071 TREE_SIDE_EFFECTS (t) = 1;
02072 TREE_INVARIANT (t) = 1;
02073 return t;
02074 }
02075
02076
02077
02078
02079 tree
02080 skip_simple_arithmetic (tree expr)
02081 {
02082 tree inner;
02083
02084
02085
02086 while (TREE_CODE (expr) == NON_LVALUE_EXPR)
02087 expr = TREE_OPERAND (expr, 0);
02088
02089
02090
02091
02092
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
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:
02161 break;
02162 }
02163 switch (code)
02164 {
02165
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
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
02192
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
02210
02211
02212
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
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
02261
02262
02263
02264 static bool
02265 type_contains_placeholder_1 (tree type)
02266 {
02267
02268
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
02276
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
02294 return (CONTAINS_PLACEHOLDER_P (TYPE_MIN_VALUE (type))
02295 || CONTAINS_PLACEHOLDER_P (TYPE_MAX_VALUE (type)));
02296
02297 case ARRAY_TYPE:
02298
02299
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
02330
02331 if (TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) > 0)
02332 return TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) - 1;
02333
02334
02335
02336 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = 1;
02337
02338
02339 result = type_contains_placeholder_1 (type);
02340
02341
02342 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = result + 1;
02343
02344 return result;
02345 }
02346
02347
02348
02349
02350
02351
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
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
02374
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
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
02470
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
02479
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
02512
02513 return exp;
02514 }
02515
02516
02517
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
02597
02598
02599
02600
02601
02602
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
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
02662
02663
02664 return stabilize_reference_1 (ref);
02665
02666
02667
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
02684
02685
02686
02687
02688
02689
02690
02691
02692
02693
02694
02695
02696 tree
02697 stabilize_reference_1 (tree e)
02698 {
02699 tree result;
02700 enum tree_code code = TREE_CODE (e);
02701
02702
02703
02704
02705
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
02720
02721
02722
02723 if (TREE_SIDE_EFFECTS (e))
02724 return save_expr (e);
02725 return e;
02726
02727 case tcc_constant:
02728
02729
02730 return e;
02731
02732 case tcc_binary:
02733
02734
02735
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
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
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
02765
02766
02767
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
02776
02777
02778
02779
02780
02781
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
02793
02794
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
02806
02807
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
02821
02822
02823
02824
02825
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
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
02855
02856
02857
02858
02859
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:
02887 kind = s_kind;
02888 break;
02889 case tcc_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
02930
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
02939
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
02993
02994
02995
02996
02997
02998
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
03043
03044 i = call_expr_flags (t);
03045 if (!(i & (ECF_CONST | ECF_PURE)))
03046 side_effects = 1;
03047
03048
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
03150
03151
03152
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
03175
03176
03177
03178
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
03188
03189
03190
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
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
03221
03222
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
03237
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
03261
03262
03263 void
03264 annotate_with_file_line (tree node, const char *file, int line)
03265 {
03266
03267
03268
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
03279
03280
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
03304
03305
03306 tree
03307 build_decl_attribute_variant (tree ddecl, tree attribute)
03308 {
03309 DECL_ATTRIBUTES (ddecl) = attribute;
03310 return ddecl;
03311 }
03312
03313
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
03329 static inline hashval_t
03330 iterative_hash_hashval_t (hashval_t val, hashval_t val2)
03331 {
03332
03333 hashval_t a = 0x9e3779b9;
03334
03335 mix (a, val, val2);
03336 return val2;
03337 }
03338
03339
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
03349
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
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
03367
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
03382
03383
03384
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
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
03446
03447
03448
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
03458
03459
03460
03461
03462
03463
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
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
03504
03505
03506
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
03515
03516
03517
03518
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
03537
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
03559
03560 tree
03561 merge_attributes (tree a1, tree a2)
03562 {
03563 tree attributes;
03564
03565
03566
03567 if ((attributes = a1) == 0)
03568 attributes = a2;
03569
03570
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
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
03618
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
03628
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
03640
03641
03642
03643
03644
03645
03646
03647
03648 tree
03649 merge_dllimport_decl_attributes (tree old, tree new)
03650 {
03651 tree a;
03652 int delete_dllimport_p = 1;
03653
03654
03655
03656
03657
03658
03659
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
03672
03673
03674
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
03681
03682
03683
03684
03685
03686 if (TREE_CODE (old) == VAR_DECL && TREE_ADDRESSABLE (old))
03687 DECL_DLLIMPORT_P (new) = 1;
03688 }
03689
03690
03691
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
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
03726
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
03735
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
03764
03765 else if (is_attribute_p ("dllimport", name))
03766 {
03767
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
03779
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
03796
03797 DECL_EXTERNAL (node) = 1;
03798
03799
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
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
03822
03823
03824
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
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
03842 && TYPE_CONTEXT (cand) == TYPE_CONTEXT (base)
03843 && attribute_list_equal (TYPE_ATTRIBUTES (cand),
03844 TYPE_ATTRIBUTES (base)));
03845 }
03846
03847
03848
03849
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
03860
03861
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
03870
03871
03872 tree
03873 build_qualified_type (tree type, int type_quals)
03874 {
03875 tree t;
03876
03877
03878 t = get_qualified_type (type, type_quals);
03879
03880
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
03891
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
03902 TYPE_MAIN_VARIANT (t) = t;
03903 TYPE_NEXT_VARIANT (t) = 0;
03904
03905
03906
03907
03908
03909 return t;
03910 }
03911
03912
03913
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
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
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
03940
03941 unsigned int
03942 tree_map_hash (const void *item)
03943 {
03944 return (((const struct tree_map *) item)->hash);
03945 }
03946
03947
03948
03949
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
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
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
03977
03978
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
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
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
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
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
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
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
04071
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
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
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
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
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
04145
04146
04147
04148
04149
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
04165
04166
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
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
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
04258
04259 static hashval_t
04260 type_hash_hash (const void *item)
04261 {
04262 return ((const struct type_hash *) item)->hash;
04263 }
04264
04265
04266
04267
04268 tree
04269 type_hash_lookup (hashval_t hashcode, tree type)
04270 {
04271 struct type_hash *h, in;
04272
04273
04274
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
04287
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
04303
04304
04305
04306
04307
04308
04309
04310
04311 tree
04312 type_hash_canon (unsigned int hashcode, tree type)
04313 {
04314 tree t1;
04315
04316
04317
04318 gcc_assert (TYPE_MAIN_VARIANT (type) == type);
04319
04320 if (!lang_hooks.types.hash_types)
04321 return type;
04322
04323
04324
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
04342
04343
04344
04345
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
04365
04366
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
04375 hashcode = iterative_hash_object
04376 (IDENTIFIER_HASH_VALUE (TREE_PURPOSE (tail)), hashcode);
04377 return hashcode;
04378 }
04379
04380
04381
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
04391
04392
04393
04394
04395
04396
04397
04398 int
04399 attribute_list_contained (tree l1, tree l2)
04400 {
04401 tree t1, t2;
04402
04403
04404 if (l1 == l2)
04405 return 1;
04406
04407
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
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
04447
04448
04449
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
04468
04469
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
04479
04480 if (VOID_TYPE_P (TREE_VALUE (t)))
04481 break;
04482 else
04483 ++i;
04484
04485 return i;
04486 }
04487
04488
04489
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
04510
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
04528
04529
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
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
04551
04552
04553
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
04568
04569
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
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
04588
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
04596
04597
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
04613
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
04631
04632
04633
04634
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
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
04710
04711
04712
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
04752
04753
04754
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
04782
04783
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
04801
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
04823
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
04854
04855
04856
04857
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
04874
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
04896 return iterative_hash_pointer (t, val);
04897
04898 case TREE_LIST:
04899
04900
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
04917
04918
04919
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
04927 default:
04928 class = TREE_CODE_CLASS (code);
04929
04930 if (class == tcc_declaration)
04931 {
04932
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
04942
04943
04944 if (code == NOP_EXPR
04945 || code == CONVERT_EXPR
04946 || code == NON_LVALUE_EXPR)
04947 {
04948
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
04956
04957
04958
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
04979
04980
04981
04982
04983
04984
04985
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
04997
04998
04999
05000
05001
05002
05003
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
05009
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
05023
05024 layout_type (t);
05025
05026 return t;
05027 }
05028
05029
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
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
05046
05047
05048
05049
05050
05051
05052
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
05058
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
05078
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
05087
05088
05089
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
05111
05112
05113
05114
05115
05116
05117
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
05141
05142
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
05163
05164
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
05194
05195
05196 tree
05197 build_index_2_type (tree lowval, tree highval)
05198 {
05199 return build_range_type (sizetype, lowval, highval);
05200 }
05201
05202
05203
05204
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
05242
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
05256
05257
05258
05259
05260
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
05275 t = make_node (FUNCTION_TYPE);
05276 TREE_TYPE (t) = value_type;
05277 TYPE_ARG_TYPES (t) = arg_types;
05278
05279
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
05290
05291
05292
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
05321
05322
05323
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
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
05342
05343 argtypes = tree_cons (NULL_TREE, ptype, argtypes);
05344 TYPE_ARG_TYPES (t) = argtypes;
05345
05346
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
05359
05360
05361
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
05374
05375
05376
05377 tree
05378 build_offset_type (tree basetype, tree type)
05379 {
05380 tree t;
05381 hashval_t hashcode = 0;
05382
05383
05384 t = make_node (OFFSET_TYPE);
05385
05386 TYPE_OFFSET_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
05387 TREE_TYPE (t) = type;
05388
05389
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
05401
05402 tree
05403 build_complex_type (tree component_type)
05404 {
05405 tree t;
05406 hashval_t hashcode;
05407
05408
05409 t = make_node (COMPLEX_TYPE);
05410
05411 TREE_TYPE (t) = TYPE_MAIN_VARIANT (component_type);
05412
05413
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
05421
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
05459
05460
05461
05462
05463
05464
05465
05466
05467
05468
05469
05470
05471
05472
05473
05474
05475
05476
05477
05478
05479
05480
05481 tree
05482 get_unwidened (tree op, tree for_type)
05483 {
05484
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
05500
05501
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
05509
05510 if (bitschange < 0
05511 && final_prec > TYPE_PRECISION (TREE_TYPE (op)))
05512 break;
05513
05514
05515
05516 op = TREE_OPERAND (op, 0);
05517
05518
05519
05520
05521
05522
05523
05524
05525 if (bitschange > 0)
05526 {
05527 if (! uns || final_prec <= TYPE_PRECISION (TREE_TYPE (op)))
05528 win = op;
05529
05530
05531
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
05545 && TREE_CODE (type) != REAL_TYPE
05546
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
05557
05558
05559
05560
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
05578
05579
05580
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
05597 if (bitschange < 0)
05598 break;
05599
05600
05601
05602
05603 if (bitschange > 0)
05604 {
05605 op = TREE_OPERAND (op, 0);
05606
05607
05608 if (first)
05609 uns = TYPE_UNSIGNED (TREE_TYPE (op));
05610
05611
05612
05613 else if (uns != TYPE_UNSIGNED (TREE_TYPE (op)))
05614 break;
05615 first = 0;
05616 }
05617 else
05618 {
05619
05620
05621 if (first)
05622 uns = TYPE_UNSIGNED (TREE_TYPE (op));
05623 first = 0;
05624 op = TREE_OPERAND (op, 0);
05625
05626
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
05636 && TREE_CODE (TREE_TYPE (op)) != REAL_TYPE
05637
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
05648
05649
05650
05651
05652
05653
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
05671
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
05682
05683
05684
05685
05686
05687
05688
05689
05690
05691
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
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
05712 if (ok_for_low_bound && ok_for_high_bound)
05713 return 1;
05714
05715
05716
05717
05718 if (TYPE_UNSIGNED (type) && tree_int_cst_sgn (c) < 0)
05719 return 0;
05720
05721
05722 if (TYPE_PRECISION (type) > TYPE_PRECISION (TREE_TYPE (c)))
05723 return 1;
05724
05725
05726 if (! TYPE_UNSIGNED (type)
05727 && TYPE_UNSIGNED (TREE_TYPE (c))
05728 && tree_int_cst_msb (c))
05729 return 0;
05730
05731
05732
05733
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
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
05748
05749
05750
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
05768
05769
05770
05771
05772
05773
05774
05775
05776
05777
05778
05779
05780
05781 bool
05782 variably_modified_type_p (tree type, tree fn)
05783 {
05784 tree t;
05785
05786
05787
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
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
05813
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
05823
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
05832
05833
05834
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
05849
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
05859
05860 return lang_hooks.tree_inlining.var_mod_type_p (type, fn);
05861
05862 #undef RETURN_TRUE_IF_VAR
05863 }
05864
05865
05866
05867
05868 tree
05869 get_containing_scope (tree t)
05870 {
05871 return (TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t));
05872 }
05873
05874
05875
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
05886
05887
05888
05889
05890
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
05910
05911
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
05947
05948
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
05959
05960 gcc_assert (TREE_CODE (call) == CALL_EXPR);
05961
05962
05963
05964 addr = TREE_OPERAND (call, 0);
05965
05966 STRIP_NOPS (addr);
05967
05968
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
05975
05976 if (TREE_CODE (addr) == ADDR_EXPR
05977 && TREE_CODE (TREE_OPERAND (addr, 0)) == FUNCTION_DECL)
05978 return TREE_OPERAND (addr, 0);
05979
05980
05981
05982 return lang_hooks.lang_get_callee_fndecl (call);
05983 }
05984
05985
05986
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
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
06049
06050
06051 void
06052 clean_symbol_name (char *p)
06053 {
06054 for (; *p; p++)
06055 if (! (ISALNUM (*p)
06056 #ifndef NO_DOLLAR_IN_LABEL
06057 || *p == '$'
06058 #endif
06059 #ifndef NO_DOT_IN_LABEL
06060 || *p == '.'
06061 #endif
06062 ))
06063 *p = '_';
06064 }
06065
06066
06067
06068
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
06082
06083
06084
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
06101
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
06125
06126
06127
06128 sprintf (buf, FILE_FUNCTION_FORMAT, type, p);
06129
06130 return get_identifier (buf);
06131 }
06132
06133
06134
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
06150
06151
06152
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
06193
06194
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
06230
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
06244
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
06279
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
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
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
06350
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
06366
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
06378
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
06390
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
06403
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
06416
06417
06418
06419
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
06428
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
06455
06456
06457
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
06489
06490
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
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
06507
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
06524
06525
06526
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
06533
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
06552
06553
06554 void
06555 build_common_tree_nodes_2 (int short_double)
06556 {
06557
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
06575
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
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
06646
06647
06648
06649
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
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
06683
06684
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
06795
06796
06797
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
06838
06839
06840
06841
06842
06843
06844
06845
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
06872
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
06889
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
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
06919
06920
06921 tree
06922 build_vector_type (tree innertype, int nunits)
06923 {
06924 return make_vector_type (innertype, nunits, VOIDmode);
06925 }
06926
06927
06928
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
06939
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
06954
06955
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
06987
06988 tree
06989 build_empty_stmt (void)
06990 {
06991 return build1 (NOP_EXPR, void_type_node, size_zero_node);
06992 }
06993
06994
06995
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
07021
07022
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
07049
07050
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
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
07093
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
07105
07106
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
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
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
07144
07145 return orig_field;
07146 }
07147
07148
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
07168
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
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
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
07227
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
07239 det |= (oprec > iprec) ? 4 : 0;
07240 det |= TYPE_UNSIGNED (outer) ? 2 : 0;
07241 det |= TYPE_UNSIGNED (inner) ? 1 : 0;
07242
07243
07244 switch (det)
07245 {
07246 case 0:
07247 case 1:
07248
07249 prec = oprec - 1;
07250 break;
07251 case 2:
07252 case 3:
07253
07254 prec = oprec;
07255 break;
07256 case 4:
07257
07258 prec = iprec - 1;
07259 break;
07260 case 5:
07261
07262 prec = iprec;
07263 break;
07264 case 6:
07265
07266 prec = oprec;
07267 break;
07268 case 7:
07269
07270 prec = iprec;
07271 break;
07272 default:
07273 gcc_unreachable ();
07274 }
07275
07276
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
07294
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
07304
07305 if (TYPE_UNSIGNED (outer)
07306
07307
07308
07309 || (oprec > iprec && TYPE_UNSIGNED (inner)))
07310 lo = hi = 0;
07311 else
07312 {
07313
07314
07315
07316
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
07336
07337
07338
07339
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
07352
07353
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
07400
07401
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
07414
07415
07416
07417
07418
07419
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
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
07443
07444 case FUNCTION_TYPE:
07445 WALK_SUBTREE (TREE_TYPE (type));
07446 {
07447 tree arg;
07448
07449
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
07457
07458
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
07487
07488
07489
07490
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
07509 if (!*tp)
07510 return NULL_TREE;
07511
07512
07513
07514 if (pset && pointer_set_insert (pset, *tp))
07515 return NULL_TREE;
07516
07517
07518 walk_subtrees = 1;
07519 result = (*func) (tp, &walk_subtrees, data);
07520
07521
07522 if (result)
07523 return result;
07524
07525 code = TREE_CODE (*tp);
07526
07527
07528
07529 if (!walk_subtrees)
07530 {
07531
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
07559
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
07575 while (--len)
07576 WALK_SUBTREE (TREE_VEC_ELT (*tp, len));
07577
07578
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
07607
07608
07609
07610
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
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
07664
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
07673
07674
07675
07676
07677
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
07684
07685
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
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 =