Mercurial > hg > CbC > CbC_gcc
comparison gcc/tree.c @ 57:326d9e06c2e3
modify c-parser.c
author | ryoma <e075725@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 15 Feb 2010 00:54:17 +0900 |
parents | 9de9dad105d4 77e2b8dfacca |
children | 1b10fe6932e1 |
comparison
equal
deleted
inserted
replaced
54:f62c169bbc24 | 57:326d9e06c2e3 |
---|---|
1 /* Language-independent node constructors for parse phase of GNU compiler. | 1 /* Language-independent node constructors for parse phase of GNU compiler. |
2 Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, | 2 Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, |
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 | 3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 |
4 Free Software Foundation, Inc. | 4 Free Software Foundation, Inc. |
5 | 5 |
6 This file is part of GCC. | 6 This file is part of GCC. |
7 | 7 |
8 GCC is free software; you can redistribute it and/or modify it under | 8 GCC is free software; you can redistribute it and/or modify it under |
43 #include "ggc.h" | 43 #include "ggc.h" |
44 #include "hashtab.h" | 44 #include "hashtab.h" |
45 #include "output.h" | 45 #include "output.h" |
46 #include "target.h" | 46 #include "target.h" |
47 #include "langhooks.h" | 47 #include "langhooks.h" |
48 #include "tree-inline.h" | |
48 #include "tree-iterator.h" | 49 #include "tree-iterator.h" |
49 #include "basic-block.h" | 50 #include "basic-block.h" |
50 #include "tree-flow.h" | 51 #include "tree-flow.h" |
51 #include "params.h" | 52 #include "params.h" |
52 #include "pointer-set.h" | 53 #include "pointer-set.h" |
53 #include "fixed-value.h" | 54 #include "fixed-value.h" |
55 #include "tree-pass.h" | |
56 #include "langhooks-def.h" | |
57 #include "diagnostic.h" | |
58 #include "cgraph.h" | |
59 #include "timevar.h" | |
60 #include "except.h" | |
61 #include "debug.h" | |
62 #include "intl.h" | |
54 | 63 |
55 /* Tree code classes. */ | 64 /* Tree code classes. */ |
56 | 65 |
57 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE, | 66 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE, |
58 #define END_OF_BASE_TREE_CODES tcc_exceptional, | 67 #define END_OF_BASE_TREE_CODES tcc_exceptional, |
146 | 155 |
147 /* Unique id for next decl created. */ | 156 /* Unique id for next decl created. */ |
148 static GTY(()) int next_decl_uid; | 157 static GTY(()) int next_decl_uid; |
149 /* Unique id for next type created. */ | 158 /* Unique id for next type created. */ |
150 static GTY(()) int next_type_uid = 1; | 159 static GTY(()) int next_type_uid = 1; |
160 /* Unique id for next debug decl created. Use negative numbers, | |
161 to catch erroneous uses. */ | |
162 static GTY(()) int next_debug_decl_uid; | |
151 | 163 |
152 /* Since we cannot rehash a type after it is in the table, we have to | 164 /* Since we cannot rehash a type after it is in the table, we have to |
153 keep the hash code. */ | 165 keep the hash code. */ |
154 | 166 |
155 struct type_hash GTY(()) | 167 struct GTY(()) type_hash { |
156 { | |
157 unsigned long hash; | 168 unsigned long hash; |
158 tree type; | 169 tree type; |
159 }; | 170 }; |
160 | 171 |
161 /* Initial size of the hash table (rounded to next prime). */ | 172 /* Initial size of the hash table (rounded to next prime). */ |
187 htab_t cl_option_hash_table; | 198 htab_t cl_option_hash_table; |
188 | 199 |
189 /* General tree->tree mapping structure for use in hash tables. */ | 200 /* General tree->tree mapping structure for use in hash tables. */ |
190 | 201 |
191 | 202 |
192 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map))) | 203 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map))) |
193 htab_t debug_expr_for_decl; | 204 htab_t debug_expr_for_decl; |
194 | 205 |
195 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map))) | 206 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map))) |
196 htab_t value_expr_for_decl; | 207 htab_t value_expr_for_decl; |
197 | 208 |
198 static GTY ((if_marked ("tree_priority_map_marked_p"), | 209 static GTY ((if_marked ("tree_priority_map_marked_p"), |
199 param_is (struct tree_priority_map))) | 210 param_is (struct tree_priority_map))) |
200 htab_t init_priority_for_decl; | 211 htab_t init_priority_for_decl; |
201 | |
202 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map))) | |
203 htab_t restrict_base_for_decl; | |
204 | 212 |
205 static void set_type_quals (tree, int); | 213 static void set_type_quals (tree, int); |
206 static int type_hash_eq (const void *, const void *); | 214 static int type_hash_eq (const void *, const void *); |
207 static hashval_t type_hash_hash (const void *); | 215 static hashval_t type_hash_hash (const void *); |
208 static hashval_t int_cst_hash_hash (const void *); | 216 static hashval_t int_cst_hash_hash (const void *); |
259 "ordered", | 267 "ordered", |
260 "default", | 268 "default", |
261 "collapse", | 269 "collapse", |
262 "untied" | 270 "untied" |
263 }; | 271 }; |
264 | 272 |
265 /* Init tree.c. */ | 273 |
266 | 274 /* Return the tree node structure used by tree code CODE. */ |
267 void | 275 |
268 init_ttree (void) | 276 static inline enum tree_node_structure_enum |
269 { | 277 tree_node_structure_for_code (enum tree_code code) |
270 /* Initialize the hash table of types. */ | |
271 type_hash_table = htab_create_ggc (TYPE_HASH_INITIAL_SIZE, type_hash_hash, | |
272 type_hash_eq, 0); | |
273 | |
274 debug_expr_for_decl = htab_create_ggc (512, tree_map_hash, | |
275 tree_map_eq, 0); | |
276 | |
277 value_expr_for_decl = htab_create_ggc (512, tree_map_hash, | |
278 tree_map_eq, 0); | |
279 init_priority_for_decl = htab_create_ggc (512, tree_priority_map_hash, | |
280 tree_priority_map_eq, 0); | |
281 restrict_base_for_decl = htab_create_ggc (256, tree_map_hash, | |
282 tree_map_eq, 0); | |
283 | |
284 int_cst_hash_table = htab_create_ggc (1024, int_cst_hash_hash, | |
285 int_cst_hash_eq, NULL); | |
286 | |
287 int_cst_node = make_node (INTEGER_CST); | |
288 | |
289 cl_option_hash_table = htab_create_ggc (64, cl_option_hash_hash, | |
290 cl_option_hash_eq, NULL); | |
291 | |
292 cl_optimization_node = make_node (OPTIMIZATION_NODE); | |
293 cl_target_option_node = make_node (TARGET_OPTION_NODE); | |
294 | |
295 tree_contains_struct[FUNCTION_DECL][TS_DECL_NON_COMMON] = 1; | |
296 tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_NON_COMMON] = 1; | |
297 tree_contains_struct[TYPE_DECL][TS_DECL_NON_COMMON] = 1; | |
298 | |
299 | |
300 tree_contains_struct[CONST_DECL][TS_DECL_COMMON] = 1; | |
301 tree_contains_struct[VAR_DECL][TS_DECL_COMMON] = 1; | |
302 tree_contains_struct[PARM_DECL][TS_DECL_COMMON] = 1; | |
303 tree_contains_struct[RESULT_DECL][TS_DECL_COMMON] = 1; | |
304 tree_contains_struct[FUNCTION_DECL][TS_DECL_COMMON] = 1; | |
305 tree_contains_struct[TYPE_DECL][TS_DECL_COMMON] = 1; | |
306 tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_COMMON] = 1; | |
307 tree_contains_struct[LABEL_DECL][TS_DECL_COMMON] = 1; | |
308 tree_contains_struct[FIELD_DECL][TS_DECL_COMMON] = 1; | |
309 | |
310 | |
311 tree_contains_struct[CONST_DECL][TS_DECL_WRTL] = 1; | |
312 tree_contains_struct[VAR_DECL][TS_DECL_WRTL] = 1; | |
313 tree_contains_struct[PARM_DECL][TS_DECL_WRTL] = 1; | |
314 tree_contains_struct[RESULT_DECL][TS_DECL_WRTL] = 1; | |
315 tree_contains_struct[FUNCTION_DECL][TS_DECL_WRTL] = 1; | |
316 tree_contains_struct[LABEL_DECL][TS_DECL_WRTL] = 1; | |
317 | |
318 tree_contains_struct[CONST_DECL][TS_DECL_MINIMAL] = 1; | |
319 tree_contains_struct[VAR_DECL][TS_DECL_MINIMAL] = 1; | |
320 tree_contains_struct[PARM_DECL][TS_DECL_MINIMAL] = 1; | |
321 tree_contains_struct[RESULT_DECL][TS_DECL_MINIMAL] = 1; | |
322 tree_contains_struct[FUNCTION_DECL][TS_DECL_MINIMAL] = 1; | |
323 tree_contains_struct[TYPE_DECL][TS_DECL_MINIMAL] = 1; | |
324 tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_MINIMAL] = 1; | |
325 tree_contains_struct[LABEL_DECL][TS_DECL_MINIMAL] = 1; | |
326 tree_contains_struct[FIELD_DECL][TS_DECL_MINIMAL] = 1; | |
327 tree_contains_struct[NAME_MEMORY_TAG][TS_DECL_MINIMAL] = 1; | |
328 tree_contains_struct[SYMBOL_MEMORY_TAG][TS_DECL_MINIMAL] = 1; | |
329 tree_contains_struct[MEMORY_PARTITION_TAG][TS_DECL_MINIMAL] = 1; | |
330 | |
331 tree_contains_struct[NAME_MEMORY_TAG][TS_MEMORY_TAG] = 1; | |
332 tree_contains_struct[SYMBOL_MEMORY_TAG][TS_MEMORY_TAG] = 1; | |
333 tree_contains_struct[MEMORY_PARTITION_TAG][TS_MEMORY_TAG] = 1; | |
334 | |
335 tree_contains_struct[MEMORY_PARTITION_TAG][TS_MEMORY_PARTITION_TAG] = 1; | |
336 | |
337 tree_contains_struct[VAR_DECL][TS_DECL_WITH_VIS] = 1; | |
338 tree_contains_struct[FUNCTION_DECL][TS_DECL_WITH_VIS] = 1; | |
339 tree_contains_struct[TYPE_DECL][TS_DECL_WITH_VIS] = 1; | |
340 tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_WITH_VIS] = 1; | |
341 | |
342 tree_contains_struct[VAR_DECL][TS_VAR_DECL] = 1; | |
343 tree_contains_struct[FIELD_DECL][TS_FIELD_DECL] = 1; | |
344 tree_contains_struct[PARM_DECL][TS_PARM_DECL] = 1; | |
345 tree_contains_struct[LABEL_DECL][TS_LABEL_DECL] = 1; | |
346 tree_contains_struct[RESULT_DECL][TS_RESULT_DECL] = 1; | |
347 tree_contains_struct[CONST_DECL][TS_CONST_DECL] = 1; | |
348 tree_contains_struct[TYPE_DECL][TS_TYPE_DECL] = 1; | |
349 tree_contains_struct[FUNCTION_DECL][TS_FUNCTION_DECL] = 1; | |
350 tree_contains_struct[IMPORTED_DECL][TS_DECL_MINIMAL] = 1; | |
351 tree_contains_struct[IMPORTED_DECL][TS_DECL_COMMON] = 1; | |
352 | |
353 lang_hooks.init_ts (); | |
354 } | |
355 | |
356 | |
357 /* The name of the object as the assembler will see it (but before any | |
358 translations made by ASM_OUTPUT_LABELREF). Often this is the same | |
359 as DECL_NAME. It is an IDENTIFIER_NODE. */ | |
360 tree | |
361 decl_assembler_name (tree decl) | |
362 { | |
363 if (!DECL_ASSEMBLER_NAME_SET_P (decl)) | |
364 lang_hooks.set_decl_assembler_name (decl); | |
365 return DECL_WITH_VIS_CHECK (decl)->decl_with_vis.assembler_name; | |
366 } | |
367 | |
368 /* Compare ASMNAME with the DECL_ASSEMBLER_NAME of DECL. */ | |
369 | |
370 bool | |
371 decl_assembler_name_equal (tree decl, const_tree asmname) | |
372 { | |
373 tree decl_asmname = DECL_ASSEMBLER_NAME (decl); | |
374 const char *decl_str; | |
375 const char *asmname_str; | |
376 bool test = false; | |
377 | |
378 if (decl_asmname == asmname) | |
379 return true; | |
380 | |
381 decl_str = IDENTIFIER_POINTER (decl_asmname); | |
382 asmname_str = IDENTIFIER_POINTER (asmname); | |
383 | |
384 | |
385 /* If the target assembler name was set by the user, things are trickier. | |
386 We have a leading '*' to begin with. After that, it's arguable what | |
387 is the correct thing to do with -fleading-underscore. Arguably, we've | |
388 historically been doing the wrong thing in assemble_alias by always | |
389 printing the leading underscore. Since we're not changing that, make | |
390 sure user_label_prefix follows the '*' before matching. */ | |
391 if (decl_str[0] == '*') | |
392 { | |
393 size_t ulp_len = strlen (user_label_prefix); | |
394 | |
395 decl_str ++; | |
396 | |
397 if (ulp_len == 0) | |
398 test = true; | |
399 else if (strncmp (decl_str, user_label_prefix, ulp_len) == 0) | |
400 decl_str += ulp_len, test=true; | |
401 else | |
402 decl_str --; | |
403 } | |
404 if (asmname_str[0] == '*') | |
405 { | |
406 size_t ulp_len = strlen (user_label_prefix); | |
407 | |
408 asmname_str ++; | |
409 | |
410 if (ulp_len == 0) | |
411 test = true; | |
412 else if (strncmp (asmname_str, user_label_prefix, ulp_len) == 0) | |
413 asmname_str += ulp_len, test=true; | |
414 else | |
415 asmname_str --; | |
416 } | |
417 | |
418 if (!test) | |
419 return false; | |
420 return strcmp (decl_str, asmname_str) == 0; | |
421 } | |
422 | |
423 /* Hash asmnames ignoring the user specified marks. */ | |
424 | |
425 hashval_t | |
426 decl_assembler_name_hash (const_tree asmname) | |
427 { | |
428 if (IDENTIFIER_POINTER (asmname)[0] == '*') | |
429 { | |
430 const char *decl_str = IDENTIFIER_POINTER (asmname) + 1; | |
431 size_t ulp_len = strlen (user_label_prefix); | |
432 | |
433 if (ulp_len == 0) | |
434 ; | |
435 else if (strncmp (decl_str, user_label_prefix, ulp_len) == 0) | |
436 decl_str += ulp_len; | |
437 | |
438 return htab_hash_string (decl_str); | |
439 } | |
440 | |
441 return htab_hash_string (IDENTIFIER_POINTER (asmname)); | |
442 } | |
443 | |
444 /* Compute the number of bytes occupied by a tree with code CODE. | |
445 This function cannot be used for nodes that have variable sizes, | |
446 including TREE_VEC, STRING_CST, and CALL_EXPR. */ | |
447 size_t | |
448 tree_code_size (enum tree_code code) | |
449 { | 278 { |
450 switch (TREE_CODE_CLASS (code)) | 279 switch (TREE_CODE_CLASS (code)) |
451 { | 280 { |
452 case tcc_declaration: /* A decl node */ | |
453 { | |
454 switch (code) | |
455 { | |
456 case FIELD_DECL: | |
457 return sizeof (struct tree_field_decl); | |
458 case PARM_DECL: | |
459 return sizeof (struct tree_parm_decl); | |
460 case VAR_DECL: | |
461 return sizeof (struct tree_var_decl); | |
462 case LABEL_DECL: | |
463 return sizeof (struct tree_label_decl); | |
464 case RESULT_DECL: | |
465 return sizeof (struct tree_result_decl); | |
466 case CONST_DECL: | |
467 return sizeof (struct tree_const_decl); | |
468 case TYPE_DECL: | |
469 return sizeof (struct tree_type_decl); | |
470 case FUNCTION_DECL: | |
471 return sizeof (struct tree_function_decl); | |
472 case NAME_MEMORY_TAG: | |
473 case SYMBOL_MEMORY_TAG: | |
474 return sizeof (struct tree_memory_tag); | |
475 case MEMORY_PARTITION_TAG: | |
476 return sizeof (struct tree_memory_partition_tag); | |
477 default: | |
478 return sizeof (struct tree_decl_non_common); | |
479 } | |
480 } | |
481 | |
482 case tcc_type: /* a type node */ | |
483 return sizeof (struct tree_type); | |
484 | |
485 case tcc_reference: /* a reference */ | |
486 case tcc_expression: /* an expression */ | |
487 case tcc_statement: /* an expression with side effects */ | |
488 case tcc_comparison: /* a comparison expression */ | |
489 case tcc_unary: /* a unary arithmetic expression */ | |
490 case tcc_binary: /* a binary arithmetic expression */ | |
491 return (sizeof (struct tree_exp) | |
492 + (TREE_CODE_LENGTH (code) - 1) * sizeof (tree)); | |
493 | |
494 case tcc_constant: /* a constant */ | |
495 switch (code) | |
496 { | |
497 case INTEGER_CST: return sizeof (struct tree_int_cst); | |
498 case REAL_CST: return sizeof (struct tree_real_cst); | |
499 case FIXED_CST: return sizeof (struct tree_fixed_cst); | |
500 case COMPLEX_CST: return sizeof (struct tree_complex); | |
501 case VECTOR_CST: return sizeof (struct tree_vector); | |
502 case STRING_CST: gcc_unreachable (); | |
503 default: | |
504 return lang_hooks.tree_size (code); | |
505 } | |
506 | |
507 case tcc_exceptional: /* something random, like an identifier. */ | |
508 switch (code) | |
509 { | |
510 case IDENTIFIER_NODE: return lang_hooks.identifier_size; | |
511 case TREE_LIST: return sizeof (struct tree_list); | |
512 | |
513 case ERROR_MARK: | |
514 case PLACEHOLDER_EXPR: return sizeof (struct tree_common); | |
515 | |
516 case TREE_VEC: | |
517 case OMP_CLAUSE: gcc_unreachable (); | |
518 | |
519 case SSA_NAME: return sizeof (struct tree_ssa_name); | |
520 | |
521 case STATEMENT_LIST: return sizeof (struct tree_statement_list); | |
522 case BLOCK: return sizeof (struct tree_block); | |
523 case CONSTRUCTOR: return sizeof (struct tree_constructor); | |
524 case OPTIMIZATION_NODE: return sizeof (struct tree_optimization_option); | |
525 case TARGET_OPTION_NODE: return sizeof (struct tree_target_option); | |
526 | |
527 default: | |
528 return lang_hooks.tree_size (code); | |
529 } | |
530 | |
531 default: | |
532 gcc_unreachable (); | |
533 } | |
534 } | |
535 | |
536 /* Compute the number of bytes occupied by NODE. This routine only | |
537 looks at TREE_CODE, except for those nodes that have variable sizes. */ | |
538 size_t | |
539 tree_size (const_tree node) | |
540 { | |
541 const enum tree_code code = TREE_CODE (node); | |
542 switch (code) | |
543 { | |
544 case TREE_BINFO: | |
545 return (offsetof (struct tree_binfo, base_binfos) | |
546 + VEC_embedded_size (tree, BINFO_N_BASE_BINFOS (node))); | |
547 | |
548 case TREE_VEC: | |
549 return (sizeof (struct tree_vec) | |
550 + (TREE_VEC_LENGTH (node) - 1) * sizeof (tree)); | |
551 | |
552 case STRING_CST: | |
553 return TREE_STRING_LENGTH (node) + offsetof (struct tree_string, str) + 1; | |
554 | |
555 case OMP_CLAUSE: | |
556 return (sizeof (struct tree_omp_clause) | |
557 + (omp_clause_num_ops[OMP_CLAUSE_CODE (node)] - 1) | |
558 * sizeof (tree)); | |
559 | |
560 default: | |
561 if (TREE_CODE_CLASS (code) == tcc_vl_exp) | |
562 return (sizeof (struct tree_exp) | |
563 + (VL_EXP_OPERAND_LENGTH (node) - 1) * sizeof (tree)); | |
564 else | |
565 return tree_code_size (code); | |
566 } | |
567 } | |
568 | |
569 /* Return a newly allocated node of code CODE. For decl and type | |
570 nodes, some other fields are initialized. The rest of the node is | |
571 initialized to zero. This function cannot be used for TREE_VEC or | |
572 OMP_CLAUSE nodes, which is enforced by asserts in tree_code_size. | |
573 | |
574 Achoo! I got a code in the node. */ | |
575 | |
576 tree | |
577 make_node_stat (enum tree_code code MEM_STAT_DECL) | |
578 { | |
579 tree t; | |
580 enum tree_code_class type = TREE_CODE_CLASS (code); | |
581 size_t length = tree_code_size (code); | |
582 #ifdef GATHER_STATISTICS | |
583 tree_node_kind kind; | |
584 | |
585 switch (type) | |
586 { | |
587 case tcc_declaration: /* A decl node */ | |
588 kind = d_kind; | |
589 break; | |
590 | |
591 case tcc_type: /* a type node */ | |
592 kind = t_kind; | |
593 break; | |
594 | |
595 case tcc_statement: /* an expression with side effects */ | |
596 kind = s_kind; | |
597 break; | |
598 | |
599 case tcc_reference: /* a reference */ | |
600 kind = r_kind; | |
601 break; | |
602 | |
603 case tcc_expression: /* an expression */ | |
604 case tcc_comparison: /* a comparison expression */ | |
605 case tcc_unary: /* a unary arithmetic expression */ | |
606 case tcc_binary: /* a binary arithmetic expression */ | |
607 kind = e_kind; | |
608 break; | |
609 | |
610 case tcc_constant: /* a constant */ | |
611 kind = c_kind; | |
612 break; | |
613 | |
614 case tcc_exceptional: /* something random, like an identifier. */ | |
615 switch (code) | |
616 { | |
617 case IDENTIFIER_NODE: | |
618 kind = id_kind; | |
619 break; | |
620 | |
621 case TREE_VEC: | |
622 kind = vec_kind; | |
623 break; | |
624 | |
625 case TREE_BINFO: | |
626 kind = binfo_kind; | |
627 break; | |
628 | |
629 case SSA_NAME: | |
630 kind = ssa_name_kind; | |
631 break; | |
632 | |
633 case BLOCK: | |
634 kind = b_kind; | |
635 break; | |
636 | |
637 case CONSTRUCTOR: | |
638 kind = constr_kind; | |
639 break; | |
640 | |
641 default: | |
642 kind = x_kind; | |
643 break; | |
644 } | |
645 break; | |
646 | |
647 default: | |
648 gcc_unreachable (); | |
649 } | |
650 | |
651 tree_node_counts[(int) kind]++; | |
652 tree_node_sizes[(int) kind] += length; | |
653 #endif | |
654 | |
655 if (code == IDENTIFIER_NODE) | |
656 t = (tree) ggc_alloc_zone_pass_stat (length, &tree_id_zone); | |
657 else | |
658 t = (tree) ggc_alloc_zone_pass_stat (length, &tree_zone); | |
659 | |
660 memset (t, 0, length); | |
661 | |
662 TREE_SET_CODE (t, code); | |
663 | |
664 switch (type) | |
665 { | |
666 case tcc_statement: | |
667 TREE_SIDE_EFFECTS (t) = 1; | |
668 break; | |
669 | |
670 case tcc_declaration: | |
671 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON)) | |
672 { | |
673 if (code == FUNCTION_DECL) | |
674 { | |
675 DECL_ALIGN (t) = FUNCTION_BOUNDARY; | |
676 DECL_MODE (t) = FUNCTION_MODE; | |
677 } | |
678 else | |
679 DECL_ALIGN (t) = 1; | |
680 /* We have not yet computed the alias set for this declaration. */ | |
681 DECL_POINTER_ALIAS_SET (t) = -1; | |
682 } | |
683 DECL_SOURCE_LOCATION (t) = input_location; | |
684 DECL_UID (t) = next_decl_uid++; | |
685 | |
686 break; | |
687 | |
688 case tcc_type: | |
689 TYPE_UID (t) = next_type_uid++; | |
690 TYPE_ALIGN (t) = BITS_PER_UNIT; | |
691 TYPE_USER_ALIGN (t) = 0; | |
692 TYPE_MAIN_VARIANT (t) = t; | |
693 TYPE_CANONICAL (t) = t; | |
694 | |
695 /* Default to no attributes for type, but let target change that. */ | |
696 TYPE_ATTRIBUTES (t) = NULL_TREE; | |
697 targetm.set_default_type_attributes (t); | |
698 | |
699 /* We have not yet computed the alias set for this type. */ | |
700 TYPE_ALIAS_SET (t) = -1; | |
701 break; | |
702 | |
703 case tcc_constant: | |
704 TREE_CONSTANT (t) = 1; | |
705 break; | |
706 | |
707 case tcc_expression: | |
708 switch (code) | |
709 { | |
710 case INIT_EXPR: | |
711 case MODIFY_EXPR: | |
712 case VA_ARG_EXPR: | |
713 case PREDECREMENT_EXPR: | |
714 case PREINCREMENT_EXPR: | |
715 case POSTDECREMENT_EXPR: | |
716 case POSTINCREMENT_EXPR: | |
717 /* All of these have side-effects, no matter what their | |
718 operands are. */ | |
719 TREE_SIDE_EFFECTS (t) = 1; | |
720 break; | |
721 | |
722 default: | |
723 break; | |
724 } | |
725 break; | |
726 | |
727 default: | |
728 /* Other classes need no special treatment. */ | |
729 break; | |
730 } | |
731 | |
732 return t; | |
733 } | |
734 | |
735 /* Return a new node with the same contents as NODE except that its | |
736 TREE_CHAIN is zero and it has a fresh uid. */ | |
737 | |
738 tree | |
739 copy_node_stat (tree node MEM_STAT_DECL) | |
740 { | |
741 tree t; | |
742 enum tree_code code = TREE_CODE (node); | |
743 size_t length; | |
744 | |
745 gcc_assert (code != STATEMENT_LIST); | |
746 | |
747 length = tree_size (node); | |
748 t = (tree) ggc_alloc_zone_pass_stat (length, &tree_zone); | |
749 memcpy (t, node, length); | |
750 | |
751 TREE_CHAIN (t) = 0; | |
752 TREE_ASM_WRITTEN (t) = 0; | |
753 TREE_VISITED (t) = 0; | |
754 t->base.ann = 0; | |
755 | |
756 if (TREE_CODE_CLASS (code) == tcc_declaration) | |
757 { | |
758 DECL_UID (t) = next_decl_uid++; | |
759 if ((TREE_CODE (node) == PARM_DECL || TREE_CODE (node) == VAR_DECL) | |
760 && DECL_HAS_VALUE_EXPR_P (node)) | |
761 { | |
762 SET_DECL_VALUE_EXPR (t, DECL_VALUE_EXPR (node)); | |
763 DECL_HAS_VALUE_EXPR_P (t) = 1; | |
764 } | |
765 if (TREE_CODE (node) == VAR_DECL && DECL_HAS_INIT_PRIORITY_P (node)) | |
766 { | |
767 SET_DECL_INIT_PRIORITY (t, DECL_INIT_PRIORITY (node)); | |
768 DECL_HAS_INIT_PRIORITY_P (t) = 1; | |
769 } | |
770 if (TREE_CODE (node) == VAR_DECL && DECL_BASED_ON_RESTRICT_P (node)) | |
771 { | |
772 SET_DECL_RESTRICT_BASE (t, DECL_GET_RESTRICT_BASE (node)); | |
773 DECL_BASED_ON_RESTRICT_P (t) = 1; | |
774 } | |
775 } | |
776 else if (TREE_CODE_CLASS (code) == tcc_type) | |
777 { | |
778 TYPE_UID (t) = next_type_uid++; | |
779 /* The following is so that the debug code for | |
780 the copy is different from the original type. | |
781 The two statements usually duplicate each other | |
782 (because they clear fields of the same union), | |
783 but the optimizer should catch that. */ | |
784 TYPE_SYMTAB_POINTER (t) = 0; | |
785 TYPE_SYMTAB_ADDRESS (t) = 0; | |
786 | |
787 /* Do not copy the values cache. */ | |
788 if (TYPE_CACHED_VALUES_P(t)) | |
789 { | |
790 TYPE_CACHED_VALUES_P (t) = 0; | |
791 TYPE_CACHED_VALUES (t) = NULL_TREE; | |
792 } | |
793 } | |
794 | |
795 return t; | |
796 } | |
797 | |
798 /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field. | |
799 For example, this can copy a list made of TREE_LIST nodes. */ | |
800 | |
801 tree | |
802 copy_list (tree list) | |
803 { | |
804 tree head; | |
805 tree prev, next; | |
806 | |
807 if (list == 0) | |
808 return 0; | |
809 | |
810 head = prev = copy_node (list); | |
811 next = TREE_CHAIN (list); | |
812 while (next) | |
813 { | |
814 TREE_CHAIN (prev) = copy_node (next); | |
815 prev = TREE_CHAIN (prev); | |
816 next = TREE_CHAIN (next); | |
817 } | |
818 return head; | |
819 } | |
820 | |
821 | |
822 /* Create an INT_CST node with a LOW value sign extended. */ | |
823 | |
824 tree | |
825 build_int_cst (tree type, HOST_WIDE_INT low) | |
826 { | |
827 /* Support legacy code. */ | |
828 if (!type) | |
829 type = integer_type_node; | |
830 | |
831 return build_int_cst_wide (type, low, low < 0 ? -1 : 0); | |
832 } | |
833 | |
834 /* Create an INT_CST node with a LOW value zero extended. */ | |
835 | |
836 tree | |
837 build_int_cstu (tree type, unsigned HOST_WIDE_INT low) | |
838 { | |
839 return build_int_cst_wide (type, low, 0); | |
840 } | |
841 | |
842 /* Create an INT_CST node with a LOW value in TYPE. The value is sign extended | |
843 if it is negative. This function is similar to build_int_cst, but | |
844 the extra bits outside of the type precision are cleared. Constants | |
845 with these extra bits may confuse the fold so that it detects overflows | |
846 even in cases when they do not occur, and in general should be avoided. | |
847 We cannot however make this a default behavior of build_int_cst without | |
848 more intrusive changes, since there are parts of gcc that rely on the extra | |
849 precision of the integer constants. */ | |
850 | |
851 tree | |
852 build_int_cst_type (tree type, HOST_WIDE_INT low) | |
853 { | |
854 unsigned HOST_WIDE_INT low1; | |
855 HOST_WIDE_INT hi; | |
856 | |
857 gcc_assert (type); | |
858 | |
859 fit_double_type (low, low < 0 ? -1 : 0, &low1, &hi, type); | |
860 | |
861 return build_int_cst_wide (type, low1, hi); | |
862 } | |
863 | |
864 /* Create an INT_CST node of TYPE and value HI:LOW. The value is truncated | |
865 and sign extended according to the value range of TYPE. */ | |
866 | |
867 tree | |
868 build_int_cst_wide_type (tree type, | |
869 unsigned HOST_WIDE_INT low, HOST_WIDE_INT high) | |
870 { | |
871 fit_double_type (low, high, &low, &high, type); | |
872 return build_int_cst_wide (type, low, high); | |
873 } | |
874 | |
875 /* These are the hash table functions for the hash table of INTEGER_CST | |
876 nodes of a sizetype. */ | |
877 | |
878 /* Return the hash code code X, an INTEGER_CST. */ | |
879 | |
880 static hashval_t | |
881 int_cst_hash_hash (const void *x) | |
882 { | |
883 const_tree const t = (const_tree) x; | |
884 | |
885 return (TREE_INT_CST_HIGH (t) ^ TREE_INT_CST_LOW (t) | |
886 ^ htab_hash_pointer (TREE_TYPE (t))); | |
887 } | |
888 | |
889 /* Return nonzero if the value represented by *X (an INTEGER_CST tree node) | |
890 is the same as that given by *Y, which is the same. */ | |
891 | |
892 static int | |
893 int_cst_hash_eq (const void *x, const void *y) | |
894 { | |
895 const_tree const xt = (const_tree) x; | |
896 const_tree const yt = (const_tree) y; | |
897 | |
898 return (TREE_TYPE (xt) == TREE_TYPE (yt) | |
899 && TREE_INT_CST_HIGH (xt) == TREE_INT_CST_HIGH (yt) | |
900 && TREE_INT_CST_LOW (xt) == TREE_INT_CST_LOW (yt)); | |
901 } | |
902 | |
903 /* Create an INT_CST node of TYPE and value HI:LOW. | |
904 The returned node is always shared. For small integers we use a | |
905 per-type vector cache, for larger ones we use a single hash table. */ | |
906 | |
907 tree | |
908 build_int_cst_wide (tree type, unsigned HOST_WIDE_INT low, HOST_WIDE_INT hi) | |
909 { | |
910 tree t; | |
911 int ix = -1; | |
912 int limit = 0; | |
913 | |
914 gcc_assert (type); | |
915 | |
916 switch (TREE_CODE (type)) | |
917 { | |
918 case POINTER_TYPE: | |
919 case REFERENCE_TYPE: | |
920 /* Cache NULL pointer. */ | |
921 if (!hi && !low) | |
922 { | |
923 limit = 1; | |
924 ix = 0; | |
925 } | |
926 break; | |
927 | |
928 case BOOLEAN_TYPE: | |
929 /* Cache false or true. */ | |
930 limit = 2; | |
931 if (!hi && low < 2) | |
932 ix = low; | |
933 break; | |
934 | |
935 case INTEGER_TYPE: | |
936 case OFFSET_TYPE: | |
937 if (TYPE_UNSIGNED (type)) | |
938 { | |
939 /* Cache 0..N */ | |
940 limit = INTEGER_SHARE_LIMIT; | |
941 if (!hi && low < (unsigned HOST_WIDE_INT)INTEGER_SHARE_LIMIT) | |
942 ix = low; | |
943 } | |
944 else | |
945 { | |
946 /* Cache -1..N */ | |
947 limit = INTEGER_SHARE_LIMIT + 1; | |
948 if (!hi && low < (unsigned HOST_WIDE_INT)INTEGER_SHARE_LIMIT) | |
949 ix = low + 1; | |
950 else if (hi == -1 && low == -(unsigned HOST_WIDE_INT)1) | |
951 ix = 0; | |
952 } | |
953 break; | |
954 | |
955 case ENUMERAL_TYPE: | |
956 break; | |
957 | |
958 default: | |
959 gcc_unreachable (); | |
960 } | |
961 | |
962 if (ix >= 0) | |
963 { | |
964 /* Look for it in the type's vector of small shared ints. */ | |
965 if (!TYPE_CACHED_VALUES_P (type)) | |
966 { | |
967 TYPE_CACHED_VALUES_P (type) = 1; | |
968 TYPE_CACHED_VALUES (type) = make_tree_vec (limit); | |
969 } | |
970 | |
971 t = TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix); | |
972 if (t) | |
973 { | |
974 /* Make sure no one is clobbering the shared constant. */ | |
975 gcc_assert (TREE_TYPE (t) == type); | |
976 gcc_assert (TREE_INT_CST_LOW (t) == low); | |
977 gcc_assert (TREE_INT_CST_HIGH (t) == hi); | |
978 } | |
979 else | |
980 { | |
981 /* Create a new shared int. */ | |
982 t = make_node (INTEGER_CST); | |
983 | |
984 TREE_INT_CST_LOW (t) = low; | |
985 TREE_INT_CST_HIGH (t) = hi; | |
986 TREE_TYPE (t) = type; | |
987 | |
988 TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix) = t; | |
989 } | |
990 } | |
991 else | |
992 { | |
993 /* Use the cache of larger shared ints. */ | |
994 void **slot; | |
995 | |
996 TREE_INT_CST_LOW (int_cst_node) = low; | |
997 TREE_INT_CST_HIGH (int_cst_node) = hi; | |
998 TREE_TYPE (int_cst_node) = type; | |
999 | |
1000 slot = htab_find_slot (int_cst_hash_table, int_cst_node, INSERT); | |
1001 t = (tree) *slot; | |
1002 if (!t) | |
1003 { | |
1004 /* Insert this one into the hash table. */ | |
1005 t = int_cst_node; | |
1006 *slot = t; | |
1007 /* Make a new node for next time round. */ | |
1008 int_cst_node = make_node (INTEGER_CST); | |
1009 } | |
1010 } | |
1011 | |
1012 return t; | |
1013 } | |
1014 | |
1015 /* Builds an integer constant in TYPE such that lowest BITS bits are ones | |
1016 and the rest are zeros. */ | |
1017 | |
1018 tree | |
1019 build_low_bits_mask (tree type, unsigned bits) | |
1020 { | |
1021 unsigned HOST_WIDE_INT low; | |
1022 HOST_WIDE_INT high; | |
1023 unsigned HOST_WIDE_INT all_ones = ~(unsigned HOST_WIDE_INT) 0; | |
1024 | |
1025 gcc_assert (bits <= TYPE_PRECISION (type)); | |
1026 | |
1027 if (bits == TYPE_PRECISION (type) | |
1028 && !TYPE_UNSIGNED (type)) | |
1029 { | |
1030 /* Sign extended all-ones mask. */ | |
1031 low = all_ones; | |
1032 high = -1; | |
1033 } | |
1034 else if (bits <= HOST_BITS_PER_WIDE_INT) | |
1035 { | |
1036 low = all_ones >> (HOST_BITS_PER_WIDE_INT - bits); | |
1037 high = 0; | |
1038 } | |
1039 else | |
1040 { | |
1041 bits -= HOST_BITS_PER_WIDE_INT; | |
1042 low = all_ones; | |
1043 high = all_ones >> (HOST_BITS_PER_WIDE_INT - bits); | |
1044 } | |
1045 | |
1046 return build_int_cst_wide (type, low, high); | |
1047 } | |
1048 | |
1049 /* Checks that X is integer constant that can be expressed in (unsigned) | |
1050 HOST_WIDE_INT without loss of precision. */ | |
1051 | |
1052 bool | |
1053 cst_and_fits_in_hwi (const_tree x) | |
1054 { | |
1055 if (TREE_CODE (x) != INTEGER_CST) | |
1056 return false; | |
1057 | |
1058 if (TYPE_PRECISION (TREE_TYPE (x)) > HOST_BITS_PER_WIDE_INT) | |
1059 return false; | |
1060 | |
1061 return (TREE_INT_CST_HIGH (x) == 0 | |
1062 || TREE_INT_CST_HIGH (x) == -1); | |
1063 } | |
1064 | |
1065 /* Return a new VECTOR_CST node whose type is TYPE and whose values | |
1066 are in a list pointed to by VALS. */ | |
1067 | |
1068 tree | |
1069 build_vector (tree type, tree vals) | |
1070 { | |
1071 tree v = make_node (VECTOR_CST); | |
1072 int over = 0; | |
1073 tree link; | |
1074 | |
1075 TREE_VECTOR_CST_ELTS (v) = vals; | |
1076 TREE_TYPE (v) = type; | |
1077 | |
1078 /* Iterate through elements and check for overflow. */ | |
1079 for (link = vals; link; link = TREE_CHAIN (link)) | |
1080 { | |
1081 tree value = TREE_VALUE (link); | |
1082 | |
1083 /* Don't crash if we get an address constant. */ | |
1084 if (!CONSTANT_CLASS_P (value)) | |
1085 continue; | |
1086 | |
1087 over |= TREE_OVERFLOW (value); | |
1088 } | |
1089 | |
1090 TREE_OVERFLOW (v) = over; | |
1091 return v; | |
1092 } | |
1093 | |
1094 /* Return a new VECTOR_CST node whose type is TYPE and whose values | |
1095 are extracted from V, a vector of CONSTRUCTOR_ELT. */ | |
1096 | |
1097 tree | |
1098 build_vector_from_ctor (tree type, VEC(constructor_elt,gc) *v) | |
1099 { | |
1100 tree list = NULL_TREE; | |
1101 unsigned HOST_WIDE_INT idx; | |
1102 tree value; | |
1103 | |
1104 FOR_EACH_CONSTRUCTOR_VALUE (v, idx, value) | |
1105 list = tree_cons (NULL_TREE, value, list); | |
1106 return build_vector (type, nreverse (list)); | |
1107 } | |
1108 | |
1109 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values | |
1110 are in the VEC pointed to by VALS. */ | |
1111 tree | |
1112 build_constructor (tree type, VEC(constructor_elt,gc) *vals) | |
1113 { | |
1114 tree c = make_node (CONSTRUCTOR); | |
1115 TREE_TYPE (c) = type; | |
1116 CONSTRUCTOR_ELTS (c) = vals; | |
1117 return c; | |
1118 } | |
1119 | |
1120 /* Build a CONSTRUCTOR node made of a single initializer, with the specified | |
1121 INDEX and VALUE. */ | |
1122 tree | |
1123 build_constructor_single (tree type, tree index, tree value) | |
1124 { | |
1125 VEC(constructor_elt,gc) *v; | |
1126 constructor_elt *elt; | |
1127 tree t; | |
1128 | |
1129 v = VEC_alloc (constructor_elt, gc, 1); | |
1130 elt = VEC_quick_push (constructor_elt, v, NULL); | |
1131 elt->index = index; | |
1132 elt->value = value; | |
1133 | |
1134 t = build_constructor (type, v); | |
1135 TREE_CONSTANT (t) = TREE_CONSTANT (value); | |
1136 return t; | |
1137 } | |
1138 | |
1139 | |
1140 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values | |
1141 are in a list pointed to by VALS. */ | |
1142 tree | |
1143 build_constructor_from_list (tree type, tree vals) | |
1144 { | |
1145 tree t, val; | |
1146 VEC(constructor_elt,gc) *v = NULL; | |
1147 bool constant_p = true; | |
1148 | |
1149 if (vals) | |
1150 { | |
1151 v = VEC_alloc (constructor_elt, gc, list_length (vals)); | |
1152 for (t = vals; t; t = TREE_CHAIN (t)) | |
1153 { | |
1154 constructor_elt *elt = VEC_quick_push (constructor_elt, v, NULL); | |
1155 val = TREE_VALUE (t); | |
1156 elt->index = TREE_PURPOSE (t); | |
1157 elt->value = val; | |
1158 if (!TREE_CONSTANT (val)) | |
1159 constant_p = false; | |
1160 } | |
1161 } | |
1162 | |
1163 t = build_constructor (type, v); | |
1164 TREE_CONSTANT (t) = constant_p; | |
1165 return t; | |
1166 } | |
1167 | |
1168 /* Return a new FIXED_CST node whose type is TYPE and value is F. */ | |
1169 | |
1170 tree | |
1171 build_fixed (tree type, FIXED_VALUE_TYPE f) | |
1172 { | |
1173 tree v; | |
1174 FIXED_VALUE_TYPE *fp; | |
1175 | |
1176 v = make_node (FIXED_CST); | |
1177 fp = GGC_NEW (FIXED_VALUE_TYPE); | |
1178 memcpy (fp, &f, sizeof (FIXED_VALUE_TYPE)); | |
1179 | |
1180 TREE_TYPE (v) = type; | |
1181 TREE_FIXED_CST_PTR (v) = fp; | |
1182 return v; | |
1183 } | |
1184 | |
1185 /* Return a new REAL_CST node whose type is TYPE and value is D. */ | |
1186 | |
1187 tree | |
1188 build_real (tree type, REAL_VALUE_TYPE d) | |
1189 { | |
1190 tree v; | |
1191 REAL_VALUE_TYPE *dp; | |
1192 int overflow = 0; | |
1193 | |
1194 /* ??? Used to check for overflow here via CHECK_FLOAT_TYPE. | |
1195 Consider doing it via real_convert now. */ | |
1196 | |
1197 v = make_node (REAL_CST); | |
1198 dp = GGC_NEW (REAL_VALUE_TYPE); | |
1199 memcpy (dp, &d, sizeof (REAL_VALUE_TYPE)); | |
1200 | |
1201 TREE_TYPE (v) = type; | |
1202 TREE_REAL_CST_PTR (v) = dp; | |
1203 TREE_OVERFLOW (v) = overflow; | |
1204 return v; | |
1205 } | |
1206 | |
1207 /* Return a new REAL_CST node whose type is TYPE | |
1208 and whose value is the integer value of the INTEGER_CST node I. */ | |
1209 | |
1210 REAL_VALUE_TYPE | |
1211 real_value_from_int_cst (const_tree type, const_tree i) | |
1212 { | |
1213 REAL_VALUE_TYPE d; | |
1214 | |
1215 /* Clear all bits of the real value type so that we can later do | |
1216 bitwise comparisons to see if two values are the same. */ | |
1217 memset (&d, 0, sizeof d); | |
1218 | |
1219 real_from_integer (&d, type ? TYPE_MODE (type) : VOIDmode, | |
1220 TREE_INT_CST_LOW (i), TREE_INT_CST_HIGH (i), | |
1221 TYPE_UNSIGNED (TREE_TYPE (i))); | |
1222 return d; | |
1223 } | |
1224 | |
1225 /* Given a tree representing an integer constant I, return a tree | |
1226 representing the same value as a floating-point constant of type TYPE. */ | |
1227 | |
1228 tree | |
1229 build_real_from_int_cst (tree type, const_tree i) | |
1230 { | |
1231 tree v; | |
1232 int overflow = TREE_OVERFLOW (i); | |
1233 | |
1234 v = build_real (type, real_value_from_int_cst (type, i)); | |
1235 | |
1236 TREE_OVERFLOW (v) |= overflow; | |
1237 return v; | |
1238 } | |
1239 | |
1240 /* Return a newly constructed STRING_CST node whose value is | |
1241 the LEN characters at STR. | |
1242 The TREE_TYPE is not initialized. */ | |
1243 | |
1244 tree | |
1245 build_string (int len, const char *str) | |
1246 { | |
1247 tree s; | |
1248 size_t length; | |
1249 | |
1250 /* Do not waste bytes provided by padding of struct tree_string. */ | |
1251 length = len + offsetof (struct tree_string, str) + 1; | |
1252 | |
1253 #ifdef GATHER_STATISTICS | |
1254 tree_node_counts[(int) c_kind]++; | |
1255 tree_node_sizes[(int) c_kind] += length; | |
1256 #endif | |
1257 | |
1258 s = ggc_alloc_tree (length); | |
1259 | |
1260 memset (s, 0, sizeof (struct tree_common)); | |
1261 TREE_SET_CODE (s, STRING_CST); | |
1262 TREE_CONSTANT (s) = 1; | |
1263 TREE_STRING_LENGTH (s) = len; | |
1264 memcpy (s->string.str, str, len); | |
1265 s->string.str[len] = '\0'; | |
1266 | |
1267 return s; | |
1268 } | |
1269 | |
1270 /* Return a newly constructed COMPLEX_CST node whose value is | |
1271 specified by the real and imaginary parts REAL and IMAG. | |
1272 Both REAL and IMAG should be constant nodes. TYPE, if specified, | |
1273 will be the type of the COMPLEX_CST; otherwise a new type will be made. */ | |
1274 | |
1275 tree | |
1276 build_complex (tree type, tree real, tree imag) | |
1277 { | |
1278 tree t = make_node (COMPLEX_CST); | |
1279 | |
1280 TREE_REALPART (t) = real; | |
1281 TREE_IMAGPART (t) = imag; | |
1282 TREE_TYPE (t) = type ? type : build_complex_type (TREE_TYPE (real)); | |
1283 TREE_OVERFLOW (t) = TREE_OVERFLOW (real) | TREE_OVERFLOW (imag); | |
1284 return t; | |
1285 } | |
1286 | |
1287 /* Return a constant of arithmetic type TYPE which is the | |
1288 multiplicative identity of the set TYPE. */ | |
1289 | |
1290 tree | |
1291 build_one_cst (tree type) | |
1292 { | |
1293 switch (TREE_CODE (type)) | |
1294 { | |
1295 case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE: | |
1296 case POINTER_TYPE: case REFERENCE_TYPE: | |
1297 case OFFSET_TYPE: | |
1298 return build_int_cst (type, 1); | |
1299 | |
1300 case REAL_TYPE: | |
1301 return build_real (type, dconst1); | |
1302 | |
1303 case FIXED_POINT_TYPE: | |
1304 /* We can only generate 1 for accum types. */ | |
1305 gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type))); | |
1306 return build_fixed (type, FCONST1(TYPE_MODE (type))); | |
1307 | |
1308 case VECTOR_TYPE: | |
1309 { | |
1310 tree scalar, cst; | |
1311 int i; | |
1312 | |
1313 scalar = build_one_cst (TREE_TYPE (type)); | |
1314 | |
1315 /* Create 'vect_cst_ = {cst,cst,...,cst}' */ | |
1316 cst = NULL_TREE; | |
1317 for (i = TYPE_VECTOR_SUBPARTS (type); --i >= 0; ) | |
1318 cst = tree_cons (NULL_TREE, scalar, cst); | |
1319 | |
1320 return build_vector (type, cst); | |
1321 } | |
1322 | |
1323 case COMPLEX_TYPE: | |
1324 return build_complex (type, | |
1325 build_one_cst (TREE_TYPE (type)), | |
1326 fold_convert (TREE_TYPE (type), integer_zero_node)); | |
1327 | |
1328 default: | |
1329 gcc_unreachable (); | |
1330 } | |
1331 } | |
1332 | |
1333 /* Build a BINFO with LEN language slots. */ | |
1334 | |
1335 tree | |
1336 make_tree_binfo_stat (unsigned base_binfos MEM_STAT_DECL) | |
1337 { | |
1338 tree t; | |
1339 size_t length = (offsetof (struct tree_binfo, base_binfos) | |
1340 + VEC_embedded_size (tree, base_binfos)); | |
1341 | |
1342 #ifdef GATHER_STATISTICS | |
1343 tree_node_counts[(int) binfo_kind]++; | |
1344 tree_node_sizes[(int) binfo_kind] += length; | |
1345 #endif | |
1346 | |
1347 t = (tree) ggc_alloc_zone_pass_stat (length, &tree_zone); | |
1348 | |
1349 memset (t, 0, offsetof (struct tree_binfo, base_binfos)); | |
1350 | |
1351 TREE_SET_CODE (t, TREE_BINFO); | |
1352 | |
1353 VEC_embedded_init (tree, BINFO_BASE_BINFOS (t), base_binfos); | |
1354 | |
1355 return t; | |
1356 } | |
1357 | |
1358 | |
1359 /* Build a newly constructed TREE_VEC node of length LEN. */ | |
1360 | |
1361 tree | |
1362 make_tree_vec_stat (int len MEM_STAT_DECL) | |
1363 { | |
1364 tree t; | |
1365 int length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec); | |
1366 | |
1367 #ifdef GATHER_STATISTICS | |
1368 tree_node_counts[(int) vec_kind]++; | |
1369 tree_node_sizes[(int) vec_kind] += length; | |
1370 #endif | |
1371 | |
1372 t = (tree) ggc_alloc_zone_pass_stat (length, &tree_zone); | |
1373 | |
1374 memset (t, 0, length); | |
1375 | |
1376 TREE_SET_CODE (t, TREE_VEC); | |
1377 TREE_VEC_LENGTH (t) = len; | |
1378 | |
1379 return t; | |
1380 } | |
1381 | |
1382 /* Return 1 if EXPR is the integer constant zero or a complex constant | |
1383 of zero. */ | |
1384 | |
1385 int | |
1386 integer_zerop (const_tree expr) | |
1387 { | |
1388 STRIP_NOPS (expr); | |
1389 | |
1390 return ((TREE_CODE (expr) == INTEGER_CST | |
1391 && TREE_INT_CST_LOW (expr) == 0 | |
1392 && TREE_INT_CST_HIGH (expr) == 0) | |
1393 || (TREE_CODE (expr) == COMPLEX_CST | |
1394 && integer_zerop (TREE_REALPART (expr)) | |
1395 && integer_zerop (TREE_IMAGPART (expr)))); | |
1396 } | |
1397 | |
1398 /* Return 1 if EXPR is the integer constant one or the corresponding | |
1399 complex constant. */ | |
1400 | |
1401 int | |
1402 integer_onep (const_tree expr) | |
1403 { | |
1404 STRIP_NOPS (expr); | |
1405 | |
1406 return ((TREE_CODE (expr) == INTEGER_CST | |
1407 && TREE_INT_CST_LOW (expr) == 1 | |
1408 && TREE_INT_CST_HIGH (expr) == 0) | |
1409 || (TREE_CODE (expr) == COMPLEX_CST | |
1410 && integer_onep (TREE_REALPART (expr)) | |
1411 && integer_zerop (TREE_IMAGPART (expr)))); | |
1412 } | |
1413 | |
1414 /* Return 1 if EXPR is an integer containing all 1's in as much precision as | |
1415 it contains. Likewise for the corresponding complex constant. */ | |
1416 | |
1417 int | |
1418 integer_all_onesp (const_tree expr) | |
1419 { | |
1420 int prec; | |
1421 int uns; | |
1422 | |
1423 STRIP_NOPS (expr); | |
1424 | |
1425 if (TREE_CODE (expr) == COMPLEX_CST | |
1426 && integer_all_onesp (TREE_REALPART (expr)) | |
1427 && integer_zerop (TREE_IMAGPART (expr))) | |
1428 return 1; | |
1429 | |
1430 else if (TREE_CODE (expr) != INTEGER_CST) | |
1431 return 0; | |
1432 | |
1433 uns = TYPE_UNSIGNED (TREE_TYPE (expr)); | |
1434 if (TREE_INT_CST_LOW (expr) == ~(unsigned HOST_WIDE_INT) 0 | |
1435 && TREE_INT_CST_HIGH (expr) == -1) | |
1436 return 1; | |
1437 if (!uns) | |
1438 return 0; | |
1439 | |
1440 /* Note that using TYPE_PRECISION here is wrong. We care about the | |
1441 actual bits, not the (arbitrary) range of the type. */ | |
1442 prec = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (expr))); | |
1443 if (prec >= HOST_BITS_PER_WIDE_INT) | |
1444 { | |
1445 HOST_WIDE_INT high_value; | |
1446 int shift_amount; | |
1447 | |
1448 shift_amount = prec - HOST_BITS_PER_WIDE_INT; | |
1449 | |
1450 /* Can not handle precisions greater than twice the host int size. */ | |
1451 gcc_assert (shift_amount <= HOST_BITS_PER_WIDE_INT); | |
1452 if (shift_amount == HOST_BITS_PER_WIDE_INT) | |
1453 /* Shifting by the host word size is undefined according to the ANSI | |
1454 standard, so we must handle this as a special case. */ | |
1455 high_value = -1; | |
1456 else | |
1457 high_value = ((HOST_WIDE_INT) 1 << shift_amount) - 1; | |
1458 | |
1459 return (TREE_INT_CST_LOW (expr) == ~(unsigned HOST_WIDE_INT) 0 | |
1460 && TREE_INT_CST_HIGH (expr) == high_value); | |
1461 } | |
1462 else | |
1463 return TREE_INT_CST_LOW (expr) == ((unsigned HOST_WIDE_INT) 1 << prec) - 1; | |
1464 } | |
1465 | |
1466 /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only | |
1467 one bit on). */ | |
1468 | |
1469 int | |
1470 integer_pow2p (const_tree expr) | |
1471 { | |
1472 int prec; | |
1473 HOST_WIDE_INT high, low; | |
1474 | |
1475 STRIP_NOPS (expr); | |
1476 | |
1477 if (TREE_CODE (expr) == COMPLEX_CST | |
1478 && integer_pow2p (TREE_REALPART (expr)) | |
1479 && integer_zerop (TREE_IMAGPART (expr))) | |
1480 return 1; | |
1481 | |
1482 if (TREE_CODE (expr) != INTEGER_CST) | |
1483 return 0; | |
1484 | |
1485 prec = (POINTER_TYPE_P (TREE_TYPE (expr)) | |
1486 ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr))); | |
1487 high = TREE_INT_CST_HIGH (expr); | |
1488 low = TREE_INT_CST_LOW (expr); | |
1489 | |
1490 /* First clear all bits that are beyond the type's precision in case | |
1491 we've been sign extended. */ | |
1492 | |
1493 if (prec == 2 * HOST_BITS_PER_WIDE_INT) | |
1494 ; | |
1495 else if (prec > HOST_BITS_PER_WIDE_INT) | |
1496 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT)); | |
1497 else | |
1498 { | |
1499 high = 0; | |
1500 if (prec < HOST_BITS_PER_WIDE_INT) | |
1501 low &= ~((HOST_WIDE_INT) (-1) << prec); | |
1502 } | |
1503 | |
1504 if (high == 0 && low == 0) | |
1505 return 0; | |
1506 | |
1507 return ((high == 0 && (low & (low - 1)) == 0) | |
1508 || (low == 0 && (high & (high - 1)) == 0)); | |
1509 } | |
1510 | |
1511 /* Return 1 if EXPR is an integer constant other than zero or a | |
1512 complex constant other than zero. */ | |
1513 | |
1514 int | |
1515 integer_nonzerop (const_tree expr) | |
1516 { | |
1517 STRIP_NOPS (expr); | |
1518 | |
1519 return ((TREE_CODE (expr) == INTEGER_CST | |
1520 && (TREE_INT_CST_LOW (expr) != 0 | |
1521 || TREE_INT_CST_HIGH (expr) != 0)) | |
1522 || (TREE_CODE (expr) == COMPLEX_CST | |
1523 && (integer_nonzerop (TREE_REALPART (expr)) | |
1524 || integer_nonzerop (TREE_IMAGPART (expr))))); | |
1525 } | |
1526 | |
1527 /* Return 1 if EXPR is the fixed-point constant zero. */ | |
1528 | |
1529 int | |
1530 fixed_zerop (const_tree expr) | |
1531 { | |
1532 return (TREE_CODE (expr) == FIXED_CST | |
1533 && double_int_zero_p (TREE_FIXED_CST (expr).data)); | |
1534 } | |
1535 | |
1536 /* Return the power of two represented by a tree node known to be a | |
1537 power of two. */ | |
1538 | |
1539 int | |
1540 tree_log2 (const_tree expr) | |
1541 { | |
1542 int prec; | |
1543 HOST_WIDE_INT high, low; | |
1544 | |
1545 STRIP_NOPS (expr); | |
1546 | |
1547 if (TREE_CODE (expr) == COMPLEX_CST) | |
1548 return tree_log2 (TREE_REALPART (expr)); | |
1549 | |
1550 prec = (POINTER_TYPE_P (TREE_TYPE (expr)) | |
1551 ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr))); | |
1552 | |
1553 high = TREE_INT_CST_HIGH (expr); | |
1554 low = TREE_INT_CST_LOW (expr); | |
1555 | |
1556 /* First clear all bits that are beyond the type's precision in case | |
1557 we've been sign extended. */ | |
1558 | |
1559 if (prec == 2 * HOST_BITS_PER_WIDE_INT) | |
1560 ; | |
1561 else if (prec > HOST_BITS_PER_WIDE_INT) | |
1562 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT)); | |
1563 else | |
1564 { | |
1565 high = 0; | |
1566 if (prec < HOST_BITS_PER_WIDE_INT) | |
1567 low &= ~((HOST_WIDE_INT) (-1) << prec); | |
1568 } | |
1569 | |
1570 return (high != 0 ? HOST_BITS_PER_WIDE_INT + exact_log2 (high) | |
1571 : exact_log2 (low)); | |
1572 } | |
1573 | |
1574 /* Similar, but return the largest integer Y such that 2 ** Y is less | |
1575 than or equal to EXPR. */ | |
1576 | |
1577 int | |
1578 tree_floor_log2 (const_tree expr) | |
1579 { | |
1580 int prec; | |
1581 HOST_WIDE_INT high, low; | |
1582 | |
1583 STRIP_NOPS (expr); | |
1584 | |
1585 if (TREE_CODE (expr) == COMPLEX_CST) | |
1586 return tree_log2 (TREE_REALPART (expr)); | |
1587 | |
1588 prec = (POINTER_TYPE_P (TREE_TYPE (expr)) | |
1589 ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr))); | |
1590 | |
1591 high = TREE_INT_CST_HIGH (expr); | |
1592 low = TREE_INT_CST_LOW (expr); | |
1593 | |
1594 /* First clear all bits that are beyond the type's precision in case | |
1595 we've been sign extended. Ignore if type's precision hasn't been set | |
1596 since what we are doing is setting it. */ | |
1597 | |
1598 if (prec == 2 * HOST_BITS_PER_WIDE_INT || prec == 0) | |
1599 ; | |
1600 else if (prec > HOST_BITS_PER_WIDE_INT) | |
1601 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT)); | |
1602 else | |
1603 { | |
1604 high = 0; | |
1605 if (prec < HOST_BITS_PER_WIDE_INT) | |
1606 low &= ~((HOST_WIDE_INT) (-1) << prec); | |
1607 } | |
1608 | |
1609 return (high != 0 ? HOST_BITS_PER_WIDE_INT + floor_log2 (high) | |
1610 : floor_log2 (low)); | |
1611 } | |
1612 | |
1613 /* Return 1 if EXPR is the real constant zero. Trailing zeroes matter for | |
1614 decimal float constants, so don't return 1 for them. */ | |
1615 | |
1616 int | |
1617 real_zerop (const_tree expr) | |
1618 { | |
1619 STRIP_NOPS (expr); | |
1620 | |
1621 return ((TREE_CODE (expr) == REAL_CST | |
1622 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst0) | |
1623 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))))) | |
1624 || (TREE_CODE (expr) == COMPLEX_CST | |
1625 && real_zerop (TREE_REALPART (expr)) | |
1626 && real_zerop (TREE_IMAGPART (expr)))); | |
1627 } | |
1628 | |
1629 /* Return 1 if EXPR is the real constant one in real or complex form. | |
1630 Trailing zeroes matter for decimal float constants, so don't return | |
1631 1 for them. */ | |
1632 | |
1633 int | |
1634 real_onep (const_tree expr) | |
1635 { | |
1636 STRIP_NOPS (expr); | |
1637 | |
1638 return ((TREE_CODE (expr) == REAL_CST | |
1639 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst1) | |
1640 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))))) | |
1641 || (TREE_CODE (expr) == COMPLEX_CST | |
1642 && real_onep (TREE_REALPART (expr)) | |
1643 && real_zerop (TREE_IMAGPART (expr)))); | |
1644 } | |
1645 | |
1646 /* Return 1 if EXPR is the real constant two. Trailing zeroes matter | |
1647 for decimal float constants, so don't return 1 for them. */ | |
1648 | |
1649 int | |
1650 real_twop (const_tree expr) | |
1651 { | |
1652 STRIP_NOPS (expr); | |
1653 | |
1654 return ((TREE_CODE (expr) == REAL_CST | |
1655 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst2) | |
1656 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))))) | |
1657 || (TREE_CODE (expr) == COMPLEX_CST | |
1658 && real_twop (TREE_REALPART (expr)) | |
1659 && real_zerop (TREE_IMAGPART (expr)))); | |
1660 } | |
1661 | |
1662 /* Return 1 if EXPR is the real constant minus one. Trailing zeroes | |
1663 matter for decimal float constants, so don't return 1 for them. */ | |
1664 | |
1665 int | |
1666 real_minus_onep (const_tree expr) | |
1667 { | |
1668 STRIP_NOPS (expr); | |
1669 | |
1670 return ((TREE_CODE (expr) == REAL_CST | |
1671 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconstm1) | |
1672 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))))) | |
1673 || (TREE_CODE (expr) == COMPLEX_CST | |
1674 && real_minus_onep (TREE_REALPART (expr)) | |
1675 && real_zerop (TREE_IMAGPART (expr)))); | |
1676 } | |
1677 | |
1678 /* Nonzero if EXP is a constant or a cast of a constant. */ | |
1679 | |
1680 int | |
1681 really_constant_p (const_tree exp) | |
1682 { | |
1683 /* This is not quite the same as STRIP_NOPS. It does more. */ | |
1684 while (CONVERT_EXPR_P (exp) | |
1685 || TREE_CODE (exp) == NON_LVALUE_EXPR) | |
1686 exp = TREE_OPERAND (exp, 0); | |
1687 return TREE_CONSTANT (exp); | |
1688 } | |
1689 | |
1690 /* Return first list element whose TREE_VALUE is ELEM. | |
1691 Return 0 if ELEM is not in LIST. */ | |
1692 | |
1693 tree | |
1694 value_member (tree elem, tree list) | |
1695 { | |
1696 while (list) | |
1697 { | |
1698 if (elem == TREE_VALUE (list)) | |
1699 return list; | |
1700 list = TREE_CHAIN (list); | |
1701 } | |
1702 return NULL_TREE; | |
1703 } | |
1704 | |
1705 /* Return first list element whose TREE_PURPOSE is ELEM. | |
1706 Return 0 if ELEM is not in LIST. */ | |
1707 | |
1708 tree | |
1709 purpose_member (const_tree elem, tree list) | |
1710 { | |
1711 while (list) | |
1712 { | |
1713 if (elem == TREE_PURPOSE (list)) | |
1714 return list; | |
1715 list = TREE_CHAIN (list); | |
1716 } | |
1717 return NULL_TREE; | |
1718 } | |
1719 | |
1720 /* Return nonzero if ELEM is part of the chain CHAIN. */ | |
1721 | |
1722 int | |
1723 chain_member (const_tree elem, const_tree chain) | |
1724 { | |
1725 while (chain) | |
1726 { | |
1727 if (elem == chain) | |
1728 return 1; | |
1729 chain = TREE_CHAIN (chain); | |
1730 } | |
1731 | |
1732 return 0; | |
1733 } | |
1734 | |
1735 /* Return the length of a chain of nodes chained through TREE_CHAIN. | |
1736 We expect a null pointer to mark the end of the chain. | |
1737 This is the Lisp primitive `length'. */ | |
1738 | |
1739 int | |
1740 list_length (const_tree t) | |
1741 { | |
1742 const_tree p = t; | |
1743 #ifdef ENABLE_TREE_CHECKING | |
1744 const_tree q = t; | |
1745 #endif | |
1746 int len = 0; | |
1747 | |
1748 while (p) | |
1749 { | |
1750 p = TREE_CHAIN (p); | |
1751 #ifdef ENABLE_TREE_CHECKING | |
1752 if (len % 2) | |
1753 q = TREE_CHAIN (q); | |
1754 gcc_assert (p != q); | |
1755 #endif | |
1756 len++; | |
1757 } | |
1758 | |
1759 return len; | |
1760 } | |
1761 | |
1762 /* Returns the number of FIELD_DECLs in TYPE. */ | |
1763 | |
1764 int | |
1765 fields_length (const_tree type) | |
1766 { | |
1767 tree t = TYPE_FIELDS (type); | |
1768 int count = 0; | |
1769 | |
1770 for (; t; t = TREE_CHAIN (t)) | |
1771 if (TREE_CODE (t) == FIELD_DECL) | |
1772 ++count; | |
1773 | |
1774 return count; | |
1775 } | |
1776 | |
1777 /* Concatenate two chains of nodes (chained through TREE_CHAIN) | |
1778 by modifying the last node in chain 1 to point to chain 2. | |
1779 This is the Lisp primitive `nconc'. */ | |
1780 | |
1781 tree | |
1782 chainon (tree op1, tree op2) | |
1783 { | |
1784 tree t1; | |
1785 | |
1786 if (!op1) | |
1787 return op2; | |
1788 if (!op2) | |
1789 return op1; | |
1790 | |
1791 for (t1 = op1; TREE_CHAIN (t1); t1 = TREE_CHAIN (t1)) | |
1792 continue; | |
1793 TREE_CHAIN (t1) = op2; | |
1794 | |
1795 #ifdef ENABLE_TREE_CHECKING | |
1796 { | |
1797 tree t2; | |
1798 for (t2 = op2; t2; t2 = TREE_CHAIN (t2)) | |
1799 gcc_assert (t2 != t1); | |
1800 } | |
1801 #endif | |
1802 | |
1803 return op1; | |
1804 } | |
1805 | |
1806 /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */ | |
1807 | |
1808 tree | |
1809 tree_last (tree chain) | |
1810 { | |
1811 tree next; | |
1812 if (chain) | |
1813 while ((next = TREE_CHAIN (chain))) | |
1814 chain = next; | |
1815 return chain; | |
1816 } | |
1817 | |
1818 /* Reverse the order of elements in the chain T, | |
1819 and return the new head of the chain (old last element). */ | |
1820 | |
1821 tree | |
1822 nreverse (tree t) | |
1823 { | |
1824 tree prev = 0, decl, next; | |
1825 for (decl = t; decl; decl = next) | |
1826 { | |
1827 next = TREE_CHAIN (decl); | |
1828 TREE_CHAIN (decl) = prev; | |
1829 prev = decl; | |
1830 } | |
1831 return prev; | |
1832 } | |
1833 | |
1834 /* Return a newly created TREE_LIST node whose | |
1835 purpose and value fields are PARM and VALUE. */ | |
1836 | |
1837 tree | |
1838 build_tree_list_stat (tree parm, tree value MEM_STAT_DECL) | |
1839 { | |
1840 tree t = make_node_stat (TREE_LIST PASS_MEM_STAT); | |
1841 TREE_PURPOSE (t) = parm; | |
1842 TREE_VALUE (t) = value; | |
1843 return t; | |
1844 } | |
1845 | |
1846 /* Return a newly created TREE_LIST node whose | |
1847 purpose and value fields are PURPOSE and VALUE | |
1848 and whose TREE_CHAIN is CHAIN. */ | |
1849 | |
1850 tree | |
1851 tree_cons_stat (tree purpose, tree value, tree chain MEM_STAT_DECL) | |
1852 { | |
1853 tree node; | |
1854 | |
1855 node = (tree) ggc_alloc_zone_pass_stat (sizeof (struct tree_list), &tree_zone); | |
1856 | |
1857 memset (node, 0, sizeof (struct tree_common)); | |
1858 | |
1859 #ifdef GATHER_STATISTICS | |
1860 tree_node_counts[(int) x_kind]++; | |
1861 tree_node_sizes[(int) x_kind] += sizeof (struct tree_list); | |
1862 #endif | |
1863 | |
1864 TREE_SET_CODE (node, TREE_LIST); | |
1865 TREE_CHAIN (node) = chain; | |
1866 TREE_PURPOSE (node) = purpose; | |
1867 TREE_VALUE (node) = value; | |
1868 return node; | |
1869 } | |
1870 | |
1871 /* Return the elements of a CONSTRUCTOR as a TREE_LIST. */ | |
1872 | |
1873 tree | |
1874 ctor_to_list (tree ctor) | |
1875 { | |
1876 tree list = NULL_TREE; | |
1877 tree *p = &list; | |
1878 unsigned ix; | |
1879 tree purpose, val; | |
1880 | |
1881 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), ix, purpose, val) | |
1882 { | |
1883 *p = build_tree_list (purpose, val); | |
1884 p = &TREE_CHAIN (*p); | |
1885 } | |
1886 | |
1887 return list; | |
1888 } | |
1889 | |
1890 /* Return the size nominally occupied by an object of type TYPE | |
1891 when it resides in memory. The value is measured in units of bytes, | |
1892 and its data type is that normally used for type sizes | |
1893 (which is the first type created by make_signed_type or | |
1894 make_unsigned_type). */ | |
1895 | |
1896 tree | |
1897 size_in_bytes (const_tree type) | |
1898 { | |
1899 tree t; | |
1900 | |
1901 if (type == error_mark_node) | |
1902 return integer_zero_node; | |
1903 | |
1904 type = TYPE_MAIN_VARIANT (type); | |
1905 t = TYPE_SIZE_UNIT (type); | |
1906 | |
1907 if (t == 0) | |
1908 { | |
1909 lang_hooks.types.incomplete_type_error (NULL_TREE, type); | |
1910 return size_zero_node; | |
1911 } | |
1912 | |
1913 return t; | |
1914 } | |
1915 | |
1916 /* Return the size of TYPE (in bytes) as a wide integer | |
1917 or return -1 if the size can vary or is larger than an integer. */ | |
1918 | |
1919 HOST_WIDE_INT | |
1920 int_size_in_bytes (const_tree type) | |
1921 { | |
1922 tree t; | |
1923 | |
1924 if (type == error_mark_node) | |
1925 return 0; | |
1926 | |
1927 type = TYPE_MAIN_VARIANT (type); | |
1928 t = TYPE_SIZE_UNIT (type); | |
1929 if (t == 0 | |
1930 || TREE_CODE (t) != INTEGER_CST | |
1931 || TREE_INT_CST_HIGH (t) != 0 | |
1932 /* If the result would appear negative, it's too big to represent. */ | |
1933 || (HOST_WIDE_INT) TREE_INT_CST_LOW (t) < 0) | |
1934 return -1; | |
1935 | |
1936 return TREE_INT_CST_LOW (t); | |
1937 } | |
1938 | |
1939 /* Return the maximum size of TYPE (in bytes) as a wide integer | |
1940 or return -1 if the size can vary or is larger than an integer. */ | |
1941 | |
1942 HOST_WIDE_INT | |
1943 max_int_size_in_bytes (const_tree type) | |
1944 { | |
1945 HOST_WIDE_INT size = -1; | |
1946 tree size_tree; | |
1947 | |
1948 /* If this is an array type, check for a possible MAX_SIZE attached. */ | |
1949 | |
1950 if (TREE_CODE (type) == ARRAY_TYPE) | |
1951 { | |
1952 size_tree = TYPE_ARRAY_MAX_SIZE (type); | |
1953 | |
1954 if (size_tree && host_integerp (size_tree, 1)) | |
1955 size = tree_low_cst (size_tree, 1); | |
1956 } | |
1957 | |
1958 /* If we still haven't been able to get a size, see if the language | |
1959 can compute a maximum size. */ | |
1960 | |
1961 if (size == -1) | |
1962 { | |
1963 size_tree = lang_hooks.types.max_size (type); | |
1964 | |
1965 if (size_tree && host_integerp (size_tree, 1)) | |
1966 size = tree_low_cst (size_tree, 1); | |
1967 } | |
1968 | |
1969 return size; | |
1970 } | |
1971 | |
1972 /* Return the bit position of FIELD, in bits from the start of the record. | |
1973 This is a tree of type bitsizetype. */ | |
1974 | |
1975 tree | |
1976 bit_position (const_tree field) | |
1977 { | |
1978 return bit_from_pos (DECL_FIELD_OFFSET (field), | |
1979 DECL_FIELD_BIT_OFFSET (field)); | |
1980 } | |
1981 | |
1982 /* Likewise, but return as an integer. It must be representable in | |
1983 that way (since it could be a signed value, we don't have the | |
1984 option of returning -1 like int_size_in_byte can. */ | |
1985 | |
1986 HOST_WIDE_INT | |
1987 int_bit_position (const_tree field) | |
1988 { | |
1989 return tree_low_cst (bit_position (field), 0); | |
1990 } | |
1991 | |
1992 /* Return the byte position of FIELD, in bytes from the start of the record. | |
1993 This is a tree of type sizetype. */ | |
1994 | |
1995 tree | |
1996 byte_position (const_tree field) | |
1997 { | |
1998 return byte_from_pos (DECL_FIELD_OFFSET (field), | |
1999 DECL_FIELD_BIT_OFFSET (field)); | |
2000 } | |
2001 | |
2002 /* Likewise, but return as an integer. It must be representable in | |
2003 that way (since it could be a signed value, we don't have the | |
2004 option of returning -1 like int_size_in_byte can. */ | |
2005 | |
2006 HOST_WIDE_INT | |
2007 int_byte_position (const_tree field) | |
2008 { | |
2009 return tree_low_cst (byte_position (field), 0); | |
2010 } | |
2011 | |
2012 /* Return the strictest alignment, in bits, that T is known to have. */ | |
2013 | |
2014 unsigned int | |
2015 expr_align (const_tree t) | |
2016 { | |
2017 unsigned int align0, align1; | |
2018 | |
2019 switch (TREE_CODE (t)) | |
2020 { | |
2021 CASE_CONVERT: case NON_LVALUE_EXPR: | |
2022 /* If we have conversions, we know that the alignment of the | |
2023 object must meet each of the alignments of the types. */ | |
2024 align0 = expr_align (TREE_OPERAND (t, 0)); | |
2025 align1 = TYPE_ALIGN (TREE_TYPE (t)); | |
2026 return MAX (align0, align1); | |
2027 | |
2028 case SAVE_EXPR: case COMPOUND_EXPR: case MODIFY_EXPR: | |
2029 case INIT_EXPR: case TARGET_EXPR: case WITH_CLEANUP_EXPR: | |
2030 case CLEANUP_POINT_EXPR: | |
2031 /* These don't change the alignment of an object. */ | |
2032 return expr_align (TREE_OPERAND (t, 0)); | |
2033 | |
2034 case COND_EXPR: | |
2035 /* The best we can do is say that the alignment is the least aligned | |
2036 of the two arms. */ | |
2037 align0 = expr_align (TREE_OPERAND (t, 1)); | |
2038 align1 = expr_align (TREE_OPERAND (t, 2)); | |
2039 return MIN (align0, align1); | |
2040 | |
2041 /* FIXME: LABEL_DECL and CONST_DECL never have DECL_ALIGN set | |
2042 meaningfully, it's always 1. */ | |
2043 case LABEL_DECL: case CONST_DECL: | |
2044 case VAR_DECL: case PARM_DECL: case RESULT_DECL: | |
2045 case FUNCTION_DECL: | |
2046 gcc_assert (DECL_ALIGN (t) != 0); | |
2047 return DECL_ALIGN (t); | |
2048 | |
2049 default: | |
2050 break; | |
2051 } | |
2052 | |
2053 /* Otherwise take the alignment from that of the type. */ | |
2054 return TYPE_ALIGN (TREE_TYPE (t)); | |
2055 } | |
2056 | |
2057 /* Return, as a tree node, the number of elements for TYPE (which is an | |
2058 ARRAY_TYPE) minus one. This counts only elements of the top array. */ | |
2059 | |
2060 tree | |
2061 array_type_nelts (const_tree type) | |
2062 { | |
2063 tree index_type, min, max; | |
2064 | |
2065 /* If they did it with unspecified bounds, then we should have already | |
2066 given an error about it before we got here. */ | |
2067 if (! TYPE_DOMAIN (type)) | |
2068 return error_mark_node; | |
2069 | |
2070 index_type = TYPE_DOMAIN (type); | |
2071 min = TYPE_MIN_VALUE (index_type); | |
2072 max = TYPE_MAX_VALUE (index_type); | |
2073 | |
2074 return (integer_zerop (min) | |
2075 ? max | |
2076 : fold_build2 (MINUS_EXPR, TREE_TYPE (max), max, min)); | |
2077 } | |
2078 | |
2079 /* If arg is static -- a reference to an object in static storage -- then | |
2080 return the object. This is not the same as the C meaning of `static'. | |
2081 If arg isn't static, return NULL. */ | |
2082 | |
2083 tree | |
2084 staticp (tree arg) | |
2085 { | |
2086 switch (TREE_CODE (arg)) | |
2087 { | |
2088 case FUNCTION_DECL: | |
2089 /* Nested functions are static, even though taking their address will | |
2090 involve a trampoline as we unnest the nested function and create | |
2091 the trampoline on the tree level. */ | |
2092 return arg; | |
2093 | |
2094 case VAR_DECL: | |
2095 return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg)) | |
2096 && ! DECL_THREAD_LOCAL_P (arg) | |
2097 && ! DECL_DLLIMPORT_P (arg) | |
2098 ? arg : NULL); | |
2099 | |
2100 case CONST_DECL: | |
2101 return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg)) | |
2102 ? arg : NULL); | |
2103 | |
2104 case CONSTRUCTOR: | |
2105 return TREE_STATIC (arg) ? arg : NULL; | |
2106 | |
2107 case LABEL_DECL: | |
2108 case STRING_CST: | |
2109 return arg; | |
2110 | |
2111 case COMPONENT_REF: | |
2112 /* If the thing being referenced is not a field, then it is | |
2113 something language specific. */ | |
2114 if (TREE_CODE (TREE_OPERAND (arg, 1)) != FIELD_DECL) | |
2115 return (*lang_hooks.staticp) (arg); | |
2116 | |
2117 /* If we are referencing a bitfield, we can't evaluate an | |
2118 ADDR_EXPR at compile time and so it isn't a constant. */ | |
2119 if (DECL_BIT_FIELD (TREE_OPERAND (arg, 1))) | |
2120 return NULL; | |
2121 | |
2122 return staticp (TREE_OPERAND (arg, 0)); | |
2123 | |
2124 case BIT_FIELD_REF: | |
2125 return NULL; | |
2126 | |
2127 case MISALIGNED_INDIRECT_REF: | |
2128 case ALIGN_INDIRECT_REF: | |
2129 case INDIRECT_REF: | |
2130 return TREE_CONSTANT (TREE_OPERAND (arg, 0)) ? arg : NULL; | |
2131 | |
2132 case ARRAY_REF: | |
2133 case ARRAY_RANGE_REF: | |
2134 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST | |
2135 && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST) | |
2136 return staticp (TREE_OPERAND (arg, 0)); | |
2137 else | |
2138 return false; | |
2139 | |
2140 default: | |
2141 if ((unsigned int) TREE_CODE (arg) | |
2142 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE) | |
2143 return lang_hooks.staticp (arg); | |
2144 else | |
2145 return NULL; | |
2146 } | |
2147 } | |
2148 | |
2149 | |
2150 | |
2151 | |
2152 /* Return whether OP is a DECL whose address is function-invariant. */ | |
2153 | |
2154 bool | |
2155 decl_address_invariant_p (const_tree op) | |
2156 { | |
2157 /* The conditions below are slightly less strict than the one in | |
2158 staticp. */ | |
2159 | |
2160 switch (TREE_CODE (op)) | |
2161 { | |
2162 case PARM_DECL: | |
2163 case RESULT_DECL: | |
2164 case LABEL_DECL: | |
2165 case FUNCTION_DECL: | |
2166 return true; | |
2167 | |
2168 case VAR_DECL: | |
2169 if (((TREE_STATIC (op) || DECL_EXTERNAL (op)) | |
2170 && !DECL_DLLIMPORT_P (op)) | |
2171 || DECL_THREAD_LOCAL_P (op) | |
2172 || DECL_CONTEXT (op) == current_function_decl | |
2173 || decl_function_context (op) == current_function_decl) | |
2174 return true; | |
2175 break; | |
2176 | |
2177 case CONST_DECL: | |
2178 if ((TREE_STATIC (op) || DECL_EXTERNAL (op)) | |
2179 || decl_function_context (op) == current_function_decl) | |
2180 return true; | |
2181 break; | |
2182 | |
2183 default: | |
2184 break; | |
2185 } | |
2186 | |
2187 return false; | |
2188 } | |
2189 | |
2190 /* Return whether OP is a DECL whose address is interprocedural-invariant. */ | |
2191 | |
2192 bool | |
2193 decl_address_ip_invariant_p (const_tree op) | |
2194 { | |
2195 /* The conditions below are slightly less strict than the one in | |
2196 staticp. */ | |
2197 | |
2198 switch (TREE_CODE (op)) | |
2199 { | |
2200 case LABEL_DECL: | |
2201 case FUNCTION_DECL: | |
2202 case STRING_CST: | |
2203 return true; | |
2204 | |
2205 case VAR_DECL: | |
2206 if (((TREE_STATIC (op) || DECL_EXTERNAL (op)) | |
2207 && !DECL_DLLIMPORT_P (op)) | |
2208 || DECL_THREAD_LOCAL_P (op)) | |
2209 return true; | |
2210 break; | |
2211 | |
2212 case CONST_DECL: | |
2213 if ((TREE_STATIC (op) || DECL_EXTERNAL (op))) | |
2214 return true; | |
2215 break; | |
2216 | |
2217 default: | |
2218 break; | |
2219 } | |
2220 | |
2221 return false; | |
2222 } | |
2223 | |
2224 | |
2225 /* Return true if T is function-invariant (internal function, does | |
2226 not handle arithmetic; that's handled in skip_simple_arithmetic and | |
2227 tree_invariant_p). */ | |
2228 | |
2229 static bool tree_invariant_p (tree t); | |
2230 | |
2231 static bool | |
2232 tree_invariant_p_1 (tree t) | |
2233 { | |
2234 tree op; | |
2235 | |
2236 if (TREE_CONSTANT (t) | |
2237 || (TREE_READONLY (t) && !TREE_SIDE_EFFECTS (t))) | |
2238 return true; | |
2239 | |
2240 switch (TREE_CODE (t)) | |
2241 { | |
2242 case SAVE_EXPR: | |
2243 return true; | |
2244 | |
2245 case ADDR_EXPR: | |
2246 op = TREE_OPERAND (t, 0); | |
2247 while (handled_component_p (op)) | |
2248 { | |
2249 switch (TREE_CODE (op)) | |
2250 { | |
2251 case ARRAY_REF: | |
2252 case ARRAY_RANGE_REF: | |
2253 if (!tree_invariant_p (TREE_OPERAND (op, 1)) | |
2254 || TREE_OPERAND (op, 2) != NULL_TREE | |
2255 || TREE_OPERAND (op, 3) != NULL_TREE) | |
2256 return false; | |
2257 break; | |
2258 | |
2259 case COMPONENT_REF: | |
2260 if (TREE_OPERAND (op, 2) != NULL_TREE) | |
2261 return false; | |
2262 break; | |
2263 | |
2264 default:; | |
2265 } | |
2266 op = TREE_OPERAND (op, 0); | |
2267 } | |
2268 | |
2269 return CONSTANT_CLASS_P (op) || decl_address_invariant_p (op); | |
2270 | |
2271 default: | |
2272 break; | |
2273 } | |
2274 | |
2275 return false; | |
2276 } | |
2277 | |
2278 /* Return true if T is function-invariant. */ | |
2279 | |
2280 static bool | |
2281 tree_invariant_p (tree t) | |
2282 { | |
2283 tree inner = skip_simple_arithmetic (t); | |
2284 return tree_invariant_p_1 (inner); | |
2285 } | |
2286 | |
2287 /* Wrap a SAVE_EXPR around EXPR, if appropriate. | |
2288 Do this to any expression which may be used in more than one place, | |
2289 but must be evaluated only once. | |
2290 | |
2291 Normally, expand_expr would reevaluate the expression each time. | |
2292 Calling save_expr produces something that is evaluated and recorded | |
2293 the first time expand_expr is called on it. Subsequent calls to | |
2294 expand_expr just reuse the recorded value. | |
2295 | |
2296 The call to expand_expr that generates code that actually computes | |
2297 the value is the first call *at compile time*. Subsequent calls | |
2298 *at compile time* generate code to use the saved value. | |
2299 This produces correct result provided that *at run time* control | |
2300 always flows through the insns made by the first expand_expr | |
2301 before reaching the other places where the save_expr was evaluated. | |
2302 You, the caller of save_expr, must make sure this is so. | |
2303 | |
2304 Constants, and certain read-only nodes, are returned with no | |
2305 SAVE_EXPR because that is safe. Expressions containing placeholders | |
2306 are not touched; see tree.def for an explanation of what these | |
2307 are used for. */ | |
2308 | |
2309 tree | |
2310 save_expr (tree expr) | |
2311 { | |
2312 tree t = fold (expr); | |
2313 tree inner; | |
2314 | |
2315 /* If the tree evaluates to a constant, then we don't want to hide that | |
2316 fact (i.e. this allows further folding, and direct checks for constants). | |
2317 However, a read-only object that has side effects cannot be bypassed. | |
2318 Since it is no problem to reevaluate literals, we just return the | |
2319 literal node. */ | |
2320 inner = skip_simple_arithmetic (t); | |
2321 if (TREE_CODE (inner) == ERROR_MARK) | |
2322 return inner; | |
2323 | |
2324 if (tree_invariant_p_1 (inner)) | |
2325 return t; | |
2326 | |
2327 /* If INNER contains a PLACEHOLDER_EXPR, we must evaluate it each time, since | |
2328 it means that the size or offset of some field of an object depends on | |
2329 the value within another field. | |
2330 | |
2331 Note that it must not be the case that T contains both a PLACEHOLDER_EXPR | |
2332 and some variable since it would then need to be both evaluated once and | |
2333 evaluated more than once. Front-ends must assure this case cannot | |
2334 happen by surrounding any such subexpressions in their own SAVE_EXPR | |
2335 and forcing evaluation at the proper time. */ | |
2336 if (contains_placeholder_p (inner)) | |
2337 return t; | |
2338 | |
2339 t = build1 (SAVE_EXPR, TREE_TYPE (expr), t); | |
2340 | |
2341 /* This expression might be placed ahead of a jump to ensure that the | |
2342 value was computed on both sides of the jump. So make sure it isn't | |
2343 eliminated as dead. */ | |
2344 TREE_SIDE_EFFECTS (t) = 1; | |
2345 return t; | |
2346 } | |
2347 | |
2348 /* Look inside EXPR and into any simple arithmetic operations. Return | |
2349 the innermost non-arithmetic node. */ | |
2350 | |
2351 tree | |
2352 skip_simple_arithmetic (tree expr) | |
2353 { | |
2354 tree inner; | |
2355 | |
2356 /* We don't care about whether this can be used as an lvalue in this | |
2357 context. */ | |
2358 while (TREE_CODE (expr) == NON_LVALUE_EXPR) | |
2359 expr = TREE_OPERAND (expr, 0); | |
2360 | |
2361 /* If we have simple operations applied to a SAVE_EXPR or to a SAVE_EXPR and | |
2362 a constant, it will be more efficient to not make another SAVE_EXPR since | |
2363 it will allow better simplification and GCSE will be able to merge the | |
2364 computations if they actually occur. */ | |
2365 inner = expr; | |
2366 while (1) | |
2367 { | |
2368 if (UNARY_CLASS_P (inner)) | |
2369 inner = TREE_OPERAND (inner, 0); | |
2370 else if (BINARY_CLASS_P (inner)) | |
2371 { | |
2372 if (tree_invariant_p (TREE_OPERAND (inner, 1))) | |
2373 inner = TREE_OPERAND (inner, 0); | |
2374 else if (tree_invariant_p (TREE_OPERAND (inner, 0))) | |
2375 inner = TREE_OPERAND (inner, 1); | |
2376 else | |
2377 break; | |
2378 } | |
2379 else | |
2380 break; | |
2381 } | |
2382 | |
2383 return inner; | |
2384 } | |
2385 | |
2386 /* Return which tree structure is used by T. */ | |
2387 | |
2388 enum tree_node_structure_enum | |
2389 tree_node_structure (const_tree t) | |
2390 { | |
2391 const enum tree_code code = TREE_CODE (t); | |
2392 | |
2393 switch (TREE_CODE_CLASS (code)) | |
2394 { | |
2395 case tcc_declaration: | 281 case tcc_declaration: |
2396 { | 282 { |
2397 switch (code) | 283 switch (code) |
2398 { | 284 { |
2399 case FIELD_DECL: | 285 case FIELD_DECL: |
2404 return TS_VAR_DECL; | 290 return TS_VAR_DECL; |
2405 case LABEL_DECL: | 291 case LABEL_DECL: |
2406 return TS_LABEL_DECL; | 292 return TS_LABEL_DECL; |
2407 case RESULT_DECL: | 293 case RESULT_DECL: |
2408 return TS_RESULT_DECL; | 294 return TS_RESULT_DECL; |
295 case DEBUG_EXPR_DECL: | |
296 return TS_DECL_WRTL; | |
2409 case CONST_DECL: | 297 case CONST_DECL: |
2410 return TS_CONST_DECL; | 298 return TS_CONST_DECL; |
2411 case TYPE_DECL: | 299 case TYPE_DECL: |
2412 return TS_TYPE_DECL; | 300 return TS_TYPE_DECL; |
2413 case FUNCTION_DECL: | 301 case FUNCTION_DECL: |
2414 return TS_FUNCTION_DECL; | 302 return TS_FUNCTION_DECL; |
2415 case SYMBOL_MEMORY_TAG: | |
2416 case NAME_MEMORY_TAG: | |
2417 case MEMORY_PARTITION_TAG: | |
2418 return TS_MEMORY_TAG; | |
2419 default: | 303 default: |
2420 return TS_DECL_NON_COMMON; | 304 return TS_DECL_NON_COMMON; |
2421 } | 305 } |
2422 } | 306 } |
2423 case tcc_type: | 307 case tcc_type: |
2459 | 343 |
2460 default: | 344 default: |
2461 gcc_unreachable (); | 345 gcc_unreachable (); |
2462 } | 346 } |
2463 } | 347 } |
348 | |
349 | |
350 /* Initialize tree_contains_struct to describe the hierarchy of tree | |
351 nodes. */ | |
352 | |
353 static void | |
354 initialize_tree_contains_struct (void) | |
355 { | |
356 unsigned i; | |
357 | |
358 #define MARK_TS_BASE(C) \ | |
359 do { \ | |
360 tree_contains_struct[C][TS_BASE] = 1; \ | |
361 } while (0) | |
362 | |
363 #define MARK_TS_COMMON(C) \ | |
364 do { \ | |
365 MARK_TS_BASE (C); \ | |
366 tree_contains_struct[C][TS_COMMON] = 1; \ | |
367 } while (0) | |
368 | |
369 #define MARK_TS_DECL_MINIMAL(C) \ | |
370 do { \ | |
371 MARK_TS_COMMON (C); \ | |
372 tree_contains_struct[C][TS_DECL_MINIMAL] = 1; \ | |
373 } while (0) | |
374 | |
375 #define MARK_TS_DECL_COMMON(C) \ | |
376 do { \ | |
377 MARK_TS_DECL_MINIMAL (C); \ | |
378 tree_contains_struct[C][TS_DECL_COMMON] = 1; \ | |
379 } while (0) | |
380 | |
381 #define MARK_TS_DECL_WRTL(C) \ | |
382 do { \ | |
383 MARK_TS_DECL_COMMON (C); \ | |
384 tree_contains_struct[C][TS_DECL_WRTL] = 1; \ | |
385 } while (0) | |
386 | |
387 #define MARK_TS_DECL_WITH_VIS(C) \ | |
388 do { \ | |
389 MARK_TS_DECL_WRTL (C); \ | |
390 tree_contains_struct[C][TS_DECL_WITH_VIS] = 1; \ | |
391 } while (0) | |
392 | |
393 #define MARK_TS_DECL_NON_COMMON(C) \ | |
394 do { \ | |
395 MARK_TS_DECL_WITH_VIS (C); \ | |
396 tree_contains_struct[C][TS_DECL_NON_COMMON] = 1; \ | |
397 } while (0) | |
398 | |
399 for (i = ERROR_MARK; i < LAST_AND_UNUSED_TREE_CODE; i++) | |
400 { | |
401 enum tree_code code; | |
402 enum tree_node_structure_enum ts_code; | |
403 | |
404 code = (enum tree_code) i; | |
405 ts_code = tree_node_structure_for_code (code); | |
406 | |
407 /* Mark the TS structure itself. */ | |
408 tree_contains_struct[code][ts_code] = 1; | |
409 | |
410 /* Mark all the structures that TS is derived from. */ | |
411 switch (ts_code) | |
412 { | |
413 case TS_COMMON: | |
414 MARK_TS_BASE (code); | |
415 break; | |
416 | |
417 case TS_INT_CST: | |
418 case TS_REAL_CST: | |
419 case TS_FIXED_CST: | |
420 case TS_VECTOR: | |
421 case TS_STRING: | |
422 case TS_COMPLEX: | |
423 case TS_IDENTIFIER: | |
424 case TS_DECL_MINIMAL: | |
425 case TS_TYPE: | |
426 case TS_LIST: | |
427 case TS_VEC: | |
428 case TS_EXP: | |
429 case TS_SSA_NAME: | |
430 case TS_BLOCK: | |
431 case TS_BINFO: | |
432 case TS_STATEMENT_LIST: | |
433 case TS_CONSTRUCTOR: | |
434 case TS_OMP_CLAUSE: | |
435 case TS_OPTIMIZATION: | |
436 case TS_TARGET_OPTION: | |
437 MARK_TS_COMMON (code); | |
438 break; | |
439 | |
440 case TS_DECL_COMMON: | |
441 MARK_TS_DECL_MINIMAL (code); | |
442 break; | |
443 | |
444 case TS_DECL_WRTL: | |
445 MARK_TS_DECL_COMMON (code); | |
446 break; | |
447 | |
448 case TS_DECL_NON_COMMON: | |
449 MARK_TS_DECL_WITH_VIS (code); | |
450 break; | |
451 | |
452 case TS_DECL_WITH_VIS: | |
453 case TS_PARM_DECL: | |
454 case TS_LABEL_DECL: | |
455 case TS_RESULT_DECL: | |
456 case TS_CONST_DECL: | |
457 MARK_TS_DECL_WRTL (code); | |
458 break; | |
459 | |
460 case TS_FIELD_DECL: | |
461 MARK_TS_DECL_COMMON (code); | |
462 break; | |
463 | |
464 case TS_VAR_DECL: | |
465 MARK_TS_DECL_WITH_VIS (code); | |
466 break; | |
467 | |
468 case TS_TYPE_DECL: | |
469 case TS_FUNCTION_DECL: | |
470 MARK_TS_DECL_NON_COMMON (code); | |
471 break; | |
472 | |
473 default: | |
474 gcc_unreachable (); | |
475 } | |
476 } | |
477 | |
478 /* Basic consistency checks for attributes used in fold. */ | |
479 gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_NON_COMMON]); | |
480 gcc_assert (tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_NON_COMMON]); | |
481 gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_NON_COMMON]); | |
482 gcc_assert (tree_contains_struct[CONST_DECL][TS_DECL_COMMON]); | |
483 gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_COMMON]); | |
484 gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_COMMON]); | |
485 gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_COMMON]); | |
486 gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_COMMON]); | |
487 gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_COMMON]); | |
488 gcc_assert (tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_COMMON]); | |
489 gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_COMMON]); | |
490 gcc_assert (tree_contains_struct[FIELD_DECL][TS_DECL_COMMON]); | |
491 gcc_assert (tree_contains_struct[CONST_DECL][TS_DECL_WRTL]); | |
492 gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_WRTL]); | |
493 gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_WRTL]); | |
494 gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_WRTL]); | |
495 gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_WRTL]); | |
496 gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_WRTL]); | |
497 gcc_assert (tree_contains_struct[CONST_DECL][TS_DECL_MINIMAL]); | |
498 gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_MINIMAL]); | |
499 gcc_assert (tree_contains_struct[PARM_DECL][TS_DECL_MINIMAL]); | |
500 gcc_assert (tree_contains_struct[RESULT_DECL][TS_DECL_MINIMAL]); | |
501 gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_MINIMAL]); | |
502 gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_MINIMAL]); | |
503 gcc_assert (tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_MINIMAL]); | |
504 gcc_assert (tree_contains_struct[LABEL_DECL][TS_DECL_MINIMAL]); | |
505 gcc_assert (tree_contains_struct[FIELD_DECL][TS_DECL_MINIMAL]); | |
506 gcc_assert (tree_contains_struct[VAR_DECL][TS_DECL_WITH_VIS]); | |
507 gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_DECL_WITH_VIS]); | |
508 gcc_assert (tree_contains_struct[TYPE_DECL][TS_DECL_WITH_VIS]); | |
509 gcc_assert (tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_WITH_VIS]); | |
510 gcc_assert (tree_contains_struct[VAR_DECL][TS_VAR_DECL]); | |
511 gcc_assert (tree_contains_struct[FIELD_DECL][TS_FIELD_DECL]); | |
512 gcc_assert (tree_contains_struct[PARM_DECL][TS_PARM_DECL]); | |
513 gcc_assert (tree_contains_struct[LABEL_DECL][TS_LABEL_DECL]); | |
514 gcc_assert (tree_contains_struct[RESULT_DECL][TS_RESULT_DECL]); | |
515 gcc_assert (tree_contains_struct[CONST_DECL][TS_CONST_DECL]); | |
516 gcc_assert (tree_contains_struct[TYPE_DECL][TS_TYPE_DECL]); | |
517 gcc_assert (tree_contains_struct[FUNCTION_DECL][TS_FUNCTION_DECL]); | |
518 gcc_assert (tree_contains_struct[IMPORTED_DECL][TS_DECL_MINIMAL]); | |
519 gcc_assert (tree_contains_struct[IMPORTED_DECL][TS_DECL_COMMON]); | |
520 | |
521 #undef MARK_TS_BASE | |
522 #undef MARK_TS_COMMON | |
523 #undef MARK_TS_DECL_MINIMAL | |
524 #undef MARK_TS_DECL_COMMON | |
525 #undef MARK_TS_DECL_WRTL | |
526 #undef MARK_TS_DECL_WITH_VIS | |
527 #undef MARK_TS_DECL_NON_COMMON | |
528 } | |
529 | |
530 | |
531 /* Init tree.c. */ | |
532 | |
533 void | |
534 init_ttree (void) | |
535 { | |
536 /* Initialize the hash table of types. */ | |
537 type_hash_table = htab_create_ggc (TYPE_HASH_INITIAL_SIZE, type_hash_hash, | |
538 type_hash_eq, 0); | |
539 | |
540 debug_expr_for_decl = htab_create_ggc (512, tree_map_hash, | |
541 tree_map_eq, 0); | |
542 | |
543 value_expr_for_decl = htab_create_ggc (512, tree_map_hash, | |
544 tree_map_eq, 0); | |
545 init_priority_for_decl = htab_create_ggc (512, tree_priority_map_hash, | |
546 tree_priority_map_eq, 0); | |
547 | |
548 int_cst_hash_table = htab_create_ggc (1024, int_cst_hash_hash, | |
549 int_cst_hash_eq, NULL); | |
550 | |
551 int_cst_node = make_node (INTEGER_CST); | |
552 | |
553 cl_option_hash_table = htab_create_ggc (64, cl_option_hash_hash, | |
554 cl_option_hash_eq, NULL); | |
555 | |
556 cl_optimization_node = make_node (OPTIMIZATION_NODE); | |
557 cl_target_option_node = make_node (TARGET_OPTION_NODE); | |
558 | |
559 /* Initialize the tree_contains_struct array. */ | |
560 initialize_tree_contains_struct (); | |
561 lang_hooks.init_ts (); | |
562 } | |
563 | |
564 | |
565 /* The name of the object as the assembler will see it (but before any | |
566 translations made by ASM_OUTPUT_LABELREF). Often this is the same | |
567 as DECL_NAME. It is an IDENTIFIER_NODE. */ | |
568 tree | |
569 decl_assembler_name (tree decl) | |
570 { | |
571 if (!DECL_ASSEMBLER_NAME_SET_P (decl)) | |
572 lang_hooks.set_decl_assembler_name (decl); | |
573 return DECL_WITH_VIS_CHECK (decl)->decl_with_vis.assembler_name; | |
574 } | |
575 | |
576 /* Compare ASMNAME with the DECL_ASSEMBLER_NAME of DECL. */ | |
577 | |
578 bool | |
579 decl_assembler_name_equal (tree decl, const_tree asmname) | |
580 { | |
581 tree decl_asmname = DECL_ASSEMBLER_NAME (decl); | |
582 const char *decl_str; | |
583 const char *asmname_str; | |
584 bool test = false; | |
585 | |
586 if (decl_asmname == asmname) | |
587 return true; | |
588 | |
589 decl_str = IDENTIFIER_POINTER (decl_asmname); | |
590 asmname_str = IDENTIFIER_POINTER (asmname); | |
591 | |
592 | |
593 /* If the target assembler name was set by the user, things are trickier. | |
594 We have a leading '*' to begin with. After that, it's arguable what | |
595 is the correct thing to do with -fleading-underscore. Arguably, we've | |
596 historically been doing the wrong thing in assemble_alias by always | |
597 printing the leading underscore. Since we're not changing that, make | |
598 sure user_label_prefix follows the '*' before matching. */ | |
599 if (decl_str[0] == '*') | |
600 { | |
601 size_t ulp_len = strlen (user_label_prefix); | |
602 | |
603 decl_str ++; | |
604 | |
605 if (ulp_len == 0) | |
606 test = true; | |
607 else if (strncmp (decl_str, user_label_prefix, ulp_len) == 0) | |
608 decl_str += ulp_len, test=true; | |
609 else | |
610 decl_str --; | |
611 } | |
612 if (asmname_str[0] == '*') | |
613 { | |
614 size_t ulp_len = strlen (user_label_prefix); | |
615 | |
616 asmname_str ++; | |
617 | |
618 if (ulp_len == 0) | |
619 test = true; | |
620 else if (strncmp (asmname_str, user_label_prefix, ulp_len) == 0) | |
621 asmname_str += ulp_len, test=true; | |
622 else | |
623 asmname_str --; | |
624 } | |
625 | |
626 if (!test) | |
627 return false; | |
628 return strcmp (decl_str, asmname_str) == 0; | |
629 } | |
630 | |
631 /* Hash asmnames ignoring the user specified marks. */ | |
632 | |
633 hashval_t | |
634 decl_assembler_name_hash (const_tree asmname) | |
635 { | |
636 if (IDENTIFIER_POINTER (asmname)[0] == '*') | |
637 { | |
638 const char *decl_str = IDENTIFIER_POINTER (asmname) + 1; | |
639 size_t ulp_len = strlen (user_label_prefix); | |
640 | |
641 if (ulp_len == 0) | |
642 ; | |
643 else if (strncmp (decl_str, user_label_prefix, ulp_len) == 0) | |
644 decl_str += ulp_len; | |
645 | |
646 return htab_hash_string (decl_str); | |
647 } | |
648 | |
649 return htab_hash_string (IDENTIFIER_POINTER (asmname)); | |
650 } | |
651 | |
652 /* Compute the number of bytes occupied by a tree with code CODE. | |
653 This function cannot be used for nodes that have variable sizes, | |
654 including TREE_VEC, STRING_CST, and CALL_EXPR. */ | |
655 size_t | |
656 tree_code_size (enum tree_code code) | |
657 { | |
658 switch (TREE_CODE_CLASS (code)) | |
659 { | |
660 case tcc_declaration: /* A decl node */ | |
661 { | |
662 switch (code) | |
663 { | |
664 case FIELD_DECL: | |
665 return sizeof (struct tree_field_decl); | |
666 case PARM_DECL: | |
667 return sizeof (struct tree_parm_decl); | |
668 case VAR_DECL: | |
669 return sizeof (struct tree_var_decl); | |
670 case LABEL_DECL: | |
671 return sizeof (struct tree_label_decl); | |
672 case RESULT_DECL: | |
673 return sizeof (struct tree_result_decl); | |
674 case CONST_DECL: | |
675 return sizeof (struct tree_const_decl); | |
676 case TYPE_DECL: | |
677 return sizeof (struct tree_type_decl); | |
678 case FUNCTION_DECL: | |
679 return sizeof (struct tree_function_decl); | |
680 case DEBUG_EXPR_DECL: | |
681 return sizeof (struct tree_decl_with_rtl); | |
682 default: | |
683 return sizeof (struct tree_decl_non_common); | |
684 } | |
685 } | |
686 | |
687 case tcc_type: /* a type node */ | |
688 return sizeof (struct tree_type); | |
689 | |
690 case tcc_reference: /* a reference */ | |
691 case tcc_expression: /* an expression */ | |
692 case tcc_statement: /* an expression with side effects */ | |
693 case tcc_comparison: /* a comparison expression */ | |
694 case tcc_unary: /* a unary arithmetic expression */ | |
695 case tcc_binary: /* a binary arithmetic expression */ | |
696 return (sizeof (struct tree_exp) | |
697 + (TREE_CODE_LENGTH (code) - 1) * sizeof (tree)); | |
698 | |
699 case tcc_constant: /* a constant */ | |
700 switch (code) | |
701 { | |
702 case INTEGER_CST: return sizeof (struct tree_int_cst); | |
703 case REAL_CST: return sizeof (struct tree_real_cst); | |
704 case FIXED_CST: return sizeof (struct tree_fixed_cst); | |
705 case COMPLEX_CST: return sizeof (struct tree_complex); | |
706 case VECTOR_CST: return sizeof (struct tree_vector); | |
707 case STRING_CST: gcc_unreachable (); | |
708 default: | |
709 return lang_hooks.tree_size (code); | |
710 } | |
711 | |
712 case tcc_exceptional: /* something random, like an identifier. */ | |
713 switch (code) | |
714 { | |
715 case IDENTIFIER_NODE: return lang_hooks.identifier_size; | |
716 case TREE_LIST: return sizeof (struct tree_list); | |
717 | |
718 case ERROR_MARK: | |
719 case PLACEHOLDER_EXPR: return sizeof (struct tree_common); | |
720 | |
721 case TREE_VEC: | |
722 case OMP_CLAUSE: gcc_unreachable (); | |
723 | |
724 case SSA_NAME: return sizeof (struct tree_ssa_name); | |
725 | |
726 case STATEMENT_LIST: return sizeof (struct tree_statement_list); | |
727 case BLOCK: return sizeof (struct tree_block); | |
728 case CONSTRUCTOR: return sizeof (struct tree_constructor); | |
729 case OPTIMIZATION_NODE: return sizeof (struct tree_optimization_option); | |
730 case TARGET_OPTION_NODE: return sizeof (struct tree_target_option); | |
731 | |
732 default: | |
733 return lang_hooks.tree_size (code); | |
734 } | |
735 | |
736 default: | |
737 gcc_unreachable (); | |
738 } | |
739 } | |
740 | |
741 /* Compute the number of bytes occupied by NODE. This routine only | |
742 looks at TREE_CODE, except for those nodes that have variable sizes. */ | |
743 size_t | |
744 tree_size (const_tree node) | |
745 { | |
746 const enum tree_code code = TREE_CODE (node); | |
747 switch (code) | |
748 { | |
749 case TREE_BINFO: | |
750 return (offsetof (struct tree_binfo, base_binfos) | |
751 + VEC_embedded_size (tree, BINFO_N_BASE_BINFOS (node))); | |
752 | |
753 case TREE_VEC: | |
754 return (sizeof (struct tree_vec) | |
755 + (TREE_VEC_LENGTH (node) - 1) * sizeof (tree)); | |
756 | |
757 case STRING_CST: | |
758 return TREE_STRING_LENGTH (node) + offsetof (struct tree_string, str) + 1; | |
759 | |
760 case OMP_CLAUSE: | |
761 return (sizeof (struct tree_omp_clause) | |
762 + (omp_clause_num_ops[OMP_CLAUSE_CODE (node)] - 1) | |
763 * sizeof (tree)); | |
764 | |
765 default: | |
766 if (TREE_CODE_CLASS (code) == tcc_vl_exp) | |
767 return (sizeof (struct tree_exp) | |
768 + (VL_EXP_OPERAND_LENGTH (node) - 1) * sizeof (tree)); | |
769 else | |
770 return tree_code_size (code); | |
771 } | |
772 } | |
773 | |
774 /* Return a newly allocated node of code CODE. For decl and type | |
775 nodes, some other fields are initialized. The rest of the node is | |
776 initialized to zero. This function cannot be used for TREE_VEC or | |
777 OMP_CLAUSE nodes, which is enforced by asserts in tree_code_size. | |
778 | |
779 Achoo! I got a code in the node. */ | |
780 | |
781 tree | |
782 make_node_stat (enum tree_code code MEM_STAT_DECL) | |
783 { | |
784 tree t; | |
785 enum tree_code_class type = TREE_CODE_CLASS (code); | |
786 size_t length = tree_code_size (code); | |
787 #ifdef GATHER_STATISTICS | |
788 tree_node_kind kind; | |
789 | |
790 switch (type) | |
791 { | |
792 case tcc_declaration: /* A decl node */ | |
793 kind = d_kind; | |
794 break; | |
795 | |
796 case tcc_type: /* a type node */ | |
797 kind = t_kind; | |
798 break; | |
799 | |
800 case tcc_statement: /* an expression with side effects */ | |
801 kind = s_kind; | |
802 break; | |
803 | |
804 case tcc_reference: /* a reference */ | |
805 kind = r_kind; | |
806 break; | |
807 | |
808 case tcc_expression: /* an expression */ | |
809 case tcc_comparison: /* a comparison expression */ | |
810 case tcc_unary: /* a unary arithmetic expression */ | |
811 case tcc_binary: /* a binary arithmetic expression */ | |
812 kind = e_kind; | |
813 break; | |
814 | |
815 case tcc_constant: /* a constant */ | |
816 kind = c_kind; | |
817 break; | |
818 | |
819 case tcc_exceptional: /* something random, like an identifier. */ | |
820 switch (code) | |
821 { | |
822 case IDENTIFIER_NODE: | |
823 kind = id_kind; | |
824 break; | |
825 | |
826 case TREE_VEC: | |
827 kind = vec_kind; | |
828 break; | |
829 | |
830 case TREE_BINFO: | |
831 kind = binfo_kind; | |
832 break; | |
833 | |
834 case SSA_NAME: | |
835 kind = ssa_name_kind; | |
836 break; | |
837 | |
838 case BLOCK: | |
839 kind = b_kind; | |
840 break; | |
841 | |
842 case CONSTRUCTOR: | |
843 kind = constr_kind; | |
844 break; | |
845 | |
846 default: | |
847 kind = x_kind; | |
848 break; | |
849 } | |
850 break; | |
851 | |
852 default: | |
853 gcc_unreachable (); | |
854 } | |
855 | |
856 tree_node_counts[(int) kind]++; | |
857 tree_node_sizes[(int) kind] += length; | |
858 #endif | |
859 | |
860 if (code == IDENTIFIER_NODE) | |
861 t = (tree) ggc_alloc_zone_pass_stat (length, &tree_id_zone); | |
862 else | |
863 t = (tree) ggc_alloc_zone_pass_stat (length, &tree_zone); | |
864 | |
865 memset (t, 0, length); | |
866 | |
867 TREE_SET_CODE (t, code); | |
868 | |
869 switch (type) | |
870 { | |
871 case tcc_statement: | |
872 TREE_SIDE_EFFECTS (t) = 1; | |
873 break; | |
874 | |
875 case tcc_declaration: | |
876 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON)) | |
877 { | |
878 if (code == FUNCTION_DECL) | |
879 { | |
880 DECL_ALIGN (t) = FUNCTION_BOUNDARY; | |
881 DECL_MODE (t) = FUNCTION_MODE; | |
882 } | |
883 else | |
884 DECL_ALIGN (t) = 1; | |
885 } | |
886 DECL_SOURCE_LOCATION (t) = input_location; | |
887 if (TREE_CODE (t) == DEBUG_EXPR_DECL) | |
888 DECL_UID (t) = --next_debug_decl_uid; | |
889 else | |
890 DECL_UID (t) = next_decl_uid++; | |
891 if (TREE_CODE (t) == LABEL_DECL) | |
892 LABEL_DECL_UID (t) = -1; | |
893 | |
894 break; | |
895 | |
896 case tcc_type: | |
897 TYPE_UID (t) = next_type_uid++; | |
898 TYPE_ALIGN (t) = BITS_PER_UNIT; | |
899 TYPE_USER_ALIGN (t) = 0; | |
900 TYPE_MAIN_VARIANT (t) = t; | |
901 TYPE_CANONICAL (t) = t; | |
902 | |
903 /* Default to no attributes for type, but let target change that. */ | |
904 TYPE_ATTRIBUTES (t) = NULL_TREE; | |
905 targetm.set_default_type_attributes (t); | |
906 | |
907 /* We have not yet computed the alias set for this type. */ | |
908 TYPE_ALIAS_SET (t) = -1; | |
909 break; | |
910 | |
911 case tcc_constant: | |
912 TREE_CONSTANT (t) = 1; | |
913 break; | |
914 | |
915 case tcc_expression: | |
916 switch (code) | |
917 { | |
918 case INIT_EXPR: | |
919 case MODIFY_EXPR: | |
920 case VA_ARG_EXPR: | |
921 case PREDECREMENT_EXPR: | |
922 case PREINCREMENT_EXPR: | |
923 case POSTDECREMENT_EXPR: | |
924 case POSTINCREMENT_EXPR: | |
925 /* All of these have side-effects, no matter what their | |
926 operands are. */ | |
927 TREE_SIDE_EFFECTS (t) = 1; | |
928 break; | |
929 | |
930 default: | |
931 break; | |
932 } | |
933 break; | |
934 | |
935 default: | |
936 /* Other classes need no special treatment. */ | |
937 break; | |
938 } | |
939 | |
940 return t; | |
941 } | |
942 | |
943 /* Return a new node with the same contents as NODE except that its | |
944 TREE_CHAIN is zero and it has a fresh uid. */ | |
945 | |
946 tree | |
947 copy_node_stat (tree node MEM_STAT_DECL) | |
948 { | |
949 tree t; | |
950 enum tree_code code = TREE_CODE (node); | |
951 size_t length; | |
952 | |
953 gcc_assert (code != STATEMENT_LIST); | |
954 | |
955 length = tree_size (node); | |
956 t = (tree) ggc_alloc_zone_pass_stat (length, &tree_zone); | |
957 memcpy (t, node, length); | |
958 | |
959 TREE_CHAIN (t) = 0; | |
960 TREE_ASM_WRITTEN (t) = 0; | |
961 TREE_VISITED (t) = 0; | |
962 if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL) | |
963 *DECL_VAR_ANN_PTR (t) = 0; | |
964 | |
965 if (TREE_CODE_CLASS (code) == tcc_declaration) | |
966 { | |
967 if (code == DEBUG_EXPR_DECL) | |
968 DECL_UID (t) = --next_debug_decl_uid; | |
969 else | |
970 DECL_UID (t) = next_decl_uid++; | |
971 if ((TREE_CODE (node) == PARM_DECL || TREE_CODE (node) == VAR_DECL) | |
972 && DECL_HAS_VALUE_EXPR_P (node)) | |
973 { | |
974 SET_DECL_VALUE_EXPR (t, DECL_VALUE_EXPR (node)); | |
975 DECL_HAS_VALUE_EXPR_P (t) = 1; | |
976 } | |
977 if (TREE_CODE (node) == VAR_DECL && DECL_HAS_INIT_PRIORITY_P (node)) | |
978 { | |
979 SET_DECL_INIT_PRIORITY (t, DECL_INIT_PRIORITY (node)); | |
980 DECL_HAS_INIT_PRIORITY_P (t) = 1; | |
981 } | |
982 } | |
983 else if (TREE_CODE_CLASS (code) == tcc_type) | |
984 { | |
985 TYPE_UID (t) = next_type_uid++; | |
986 /* The following is so that the debug code for | |
987 the copy is different from the original type. | |
988 The two statements usually duplicate each other | |
989 (because they clear fields of the same union), | |
990 but the optimizer should catch that. */ | |
991 TYPE_SYMTAB_POINTER (t) = 0; | |
992 TYPE_SYMTAB_ADDRESS (t) = 0; | |
993 | |
994 /* Do not copy the values cache. */ | |
995 if (TYPE_CACHED_VALUES_P(t)) | |
996 { | |
997 TYPE_CACHED_VALUES_P (t) = 0; | |
998 TYPE_CACHED_VALUES (t) = NULL_TREE; | |
999 } | |
1000 } | |
1001 | |
1002 return t; | |
1003 } | |
1004 | |
1005 /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field. | |
1006 For example, this can copy a list made of TREE_LIST nodes. */ | |
1007 | |
1008 tree | |
1009 copy_list (tree list) | |
1010 { | |
1011 tree head; | |
1012 tree prev, next; | |
1013 | |
1014 if (list == 0) | |
1015 return 0; | |
1016 | |
1017 head = prev = copy_node (list); | |
1018 next = TREE_CHAIN (list); | |
1019 while (next) | |
1020 { | |
1021 TREE_CHAIN (prev) = copy_node (next); | |
1022 prev = TREE_CHAIN (prev); | |
1023 next = TREE_CHAIN (next); | |
1024 } | |
1025 return head; | |
1026 } | |
1027 | |
1028 | |
1029 /* Create an INT_CST node with a LOW value sign extended. */ | |
1030 | |
1031 tree | |
1032 build_int_cst (tree type, HOST_WIDE_INT low) | |
1033 { | |
1034 /* Support legacy code. */ | |
1035 if (!type) | |
1036 type = integer_type_node; | |
1037 | |
1038 return build_int_cst_wide (type, low, low < 0 ? -1 : 0); | |
1039 } | |
1040 | |
1041 /* Create an INT_CST node with a LOW value zero extended. */ | |
1042 | |
1043 tree | |
1044 build_int_cstu (tree type, unsigned HOST_WIDE_INT low) | |
1045 { | |
1046 return build_int_cst_wide (type, low, 0); | |
1047 } | |
1048 | |
1049 /* Create an INT_CST node with a LOW value in TYPE. The value is sign extended | |
1050 if it is negative. This function is similar to build_int_cst, but | |
1051 the extra bits outside of the type precision are cleared. Constants | |
1052 with these extra bits may confuse the fold so that it detects overflows | |
1053 even in cases when they do not occur, and in general should be avoided. | |
1054 We cannot however make this a default behavior of build_int_cst without | |
1055 more intrusive changes, since there are parts of gcc that rely on the extra | |
1056 precision of the integer constants. */ | |
1057 | |
1058 tree | |
1059 build_int_cst_type (tree type, HOST_WIDE_INT low) | |
1060 { | |
1061 unsigned HOST_WIDE_INT low1; | |
1062 HOST_WIDE_INT hi; | |
1063 | |
1064 gcc_assert (type); | |
1065 | |
1066 fit_double_type (low, low < 0 ? -1 : 0, &low1, &hi, type); | |
1067 | |
1068 return build_int_cst_wide (type, low1, hi); | |
1069 } | |
1070 | |
1071 /* Create an INT_CST node of TYPE and value HI:LOW. The value is truncated | |
1072 and sign extended according to the value range of TYPE. */ | |
1073 | |
1074 tree | |
1075 build_int_cst_wide_type (tree type, | |
1076 unsigned HOST_WIDE_INT low, HOST_WIDE_INT high) | |
1077 { | |
1078 fit_double_type (low, high, &low, &high, type); | |
1079 return build_int_cst_wide (type, low, high); | |
1080 } | |
1081 | |
1082 /* These are the hash table functions for the hash table of INTEGER_CST | |
1083 nodes of a sizetype. */ | |
1084 | |
1085 /* Return the hash code code X, an INTEGER_CST. */ | |
1086 | |
1087 static hashval_t | |
1088 int_cst_hash_hash (const void *x) | |
1089 { | |
1090 const_tree const t = (const_tree) x; | |
1091 | |
1092 return (TREE_INT_CST_HIGH (t) ^ TREE_INT_CST_LOW (t) | |
1093 ^ htab_hash_pointer (TREE_TYPE (t))); | |
1094 } | |
1095 | |
1096 /* Return nonzero if the value represented by *X (an INTEGER_CST tree node) | |
1097 is the same as that given by *Y, which is the same. */ | |
1098 | |
1099 static int | |
1100 int_cst_hash_eq (const void *x, const void *y) | |
1101 { | |
1102 const_tree const xt = (const_tree) x; | |
1103 const_tree const yt = (const_tree) y; | |
1104 | |
1105 return (TREE_TYPE (xt) == TREE_TYPE (yt) | |
1106 && TREE_INT_CST_HIGH (xt) == TREE_INT_CST_HIGH (yt) | |
1107 && TREE_INT_CST_LOW (xt) == TREE_INT_CST_LOW (yt)); | |
1108 } | |
1109 | |
1110 /* Create an INT_CST node of TYPE and value HI:LOW. | |
1111 The returned node is always shared. For small integers we use a | |
1112 per-type vector cache, for larger ones we use a single hash table. */ | |
1113 | |
1114 tree | |
1115 build_int_cst_wide (tree type, unsigned HOST_WIDE_INT low, HOST_WIDE_INT hi) | |
1116 { | |
1117 tree t; | |
1118 int ix = -1; | |
1119 int limit = 0; | |
1120 | |
1121 gcc_assert (type); | |
1122 | |
1123 switch (TREE_CODE (type)) | |
1124 { | |
1125 case POINTER_TYPE: | |
1126 case REFERENCE_TYPE: | |
1127 /* Cache NULL pointer. */ | |
1128 if (!hi && !low) | |
1129 { | |
1130 limit = 1; | |
1131 ix = 0; | |
1132 } | |
1133 break; | |
1134 | |
1135 case BOOLEAN_TYPE: | |
1136 /* Cache false or true. */ | |
1137 limit = 2; | |
1138 if (!hi && low < 2) | |
1139 ix = low; | |
1140 break; | |
1141 | |
1142 case INTEGER_TYPE: | |
1143 case OFFSET_TYPE: | |
1144 if (TYPE_UNSIGNED (type)) | |
1145 { | |
1146 /* Cache 0..N */ | |
1147 limit = INTEGER_SHARE_LIMIT; | |
1148 if (!hi && low < (unsigned HOST_WIDE_INT)INTEGER_SHARE_LIMIT) | |
1149 ix = low; | |
1150 } | |
1151 else | |
1152 { | |
1153 /* Cache -1..N */ | |
1154 limit = INTEGER_SHARE_LIMIT + 1; | |
1155 if (!hi && low < (unsigned HOST_WIDE_INT)INTEGER_SHARE_LIMIT) | |
1156 ix = low + 1; | |
1157 else if (hi == -1 && low == -(unsigned HOST_WIDE_INT)1) | |
1158 ix = 0; | |
1159 } | |
1160 break; | |
1161 | |
1162 case ENUMERAL_TYPE: | |
1163 break; | |
1164 | |
1165 default: | |
1166 gcc_unreachable (); | |
1167 } | |
1168 | |
1169 if (ix >= 0) | |
1170 { | |
1171 /* Look for it in the type's vector of small shared ints. */ | |
1172 if (!TYPE_CACHED_VALUES_P (type)) | |
1173 { | |
1174 TYPE_CACHED_VALUES_P (type) = 1; | |
1175 TYPE_CACHED_VALUES (type) = make_tree_vec (limit); | |
1176 } | |
1177 | |
1178 t = TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix); | |
1179 if (t) | |
1180 { | |
1181 /* Make sure no one is clobbering the shared constant. */ | |
1182 gcc_assert (TREE_TYPE (t) == type); | |
1183 gcc_assert (TREE_INT_CST_LOW (t) == low); | |
1184 gcc_assert (TREE_INT_CST_HIGH (t) == hi); | |
1185 } | |
1186 else | |
1187 { | |
1188 /* Create a new shared int. */ | |
1189 t = make_node (INTEGER_CST); | |
1190 | |
1191 TREE_INT_CST_LOW (t) = low; | |
1192 TREE_INT_CST_HIGH (t) = hi; | |
1193 TREE_TYPE (t) = type; | |
1194 | |
1195 TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix) = t; | |
1196 } | |
1197 } | |
1198 else | |
1199 { | |
1200 /* Use the cache of larger shared ints. */ | |
1201 void **slot; | |
1202 | |
1203 TREE_INT_CST_LOW (int_cst_node) = low; | |
1204 TREE_INT_CST_HIGH (int_cst_node) = hi; | |
1205 TREE_TYPE (int_cst_node) = type; | |
1206 | |
1207 slot = htab_find_slot (int_cst_hash_table, int_cst_node, INSERT); | |
1208 t = (tree) *slot; | |
1209 if (!t) | |
1210 { | |
1211 /* Insert this one into the hash table. */ | |
1212 t = int_cst_node; | |
1213 *slot = t; | |
1214 /* Make a new node for next time round. */ | |
1215 int_cst_node = make_node (INTEGER_CST); | |
1216 } | |
1217 } | |
1218 | |
1219 return t; | |
1220 } | |
1221 | |
1222 /* Builds an integer constant in TYPE such that lowest BITS bits are ones | |
1223 and the rest are zeros. */ | |
1224 | |
1225 tree | |
1226 build_low_bits_mask (tree type, unsigned bits) | |
1227 { | |
1228 unsigned HOST_WIDE_INT low; | |
1229 HOST_WIDE_INT high; | |
1230 unsigned HOST_WIDE_INT all_ones = ~(unsigned HOST_WIDE_INT) 0; | |
1231 | |
1232 gcc_assert (bits <= TYPE_PRECISION (type)); | |
1233 | |
1234 if (bits == TYPE_PRECISION (type) | |
1235 && !TYPE_UNSIGNED (type)) | |
1236 { | |
1237 /* Sign extended all-ones mask. */ | |
1238 low = all_ones; | |
1239 high = -1; | |
1240 } | |
1241 else if (bits <= HOST_BITS_PER_WIDE_INT) | |
1242 { | |
1243 low = all_ones >> (HOST_BITS_PER_WIDE_INT - bits); | |
1244 high = 0; | |
1245 } | |
1246 else | |
1247 { | |
1248 bits -= HOST_BITS_PER_WIDE_INT; | |
1249 low = all_ones; | |
1250 high = all_ones >> (HOST_BITS_PER_WIDE_INT - bits); | |
1251 } | |
1252 | |
1253 return build_int_cst_wide (type, low, high); | |
1254 } | |
1255 | |
1256 /* Checks that X is integer constant that can be expressed in (unsigned) | |
1257 HOST_WIDE_INT without loss of precision. */ | |
1258 | |
1259 bool | |
1260 cst_and_fits_in_hwi (const_tree x) | |
1261 { | |
1262 if (TREE_CODE (x) != INTEGER_CST) | |
1263 return false; | |
1264 | |
1265 if (TYPE_PRECISION (TREE_TYPE (x)) > HOST_BITS_PER_WIDE_INT) | |
1266 return false; | |
1267 | |
1268 return (TREE_INT_CST_HIGH (x) == 0 | |
1269 || TREE_INT_CST_HIGH (x) == -1); | |
1270 } | |
1271 | |
1272 /* Return a new VECTOR_CST node whose type is TYPE and whose values | |
1273 are in a list pointed to by VALS. */ | |
1274 | |
1275 tree | |
1276 build_vector (tree type, tree vals) | |
1277 { | |
1278 tree v = make_node (VECTOR_CST); | |
1279 int over = 0; | |
1280 tree link; | |
1281 | |
1282 TREE_VECTOR_CST_ELTS (v) = vals; | |
1283 TREE_TYPE (v) = type; | |
1284 | |
1285 /* Iterate through elements and check for overflow. */ | |
1286 for (link = vals; link; link = TREE_CHAIN (link)) | |
1287 { | |
1288 tree value = TREE_VALUE (link); | |
1289 | |
1290 /* Don't crash if we get an address constant. */ | |
1291 if (!CONSTANT_CLASS_P (value)) | |
1292 continue; | |
1293 | |
1294 over |= TREE_OVERFLOW (value); | |
1295 } | |
1296 | |
1297 TREE_OVERFLOW (v) = over; | |
1298 return v; | |
1299 } | |
1300 | |
1301 /* Return a new VECTOR_CST node whose type is TYPE and whose values | |
1302 are extracted from V, a vector of CONSTRUCTOR_ELT. */ | |
1303 | |
1304 tree | |
1305 build_vector_from_ctor (tree type, VEC(constructor_elt,gc) *v) | |
1306 { | |
1307 tree list = NULL_TREE; | |
1308 unsigned HOST_WIDE_INT idx; | |
1309 tree value; | |
1310 | |
1311 FOR_EACH_CONSTRUCTOR_VALUE (v, idx, value) | |
1312 list = tree_cons (NULL_TREE, value, list); | |
1313 return build_vector (type, nreverse (list)); | |
1314 } | |
1315 | |
1316 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values | |
1317 are in the VEC pointed to by VALS. */ | |
1318 tree | |
1319 build_constructor (tree type, VEC(constructor_elt,gc) *vals) | |
1320 { | |
1321 tree c = make_node (CONSTRUCTOR); | |
1322 TREE_TYPE (c) = type; | |
1323 CONSTRUCTOR_ELTS (c) = vals; | |
1324 return c; | |
1325 } | |
1326 | |
1327 /* Build a CONSTRUCTOR node made of a single initializer, with the specified | |
1328 INDEX and VALUE. */ | |
1329 tree | |
1330 build_constructor_single (tree type, tree index, tree value) | |
1331 { | |
1332 VEC(constructor_elt,gc) *v; | |
1333 constructor_elt *elt; | |
1334 tree t; | |
1335 | |
1336 v = VEC_alloc (constructor_elt, gc, 1); | |
1337 elt = VEC_quick_push (constructor_elt, v, NULL); | |
1338 elt->index = index; | |
1339 elt->value = value; | |
1340 | |
1341 t = build_constructor (type, v); | |
1342 TREE_CONSTANT (t) = TREE_CONSTANT (value); | |
1343 return t; | |
1344 } | |
1345 | |
1346 | |
1347 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values | |
1348 are in a list pointed to by VALS. */ | |
1349 tree | |
1350 build_constructor_from_list (tree type, tree vals) | |
1351 { | |
1352 tree t, val; | |
1353 VEC(constructor_elt,gc) *v = NULL; | |
1354 bool constant_p = true; | |
1355 | |
1356 if (vals) | |
1357 { | |
1358 v = VEC_alloc (constructor_elt, gc, list_length (vals)); | |
1359 for (t = vals; t; t = TREE_CHAIN (t)) | |
1360 { | |
1361 constructor_elt *elt = VEC_quick_push (constructor_elt, v, NULL); | |
1362 val = TREE_VALUE (t); | |
1363 elt->index = TREE_PURPOSE (t); | |
1364 elt->value = val; | |
1365 if (!TREE_CONSTANT (val)) | |
1366 constant_p = false; | |
1367 } | |
1368 } | |
1369 | |
1370 t = build_constructor (type, v); | |
1371 TREE_CONSTANT (t) = constant_p; | |
1372 return t; | |
1373 } | |
1374 | |
1375 /* Return a new FIXED_CST node whose type is TYPE and value is F. */ | |
1376 | |
1377 tree | |
1378 build_fixed (tree type, FIXED_VALUE_TYPE f) | |
1379 { | |
1380 tree v; | |
1381 FIXED_VALUE_TYPE *fp; | |
1382 | |
1383 v = make_node (FIXED_CST); | |
1384 fp = GGC_NEW (FIXED_VALUE_TYPE); | |
1385 memcpy (fp, &f, sizeof (FIXED_VALUE_TYPE)); | |
1386 | |
1387 TREE_TYPE (v) = type; | |
1388 TREE_FIXED_CST_PTR (v) = fp; | |
1389 return v; | |
1390 } | |
1391 | |
1392 /* Return a new REAL_CST node whose type is TYPE and value is D. */ | |
1393 | |
1394 tree | |
1395 build_real (tree type, REAL_VALUE_TYPE d) | |
1396 { | |
1397 tree v; | |
1398 REAL_VALUE_TYPE *dp; | |
1399 int overflow = 0; | |
1400 | |
1401 /* ??? Used to check for overflow here via CHECK_FLOAT_TYPE. | |
1402 Consider doing it via real_convert now. */ | |
1403 | |
1404 v = make_node (REAL_CST); | |
1405 dp = GGC_NEW (REAL_VALUE_TYPE); | |
1406 memcpy (dp, &d, sizeof (REAL_VALUE_TYPE)); | |
1407 | |
1408 TREE_TYPE (v) = type; | |
1409 TREE_REAL_CST_PTR (v) = dp; | |
1410 TREE_OVERFLOW (v) = overflow; | |
1411 return v; | |
1412 } | |
1413 | |
1414 /* Return a new REAL_CST node whose type is TYPE | |
1415 and whose value is the integer value of the INTEGER_CST node I. */ | |
1416 | |
1417 REAL_VALUE_TYPE | |
1418 real_value_from_int_cst (const_tree type, const_tree i) | |
1419 { | |
1420 REAL_VALUE_TYPE d; | |
1421 | |
1422 /* Clear all bits of the real value type so that we can later do | |
1423 bitwise comparisons to see if two values are the same. */ | |
1424 memset (&d, 0, sizeof d); | |
1425 | |
1426 real_from_integer (&d, type ? TYPE_MODE (type) : VOIDmode, | |
1427 TREE_INT_CST_LOW (i), TREE_INT_CST_HIGH (i), | |
1428 TYPE_UNSIGNED (TREE_TYPE (i))); | |
1429 return d; | |
1430 } | |
1431 | |
1432 /* Given a tree representing an integer constant I, return a tree | |
1433 representing the same value as a floating-point constant of type TYPE. */ | |
1434 | |
1435 tree | |
1436 build_real_from_int_cst (tree type, const_tree i) | |
1437 { | |
1438 tree v; | |
1439 int overflow = TREE_OVERFLOW (i); | |
1440 | |
1441 v = build_real (type, real_value_from_int_cst (type, i)); | |
1442 | |
1443 TREE_OVERFLOW (v) |= overflow; | |
1444 return v; | |
1445 } | |
1446 | |
1447 /* Return a newly constructed STRING_CST node whose value is | |
1448 the LEN characters at STR. | |
1449 The TREE_TYPE is not initialized. */ | |
1450 | |
1451 tree | |
1452 build_string (int len, const char *str) | |
1453 { | |
1454 tree s; | |
1455 size_t length; | |
1456 | |
1457 /* Do not waste bytes provided by padding of struct tree_string. */ | |
1458 length = len + offsetof (struct tree_string, str) + 1; | |
1459 | |
1460 #ifdef GATHER_STATISTICS | |
1461 tree_node_counts[(int) c_kind]++; | |
1462 tree_node_sizes[(int) c_kind] += length; | |
1463 #endif | |
1464 | |
1465 s = ggc_alloc_tree (length); | |
1466 | |
1467 memset (s, 0, sizeof (struct tree_common)); | |
1468 TREE_SET_CODE (s, STRING_CST); | |
1469 TREE_CONSTANT (s) = 1; | |
1470 TREE_STRING_LENGTH (s) = len; | |
1471 memcpy (s->string.str, str, len); | |
1472 s->string.str[len] = '\0'; | |
1473 | |
1474 return s; | |
1475 } | |
1476 | |
1477 /* Return a newly constructed COMPLEX_CST node whose value is | |
1478 specified by the real and imaginary parts REAL and IMAG. | |
1479 Both REAL and IMAG should be constant nodes. TYPE, if specified, | |
1480 will be the type of the COMPLEX_CST; otherwise a new type will be made. */ | |
1481 | |
1482 tree | |
1483 build_complex (tree type, tree real, tree imag) | |
1484 { | |
1485 tree t = make_node (COMPLEX_CST); | |
1486 | |
1487 TREE_REALPART (t) = real; | |
1488 TREE_IMAGPART (t) = imag; | |
1489 TREE_TYPE (t) = type ? type : build_complex_type (TREE_TYPE (real)); | |
1490 TREE_OVERFLOW (t) = TREE_OVERFLOW (real) | TREE_OVERFLOW (imag); | |
1491 return t; | |
1492 } | |
1493 | |
1494 /* Return a constant of arithmetic type TYPE which is the | |
1495 multiplicative identity of the set TYPE. */ | |
1496 | |
1497 tree | |
1498 build_one_cst (tree type) | |
1499 { | |
1500 switch (TREE_CODE (type)) | |
1501 { | |
1502 case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE: | |
1503 case POINTER_TYPE: case REFERENCE_TYPE: | |
1504 case OFFSET_TYPE: | |
1505 return build_int_cst (type, 1); | |
1506 | |
1507 case REAL_TYPE: | |
1508 return build_real (type, dconst1); | |
1509 | |
1510 case FIXED_POINT_TYPE: | |
1511 /* We can only generate 1 for accum types. */ | |
1512 gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type))); | |
1513 return build_fixed (type, FCONST1(TYPE_MODE (type))); | |
1514 | |
1515 case VECTOR_TYPE: | |
1516 { | |
1517 tree scalar, cst; | |
1518 int i; | |
1519 | |
1520 scalar = build_one_cst (TREE_TYPE (type)); | |
1521 | |
1522 /* Create 'vect_cst_ = {cst,cst,...,cst}' */ | |
1523 cst = NULL_TREE; | |
1524 for (i = TYPE_VECTOR_SUBPARTS (type); --i >= 0; ) | |
1525 cst = tree_cons (NULL_TREE, scalar, cst); | |
1526 | |
1527 return build_vector (type, cst); | |
1528 } | |
1529 | |
1530 case COMPLEX_TYPE: | |
1531 return build_complex (type, | |
1532 build_one_cst (TREE_TYPE (type)), | |
1533 fold_convert (TREE_TYPE (type), integer_zero_node)); | |
1534 | |
1535 default: | |
1536 gcc_unreachable (); | |
1537 } | |
1538 } | |
1539 | |
1540 /* Build a BINFO with LEN language slots. */ | |
1541 | |
1542 tree | |
1543 make_tree_binfo_stat (unsigned base_binfos MEM_STAT_DECL) | |
1544 { | |
1545 tree t; | |
1546 size_t length = (offsetof (struct tree_binfo, base_binfos) | |
1547 + VEC_embedded_size (tree, base_binfos)); | |
1548 | |
1549 #ifdef GATHER_STATISTICS | |
1550 tree_node_counts[(int) binfo_kind]++; | |
1551 tree_node_sizes[(int) binfo_kind] += length; | |
1552 #endif | |
1553 | |
1554 t = (tree) ggc_alloc_zone_pass_stat (length, &tree_zone); | |
1555 | |
1556 memset (t, 0, offsetof (struct tree_binfo, base_binfos)); | |
1557 | |
1558 TREE_SET_CODE (t, TREE_BINFO); | |
1559 | |
1560 VEC_embedded_init (tree, BINFO_BASE_BINFOS (t), base_binfos); | |
1561 | |
1562 return t; | |
1563 } | |
1564 | |
1565 | |
1566 /* Build a newly constructed TREE_VEC node of length LEN. */ | |
1567 | |
1568 tree | |
1569 make_tree_vec_stat (int len MEM_STAT_DECL) | |
1570 { | |
1571 tree t; | |
1572 int length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec); | |
1573 | |
1574 #ifdef GATHER_STATISTICS | |
1575 tree_node_counts[(int) vec_kind]++; | |
1576 tree_node_sizes[(int) vec_kind] += length; | |
1577 #endif | |
1578 | |
1579 t = (tree) ggc_alloc_zone_pass_stat (length, &tree_zone); | |
1580 | |
1581 memset (t, 0, length); | |
1582 | |
1583 TREE_SET_CODE (t, TREE_VEC); | |
1584 TREE_VEC_LENGTH (t) = len; | |
1585 | |
1586 return t; | |
1587 } | |
1588 | |
1589 /* Return 1 if EXPR is the integer constant zero or a complex constant | |
1590 of zero. */ | |
1591 | |
1592 int | |
1593 integer_zerop (const_tree expr) | |
1594 { | |
1595 STRIP_NOPS (expr); | |
1596 | |
1597 return ((TREE_CODE (expr) == INTEGER_CST | |
1598 && TREE_INT_CST_LOW (expr) == 0 | |
1599 && TREE_INT_CST_HIGH (expr) == 0) | |
1600 || (TREE_CODE (expr) == COMPLEX_CST | |
1601 && integer_zerop (TREE_REALPART (expr)) | |
1602 && integer_zerop (TREE_IMAGPART (expr)))); | |
1603 } | |
1604 | |
1605 /* Return 1 if EXPR is the integer constant one or the corresponding | |
1606 complex constant. */ | |
1607 | |
1608 int | |
1609 integer_onep (const_tree expr) | |
1610 { | |
1611 STRIP_NOPS (expr); | |
1612 | |
1613 return ((TREE_CODE (expr) == INTEGER_CST | |
1614 && TREE_INT_CST_LOW (expr) == 1 | |
1615 && TREE_INT_CST_HIGH (expr) == 0) | |
1616 || (TREE_CODE (expr) == COMPLEX_CST | |
1617 && integer_onep (TREE_REALPART (expr)) | |
1618 && integer_zerop (TREE_IMAGPART (expr)))); | |
1619 } | |
1620 | |
1621 /* Return 1 if EXPR is an integer containing all 1's in as much precision as | |
1622 it contains. Likewise for the corresponding complex constant. */ | |
1623 | |
1624 int | |
1625 integer_all_onesp (const_tree expr) | |
1626 { | |
1627 int prec; | |
1628 int uns; | |
1629 | |
1630 STRIP_NOPS (expr); | |
1631 | |
1632 if (TREE_CODE (expr) == COMPLEX_CST | |
1633 && integer_all_onesp (TREE_REALPART (expr)) | |
1634 && integer_zerop (TREE_IMAGPART (expr))) | |
1635 return 1; | |
1636 | |
1637 else if (TREE_CODE (expr) != INTEGER_CST) | |
1638 return 0; | |
1639 | |
1640 uns = TYPE_UNSIGNED (TREE_TYPE (expr)); | |
1641 if (TREE_INT_CST_LOW (expr) == ~(unsigned HOST_WIDE_INT) 0 | |
1642 && TREE_INT_CST_HIGH (expr) == -1) | |
1643 return 1; | |
1644 if (!uns) | |
1645 return 0; | |
1646 | |
1647 /* Note that using TYPE_PRECISION here is wrong. We care about the | |
1648 actual bits, not the (arbitrary) range of the type. */ | |
1649 prec = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (expr))); | |
1650 if (prec >= HOST_BITS_PER_WIDE_INT) | |
1651 { | |
1652 HOST_WIDE_INT high_value; | |
1653 int shift_amount; | |
1654 | |
1655 shift_amount = prec - HOST_BITS_PER_WIDE_INT; | |
1656 | |
1657 /* Can not handle precisions greater than twice the host int size. */ | |
1658 gcc_assert (shift_amount <= HOST_BITS_PER_WIDE_INT); | |
1659 if (shift_amount == HOST_BITS_PER_WIDE_INT) | |
1660 /* Shifting by the host word size is undefined according to the ANSI | |
1661 standard, so we must handle this as a special case. */ | |
1662 high_value = -1; | |
1663 else | |
1664 high_value = ((HOST_WIDE_INT) 1 << shift_amount) - 1; | |
1665 | |
1666 return (TREE_INT_CST_LOW (expr) == ~(unsigned HOST_WIDE_INT) 0 | |
1667 && TREE_INT_CST_HIGH (expr) == high_value); | |
1668 } | |
1669 else | |
1670 return TREE_INT_CST_LOW (expr) == ((unsigned HOST_WIDE_INT) 1 << prec) - 1; | |
1671 } | |
1672 | |
1673 /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only | |
1674 one bit on). */ | |
1675 | |
1676 int | |
1677 integer_pow2p (const_tree expr) | |
1678 { | |
1679 int prec; | |
1680 HOST_WIDE_INT high, low; | |
1681 | |
1682 STRIP_NOPS (expr); | |
1683 | |
1684 if (TREE_CODE (expr) == COMPLEX_CST | |
1685 && integer_pow2p (TREE_REALPART (expr)) | |
1686 && integer_zerop (TREE_IMAGPART (expr))) | |
1687 return 1; | |
1688 | |
1689 if (TREE_CODE (expr) != INTEGER_CST) | |
1690 return 0; | |
1691 | |
1692 prec = TYPE_PRECISION (TREE_TYPE (expr)); | |
1693 high = TREE_INT_CST_HIGH (expr); | |
1694 low = TREE_INT_CST_LOW (expr); | |
1695 | |
1696 /* First clear all bits that are beyond the type's precision in case | |
1697 we've been sign extended. */ | |
1698 | |
1699 if (prec == 2 * HOST_BITS_PER_WIDE_INT) | |
1700 ; | |
1701 else if (prec > HOST_BITS_PER_WIDE_INT) | |
1702 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT)); | |
1703 else | |
1704 { | |
1705 high = 0; | |
1706 if (prec < HOST_BITS_PER_WIDE_INT) | |
1707 low &= ~((HOST_WIDE_INT) (-1) << prec); | |
1708 } | |
1709 | |
1710 if (high == 0 && low == 0) | |
1711 return 0; | |
1712 | |
1713 return ((high == 0 && (low & (low - 1)) == 0) | |
1714 || (low == 0 && (high & (high - 1)) == 0)); | |
1715 } | |
1716 | |
1717 /* Return 1 if EXPR is an integer constant other than zero or a | |
1718 complex constant other than zero. */ | |
1719 | |
1720 int | |
1721 integer_nonzerop (const_tree expr) | |
1722 { | |
1723 STRIP_NOPS (expr); | |
1724 | |
1725 return ((TREE_CODE (expr) == INTEGER_CST | |
1726 && (TREE_INT_CST_LOW (expr) != 0 | |
1727 || TREE_INT_CST_HIGH (expr) != 0)) | |
1728 || (TREE_CODE (expr) == COMPLEX_CST | |
1729 && (integer_nonzerop (TREE_REALPART (expr)) | |
1730 || integer_nonzerop (TREE_IMAGPART (expr))))); | |
1731 } | |
1732 | |
1733 /* Return 1 if EXPR is the fixed-point constant zero. */ | |
1734 | |
1735 int | |
1736 fixed_zerop (const_tree expr) | |
1737 { | |
1738 return (TREE_CODE (expr) == FIXED_CST | |
1739 && double_int_zero_p (TREE_FIXED_CST (expr).data)); | |
1740 } | |
1741 | |
1742 /* Return the power of two represented by a tree node known to be a | |
1743 power of two. */ | |
1744 | |
1745 int | |
1746 tree_log2 (const_tree expr) | |
1747 { | |
1748 int prec; | |
1749 HOST_WIDE_INT high, low; | |
1750 | |
1751 STRIP_NOPS (expr); | |
1752 | |
1753 if (TREE_CODE (expr) == COMPLEX_CST) | |
1754 return tree_log2 (TREE_REALPART (expr)); | |
1755 | |
1756 prec = TYPE_PRECISION (TREE_TYPE (expr)); | |
1757 high = TREE_INT_CST_HIGH (expr); | |
1758 low = TREE_INT_CST_LOW (expr); | |
1759 | |
1760 /* First clear all bits that are beyond the type's precision in case | |
1761 we've been sign extended. */ | |
1762 | |
1763 if (prec == 2 * HOST_BITS_PER_WIDE_INT) | |
1764 ; | |
1765 else if (prec > HOST_BITS_PER_WIDE_INT) | |
1766 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT)); | |
1767 else | |
1768 { | |
1769 high = 0; | |
1770 if (prec < HOST_BITS_PER_WIDE_INT) | |
1771 low &= ~((HOST_WIDE_INT) (-1) << prec); | |
1772 } | |
1773 | |
1774 return (high != 0 ? HOST_BITS_PER_WIDE_INT + exact_log2 (high) | |
1775 : exact_log2 (low)); | |
1776 } | |
1777 | |
1778 /* Similar, but return the largest integer Y such that 2 ** Y is less | |
1779 than or equal to EXPR. */ | |
1780 | |
1781 int | |
1782 tree_floor_log2 (const_tree expr) | |
1783 { | |
1784 int prec; | |
1785 HOST_WIDE_INT high, low; | |
1786 | |
1787 STRIP_NOPS (expr); | |
1788 | |
1789 if (TREE_CODE (expr) == COMPLEX_CST) | |
1790 return tree_log2 (TREE_REALPART (expr)); | |
1791 | |
1792 prec = TYPE_PRECISION (TREE_TYPE (expr)); | |
1793 high = TREE_INT_CST_HIGH (expr); | |
1794 low = TREE_INT_CST_LOW (expr); | |
1795 | |
1796 /* First clear all bits that are beyond the type's precision in case | |
1797 we've been sign extended. Ignore if type's precision hasn't been set | |
1798 since what we are doing is setting it. */ | |
1799 | |
1800 if (prec == 2 * HOST_BITS_PER_WIDE_INT || prec == 0) | |
1801 ; | |
1802 else if (prec > HOST_BITS_PER_WIDE_INT) | |
1803 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT)); | |
1804 else | |
1805 { | |
1806 high = 0; | |
1807 if (prec < HOST_BITS_PER_WIDE_INT) | |
1808 low &= ~((HOST_WIDE_INT) (-1) << prec); | |
1809 } | |
1810 | |
1811 return (high != 0 ? HOST_BITS_PER_WIDE_INT + floor_log2 (high) | |
1812 : floor_log2 (low)); | |
1813 } | |
1814 | |
1815 /* Return 1 if EXPR is the real constant zero. Trailing zeroes matter for | |
1816 decimal float constants, so don't return 1 for them. */ | |
1817 | |
1818 int | |
1819 real_zerop (const_tree expr) | |
1820 { | |
1821 STRIP_NOPS (expr); | |
1822 | |
1823 return ((TREE_CODE (expr) == REAL_CST | |
1824 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst0) | |
1825 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))))) | |
1826 || (TREE_CODE (expr) == COMPLEX_CST | |
1827 && real_zerop (TREE_REALPART (expr)) | |
1828 && real_zerop (TREE_IMAGPART (expr)))); | |
1829 } | |
1830 | |
1831 /* Return 1 if EXPR is the real constant one in real or complex form. | |
1832 Trailing zeroes matter for decimal float constants, so don't return | |
1833 1 for them. */ | |
1834 | |
1835 int | |
1836 real_onep (const_tree expr) | |
1837 { | |
1838 STRIP_NOPS (expr); | |
1839 | |
1840 return ((TREE_CODE (expr) == REAL_CST | |
1841 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst1) | |
1842 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))))) | |
1843 || (TREE_CODE (expr) == COMPLEX_CST | |
1844 && real_onep (TREE_REALPART (expr)) | |
1845 && real_zerop (TREE_IMAGPART (expr)))); | |
1846 } | |
1847 | |
1848 /* Return 1 if EXPR is the real constant two. Trailing zeroes matter | |
1849 for decimal float constants, so don't return 1 for them. */ | |
1850 | |
1851 int | |
1852 real_twop (const_tree expr) | |
1853 { | |
1854 STRIP_NOPS (expr); | |
1855 | |
1856 return ((TREE_CODE (expr) == REAL_CST | |
1857 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst2) | |
1858 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))))) | |
1859 || (TREE_CODE (expr) == COMPLEX_CST | |
1860 && real_twop (TREE_REALPART (expr)) | |
1861 && real_zerop (TREE_IMAGPART (expr)))); | |
1862 } | |
1863 | |
1864 /* Return 1 if EXPR is the real constant minus one. Trailing zeroes | |
1865 matter for decimal float constants, so don't return 1 for them. */ | |
1866 | |
1867 int | |
1868 real_minus_onep (const_tree expr) | |
1869 { | |
1870 STRIP_NOPS (expr); | |
1871 | |
1872 return ((TREE_CODE (expr) == REAL_CST | |
1873 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconstm1) | |
1874 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))))) | |
1875 || (TREE_CODE (expr) == COMPLEX_CST | |
1876 && real_minus_onep (TREE_REALPART (expr)) | |
1877 && real_zerop (TREE_IMAGPART (expr)))); | |
1878 } | |
1879 | |
1880 /* Nonzero if EXP is a constant or a cast of a constant. */ | |
1881 | |
1882 int | |
1883 really_constant_p (const_tree exp) | |
1884 { | |
1885 /* This is not quite the same as STRIP_NOPS. It does more. */ | |
1886 while (CONVERT_EXPR_P (exp) | |
1887 || TREE_CODE (exp) == NON_LVALUE_EXPR) | |
1888 exp = TREE_OPERAND (exp, 0); | |
1889 return TREE_CONSTANT (exp); | |
1890 } | |
1891 | |
1892 /* Return first list element whose TREE_VALUE is ELEM. | |
1893 Return 0 if ELEM is not in LIST. */ | |
1894 | |
1895 tree | |
1896 value_member (tree elem, tree list) | |
1897 { | |
1898 while (list) | |
1899 { | |
1900 if (elem == TREE_VALUE (list)) | |
1901 return list; | |
1902 list = TREE_CHAIN (list); | |
1903 } | |
1904 return NULL_TREE; | |
1905 } | |
1906 | |
1907 /* Return first list element whose TREE_PURPOSE is ELEM. | |
1908 Return 0 if ELEM is not in LIST. */ | |
1909 | |
1910 tree | |
1911 purpose_member (const_tree elem, tree list) | |
1912 { | |
1913 while (list) | |
1914 { | |
1915 if (elem == TREE_PURPOSE (list)) | |
1916 return list; | |
1917 list = TREE_CHAIN (list); | |
1918 } | |
1919 return NULL_TREE; | |
1920 } | |
1921 | |
1922 /* Returns element number IDX (zero-origin) of chain CHAIN, or | |
1923 NULL_TREE. */ | |
1924 | |
1925 tree | |
1926 chain_index (int idx, tree chain) | |
1927 { | |
1928 for (; chain && idx > 0; --idx) | |
1929 chain = TREE_CHAIN (chain); | |
1930 return chain; | |
1931 } | |
1932 | |
1933 /* Return nonzero if ELEM is part of the chain CHAIN. */ | |
1934 | |
1935 int | |
1936 chain_member (const_tree elem, const_tree chain) | |
1937 { | |
1938 while (chain) | |
1939 { | |
1940 if (elem == chain) | |
1941 return 1; | |
1942 chain = TREE_CHAIN (chain); | |
1943 } | |
1944 | |
1945 return 0; | |
1946 } | |
1947 | |
1948 /* Return the length of a chain of nodes chained through TREE_CHAIN. | |
1949 We expect a null pointer to mark the end of the chain. | |
1950 This is the Lisp primitive `length'. */ | |
1951 | |
1952 int | |
1953 list_length (const_tree t) | |
1954 { | |
1955 const_tree p = t; | |
1956 #ifdef ENABLE_TREE_CHECKING | |
1957 const_tree q = t; | |
1958 #endif | |
1959 int len = 0; | |
1960 | |
1961 while (p) | |
1962 { | |
1963 p = TREE_CHAIN (p); | |
1964 #ifdef ENABLE_TREE_CHECKING | |
1965 if (len % 2) | |
1966 q = TREE_CHAIN (q); | |
1967 gcc_assert (p != q); | |
1968 #endif | |
1969 len++; | |
1970 } | |
1971 | |
1972 return len; | |
1973 } | |
1974 | |
1975 /* Returns the number of FIELD_DECLs in TYPE. */ | |
1976 | |
1977 int | |
1978 fields_length (const_tree type) | |
1979 { | |
1980 tree t = TYPE_FIELDS (type); | |
1981 int count = 0; | |
1982 | |
1983 for (; t; t = TREE_CHAIN (t)) | |
1984 if (TREE_CODE (t) == FIELD_DECL) | |
1985 ++count; | |
1986 | |
1987 return count; | |
1988 } | |
1989 | |
1990 /* Concatenate two chains of nodes (chained through TREE_CHAIN) | |
1991 by modifying the last node in chain 1 to point to chain 2. | |
1992 This is the Lisp primitive `nconc'. */ | |
1993 | |
1994 tree | |
1995 chainon (tree op1, tree op2) | |
1996 { | |
1997 tree t1; | |
1998 | |
1999 if (!op1) | |
2000 return op2; | |
2001 if (!op2) | |
2002 return op1; | |
2003 | |
2004 for (t1 = op1; TREE_CHAIN (t1); t1 = TREE_CHAIN (t1)) | |
2005 continue; | |
2006 TREE_CHAIN (t1) = op2; | |
2007 | |
2008 #ifdef ENABLE_TREE_CHECKING | |
2009 { | |
2010 tree t2; | |
2011 for (t2 = op2; t2; t2 = TREE_CHAIN (t2)) | |
2012 gcc_assert (t2 != t1); | |
2013 } | |
2014 #endif | |
2015 | |
2016 return op1; | |
2017 } | |
2018 | |
2019 /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */ | |
2020 | |
2021 tree | |
2022 tree_last (tree chain) | |
2023 { | |
2024 tree next; | |
2025 if (chain) | |
2026 while ((next = TREE_CHAIN (chain))) | |
2027 chain = next; | |
2028 return chain; | |
2029 } | |
2030 | |
2031 /* Reverse the order of elements in the chain T, | |
2032 and return the new head of the chain (old last element). */ | |
2033 | |
2034 tree | |
2035 nreverse (tree t) | |
2036 { | |
2037 tree prev = 0, decl, next; | |
2038 for (decl = t; decl; decl = next) | |
2039 { | |
2040 next = TREE_CHAIN (decl); | |
2041 TREE_CHAIN (decl) = prev; | |
2042 prev = decl; | |
2043 } | |
2044 return prev; | |
2045 } | |
2046 | |
2047 /* Return a newly created TREE_LIST node whose | |
2048 purpose and value fields are PARM and VALUE. */ | |
2049 | |
2050 tree | |
2051 build_tree_list_stat (tree parm, tree value MEM_STAT_DECL) | |
2052 { | |
2053 tree t = make_node_stat (TREE_LIST PASS_MEM_STAT); | |
2054 TREE_PURPOSE (t) = parm; | |
2055 TREE_VALUE (t) = value; | |
2056 return t; | |
2057 } | |
2058 | |
2059 /* Build a chain of TREE_LIST nodes from a vector. */ | |
2060 | |
2061 tree | |
2062 build_tree_list_vec_stat (const VEC(tree,gc) *vec MEM_STAT_DECL) | |
2063 { | |
2064 tree ret = NULL_TREE; | |
2065 tree *pp = &ret; | |
2066 unsigned int i; | |
2067 tree t; | |
2068 for (i = 0; VEC_iterate (tree, vec, i, t); ++i) | |
2069 { | |
2070 *pp = build_tree_list_stat (NULL, t PASS_MEM_STAT); | |
2071 pp = &TREE_CHAIN (*pp); | |
2072 } | |
2073 return ret; | |
2074 } | |
2075 | |
2076 /* Return a newly created TREE_LIST node whose | |
2077 purpose and value fields are PURPOSE and VALUE | |
2078 and whose TREE_CHAIN is CHAIN. */ | |
2079 | |
2080 tree | |
2081 tree_cons_stat (tree purpose, tree value, tree chain MEM_STAT_DECL) | |
2082 { | |
2083 tree node; | |
2084 | |
2085 node = (tree) ggc_alloc_zone_pass_stat (sizeof (struct tree_list), &tree_zone); | |
2086 | |
2087 memset (node, 0, sizeof (struct tree_common)); | |
2088 | |
2089 #ifdef GATHER_STATISTICS | |
2090 tree_node_counts[(int) x_kind]++; | |
2091 tree_node_sizes[(int) x_kind] += sizeof (struct tree_list); | |
2092 #endif | |
2093 | |
2094 TREE_SET_CODE (node, TREE_LIST); | |
2095 TREE_CHAIN (node) = chain; | |
2096 TREE_PURPOSE (node) = purpose; | |
2097 TREE_VALUE (node) = value; | |
2098 return node; | |
2099 } | |
2100 | |
2101 /* Return the elements of a CONSTRUCTOR as a TREE_LIST. */ | |
2102 | |
2103 tree | |
2104 ctor_to_list (tree ctor) | |
2105 { | |
2106 tree list = NULL_TREE; | |
2107 tree *p = &list; | |
2108 unsigned ix; | |
2109 tree purpose, val; | |
2110 | |
2111 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), ix, purpose, val) | |
2112 { | |
2113 *p = build_tree_list (purpose, val); | |
2114 p = &TREE_CHAIN (*p); | |
2115 } | |
2116 | |
2117 return list; | |
2118 } | |
2119 | |
2120 /* Return the values of the elements of a CONSTRUCTOR as a vector of | |
2121 trees. */ | |
2122 | |
2123 VEC(tree,gc) * | |
2124 ctor_to_vec (tree ctor) | |
2125 { | |
2126 VEC(tree, gc) *vec = VEC_alloc (tree, gc, CONSTRUCTOR_NELTS (ctor)); | |
2127 unsigned int ix; | |
2128 tree val; | |
2129 | |
2130 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor), ix, val) | |
2131 VEC_quick_push (tree, vec, val); | |
2132 | |
2133 return vec; | |
2134 } | |
2135 | |
2136 /* Return the size nominally occupied by an object of type TYPE | |
2137 when it resides in memory. The value is measured in units of bytes, | |
2138 and its data type is that normally used for type sizes | |
2139 (which is the first type created by make_signed_type or | |
2140 make_unsigned_type). */ | |
2141 | |
2142 tree | |
2143 size_in_bytes (const_tree type) | |
2144 { | |
2145 tree t; | |
2146 | |
2147 if (type == error_mark_node) | |
2148 return integer_zero_node; | |
2149 | |
2150 type = TYPE_MAIN_VARIANT (type); | |
2151 t = TYPE_SIZE_UNIT (type); | |
2152 | |
2153 if (t == 0) | |
2154 { | |
2155 lang_hooks.types.incomplete_type_error (NULL_TREE, type); | |
2156 return size_zero_node; | |
2157 } | |
2158 | |
2159 return t; | |
2160 } | |
2161 | |
2162 /* Return the size of TYPE (in bytes) as a wide integer | |
2163 or return -1 if the size can vary or is larger than an integer. */ | |
2164 | |
2165 HOST_WIDE_INT | |
2166 int_size_in_bytes (const_tree type) | |
2167 { | |
2168 tree t; | |
2169 | |
2170 if (type == error_mark_node) | |
2171 return 0; | |
2172 | |
2173 type = TYPE_MAIN_VARIANT (type); | |
2174 t = TYPE_SIZE_UNIT (type); | |
2175 if (t == 0 | |
2176 || TREE_CODE (t) != INTEGER_CST | |
2177 || TREE_INT_CST_HIGH (t) != 0 | |
2178 /* If the result would appear negative, it's too big to represent. */ | |
2179 || (HOST_WIDE_INT) TREE_INT_CST_LOW (t) < 0) | |
2180 return -1; | |
2181 | |
2182 return TREE_INT_CST_LOW (t); | |
2183 } | |
2184 | |
2185 /* Return the maximum size of TYPE (in bytes) as a wide integer | |
2186 or return -1 if the size can vary or is larger than an integer. */ | |
2187 | |
2188 HOST_WIDE_INT | |
2189 max_int_size_in_bytes (const_tree type) | |
2190 { | |
2191 HOST_WIDE_INT size = -1; | |
2192 tree size_tree; | |
2193 | |
2194 /* If this is an array type, check for a possible MAX_SIZE attached. */ | |
2195 | |
2196 if (TREE_CODE (type) == ARRAY_TYPE) | |
2197 { | |
2198 size_tree = TYPE_ARRAY_MAX_SIZE (type); | |
2199 | |
2200 if (size_tree && host_integerp (size_tree, 1)) | |
2201 size = tree_low_cst (size_tree, 1); | |
2202 } | |
2203 | |
2204 /* If we still haven't been able to get a size, see if the language | |
2205 can compute a maximum size. */ | |
2206 | |
2207 if (size == -1) | |
2208 { | |
2209 size_tree = lang_hooks.types.max_size (type); | |
2210 | |
2211 if (size_tree && host_integerp (size_tree, 1)) | |
2212 size = tree_low_cst (size_tree, 1); | |
2213 } | |
2214 | |
2215 return size; | |
2216 } | |
2217 | |
2218 /* Returns a tree for the size of EXP in bytes. */ | |
2219 | |
2220 tree | |
2221 tree_expr_size (const_tree exp) | |
2222 { | |
2223 if (DECL_P (exp) | |
2224 && DECL_SIZE_UNIT (exp) != 0) | |
2225 return DECL_SIZE_UNIT (exp); | |
2226 else | |
2227 return size_in_bytes (TREE_TYPE (exp)); | |
2228 } | |
2229 | |
2230 /* Return the bit position of FIELD, in bits from the start of the record. | |
2231 This is a tree of type bitsizetype. */ | |
2232 | |
2233 tree | |
2234 bit_position (const_tree field) | |
2235 { | |
2236 return bit_from_pos (DECL_FIELD_OFFSET (field), | |
2237 DECL_FIELD_BIT_OFFSET (field)); | |
2238 } | |
2239 | |
2240 /* Likewise, but return as an integer. It must be representable in | |
2241 that way (since it could be a signed value, we don't have the | |
2242 option of returning -1 like int_size_in_byte can. */ | |
2243 | |
2244 HOST_WIDE_INT | |
2245 int_bit_position (const_tree field) | |
2246 { | |
2247 return tree_low_cst (bit_position (field), 0); | |
2248 } | |
2249 | |
2250 /* Return the byte position of FIELD, in bytes from the start of the record. | |
2251 This is a tree of type sizetype. */ | |
2252 | |
2253 tree | |
2254 byte_position (const_tree field) | |
2255 { | |
2256 return byte_from_pos (DECL_FIELD_OFFSET (field), | |
2257 DECL_FIELD_BIT_OFFSET (field)); | |
2258 } | |
2259 | |
2260 /* Likewise, but return as an integer. It must be representable in | |
2261 that way (since it could be a signed value, we don't have the | |
2262 option of returning -1 like int_size_in_byte can. */ | |
2263 | |
2264 HOST_WIDE_INT | |
2265 int_byte_position (const_tree field) | |
2266 { | |
2267 return tree_low_cst (byte_position (field), 0); | |
2268 } | |
2269 | |
2270 /* Return the strictest alignment, in bits, that T is known to have. */ | |
2271 | |
2272 unsigned int | |
2273 expr_align (const_tree t) | |
2274 { | |
2275 unsigned int align0, align1; | |
2276 | |
2277 switch (TREE_CODE (t)) | |
2278 { | |
2279 CASE_CONVERT: case NON_LVALUE_EXPR: | |
2280 /* If we have conversions, we know that the alignment of the | |
2281 object must meet each of the alignments of the types. */ | |
2282 align0 = expr_align (TREE_OPERAND (t, 0)); | |
2283 align1 = TYPE_ALIGN (TREE_TYPE (t)); | |
2284 return MAX (align0, align1); | |
2285 | |
2286 case SAVE_EXPR: case COMPOUND_EXPR: case MODIFY_EXPR: | |
2287 case INIT_EXPR: case TARGET_EXPR: case WITH_CLEANUP_EXPR: | |
2288 case CLEANUP_POINT_EXPR: | |
2289 /* These don't change the alignment of an object. */ | |
2290 return expr_align (TREE_OPERAND (t, 0)); | |
2291 | |
2292 case COND_EXPR: | |
2293 /* The best we can do is say that the alignment is the least aligned | |
2294 of the two arms. */ | |
2295 align0 = expr_align (TREE_OPERAND (t, 1)); | |
2296 align1 = expr_align (TREE_OPERAND (t, 2)); | |
2297 return MIN (align0, align1); | |
2298 | |
2299 /* FIXME: LABEL_DECL and CONST_DECL never have DECL_ALIGN set | |
2300 meaningfully, it's always 1. */ | |
2301 case LABEL_DECL: case CONST_DECL: | |
2302 case VAR_DECL: case PARM_DECL: case RESULT_DECL: | |
2303 case FUNCTION_DECL: | |
2304 gcc_assert (DECL_ALIGN (t) != 0); | |
2305 return DECL_ALIGN (t); | |
2306 | |
2307 default: | |
2308 break; | |
2309 } | |
2310 | |
2311 /* Otherwise take the alignment from that of the type. */ | |
2312 return TYPE_ALIGN (TREE_TYPE (t)); | |
2313 } | |
2314 | |
2315 /* Return, as a tree node, the number of elements for TYPE (which is an | |
2316 ARRAY_TYPE) minus one. This counts only elements of the top array. */ | |
2317 | |
2318 tree | |
2319 array_type_nelts (const_tree type) | |
2320 { | |
2321 tree index_type, min, max; | |
2322 | |
2323 /* If they did it with unspecified bounds, then we should have already | |
2324 given an error about it before we got here. */ | |
2325 if (! TYPE_DOMAIN (type)) | |
2326 return error_mark_node; | |
2327 | |
2328 index_type = TYPE_DOMAIN (type); | |
2329 min = TYPE_MIN_VALUE (index_type); | |
2330 max = TYPE_MAX_VALUE (index_type); | |
2331 | |
2332 return (integer_zerop (min) | |
2333 ? max | |
2334 : fold_build2 (MINUS_EXPR, TREE_TYPE (max), max, min)); | |
2335 } | |
2336 | |
2337 /* If arg is static -- a reference to an object in static storage -- then | |
2338 return the object. This is not the same as the C meaning of `static'. | |
2339 If arg isn't static, return NULL. */ | |
2340 | |
2341 tree | |
2342 staticp (tree arg) | |
2343 { | |
2344 switch (TREE_CODE (arg)) | |
2345 { | |
2346 case FUNCTION_DECL: | |
2347 /* Nested functions are static, even though taking their address will | |
2348 involve a trampoline as we unnest the nested function and create | |
2349 the trampoline on the tree level. */ | |
2350 return arg; | |
2351 | |
2352 case VAR_DECL: | |
2353 return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg)) | |
2354 && ! DECL_THREAD_LOCAL_P (arg) | |
2355 && ! DECL_DLLIMPORT_P (arg) | |
2356 ? arg : NULL); | |
2357 | |
2358 case CONST_DECL: | |
2359 return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg)) | |
2360 ? arg : NULL); | |
2361 | |
2362 case CONSTRUCTOR: | |
2363 return TREE_STATIC (arg) ? arg : NULL; | |
2364 | |
2365 case LABEL_DECL: | |
2366 case STRING_CST: | |
2367 return arg; | |
2368 | |
2369 case COMPONENT_REF: | |
2370 /* If the thing being referenced is not a field, then it is | |
2371 something language specific. */ | |
2372 gcc_assert (TREE_CODE (TREE_OPERAND (arg, 1)) == FIELD_DECL); | |
2373 | |
2374 /* If we are referencing a bitfield, we can't evaluate an | |
2375 ADDR_EXPR at compile time and so it isn't a constant. */ | |
2376 if (DECL_BIT_FIELD (TREE_OPERAND (arg, 1))) | |
2377 return NULL; | |
2378 | |
2379 return staticp (TREE_OPERAND (arg, 0)); | |
2380 | |
2381 case BIT_FIELD_REF: | |
2382 return NULL; | |
2383 | |
2384 case MISALIGNED_INDIRECT_REF: | |
2385 case ALIGN_INDIRECT_REF: | |
2386 case INDIRECT_REF: | |
2387 return TREE_CONSTANT (TREE_OPERAND (arg, 0)) ? arg : NULL; | |
2388 | |
2389 case ARRAY_REF: | |
2390 case ARRAY_RANGE_REF: | |
2391 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST | |
2392 && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST) | |
2393 return staticp (TREE_OPERAND (arg, 0)); | |
2394 else | |
2395 return NULL; | |
2396 | |
2397 case COMPOUND_LITERAL_EXPR: | |
2398 return TREE_STATIC (COMPOUND_LITERAL_EXPR_DECL (arg)) ? arg : NULL; | |
2399 | |
2400 default: | |
2401 return NULL; | |
2402 } | |
2403 } | |
2404 | |
2405 | |
2406 | |
2407 | |
2408 /* Return whether OP is a DECL whose address is function-invariant. */ | |
2409 | |
2410 bool | |
2411 decl_address_invariant_p (const_tree op) | |
2412 { | |
2413 /* The conditions below are slightly less strict than the one in | |
2414 staticp. */ | |
2415 | |
2416 switch (TREE_CODE (op)) | |
2417 { | |
2418 case PARM_DECL: | |
2419 case RESULT_DECL: | |
2420 case LABEL_DECL: | |
2421 case FUNCTION_DECL: | |
2422 return true; | |
2423 | |
2424 case VAR_DECL: | |
2425 if (((TREE_STATIC (op) || DECL_EXTERNAL (op)) | |
2426 && !DECL_DLLIMPORT_P (op)) | |
2427 || DECL_THREAD_LOCAL_P (op) | |
2428 || DECL_CONTEXT (op) == current_function_decl | |
2429 || decl_function_context (op) == current_function_decl) | |
2430 return true; | |
2431 break; | |
2432 | |
2433 case CONST_DECL: | |
2434 if ((TREE_STATIC (op) || DECL_EXTERNAL (op)) | |
2435 || decl_function_context (op) == current_function_decl) | |
2436 return true; | |
2437 break; | |
2438 | |
2439 default: | |
2440 break; | |
2441 } | |
2442 | |
2443 return false; | |
2444 } | |
2445 | |
2446 /* Return whether OP is a DECL whose address is interprocedural-invariant. */ | |
2447 | |
2448 bool | |
2449 decl_address_ip_invariant_p (const_tree op) | |
2450 { | |
2451 /* The conditions below are slightly less strict than the one in | |
2452 staticp. */ | |
2453 | |
2454 switch (TREE_CODE (op)) | |
2455 { | |
2456 case LABEL_DECL: | |
2457 case FUNCTION_DECL: | |
2458 case STRING_CST: | |
2459 return true; | |
2460 | |
2461 case VAR_DECL: | |
2462 if (((TREE_STATIC (op) || DECL_EXTERNAL (op)) | |
2463 && !DECL_DLLIMPORT_P (op)) | |
2464 || DECL_THREAD_LOCAL_P (op)) | |
2465 return true; | |
2466 break; | |
2467 | |
2468 case CONST_DECL: | |
2469 if ((TREE_STATIC (op) || DECL_EXTERNAL (op))) | |
2470 return true; | |
2471 break; | |
2472 | |
2473 default: | |
2474 break; | |
2475 } | |
2476 | |
2477 return false; | |
2478 } | |
2479 | |
2480 | |
2481 /* Return true if T is function-invariant (internal function, does | |
2482 not handle arithmetic; that's handled in skip_simple_arithmetic and | |
2483 tree_invariant_p). */ | |
2484 | |
2485 static bool tree_invariant_p (tree t); | |
2486 | |
2487 static bool | |
2488 tree_invariant_p_1 (tree t) | |
2489 { | |
2490 tree op; | |
2491 | |
2492 if (TREE_CONSTANT (t) | |
2493 || (TREE_READONLY (t) && !TREE_SIDE_EFFECTS (t))) | |
2494 return true; | |
2495 | |
2496 switch (TREE_CODE (t)) | |
2497 { | |
2498 case SAVE_EXPR: | |
2499 return true; | |
2500 | |
2501 case ADDR_EXPR: | |
2502 op = TREE_OPERAND (t, 0); | |
2503 while (handled_component_p (op)) | |
2504 { | |
2505 switch (TREE_CODE (op)) | |
2506 { | |
2507 case ARRAY_REF: | |
2508 case ARRAY_RANGE_REF: | |
2509 if (!tree_invariant_p (TREE_OPERAND (op, 1)) | |
2510 || TREE_OPERAND (op, 2) != NULL_TREE | |
2511 || TREE_OPERAND (op, 3) != NULL_TREE) | |
2512 return false; | |
2513 break; | |
2514 | |
2515 case COMPONENT_REF: | |
2516 if (TREE_OPERAND (op, 2) != NULL_TREE) | |
2517 return false; | |
2518 break; | |
2519 | |
2520 default:; | |
2521 } | |
2522 op = TREE_OPERAND (op, 0); | |
2523 } | |
2524 | |
2525 return CONSTANT_CLASS_P (op) || decl_address_invariant_p (op); | |
2526 | |
2527 default: | |
2528 break; | |
2529 } | |
2530 | |
2531 return false; | |
2532 } | |
2533 | |
2534 /* Return true if T is function-invariant. */ | |
2535 | |
2536 static bool | |
2537 tree_invariant_p (tree t) | |
2538 { | |
2539 tree inner = skip_simple_arithmetic (t); | |
2540 return tree_invariant_p_1 (inner); | |
2541 } | |
2542 | |
2543 /* Wrap a SAVE_EXPR around EXPR, if appropriate. | |
2544 Do this to any expression which may be used in more than one place, | |
2545 but must be evaluated only once. | |
2546 | |
2547 Normally, expand_expr would reevaluate the expression each time. | |
2548 Calling save_expr produces something that is evaluated and recorded | |
2549 the first time expand_expr is called on it. Subsequent calls to | |
2550 expand_expr just reuse the recorded value. | |
2551 | |
2552 The call to expand_expr that generates code that actually computes | |
2553 the value is the first call *at compile time*. Subsequent calls | |
2554 *at compile time* generate code to use the saved value. | |
2555 This produces correct result provided that *at run time* control | |
2556 always flows through the insns made by the first expand_expr | |
2557 before reaching the other places where the save_expr was evaluated. | |
2558 You, the caller of save_expr, must make sure this is so. | |
2559 | |
2560 Constants, and certain read-only nodes, are returned with no | |
2561 SAVE_EXPR because that is safe. Expressions containing placeholders | |
2562 are not touched; see tree.def for an explanation of what these | |
2563 are used for. */ | |
2564 | |
2565 tree | |
2566 save_expr (tree expr) | |
2567 { | |
2568 tree t = fold (expr); | |
2569 tree inner; | |
2570 | |
2571 /* If the tree evaluates to a constant, then we don't want to hide that | |
2572 fact (i.e. this allows further folding, and direct checks for constants). | |
2573 However, a read-only object that has side effects cannot be bypassed. | |
2574 Since it is no problem to reevaluate literals, we just return the | |
2575 literal node. */ | |
2576 inner = skip_simple_arithmetic (t); | |
2577 if (TREE_CODE (inner) == ERROR_MARK) | |
2578 return inner; | |
2579 | |
2580 if (tree_invariant_p_1 (inner)) | |
2581 return t; | |
2582 | |
2583 /* If INNER contains a PLACEHOLDER_EXPR, we must evaluate it each time, since | |
2584 it means that the size or offset of some field of an object depends on | |
2585 the value within another field. | |
2586 | |
2587 Note that it must not be the case that T contains both a PLACEHOLDER_EXPR | |
2588 and some variable since it would then need to be both evaluated once and | |
2589 evaluated more than once. Front-ends must assure this case cannot | |
2590 happen by surrounding any such subexpressions in their own SAVE_EXPR | |
2591 and forcing evaluation at the proper time. */ | |
2592 if (contains_placeholder_p (inner)) | |
2593 return t; | |
2594 | |
2595 t = build1 (SAVE_EXPR, TREE_TYPE (expr), t); | |
2596 SET_EXPR_LOCATION (t, EXPR_LOCATION (expr)); | |
2597 | |
2598 /* This expression might be placed ahead of a jump to ensure that the | |
2599 value was computed on both sides of the jump. So make sure it isn't | |
2600 eliminated as dead. */ | |
2601 TREE_SIDE_EFFECTS (t) = 1; | |
2602 return t; | |
2603 } | |
2604 | |
2605 /* Look inside EXPR and into any simple arithmetic operations. Return | |
2606 the innermost non-arithmetic node. */ | |
2607 | |
2608 tree | |
2609 skip_simple_arithmetic (tree expr) | |
2610 { | |
2611 tree inner; | |
2612 | |
2613 /* We don't care about whether this can be used as an lvalue in this | |
2614 context. */ | |
2615 while (TREE_CODE (expr) == NON_LVALUE_EXPR) | |
2616 expr = TREE_OPERAND (expr, 0); | |
2617 | |
2618 /* If we have simple operations applied to a SAVE_EXPR or to a SAVE_EXPR and | |
2619 a constant, it will be more efficient to not make another SAVE_EXPR since | |
2620 it will allow better simplification and GCSE will be able to merge the | |
2621 computations if they actually occur. */ | |
2622 inner = expr; | |
2623 while (1) | |
2624 { | |
2625 if (UNARY_CLASS_P (inner)) | |
2626 inner = TREE_OPERAND (inner, 0); | |
2627 else if (BINARY_CLASS_P (inner)) | |
2628 { | |
2629 if (tree_invariant_p (TREE_OPERAND (inner, 1))) | |
2630 inner = TREE_OPERAND (inner, 0); | |
2631 else if (tree_invariant_p (TREE_OPERAND (inner, 0))) | |
2632 inner = TREE_OPERAND (inner, 1); | |
2633 else | |
2634 break; | |
2635 } | |
2636 else | |
2637 break; | |
2638 } | |
2639 | |
2640 return inner; | |
2641 } | |
2642 | |
2643 | |
2644 /* Return which tree structure is used by T. */ | |
2645 | |
2646 enum tree_node_structure_enum | |
2647 tree_node_structure (const_tree t) | |
2648 { | |
2649 const enum tree_code code = TREE_CODE (t); | |
2650 return tree_node_structure_for_code (code); | |
2651 } | |
2652 | |
2653 /* Set various status flags when building a CALL_EXPR object T. */ | |
2654 | |
2655 static void | |
2656 process_call_operands (tree t) | |
2657 { | |
2658 bool side_effects = TREE_SIDE_EFFECTS (t); | |
2659 bool read_only = false; | |
2660 int i = call_expr_flags (t); | |
2661 | |
2662 /* Calls have side-effects, except those to const or pure functions. */ | |
2663 if ((i & ECF_LOOPING_CONST_OR_PURE) || !(i & (ECF_CONST | ECF_PURE))) | |
2664 side_effects = true; | |
2665 /* Propagate TREE_READONLY of arguments for const functions. */ | |
2666 if (i & ECF_CONST) | |
2667 read_only = true; | |
2668 | |
2669 if (!side_effects || read_only) | |
2670 for (i = 1; i < TREE_OPERAND_LENGTH (t); i++) | |
2671 { | |
2672 tree op = TREE_OPERAND (t, i); | |
2673 if (op && TREE_SIDE_EFFECTS (op)) | |
2674 side_effects = true; | |
2675 if (op && !TREE_READONLY (op) && !CONSTANT_CLASS_P (op)) | |
2676 read_only = false; | |
2677 } | |
2678 | |
2679 TREE_SIDE_EFFECTS (t) = side_effects; | |
2680 TREE_READONLY (t) = read_only; | |
2681 } | |
2464 | 2682 |
2465 /* Return 1 if EXP contains a PLACEHOLDER_EXPR; i.e., if it represents a size | 2683 /* Return 1 if EXP contains a PLACEHOLDER_EXPR; i.e., if it represents a size |
2466 or offset that depends on a field within a record. */ | 2684 or offset that depends on a field within a record. */ |
2467 | 2685 |
2468 bool | 2686 bool |
2635 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = result + 1; | 2853 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = result + 1; |
2636 | 2854 |
2637 return result; | 2855 return result; |
2638 } | 2856 } |
2639 | 2857 |
2640 /* Given a tree EXP, a FIELD_DECL F, and a replacement value R, | 2858 /* Push tree EXP onto vector QUEUE if it is not already present. */ |
2641 return a tree with all occurrences of references to F in a | 2859 |
2642 PLACEHOLDER_EXPR replaced by R. Note that we assume here that EXP | 2860 static void |
2643 contains only arithmetic expressions or a CALL_EXPR with a | 2861 push_without_duplicates (tree exp, VEC (tree, heap) **queue) |
2644 PLACEHOLDER_EXPR occurring only in its arglist. */ | 2862 { |
2645 | 2863 unsigned int i; |
2646 tree | 2864 tree iter; |
2647 substitute_in_expr (tree exp, tree f, tree r) | 2865 |
2866 for (i = 0; VEC_iterate (tree, *queue, i, iter); i++) | |
2867 if (simple_cst_equal (iter, exp) == 1) | |
2868 break; | |
2869 | |
2870 if (!iter) | |
2871 VEC_safe_push (tree, heap, *queue, exp); | |
2872 } | |
2873 | |
2874 /* Given a tree EXP, find all occurences of references to fields | |
2875 in a PLACEHOLDER_EXPR and place them in vector REFS without | |
2876 duplicates. Also record VAR_DECLs and CONST_DECLs. Note that | |
2877 we assume here that EXP contains only arithmetic expressions | |
2878 or CALL_EXPRs with PLACEHOLDER_EXPRs occurring only in their | |
2879 argument list. */ | |
2880 | |
2881 void | |
2882 find_placeholder_in_expr (tree exp, VEC (tree, heap) **refs) | |
2648 { | 2883 { |
2649 enum tree_code code = TREE_CODE (exp); | 2884 enum tree_code code = TREE_CODE (exp); |
2650 tree op0, op1, op2, op3; | 2885 tree inner; |
2651 tree new_tree, inner; | 2886 int i; |
2652 | 2887 |
2653 /* We handle TREE_LIST and COMPONENT_REF separately. */ | 2888 /* We handle TREE_LIST and COMPONENT_REF separately. */ |
2654 if (code == TREE_LIST) | 2889 if (code == TREE_LIST) |
2655 { | 2890 { |
2656 op0 = SUBSTITUTE_IN_EXPR (TREE_CHAIN (exp), f, r); | 2891 FIND_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp), refs); |
2657 op1 = SUBSTITUTE_IN_EXPR (TREE_VALUE (exp), f, r); | 2892 FIND_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp), refs); |
2658 if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp)) | |
2659 return exp; | |
2660 | |
2661 return tree_cons (TREE_PURPOSE (exp), op1, op0); | |
2662 } | 2893 } |
2663 else if (code == COMPONENT_REF) | 2894 else if (code == COMPONENT_REF) |
2664 { | 2895 { |
2665 /* If this expression is getting a value from a PLACEHOLDER_EXPR | 2896 for (inner = TREE_OPERAND (exp, 0); |
2666 and it is the right field, replace it with R. */ | 2897 REFERENCE_CLASS_P (inner); |
2667 for (inner = TREE_OPERAND (exp, 0); | 2898 inner = TREE_OPERAND (inner, 0)) |
2668 REFERENCE_CLASS_P (inner); | 2899 ; |
2669 inner = TREE_OPERAND (inner, 0)) | 2900 |
2670 ; | 2901 if (TREE_CODE (inner) == PLACEHOLDER_EXPR) |
2671 if (TREE_CODE (inner) == PLACEHOLDER_EXPR | 2902 push_without_duplicates (exp, refs); |
2672 && TREE_OPERAND (exp, 1) == f) | 2903 else |
2673 return r; | 2904 FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), refs); |
2674 | |
2675 /* If this expression hasn't been completed let, leave it alone. */ | |
2676 if (TREE_CODE (inner) == PLACEHOLDER_EXPR && TREE_TYPE (inner) == 0) | |
2677 return exp; | |
2678 | |
2679 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r); | |
2680 if (op0 == TREE_OPERAND (exp, 0)) | |
2681 return exp; | |
2682 | |
2683 new_tree = fold_build3 (COMPONENT_REF, TREE_TYPE (exp), | |
2684 op0, TREE_OPERAND (exp, 1), NULL_TREE); | |
2685 } | 2905 } |
2686 else | 2906 else |
2687 switch (TREE_CODE_CLASS (code)) | 2907 switch (TREE_CODE_CLASS (code)) |
2688 { | 2908 { |
2689 case tcc_constant: | 2909 case tcc_constant: |
2910 break; | |
2911 | |
2690 case tcc_declaration: | 2912 case tcc_declaration: |
2691 return exp; | 2913 /* Variables allocated to static storage can stay. */ |
2914 if (!TREE_STATIC (exp)) | |
2915 push_without_duplicates (exp, refs); | |
2916 break; | |
2917 | |
2918 case tcc_expression: | |
2919 /* This is the pattern built in ada/make_aligning_type. */ | |
2920 if (code == ADDR_EXPR | |
2921 && TREE_CODE (TREE_OPERAND (exp, 0)) == PLACEHOLDER_EXPR) | |
2922 { | |
2923 push_without_duplicates (exp, refs); | |
2924 break; | |
2925 } | |
2926 | |
2927 /* Fall through... */ | |
2692 | 2928 |
2693 case tcc_exceptional: | 2929 case tcc_exceptional: |
2694 case tcc_unary: | 2930 case tcc_unary: |
2695 case tcc_binary: | 2931 case tcc_binary: |
2696 case tcc_comparison: | 2932 case tcc_comparison: |
2933 case tcc_reference: | |
2934 for (i = 0; i < TREE_CODE_LENGTH (code); i++) | |
2935 FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, i), refs); | |
2936 break; | |
2937 | |
2938 case tcc_vl_exp: | |
2939 for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++) | |
2940 FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, i), refs); | |
2941 break; | |
2942 | |
2943 default: | |
2944 gcc_unreachable (); | |
2945 } | |
2946 } | |
2947 | |
2948 /* Given a tree EXP, a FIELD_DECL F, and a replacement value R, | |
2949 return a tree with all occurrences of references to F in a | |
2950 PLACEHOLDER_EXPR replaced by R. Also handle VAR_DECLs and | |
2951 CONST_DECLs. Note that we assume here that EXP contains only | |
2952 arithmetic expressions or CALL_EXPRs with PLACEHOLDER_EXPRs | |
2953 occurring only in their argument list. */ | |
2954 | |
2955 tree | |
2956 substitute_in_expr (tree exp, tree f, tree r) | |
2957 { | |
2958 enum tree_code code = TREE_CODE (exp); | |
2959 tree op0, op1, op2, op3; | |
2960 tree new_tree; | |
2961 | |
2962 /* We handle TREE_LIST and COMPONENT_REF separately. */ | |
2963 if (code == TREE_LIST) | |
2964 { | |
2965 op0 = SUBSTITUTE_IN_EXPR (TREE_CHAIN (exp), f, r); | |
2966 op1 = SUBSTITUTE_IN_EXPR (TREE_VALUE (exp), f, r); | |
2967 if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp)) | |
2968 return exp; | |
2969 | |
2970 return tree_cons (TREE_PURPOSE (exp), op1, op0); | |
2971 } | |
2972 else if (code == COMPONENT_REF) | |
2973 { | |
2974 tree inner; | |
2975 | |
2976 /* If this expression is getting a value from a PLACEHOLDER_EXPR | |
2977 and it is the right field, replace it with R. */ | |
2978 for (inner = TREE_OPERAND (exp, 0); | |
2979 REFERENCE_CLASS_P (inner); | |
2980 inner = TREE_OPERAND (inner, 0)) | |
2981 ; | |
2982 | |
2983 /* The field. */ | |
2984 op1 = TREE_OPERAND (exp, 1); | |
2985 | |
2986 if (TREE_CODE (inner) == PLACEHOLDER_EXPR && op1 == f) | |
2987 return r; | |
2988 | |
2989 /* If this expression hasn't been completed let, leave it alone. */ | |
2990 if (TREE_CODE (inner) == PLACEHOLDER_EXPR && !TREE_TYPE (inner)) | |
2991 return exp; | |
2992 | |
2993 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r); | |
2994 if (op0 == TREE_OPERAND (exp, 0)) | |
2995 return exp; | |
2996 | |
2997 new_tree | |
2998 = fold_build3 (COMPONENT_REF, TREE_TYPE (exp), op0, op1, NULL_TREE); | |
2999 } | |
3000 else | |
3001 switch (TREE_CODE_CLASS (code)) | |
3002 { | |
3003 case tcc_constant: | |
3004 return exp; | |
3005 | |
3006 case tcc_declaration: | |
3007 if (exp == f) | |
3008 return r; | |
3009 else | |
3010 return exp; | |
3011 | |
2697 case tcc_expression: | 3012 case tcc_expression: |
3013 if (exp == f) | |
3014 return r; | |
3015 | |
3016 /* Fall through... */ | |
3017 | |
3018 case tcc_exceptional: | |
3019 case tcc_unary: | |
3020 case tcc_binary: | |
3021 case tcc_comparison: | |
2698 case tcc_reference: | 3022 case tcc_reference: |
2699 switch (TREE_CODE_LENGTH (code)) | 3023 switch (TREE_CODE_LENGTH (code)) |
2700 { | 3024 { |
2701 case 0: | 3025 case 0: |
2702 return exp; | 3026 return exp; |
2740 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1) | 3064 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1) |
2741 && op2 == TREE_OPERAND (exp, 2) | 3065 && op2 == TREE_OPERAND (exp, 2) |
2742 && op3 == TREE_OPERAND (exp, 3)) | 3066 && op3 == TREE_OPERAND (exp, 3)) |
2743 return exp; | 3067 return exp; |
2744 | 3068 |
2745 new_tree = fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3)); | 3069 new_tree |
3070 = fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3)); | |
2746 break; | 3071 break; |
2747 | 3072 |
2748 default: | 3073 default: |
2749 gcc_unreachable (); | 3074 gcc_unreachable (); |
2750 } | 3075 } |
2751 break; | 3076 break; |
2752 | 3077 |
2753 case tcc_vl_exp: | 3078 case tcc_vl_exp: |
2754 { | 3079 { |
2755 tree copy = NULL_TREE; | |
2756 int i; | 3080 int i; |
3081 | |
3082 new_tree = NULL_TREE; | |
3083 | |
3084 /* If we are trying to replace F with a constant, inline back | |
3085 functions which do nothing else than computing a value from | |
3086 the arguments they are passed. This makes it possible to | |
3087 fold partially or entirely the replacement expression. */ | |
3088 if (CONSTANT_CLASS_P (r) && code == CALL_EXPR) | |
3089 { | |
3090 tree t = maybe_inline_call_in_expr (exp); | |
3091 if (t) | |
3092 return SUBSTITUTE_IN_EXPR (t, f, r); | |
3093 } | |
2757 | 3094 |
2758 for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++) | 3095 for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++) |
2759 { | 3096 { |
2760 tree op = TREE_OPERAND (exp, i); | 3097 tree op = TREE_OPERAND (exp, i); |
2761 tree new_op = SUBSTITUTE_IN_EXPR (op, f, r); | 3098 tree new_op = SUBSTITUTE_IN_EXPR (op, f, r); |
2762 if (new_op != op) | 3099 if (new_op != op) |
2763 { | 3100 { |
2764 if (!copy) | 3101 if (!new_tree) |
2765 copy = copy_node (exp); | 3102 new_tree = copy_node (exp); |
2766 TREE_OPERAND (copy, i) = new_op; | 3103 TREE_OPERAND (new_tree, i) = new_op; |
2767 } | 3104 } |
2768 } | 3105 } |
2769 | 3106 |
2770 if (copy) | 3107 if (new_tree) |
2771 new_tree = fold (copy); | 3108 { |
3109 new_tree = fold (new_tree); | |
3110 if (TREE_CODE (new_tree) == CALL_EXPR) | |
3111 process_call_operands (new_tree); | |
3112 } | |
2772 else | 3113 else |
2773 return exp; | 3114 return exp; |
2774 } | 3115 } |
2775 break; | 3116 break; |
2776 | 3117 |
2777 default: | 3118 default: |
2778 gcc_unreachable (); | 3119 gcc_unreachable (); |
2779 } | 3120 } |
2780 | 3121 |
2781 TREE_READONLY (new_tree) = TREE_READONLY (exp); | 3122 TREE_READONLY (new_tree) |= TREE_READONLY (exp); |
2782 return new_tree; | 3123 return new_tree; |
2783 } | 3124 } |
2784 | 3125 |
2785 /* Similar, but look for a PLACEHOLDER_EXPR in EXP and find a replacement | 3126 /* Similar, but look for a PLACEHOLDER_EXPR in EXP and find a replacement |
2786 for it within OBJ, a tree that is an object or a chain of references. */ | 3127 for it within OBJ, a tree that is an object or a chain of references. */ |
2788 tree | 3129 tree |
2789 substitute_placeholder_in_expr (tree exp, tree obj) | 3130 substitute_placeholder_in_expr (tree exp, tree obj) |
2790 { | 3131 { |
2791 enum tree_code code = TREE_CODE (exp); | 3132 enum tree_code code = TREE_CODE (exp); |
2792 tree op0, op1, op2, op3; | 3133 tree op0, op1, op2, op3; |
3134 tree new_tree; | |
2793 | 3135 |
2794 /* If this is a PLACEHOLDER_EXPR, see if we find a corresponding type | 3136 /* If this is a PLACEHOLDER_EXPR, see if we find a corresponding type |
2795 in the chain of OBJ. */ | 3137 in the chain of OBJ. */ |
2796 if (code == PLACEHOLDER_EXPR) | 3138 if (code == PLACEHOLDER_EXPR) |
2797 { | 3139 { |
2863 | 3205 |
2864 case 1: | 3206 case 1: |
2865 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj); | 3207 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj); |
2866 if (op0 == TREE_OPERAND (exp, 0)) | 3208 if (op0 == TREE_OPERAND (exp, 0)) |
2867 return exp; | 3209 return exp; |
2868 else | 3210 |
2869 return fold_build1 (code, TREE_TYPE (exp), op0); | 3211 new_tree = fold_build1 (code, TREE_TYPE (exp), op0); |
3212 break; | |
2870 | 3213 |
2871 case 2: | 3214 case 2: |
2872 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj); | 3215 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj); |
2873 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj); | 3216 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj); |
2874 | 3217 |
2875 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)) | 3218 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)) |
2876 return exp; | 3219 return exp; |
2877 else | 3220 |
2878 return fold_build2 (code, TREE_TYPE (exp), op0, op1); | 3221 new_tree = fold_build2 (code, TREE_TYPE (exp), op0, op1); |
3222 break; | |
2879 | 3223 |
2880 case 3: | 3224 case 3: |
2881 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj); | 3225 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj); |
2882 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj); | 3226 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj); |
2883 op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj); | 3227 op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj); |
2884 | 3228 |
2885 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1) | 3229 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1) |
2886 && op2 == TREE_OPERAND (exp, 2)) | 3230 && op2 == TREE_OPERAND (exp, 2)) |
2887 return exp; | 3231 return exp; |
2888 else | 3232 |
2889 return fold_build3 (code, TREE_TYPE (exp), op0, op1, op2); | 3233 new_tree = fold_build3 (code, TREE_TYPE (exp), op0, op1, op2); |
3234 break; | |
2890 | 3235 |
2891 case 4: | 3236 case 4: |
2892 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj); | 3237 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj); |
2893 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj); | 3238 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj); |
2894 op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj); | 3239 op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj); |
2896 | 3241 |
2897 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1) | 3242 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1) |
2898 && op2 == TREE_OPERAND (exp, 2) | 3243 && op2 == TREE_OPERAND (exp, 2) |
2899 && op3 == TREE_OPERAND (exp, 3)) | 3244 && op3 == TREE_OPERAND (exp, 3)) |
2900 return exp; | 3245 return exp; |
2901 else | 3246 |
2902 return fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3)); | 3247 new_tree |
3248 = fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3)); | |
3249 break; | |
2903 | 3250 |
2904 default: | 3251 default: |
2905 gcc_unreachable (); | 3252 gcc_unreachable (); |
2906 } | 3253 } |
2907 break; | 3254 break; |
2908 | 3255 |
2909 case tcc_vl_exp: | 3256 case tcc_vl_exp: |
2910 { | 3257 { |
2911 tree copy = NULL_TREE; | |
2912 int i; | 3258 int i; |
3259 | |
3260 new_tree = NULL_TREE; | |
2913 | 3261 |
2914 for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++) | 3262 for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++) |
2915 { | 3263 { |
2916 tree op = TREE_OPERAND (exp, i); | 3264 tree op = TREE_OPERAND (exp, i); |
2917 tree new_op = SUBSTITUTE_PLACEHOLDER_IN_EXPR (op, obj); | 3265 tree new_op = SUBSTITUTE_PLACEHOLDER_IN_EXPR (op, obj); |
2918 if (new_op != op) | 3266 if (new_op != op) |
2919 { | 3267 { |
2920 if (!copy) | 3268 if (!new_tree) |
2921 copy = copy_node (exp); | 3269 new_tree = copy_node (exp); |
2922 TREE_OPERAND (copy, i) = new_op; | 3270 TREE_OPERAND (new_tree, i) = new_op; |
2923 } | 3271 } |
2924 } | 3272 } |
2925 | 3273 |
2926 if (copy) | 3274 if (new_tree) |
2927 return fold (copy); | 3275 { |
3276 new_tree = fold (new_tree); | |
3277 if (TREE_CODE (new_tree) == CALL_EXPR) | |
3278 process_call_operands (new_tree); | |
3279 } | |
2928 else | 3280 else |
2929 return exp; | 3281 return exp; |
2930 } | 3282 } |
3283 break; | |
2931 | 3284 |
2932 default: | 3285 default: |
2933 gcc_unreachable (); | 3286 gcc_unreachable (); |
2934 } | 3287 } |
3288 | |
3289 TREE_READONLY (new_tree) |= TREE_READONLY (exp); | |
3290 return new_tree; | |
2935 } | 3291 } |
2936 | 3292 |
2937 /* Stabilize a reference so that we can use it any number of times | 3293 /* Stabilize a reference so that we can use it any number of times |
2938 without causing its operands to be evaluated more than once. | 3294 without causing its operands to be evaluated more than once. |
2939 Returns the stabilized reference. This works by means of save_expr, | 3295 Returns the stabilized reference. This works by means of save_expr, |
3277 } | 3633 } |
3278 | 3634 |
3279 return t; | 3635 return t; |
3280 } | 3636 } |
3281 | 3637 |
3282 #define PROCESS_ARG(N) \ | 3638 #define PROCESS_ARG(N) \ |
3283 do { \ | 3639 do { \ |
3284 TREE_OPERAND (t, N) = arg##N; \ | 3640 TREE_OPERAND (t, N) = arg##N; \ |
3285 if (arg##N &&!TYPE_P (arg##N)) \ | 3641 if (arg##N &&!TYPE_P (arg##N)) \ |
3286 { \ | 3642 { \ |
3287 if (TREE_SIDE_EFFECTS (arg##N)) \ | 3643 if (TREE_SIDE_EFFECTS (arg##N)) \ |
3288 side_effects = 1; \ | 3644 side_effects = 1; \ |
3289 if (!TREE_READONLY (arg##N)) \ | 3645 if (!TREE_READONLY (arg##N) \ |
3290 read_only = 0; \ | 3646 && !CONSTANT_CLASS_P (arg##N)) \ |
3291 if (!TREE_CONSTANT (arg##N)) \ | 3647 read_only = 0; \ |
3292 constant = 0; \ | 3648 if (!TREE_CONSTANT (arg##N)) \ |
3293 } \ | 3649 constant = 0; \ |
3650 } \ | |
3294 } while (0) | 3651 } while (0) |
3295 | 3652 |
3296 tree | 3653 tree |
3297 build2_stat (enum tree_code code, tree tt, tree arg0, tree arg1 MEM_STAT_DECL) | 3654 build2_stat (enum tree_code code, tree tt, tree arg0, tree arg1 MEM_STAT_DECL) |
3298 { | 3655 { |
3354 gcc_assert (TREE_CODE_LENGTH (code) == 3); | 3711 gcc_assert (TREE_CODE_LENGTH (code) == 3); |
3355 gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp); | 3712 gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp); |
3356 | 3713 |
3357 t = make_node_stat (code PASS_MEM_STAT); | 3714 t = make_node_stat (code PASS_MEM_STAT); |
3358 TREE_TYPE (t) = tt; | 3715 TREE_TYPE (t) = tt; |
3716 | |
3717 read_only = 1; | |
3359 | 3718 |
3360 /* As a special exception, if COND_EXPR has NULL branches, we | 3719 /* As a special exception, if COND_EXPR has NULL branches, we |
3361 assume that it is a gimple statement and always consider | 3720 assume that it is a gimple statement and always consider |
3362 it to have side effects. */ | 3721 it to have side effects. */ |
3363 if (code == COND_EXPR | 3722 if (code == COND_EXPR |
3370 | 3729 |
3371 PROCESS_ARG(0); | 3730 PROCESS_ARG(0); |
3372 PROCESS_ARG(1); | 3731 PROCESS_ARG(1); |
3373 PROCESS_ARG(2); | 3732 PROCESS_ARG(2); |
3374 | 3733 |
3734 if (code == COND_EXPR) | |
3735 TREE_READONLY (t) = read_only; | |
3736 | |
3375 TREE_SIDE_EFFECTS (t) = side_effects; | 3737 TREE_SIDE_EFFECTS (t) = side_effects; |
3376 TREE_THIS_VOLATILE (t) | 3738 TREE_THIS_VOLATILE (t) |
3377 = (TREE_CODE_CLASS (code) == tcc_reference | 3739 = (TREE_CODE_CLASS (code) == tcc_reference |
3378 && arg0 && TREE_THIS_VOLATILE (arg0)); | 3740 && arg0 && TREE_THIS_VOLATILE (arg0)); |
3379 | 3741 |
3434 | 3796 |
3435 return t; | 3797 return t; |
3436 } | 3798 } |
3437 | 3799 |
3438 tree | 3800 tree |
3439 build7_stat (enum tree_code code, tree tt, tree arg0, tree arg1, | 3801 build6_stat (enum tree_code code, tree tt, tree arg0, tree arg1, |
3440 tree arg2, tree arg3, tree arg4, tree arg5, | 3802 tree arg2, tree arg3, tree arg4, tree arg5 MEM_STAT_DECL) |
3441 tree arg6 MEM_STAT_DECL) | |
3442 { | 3803 { |
3443 bool constant, read_only, side_effects; | 3804 bool constant, read_only, side_effects; |
3444 tree t; | 3805 tree t; |
3445 | 3806 |
3446 gcc_assert (code == TARGET_MEM_REF); | 3807 gcc_assert (code == TARGET_MEM_REF); |
3454 PROCESS_ARG(1); | 3815 PROCESS_ARG(1); |
3455 PROCESS_ARG(2); | 3816 PROCESS_ARG(2); |
3456 PROCESS_ARG(3); | 3817 PROCESS_ARG(3); |
3457 PROCESS_ARG(4); | 3818 PROCESS_ARG(4); |
3458 PROCESS_ARG(5); | 3819 PROCESS_ARG(5); |
3459 PROCESS_ARG(6); | |
3460 | 3820 |
3461 TREE_SIDE_EFFECTS (t) = side_effects; | 3821 TREE_SIDE_EFFECTS (t) = side_effects; |
3462 TREE_THIS_VOLATILE (t) = 0; | 3822 TREE_THIS_VOLATILE (t) = 0; |
3463 | 3823 |
3464 return t; | 3824 return t; |
3505 CALL_EXPR_STATIC_CHAIN (t) = NULL_TREE; | 3865 CALL_EXPR_STATIC_CHAIN (t) = NULL_TREE; |
3506 for (i = 0; arglist; arglist = TREE_CHAIN (arglist), i++) | 3866 for (i = 0; arglist; arglist = TREE_CHAIN (arglist), i++) |
3507 CALL_EXPR_ARG (t, i) = TREE_VALUE (arglist); | 3867 CALL_EXPR_ARG (t, i) = TREE_VALUE (arglist); |
3508 return t; | 3868 return t; |
3509 } | 3869 } |
3870 | |
3871 /* Similar to build_nt, but for creating a CALL_EXPR object with a | |
3872 tree VEC. */ | |
3873 | |
3874 tree | |
3875 build_nt_call_vec (tree fn, VEC(tree,gc) *args) | |
3876 { | |
3877 tree ret, t; | |
3878 unsigned int ix; | |
3879 | |
3880 ret = build_vl_exp (CALL_EXPR, VEC_length (tree, args) + 3); | |
3881 CALL_EXPR_FN (ret) = fn; | |
3882 CALL_EXPR_STATIC_CHAIN (ret) = NULL_TREE; | |
3883 for (ix = 0; VEC_iterate (tree, args, ix, t); ++ix) | |
3884 CALL_EXPR_ARG (ret, ix) = t; | |
3885 return ret; | |
3886 } | |
3510 | 3887 |
3511 /* Create a DECL_... node of code CODE, name NAME and data type TYPE. | 3888 /* Create a DECL_... node of code CODE, name NAME and data type TYPE. |
3512 We do NOT enter this node in any sort of symbol table. | 3889 We do NOT enter this node in any sort of symbol table. |
3513 | 3890 |
3891 LOC is the location of the decl. | |
3892 | |
3514 layout_decl is used to set up the decl's storage layout. | 3893 layout_decl is used to set up the decl's storage layout. |
3515 Other slots are initialized to 0 or null pointers. */ | 3894 Other slots are initialized to 0 or null pointers. */ |
3516 | 3895 |
3517 tree | 3896 tree |
3518 build_decl_stat (enum tree_code code, tree name, tree type MEM_STAT_DECL) | 3897 build_decl_stat (location_t loc, enum tree_code code, tree name, |
3898 tree type MEM_STAT_DECL) | |
3519 { | 3899 { |
3520 tree t; | 3900 tree t; |
3521 | 3901 |
3522 t = make_node_stat (code PASS_MEM_STAT); | 3902 t = make_node_stat (code PASS_MEM_STAT); |
3903 DECL_SOURCE_LOCATION (t) = loc; | |
3523 | 3904 |
3524 /* if (type == error_mark_node) | 3905 /* if (type == error_mark_node) |
3525 type = integer_type_node; */ | 3906 type = integer_type_node; */ |
3526 /* That is not done, deliberately, so that having error_mark_node | 3907 /* That is not done, deliberately, so that having error_mark_node |
3527 as the type can suppress useless errors in the use of this variable. */ | 3908 as the type can suppress useless errors in the use of this variable. */ |
3539 | 3920 |
3540 tree | 3921 tree |
3541 build_fn_decl (const char *name, tree type) | 3922 build_fn_decl (const char *name, tree type) |
3542 { | 3923 { |
3543 tree id = get_identifier (name); | 3924 tree id = get_identifier (name); |
3544 tree decl = build_decl (FUNCTION_DECL, id, type); | 3925 tree decl = build_decl (input_location, FUNCTION_DECL, id, type); |
3545 | 3926 |
3546 DECL_EXTERNAL (decl) = 1; | 3927 DECL_EXTERNAL (decl) = 1; |
3547 TREE_PUBLIC (decl) = 1; | 3928 TREE_PUBLIC (decl) = 1; |
3548 DECL_ARTIFICIAL (decl) = 1; | 3929 DECL_ARTIFICIAL (decl) = 1; |
3549 TREE_NOTHROW (decl) = 1; | 3930 TREE_NOTHROW (decl) = 1; |
3570 | 3951 |
3571 expanded_location | 3952 expanded_location |
3572 expand_location (source_location loc) | 3953 expand_location (source_location loc) |
3573 { | 3954 { |
3574 expanded_location xloc; | 3955 expanded_location xloc; |
3575 if (loc == 0) | 3956 if (loc <= BUILTINS_LOCATION) |
3576 { | 3957 { |
3577 xloc.file = NULL; | 3958 xloc.file = loc == UNKNOWN_LOCATION ? NULL : _("<built-in>"); |
3578 xloc.line = 0; | 3959 xloc.line = 0; |
3579 xloc.column = 0; | 3960 xloc.column = 0; |
3580 xloc.sysp = 0; | 3961 xloc.sysp = 0; |
3581 } | 3962 } |
3582 else | 3963 else |
3589 }; | 3970 }; |
3590 return xloc; | 3971 return xloc; |
3591 } | 3972 } |
3592 | 3973 |
3593 | 3974 |
3594 /* Source location accessor functions. */ | 3975 /* Like SET_EXPR_LOCATION, but make sure the tree can have a location. |
3595 | 3976 |
3977 LOC is the location to use in tree T. */ | |
3596 | 3978 |
3597 void | 3979 void |
3598 set_expr_locus (tree node, source_location *loc) | 3980 protected_set_expr_location (tree t, location_t loc) |
3599 { | |
3600 if (loc == NULL) | |
3601 EXPR_CHECK (node)->exp.locus = UNKNOWN_LOCATION; | |
3602 else | |
3603 EXPR_CHECK (node)->exp.locus = *loc; | |
3604 } | |
3605 | |
3606 /* Like SET_EXPR_LOCATION, but make sure the tree can have a location. | |
3607 | |
3608 LOC is the location to use in tree T. */ | |
3609 | |
3610 void protected_set_expr_location (tree t, location_t loc) | |
3611 { | 3981 { |
3612 if (t && CAN_HAVE_LOCATION_P (t)) | 3982 if (t && CAN_HAVE_LOCATION_P (t)) |
3613 SET_EXPR_LOCATION (t, loc); | 3983 SET_EXPR_LOCATION (t, loc); |
3614 } | 3984 } |
3615 | 3985 |
3647 | 4017 |
3648 mix (a, val, val2); | 4018 mix (a, val, val2); |
3649 return val2; | 4019 return val2; |
3650 } | 4020 } |
3651 | 4021 |
3652 /* Produce good hash value combining PTR and VAL2. */ | |
3653 static inline hashval_t | |
3654 iterative_hash_pointer (const void *ptr, hashval_t val2) | |
3655 { | |
3656 if (sizeof (ptr) == sizeof (hashval_t)) | |
3657 return iterative_hash_hashval_t ((size_t) ptr, val2); | |
3658 else | |
3659 { | |
3660 hashval_t a = (hashval_t) (size_t) ptr; | |
3661 /* Avoid warnings about shifting of more than the width of the type on | |
3662 hosts that won't execute this path. */ | |
3663 int zero = 0; | |
3664 hashval_t b = (hashval_t) ((size_t) ptr >> (sizeof (hashval_t) * 8 + zero)); | |
3665 mix (a, b, val2); | |
3666 return val2; | |
3667 } | |
3668 } | |
3669 | |
3670 /* Produce good hash value combining VAL and VAL2. */ | 4022 /* Produce good hash value combining VAL and VAL2. */ |
3671 static inline hashval_t | 4023 hashval_t |
3672 iterative_hash_host_wide_int (HOST_WIDE_INT val, hashval_t val2) | 4024 iterative_hash_host_wide_int (HOST_WIDE_INT val, hashval_t val2) |
3673 { | 4025 { |
3674 if (sizeof (HOST_WIDE_INT) == sizeof (hashval_t)) | 4026 if (sizeof (HOST_WIDE_INT) == sizeof (hashval_t)) |
3675 return iterative_hash_hashval_t (val, val2); | 4027 return iterative_hash_hashval_t (val, val2); |
3676 else | 4028 else |
3694 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE | 4046 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE |
3695 is ATTRIBUTE and its qualifiers are QUALS. | 4047 is ATTRIBUTE and its qualifiers are QUALS. |
3696 | 4048 |
3697 Record such modified types already made so we don't make duplicates. */ | 4049 Record such modified types already made so we don't make duplicates. */ |
3698 | 4050 |
3699 static tree | 4051 tree |
3700 build_type_attribute_qual_variant (tree ttype, tree attribute, int quals) | 4052 build_type_attribute_qual_variant (tree ttype, tree attribute, int quals) |
3701 { | 4053 { |
3702 if (! attribute_list_equal (TYPE_ATTRIBUTES (ttype), attribute)) | 4054 if (! attribute_list_equal (TYPE_ATTRIBUTES (ttype), attribute)) |
3703 { | 4055 { |
3704 hashval_t hashcode = 0; | 4056 hashval_t hashcode = 0; |
3790 { | 4142 { |
3791 return build_type_attribute_qual_variant (ttype, attribute, | 4143 return build_type_attribute_qual_variant (ttype, attribute, |
3792 TYPE_QUALS (ttype)); | 4144 TYPE_QUALS (ttype)); |
3793 } | 4145 } |
3794 | 4146 |
4147 | |
4148 /* Reset all the fields in a binfo node BINFO. We only keep | |
4149 BINFO_VIRTUALS, which is used by gimple_fold_obj_type_ref. */ | |
4150 | |
4151 static void | |
4152 free_lang_data_in_binfo (tree binfo) | |
4153 { | |
4154 unsigned i; | |
4155 tree t; | |
4156 | |
4157 gcc_assert (TREE_CODE (binfo) == TREE_BINFO); | |
4158 | |
4159 BINFO_VTABLE (binfo) = NULL_TREE; | |
4160 BINFO_BASE_ACCESSES (binfo) = NULL; | |
4161 BINFO_INHERITANCE_CHAIN (binfo) = NULL_TREE; | |
4162 BINFO_SUBVTT_INDEX (binfo) = NULL_TREE; | |
4163 | |
4164 for (i = 0; VEC_iterate (tree, BINFO_BASE_BINFOS (binfo), i, t); i++) | |
4165 free_lang_data_in_binfo (t); | |
4166 } | |
4167 | |
4168 | |
4169 /* Reset all language specific information still present in TYPE. */ | |
4170 | |
4171 static void | |
4172 free_lang_data_in_type (tree type) | |
4173 { | |
4174 gcc_assert (TYPE_P (type)); | |
4175 | |
4176 /* Give the FE a chance to remove its own data first. */ | |
4177 lang_hooks.free_lang_data (type); | |
4178 | |
4179 TREE_LANG_FLAG_0 (type) = 0; | |
4180 TREE_LANG_FLAG_1 (type) = 0; | |
4181 TREE_LANG_FLAG_2 (type) = 0; | |
4182 TREE_LANG_FLAG_3 (type) = 0; | |
4183 TREE_LANG_FLAG_4 (type) = 0; | |
4184 TREE_LANG_FLAG_5 (type) = 0; | |
4185 TREE_LANG_FLAG_6 (type) = 0; | |
4186 | |
4187 if (TREE_CODE (type) == FUNCTION_TYPE) | |
4188 { | |
4189 /* Remove the const and volatile qualifiers from arguments. The | |
4190 C++ front end removes them, but the C front end does not, | |
4191 leading to false ODR violation errors when merging two | |
4192 instances of the same function signature compiled by | |
4193 different front ends. */ | |
4194 tree p; | |
4195 | |
4196 for (p = TYPE_ARG_TYPES (type); p; p = TREE_CHAIN (p)) | |
4197 { | |
4198 tree arg_type = TREE_VALUE (p); | |
4199 | |
4200 if (TYPE_READONLY (arg_type) || TYPE_VOLATILE (arg_type)) | |
4201 { | |
4202 int quals = TYPE_QUALS (arg_type) | |
4203 & ~TYPE_QUAL_CONST | |
4204 & ~TYPE_QUAL_VOLATILE; | |
4205 TREE_VALUE (p) = build_qualified_type (arg_type, quals); | |
4206 free_lang_data_in_type (TREE_VALUE (p)); | |
4207 } | |
4208 } | |
4209 } | |
4210 | |
4211 /* Remove members that are not actually FIELD_DECLs from the field | |
4212 list of an aggregate. These occur in C++. */ | |
4213 if (RECORD_OR_UNION_TYPE_P (type)) | |
4214 { | |
4215 tree prev, member; | |
4216 | |
4217 /* Note that TYPE_FIELDS can be shared across distinct | |
4218 TREE_TYPEs. Therefore, if the first field of TYPE_FIELDS is | |
4219 to be removed, we cannot set its TREE_CHAIN to NULL. | |
4220 Otherwise, we would not be able to find all the other fields | |
4221 in the other instances of this TREE_TYPE. | |
4222 | |
4223 This was causing an ICE in testsuite/g++.dg/lto/20080915.C. */ | |
4224 prev = NULL_TREE; | |
4225 member = TYPE_FIELDS (type); | |
4226 while (member) | |
4227 { | |
4228 if (TREE_CODE (member) == FIELD_DECL) | |
4229 { | |
4230 if (prev) | |
4231 TREE_CHAIN (prev) = member; | |
4232 else | |
4233 TYPE_FIELDS (type) = member; | |
4234 prev = member; | |
4235 } | |
4236 | |
4237 member = TREE_CHAIN (member); | |
4238 } | |
4239 | |
4240 if (prev) | |
4241 TREE_CHAIN (prev) = NULL_TREE; | |
4242 else | |
4243 TYPE_FIELDS (type) = NULL_TREE; | |
4244 | |
4245 TYPE_METHODS (type) = NULL_TREE; | |
4246 if (TYPE_BINFO (type)) | |
4247 free_lang_data_in_binfo (TYPE_BINFO (type)); | |
4248 } | |
4249 else | |
4250 { | |
4251 /* For non-aggregate types, clear out the language slot (which | |
4252 overloads TYPE_BINFO). */ | |
4253 TYPE_LANG_SLOT_1 (type) = NULL_TREE; | |
4254 } | |
4255 | |
4256 TYPE_CONTEXT (type) = NULL_TREE; | |
4257 if (debug_info_level < DINFO_LEVEL_TERSE) | |
4258 TYPE_STUB_DECL (type) = NULL_TREE; | |
4259 } | |
4260 | |
4261 | |
4262 /* Return true if DECL may need an assembler name to be set. */ | |
4263 | |
4264 static inline bool | |
4265 need_assembler_name_p (tree decl) | |
4266 { | |
4267 /* Only FUNCTION_DECLs and VAR_DECLs are considered. */ | |
4268 if (TREE_CODE (decl) != FUNCTION_DECL | |
4269 && TREE_CODE (decl) != VAR_DECL) | |
4270 return false; | |
4271 | |
4272 /* If DECL already has its assembler name set, it does not need a | |
4273 new one. */ | |
4274 if (!HAS_DECL_ASSEMBLER_NAME_P (decl) | |
4275 || DECL_ASSEMBLER_NAME_SET_P (decl)) | |
4276 return false; | |
4277 | |
4278 /* Abstract decls do not need an assembler name. */ | |
4279 if (DECL_ABSTRACT (decl)) | |
4280 return false; | |
4281 | |
4282 /* For VAR_DECLs, only static, public and external symbols need an | |
4283 assembler name. */ | |
4284 if (TREE_CODE (decl) == VAR_DECL | |
4285 && !TREE_STATIC (decl) | |
4286 && !TREE_PUBLIC (decl) | |
4287 && !DECL_EXTERNAL (decl)) | |
4288 return false; | |
4289 | |
4290 if (TREE_CODE (decl) == FUNCTION_DECL) | |
4291 { | |
4292 /* Do not set assembler name on builtins. Allow RTL expansion to | |
4293 decide whether to expand inline or via a regular call. */ | |
4294 if (DECL_BUILT_IN (decl) | |
4295 && DECL_BUILT_IN_CLASS (decl) != BUILT_IN_FRONTEND) | |
4296 return false; | |
4297 | |
4298 /* Functions represented in the callgraph need an assembler name. */ | |
4299 if (cgraph_get_node (decl) != NULL) | |
4300 return true; | |
4301 | |
4302 /* Unused and not public functions don't need an assembler name. */ | |
4303 if (!TREE_USED (decl) && !TREE_PUBLIC (decl)) | |
4304 return false; | |
4305 } | |
4306 | |
4307 return true; | |
4308 } | |
4309 | |
4310 | |
4311 /* Remove all the non-variable decls from BLOCK. LOCALS is the set of | |
4312 variables in DECL_STRUCT_FUNCTION (FN)->local_decls. Every decl | |
4313 in BLOCK that is not in LOCALS is removed. */ | |
4314 | |
4315 static void | |
4316 free_lang_data_in_block (tree fn, tree block, struct pointer_set_t *locals) | |
4317 { | |
4318 tree *tp, t; | |
4319 | |
4320 tp = &BLOCK_VARS (block); | |
4321 while (*tp) | |
4322 { | |
4323 if (!pointer_set_contains (locals, *tp)) | |
4324 *tp = TREE_CHAIN (*tp); | |
4325 else | |
4326 tp = &TREE_CHAIN (*tp); | |
4327 } | |
4328 | |
4329 for (t = BLOCK_SUBBLOCKS (block); t; t = BLOCK_CHAIN (t)) | |
4330 free_lang_data_in_block (fn, t, locals); | |
4331 } | |
4332 | |
4333 | |
4334 /* Reset all language specific information still present in symbol | |
4335 DECL. */ | |
4336 | |
4337 static void | |
4338 free_lang_data_in_decl (tree decl) | |
4339 { | |
4340 gcc_assert (DECL_P (decl)); | |
4341 | |
4342 /* Give the FE a chance to remove its own data first. */ | |
4343 lang_hooks.free_lang_data (decl); | |
4344 | |
4345 TREE_LANG_FLAG_0 (decl) = 0; | |
4346 TREE_LANG_FLAG_1 (decl) = 0; | |
4347 TREE_LANG_FLAG_2 (decl) = 0; | |
4348 TREE_LANG_FLAG_3 (decl) = 0; | |
4349 TREE_LANG_FLAG_4 (decl) = 0; | |
4350 TREE_LANG_FLAG_5 (decl) = 0; | |
4351 TREE_LANG_FLAG_6 (decl) = 0; | |
4352 | |
4353 /* Identifiers need not have a type. */ | |
4354 if (DECL_NAME (decl)) | |
4355 TREE_TYPE (DECL_NAME (decl)) = NULL_TREE; | |
4356 | |
4357 /* Ignore any intervening types, because we are going to clear their | |
4358 TYPE_CONTEXT fields. */ | |
4359 if (TREE_CODE (decl) != FIELD_DECL) | |
4360 DECL_CONTEXT (decl) = decl_function_context (decl); | |
4361 | |
4362 if (DECL_CONTEXT (decl) | |
4363 && TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL) | |
4364 DECL_CONTEXT (decl) = NULL_TREE; | |
4365 | |
4366 if (TREE_CODE (decl) == VAR_DECL) | |
4367 { | |
4368 tree context = DECL_CONTEXT (decl); | |
4369 | |
4370 if (context) | |
4371 { | |
4372 enum tree_code code = TREE_CODE (context); | |
4373 if (code == FUNCTION_DECL && DECL_ABSTRACT (context)) | |
4374 { | |
4375 /* Do not clear the decl context here, that will promote | |
4376 all vars to global ones. */ | |
4377 DECL_INITIAL (decl) = NULL_TREE; | |
4378 } | |
4379 | |
4380 if (TREE_STATIC (decl)) | |
4381 DECL_CONTEXT (decl) = NULL_TREE; | |
4382 } | |
4383 } | |
4384 | |
4385 /* ??? We could free non-constant DECL_SIZE, DECL_SIZE_UNIT | |
4386 and DECL_FIELD_OFFSET. But it's cheap enough to not do | |
4387 that and refrain from adding workarounds to dwarf2out.c */ | |
4388 | |
4389 /* DECL_FCONTEXT is only used for debug info generation. */ | |
4390 if (TREE_CODE (decl) == FIELD_DECL | |
4391 && debug_info_level < DINFO_LEVEL_TERSE) | |
4392 DECL_FCONTEXT (decl) = NULL_TREE; | |
4393 | |
4394 if (TREE_CODE (decl) == FUNCTION_DECL) | |
4395 { | |
4396 if (gimple_has_body_p (decl)) | |
4397 { | |
4398 tree t; | |
4399 struct pointer_set_t *locals; | |
4400 | |
4401 /* If DECL has a gimple body, then the context for its | |
4402 arguments must be DECL. Otherwise, it doesn't really | |
4403 matter, as we will not be emitting any code for DECL. In | |
4404 general, there may be other instances of DECL created by | |
4405 the front end and since PARM_DECLs are generally shared, | |
4406 their DECL_CONTEXT changes as the replicas of DECL are | |
4407 created. The only time where DECL_CONTEXT is important | |
4408 is for the FUNCTION_DECLs that have a gimple body (since | |
4409 the PARM_DECL will be used in the function's body). */ | |
4410 for (t = DECL_ARGUMENTS (decl); t; t = TREE_CHAIN (t)) | |
4411 DECL_CONTEXT (t) = decl; | |
4412 | |
4413 /* Collect all the symbols declared in DECL. */ | |
4414 locals = pointer_set_create (); | |
4415 t = DECL_STRUCT_FUNCTION (decl)->local_decls; | |
4416 for (; t; t = TREE_CHAIN (t)) | |
4417 { | |
4418 pointer_set_insert (locals, TREE_VALUE (t)); | |
4419 | |
4420 /* All the local symbols should have DECL as their | |
4421 context. */ | |
4422 DECL_CONTEXT (TREE_VALUE (t)) = decl; | |
4423 } | |
4424 | |
4425 /* Get rid of any decl not in local_decls. */ | |
4426 free_lang_data_in_block (decl, DECL_INITIAL (decl), locals); | |
4427 | |
4428 pointer_set_destroy (locals); | |
4429 } | |
4430 | |
4431 /* DECL_SAVED_TREE holds the GENERIC representation for DECL. | |
4432 At this point, it is not needed anymore. */ | |
4433 DECL_SAVED_TREE (decl) = NULL_TREE; | |
4434 } | |
4435 else if (TREE_CODE (decl) == VAR_DECL) | |
4436 { | |
4437 tree expr = DECL_DEBUG_EXPR (decl); | |
4438 if (expr | |
4439 && TREE_CODE (expr) == VAR_DECL | |
4440 && !TREE_STATIC (expr) && !DECL_EXTERNAL (expr)) | |
4441 SET_DECL_DEBUG_EXPR (decl, NULL_TREE); | |
4442 | |
4443 if (DECL_EXTERNAL (decl) | |
4444 && (!TREE_STATIC (decl) || !TREE_READONLY (decl))) | |
4445 DECL_INITIAL (decl) = NULL_TREE; | |
4446 } | |
4447 else if (TREE_CODE (decl) == TYPE_DECL) | |
4448 { | |
4449 DECL_INITIAL (decl) = NULL_TREE; | |
4450 | |
4451 /* DECL_CONTEXT is overloaded as DECL_FIELD_CONTEXT for | |
4452 FIELD_DECLs, which should be preserved. Otherwise, | |
4453 we shouldn't be concerned with source-level lexical | |
4454 nesting beyond this point. */ | |
4455 DECL_CONTEXT (decl) = NULL_TREE; | |
4456 } | |
4457 } | |
4458 | |
4459 | |
4460 /* Data used when collecting DECLs and TYPEs for language data removal. */ | |
4461 | |
4462 struct free_lang_data_d | |
4463 { | |
4464 /* Worklist to avoid excessive recursion. */ | |
4465 VEC(tree,heap) *worklist; | |
4466 | |
4467 /* Set of traversed objects. Used to avoid duplicate visits. */ | |
4468 struct pointer_set_t *pset; | |
4469 | |
4470 /* Array of symbols to process with free_lang_data_in_decl. */ | |
4471 VEC(tree,heap) *decls; | |
4472 | |
4473 /* Array of types to process with free_lang_data_in_type. */ | |
4474 VEC(tree,heap) *types; | |
4475 }; | |
4476 | |
4477 | |
4478 /* Save all language fields needed to generate proper debug information | |
4479 for DECL. This saves most fields cleared out by free_lang_data_in_decl. */ | |
4480 | |
4481 static void | |
4482 save_debug_info_for_decl (tree t) | |
4483 { | |
4484 /*struct saved_debug_info_d *sdi;*/ | |
4485 | |
4486 gcc_assert (debug_info_level > DINFO_LEVEL_TERSE && t && DECL_P (t)); | |
4487 | |
4488 /* FIXME. Partial implementation for saving debug info removed. */ | |
4489 } | |
4490 | |
4491 | |
4492 /* Save all language fields needed to generate proper debug information | |
4493 for TYPE. This saves most fields cleared out by free_lang_data_in_type. */ | |
4494 | |
4495 static void | |
4496 save_debug_info_for_type (tree t) | |
4497 { | |
4498 /*struct saved_debug_info_d *sdi;*/ | |
4499 | |
4500 gcc_assert (debug_info_level > DINFO_LEVEL_TERSE && t && TYPE_P (t)); | |
4501 | |
4502 /* FIXME. Partial implementation for saving debug info removed. */ | |
4503 } | |
4504 | |
4505 | |
4506 /* Add type or decl T to one of the list of tree nodes that need their | |
4507 language data removed. The lists are held inside FLD. */ | |
4508 | |
4509 static void | |
4510 add_tree_to_fld_list (tree t, struct free_lang_data_d *fld) | |
4511 { | |
4512 if (DECL_P (t)) | |
4513 { | |
4514 VEC_safe_push (tree, heap, fld->decls, t); | |
4515 if (debug_info_level > DINFO_LEVEL_TERSE) | |
4516 save_debug_info_for_decl (t); | |
4517 } | |
4518 else if (TYPE_P (t)) | |
4519 { | |
4520 VEC_safe_push (tree, heap, fld->types, t); | |
4521 if (debug_info_level > DINFO_LEVEL_TERSE) | |
4522 save_debug_info_for_type (t); | |
4523 } | |
4524 else | |
4525 gcc_unreachable (); | |
4526 } | |
4527 | |
4528 /* Push tree node T into FLD->WORKLIST. */ | |
4529 | |
4530 static inline void | |
4531 fld_worklist_push (tree t, struct free_lang_data_d *fld) | |
4532 { | |
4533 if (t && !is_lang_specific (t) && !pointer_set_contains (fld->pset, t)) | |
4534 VEC_safe_push (tree, heap, fld->worklist, (t)); | |
4535 } | |
4536 | |
4537 | |
4538 /* Operand callback helper for free_lang_data_in_node. *TP is the | |
4539 subtree operand being considered. */ | |
4540 | |
4541 static tree | |
4542 find_decls_types_r (tree *tp, int *ws, void *data) | |
4543 { | |
4544 tree t = *tp; | |
4545 struct free_lang_data_d *fld = (struct free_lang_data_d *) data; | |
4546 | |
4547 if (TREE_CODE (t) == TREE_LIST) | |
4548 return NULL_TREE; | |
4549 | |
4550 /* Language specific nodes will be removed, so there is no need | |
4551 to gather anything under them. */ | |
4552 if (is_lang_specific (t)) | |
4553 { | |
4554 *ws = 0; | |
4555 return NULL_TREE; | |
4556 } | |
4557 | |
4558 if (DECL_P (t)) | |
4559 { | |
4560 /* Note that walk_tree does not traverse every possible field in | |
4561 decls, so we have to do our own traversals here. */ | |
4562 add_tree_to_fld_list (t, fld); | |
4563 | |
4564 fld_worklist_push (DECL_NAME (t), fld); | |
4565 fld_worklist_push (DECL_CONTEXT (t), fld); | |
4566 fld_worklist_push (DECL_SIZE (t), fld); | |
4567 fld_worklist_push (DECL_SIZE_UNIT (t), fld); | |
4568 | |
4569 /* We are going to remove everything under DECL_INITIAL for | |
4570 TYPE_DECLs. No point walking them. */ | |
4571 if (TREE_CODE (t) != TYPE_DECL) | |
4572 fld_worklist_push (DECL_INITIAL (t), fld); | |
4573 | |
4574 fld_worklist_push (DECL_ATTRIBUTES (t), fld); | |
4575 fld_worklist_push (DECL_ABSTRACT_ORIGIN (t), fld); | |
4576 | |
4577 if (TREE_CODE (t) == FUNCTION_DECL) | |
4578 { | |
4579 fld_worklist_push (DECL_ARGUMENTS (t), fld); | |
4580 fld_worklist_push (DECL_RESULT (t), fld); | |
4581 } | |
4582 else if (TREE_CODE (t) == TYPE_DECL) | |
4583 { | |
4584 fld_worklist_push (DECL_ARGUMENT_FLD (t), fld); | |
4585 fld_worklist_push (DECL_VINDEX (t), fld); | |
4586 } | |
4587 else if (TREE_CODE (t) == FIELD_DECL) | |
4588 { | |
4589 fld_worklist_push (DECL_FIELD_OFFSET (t), fld); | |
4590 fld_worklist_push (DECL_BIT_FIELD_TYPE (t), fld); | |
4591 fld_worklist_push (DECL_QUALIFIER (t), fld); | |
4592 fld_worklist_push (DECL_FIELD_BIT_OFFSET (t), fld); | |
4593 fld_worklist_push (DECL_FCONTEXT (t), fld); | |
4594 } | |
4595 else if (TREE_CODE (t) == VAR_DECL) | |
4596 { | |
4597 fld_worklist_push (DECL_SECTION_NAME (t), fld); | |
4598 fld_worklist_push (DECL_COMDAT_GROUP (t), fld); | |
4599 } | |
4600 | |
4601 if (TREE_CODE (t) != FIELD_DECL) | |
4602 fld_worklist_push (TREE_CHAIN (t), fld); | |
4603 *ws = 0; | |
4604 } | |
4605 else if (TYPE_P (t)) | |
4606 { | |
4607 /* Note that walk_tree does not traverse every possible field in | |
4608 types, so we have to do our own traversals here. */ | |
4609 add_tree_to_fld_list (t, fld); | |
4610 | |
4611 if (!RECORD_OR_UNION_TYPE_P (t)) | |
4612 fld_worklist_push (TYPE_CACHED_VALUES (t), fld); | |
4613 fld_worklist_push (TYPE_SIZE (t), fld); | |
4614 fld_worklist_push (TYPE_SIZE_UNIT (t), fld); | |
4615 fld_worklist_push (TYPE_ATTRIBUTES (t), fld); | |
4616 fld_worklist_push (TYPE_POINTER_TO (t), fld); | |
4617 fld_worklist_push (TYPE_REFERENCE_TO (t), fld); | |
4618 fld_worklist_push (TYPE_NAME (t), fld); | |
4619 fld_worklist_push (TYPE_MINVAL (t), fld); | |
4620 if (!RECORD_OR_UNION_TYPE_P (t)) | |
4621 fld_worklist_push (TYPE_MAXVAL (t), fld); | |
4622 fld_worklist_push (TYPE_MAIN_VARIANT (t), fld); | |
4623 fld_worklist_push (TYPE_NEXT_VARIANT (t), fld); | |
4624 fld_worklist_push (TYPE_CONTEXT (t), fld); | |
4625 fld_worklist_push (TYPE_CANONICAL (t), fld); | |
4626 | |
4627 if (RECORD_OR_UNION_TYPE_P (t) && TYPE_BINFO (t)) | |
4628 { | |
4629 unsigned i; | |
4630 tree tem; | |
4631 for (i = 0; VEC_iterate (tree, BINFO_BASE_BINFOS (TYPE_BINFO (t)), | |
4632 i, tem); ++i) | |
4633 fld_worklist_push (TREE_TYPE (tem), fld); | |
4634 tem = BINFO_VIRTUALS (TYPE_BINFO (t)); | |
4635 if (tem | |
4636 /* The Java FE overloads BINFO_VIRTUALS for its own purpose. */ | |
4637 && TREE_CODE (tem) == TREE_LIST) | |
4638 do | |
4639 { | |
4640 fld_worklist_push (TREE_VALUE (tem), fld); | |
4641 tem = TREE_CHAIN (tem); | |
4642 } | |
4643 while (tem); | |
4644 } | |
4645 if (RECORD_OR_UNION_TYPE_P (t)) | |
4646 { | |
4647 tree tem; | |
4648 /* Push all TYPE_FIELDS - there can be interleaving interesting | |
4649 and non-interesting things. */ | |
4650 tem = TYPE_FIELDS (t); | |
4651 while (tem) | |
4652 { | |
4653 if (TREE_CODE (tem) == FIELD_DECL) | |
4654 fld_worklist_push (tem, fld); | |
4655 tem = TREE_CHAIN (tem); | |
4656 } | |
4657 } | |
4658 | |
4659 fld_worklist_push (TREE_CHAIN (t), fld); | |
4660 *ws = 0; | |
4661 } | |
4662 | |
4663 fld_worklist_push (TREE_TYPE (t), fld); | |
4664 | |
4665 return NULL_TREE; | |
4666 } | |
4667 | |
4668 | |
4669 /* Find decls and types in T. */ | |
4670 | |
4671 static void | |
4672 find_decls_types (tree t, struct free_lang_data_d *fld) | |
4673 { | |
4674 while (1) | |
4675 { | |
4676 if (!pointer_set_contains (fld->pset, t)) | |
4677 walk_tree (&t, find_decls_types_r, fld, fld->pset); | |
4678 if (VEC_empty (tree, fld->worklist)) | |
4679 break; | |
4680 t = VEC_pop (tree, fld->worklist); | |
4681 } | |
4682 } | |
4683 | |
4684 /* Translate all the types in LIST with the corresponding runtime | |
4685 types. */ | |
4686 | |
4687 static tree | |
4688 get_eh_types_for_runtime (tree list) | |
4689 { | |
4690 tree head, prev; | |
4691 | |
4692 if (list == NULL_TREE) | |
4693 return NULL_TREE; | |
4694 | |
4695 head = build_tree_list (0, lookup_type_for_runtime (TREE_VALUE (list))); | |
4696 prev = head; | |
4697 list = TREE_CHAIN (list); | |
4698 while (list) | |
4699 { | |
4700 tree n = build_tree_list (0, lookup_type_for_runtime (TREE_VALUE (list))); | |
4701 TREE_CHAIN (prev) = n; | |
4702 prev = TREE_CHAIN (prev); | |
4703 list = TREE_CHAIN (list); | |
4704 } | |
4705 | |
4706 return head; | |
4707 } | |
4708 | |
4709 | |
4710 /* Find decls and types referenced in EH region R and store them in | |
4711 FLD->DECLS and FLD->TYPES. */ | |
4712 | |
4713 static void | |
4714 find_decls_types_in_eh_region (eh_region r, struct free_lang_data_d *fld) | |
4715 { | |
4716 switch (r->type) | |
4717 { | |
4718 case ERT_CLEANUP: | |
4719 break; | |
4720 | |
4721 case ERT_TRY: | |
4722 { | |
4723 eh_catch c; | |
4724 | |
4725 /* The types referenced in each catch must first be changed to the | |
4726 EH types used at runtime. This removes references to FE types | |
4727 in the region. */ | |
4728 for (c = r->u.eh_try.first_catch; c ; c = c->next_catch) | |
4729 { | |
4730 c->type_list = get_eh_types_for_runtime (c->type_list); | |
4731 walk_tree (&c->type_list, find_decls_types_r, fld, fld->pset); | |
4732 } | |
4733 } | |
4734 break; | |
4735 | |
4736 case ERT_ALLOWED_EXCEPTIONS: | |
4737 r->u.allowed.type_list | |
4738 = get_eh_types_for_runtime (r->u.allowed.type_list); | |
4739 walk_tree (&r->u.allowed.type_list, find_decls_types_r, fld, fld->pset); | |
4740 break; | |
4741 | |
4742 case ERT_MUST_NOT_THROW: | |
4743 walk_tree (&r->u.must_not_throw.failure_decl, | |
4744 find_decls_types_r, fld, fld->pset); | |
4745 break; | |
4746 } | |
4747 } | |
4748 | |
4749 | |
4750 /* Find decls and types referenced in cgraph node N and store them in | |
4751 FLD->DECLS and FLD->TYPES. Unlike pass_referenced_vars, this will | |
4752 look for *every* kind of DECL and TYPE node reachable from N, | |
4753 including those embedded inside types and decls (i.e,, TYPE_DECLs, | |
4754 NAMESPACE_DECLs, etc). */ | |
4755 | |
4756 static void | |
4757 find_decls_types_in_node (struct cgraph_node *n, struct free_lang_data_d *fld) | |
4758 { | |
4759 basic_block bb; | |
4760 struct function *fn; | |
4761 tree t; | |
4762 | |
4763 find_decls_types (n->decl, fld); | |
4764 | |
4765 if (!gimple_has_body_p (n->decl)) | |
4766 return; | |
4767 | |
4768 gcc_assert (current_function_decl == NULL_TREE && cfun == NULL); | |
4769 | |
4770 fn = DECL_STRUCT_FUNCTION (n->decl); | |
4771 | |
4772 /* Traverse locals. */ | |
4773 for (t = fn->local_decls; t; t = TREE_CHAIN (t)) | |
4774 find_decls_types (TREE_VALUE (t), fld); | |
4775 | |
4776 /* Traverse EH regions in FN. */ | |
4777 { | |
4778 eh_region r; | |
4779 FOR_ALL_EH_REGION_FN (r, fn) | |
4780 find_decls_types_in_eh_region (r, fld); | |
4781 } | |
4782 | |
4783 /* Traverse every statement in FN. */ | |
4784 FOR_EACH_BB_FN (bb, fn) | |
4785 { | |
4786 gimple_stmt_iterator si; | |
4787 unsigned i; | |
4788 | |
4789 for (si = gsi_start_phis (bb); !gsi_end_p (si); gsi_next (&si)) | |
4790 { | |
4791 gimple phi = gsi_stmt (si); | |
4792 | |
4793 for (i = 0; i < gimple_phi_num_args (phi); i++) | |
4794 { | |
4795 tree *arg_p = gimple_phi_arg_def_ptr (phi, i); | |
4796 find_decls_types (*arg_p, fld); | |
4797 } | |
4798 } | |
4799 | |
4800 for (si = gsi_start_bb (bb); !gsi_end_p (si); gsi_next (&si)) | |
4801 { | |
4802 gimple stmt = gsi_stmt (si); | |
4803 | |
4804 for (i = 0; i < gimple_num_ops (stmt); i++) | |
4805 { | |
4806 tree arg = gimple_op (stmt, i); | |
4807 find_decls_types (arg, fld); | |
4808 } | |
4809 } | |
4810 } | |
4811 } | |
4812 | |
4813 | |
4814 /* Find decls and types referenced in varpool node N and store them in | |
4815 FLD->DECLS and FLD->TYPES. Unlike pass_referenced_vars, this will | |
4816 look for *every* kind of DECL and TYPE node reachable from N, | |
4817 including those embedded inside types and decls (i.e,, TYPE_DECLs, | |
4818 NAMESPACE_DECLs, etc). */ | |
4819 | |
4820 static void | |
4821 find_decls_types_in_var (struct varpool_node *v, struct free_lang_data_d *fld) | |
4822 { | |
4823 find_decls_types (v->decl, fld); | |
4824 } | |
4825 | |
4826 | |
4827 /* Free language specific information for every operand and expression | |
4828 in every node of the call graph. This process operates in three stages: | |
4829 | |
4830 1- Every callgraph node and varpool node is traversed looking for | |
4831 decls and types embedded in them. This is a more exhaustive | |
4832 search than that done by find_referenced_vars, because it will | |
4833 also collect individual fields, decls embedded in types, etc. | |
4834 | |
4835 2- All the decls found are sent to free_lang_data_in_decl. | |
4836 | |
4837 3- All the types found are sent to free_lang_data_in_type. | |
4838 | |
4839 The ordering between decls and types is important because | |
4840 free_lang_data_in_decl sets assembler names, which includes | |
4841 mangling. So types cannot be freed up until assembler names have | |
4842 been set up. */ | |
4843 | |
4844 static void | |
4845 free_lang_data_in_cgraph (void) | |
4846 { | |
4847 struct cgraph_node *n; | |
4848 struct varpool_node *v; | |
4849 struct free_lang_data_d fld; | |
4850 tree t; | |
4851 unsigned i; | |
4852 alias_pair *p; | |
4853 | |
4854 /* Initialize sets and arrays to store referenced decls and types. */ | |
4855 fld.pset = pointer_set_create (); | |
4856 fld.worklist = NULL; | |
4857 fld.decls = VEC_alloc (tree, heap, 100); | |
4858 fld.types = VEC_alloc (tree, heap, 100); | |
4859 | |
4860 /* Find decls and types in the body of every function in the callgraph. */ | |
4861 for (n = cgraph_nodes; n; n = n->next) | |
4862 find_decls_types_in_node (n, &fld); | |
4863 | |
4864 for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); i++) | |
4865 find_decls_types (p->decl, &fld); | |
4866 | |
4867 /* Find decls and types in every varpool symbol. */ | |
4868 for (v = varpool_nodes_queue; v; v = v->next_needed) | |
4869 find_decls_types_in_var (v, &fld); | |
4870 | |
4871 /* Set the assembler name on every decl found. We need to do this | |
4872 now because free_lang_data_in_decl will invalidate data needed | |
4873 for mangling. This breaks mangling on interdependent decls. */ | |
4874 for (i = 0; VEC_iterate (tree, fld.decls, i, t); i++) | |
4875 if (need_assembler_name_p (t)) | |
4876 { | |
4877 /* When setting DECL_ASSEMBLER_NAME, the C++ mangler may emit | |
4878 diagnostics that use input_location to show locus | |
4879 information. The problem here is that, at this point, | |
4880 input_location is generally anchored to the end of the file | |
4881 (since the parser is long gone), so we don't have a good | |
4882 position to pin it to. | |
4883 | |
4884 To alleviate this problem, this uses the location of T's | |
4885 declaration. Examples of this are | |
4886 testsuite/g++.dg/template/cond2.C and | |
4887 testsuite/g++.dg/template/pr35240.C. */ | |
4888 location_t saved_location = input_location; | |
4889 input_location = DECL_SOURCE_LOCATION (t); | |
4890 | |
4891 decl_assembler_name (t); | |
4892 | |
4893 input_location = saved_location; | |
4894 } | |
4895 | |
4896 /* Traverse every decl found freeing its language data. */ | |
4897 for (i = 0; VEC_iterate (tree, fld.decls, i, t); i++) | |
4898 free_lang_data_in_decl (t); | |
4899 | |
4900 /* Traverse every type found freeing its language data. */ | |
4901 for (i = 0; VEC_iterate (tree, fld.types, i, t); i++) | |
4902 free_lang_data_in_type (t); | |
4903 | |
4904 pointer_set_destroy (fld.pset); | |
4905 VEC_free (tree, heap, fld.worklist); | |
4906 VEC_free (tree, heap, fld.decls); | |
4907 VEC_free (tree, heap, fld.types); | |
4908 } | |
4909 | |
4910 | |
4911 /* Free resources that are used by FE but are not needed once they are done. */ | |
4912 | |
4913 static unsigned | |
4914 free_lang_data (void) | |
4915 { | |
4916 unsigned i; | |
4917 | |
4918 /* If we are the LTO frontend we have freed lang-specific data already. */ | |
4919 if (in_lto_p | |
4920 || !flag_generate_lto) | |
4921 return 0; | |
4922 | |
4923 /* Allocate and assign alias sets to the standard integer types | |
4924 while the slots are still in the way the frontends generated them. */ | |
4925 for (i = 0; i < itk_none; ++i) | |
4926 if (integer_types[i]) | |
4927 TYPE_ALIAS_SET (integer_types[i]) = get_alias_set (integer_types[i]); | |
4928 | |
4929 /* Traverse the IL resetting language specific information for | |
4930 operands, expressions, etc. */ | |
4931 free_lang_data_in_cgraph (); | |
4932 | |
4933 /* Create gimple variants for common types. */ | |
4934 ptrdiff_type_node = integer_type_node; | |
4935 fileptr_type_node = ptr_type_node; | |
4936 if (TREE_CODE (boolean_type_node) != BOOLEAN_TYPE | |
4937 || (TYPE_MODE (boolean_type_node) | |
4938 != mode_for_size (BOOL_TYPE_SIZE, MODE_INT, 0)) | |
4939 || TYPE_PRECISION (boolean_type_node) != 1 | |
4940 || !TYPE_UNSIGNED (boolean_type_node)) | |
4941 { | |
4942 boolean_type_node = make_unsigned_type (BOOL_TYPE_SIZE); | |
4943 TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE); | |
4944 TYPE_MAX_VALUE (boolean_type_node) = build_int_cst (boolean_type_node, 1); | |
4945 TYPE_PRECISION (boolean_type_node) = 1; | |
4946 boolean_false_node = TYPE_MIN_VALUE (boolean_type_node); | |
4947 boolean_true_node = TYPE_MAX_VALUE (boolean_type_node); | |
4948 } | |
4949 | |
4950 /* Unify char_type_node with its properly signed variant. */ | |
4951 if (TYPE_UNSIGNED (char_type_node)) | |
4952 unsigned_char_type_node = char_type_node; | |
4953 else | |
4954 signed_char_type_node = char_type_node; | |
4955 | |
4956 /* Reset some langhooks. Do not reset types_compatible_p, it may | |
4957 still be used indirectly via the get_alias_set langhook. */ | |
4958 lang_hooks.callgraph.analyze_expr = NULL; | |
4959 lang_hooks.dwarf_name = lhd_dwarf_name; | |
4960 lang_hooks.decl_printable_name = gimple_decl_printable_name; | |
4961 lang_hooks.set_decl_assembler_name = lhd_set_decl_assembler_name; | |
4962 lang_hooks.fold_obj_type_ref = gimple_fold_obj_type_ref; | |
4963 | |
4964 /* Reset diagnostic machinery. */ | |
4965 diagnostic_starter (global_dc) = default_diagnostic_starter; | |
4966 diagnostic_finalizer (global_dc) = default_diagnostic_finalizer; | |
4967 diagnostic_format_decoder (global_dc) = default_tree_printer; | |
4968 | |
4969 return 0; | |
4970 } | |
4971 | |
4972 | |
4973 struct simple_ipa_opt_pass pass_ipa_free_lang_data = | |
4974 { | |
4975 { | |
4976 SIMPLE_IPA_PASS, | |
4977 "*free_lang_data", /* name */ | |
4978 NULL, /* gate */ | |
4979 free_lang_data, /* execute */ | |
4980 NULL, /* sub */ | |
4981 NULL, /* next */ | |
4982 0, /* static_pass_number */ | |
4983 TV_IPA_FREE_LANG_DATA, /* tv_id */ | |
4984 0, /* properties_required */ | |
4985 0, /* properties_provided */ | |
4986 0, /* properties_destroyed */ | |
4987 0, /* todo_flags_start */ | |
4988 TODO_ggc_collect /* todo_flags_finish */ | |
4989 } | |
4990 }; | |
4991 | |
3795 /* Return nonzero if IDENT is a valid name for attribute ATTR, | 4992 /* Return nonzero if IDENT is a valid name for attribute ATTR, |
3796 or zero if not. | 4993 or zero if not. |
3797 | 4994 |
3798 We try both `text' and `__text__', ATTR may be either one. */ | 4995 We try both `text' and `__text__', ATTR may be either one. */ |
3799 /* ??? It might be a reasonable simplification to require ATTR to be only | 4996 /* ??? It might be a reasonable simplification to require ATTR to be only |
3806 int ident_len; | 5003 int ident_len; |
3807 const char *p; | 5004 const char *p; |
3808 | 5005 |
3809 if (TREE_CODE (ident) != IDENTIFIER_NODE) | 5006 if (TREE_CODE (ident) != IDENTIFIER_NODE) |
3810 return 0; | 5007 return 0; |
3811 | 5008 |
3812 p = IDENTIFIER_POINTER (ident); | 5009 p = IDENTIFIER_POINTER (ident); |
3813 ident_len = IDENTIFIER_LENGTH (ident); | 5010 ident_len = IDENTIFIER_LENGTH (ident); |
3814 | 5011 |
3815 if (ident_len == attr_len | 5012 if (ident_len == attr_len |
3816 && strcmp (attr, p) == 0) | 5013 && strcmp (attr, p) == 0) |
3817 return 1; | 5014 return 1; |
3818 | 5015 |
3819 /* If ATTR is `__text__', IDENT must be `text'; and vice versa. */ | 5016 /* If ATTR is `__text__', IDENT must be `text'; and vice versa. */ |
3991 /* What we need to do here is remove from `old' dllimport if it doesn't | 5188 /* What we need to do here is remove from `old' dllimport if it doesn't |
3992 appear in `new'. dllimport behaves like extern: if a declaration is | 5189 appear in `new'. dllimport behaves like extern: if a declaration is |
3993 marked dllimport and a definition appears later, then the object | 5190 marked dllimport and a definition appears later, then the object |
3994 is not dllimport'd. We also remove a `new' dllimport if the old list | 5191 is not dllimport'd. We also remove a `new' dllimport if the old list |
3995 contains dllexport: dllexport always overrides dllimport, regardless | 5192 contains dllexport: dllexport always overrides dllimport, regardless |
3996 of the order of declaration. */ | 5193 of the order of declaration. */ |
3997 if (!VAR_OR_FUNCTION_DECL_P (new_tree)) | 5194 if (!VAR_OR_FUNCTION_DECL_P (new_tree)) |
3998 delete_dllimport_p = 0; | 5195 delete_dllimport_p = 0; |
3999 else if (DECL_DLLIMPORT_P (new_tree) | 5196 else if (DECL_DLLIMPORT_P (new_tree) |
4000 && lookup_attribute ("dllexport", DECL_ATTRIBUTES (old))) | 5197 && lookup_attribute ("dllexport", DECL_ATTRIBUTES (old))) |
4001 { | 5198 { |
4002 DECL_DLLIMPORT_P (new_tree) = 0; | 5199 DECL_DLLIMPORT_P (new_tree) = 0; |
4003 warning (OPT_Wattributes, "%q+D already declared with dllexport attribute: " | 5200 warning (OPT_Wattributes, "%q+D already declared with dllexport attribute: " |
4004 "dllimport ignored", new_tree); | 5201 "dllimport ignored", new_tree); |
4005 } | 5202 } |
4006 else if (DECL_DLLIMPORT_P (old) && !DECL_DLLIMPORT_P (new_tree)) | 5203 else if (DECL_DLLIMPORT_P (old) && !DECL_DLLIMPORT_P (new_tree)) |
4022 if (TREE_CODE (old) == VAR_DECL && TREE_ADDRESSABLE (old)) | 5219 if (TREE_CODE (old) == VAR_DECL && TREE_ADDRESSABLE (old)) |
4023 DECL_DLLIMPORT_P (new_tree) = 1; | 5220 DECL_DLLIMPORT_P (new_tree) = 1; |
4024 } | 5221 } |
4025 | 5222 |
4026 /* Let an inline definition silently override the external reference, | 5223 /* Let an inline definition silently override the external reference, |
4027 but otherwise warn about attribute inconsistency. */ | 5224 but otherwise warn about attribute inconsistency. */ |
4028 else if (TREE_CODE (new_tree) == VAR_DECL | 5225 else if (TREE_CODE (new_tree) == VAR_DECL |
4029 || !DECL_DECLARED_INLINE_P (new_tree)) | 5226 || !DECL_DECLARED_INLINE_P (new_tree)) |
4030 warning (OPT_Wattributes, "%q+D redeclared without dllimport attribute: " | 5227 warning (OPT_Wattributes, "%q+D redeclared without dllimport attribute: " |
4031 "previous dllimport ignored", new_tree); | 5228 "previous dllimport ignored", new_tree); |
4032 } | 5229 } |
4033 else | 5230 else |
4034 delete_dllimport_p = 0; | 5231 delete_dllimport_p = 0; |
4035 | 5232 |
4036 a = merge_attributes (DECL_ATTRIBUTES (old), DECL_ATTRIBUTES (new_tree)); | 5233 a = merge_attributes (DECL_ATTRIBUTES (old), DECL_ATTRIBUTES (new_tree)); |
4037 | 5234 |
4038 if (delete_dllimport_p) | 5235 if (delete_dllimport_p) |
4039 { | 5236 { |
4040 tree prev, t; | 5237 tree prev, t; |
4041 const size_t attr_len = strlen ("dllimport"); | 5238 const size_t attr_len = strlen ("dllimport"); |
4042 | 5239 |
4043 /* Scan the list for dllimport and delete it. */ | 5240 /* Scan the list for dllimport and delete it. */ |
4044 for (prev = NULL_TREE, t = a; t; prev = t, t = TREE_CHAIN (t)) | 5241 for (prev = NULL_TREE, t = a; t; prev = t, t = TREE_CHAIN (t)) |
4045 { | 5242 { |
4046 if (is_attribute_with_length_p ("dllimport", attr_len, | 5243 if (is_attribute_with_length_p ("dllimport", attr_len, |
4047 TREE_PURPOSE (t))) | 5244 TREE_PURPOSE (t))) |
4064 tree | 5261 tree |
4065 handle_dll_attribute (tree * pnode, tree name, tree args, int flags, | 5262 handle_dll_attribute (tree * pnode, tree name, tree args, int flags, |
4066 bool *no_add_attrs) | 5263 bool *no_add_attrs) |
4067 { | 5264 { |
4068 tree node = *pnode; | 5265 tree node = *pnode; |
5266 bool is_dllimport; | |
4069 | 5267 |
4070 /* These attributes may apply to structure and union types being created, | 5268 /* These attributes may apply to structure and union types being created, |
4071 but otherwise should pass to the declaration involved. */ | 5269 but otherwise should pass to the declaration involved. */ |
4072 if (!DECL_P (node)) | 5270 if (!DECL_P (node)) |
4073 { | 5271 { |
4084 if (!node) | 5282 if (!node) |
4085 return NULL_TREE; | 5283 return NULL_TREE; |
4086 } | 5284 } |
4087 else | 5285 else |
4088 { | 5286 { |
4089 warning (OPT_Wattributes, "%qs attribute ignored", | 5287 warning (OPT_Wattributes, "%qE attribute ignored", |
4090 IDENTIFIER_POINTER (name)); | 5288 name); |
4091 *no_add_attrs = true; | 5289 *no_add_attrs = true; |
4092 return NULL_TREE; | 5290 return NULL_TREE; |
4093 } | 5291 } |
4094 } | 5292 } |
4095 | 5293 |
4096 if (TREE_CODE (node) != FUNCTION_DECL | 5294 if (TREE_CODE (node) != FUNCTION_DECL |
4097 && TREE_CODE (node) != VAR_DECL | 5295 && TREE_CODE (node) != VAR_DECL |
4098 && TREE_CODE (node) != TYPE_DECL) | 5296 && TREE_CODE (node) != TYPE_DECL) |
4099 { | 5297 { |
4100 *no_add_attrs = true; | 5298 *no_add_attrs = true; |
4101 warning (OPT_Wattributes, "%qs attribute ignored", | 5299 warning (OPT_Wattributes, "%qE attribute ignored", |
4102 IDENTIFIER_POINTER (name)); | 5300 name); |
4103 return NULL_TREE; | 5301 return NULL_TREE; |
4104 } | 5302 } |
4105 | 5303 |
4106 if (TREE_CODE (node) == TYPE_DECL | 5304 if (TREE_CODE (node) == TYPE_DECL |
4107 && TREE_CODE (TREE_TYPE (node)) != RECORD_TYPE | 5305 && TREE_CODE (TREE_TYPE (node)) != RECORD_TYPE |
4108 && TREE_CODE (TREE_TYPE (node)) != UNION_TYPE) | 5306 && TREE_CODE (TREE_TYPE (node)) != UNION_TYPE) |
4109 { | 5307 { |
4110 *no_add_attrs = true; | 5308 *no_add_attrs = true; |
4111 warning (OPT_Wattributes, "%qs attribute ignored", | 5309 warning (OPT_Wattributes, "%qE attribute ignored", |
4112 IDENTIFIER_POINTER (name)); | 5310 name); |
4113 return NULL_TREE; | 5311 return NULL_TREE; |
4114 } | 5312 } |
5313 | |
5314 is_dllimport = is_attribute_p ("dllimport", name); | |
4115 | 5315 |
4116 /* Report error on dllimport ambiguities seen now before they cause | 5316 /* Report error on dllimport ambiguities seen now before they cause |
4117 any damage. */ | 5317 any damage. */ |
4118 else if (is_attribute_p ("dllimport", name)) | 5318 if (is_dllimport) |
4119 { | 5319 { |
4120 /* Honor any target-specific overrides. */ | 5320 /* Honor any target-specific overrides. */ |
4121 if (!targetm.valid_dllimport_attribute_p (node)) | 5321 if (!targetm.valid_dllimport_attribute_p (node)) |
4122 *no_add_attrs = true; | 5322 *no_add_attrs = true; |
4123 | 5323 |
4124 else if (TREE_CODE (node) == FUNCTION_DECL | 5324 else if (TREE_CODE (node) == FUNCTION_DECL |
4125 && DECL_DECLARED_INLINE_P (node)) | 5325 && DECL_DECLARED_INLINE_P (node)) |
4126 { | 5326 { |
4127 warning (OPT_Wattributes, "inline function %q+D declared as " | 5327 warning (OPT_Wattributes, "inline function %q+D declared as " |
4128 " dllimport: attribute ignored", node); | 5328 " dllimport: attribute ignored", node); |
4129 *no_add_attrs = true; | 5329 *no_add_attrs = true; |
4130 } | 5330 } |
4131 /* Like MS, treat definition of dllimported variables and | 5331 /* Like MS, treat definition of dllimported variables and |
4132 non-inlined functions on declaration as syntax errors. */ | 5332 non-inlined functions on declaration as syntax errors. */ |
4133 else if (TREE_CODE (node) == FUNCTION_DECL && DECL_INITIAL (node)) | 5333 else if (TREE_CODE (node) == FUNCTION_DECL && DECL_INITIAL (node)) |
4155 } | 5355 } |
4156 | 5356 |
4157 if (*no_add_attrs == false) | 5357 if (*no_add_attrs == false) |
4158 DECL_DLLIMPORT_P (node) = 1; | 5358 DECL_DLLIMPORT_P (node) = 1; |
4159 } | 5359 } |
5360 else if (TREE_CODE (node) == FUNCTION_DECL | |
5361 && DECL_DECLARED_INLINE_P (node)) | |
5362 /* An exported function, even if inline, must be emitted. */ | |
5363 DECL_EXTERNAL (node) = 0; | |
4160 | 5364 |
4161 /* Report error if symbol is not accessible at global scope. */ | 5365 /* Report error if symbol is not accessible at global scope. */ |
4162 if (!TREE_PUBLIC (node) | 5366 if (!TREE_PUBLIC (node) |
4163 && (TREE_CODE (node) == VAR_DECL | 5367 && (TREE_CODE (node) == VAR_DECL |
4164 || TREE_CODE (node) == FUNCTION_DECL)) | 5368 || TREE_CODE (node) == FUNCTION_DECL)) |
4165 { | 5369 { |
4166 error ("external linkage required for symbol %q+D because of " | 5370 error ("external linkage required for symbol %q+D because of " |
4167 "%qs attribute", node, IDENTIFIER_POINTER (name)); | 5371 "%qE attribute", node, name); |
4168 *no_add_attrs = true; | 5372 *no_add_attrs = true; |
4169 } | 5373 } |
4170 | 5374 |
4171 /* A dllexport'd entity must have default visibility so that other | 5375 /* A dllexport'd entity must have default visibility so that other |
4172 program units (shared libraries or the main executable) can see | 5376 program units (shared libraries or the main executable) can see |
4175 unit can be resolved by the dynamic linker. */ | 5379 unit can be resolved by the dynamic linker. */ |
4176 if (!*no_add_attrs) | 5380 if (!*no_add_attrs) |
4177 { | 5381 { |
4178 if (DECL_VISIBILITY_SPECIFIED (node) | 5382 if (DECL_VISIBILITY_SPECIFIED (node) |
4179 && DECL_VISIBILITY (node) != VISIBILITY_DEFAULT) | 5383 && DECL_VISIBILITY (node) != VISIBILITY_DEFAULT) |
4180 error ("%qs implies default visibility, but %qD has already " | 5384 error ("%qE implies default visibility, but %qD has already " |
4181 "been declared with a different visibility", | 5385 "been declared with a different visibility", |
4182 IDENTIFIER_POINTER (name), node); | 5386 name, node); |
4183 DECL_VISIBILITY (node) = VISIBILITY_DEFAULT; | 5387 DECL_VISIBILITY (node) = VISIBILITY_DEFAULT; |
4184 DECL_VISIBILITY_SPECIFIED (node) = 1; | 5388 DECL_VISIBILITY_SPECIFIED (node) = 1; |
4185 } | 5389 } |
4186 | 5390 |
4187 return NULL_TREE; | 5391 return NULL_TREE; |
4196 set_type_quals (tree type, int type_quals) | 5400 set_type_quals (tree type, int type_quals) |
4197 { | 5401 { |
4198 TYPE_READONLY (type) = (type_quals & TYPE_QUAL_CONST) != 0; | 5402 TYPE_READONLY (type) = (type_quals & TYPE_QUAL_CONST) != 0; |
4199 TYPE_VOLATILE (type) = (type_quals & TYPE_QUAL_VOLATILE) != 0; | 5403 TYPE_VOLATILE (type) = (type_quals & TYPE_QUAL_VOLATILE) != 0; |
4200 TYPE_RESTRICT (type) = (type_quals & TYPE_QUAL_RESTRICT) != 0; | 5404 TYPE_RESTRICT (type) = (type_quals & TYPE_QUAL_RESTRICT) != 0; |
5405 TYPE_ADDR_SPACE (type) = DECODE_QUAL_ADDR_SPACE (type_quals); | |
4201 } | 5406 } |
4202 | 5407 |
4203 /* Returns true iff CAND is equivalent to BASE with TYPE_QUALS. */ | 5408 /* Returns true iff CAND is equivalent to BASE with TYPE_QUALS. */ |
4204 | 5409 |
4205 bool | 5410 bool |
4261 TYPE_CANONICAL (t) = build_qualified_type (TYPE_CANONICAL (type), | 5466 TYPE_CANONICAL (t) = build_qualified_type (TYPE_CANONICAL (type), |
4262 type_quals); | 5467 type_quals); |
4263 else | 5468 else |
4264 /* T is its own canonical type. */ | 5469 /* T is its own canonical type. */ |
4265 TYPE_CANONICAL (t) = t; | 5470 TYPE_CANONICAL (t) = t; |
4266 | 5471 |
4267 } | 5472 } |
4268 | 5473 |
4269 return t; | 5474 return t; |
4270 } | 5475 } |
4271 | 5476 |
4276 | 5481 |
4277 tree | 5482 tree |
4278 build_distinct_type_copy (tree type) | 5483 build_distinct_type_copy (tree type) |
4279 { | 5484 { |
4280 tree t = copy_node (type); | 5485 tree t = copy_node (type); |
4281 | 5486 |
4282 TYPE_POINTER_TO (t) = 0; | 5487 TYPE_POINTER_TO (t) = 0; |
4283 TYPE_REFERENCE_TO (t) = 0; | 5488 TYPE_REFERENCE_TO (t) = 0; |
4284 | 5489 |
4285 /* Set the canonical type either to a new equivalence class, or | 5490 /* Set the canonical type either to a new equivalence class, or |
4286 propagate the need for structural equality checks. */ | 5491 propagate the need for structural equality checks. */ |
4314 t = build_distinct_type_copy (type); | 5519 t = build_distinct_type_copy (type); |
4315 | 5520 |
4316 /* Since we're building a variant, assume that it is a non-semantic | 5521 /* Since we're building a variant, assume that it is a non-semantic |
4317 variant. This also propagates TYPE_STRUCTURAL_EQUALITY_P. */ | 5522 variant. This also propagates TYPE_STRUCTURAL_EQUALITY_P. */ |
4318 TYPE_CANONICAL (t) = TYPE_CANONICAL (type); | 5523 TYPE_CANONICAL (t) = TYPE_CANONICAL (type); |
4319 | 5524 |
4320 /* Add the new type to the chain of variants of TYPE. */ | 5525 /* Add the new type to the chain of variants of TYPE. */ |
4321 TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m); | 5526 TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m); |
4322 TYPE_NEXT_VARIANT (m) = t; | 5527 TYPE_NEXT_VARIANT (m) = t; |
4323 TYPE_MAIN_VARIANT (t) = m; | 5528 TYPE_MAIN_VARIANT (t) = m; |
4324 | 5529 |
4421 struct tree_priority_map *h; | 5626 struct tree_priority_map *h; |
4422 | 5627 |
4423 gcc_assert (VAR_OR_FUNCTION_DECL_P (decl)); | 5628 gcc_assert (VAR_OR_FUNCTION_DECL_P (decl)); |
4424 h = decl_priority_info (decl); | 5629 h = decl_priority_info (decl); |
4425 h->init = priority; | 5630 h->init = priority; |
4426 } | 5631 } |
4427 | 5632 |
4428 /* Set the finalization priority for DECL to PRIORITY. */ | 5633 /* Set the finalization priority for DECL to PRIORITY. */ |
4429 | 5634 |
4430 void | 5635 void |
4431 decl_fini_priority_insert (tree decl, priority_type priority) | 5636 decl_fini_priority_insert (tree decl, priority_type priority) |
4433 struct tree_priority_map *h; | 5638 struct tree_priority_map *h; |
4434 | 5639 |
4435 gcc_assert (TREE_CODE (decl) == FUNCTION_DECL); | 5640 gcc_assert (TREE_CODE (decl) == FUNCTION_DECL); |
4436 h = decl_priority_info (decl); | 5641 h = decl_priority_info (decl); |
4437 h->fini = priority; | 5642 h->fini = priority; |
4438 } | |
4439 | |
4440 /* Look up a restrict qualified base decl for FROM. */ | |
4441 | |
4442 tree | |
4443 decl_restrict_base_lookup (tree from) | |
4444 { | |
4445 struct tree_map *h; | |
4446 struct tree_map in; | |
4447 | |
4448 in.base.from = from; | |
4449 h = (struct tree_map *) htab_find_with_hash (restrict_base_for_decl, &in, | |
4450 htab_hash_pointer (from)); | |
4451 return h ? h->to : NULL_TREE; | |
4452 } | |
4453 | |
4454 /* Record the restrict qualified base TO for FROM. */ | |
4455 | |
4456 void | |
4457 decl_restrict_base_insert (tree from, tree to) | |
4458 { | |
4459 struct tree_map *h; | |
4460 void **loc; | |
4461 | |
4462 h = GGC_NEW (struct tree_map); | |
4463 h->hash = htab_hash_pointer (from); | |
4464 h->base.from = from; | |
4465 h->to = to; | |
4466 loc = htab_find_slot_with_hash (restrict_base_for_decl, h, h->hash, INSERT); | |
4467 *(struct tree_map **) loc = h; | |
4468 } | 5643 } |
4469 | 5644 |
4470 /* Print out the statistics for the DECL_DEBUG_EXPR hash table. */ | 5645 /* Print out the statistics for the DECL_DEBUG_EXPR hash table. */ |
4471 | 5646 |
4472 static void | 5647 static void |
4487 (long) htab_size (value_expr_for_decl), | 5662 (long) htab_size (value_expr_for_decl), |
4488 (long) htab_elements (value_expr_for_decl), | 5663 (long) htab_elements (value_expr_for_decl), |
4489 htab_collisions (value_expr_for_decl)); | 5664 htab_collisions (value_expr_for_decl)); |
4490 } | 5665 } |
4491 | 5666 |
4492 /* Print out statistics for the RESTRICT_BASE_FOR_DECL hash table, but | |
4493 don't print anything if the table is empty. */ | |
4494 | |
4495 static void | |
4496 print_restrict_base_statistics (void) | |
4497 { | |
4498 if (htab_elements (restrict_base_for_decl) != 0) | |
4499 fprintf (stderr, | |
4500 "RESTRICT_BASE hash: size %ld, %ld elements, %f collisions\n", | |
4501 (long) htab_size (restrict_base_for_decl), | |
4502 (long) htab_elements (restrict_base_for_decl), | |
4503 htab_collisions (restrict_base_for_decl)); | |
4504 } | |
4505 | |
4506 /* Lookup a debug expression for FROM, and return it if we find one. */ | 5667 /* Lookup a debug expression for FROM, and return it if we find one. */ |
4507 | 5668 |
4508 tree | 5669 tree |
4509 decl_debug_expr_lookup (tree from) | 5670 decl_debug_expr_lookup (tree from) |
4510 { | 5671 { |
4511 struct tree_map *h, in; | 5672 struct tree_map *h, in; |
4512 in.base.from = from; | 5673 in.base.from = from; |
4513 | 5674 |
4530 h->hash = htab_hash_pointer (from); | 5691 h->hash = htab_hash_pointer (from); |
4531 h->base.from = from; | 5692 h->base.from = from; |
4532 h->to = to; | 5693 h->to = to; |
4533 loc = htab_find_slot_with_hash (debug_expr_for_decl, h, h->hash, INSERT); | 5694 loc = htab_find_slot_with_hash (debug_expr_for_decl, h, h->hash, INSERT); |
4534 *(struct tree_map **) loc = h; | 5695 *(struct tree_map **) loc = h; |
4535 } | 5696 } |
4536 | 5697 |
4537 /* Lookup a value expression for FROM, and return it if we find one. */ | 5698 /* Lookup a value expression for FROM, and return it if we find one. */ |
4538 | 5699 |
4539 tree | 5700 tree |
4540 decl_value_expr_lookup (tree from) | 5701 decl_value_expr_lookup (tree from) |
4541 { | 5702 { |
4542 struct tree_map *h, in; | 5703 struct tree_map *h, in; |
4543 in.base.from = from; | 5704 in.base.from = from; |
4544 | 5705 |
4601 || TREE_TYPE (a->type) != TREE_TYPE (b->type) | 5762 || TREE_TYPE (a->type) != TREE_TYPE (b->type) |
4602 || !attribute_list_equal (TYPE_ATTRIBUTES (a->type), | 5763 || !attribute_list_equal (TYPE_ATTRIBUTES (a->type), |
4603 TYPE_ATTRIBUTES (b->type)) | 5764 TYPE_ATTRIBUTES (b->type)) |
4604 || TYPE_ALIGN (a->type) != TYPE_ALIGN (b->type) | 5765 || TYPE_ALIGN (a->type) != TYPE_ALIGN (b->type) |
4605 || TYPE_MODE (a->type) != TYPE_MODE (b->type) | 5766 || TYPE_MODE (a->type) != TYPE_MODE (b->type) |
4606 || (TREE_CODE (a->type) != COMPLEX_TYPE | 5767 || (TREE_CODE (a->type) != COMPLEX_TYPE |
4607 && TYPE_NAME (a->type) != TYPE_NAME (b->type))) | 5768 && TYPE_NAME (a->type) != TYPE_NAME (b->type))) |
4608 return 0; | 5769 return 0; |
4609 | 5770 |
4610 switch (TREE_CODE (a->type)) | 5771 switch (TREE_CODE (a->type)) |
4611 { | 5772 { |
4995 be represented in a single unsigned HOST_WIDE_INT. */ | 6156 be represented in a single unsigned HOST_WIDE_INT. */ |
4996 | 6157 |
4997 int | 6158 int |
4998 host_integerp (const_tree t, int pos) | 6159 host_integerp (const_tree t, int pos) |
4999 { | 6160 { |
6161 if (t == NULL_TREE) | |
6162 return 0; | |
6163 | |
5000 return (TREE_CODE (t) == INTEGER_CST | 6164 return (TREE_CODE (t) == INTEGER_CST |
5001 && ((TREE_INT_CST_HIGH (t) == 0 | 6165 && ((TREE_INT_CST_HIGH (t) == 0 |
5002 && (HOST_WIDE_INT) TREE_INT_CST_LOW (t) >= 0) | 6166 && (HOST_WIDE_INT) TREE_INT_CST_LOW (t) >= 0) |
5003 || (! pos && TREE_INT_CST_HIGH (t) == -1 | 6167 || (! pos && TREE_INT_CST_HIGH (t) == -1 |
5004 && (HOST_WIDE_INT) TREE_INT_CST_LOW (t) < 0 | 6168 && (HOST_WIDE_INT) TREE_INT_CST_LOW (t) < 0 |
5351 int i; | 6515 int i; |
5352 enum tree_code code; | 6516 enum tree_code code; |
5353 char tclass; | 6517 char tclass; |
5354 | 6518 |
5355 if (t == NULL_TREE) | 6519 if (t == NULL_TREE) |
5356 return iterative_hash_pointer (t, val); | 6520 return iterative_hash_hashval_t (0, val); |
5357 | 6521 |
5358 code = TREE_CODE (t); | 6522 code = TREE_CODE (t); |
5359 | 6523 |
5360 switch (code) | 6524 switch (code) |
5361 { | 6525 { |
5385 case VECTOR_CST: | 6549 case VECTOR_CST: |
5386 return iterative_hash_expr (TREE_VECTOR_CST_ELTS (t), val); | 6550 return iterative_hash_expr (TREE_VECTOR_CST_ELTS (t), val); |
5387 | 6551 |
5388 case SSA_NAME: | 6552 case SSA_NAME: |
5389 /* we can just compare by pointer. */ | 6553 /* we can just compare by pointer. */ |
5390 return iterative_hash_pointer (t, val); | 6554 return iterative_hash_host_wide_int (SSA_NAME_VERSION (t), val); |
5391 | 6555 |
5392 case TREE_LIST: | 6556 case TREE_LIST: |
5393 /* A list of expressions, for a CALL_EXPR or as the elements of a | 6557 /* A list of expressions, for a CALL_EXPR or as the elements of a |
5394 VECTOR_CST. */ | 6558 VECTOR_CST. */ |
5395 for (; t; t = TREE_CHAIN (t)) | 6559 for (; t; t = TREE_CHAIN (t)) |
5405 val = iterative_hash_expr (value, val); | 6569 val = iterative_hash_expr (value, val); |
5406 } | 6570 } |
5407 return val; | 6571 return val; |
5408 } | 6572 } |
5409 case FUNCTION_DECL: | 6573 case FUNCTION_DECL: |
5410 /* When referring to a built-in FUNCTION_DECL, use the | 6574 /* When referring to a built-in FUNCTION_DECL, use the __builtin__ form. |
5411 __builtin__ form. Otherwise nodes that compare equal | 6575 Otherwise nodes that compare equal according to operand_equal_p might |
5412 according to operand_equal_p might get different | 6576 get different hash codes. However, don't do this for machine specific |
5413 hash codes. */ | 6577 or front end builtins, since the function code is overloaded in those |
5414 if (DECL_BUILT_IN (t)) | 6578 cases. */ |
6579 if (DECL_BUILT_IN_CLASS (t) == BUILT_IN_NORMAL | |
6580 && built_in_decls[DECL_FUNCTION_CODE (t)]) | |
5415 { | 6581 { |
5416 val = iterative_hash_pointer (built_in_decls[DECL_FUNCTION_CODE (t)], | 6582 t = built_in_decls[DECL_FUNCTION_CODE (t)]; |
5417 val); | 6583 code = TREE_CODE (t); |
5418 return val; | |
5419 } | 6584 } |
5420 /* else FALL THROUGH */ | 6585 /* FALL THROUGH */ |
5421 default: | 6586 default: |
5422 tclass = TREE_CODE_CLASS (code); | 6587 tclass = TREE_CODE_CLASS (code); |
5423 | 6588 |
5424 if (tclass == tcc_declaration) | 6589 if (tclass == tcc_declaration) |
5425 { | 6590 { |
5427 val = iterative_hash_host_wide_int (DECL_UID (t), val); | 6592 val = iterative_hash_host_wide_int (DECL_UID (t), val); |
5428 } | 6593 } |
5429 else | 6594 else |
5430 { | 6595 { |
5431 gcc_assert (IS_EXPR_CODE_CLASS (tclass)); | 6596 gcc_assert (IS_EXPR_CODE_CLASS (tclass)); |
5432 | 6597 |
5433 val = iterative_hash_object (code, val); | 6598 val = iterative_hash_object (code, val); |
5434 | 6599 |
5435 /* Don't hash the type, that can lead to having nodes which | 6600 /* Don't hash the type, that can lead to having nodes which |
5436 compare equal according to operand_equal_p, but which | 6601 compare equal according to operand_equal_p, but which |
5437 have different hash codes. */ | 6602 have different hash codes. */ |
5557 /* By default build pointers in ptr_mode. */ | 6722 /* By default build pointers in ptr_mode. */ |
5558 | 6723 |
5559 tree | 6724 tree |
5560 build_pointer_type (tree to_type) | 6725 build_pointer_type (tree to_type) |
5561 { | 6726 { |
5562 return build_pointer_type_for_mode (to_type, ptr_mode, false); | 6727 addr_space_t as = to_type == error_mark_node? ADDR_SPACE_GENERIC |
6728 : TYPE_ADDR_SPACE (to_type); | |
6729 enum machine_mode pointer_mode = targetm.addr_space.pointer_mode (as); | |
6730 return build_pointer_type_for_mode (to_type, pointer_mode, false); | |
5563 } | 6731 } |
5564 | 6732 |
5565 /* Same as build_pointer_type_for_mode, but for REFERENCE_TYPE. */ | 6733 /* Same as build_pointer_type_for_mode, but for REFERENCE_TYPE. */ |
5566 | 6734 |
5567 tree | 6735 tree |
5605 TYPE_REFERENCE_TO (to_type) = t; | 6773 TYPE_REFERENCE_TO (to_type) = t; |
5606 | 6774 |
5607 if (TYPE_STRUCTURAL_EQUALITY_P (to_type)) | 6775 if (TYPE_STRUCTURAL_EQUALITY_P (to_type)) |
5608 SET_TYPE_STRUCTURAL_EQUALITY (t); | 6776 SET_TYPE_STRUCTURAL_EQUALITY (t); |
5609 else if (TYPE_CANONICAL (to_type) != to_type) | 6777 else if (TYPE_CANONICAL (to_type) != to_type) |
5610 TYPE_CANONICAL (t) | 6778 TYPE_CANONICAL (t) |
5611 = build_reference_type_for_mode (TYPE_CANONICAL (to_type), | 6779 = build_reference_type_for_mode (TYPE_CANONICAL (to_type), |
5612 mode, can_alias_all); | 6780 mode, can_alias_all); |
5613 | 6781 |
5614 layout_type (t); | 6782 layout_type (t); |
5615 | 6783 |
5621 in ptr_mode. */ | 6789 in ptr_mode. */ |
5622 | 6790 |
5623 tree | 6791 tree |
5624 build_reference_type (tree to_type) | 6792 build_reference_type (tree to_type) |
5625 { | 6793 { |
5626 return build_reference_type_for_mode (to_type, ptr_mode, false); | 6794 addr_space_t as = to_type == error_mark_node? ADDR_SPACE_GENERIC |
6795 : TYPE_ADDR_SPACE (to_type); | |
6796 enum machine_mode pointer_mode = targetm.addr_space.pointer_mode (as); | |
6797 return build_reference_type_for_mode (to_type, pointer_mode, false); | |
5627 } | 6798 } |
5628 | 6799 |
5629 /* Build a type that is compatible with t but has no cv quals anywhere | 6800 /* Build a type that is compatible with t but has no cv quals anywhere |
5630 in its type, thus | 6801 in its type, thus |
5631 | 6802 |
5736 itype); | 6907 itype); |
5737 else | 6908 else |
5738 return itype; | 6909 return itype; |
5739 } | 6910 } |
5740 | 6911 |
6912 /* Return true if the debug information for TYPE, a subtype, should be emitted | |
6913 as a subrange type. If so, set LOWVAL to the low bound and HIGHVAL to the | |
6914 high bound, respectively. Sometimes doing so unnecessarily obfuscates the | |
6915 debug info and doesn't reflect the source code. */ | |
6916 | |
6917 bool | |
6918 subrange_type_for_debug_p (const_tree type, tree *lowval, tree *highval) | |
6919 { | |
6920 tree base_type = TREE_TYPE (type), low, high; | |
6921 | |
6922 /* Subrange types have a base type which is an integral type. */ | |
6923 if (!INTEGRAL_TYPE_P (base_type)) | |
6924 return false; | |
6925 | |
6926 /* Get the real bounds of the subtype. */ | |
6927 if (lang_hooks.types.get_subrange_bounds) | |
6928 lang_hooks.types.get_subrange_bounds (type, &low, &high); | |
6929 else | |
6930 { | |
6931 low = TYPE_MIN_VALUE (type); | |
6932 high = TYPE_MAX_VALUE (type); | |
6933 } | |
6934 | |
6935 /* If the type and its base type have the same representation and the same | |
6936 name, then the type is not a subrange but a copy of the base type. */ | |
6937 if ((TREE_CODE (base_type) == INTEGER_TYPE | |
6938 || TREE_CODE (base_type) == BOOLEAN_TYPE) | |
6939 && int_size_in_bytes (type) == int_size_in_bytes (base_type) | |
6940 && tree_int_cst_equal (low, TYPE_MIN_VALUE (base_type)) | |
6941 && tree_int_cst_equal (high, TYPE_MAX_VALUE (base_type))) | |
6942 { | |
6943 tree type_name = TYPE_NAME (type); | |
6944 tree base_type_name = TYPE_NAME (base_type); | |
6945 | |
6946 if (type_name && TREE_CODE (type_name) == TYPE_DECL) | |
6947 type_name = DECL_NAME (type_name); | |
6948 | |
6949 if (base_type_name && TREE_CODE (base_type_name) == TYPE_DECL) | |
6950 base_type_name = DECL_NAME (base_type_name); | |
6951 | |
6952 if (type_name == base_type_name) | |
6953 return false; | |
6954 } | |
6955 | |
6956 if (lowval) | |
6957 *lowval = low; | |
6958 if (highval) | |
6959 *highval = high; | |
6960 return true; | |
6961 } | |
6962 | |
5741 /* Just like build_index_type, but takes lowval and highval instead | 6963 /* Just like build_index_type, but takes lowval and highval instead |
5742 of just highval (maxval). */ | 6964 of just highval (maxval). */ |
5743 | 6965 |
5744 tree | 6966 tree |
5745 build_index_2_type (tree lowval, tree highval) | 6967 build_index_2_type (tree lowval, tree highval) |
5764 } | 6986 } |
5765 | 6987 |
5766 t = make_node (ARRAY_TYPE); | 6988 t = make_node (ARRAY_TYPE); |
5767 TREE_TYPE (t) = elt_type; | 6989 TREE_TYPE (t) = elt_type; |
5768 TYPE_DOMAIN (t) = index_type; | 6990 TYPE_DOMAIN (t) = index_type; |
5769 | 6991 TYPE_ADDR_SPACE (t) = TYPE_ADDR_SPACE (elt_type); |
5770 if (index_type == 0) | 6992 layout_type (t); |
5771 { | 6993 |
5772 tree save = t; | 6994 /* If the element type is incomplete at this point we get marked for |
5773 hashcode = iterative_hash_object (TYPE_HASH (elt_type), hashcode); | 6995 structural equality. Do not record these types in the canonical |
5774 t = type_hash_canon (hashcode, t); | 6996 type hashtable. */ |
5775 if (save == t) | 6997 if (TYPE_STRUCTURAL_EQUALITY_P (t)) |
5776 layout_type (t); | 6998 return t; |
5777 | |
5778 if (TYPE_CANONICAL (t) == t) | |
5779 { | |
5780 if (TYPE_STRUCTURAL_EQUALITY_P (elt_type)) | |
5781 SET_TYPE_STRUCTURAL_EQUALITY (t); | |
5782 else if (TYPE_CANONICAL (elt_type) != elt_type) | |
5783 TYPE_CANONICAL (t) | |
5784 = build_array_type (TYPE_CANONICAL (elt_type), index_type); | |
5785 } | |
5786 | |
5787 return t; | |
5788 } | |
5789 | 6999 |
5790 hashcode = iterative_hash_object (TYPE_HASH (elt_type), hashcode); | 7000 hashcode = iterative_hash_object (TYPE_HASH (elt_type), hashcode); |
5791 hashcode = iterative_hash_object (TYPE_HASH (index_type), hashcode); | 7001 if (index_type) |
7002 hashcode = iterative_hash_object (TYPE_HASH (index_type), hashcode); | |
5792 t = type_hash_canon (hashcode, t); | 7003 t = type_hash_canon (hashcode, t); |
5793 | 7004 |
5794 if (!COMPLETE_TYPE_P (t)) | |
5795 layout_type (t); | |
5796 | |
5797 if (TYPE_CANONICAL (t) == t) | 7005 if (TYPE_CANONICAL (t) == t) |
5798 { | 7006 { |
5799 if (TYPE_STRUCTURAL_EQUALITY_P (elt_type) | 7007 if (TYPE_STRUCTURAL_EQUALITY_P (elt_type) |
5800 || TYPE_STRUCTURAL_EQUALITY_P (index_type)) | 7008 || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type))) |
5801 SET_TYPE_STRUCTURAL_EQUALITY (t); | 7009 SET_TYPE_STRUCTURAL_EQUALITY (t); |
5802 else if (TYPE_CANONICAL (elt_type) != elt_type | 7010 else if (TYPE_CANONICAL (elt_type) != elt_type |
5803 || TYPE_CANONICAL (index_type) != index_type) | 7011 || (index_type && TYPE_CANONICAL (index_type) != index_type)) |
5804 TYPE_CANONICAL (t) | 7012 TYPE_CANONICAL (t) |
5805 = build_array_type (TYPE_CANONICAL (elt_type), | 7013 = build_array_type (TYPE_CANONICAL (elt_type), |
5806 TYPE_CANONICAL (index_type)); | 7014 index_type ? TYPE_CANONICAL (index_type) : NULL); |
5807 } | 7015 } |
5808 | 7016 |
5809 return t; | 7017 return t; |
5810 } | 7018 } |
5811 | 7019 |
5842 return t; | 7050 return t; |
5843 } | 7051 } |
5844 #endif | 7052 #endif |
5845 | 7053 |
5846 /* Computes the canonical argument types from the argument type list | 7054 /* Computes the canonical argument types from the argument type list |
5847 ARGTYPES. | 7055 ARGTYPES. |
5848 | 7056 |
5849 Upon return, *ANY_STRUCTURAL_P will be true iff either it was true | 7057 Upon return, *ANY_STRUCTURAL_P will be true iff either it was true |
5850 on entry to this function, or if any of the ARGTYPES are | 7058 on entry to this function, or if any of the ARGTYPES are |
5851 structural. | 7059 structural. |
5852 | 7060 |
5856 | 7064 |
5857 Returns a canonical argument list, which may be ARGTYPES when the | 7065 Returns a canonical argument list, which may be ARGTYPES when the |
5858 canonical argument list is unneeded (i.e., *ANY_STRUCTURAL_P is | 7066 canonical argument list is unneeded (i.e., *ANY_STRUCTURAL_P is |
5859 true) or would not differ from ARGTYPES. */ | 7067 true) or would not differ from ARGTYPES. */ |
5860 | 7068 |
5861 static tree | 7069 static tree |
5862 maybe_canonicalize_argtypes(tree argtypes, | 7070 maybe_canonicalize_argtypes(tree argtypes, |
5863 bool *any_structural_p, | 7071 bool *any_structural_p, |
5864 bool *any_noncanonical_p) | 7072 bool *any_noncanonical_p) |
5865 { | 7073 { |
5866 tree arg; | 7074 tree arg; |
5867 bool any_noncanonical_argtypes_p = false; | 7075 bool any_noncanonical_argtypes_p = false; |
5868 | 7076 |
5869 for (arg = argtypes; arg && !(*any_structural_p); arg = TREE_CHAIN (arg)) | 7077 for (arg = argtypes; arg && !(*any_structural_p); arg = TREE_CHAIN (arg)) |
5870 { | 7078 { |
5871 if (!TREE_VALUE (arg) || TREE_VALUE (arg) == error_mark_node) | 7079 if (!TREE_VALUE (arg) || TREE_VALUE (arg) == error_mark_node) |
5872 /* Fail gracefully by stating that the type is structural. */ | 7080 /* Fail gracefully by stating that the type is structural. */ |
5873 *any_structural_p = true; | 7081 *any_structural_p = true; |
5947 t = type_hash_canon (hashcode, t); | 7155 t = type_hash_canon (hashcode, t); |
5948 | 7156 |
5949 /* Set up the canonical type. */ | 7157 /* Set up the canonical type. */ |
5950 any_structural_p = TYPE_STRUCTURAL_EQUALITY_P (value_type); | 7158 any_structural_p = TYPE_STRUCTURAL_EQUALITY_P (value_type); |
5951 any_noncanonical_p = TYPE_CANONICAL (value_type) != value_type; | 7159 any_noncanonical_p = TYPE_CANONICAL (value_type) != value_type; |
5952 canon_argtypes = maybe_canonicalize_argtypes (arg_types, | 7160 canon_argtypes = maybe_canonicalize_argtypes (arg_types, |
5953 &any_structural_p, | 7161 &any_structural_p, |
5954 &any_noncanonical_p); | 7162 &any_noncanonical_p); |
5955 if (any_structural_p) | 7163 if (any_structural_p) |
5956 SET_TYPE_STRUCTURAL_EQUALITY (t); | 7164 SET_TYPE_STRUCTURAL_EQUALITY (t); |
5957 else if (any_noncanonical_p) | 7165 else if (any_noncanonical_p) |
5958 TYPE_CANONICAL (t) = build_function_type (TYPE_CANONICAL (value_type), | 7166 TYPE_CANONICAL (t) = build_function_type (TYPE_CANONICAL (value_type), |
5959 canon_argtypes); | 7167 canon_argtypes); |
5960 | 7168 |
5961 if (!COMPLETE_TYPE_P (t)) | 7169 if (!COMPLETE_TYPE_P (t)) |
5962 layout_type (t); | 7170 layout_type (t); |
5963 return t; | 7171 return t; |
5964 } | 7172 } |
5965 | 7173 |
6021 TYPE_NEXT_VARIANT (new_type) = NULL; | 7229 TYPE_NEXT_VARIANT (new_type) = NULL; |
6022 } | 7230 } |
6023 return new_type; | 7231 return new_type; |
6024 } | 7232 } |
6025 | 7233 |
6026 /* Build variant of function type ORIG_TYPE skipping ARGS_TO_SKIP. | 7234 /* Build variant of function type ORIG_TYPE skipping ARGS_TO_SKIP. |
6027 | 7235 |
6028 Arguments from DECL_ARGUMENTS list can't be removed now, since they are | 7236 Arguments from DECL_ARGUMENTS list can't be removed now, since they are |
6029 linked by TREE_CHAIN directly. It is caller responsibility to eliminate | 7237 linked by TREE_CHAIN directly. It is caller responsibility to eliminate |
6030 them when they are being duplicated (i.e. copy_arguments_for_versioning). */ | 7238 them when they are being duplicated (i.e. copy_arguments_for_versioning). */ |
6031 | 7239 |
6032 tree | 7240 tree |
6160 &any_structural_p, | 7368 &any_structural_p, |
6161 &any_noncanonical_p); | 7369 &any_noncanonical_p); |
6162 if (any_structural_p) | 7370 if (any_structural_p) |
6163 SET_TYPE_STRUCTURAL_EQUALITY (t); | 7371 SET_TYPE_STRUCTURAL_EQUALITY (t); |
6164 else if (any_noncanonical_p) | 7372 else if (any_noncanonical_p) |
6165 TYPE_CANONICAL (t) | 7373 TYPE_CANONICAL (t) |
6166 = build_method_type_directly (TYPE_CANONICAL (basetype), | 7374 = build_method_type_directly (TYPE_CANONICAL (basetype), |
6167 TYPE_CANONICAL (rettype), | 7375 TYPE_CANONICAL (rettype), |
6168 canon_argtypes); | 7376 canon_argtypes); |
6169 if (!COMPLETE_TYPE_P (t)) | 7377 if (!COMPLETE_TYPE_P (t)) |
6170 layout_type (t); | 7378 layout_type (t); |
6216 if (TYPE_STRUCTURAL_EQUALITY_P (basetype) | 7424 if (TYPE_STRUCTURAL_EQUALITY_P (basetype) |
6217 || TYPE_STRUCTURAL_EQUALITY_P (type)) | 7425 || TYPE_STRUCTURAL_EQUALITY_P (type)) |
6218 SET_TYPE_STRUCTURAL_EQUALITY (t); | 7426 SET_TYPE_STRUCTURAL_EQUALITY (t); |
6219 else if (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype)) != basetype | 7427 else if (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype)) != basetype |
6220 || TYPE_CANONICAL (type) != type) | 7428 || TYPE_CANONICAL (type) != type) |
6221 TYPE_CANONICAL (t) | 7429 TYPE_CANONICAL (t) |
6222 = build_offset_type (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype)), | 7430 = build_offset_type (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype)), |
6223 TYPE_CANONICAL (type)); | 7431 TYPE_CANONICAL (type)); |
6224 } | 7432 } |
6225 | 7433 |
6226 return t; | 7434 return t; |
6253 if (TYPE_CANONICAL (t) == t) | 7461 if (TYPE_CANONICAL (t) == t) |
6254 { | 7462 { |
6255 if (TYPE_STRUCTURAL_EQUALITY_P (component_type)) | 7463 if (TYPE_STRUCTURAL_EQUALITY_P (component_type)) |
6256 SET_TYPE_STRUCTURAL_EQUALITY (t); | 7464 SET_TYPE_STRUCTURAL_EQUALITY (t); |
6257 else if (TYPE_CANONICAL (component_type) != component_type) | 7465 else if (TYPE_CANONICAL (component_type) != component_type) |
6258 TYPE_CANONICAL (t) | 7466 TYPE_CANONICAL (t) |
6259 = build_complex_type (TYPE_CANONICAL (component_type)); | 7467 = build_complex_type (TYPE_CANONICAL (component_type)); |
6260 } | 7468 } |
6261 | 7469 |
6262 /* We need to create a name, since complex is a fundamental type. */ | 7470 /* We need to create a name, since complex is a fundamental type. */ |
6263 if (! TYPE_NAME (t)) | 7471 if (! TYPE_NAME (t)) |
6287 name = "complex long long unsigned int"; | 7495 name = "complex long long unsigned int"; |
6288 else | 7496 else |
6289 name = 0; | 7497 name = 0; |
6290 | 7498 |
6291 if (name != 0) | 7499 if (name != 0) |
6292 TYPE_NAME (t) = build_decl (TYPE_DECL, get_identifier (name), t); | 7500 TYPE_NAME (t) = build_decl (UNKNOWN_LOCATION, TYPE_DECL, |
7501 get_identifier (name), t); | |
6293 } | 7502 } |
6294 | 7503 |
6295 return build_qualified_type (t, TYPE_QUALS (component_type)); | 7504 return build_qualified_type (t, TYPE_QUALS (component_type)); |
7505 } | |
7506 | |
7507 /* If TYPE is a real or complex floating-point type and the target | |
7508 does not directly support arithmetic on TYPE then return the wider | |
7509 type to be used for arithmetic on TYPE. Otherwise, return | |
7510 NULL_TREE. */ | |
7511 | |
7512 tree | |
7513 excess_precision_type (tree type) | |
7514 { | |
7515 if (flag_excess_precision != EXCESS_PRECISION_FAST) | |
7516 { | |
7517 int flt_eval_method = TARGET_FLT_EVAL_METHOD; | |
7518 switch (TREE_CODE (type)) | |
7519 { | |
7520 case REAL_TYPE: | |
7521 switch (flt_eval_method) | |
7522 { | |
7523 case 1: | |
7524 if (TYPE_MODE (type) == TYPE_MODE (float_type_node)) | |
7525 return double_type_node; | |
7526 break; | |
7527 case 2: | |
7528 if (TYPE_MODE (type) == TYPE_MODE (float_type_node) | |
7529 || TYPE_MODE (type) == TYPE_MODE (double_type_node)) | |
7530 return long_double_type_node; | |
7531 break; | |
7532 default: | |
7533 gcc_unreachable (); | |
7534 } | |
7535 break; | |
7536 case COMPLEX_TYPE: | |
7537 if (TREE_CODE (TREE_TYPE (type)) != REAL_TYPE) | |
7538 return NULL_TREE; | |
7539 switch (flt_eval_method) | |
7540 { | |
7541 case 1: | |
7542 if (TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (float_type_node)) | |
7543 return complex_double_type_node; | |
7544 break; | |
7545 case 2: | |
7546 if (TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (float_type_node) | |
7547 || (TYPE_MODE (TREE_TYPE (type)) | |
7548 == TYPE_MODE (double_type_node))) | |
7549 return complex_long_double_type_node; | |
7550 break; | |
7551 default: | |
7552 gcc_unreachable (); | |
7553 } | |
7554 break; | |
7555 default: | |
7556 break; | |
7557 } | |
7558 } | |
7559 return NULL_TREE; | |
6296 } | 7560 } |
6297 | 7561 |
6298 /* Return OP, stripped of any conversions to wider types as much as is safe. | 7562 /* Return OP, stripped of any conversions to wider types as much as is safe. |
6299 Converting the value back to OP's type makes a value equivalent to OP. | 7563 Converting the value back to OP's type makes a value equivalent to OP. |
6300 | 7564 |
6626 TYPE_PRECISION (type)); | 7890 TYPE_PRECISION (type)); |
6627 mpz_set_double_int (min, mn, false); | 7891 mpz_set_double_int (min, mn, false); |
6628 } | 7892 } |
6629 } | 7893 } |
6630 | 7894 |
6631 if (!POINTER_TYPE_P (type) && TYPE_MAX_VALUE (type) | 7895 if (!POINTER_TYPE_P (type) && TYPE_MAX_VALUE (type) |
6632 && TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST) | 7896 && TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST) |
6633 mpz_set_double_int (max, tree_to_double_int (TYPE_MAX_VALUE (type)), | 7897 mpz_set_double_int (max, tree_to_double_int (TYPE_MAX_VALUE (type)), |
6634 TYPE_UNSIGNED (type)); | 7898 TYPE_UNSIGNED (type)); |
6635 else | 7899 else |
6636 { | 7900 { |
6925 fprintf (stderr, "(No per-node statistics)\n"); | 8189 fprintf (stderr, "(No per-node statistics)\n"); |
6926 #endif | 8190 #endif |
6927 print_type_hash_statistics (); | 8191 print_type_hash_statistics (); |
6928 print_debug_expr_statistics (); | 8192 print_debug_expr_statistics (); |
6929 print_value_expr_statistics (); | 8193 print_value_expr_statistics (); |
6930 print_restrict_base_statistics (); | |
6931 lang_hooks.print_statistics (); | 8194 lang_hooks.print_statistics (); |
6932 } | 8195 } |
6933 | 8196 |
6934 #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s" | 8197 #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s" |
6935 | 8198 |
7076 buffer = tmp = (char *) alloca (length); | 8339 buffer = tmp = (char *) alloca (length); |
7077 length = 0; | 8340 length = 0; |
7078 while ((code = va_arg (args, int))) | 8341 while ((code = va_arg (args, int))) |
7079 { | 8342 { |
7080 const char *prefix = length ? " or " : "expected "; | 8343 const char *prefix = length ? " or " : "expected "; |
7081 | 8344 |
7082 strcpy (tmp + length, prefix); | 8345 strcpy (tmp + length, prefix); |
7083 length += strlen (prefix); | 8346 length += strlen (prefix); |
7084 strcpy (tmp + length, tree_code_name[code]); | 8347 strcpy (tmp + length, tree_code_name[code]); |
7085 length += strlen (tree_code_name[code]); | 8348 length += strlen (tree_code_name[code]); |
7086 } | 8349 } |
7153 const char *function, enum tree_code c1, | 8416 const char *function, enum tree_code c1, |
7154 enum tree_code c2) | 8417 enum tree_code c2) |
7155 { | 8418 { |
7156 char *buffer; | 8419 char *buffer; |
7157 unsigned length = 0; | 8420 unsigned length = 0; |
7158 enum tree_code c; | 8421 unsigned int c; |
7159 | 8422 |
7160 for (c = c1; c <= c2; ++c) | 8423 for (c = c1; c <= c2; ++c) |
7161 length += 4 + strlen (tree_code_name[c]); | 8424 length += 4 + strlen (tree_code_name[c]); |
7162 | 8425 |
7163 length += strlen ("expected "); | 8426 length += strlen ("expected "); |
7214 const char *function, enum omp_clause_code c1, | 8477 const char *function, enum omp_clause_code c1, |
7215 enum omp_clause_code c2) | 8478 enum omp_clause_code c2) |
7216 { | 8479 { |
7217 char *buffer; | 8480 char *buffer; |
7218 unsigned length = 0; | 8481 unsigned length = 0; |
7219 enum omp_clause_code c; | 8482 unsigned int c; |
7220 | 8483 |
7221 for (c = c1; c <= c2; ++c) | 8484 for (c = c1; c <= c2; ++c) |
7222 length += 4 + strlen (omp_clause_code_name[c]); | 8485 length += 4 + strlen (omp_clause_code_name[c]); |
7223 | 8486 |
7224 length += strlen ("expected "); | 8487 length += strlen ("expected "); |
7253 | 8516 |
7254 /* Similar to tree_class_check_failed, except that we check for | 8517 /* Similar to tree_class_check_failed, except that we check for |
7255 whether CODE contains the tree structure identified by EN. */ | 8518 whether CODE contains the tree structure identified by EN. */ |
7256 | 8519 |
7257 void | 8520 void |
7258 tree_contains_struct_check_failed (const_tree node, | 8521 tree_contains_struct_check_failed (const_tree node, |
7259 const enum tree_node_structure_enum en, | 8522 const enum tree_node_structure_enum en, |
7260 const char *file, int line, | 8523 const char *file, int line, |
7261 const char *function) | 8524 const char *function) |
7262 { | 8525 { |
7263 internal_error | 8526 internal_error |
7264 ("tree check: expected tree that contains %qs structure, have %qs in %s, at %s:%d", | 8527 ("tree check: expected tree that contains %qs structure, have %qs in %s, at %s:%d", |
7265 TS_ENUM_NAME(en), | 8528 TS_ENUM_NAME(en), |
7316 make_vector_type (tree innertype, int nunits, enum machine_mode mode) | 8579 make_vector_type (tree innertype, int nunits, enum machine_mode mode) |
7317 { | 8580 { |
7318 tree t; | 8581 tree t; |
7319 hashval_t hashcode = 0; | 8582 hashval_t hashcode = 0; |
7320 | 8583 |
7321 /* Build a main variant, based on the main variant of the inner type, then | |
7322 use it to build the variant we return. */ | |
7323 if ((TYPE_ATTRIBUTES (innertype) || TYPE_QUALS (innertype)) | |
7324 && TYPE_MAIN_VARIANT (innertype) != innertype) | |
7325 return build_type_attribute_qual_variant ( | |
7326 make_vector_type (TYPE_MAIN_VARIANT (innertype), nunits, mode), | |
7327 TYPE_ATTRIBUTES (innertype), | |
7328 TYPE_QUALS (innertype)); | |
7329 | |
7330 t = make_node (VECTOR_TYPE); | 8584 t = make_node (VECTOR_TYPE); |
7331 TREE_TYPE (t) = TYPE_MAIN_VARIANT (innertype); | 8585 TREE_TYPE (t) = TYPE_MAIN_VARIANT (innertype); |
7332 SET_TYPE_VECTOR_SUBPARTS (t, nunits); | 8586 SET_TYPE_VECTOR_SUBPARTS (t, nunits); |
7333 SET_TYPE_MODE (t, mode); | 8587 SET_TYPE_MODE (t, mode); |
7334 TYPE_READONLY (t) = TYPE_READONLY (innertype); | |
7335 TYPE_VOLATILE (t) = TYPE_VOLATILE (innertype); | |
7336 | 8588 |
7337 if (TYPE_STRUCTURAL_EQUALITY_P (innertype)) | 8589 if (TYPE_STRUCTURAL_EQUALITY_P (innertype)) |
7338 SET_TYPE_STRUCTURAL_EQUALITY (t); | 8590 SET_TYPE_STRUCTURAL_EQUALITY (t); |
7339 else if (TYPE_CANONICAL (innertype) != innertype | 8591 else if (TYPE_CANONICAL (innertype) != innertype |
7340 || mode != VOIDmode) | 8592 || mode != VOIDmode) |
7341 TYPE_CANONICAL (t) | 8593 TYPE_CANONICAL (t) |
7342 = make_vector_type (TYPE_CANONICAL (innertype), nunits, VOIDmode); | 8594 = make_vector_type (TYPE_CANONICAL (innertype), nunits, VOIDmode); |
7343 | 8595 |
7344 layout_type (t); | 8596 layout_type (t); |
7345 | 8597 |
7346 { | 8598 { |
7347 tree index = build_int_cst (NULL_TREE, nunits - 1); | 8599 tree index = build_int_cst (NULL_TREE, nunits - 1); |
7348 tree array = build_array_type (innertype, build_index_type (index)); | 8600 tree array = build_array_type (TYPE_MAIN_VARIANT (innertype), |
8601 build_index_type (index)); | |
7349 tree rt = make_node (RECORD_TYPE); | 8602 tree rt = make_node (RECORD_TYPE); |
7350 | 8603 |
7351 TYPE_FIELDS (rt) = build_decl (FIELD_DECL, get_identifier ("f"), array); | 8604 TYPE_FIELDS (rt) = build_decl (UNKNOWN_LOCATION, FIELD_DECL, |
8605 get_identifier ("f"), array); | |
7352 DECL_CONTEXT (TYPE_FIELDS (rt)) = rt; | 8606 DECL_CONTEXT (TYPE_FIELDS (rt)) = rt; |
7353 layout_type (rt); | 8607 layout_type (rt); |
7354 TYPE_DEBUG_REPRESENTATION_TYPE (t) = rt; | 8608 TYPE_DEBUG_REPRESENTATION_TYPE (t) = rt; |
7355 /* In dwarfout.c, type lookup uses TYPE_UID numbers. We want to output | 8609 /* In dwarfout.c, type lookup uses TYPE_UID numbers. We want to output |
7356 the representation type, and we want to find that die when looking up | 8610 the representation type, and we want to find that die when looking up |
7358 numbers equal. */ | 8612 numbers equal. */ |
7359 TYPE_UID (rt) = TYPE_UID (t); | 8613 TYPE_UID (rt) = TYPE_UID (t); |
7360 } | 8614 } |
7361 | 8615 |
7362 hashcode = iterative_hash_host_wide_int (VECTOR_TYPE, hashcode); | 8616 hashcode = iterative_hash_host_wide_int (VECTOR_TYPE, hashcode); |
8617 hashcode = iterative_hash_host_wide_int (nunits, hashcode); | |
7363 hashcode = iterative_hash_host_wide_int (mode, hashcode); | 8618 hashcode = iterative_hash_host_wide_int (mode, hashcode); |
7364 hashcode = iterative_hash_object (TYPE_HASH (innertype), hashcode); | 8619 hashcode = iterative_hash_object (TYPE_HASH (TREE_TYPE (t)), hashcode); |
7365 return type_hash_canon (hashcode, t); | 8620 t = type_hash_canon (hashcode, t); |
8621 | |
8622 /* We have built a main variant, based on the main variant of the | |
8623 inner type. Use it to build the variant we return. */ | |
8624 if ((TYPE_ATTRIBUTES (innertype) || TYPE_QUALS (innertype)) | |
8625 && TREE_TYPE (t) != innertype) | |
8626 return build_type_attribute_qual_variant (t, | |
8627 TYPE_ATTRIBUTES (innertype), | |
8628 TYPE_QUALS (innertype)); | |
8629 | |
8630 return t; | |
7366 } | 8631 } |
7367 | 8632 |
7368 static tree | 8633 static tree |
7369 make_or_reuse_type (unsigned size, int unsignedp) | 8634 make_or_reuse_type (unsigned size, int unsignedp) |
7370 { | 8635 { |
7583 uint32_type_node = build_nonstandard_integer_type (32, true); | 8848 uint32_type_node = build_nonstandard_integer_type (32, true); |
7584 uint64_type_node = build_nonstandard_integer_type (64, true); | 8849 uint64_type_node = build_nonstandard_integer_type (64, true); |
7585 | 8850 |
7586 /* Decimal float types. */ | 8851 /* Decimal float types. */ |
7587 dfloat32_type_node = make_node (REAL_TYPE); | 8852 dfloat32_type_node = make_node (REAL_TYPE); |
7588 TYPE_PRECISION (dfloat32_type_node) = DECIMAL32_TYPE_SIZE; | 8853 TYPE_PRECISION (dfloat32_type_node) = DECIMAL32_TYPE_SIZE; |
7589 layout_type (dfloat32_type_node); | 8854 layout_type (dfloat32_type_node); |
7590 SET_TYPE_MODE (dfloat32_type_node, SDmode); | 8855 SET_TYPE_MODE (dfloat32_type_node, SDmode); |
7591 dfloat32_ptr_type_node = build_pointer_type (dfloat32_type_node); | 8856 dfloat32_ptr_type_node = build_pointer_type (dfloat32_type_node); |
7592 | 8857 |
7593 dfloat64_type_node = make_node (REAL_TYPE); | 8858 dfloat64_type_node = make_node (REAL_TYPE); |
7595 layout_type (dfloat64_type_node); | 8860 layout_type (dfloat64_type_node); |
7596 SET_TYPE_MODE (dfloat64_type_node, DDmode); | 8861 SET_TYPE_MODE (dfloat64_type_node, DDmode); |
7597 dfloat64_ptr_type_node = build_pointer_type (dfloat64_type_node); | 8862 dfloat64_ptr_type_node = build_pointer_type (dfloat64_type_node); |
7598 | 8863 |
7599 dfloat128_type_node = make_node (REAL_TYPE); | 8864 dfloat128_type_node = make_node (REAL_TYPE); |
7600 TYPE_PRECISION (dfloat128_type_node) = DECIMAL128_TYPE_SIZE; | 8865 TYPE_PRECISION (dfloat128_type_node) = DECIMAL128_TYPE_SIZE; |
7601 layout_type (dfloat128_type_node); | 8866 layout_type (dfloat128_type_node); |
7602 SET_TYPE_MODE (dfloat128_type_node, TDmode); | 8867 SET_TYPE_MODE (dfloat128_type_node, TDmode); |
7603 dfloat128_ptr_type_node = build_pointer_type (dfloat128_type_node); | 8868 dfloat128_ptr_type_node = build_pointer_type (dfloat128_type_node); |
7604 | 8869 |
7605 complex_integer_type_node = build_complex_type (integer_type_node); | 8870 complex_integer_type_node = build_complex_type (integer_type_node); |
7668 record type without a name. This breaks name mangling. So, | 8933 record type without a name. This breaks name mangling. So, |
7669 don't copy record types and let c_common_nodes_and_builtins() | 8934 don't copy record types and let c_common_nodes_and_builtins() |
7670 declare the type to be __builtin_va_list. */ | 8935 declare the type to be __builtin_va_list. */ |
7671 if (TREE_CODE (t) != RECORD_TYPE) | 8936 if (TREE_CODE (t) != RECORD_TYPE) |
7672 t = build_variant_type_copy (t); | 8937 t = build_variant_type_copy (t); |
7673 | 8938 |
7674 va_list_type_node = t; | 8939 va_list_type_node = t; |
7675 } | 8940 } |
7676 } | 8941 } |
7677 | 8942 |
7678 /* A subroutine of build_common_builtin_nodes. Define a builtin function. */ | 8943 /* A subroutine of build_common_builtin_nodes. Define a builtin function. */ |
7707 are relied upon by the tree optimizers and the middle-end. */ | 8972 are relied upon by the tree optimizers and the middle-end. */ |
7708 | 8973 |
7709 void | 8974 void |
7710 build_common_builtin_nodes (void) | 8975 build_common_builtin_nodes (void) |
7711 { | 8976 { |
7712 tree tmp, ftype; | 8977 tree tmp, tmp2, ftype; |
7713 | 8978 |
7714 if (built_in_decls[BUILT_IN_MEMCPY] == NULL | 8979 if (built_in_decls[BUILT_IN_MEMCPY] == NULL |
7715 || built_in_decls[BUILT_IN_MEMMOVE] == NULL) | 8980 || built_in_decls[BUILT_IN_MEMMOVE] == NULL) |
7716 { | 8981 { |
7717 tmp = tree_cons (NULL_TREE, size_type_node, void_list_node); | 8982 tmp = tree_cons (NULL_TREE, size_type_node, void_list_node); |
7750 if (built_in_decls[BUILT_IN_ALLOCA] == NULL) | 9015 if (built_in_decls[BUILT_IN_ALLOCA] == NULL) |
7751 { | 9016 { |
7752 tmp = tree_cons (NULL_TREE, size_type_node, void_list_node); | 9017 tmp = tree_cons (NULL_TREE, size_type_node, void_list_node); |
7753 ftype = build_function_type (ptr_type_node, tmp); | 9018 ftype = build_function_type (ptr_type_node, tmp); |
7754 local_define_builtin ("__builtin_alloca", ftype, BUILT_IN_ALLOCA, | 9019 local_define_builtin ("__builtin_alloca", ftype, BUILT_IN_ALLOCA, |
7755 "alloca", ECF_NOTHROW | ECF_MALLOC); | 9020 "alloca", |
9021 ECF_MALLOC | (flag_stack_check ? 0 : ECF_NOTHROW)); | |
7756 } | 9022 } |
7757 | 9023 |
7758 tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node); | 9024 tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node); |
7759 tmp = tree_cons (NULL_TREE, ptr_type_node, tmp); | 9025 tmp = tree_cons (NULL_TREE, ptr_type_node, tmp); |
7760 tmp = tree_cons (NULL_TREE, ptr_type_node, tmp); | 9026 tmp = tree_cons (NULL_TREE, ptr_type_node, tmp); |
7812 local_define_builtin ("__builtin_profile_func_enter", ftype, | 9078 local_define_builtin ("__builtin_profile_func_enter", ftype, |
7813 BUILT_IN_PROFILE_FUNC_ENTER, "profile_func_enter", 0); | 9079 BUILT_IN_PROFILE_FUNC_ENTER, "profile_func_enter", 0); |
7814 local_define_builtin ("__builtin_profile_func_exit", ftype, | 9080 local_define_builtin ("__builtin_profile_func_exit", ftype, |
7815 BUILT_IN_PROFILE_FUNC_EXIT, "profile_func_exit", 0); | 9081 BUILT_IN_PROFILE_FUNC_EXIT, "profile_func_exit", 0); |
7816 | 9082 |
9083 /* If there's a possibility that we might use the ARM EABI, build the | |
9084 alternate __cxa_end_cleanup node used to resume from C++ and Java. */ | |
9085 if (targetm.arm_eabi_unwinder) | |
9086 { | |
9087 ftype = build_function_type (void_type_node, void_list_node); | |
9088 local_define_builtin ("__builtin_cxa_end_cleanup", ftype, | |
9089 BUILT_IN_CXA_END_CLEANUP, | |
9090 "__cxa_end_cleanup", ECF_NORETURN); | |
9091 } | |
9092 | |
9093 tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node); | |
9094 ftype = build_function_type (void_type_node, tmp); | |
9095 local_define_builtin ("__builtin_unwind_resume", ftype, | |
9096 BUILT_IN_UNWIND_RESUME, | |
9097 (USING_SJLJ_EXCEPTIONS | |
9098 ? "_Unwind_SjLj_Resume" : "_Unwind_Resume"), | |
9099 ECF_NORETURN); | |
9100 | |
9101 /* The exception object and filter values from the runtime. The argument | |
9102 must be zero before exception lowering, i.e. from the front end. After | |
9103 exception lowering, it will be the region number for the exception | |
9104 landing pad. These functions are PURE instead of CONST to prevent | |
9105 them from being hoisted past the exception edge that will initialize | |
9106 its value in the landing pad. */ | |
9107 tmp = tree_cons (NULL_TREE, integer_type_node, void_list_node); | |
9108 ftype = build_function_type (ptr_type_node, tmp); | |
9109 local_define_builtin ("__builtin_eh_pointer", ftype, BUILT_IN_EH_POINTER, | |
9110 "__builtin_eh_pointer", ECF_PURE | ECF_NOTHROW); | |
9111 | |
9112 tmp2 = lang_hooks.types.type_for_mode (targetm.eh_return_filter_mode (), 0); | |
9113 ftype = build_function_type (tmp2, tmp); | |
9114 local_define_builtin ("__builtin_eh_filter", ftype, BUILT_IN_EH_FILTER, | |
9115 "__builtin_eh_filter", ECF_PURE | ECF_NOTHROW); | |
9116 | |
9117 tmp = tree_cons (NULL_TREE, integer_type_node, void_list_node); | |
9118 tmp = tree_cons (NULL_TREE, integer_type_node, tmp); | |
9119 ftype = build_function_type (void_type_node, tmp); | |
9120 local_define_builtin ("__builtin_eh_copy_values", ftype, | |
9121 BUILT_IN_EH_COPY_VALUES, | |
9122 "__builtin_eh_copy_values", ECF_NOTHROW); | |
9123 | |
7817 /* Complex multiplication and division. These are handled as builtins | 9124 /* Complex multiplication and division. These are handled as builtins |
7818 rather than optabs because emit_library_call_value doesn't support | 9125 rather than optabs because emit_library_call_value doesn't support |
7819 complex. Further, we can do slightly better with folding these | 9126 complex. Further, we can do slightly better with folding these |
7820 beasties if the real and complex parts of the arguments are separate. */ | 9127 beasties if the real and complex parts of the arguments are separate. */ |
7821 { | 9128 { |
7822 enum machine_mode mode; | 9129 int mode; |
7823 | 9130 |
7824 for (mode = MIN_MODE_COMPLEX_FLOAT; mode <= MAX_MODE_COMPLEX_FLOAT; ++mode) | 9131 for (mode = MIN_MODE_COMPLEX_FLOAT; mode <= MAX_MODE_COMPLEX_FLOAT; ++mode) |
7825 { | 9132 { |
7826 char mode_name_buf[4], *q; | 9133 char mode_name_buf[4], *q; |
7827 const char *p; | 9134 const char *p; |
7828 enum built_in_function mcode, dcode; | 9135 enum built_in_function mcode, dcode; |
7829 tree type, inner_type; | 9136 tree type, inner_type; |
7830 | 9137 |
7831 type = lang_hooks.types.type_for_mode (mode, 0); | 9138 type = lang_hooks.types.type_for_mode ((enum machine_mode) mode, 0); |
7832 if (type == NULL) | 9139 if (type == NULL) |
7833 continue; | 9140 continue; |
7834 inner_type = TREE_TYPE (type); | 9141 inner_type = TREE_TYPE (type); |
7835 | 9142 |
7836 tmp = tree_cons (NULL_TREE, inner_type, void_list_node); | 9143 tmp = tree_cons (NULL_TREE, inner_type, void_list_node); |
7837 tmp = tree_cons (NULL_TREE, inner_type, tmp); | 9144 tmp = tree_cons (NULL_TREE, inner_type, tmp); |
7838 tmp = tree_cons (NULL_TREE, inner_type, tmp); | 9145 tmp = tree_cons (NULL_TREE, inner_type, tmp); |
7839 tmp = tree_cons (NULL_TREE, inner_type, tmp); | 9146 tmp = tree_cons (NULL_TREE, inner_type, tmp); |
7840 ftype = build_function_type (type, tmp); | 9147 ftype = build_function_type (type, tmp); |
7841 | 9148 |
7842 mcode = BUILT_IN_COMPLEX_MUL_MIN + mode - MIN_MODE_COMPLEX_FLOAT; | 9149 mcode = ((enum built_in_function) |
7843 dcode = BUILT_IN_COMPLEX_DIV_MIN + mode - MIN_MODE_COMPLEX_FLOAT; | 9150 (BUILT_IN_COMPLEX_MUL_MIN + mode - MIN_MODE_COMPLEX_FLOAT)); |
9151 dcode = ((enum built_in_function) | |
9152 (BUILT_IN_COMPLEX_DIV_MIN + mode - MIN_MODE_COMPLEX_FLOAT)); | |
7844 | 9153 |
7845 for (p = GET_MODE_NAME (mode), q = mode_name_buf; *p; p++, q++) | 9154 for (p = GET_MODE_NAME (mode), q = mode_name_buf; *p; p++, q++) |
7846 *q = TOLOWER (*p); | 9155 *q = TOLOWER (*p); |
7847 *q = '\0'; | 9156 *q = '\0'; |
7848 | 9157 |
7869 | 9178 |
7870 tree | 9179 tree |
7871 reconstruct_complex_type (tree type, tree bottom) | 9180 reconstruct_complex_type (tree type, tree bottom) |
7872 { | 9181 { |
7873 tree inner, outer; | 9182 tree inner, outer; |
7874 | 9183 |
7875 if (TREE_CODE (type) == POINTER_TYPE) | 9184 if (TREE_CODE (type) == POINTER_TYPE) |
7876 { | 9185 { |
7877 inner = reconstruct_complex_type (TREE_TYPE (type), bottom); | 9186 inner = reconstruct_complex_type (TREE_TYPE (type), bottom); |
7878 outer = build_pointer_type_for_mode (inner, TYPE_MODE (type), | 9187 outer = build_pointer_type_for_mode (inner, TYPE_MODE (type), |
7879 TYPE_REF_CAN_ALIAS_ALL (type)); | 9188 TYPE_REF_CAN_ALIAS_ALL (type)); |
7897 else if (TREE_CODE (type) == METHOD_TYPE) | 9206 else if (TREE_CODE (type) == METHOD_TYPE) |
7898 { | 9207 { |
7899 inner = reconstruct_complex_type (TREE_TYPE (type), bottom); | 9208 inner = reconstruct_complex_type (TREE_TYPE (type), bottom); |
7900 /* The build_method_type_directly() routine prepends 'this' to argument list, | 9209 /* The build_method_type_directly() routine prepends 'this' to argument list, |
7901 so we must compensate by getting rid of it. */ | 9210 so we must compensate by getting rid of it. */ |
7902 outer | 9211 outer |
7903 = build_method_type_directly | 9212 = build_method_type_directly |
7904 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (type))), | 9213 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (type))), |
7905 inner, | 9214 inner, |
7906 TREE_CHAIN (TYPE_ARG_TYPES (type))); | 9215 TREE_CHAIN (TYPE_ARG_TYPES (type))); |
7907 } | 9216 } |
7908 else if (TREE_CODE (type) == OFFSET_TYPE) | 9217 else if (TREE_CODE (type) == OFFSET_TYPE) |
7911 outer = build_offset_type (TYPE_OFFSET_BASETYPE (type), inner); | 9220 outer = build_offset_type (TYPE_OFFSET_BASETYPE (type), inner); |
7912 } | 9221 } |
7913 else | 9222 else |
7914 return bottom; | 9223 return bottom; |
7915 | 9224 |
7916 return build_qualified_type (outer, TYPE_QUALS (type)); | 9225 return build_type_attribute_qual_variant (outer, TYPE_ATTRIBUTES (type), |
9226 TYPE_QUALS (type)); | |
7917 } | 9227 } |
7918 | 9228 |
7919 /* Returns a vector tree node given a mode (integer, vector, or BLKmode) and | 9229 /* Returns a vector tree node given a mode (integer, vector, or BLKmode) and |
7920 the inner type. */ | 9230 the inner type. */ |
7921 tree | 9231 tree |
7957 build_vector_type (tree innertype, int nunits) | 9267 build_vector_type (tree innertype, int nunits) |
7958 { | 9268 { |
7959 return make_vector_type (innertype, nunits, VOIDmode); | 9269 return make_vector_type (innertype, nunits, VOIDmode); |
7960 } | 9270 } |
7961 | 9271 |
7962 | 9272 /* Similarly, but takes the inner type and number of units, which must be |
7963 /* Build RESX_EXPR with given REGION_NUMBER. */ | 9273 a power of two. */ |
7964 tree | 9274 |
7965 build_resx (int region_number) | 9275 tree |
9276 build_opaque_vector_type (tree innertype, int nunits) | |
7966 { | 9277 { |
7967 tree t; | 9278 tree t; |
7968 t = build1 (RESX_EXPR, void_type_node, | 9279 innertype = build_distinct_type_copy (innertype); |
7969 build_int_cst (NULL_TREE, region_number)); | 9280 t = make_vector_type (innertype, nunits, VOIDmode); |
9281 TYPE_VECTOR_OPAQUE (t) = true; | |
7970 return t; | 9282 return t; |
7971 } | 9283 } |
9284 | |
7972 | 9285 |
7973 /* Given an initializer INIT, return TRUE if INIT is zero or some | 9286 /* Given an initializer INIT, return TRUE if INIT is zero or some |
7974 aggregate of zeros. Otherwise return FALSE. */ | 9287 aggregate of zeros. Otherwise return FALSE. */ |
7975 bool | 9288 bool |
7976 initializer_zerop (const_tree init) | 9289 initializer_zerop (const_tree init) |
8019 default: | 9332 default: |
8020 return false; | 9333 return false; |
8021 } | 9334 } |
8022 } | 9335 } |
8023 | 9336 |
8024 /* Build an empty statement. */ | 9337 /* Build an empty statement at location LOC. */ |
8025 | 9338 |
8026 tree | 9339 tree |
8027 build_empty_stmt (void) | 9340 build_empty_stmt (location_t loc) |
8028 { | 9341 { |
8029 return build1 (NOP_EXPR, void_type_node, size_zero_node); | 9342 tree t = build1 (NOP_EXPR, void_type_node, size_zero_node); |
8030 } | 9343 SET_EXPR_LOCATION (t, loc); |
8031 | 9344 return t; |
8032 | 9345 } |
8033 /* Build an OpenMP clause with code CODE. */ | 9346 |
8034 | 9347 |
8035 tree | 9348 /* Build an OpenMP clause with code CODE. LOC is the location of the |
8036 build_omp_clause (enum omp_clause_code code) | 9349 clause. */ |
9350 | |
9351 tree | |
9352 build_omp_clause (location_t loc, enum omp_clause_code code) | |
8037 { | 9353 { |
8038 tree t; | 9354 tree t; |
8039 int size, length; | 9355 int size, length; |
8040 | 9356 |
8041 length = omp_clause_num_ops[code]; | 9357 length = omp_clause_num_ops[code]; |
8043 | 9359 |
8044 t = GGC_NEWVAR (union tree_node, size); | 9360 t = GGC_NEWVAR (union tree_node, size); |
8045 memset (t, 0, size); | 9361 memset (t, 0, size); |
8046 TREE_SET_CODE (t, OMP_CLAUSE); | 9362 TREE_SET_CODE (t, OMP_CLAUSE); |
8047 OMP_CLAUSE_SET_CODE (t, code); | 9363 OMP_CLAUSE_SET_CODE (t, code); |
9364 OMP_CLAUSE_LOCATION (t) = loc; | |
8048 | 9365 |
8049 #ifdef GATHER_STATISTICS | 9366 #ifdef GATHER_STATISTICS |
8050 tree_node_counts[(int) omp_clause_kind]++; | 9367 tree_node_counts[(int) omp_clause_kind]++; |
8051 tree_node_sizes[(int) omp_clause_kind] += size; | 9368 tree_node_sizes[(int) omp_clause_kind] += size; |
8052 #endif | 9369 #endif |
8053 | 9370 |
8054 return t; | 9371 return t; |
8055 } | |
8056 | |
8057 /* Set various status flags when building a CALL_EXPR object T. */ | |
8058 | |
8059 static void | |
8060 process_call_operands (tree t) | |
8061 { | |
8062 bool side_effects; | |
8063 | |
8064 side_effects = TREE_SIDE_EFFECTS (t); | |
8065 if (!side_effects) | |
8066 { | |
8067 int i, n; | |
8068 n = TREE_OPERAND_LENGTH (t); | |
8069 for (i = 1; i < n; i++) | |
8070 { | |
8071 tree op = TREE_OPERAND (t, i); | |
8072 if (op && TREE_SIDE_EFFECTS (op)) | |
8073 { | |
8074 side_effects = 1; | |
8075 break; | |
8076 } | |
8077 } | |
8078 } | |
8079 if (!side_effects) | |
8080 { | |
8081 int i; | |
8082 | |
8083 /* Calls have side-effects, except those to const or | |
8084 pure functions. */ | |
8085 i = call_expr_flags (t); | |
8086 if ((i & ECF_LOOPING_CONST_OR_PURE) || !(i & (ECF_CONST | ECF_PURE))) | |
8087 side_effects = 1; | |
8088 } | |
8089 TREE_SIDE_EFFECTS (t) = side_effects; | |
8090 } | 9372 } |
8091 | 9373 |
8092 /* Build a tcc_vl_exp object with code CODE and room for LEN operands. LEN | 9374 /* Build a tcc_vl_exp object with code CODE and room for LEN operands. LEN |
8093 includes the implicit operand count in TREE_OPERAND 0, and so must be >= 1. | 9375 includes the implicit operand count in TREE_OPERAND 0, and so must be >= 1. |
8094 Except for the CODE and operand count field, other storage for the | 9376 Except for the CODE and operand count field, other storage for the |
8180 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and | 9462 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and |
8181 FN and a null static chain slot. NARGS is the number of call arguments | 9463 FN and a null static chain slot. NARGS is the number of call arguments |
8182 which are specified as a tree array ARGS. */ | 9464 which are specified as a tree array ARGS. */ |
8183 | 9465 |
8184 tree | 9466 tree |
8185 build_call_array (tree return_type, tree fn, int nargs, tree *args) | 9467 build_call_array_loc (location_t loc, tree return_type, tree fn, |
9468 int nargs, const tree *args) | |
8186 { | 9469 { |
8187 tree t; | 9470 tree t; |
8188 int i; | 9471 int i; |
8189 | 9472 |
8190 t = build_vl_exp (CALL_EXPR, nargs + 3); | 9473 t = build_vl_exp (CALL_EXPR, nargs + 3); |
8192 CALL_EXPR_FN (t) = fn; | 9475 CALL_EXPR_FN (t) = fn; |
8193 CALL_EXPR_STATIC_CHAIN (t) = NULL_TREE; | 9476 CALL_EXPR_STATIC_CHAIN (t) = NULL_TREE; |
8194 for (i = 0; i < nargs; i++) | 9477 for (i = 0; i < nargs; i++) |
8195 CALL_EXPR_ARG (t, i) = args[i]; | 9478 CALL_EXPR_ARG (t, i) = args[i]; |
8196 process_call_operands (t); | 9479 process_call_operands (t); |
9480 SET_EXPR_LOCATION (t, loc); | |
8197 return t; | 9481 return t; |
9482 } | |
9483 | |
9484 /* Like build_call_array, but takes a VEC. */ | |
9485 | |
9486 tree | |
9487 build_call_vec (tree return_type, tree fn, VEC(tree,gc) *args) | |
9488 { | |
9489 tree ret, t; | |
9490 unsigned int ix; | |
9491 | |
9492 ret = build_vl_exp (CALL_EXPR, VEC_length (tree, args) + 3); | |
9493 TREE_TYPE (ret) = return_type; | |
9494 CALL_EXPR_FN (ret) = fn; | |
9495 CALL_EXPR_STATIC_CHAIN (ret) = NULL_TREE; | |
9496 for (ix = 0; VEC_iterate (tree, args, ix, t); ++ix) | |
9497 CALL_EXPR_ARG (ret, ix) = t; | |
9498 process_call_operands (ret); | |
9499 return ret; | |
8198 } | 9500 } |
8199 | 9501 |
8200 | 9502 |
8201 /* Returns true if it is possible to prove that the index of | 9503 /* Returns true if it is possible to prove that the index of |
8202 an array access REF (an ARRAY_REF expression) falls into the | 9504 an array access REF (an ARRAY_REF expression) falls into the |
8340 } | 9642 } |
8341 | 9643 |
8342 return val; | 9644 return val; |
8343 } | 9645 } |
8344 | 9646 |
9647 /* Return value of a constant X and sign-extend it. */ | |
9648 | |
9649 HOST_WIDEST_INT | |
9650 widest_int_cst_value (const_tree x) | |
9651 { | |
9652 unsigned bits = TYPE_PRECISION (TREE_TYPE (x)); | |
9653 unsigned HOST_WIDEST_INT val = TREE_INT_CST_LOW (x); | |
9654 | |
9655 #if HOST_BITS_PER_WIDEST_INT > HOST_BITS_PER_WIDE_INT | |
9656 gcc_assert (HOST_BITS_PER_WIDEST_INT >= 2 * HOST_BITS_PER_WIDE_INT); | |
9657 val |= (((unsigned HOST_WIDEST_INT) TREE_INT_CST_HIGH (x)) | |
9658 << HOST_BITS_PER_WIDE_INT); | |
9659 #else | |
9660 /* Make sure the sign-extended value will fit in a HOST_WIDE_INT. */ | |
9661 gcc_assert (TREE_INT_CST_HIGH (x) == 0 | |
9662 || TREE_INT_CST_HIGH (x) == -1); | |
9663 #endif | |
9664 | |
9665 if (bits < HOST_BITS_PER_WIDEST_INT) | |
9666 { | |
9667 bool negative = ((val >> (bits - 1)) & 1) != 0; | |
9668 if (negative) | |
9669 val |= (~(unsigned HOST_WIDEST_INT) 0) << (bits - 1) << 1; | |
9670 else | |
9671 val &= ~((~(unsigned HOST_WIDEST_INT) 0) << (bits - 1) << 1); | |
9672 } | |
9673 | |
9674 return val; | |
9675 } | |
9676 | |
8345 /* If TYPE is an integral type, return an equivalent type which is | 9677 /* If TYPE is an integral type, return an equivalent type which is |
8346 unsigned iff UNSIGNEDP is true. If TYPE is not an integral type, | 9678 unsigned iff UNSIGNEDP is true. If TYPE is not an integral type, |
8347 return TYPE itself. */ | 9679 return TYPE itself. */ |
8348 | 9680 |
8349 tree | 9681 tree |
8350 signed_or_unsigned_type_for (int unsignedp, tree type) | 9682 signed_or_unsigned_type_for (int unsignedp, tree type) |
8351 { | 9683 { |
8352 tree t = type; | 9684 tree t = type; |
8353 if (POINTER_TYPE_P (type)) | 9685 if (POINTER_TYPE_P (type)) |
8354 t = size_type_node; | 9686 { |
9687 /* If the pointer points to the normal address space, use the | |
9688 size_type_node. Otherwise use an appropriate size for the pointer | |
9689 based on the named address space it points to. */ | |
9690 if (!TYPE_ADDR_SPACE (TREE_TYPE (t))) | |
9691 t = size_type_node; | |
9692 else | |
9693 return lang_hooks.types.type_for_size (TYPE_PRECISION (t), unsignedp); | |
9694 } | |
8355 | 9695 |
8356 if (!INTEGRAL_TYPE_P (t) || TYPE_UNSIGNED (t) == unsignedp) | 9696 if (!INTEGRAL_TYPE_P (t) || TYPE_UNSIGNED (t) == unsignedp) |
8357 return t; | 9697 return t; |
8358 | 9698 |
8359 return lang_hooks.types.type_for_size (TYPE_PRECISION (t), unsignedp); | 9699 return lang_hooks.types.type_for_size (TYPE_PRECISION (t), unsignedp); |
8360 } | 9700 } |
8361 | 9701 |
8362 /* Returns unsigned variant of TYPE. */ | 9702 /* Returns unsigned variant of TYPE. */ |
8363 | 9703 |
8499 return 0; | 9839 return 0; |
8500 return operand_equal_p (arg0, arg1, 0); | 9840 return operand_equal_p (arg0, arg1, 0); |
8501 } | 9841 } |
8502 | 9842 |
8503 /* Returns number of zeros at the end of binary representation of X. | 9843 /* Returns number of zeros at the end of binary representation of X. |
8504 | 9844 |
8505 ??? Use ffs if available? */ | 9845 ??? Use ffs if available? */ |
8506 | 9846 |
8507 tree | 9847 tree |
8508 num_ending_zeros (const_tree x) | 9848 num_ending_zeros (const_tree x) |
8509 { | 9849 { |
8827 for (i = 0; i < len; ++i) | 10167 for (i = 0; i < len; ++i) |
8828 WALK_SUBTREE (TREE_OPERAND (*tp, i)); | 10168 WALK_SUBTREE (TREE_OPERAND (*tp, i)); |
8829 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp, len)); | 10169 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp, len)); |
8830 } | 10170 } |
8831 | 10171 |
8832 case CHANGE_DYNAMIC_TYPE_EXPR: | |
8833 WALK_SUBTREE (CHANGE_DYNAMIC_TYPE_NEW_TYPE (*tp)); | |
8834 WALK_SUBTREE_TAIL (CHANGE_DYNAMIC_TYPE_LOCATION (*tp)); | |
8835 | |
8836 case DECL_EXPR: | 10172 case DECL_EXPR: |
8837 /* If this is a TYPE_DECL, walk into the fields of the type that it's | 10173 /* If this is a TYPE_DECL, walk into the fields of the type that it's |
8838 defining. We only want to walk into these fields of a type in this | 10174 defining. We only want to walk into these fields of a type in this |
8839 case and not in the general case of a mere reference to the type. | 10175 case and not in the general case of a mere reference to the type. |
8840 | 10176 |
8841 The criterion is as follows: if the field can be an expression, it | 10177 The criterion is as follows: if the field can be an expression, it |
8842 must be walked only here. This should be in keeping with the fields | 10178 must be walked only here. This should be in keeping with the fields |
8843 that are directly gimplified in gimplify_type_sizes in order for the | 10179 that are directly gimplified in gimplify_type_sizes in order for the |
8844 mark/copy-if-shared/unmark machinery of the gimplifier to work with | 10180 mark/copy-if-shared/unmark machinery of the gimplifier to work with |
8845 variable-sized types. | 10181 variable-sized types. |
8846 | 10182 |
8847 Note that DECLs get walked as part of processing the BIND_EXPR. */ | 10183 Note that DECLs get walked as part of processing the BIND_EXPR. */ |
8848 if (TREE_CODE (DECL_EXPR_DECL (*tp)) == TYPE_DECL) | 10184 if (TREE_CODE (DECL_EXPR_DECL (*tp)) == TYPE_DECL) |
8849 { | 10185 { |
8850 tree *type_p = &TREE_TYPE (DECL_EXPR_DECL (*tp)); | 10186 tree *type_p = &TREE_TYPE (DECL_EXPR_DECL (*tp)); |
8851 if (TREE_CODE (*type_p) == ERROR_MARK) | 10187 if (TREE_CODE (*type_p) == ERROR_MARK) |
8861 result = walk_type_fields (*type_p, func, data, pset, lh); | 10197 result = walk_type_fields (*type_p, func, data, pset, lh); |
8862 if (result) | 10198 if (result) |
8863 return result; | 10199 return result; |
8864 | 10200 |
8865 /* If this is a record type, also walk the fields. */ | 10201 /* If this is a record type, also walk the fields. */ |
8866 if (TREE_CODE (*type_p) == RECORD_TYPE | 10202 if (RECORD_OR_UNION_TYPE_P (*type_p)) |
8867 || TREE_CODE (*type_p) == UNION_TYPE | |
8868 || TREE_CODE (*type_p) == QUAL_UNION_TYPE) | |
8869 { | 10203 { |
8870 tree field; | 10204 tree field; |
8871 | 10205 |
8872 for (field = TYPE_FIELDS (*type_p); field; | 10206 for (field = TYPE_FIELDS (*type_p); field; |
8873 field = TREE_CHAIN (field)) | 10207 field = TREE_CHAIN (field)) |
8974 arglist = tree_cons (NULL_TREE, CALL_EXPR_ARG (exp, i), arglist); | 10308 arglist = tree_cons (NULL_TREE, CALL_EXPR_ARG (exp, i), arglist); |
8975 return arglist; | 10309 return arglist; |
8976 } | 10310 } |
8977 | 10311 |
8978 | 10312 |
8979 /* Create a nameless artificial label and put it in the current function | 10313 /* Create a nameless artificial label and put it in the current |
8980 context. Returns the newly created label. */ | 10314 function context. The label has a location of LOC. Returns the |
8981 | 10315 newly created label. */ |
8982 tree | 10316 |
8983 create_artificial_label (void) | 10317 tree |
8984 { | 10318 create_artificial_label (location_t loc) |
8985 tree lab = build_decl (LABEL_DECL, NULL_TREE, void_type_node); | 10319 { |
10320 tree lab = build_decl (loc, | |
10321 LABEL_DECL, NULL_TREE, void_type_node); | |
8986 | 10322 |
8987 DECL_ARTIFICIAL (lab) = 1; | 10323 DECL_ARTIFICIAL (lab) = 1; |
8988 DECL_IGNORED_P (lab) = 1; | 10324 DECL_IGNORED_P (lab) = 1; |
8989 DECL_CONTEXT (lab) = current_function_decl; | 10325 DECL_CONTEXT (lab) = current_function_decl; |
8990 return lab; | 10326 return lab; |
9043 | 10379 |
9044 gcc_assert (fntype != NULL_TREE); | 10380 gcc_assert (fntype != NULL_TREE); |
9045 | 10381 |
9046 t = TYPE_ARG_TYPES (fntype); | 10382 t = TYPE_ARG_TYPES (fntype); |
9047 return (t != NULL_TREE); | 10383 return (t != NULL_TREE); |
9048 } | |
9049 | |
9050 /* Return the number of arguments that a function has. */ | |
9051 | |
9052 int | |
9053 function_args_count (tree fntype) | |
9054 { | |
9055 function_args_iterator args_iter; | |
9056 tree t; | |
9057 int num = 0; | |
9058 | |
9059 if (fntype) | |
9060 { | |
9061 FOREACH_FUNCTION_ARGS(fntype, t, args_iter) | |
9062 { | |
9063 num++; | |
9064 } | |
9065 } | |
9066 | |
9067 return num; | |
9068 } | 10384 } |
9069 | 10385 |
9070 /* If BLOCK is inlined from an __attribute__((__artificial__)) | 10386 /* If BLOCK is inlined from an __attribute__((__artificial__)) |
9071 routine, return pointer to location from where it has been | 10387 routine, return pointer to location from where it has been |
9072 called. */ | 10388 called. */ |
9292 | 10608 |
9293 return ret_val; | 10609 return ret_val; |
9294 } | 10610 } |
9295 } | 10611 } |
9296 | 10612 |
10613 /* Return true if T1 and T2 are equivalent lists. */ | |
10614 | |
10615 bool | |
10616 list_equal_p (const_tree t1, const_tree t2) | |
10617 { | |
10618 for (; t1 && t2; t1 = TREE_CHAIN (t1) , t2 = TREE_CHAIN (t2)) | |
10619 if (TREE_VALUE (t1) != TREE_VALUE (t2)) | |
10620 return false; | |
10621 return !t1 && !t2; | |
10622 } | |
10623 | |
10624 /* Return true iff conversion in EXP generates no instruction. Mark | |
10625 it inline so that we fully inline into the stripping functions even | |
10626 though we have two uses of this function. */ | |
10627 | |
10628 static inline bool | |
10629 tree_nop_conversion (const_tree exp) | |
10630 { | |
10631 tree outer_type, inner_type; | |
10632 | |
10633 if (!CONVERT_EXPR_P (exp) | |
10634 && TREE_CODE (exp) != NON_LVALUE_EXPR) | |
10635 return false; | |
10636 if (TREE_OPERAND (exp, 0) == error_mark_node) | |
10637 return false; | |
10638 | |
10639 outer_type = TREE_TYPE (exp); | |
10640 inner_type = TREE_TYPE (TREE_OPERAND (exp, 0)); | |
10641 | |
10642 /* Use precision rather then machine mode when we can, which gives | |
10643 the correct answer even for submode (bit-field) types. */ | |
10644 if ((INTEGRAL_TYPE_P (outer_type) | |
10645 || POINTER_TYPE_P (outer_type) | |
10646 || TREE_CODE (outer_type) == OFFSET_TYPE) | |
10647 && (INTEGRAL_TYPE_P (inner_type) | |
10648 || POINTER_TYPE_P (inner_type) | |
10649 || TREE_CODE (inner_type) == OFFSET_TYPE)) | |
10650 return TYPE_PRECISION (outer_type) == TYPE_PRECISION (inner_type); | |
10651 | |
10652 /* Otherwise fall back on comparing machine modes (e.g. for | |
10653 aggregate types, floats). */ | |
10654 return TYPE_MODE (outer_type) == TYPE_MODE (inner_type); | |
10655 } | |
10656 | |
10657 /* Return true iff conversion in EXP generates no instruction. Don't | |
10658 consider conversions changing the signedness. */ | |
10659 | |
10660 static bool | |
10661 tree_sign_nop_conversion (const_tree exp) | |
10662 { | |
10663 tree outer_type, inner_type; | |
10664 | |
10665 if (!tree_nop_conversion (exp)) | |
10666 return false; | |
10667 | |
10668 outer_type = TREE_TYPE (exp); | |
10669 inner_type = TREE_TYPE (TREE_OPERAND (exp, 0)); | |
10670 | |
10671 return (TYPE_UNSIGNED (outer_type) == TYPE_UNSIGNED (inner_type) | |
10672 && POINTER_TYPE_P (outer_type) == POINTER_TYPE_P (inner_type)); | |
10673 } | |
10674 | |
10675 /* Strip conversions from EXP according to tree_nop_conversion and | |
10676 return the resulting expression. */ | |
10677 | |
10678 tree | |
10679 tree_strip_nop_conversions (tree exp) | |
10680 { | |
10681 while (tree_nop_conversion (exp)) | |
10682 exp = TREE_OPERAND (exp, 0); | |
10683 return exp; | |
10684 } | |
10685 | |
10686 /* Strip conversions from EXP according to tree_sign_nop_conversion | |
10687 and return the resulting expression. */ | |
10688 | |
10689 tree | |
10690 tree_strip_sign_nop_conversions (tree exp) | |
10691 { | |
10692 while (tree_sign_nop_conversion (exp)) | |
10693 exp = TREE_OPERAND (exp, 0); | |
10694 return exp; | |
10695 } | |
10696 | |
10697 static GTY(()) tree gcc_eh_personality_decl; | |
10698 | |
10699 /* Return the GCC personality function decl. */ | |
10700 | |
10701 tree | |
10702 lhd_gcc_personality (void) | |
10703 { | |
10704 if (!gcc_eh_personality_decl) | |
10705 gcc_eh_personality_decl | |
10706 = build_personality_function (USING_SJLJ_EXCEPTIONS | |
10707 ? "__gcc_personality_sj0" | |
10708 : "__gcc_personality_v0"); | |
10709 | |
10710 return gcc_eh_personality_decl; | |
10711 } | |
10712 | |
9297 #include "gt-tree.h" | 10713 #include "gt-tree.h" |