comparison gcc/gimple.c @ 67:f6334be47118

update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
author nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
date Tue, 22 Mar 2011 17:18:12 +0900
parents b7f97abdc517
children 1b10fe6932e1 04ced10e8804
comparison
equal deleted inserted replaced
65:65488c3d617d 67:f6334be47118
27 #include "tree.h" 27 #include "tree.h"
28 #include "ggc.h" 28 #include "ggc.h"
29 #include "hard-reg-set.h" 29 #include "hard-reg-set.h"
30 #include "basic-block.h" 30 #include "basic-block.h"
31 #include "gimple.h" 31 #include "gimple.h"
32 #include "toplev.h"
33 #include "diagnostic.h" 32 #include "diagnostic.h"
34 #include "tree-flow.h" 33 #include "tree-flow.h"
35 #include "value-prof.h" 34 #include "value-prof.h"
36 #include "flags.h" 35 #include "flags.h"
37 #include "alias.h" 36 #include "alias.h"
38 #include "demangle.h" 37 #include "demangle.h"
38 #include "langhooks.h"
39 39
40 /* Global type table. FIXME lto, it should be possible to re-use some 40 /* Global type table. FIXME lto, it should be possible to re-use some
41 of the type hashing routines in tree.c (type_hash_canon, type_hash_lookup, 41 of the type hashing routines in tree.c (type_hash_canon, type_hash_lookup,
42 etc), but those assume that types were built with the various 42 etc), but those assume that types were built with the various
43 build_*_type routines which is not the case with the streamer. */ 43 build_*_type routines which is not the case with the streamer. */
44 static htab_t gimple_types; 44 static GTY((if_marked ("ggc_marked_p"), param_is (union tree_node)))
45 static struct pointer_map_t *type_hash_cache; 45 htab_t gimple_types;
46 46 static GTY((if_marked ("ggc_marked_p"), param_is (union tree_node)))
47 /* Global type comparison cache. */ 47 htab_t gimple_canonical_types;
48 static GTY((if_marked ("tree_int_map_marked_p"), param_is (struct tree_int_map)))
49 htab_t type_hash_cache;
50 static GTY((if_marked ("tree_int_map_marked_p"), param_is (struct tree_int_map)))
51 htab_t canonical_type_hash_cache;
52
53 /* Global type comparison cache. This is by TYPE_UID for space efficiency
54 and thus cannot use and does not need GC. */
48 static htab_t gtc_visited; 55 static htab_t gtc_visited;
49 static struct obstack gtc_ob; 56 static struct obstack gtc_ob;
50 57
51 /* All the tuples have their operand vector (if present) at the very bottom 58 /* All the tuples have their operand vector (if present) at the very bottom
52 of the structure. Therefore, the offset required to find the 59 of the structure. Therefore, the offset required to find the
143 gimple_alloc_counts[(int) kind]++; 150 gimple_alloc_counts[(int) kind]++;
144 gimple_alloc_sizes[(int) kind] += size; 151 gimple_alloc_sizes[(int) kind] += size;
145 } 152 }
146 #endif 153 #endif
147 154
148 stmt = (gimple) ggc_alloc_cleared_stat (size PASS_MEM_STAT); 155 stmt = ggc_alloc_cleared_gimple_statement_d_stat (size PASS_MEM_STAT);
149 gimple_set_code (stmt, code); 156 gimple_set_code (stmt, code);
150 gimple_set_num_ops (stmt, num_ops); 157 gimple_set_num_ops (stmt, num_ops);
151 158
152 /* Do not call gimple_set_modified here as it has other side 159 /* Do not call gimple_set_modified here as it has other side
153 effects and this tuple is still not completely built. */ 160 effects and this tuple is still not completely built. */
303 return call; 310 return call;
304 } 311 }
305 312
306 313
307 /* Extract the operands and code for expression EXPR into *SUBCODE_P, 314 /* Extract the operands and code for expression EXPR into *SUBCODE_P,
308 *OP1_P and *OP2_P respectively. */ 315 *OP1_P, *OP2_P and *OP3_P respectively. */
309 316
310 void 317 void
311 extract_ops_from_tree (tree expr, enum tree_code *subcode_p, tree *op1_p, 318 extract_ops_from_tree_1 (tree expr, enum tree_code *subcode_p, tree *op1_p,
312 tree *op2_p) 319 tree *op2_p, tree *op3_p)
313 { 320 {
314 enum gimple_rhs_class grhs_class; 321 enum gimple_rhs_class grhs_class;
315 322
316 *subcode_p = TREE_CODE (expr); 323 *subcode_p = TREE_CODE (expr);
317 grhs_class = get_gimple_rhs_class (*subcode_p); 324 grhs_class = get_gimple_rhs_class (*subcode_p);
318 325
319 if (grhs_class == GIMPLE_BINARY_RHS) 326 if (grhs_class == GIMPLE_TERNARY_RHS)
320 { 327 {
321 *op1_p = TREE_OPERAND (expr, 0); 328 *op1_p = TREE_OPERAND (expr, 0);
322 *op2_p = TREE_OPERAND (expr, 1); 329 *op2_p = TREE_OPERAND (expr, 1);
330 *op3_p = TREE_OPERAND (expr, 2);
331 }
332 else if (grhs_class == GIMPLE_BINARY_RHS)
333 {
334 *op1_p = TREE_OPERAND (expr, 0);
335 *op2_p = TREE_OPERAND (expr, 1);
336 *op3_p = NULL_TREE;
323 } 337 }
324 else if (grhs_class == GIMPLE_UNARY_RHS) 338 else if (grhs_class == GIMPLE_UNARY_RHS)
325 { 339 {
326 *op1_p = TREE_OPERAND (expr, 0); 340 *op1_p = TREE_OPERAND (expr, 0);
327 *op2_p = NULL_TREE; 341 *op2_p = NULL_TREE;
342 *op3_p = NULL_TREE;
328 } 343 }
329 else if (grhs_class == GIMPLE_SINGLE_RHS) 344 else if (grhs_class == GIMPLE_SINGLE_RHS)
330 { 345 {
331 *op1_p = expr; 346 *op1_p = expr;
332 *op2_p = NULL_TREE; 347 *op2_p = NULL_TREE;
348 *op3_p = NULL_TREE;
333 } 349 }
334 else 350 else
335 gcc_unreachable (); 351 gcc_unreachable ();
336 } 352 }
337 353
343 359
344 gimple 360 gimple
345 gimple_build_assign_stat (tree lhs, tree rhs MEM_STAT_DECL) 361 gimple_build_assign_stat (tree lhs, tree rhs MEM_STAT_DECL)
346 { 362 {
347 enum tree_code subcode; 363 enum tree_code subcode;
348 tree op1, op2; 364 tree op1, op2, op3;
349 365
350 extract_ops_from_tree (rhs, &subcode, &op1, &op2); 366 extract_ops_from_tree_1 (rhs, &subcode, &op1, &op2, &op3);
351 return gimple_build_assign_with_ops_stat (subcode, lhs, op1, op2 367 return gimple_build_assign_with_ops_stat (subcode, lhs, op1, op2, op3
352 PASS_MEM_STAT); 368 PASS_MEM_STAT);
353 } 369 }
354 370
355 371
356 /* Build a GIMPLE_ASSIGN statement with sub-code SUBCODE and operands 372 /* Build a GIMPLE_ASSIGN statement with sub-code SUBCODE and operands
357 OP1 and OP2. If OP2 is NULL then SUBCODE must be of class 373 OP1 and OP2. If OP2 is NULL then SUBCODE must be of class
358 GIMPLE_UNARY_RHS or GIMPLE_SINGLE_RHS. */ 374 GIMPLE_UNARY_RHS or GIMPLE_SINGLE_RHS. */
359 375
360 gimple 376 gimple
361 gimple_build_assign_with_ops_stat (enum tree_code subcode, tree lhs, tree op1, 377 gimple_build_assign_with_ops_stat (enum tree_code subcode, tree lhs, tree op1,
362 tree op2 MEM_STAT_DECL) 378 tree op2, tree op3 MEM_STAT_DECL)
363 { 379 {
364 unsigned num_ops; 380 unsigned num_ops;
365 gimple p; 381 gimple p;
366 382
367 /* Need 1 operand for LHS and 1 or 2 for the RHS (depending on the 383 /* Need 1 operand for LHS and 1 or 2 for the RHS (depending on the
374 gimple_assign_set_rhs1 (p, op1); 390 gimple_assign_set_rhs1 (p, op1);
375 if (op2) 391 if (op2)
376 { 392 {
377 gcc_assert (num_ops > 2); 393 gcc_assert (num_ops > 2);
378 gimple_assign_set_rhs2 (p, op2); 394 gimple_assign_set_rhs2 (p, op2);
395 }
396
397 if (op3)
398 {
399 gcc_assert (num_ops > 3);
400 gimple_assign_set_rhs3 (p, op3);
379 } 401 }
380 402
381 return p; 403 return p;
382 } 404 }
383 405
426 448
427 void 449 void
428 gimple_cond_get_ops_from_tree (tree cond, enum tree_code *code_p, 450 gimple_cond_get_ops_from_tree (tree cond, enum tree_code *code_p,
429 tree *lhs_p, tree *rhs_p) 451 tree *lhs_p, tree *rhs_p)
430 { 452 {
431 location_t loc = EXPR_LOCATION (cond);
432 gcc_assert (TREE_CODE_CLASS (TREE_CODE (cond)) == tcc_comparison 453 gcc_assert (TREE_CODE_CLASS (TREE_CODE (cond)) == tcc_comparison
433 || TREE_CODE (cond) == TRUTH_NOT_EXPR 454 || TREE_CODE (cond) == TRUTH_NOT_EXPR
434 || is_gimple_min_invariant (cond) 455 || is_gimple_min_invariant (cond)
435 || SSA_VAR_P (cond)); 456 || SSA_VAR_P (cond));
436 457
439 /* Canonicalize conditionals of the form 'if (!VAL)'. */ 460 /* Canonicalize conditionals of the form 'if (!VAL)'. */
440 if (*code_p == TRUTH_NOT_EXPR) 461 if (*code_p == TRUTH_NOT_EXPR)
441 { 462 {
442 *code_p = EQ_EXPR; 463 *code_p = EQ_EXPR;
443 gcc_assert (*lhs_p && *rhs_p == NULL_TREE); 464 gcc_assert (*lhs_p && *rhs_p == NULL_TREE);
444 *rhs_p = fold_convert_loc (loc, TREE_TYPE (*lhs_p), integer_zero_node); 465 *rhs_p = build_zero_cst (TREE_TYPE (*lhs_p));
445 } 466 }
446 /* Canonicalize conditionals of the form 'if (VAL)' */ 467 /* Canonicalize conditionals of the form 'if (VAL)' */
447 else if (TREE_CODE_CLASS (*code_p) != tcc_comparison) 468 else if (TREE_CODE_CLASS (*code_p) != tcc_comparison)
448 { 469 {
449 *code_p = NE_EXPR; 470 *code_p = NE_EXPR;
450 gcc_assert (*lhs_p && *rhs_p == NULL_TREE); 471 gcc_assert (*lhs_p && *rhs_p == NULL_TREE);
451 *rhs_p = fold_convert_loc (loc, TREE_TYPE (*lhs_p), integer_zero_node); 472 *rhs_p = build_zero_cst (TREE_TYPE (*lhs_p));
452 } 473 }
453 } 474 }
454 475
455 476
456 /* Build a GIMPLE_COND statement from the conditional expression tree 477 /* Build a GIMPLE_COND statement from the conditional expression tree
822 gimple p = gimple_alloc (GIMPLE_OMP_FOR, 0); 843 gimple p = gimple_alloc (GIMPLE_OMP_FOR, 0);
823 if (body) 844 if (body)
824 gimple_omp_set_body (p, body); 845 gimple_omp_set_body (p, body);
825 gimple_omp_for_set_clauses (p, clauses); 846 gimple_omp_for_set_clauses (p, clauses);
826 p->gimple_omp_for.collapse = collapse; 847 p->gimple_omp_for.collapse = collapse;
827 p->gimple_omp_for.iter = GGC_CNEWVEC (struct gimple_omp_for_iter, collapse); 848 p->gimple_omp_for.iter
849 = ggc_alloc_cleared_vec_gimple_omp_for_iter (collapse);
828 if (pre_body) 850 if (pre_body)
829 gimple_omp_for_set_pre_body (p, pre_body); 851 gimple_omp_for_set_pre_body (p, pre_body);
830 852
831 return p; 853 return p;
832 } 854 }
1072 gcc_assert (gimple_seq_cache != seq); 1094 gcc_assert (gimple_seq_cache != seq);
1073 memset (seq, 0, sizeof (*seq)); 1095 memset (seq, 0, sizeof (*seq));
1074 } 1096 }
1075 else 1097 else
1076 { 1098 {
1077 seq = (gimple_seq) ggc_alloc_cleared (sizeof (*seq)); 1099 seq = ggc_alloc_cleared_gimple_seq_d ();
1078 #ifdef GATHER_STATISTICS 1100 #ifdef GATHER_STATISTICS
1079 gimple_alloc_counts[(int) gimple_alloc_kind_seq]++; 1101 gimple_alloc_counts[(int) gimple_alloc_kind_seq]++;
1080 gimple_alloc_sizes[(int) gimple_alloc_kind_seq] += sizeof (*seq); 1102 gimple_alloc_sizes[(int) gimple_alloc_kind_seq] += sizeof (*seq);
1081 #endif 1103 #endif
1082 } 1104 }
1365 } 1387 }
1366 break; 1388 break;
1367 1389
1368 case GIMPLE_CALL: 1390 case GIMPLE_CALL:
1369 if (wi) 1391 if (wi)
1370 wi->is_lhs = false; 1392 {
1393 wi->is_lhs = false;
1394 wi->val_only = true;
1395 }
1371 1396
1372 ret = walk_tree (gimple_call_chain_ptr (stmt), callback_op, wi, pset); 1397 ret = walk_tree (gimple_call_chain_ptr (stmt), callback_op, wi, pset);
1373 if (ret) 1398 if (ret)
1374 return ret; 1399 return ret;
1375 1400
1377 if (ret) 1402 if (ret)
1378 return ret; 1403 return ret;
1379 1404
1380 for (i = 0; i < gimple_call_num_args (stmt); i++) 1405 for (i = 0; i < gimple_call_num_args (stmt); i++)
1381 { 1406 {
1407 if (wi)
1408 wi->val_only = is_gimple_reg_type (gimple_call_arg (stmt, i));
1382 ret = walk_tree (gimple_call_arg_ptr (stmt, i), callback_op, wi, 1409 ret = walk_tree (gimple_call_arg_ptr (stmt, i), callback_op, wi,
1383 pset); 1410 pset);
1384 if (ret) 1411 if (ret)
1385 return ret; 1412 return ret;
1386 } 1413 }
1387 1414
1415 if (gimple_call_lhs (stmt))
1416 {
1417 if (wi)
1418 {
1419 wi->is_lhs = true;
1420 wi->val_only = is_gimple_reg_type (gimple_call_lhs (stmt));
1421 }
1422
1423 ret = walk_tree (gimple_call_lhs_ptr (stmt), callback_op, wi, pset);
1424 if (ret)
1425 return ret;
1426 }
1427
1388 if (wi) 1428 if (wi)
1389 wi->is_lhs = true; 1429 {
1390 1430 wi->is_lhs = false;
1391 ret = walk_tree (gimple_call_lhs_ptr (stmt), callback_op, wi, pset); 1431 wi->val_only = true;
1392 if (ret) 1432 }
1393 return ret;
1394
1395 if (wi)
1396 wi->is_lhs = false;
1397 break; 1433 break;
1398 1434
1399 case GIMPLE_CATCH: 1435 case GIMPLE_CATCH:
1400 ret = walk_tree (gimple_catch_types_ptr (stmt), callback_op, wi, 1436 ret = walk_tree (gimple_catch_types_ptr (stmt), callback_op, wi,
1401 pset); 1437 pset);
1713 else 1749 else
1714 fn->gimple_body = seq; 1750 fn->gimple_body = seq;
1715 } 1751 }
1716 1752
1717 1753
1718 /* Return the body of GIMPLE statements for function FN. */ 1754 /* Return the body of GIMPLE statements for function FN. After the
1755 CFG pass, the function body doesn't exist anymore because it has
1756 been split up into basic blocks. In this case, it returns
1757 NULL. */
1719 1758
1720 gimple_seq 1759 gimple_seq
1721 gimple_body (tree fndecl) 1760 gimple_body (tree fndecl)
1722 { 1761 {
1723 struct function *fn = DECL_STRUCT_FUNCTION (fndecl); 1762 struct function *fn = DECL_STRUCT_FUNCTION (fndecl);
1833 default: 1872 default:
1834 return 0; 1873 return 0;
1835 } 1874 }
1836 } 1875 }
1837 1876
1877
1838 /* Return true if GS is a copy assignment. */ 1878 /* Return true if GS is a copy assignment. */
1839 1879
1840 bool 1880 bool
1841 gimple_assign_copy_p (gimple gs) 1881 gimple_assign_copy_p (gimple gs)
1842 { 1882 {
1843 return gimple_code (gs) == GIMPLE_ASSIGN 1883 return (gimple_assign_single_p (gs)
1844 && get_gimple_rhs_class (gimple_assign_rhs_code (gs)) 1884 && is_gimple_val (gimple_op (gs, 1)));
1845 == GIMPLE_SINGLE_RHS
1846 && is_gimple_val (gimple_op (gs, 1));
1847 } 1885 }
1848 1886
1849 1887
1850 /* Return true if GS is a SSA_NAME copy assignment. */ 1888 /* Return true if GS is a SSA_NAME copy assignment. */
1851 1889
1852 bool 1890 bool
1853 gimple_assign_ssa_name_copy_p (gimple gs) 1891 gimple_assign_ssa_name_copy_p (gimple gs)
1854 { 1892 {
1855 return (gimple_code (gs) == GIMPLE_ASSIGN 1893 return (gimple_assign_single_p (gs)
1856 && (get_gimple_rhs_class (gimple_assign_rhs_code (gs))
1857 == GIMPLE_SINGLE_RHS)
1858 && TREE_CODE (gimple_assign_lhs (gs)) == SSA_NAME 1894 && TREE_CODE (gimple_assign_lhs (gs)) == SSA_NAME
1859 && TREE_CODE (gimple_assign_rhs1 (gs)) == SSA_NAME); 1895 && TREE_CODE (gimple_assign_rhs1 (gs)) == SSA_NAME);
1860 } 1896 }
1861 1897
1862
1863 /* Return true if GS is an assignment with a singleton RHS, i.e.,
1864 there is no operator associated with the assignment itself.
1865 Unlike gimple_assign_copy_p, this predicate returns true for
1866 any RHS operand, including those that perform an operation
1867 and do not have the semantics of a copy, such as COND_EXPR. */
1868
1869 bool
1870 gimple_assign_single_p (gimple gs)
1871 {
1872 return (gimple_code (gs) == GIMPLE_ASSIGN
1873 && get_gimple_rhs_class (gimple_assign_rhs_code (gs))
1874 == GIMPLE_SINGLE_RHS);
1875 }
1876 1898
1877 /* Return true if GS is an assignment with a unary RHS, but the 1899 /* Return true if GS is an assignment with a unary RHS, but the
1878 operator has no effect on the assigned value. The logic is adapted 1900 operator has no effect on the assigned value. The logic is adapted
1879 from STRIP_NOPS. This predicate is intended to be used in tuplifying 1901 from STRIP_NOPS. This predicate is intended to be used in tuplifying
1880 instances in which STRIP_NOPS was previously applied to the RHS of 1902 instances in which STRIP_NOPS was previously applied to the RHS of
1889 treatment of unary NOPs is appropriate. */ 1911 treatment of unary NOPs is appropriate. */
1890 1912
1891 bool 1913 bool
1892 gimple_assign_unary_nop_p (gimple gs) 1914 gimple_assign_unary_nop_p (gimple gs)
1893 { 1915 {
1894 return (gimple_code (gs) == GIMPLE_ASSIGN 1916 return (is_gimple_assign (gs)
1895 && (CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (gs)) 1917 && (CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (gs))
1896 || gimple_assign_rhs_code (gs) == NON_LVALUE_EXPR) 1918 || gimple_assign_rhs_code (gs) == NON_LVALUE_EXPR)
1897 && gimple_assign_rhs1 (gs) != error_mark_node 1919 && gimple_assign_rhs1 (gs) != error_mark_node
1898 && (TYPE_MODE (TREE_TYPE (gimple_assign_lhs (gs))) 1920 && (TYPE_MODE (TREE_TYPE (gimple_assign_lhs (gs)))
1899 == TYPE_MODE (TREE_TYPE (gimple_assign_rhs1 (gs))))); 1921 == TYPE_MODE (TREE_TYPE (gimple_assign_rhs1 (gs)))));
1952 1974
1953 void 1975 void
1954 gimple_assign_set_rhs_from_tree (gimple_stmt_iterator *gsi, tree expr) 1976 gimple_assign_set_rhs_from_tree (gimple_stmt_iterator *gsi, tree expr)
1955 { 1977 {
1956 enum tree_code subcode; 1978 enum tree_code subcode;
1957 tree op1, op2; 1979 tree op1, op2, op3;
1958 1980
1959 extract_ops_from_tree (expr, &subcode, &op1, &op2); 1981 extract_ops_from_tree_1 (expr, &subcode, &op1, &op2, &op3);
1960 gimple_assign_set_rhs_with_ops (gsi, subcode, op1, op2); 1982 gimple_assign_set_rhs_with_ops_1 (gsi, subcode, op1, op2, op3);
1961 } 1983 }
1962 1984
1963 1985
1964 /* Set the RHS of assignment statement pointed-to by GSI to CODE with 1986 /* Set the RHS of assignment statement pointed-to by GSI to CODE with
1965 operands OP1 and OP2. 1987 operands OP1, OP2 and OP3.
1966 1988
1967 NOTE: The statement pointed-to by GSI may be reallocated if it 1989 NOTE: The statement pointed-to by GSI may be reallocated if it
1968 did not have enough operand slots. */ 1990 did not have enough operand slots. */
1969 1991
1970 void 1992 void
1971 gimple_assign_set_rhs_with_ops (gimple_stmt_iterator *gsi, enum tree_code code, 1993 gimple_assign_set_rhs_with_ops_1 (gimple_stmt_iterator *gsi, enum tree_code code,
1972 tree op1, tree op2) 1994 tree op1, tree op2, tree op3)
1973 { 1995 {
1974 unsigned new_rhs_ops = get_gimple_rhs_num_ops (code); 1996 unsigned new_rhs_ops = get_gimple_rhs_num_ops (code);
1975 gimple stmt = gsi_stmt (*gsi); 1997 gimple stmt = gsi_stmt (*gsi);
1976 1998
1977 /* If the new CODE needs more operands, allocate a new statement. */ 1999 /* If the new CODE needs more operands, allocate a new statement. */
1991 gimple_set_num_ops (stmt, new_rhs_ops + 1); 2013 gimple_set_num_ops (stmt, new_rhs_ops + 1);
1992 gimple_set_subcode (stmt, code); 2014 gimple_set_subcode (stmt, code);
1993 gimple_assign_set_rhs1 (stmt, op1); 2015 gimple_assign_set_rhs1 (stmt, op1);
1994 if (new_rhs_ops > 1) 2016 if (new_rhs_ops > 1)
1995 gimple_assign_set_rhs2 (stmt, op2); 2017 gimple_assign_set_rhs2 (stmt, op2);
2018 if (new_rhs_ops > 2)
2019 gimple_assign_set_rhs3 (stmt, op3);
1996 } 2020 }
1997 2021
1998 2022
1999 /* Return the LHS of a statement that performs an assignment, 2023 /* Return the LHS of a statement that performs an assignment,
2000 either a GIMPLE_ASSIGN or a GIMPLE_CALL. Returns NULL_TREE 2024 either a GIMPLE_ASSIGN or a GIMPLE_CALL. Returns NULL_TREE
2120 new_seq = gimple_seq_copy (gimple_omp_for_pre_body (stmt)); 2144 new_seq = gimple_seq_copy (gimple_omp_for_pre_body (stmt));
2121 gimple_omp_for_set_pre_body (copy, new_seq); 2145 gimple_omp_for_set_pre_body (copy, new_seq);
2122 t = unshare_expr (gimple_omp_for_clauses (stmt)); 2146 t = unshare_expr (gimple_omp_for_clauses (stmt));
2123 gimple_omp_for_set_clauses (copy, t); 2147 gimple_omp_for_set_clauses (copy, t);
2124 copy->gimple_omp_for.iter 2148 copy->gimple_omp_for.iter
2125 = GGC_NEWVEC (struct gimple_omp_for_iter, 2149 = ggc_alloc_vec_gimple_omp_for_iter
2126 gimple_omp_for_collapse (stmt)); 2150 (gimple_omp_for_collapse (stmt));
2127 for (i = 0; i < gimple_omp_for_collapse (stmt); i++) 2151 for (i = 0; i < gimple_omp_for_collapse (stmt); i++)
2128 { 2152 {
2129 gimple_omp_for_set_cond (copy, i, 2153 gimple_omp_for_set_cond (copy, i,
2130 gimple_omp_for_cond (stmt, i)); 2154 gimple_omp_for_cond (stmt, i));
2131 gimple_omp_for_set_index (copy, i, 2155 gimple_omp_for_set_index (copy, i,
2362 } 2386 }
2363 2387
2364 return false; 2388 return false;
2365 } 2389 }
2366 2390
2367
2368 /* Helper for gimple_could_trap_p and gimple_assign_rhs_could_trap_p. 2391 /* Helper for gimple_could_trap_p and gimple_assign_rhs_could_trap_p.
2369 Return true if S can trap. If INCLUDE_LHS is true and S is a 2392 Return true if S can trap. When INCLUDE_MEM is true, check whether
2370 GIMPLE_ASSIGN, the LHS of the assignment is also checked. 2393 the memory operations could trap. When INCLUDE_STORES is true and
2371 Otherwise, only the RHS of the assignment is checked. */ 2394 S is a GIMPLE_ASSIGN, the LHS of the assignment is also checked. */
2372 2395
2373 static bool 2396 bool
2374 gimple_could_trap_p_1 (gimple s, bool include_lhs) 2397 gimple_could_trap_p_1 (gimple s, bool include_mem, bool include_stores)
2375 { 2398 {
2376 unsigned i, start;
2377 tree t, div = NULL_TREE; 2399 tree t, div = NULL_TREE;
2378 enum tree_code op; 2400 enum tree_code op;
2379 2401
2380 start = (is_gimple_assign (s) && !include_lhs) ? 1 : 0; 2402 if (include_mem)
2381 2403 {
2382 for (i = start; i < gimple_num_ops (s); i++) 2404 unsigned i, start = (is_gimple_assign (s) && !include_stores) ? 1 : 0;
2383 if (tree_could_trap_p (gimple_op (s, i))) 2405
2384 return true; 2406 for (i = start; i < gimple_num_ops (s); i++)
2407 if (tree_could_trap_p (gimple_op (s, i)))
2408 return true;
2409 }
2385 2410
2386 switch (gimple_code (s)) 2411 switch (gimple_code (s))
2387 { 2412 {
2388 case GIMPLE_ASM: 2413 case GIMPLE_ASM:
2389 return gimple_asm_volatile_p (s); 2414 return gimple_asm_volatile_p (s);
2408 default: 2433 default:
2409 break; 2434 break;
2410 } 2435 }
2411 2436
2412 return false; 2437 return false;
2413 2438 }
2414 }
2415
2416 2439
2417 /* Return true if statement S can trap. */ 2440 /* Return true if statement S can trap. */
2418 2441
2419 bool 2442 bool
2420 gimple_could_trap_p (gimple s) 2443 gimple_could_trap_p (gimple s)
2421 { 2444 {
2422 return gimple_could_trap_p_1 (s, true); 2445 return gimple_could_trap_p_1 (s, true, true);
2423 } 2446 }
2424
2425 2447
2426 /* Return true if RHS of a GIMPLE_ASSIGN S can trap. */ 2448 /* Return true if RHS of a GIMPLE_ASSIGN S can trap. */
2427 2449
2428 bool 2450 bool
2429 gimple_assign_rhs_could_trap_p (gimple s) 2451 gimple_assign_rhs_could_trap_p (gimple s)
2430 { 2452 {
2431 gcc_assert (is_gimple_assign (s)); 2453 gcc_assert (is_gimple_assign (s));
2432 return gimple_could_trap_p_1 (s, false); 2454 return gimple_could_trap_p_1 (s, true, false);
2433 } 2455 }
2434 2456
2435 2457
2436 /* Print debugging information for gimple stmts generated. */ 2458 /* Print debugging information for gimple stmts generated. */
2437 2459
2470 2492
2471 if (rhs_class == GIMPLE_UNARY_RHS || rhs_class == GIMPLE_SINGLE_RHS) 2493 if (rhs_class == GIMPLE_UNARY_RHS || rhs_class == GIMPLE_SINGLE_RHS)
2472 return 1; 2494 return 1;
2473 else if (rhs_class == GIMPLE_BINARY_RHS) 2495 else if (rhs_class == GIMPLE_BINARY_RHS)
2474 return 2; 2496 return 2;
2497 else if (rhs_class == GIMPLE_TERNARY_RHS)
2498 return 3;
2475 else 2499 else
2476 gcc_unreachable (); 2500 gcc_unreachable ();
2477 } 2501 }
2478 2502
2479 #define DEFTREECODE(SYM, STRING, TYPE, NARGS) \ 2503 #define DEFTREECODE(SYM, STRING, TYPE, NARGS) \
2486 || (TYPE) == tcc_reference) ? GIMPLE_SINGLE_RHS \ 2510 || (TYPE) == tcc_reference) ? GIMPLE_SINGLE_RHS \
2487 : ((SYM) == TRUTH_AND_EXPR \ 2511 : ((SYM) == TRUTH_AND_EXPR \
2488 || (SYM) == TRUTH_OR_EXPR \ 2512 || (SYM) == TRUTH_OR_EXPR \
2489 || (SYM) == TRUTH_XOR_EXPR) ? GIMPLE_BINARY_RHS \ 2513 || (SYM) == TRUTH_XOR_EXPR) ? GIMPLE_BINARY_RHS \
2490 : (SYM) == TRUTH_NOT_EXPR ? GIMPLE_UNARY_RHS \ 2514 : (SYM) == TRUTH_NOT_EXPR ? GIMPLE_UNARY_RHS \
2515 : ((SYM) == WIDEN_MULT_PLUS_EXPR \
2516 || (SYM) == WIDEN_MULT_MINUS_EXPR \
2517 || (SYM) == FMA_EXPR) ? GIMPLE_TERNARY_RHS \
2491 : ((SYM) == COND_EXPR \ 2518 : ((SYM) == COND_EXPR \
2492 || (SYM) == CONSTRUCTOR \ 2519 || (SYM) == CONSTRUCTOR \
2493 || (SYM) == OBJ_TYPE_REF \ 2520 || (SYM) == OBJ_TYPE_REF \
2494 || (SYM) == ASSERT_EXPR \ 2521 || (SYM) == ASSERT_EXPR \
2495 || (SYM) == ADDR_EXPR \ 2522 || (SYM) == ADDR_EXPR \
2511 2538
2512 /* For the definitive definition of GIMPLE, see doc/tree-ssa.texi. */ 2539 /* For the definitive definition of GIMPLE, see doc/tree-ssa.texi. */
2513 2540
2514 /* Validation of GIMPLE expressions. */ 2541 /* Validation of GIMPLE expressions. */
2515 2542
2516 /* Return true if OP is an acceptable tree node to be used as a GIMPLE
2517 operand. */
2518
2519 bool
2520 is_gimple_operand (const_tree op)
2521 {
2522 return op && get_gimple_rhs_class (TREE_CODE (op)) == GIMPLE_SINGLE_RHS;
2523 }
2524
2525 /* Returns true iff T is a valid RHS for an assignment to a renamed 2543 /* Returns true iff T is a valid RHS for an assignment to a renamed
2526 user -- or front-end generated artificial -- variable. */ 2544 user -- or front-end generated artificial -- variable. */
2527 2545
2528 bool 2546 bool
2529 is_gimple_reg_rhs (tree t) 2547 is_gimple_reg_rhs (tree t)
2571 /* Return true if T is something whose address can be taken. */ 2589 /* Return true if T is something whose address can be taken. */
2572 2590
2573 bool 2591 bool
2574 is_gimple_addressable (tree t) 2592 is_gimple_addressable (tree t)
2575 { 2593 {
2576 return (is_gimple_id (t) || handled_component_p (t) || INDIRECT_REF_P (t)); 2594 return (is_gimple_id (t) || handled_component_p (t)
2595 || TREE_CODE (t) == MEM_REF);
2577 } 2596 }
2578 2597
2579 /* Return true if T is a valid gimple constant. */ 2598 /* Return true if T is a valid gimple constant. */
2580 2599
2581 bool 2600 bool
2622 return false; 2641 return false;
2623 2642
2624 op = TREE_OPERAND (op, 0); 2643 op = TREE_OPERAND (op, 0);
2625 } 2644 }
2626 2645
2627 if (CONSTANT_CLASS_P (op) || INDIRECT_REF_P (op)) 2646 if (CONSTANT_CLASS_P (op) || TREE_CODE (op) == MEM_REF)
2628 return true; 2647 return true;
2629 2648
2630 switch (TREE_CODE (op)) 2649 switch (TREE_CODE (op))
2631 { 2650 {
2632 case PARM_DECL: 2651 case PARM_DECL:
2682 2701
2683 if (TREE_CODE (t) != ADDR_EXPR) 2702 if (TREE_CODE (t) != ADDR_EXPR)
2684 return false; 2703 return false;
2685 2704
2686 op = strip_invariant_refs (TREE_OPERAND (t, 0)); 2705 op = strip_invariant_refs (TREE_OPERAND (t, 0));
2687 2706 if (!op)
2688 return op && (CONSTANT_CLASS_P (op) || decl_address_invariant_p (op)); 2707 return false;
2708
2709 if (TREE_CODE (op) == MEM_REF)
2710 {
2711 const_tree op0 = TREE_OPERAND (op, 0);
2712 return (TREE_CODE (op0) == ADDR_EXPR
2713 && (CONSTANT_CLASS_P (TREE_OPERAND (op0, 0))
2714 || decl_address_invariant_p (TREE_OPERAND (op0, 0))));
2715 }
2716
2717 return CONSTANT_CLASS_P (op) || decl_address_invariant_p (op);
2689 } 2718 }
2690 2719
2691 /* Return true if T is a gimple invariant address at IPA level 2720 /* Return true if T is a gimple invariant address at IPA level
2692 (so addresses of variables on stack are not allowed). */ 2721 (so addresses of variables on stack are not allowed). */
2693 2722
2900 bool 2929 bool
2901 is_gimple_min_lval (tree t) 2930 is_gimple_min_lval (tree t)
2902 { 2931 {
2903 if (!(t = CONST_CAST_TREE (strip_invariant_refs (t)))) 2932 if (!(t = CONST_CAST_TREE (strip_invariant_refs (t))))
2904 return false; 2933 return false;
2905 return (is_gimple_id (t) || TREE_CODE (t) == INDIRECT_REF); 2934 return (is_gimple_id (t) || TREE_CODE (t) == MEM_REF);
2906 }
2907
2908 /* Return true if T is a typecast operation. */
2909
2910 bool
2911 is_gimple_cast (tree t)
2912 {
2913 return (CONVERT_EXPR_P (t)
2914 || TREE_CODE (t) == FIX_TRUNC_EXPR);
2915 } 2935 }
2916 2936
2917 /* Return true if T is a valid function operand of a CALL_EXPR. */ 2937 /* Return true if T is a valid function operand of a CALL_EXPR. */
2918 2938
2919 bool 2939 bool
2920 is_gimple_call_addr (tree t) 2940 is_gimple_call_addr (tree t)
2921 { 2941 {
2922 return (TREE_CODE (t) == OBJ_TYPE_REF || is_gimple_val (t)); 2942 return (TREE_CODE (t) == OBJ_TYPE_REF || is_gimple_val (t));
2943 }
2944
2945 /* Return true if T is a valid address operand of a MEM_REF. */
2946
2947 bool
2948 is_gimple_mem_ref_addr (tree t)
2949 {
2950 return (is_gimple_reg (t)
2951 || TREE_CODE (t) == INTEGER_CST
2952 || (TREE_CODE (t) == ADDR_EXPR
2953 && (CONSTANT_CLASS_P (TREE_OPERAND (t, 0))
2954 || decl_address_invariant_p (TREE_OPERAND (t, 0)))));
2923 } 2955 }
2924 2956
2925 /* If T makes a function call, return the corresponding CALL_EXPR operand. 2957 /* If T makes a function call, return the corresponding CALL_EXPR operand.
2926 Otherwise, return NULL_TREE. */ 2958 Otherwise, return NULL_TREE. */
2927 2959
2951 get_base_address (tree t) 2983 get_base_address (tree t)
2952 { 2984 {
2953 while (handled_component_p (t)) 2985 while (handled_component_p (t))
2954 t = TREE_OPERAND (t, 0); 2986 t = TREE_OPERAND (t, 0);
2955 2987
2956 if (SSA_VAR_P (t) 2988 if ((TREE_CODE (t) == MEM_REF
2989 || TREE_CODE (t) == TARGET_MEM_REF)
2990 && TREE_CODE (TREE_OPERAND (t, 0)) == ADDR_EXPR)
2991 t = TREE_OPERAND (TREE_OPERAND (t, 0), 0);
2992
2993 if (TREE_CODE (t) == SSA_NAME
2994 || DECL_P (t)
2957 || TREE_CODE (t) == STRING_CST 2995 || TREE_CODE (t) == STRING_CST
2958 || TREE_CODE (t) == CONSTRUCTOR 2996 || TREE_CODE (t) == CONSTRUCTOR
2959 || INDIRECT_REF_P (t)) 2997 || INDIRECT_REF_P (t)
2998 || TREE_CODE (t) == MEM_REF
2999 || TREE_CODE (t) == TARGET_MEM_REF)
2960 return t; 3000 return t;
2961 else 3001 else
2962 return NULL_TREE; 3002 return NULL_TREE;
2963 } 3003 }
2964 3004
3082 gimple_set_vdef (new_stmt, gimple_vdef (stmt)); 3122 gimple_set_vdef (new_stmt, gimple_vdef (stmt));
3083 3123
3084 gimple_set_block (new_stmt, gimple_block (stmt)); 3124 gimple_set_block (new_stmt, gimple_block (stmt));
3085 if (gimple_has_location (stmt)) 3125 if (gimple_has_location (stmt))
3086 gimple_set_location (new_stmt, gimple_location (stmt)); 3126 gimple_set_location (new_stmt, gimple_location (stmt));
3087 3127 gimple_call_copy_flags (new_stmt, stmt);
3088 /* Carry all the flags to the new GIMPLE_CALL. */
3089 gimple_call_set_chain (new_stmt, gimple_call_chain (stmt)); 3128 gimple_call_set_chain (new_stmt, gimple_call_chain (stmt));
3090 gimple_call_set_tail (new_stmt, gimple_call_tail_p (stmt));
3091 gimple_call_set_cannot_inline (new_stmt, gimple_call_cannot_inline_p (stmt));
3092 gimple_call_set_return_slot_opt (new_stmt, gimple_call_return_slot_opt_p (stmt));
3093 gimple_call_set_from_thunk (new_stmt, gimple_call_from_thunk_p (stmt));
3094 gimple_call_set_va_arg_pack (new_stmt, gimple_call_va_arg_pack_p (stmt));
3095 3129
3096 gimple_set_modified (new_stmt, true); 3130 gimple_set_modified (new_stmt, true);
3097 3131
3098 return new_stmt; 3132 return new_stmt;
3099 } 3133 }
3100 3134
3101 3135
3102 static hashval_t gimple_type_hash (const void *); 3136 static hashval_t gimple_type_hash_1 (const void *, enum gtc_mode);
3103 3137
3104 /* Structure used to maintain a cache of some type pairs compared by 3138 /* Structure used to maintain a cache of some type pairs compared by
3105 gimple_types_compatible_p when comparing aggregate types. There are 3139 gimple_types_compatible_p when comparing aggregate types. There are
3106 four possible values for SAME_P: 3140 three possible values for SAME_P:
3107 3141
3108 -2: The pair (T1, T2) has just been inserted in the table. 3142 -2: The pair (T1, T2) has just been inserted in the table.
3109 -1: The pair (T1, T2) is currently being compared.
3110 0: T1 and T2 are different types. 3143 0: T1 and T2 are different types.
3111 1: T1 and T2 are the same type. 3144 1: T1 and T2 are the same type.
3112 3145
3113 This table is only used when comparing aggregate types to avoid 3146 The two elements in the SAME_P array are indexed by the comparison
3114 infinite recursion due to self-referential types. */ 3147 mode gtc_mode. */
3148
3115 struct type_pair_d 3149 struct type_pair_d
3116 { 3150 {
3117 unsigned int uid1; 3151 unsigned int uid1;
3118 unsigned int uid2; 3152 unsigned int uid2;
3119 int same_p; 3153 signed char same_p[2];
3120 }; 3154 };
3121 typedef struct type_pair_d *type_pair_t; 3155 typedef struct type_pair_d *type_pair_t;
3156
3157 DEF_VEC_P(type_pair_t);
3158 DEF_VEC_ALLOC_P(type_pair_t,heap);
3122 3159
3123 /* Return a hash value for the type pair pointed-to by P. */ 3160 /* Return a hash value for the type pair pointed-to by P. */
3124 3161
3125 static hashval_t 3162 static hashval_t
3126 type_pair_hash (const void *p) 3163 type_pair_hash (const void *p)
3168 else 3205 else
3169 { 3206 {
3170 p = XOBNEW (ob_p, struct type_pair_d); 3207 p = XOBNEW (ob_p, struct type_pair_d);
3171 p->uid1 = TYPE_UID (t1); 3208 p->uid1 = TYPE_UID (t1);
3172 p->uid2 = TYPE_UID (t2); 3209 p->uid2 = TYPE_UID (t2);
3173 p->same_p = -2; 3210 p->same_p[0] = -2;
3211 p->same_p[1] = -2;
3174 *slot = (void *) p; 3212 *slot = (void *) p;
3175 } 3213 }
3176 3214
3177 return p; 3215 return p;
3178 } 3216 }
3179 3217
3218 /* Per pointer state for the SCC finding. The on_sccstack flag
3219 is not strictly required, it is true when there is no hash value
3220 recorded for the type and false otherwise. But querying that
3221 is slower. */
3222
3223 struct sccs
3224 {
3225 unsigned int dfsnum;
3226 unsigned int low;
3227 bool on_sccstack;
3228 union {
3229 hashval_t hash;
3230 signed char same_p;
3231 } u;
3232 };
3233
3234 static unsigned int next_dfs_num;
3235 static unsigned int gtc_next_dfs_num;
3236
3237
3238 /* GIMPLE type merging cache. A direct-mapped cache based on TYPE_UID. */
3239
3240 typedef struct GTY(()) gimple_type_leader_entry_s {
3241 tree type;
3242 tree leader;
3243 } gimple_type_leader_entry;
3244
3245 #define GIMPLE_TYPE_LEADER_SIZE 16381
3246 static GTY((length("GIMPLE_TYPE_LEADER_SIZE"))) gimple_type_leader_entry
3247 *gimple_type_leader;
3248
3249 /* Lookup an existing leader for T and return it or NULL_TREE, if
3250 there is none in the cache. */
3251
3252 static tree
3253 gimple_lookup_type_leader (tree t)
3254 {
3255 gimple_type_leader_entry *leader;
3256
3257 if (!gimple_type_leader)
3258 return NULL_TREE;
3259
3260 leader = &gimple_type_leader[TYPE_UID (t) % GIMPLE_TYPE_LEADER_SIZE];
3261 if (leader->type != t)
3262 return NULL_TREE;
3263
3264 return leader->leader;
3265 }
3180 3266
3181 /* Return true if T1 and T2 have the same name. If FOR_COMPLETION_P is 3267 /* Return true if T1 and T2 have the same name. If FOR_COMPLETION_P is
3182 true then if any type has no name return false, otherwise return 3268 true then if any type has no name return false, otherwise return
3183 true if both types have no names. */ 3269 true if both types have no names. */
3184 3270
3269 } 3355 }
3270 3356
3271 return false; 3357 return false;
3272 } 3358 }
3273 3359
3274 /* Return 1 iff T1 and T2 are structurally identical. 3360 /* If the type T1 and the type T2 are a complete and an incomplete
3275 Otherwise, return 0. */ 3361 variant of the same type return true. */
3276 3362
3277 static int 3363 static bool
3278 gimple_types_compatible_p (tree t1, tree t2) 3364 gimple_compatible_complete_and_incomplete_subtype_p (tree t1, tree t2)
3279 { 3365 {
3280 type_pair_t p = NULL; 3366 /* If one pointer points to an incomplete type variant of
3367 the other pointed-to type they are the same. */
3368 if (TREE_CODE (t1) == TREE_CODE (t2)
3369 && RECORD_OR_UNION_TYPE_P (t1)
3370 && (!COMPLETE_TYPE_P (t1)
3371 || !COMPLETE_TYPE_P (t2))
3372 && TYPE_QUALS (t1) == TYPE_QUALS (t2)
3373 && compare_type_names_p (TYPE_MAIN_VARIANT (t1),
3374 TYPE_MAIN_VARIANT (t2), true))
3375 return true;
3376 return false;
3377 }
3378
3379 static bool
3380 gimple_types_compatible_p_1 (tree, tree, enum gtc_mode, type_pair_t,
3381 VEC(type_pair_t, heap) **,
3382 struct pointer_map_t *, struct obstack *);
3383
3384 /* DFS visit the edge from the callers type pair with state *STATE to
3385 the pair T1, T2 while operating in FOR_MERGING_P mode.
3386 Update the merging status if it is not part of the SCC containing the
3387 callers pair and return it.
3388 SCCSTACK, SCCSTATE and SCCSTATE_OBSTACK are state for the DFS walk done. */
3389
3390 static bool
3391 gtc_visit (tree t1, tree t2, enum gtc_mode mode,
3392 struct sccs *state,
3393 VEC(type_pair_t, heap) **sccstack,
3394 struct pointer_map_t *sccstate,
3395 struct obstack *sccstate_obstack)
3396 {
3397 struct sccs *cstate = NULL;
3398 type_pair_t p;
3399 void **slot;
3281 3400
3282 /* Check first for the obvious case of pointer identity. */ 3401 /* Check first for the obvious case of pointer identity. */
3283 if (t1 == t2) 3402 if (t1 == t2)
3284 return 1; 3403 return true;
3285 3404
3286 /* Check that we have two types to compare. */ 3405 /* Check that we have two types to compare. */
3287 if (t1 == NULL_TREE || t2 == NULL_TREE) 3406 if (t1 == NULL_TREE || t2 == NULL_TREE)
3288 return 0; 3407 return false;
3408
3409 /* If the types have been previously registered and found equal
3410 they still are. */
3411 if (mode == GTC_MERGE)
3412 {
3413 tree leader1 = gimple_lookup_type_leader (t1);
3414 tree leader2 = gimple_lookup_type_leader (t2);
3415 if (leader1 == t2
3416 || t1 == leader2
3417 || (leader1 && leader1 == leader2))
3418 return true;
3419 }
3420 else if (mode == GTC_DIAG)
3421 {
3422 if (TYPE_CANONICAL (t1)
3423 && TYPE_CANONICAL (t1) == TYPE_CANONICAL (t2))
3424 return true;
3425 }
3289 3426
3290 /* Can't be the same type if the types don't have the same code. */ 3427 /* Can't be the same type if the types don't have the same code. */
3291 if (TREE_CODE (t1) != TREE_CODE (t2)) 3428 if (TREE_CODE (t1) != TREE_CODE (t2))
3292 return 0; 3429 return false;
3293 3430
3294 /* Can't be the same type if they have different CV qualifiers. */ 3431 /* Can't be the same type if they have different CV qualifiers. */
3295 if (TYPE_QUALS (t1) != TYPE_QUALS (t2)) 3432 if (TYPE_QUALS (t1) != TYPE_QUALS (t2))
3296 return 0; 3433 return false;
3297 3434
3298 /* Void types are always the same. */ 3435 /* Void types are always the same. */
3299 if (TREE_CODE (t1) == VOID_TYPE) 3436 if (TREE_CODE (t1) == VOID_TYPE)
3300 return 1; 3437 return true;
3301 3438
3302 /* For numerical types do some simple checks before doing three 3439 /* Do some simple checks before doing three hashtable queries. */
3303 hashtable queries. */
3304 if (INTEGRAL_TYPE_P (t1) 3440 if (INTEGRAL_TYPE_P (t1)
3305 || SCALAR_FLOAT_TYPE_P (t1) 3441 || SCALAR_FLOAT_TYPE_P (t1)
3306 || FIXED_POINT_TYPE_P (t1) 3442 || FIXED_POINT_TYPE_P (t1)
3307 || TREE_CODE (t1) == VECTOR_TYPE 3443 || TREE_CODE (t1) == VECTOR_TYPE
3308 || TREE_CODE (t1) == COMPLEX_TYPE 3444 || TREE_CODE (t1) == COMPLEX_TYPE
3312 sign, precision or mode. */ 3448 sign, precision or mode. */
3313 if (TYPE_ALIGN (t1) != TYPE_ALIGN (t2) 3449 if (TYPE_ALIGN (t1) != TYPE_ALIGN (t2)
3314 || TYPE_PRECISION (t1) != TYPE_PRECISION (t2) 3450 || TYPE_PRECISION (t1) != TYPE_PRECISION (t2)
3315 || TYPE_MODE (t1) != TYPE_MODE (t2) 3451 || TYPE_MODE (t1) != TYPE_MODE (t2)
3316 || TYPE_UNSIGNED (t1) != TYPE_UNSIGNED (t2)) 3452 || TYPE_UNSIGNED (t1) != TYPE_UNSIGNED (t2))
3317 return 0; 3453 return false;
3318 3454
3319 if (TREE_CODE (t1) == INTEGER_TYPE 3455 if (TREE_CODE (t1) == INTEGER_TYPE
3320 && (TYPE_IS_SIZETYPE (t1) != TYPE_IS_SIZETYPE (t2) 3456 && (TYPE_IS_SIZETYPE (t1) != TYPE_IS_SIZETYPE (t2)
3321 || TYPE_STRING_FLAG (t1) != TYPE_STRING_FLAG (t2))) 3457 || TYPE_STRING_FLAG (t1) != TYPE_STRING_FLAG (t2)))
3322 return 0; 3458 return false;
3323 3459
3324 /* That's all we need to check for float and fixed-point types. */ 3460 /* That's all we need to check for float and fixed-point types. */
3325 if (SCALAR_FLOAT_TYPE_P (t1) 3461 if (SCALAR_FLOAT_TYPE_P (t1)
3326 || FIXED_POINT_TYPE_P (t1)) 3462 || FIXED_POINT_TYPE_P (t1))
3327 return 1; 3463 return true;
3328
3329 /* Perform cheap tail-recursion for vector and complex types. */
3330 if (TREE_CODE (t1) == VECTOR_TYPE
3331 || TREE_CODE (t1) == COMPLEX_TYPE)
3332 return gimple_types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2));
3333 3464
3334 /* For integral types fall thru to more complex checks. */ 3465 /* For integral types fall thru to more complex checks. */
3466 }
3467
3468 else if (AGGREGATE_TYPE_P (t1) || POINTER_TYPE_P (t1))
3469 {
3470 /* Can't be the same type if they have different alignment or mode. */
3471 if (TYPE_ALIGN (t1) != TYPE_ALIGN (t2)
3472 || TYPE_MODE (t1) != TYPE_MODE (t2))
3473 return false;
3335 } 3474 }
3336 3475
3337 /* If the hash values of t1 and t2 are different the types can't 3476 /* If the hash values of t1 and t2 are different the types can't
3338 possibly be the same. This helps keeping the type-pair hashtable 3477 possibly be the same. This helps keeping the type-pair hashtable
3339 small, only tracking comparisons for hash collisions. */ 3478 small, only tracking comparisons for hash collisions. */
3340 if (gimple_type_hash (t1) != gimple_type_hash (t2)) 3479 if (gimple_type_hash_1 (t1, mode) != gimple_type_hash_1 (t2, mode))
3341 return 0; 3480 return false;
3342 3481
3343 /* If we've visited this type pair before (in the case of aggregates 3482 /* Allocate a new cache entry for this comparison. */
3344 with self-referential types), and we made a decision, return it. */
3345 p = lookup_type_pair (t1, t2, &gtc_visited, &gtc_ob); 3483 p = lookup_type_pair (t1, t2, &gtc_visited, &gtc_ob);
3346 if (p->same_p == 0 || p->same_p == 1) 3484 if (p->same_p[mode] == 0 || p->same_p[mode] == 1)
3347 { 3485 {
3348 /* We have already decided whether T1 and T2 are the 3486 /* We have already decided whether T1 and T2 are the
3349 same, return the cached result. */ 3487 same, return the cached result. */
3350 return p->same_p == 1; 3488 return p->same_p[mode] == 1;
3351 } 3489 }
3352 else if (p->same_p == -1) 3490
3353 { 3491 if ((slot = pointer_map_contains (sccstate, p)) != NULL)
3354 /* We are currently comparing this pair of types, assume 3492 cstate = (struct sccs *)*slot;
3355 that they are the same and let the caller decide. */ 3493 /* Not yet visited. DFS recurse. */
3356 return 1; 3494 if (!cstate)
3357 } 3495 {
3358 3496 gimple_types_compatible_p_1 (t1, t2, mode, p,
3359 gcc_assert (p->same_p == -2); 3497 sccstack, sccstate, sccstate_obstack);
3360 3498 cstate = (struct sccs *)* pointer_map_contains (sccstate, p);
3361 /* Mark the (T1, T2) comparison in progress. */ 3499 state->low = MIN (state->low, cstate->low);
3362 p->same_p = -1; 3500 }
3501 /* If the type is still on the SCC stack adjust the parents low. */
3502 if (cstate->dfsnum < state->dfsnum
3503 && cstate->on_sccstack)
3504 state->low = MIN (cstate->dfsnum, state->low);
3505
3506 /* Return the current lattice value. We start with an equality
3507 assumption so types part of a SCC will be optimistically
3508 treated equal unless proven otherwise. */
3509 return cstate->u.same_p;
3510 }
3511
3512 /* Worker for gimple_types_compatible.
3513 SCCSTACK, SCCSTATE and SCCSTATE_OBSTACK are state for the DFS walk done. */
3514
3515 static bool
3516 gimple_types_compatible_p_1 (tree t1, tree t2, enum gtc_mode mode,
3517 type_pair_t p,
3518 VEC(type_pair_t, heap) **sccstack,
3519 struct pointer_map_t *sccstate,
3520 struct obstack *sccstate_obstack)
3521 {
3522 struct sccs *state;
3523
3524 gcc_assert (p->same_p[mode] == -2);
3525
3526 state = XOBNEW (sccstate_obstack, struct sccs);
3527 *pointer_map_insert (sccstate, p) = state;
3528
3529 VEC_safe_push (type_pair_t, heap, *sccstack, p);
3530 state->dfsnum = gtc_next_dfs_num++;
3531 state->low = state->dfsnum;
3532 state->on_sccstack = true;
3533 /* Start with an equality assumption. As we DFS recurse into child
3534 SCCs this assumption may get revisited. */
3535 state->u.same_p = 1;
3363 3536
3364 /* If their attributes are not the same they can't be the same type. */ 3537 /* If their attributes are not the same they can't be the same type. */
3365 if (!attribute_list_equal (TYPE_ATTRIBUTES (t1), TYPE_ATTRIBUTES (t2))) 3538 if (!attribute_list_equal (TYPE_ATTRIBUTES (t1), TYPE_ATTRIBUTES (t2)))
3366 goto different_types; 3539 goto different_types;
3367 3540
3368 /* Do type-specific comparisons. */ 3541 /* Do type-specific comparisons. */
3369 switch (TREE_CODE (t1)) 3542 switch (TREE_CODE (t1))
3370 { 3543 {
3544 case VECTOR_TYPE:
3545 case COMPLEX_TYPE:
3546 if (!gtc_visit (TREE_TYPE (t1), TREE_TYPE (t2), mode,
3547 state, sccstack, sccstate, sccstate_obstack))
3548 goto different_types;
3549 goto same_types;
3550
3371 case ARRAY_TYPE: 3551 case ARRAY_TYPE:
3372 /* Array types are the same if the element types are the same and 3552 /* Array types are the same if the element types are the same and
3373 the number of elements are the same. */ 3553 the number of elements are the same. */
3374 if (!gimple_types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2)) 3554 if (!gtc_visit (TREE_TYPE (t1), TREE_TYPE (t2), mode,
3555 state, sccstack, sccstate, sccstate_obstack)
3375 || TYPE_STRING_FLAG (t1) != TYPE_STRING_FLAG (t2) 3556 || TYPE_STRING_FLAG (t1) != TYPE_STRING_FLAG (t2)
3376 || TYPE_NONALIASED_COMPONENT (t1) != TYPE_NONALIASED_COMPONENT (t2)) 3557 || TYPE_NONALIASED_COMPONENT (t1) != TYPE_NONALIASED_COMPONENT (t2))
3377 goto different_types; 3558 goto different_types;
3378 else 3559 else
3379 { 3560 {
3417 } 3598 }
3418 } 3599 }
3419 3600
3420 case METHOD_TYPE: 3601 case METHOD_TYPE:
3421 /* Method types should belong to the same class. */ 3602 /* Method types should belong to the same class. */
3422 if (!gimple_types_compatible_p (TYPE_METHOD_BASETYPE (t1), 3603 if (!gtc_visit (TYPE_METHOD_BASETYPE (t1), TYPE_METHOD_BASETYPE (t2),
3423 TYPE_METHOD_BASETYPE (t2))) 3604 mode, state, sccstack, sccstate, sccstate_obstack))
3424 goto different_types; 3605 goto different_types;
3425 3606
3426 /* Fallthru */ 3607 /* Fallthru */
3427 3608
3428 case FUNCTION_TYPE: 3609 case FUNCTION_TYPE:
3429 /* Function types are the same if the return type and arguments types 3610 /* Function types are the same if the return type and arguments types
3430 are the same. */ 3611 are the same. */
3431 if (!gimple_types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2))) 3612 if ((mode != GTC_DIAG
3613 || !gimple_compatible_complete_and_incomplete_subtype_p
3614 (TREE_TYPE (t1), TREE_TYPE (t2)))
3615 && !gtc_visit (TREE_TYPE (t1), TREE_TYPE (t2), mode,
3616 state, sccstack, sccstate, sccstate_obstack))
3432 goto different_types; 3617 goto different_types;
3618
3619 if (!targetm.comp_type_attributes (t1, t2))
3620 goto different_types;
3621
3622 if (TYPE_ARG_TYPES (t1) == TYPE_ARG_TYPES (t2))
3623 goto same_types;
3433 else 3624 else
3434 { 3625 {
3435 if (!targetm.comp_type_attributes (t1, t2)) 3626 tree parms1, parms2;
3627
3628 for (parms1 = TYPE_ARG_TYPES (t1), parms2 = TYPE_ARG_TYPES (t2);
3629 parms1 && parms2;
3630 parms1 = TREE_CHAIN (parms1), parms2 = TREE_CHAIN (parms2))
3631 {
3632 if ((mode == GTC_MERGE
3633 || !gimple_compatible_complete_and_incomplete_subtype_p
3634 (TREE_VALUE (parms1), TREE_VALUE (parms2)))
3635 && !gtc_visit (TREE_VALUE (parms1), TREE_VALUE (parms2), mode,
3636 state, sccstack, sccstate, sccstate_obstack))
3637 goto different_types;
3638 }
3639
3640 if (parms1 || parms2)
3436 goto different_types; 3641 goto different_types;
3437 3642
3438 if (TYPE_ARG_TYPES (t1) == TYPE_ARG_TYPES (t2)) 3643 goto same_types;
3439 goto same_types;
3440 else
3441 {
3442 tree parms1, parms2;
3443
3444 for (parms1 = TYPE_ARG_TYPES (t1), parms2 = TYPE_ARG_TYPES (t2);
3445 parms1 && parms2;
3446 parms1 = TREE_CHAIN (parms1), parms2 = TREE_CHAIN (parms2))
3447 {
3448 if (!gimple_types_compatible_p (TREE_VALUE (parms1),
3449 TREE_VALUE (parms2)))
3450 goto different_types;
3451 }
3452
3453 if (parms1 || parms2)
3454 goto different_types;
3455
3456 goto same_types;
3457 }
3458 } 3644 }
3459 3645
3460 case OFFSET_TYPE: 3646 case OFFSET_TYPE:
3461 { 3647 {
3462 if (!gimple_types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2)) 3648 if (!gtc_visit (TREE_TYPE (t1), TREE_TYPE (t2), mode,
3463 || !gimple_types_compatible_p (TYPE_OFFSET_BASETYPE (t1), 3649 state, sccstack, sccstate, sccstate_obstack)
3464 TYPE_OFFSET_BASETYPE (t2))) 3650 || !gtc_visit (TYPE_OFFSET_BASETYPE (t1),
3651 TYPE_OFFSET_BASETYPE (t2), mode,
3652 state, sccstack, sccstate, sccstate_obstack))
3465 goto different_types; 3653 goto different_types;
3466 3654
3467 goto same_types; 3655 goto same_types;
3468 } 3656 }
3469 3657
3475 if (TYPE_REF_CAN_ALIAS_ALL (t1) != TYPE_REF_CAN_ALIAS_ALL (t2)) 3663 if (TYPE_REF_CAN_ALIAS_ALL (t1) != TYPE_REF_CAN_ALIAS_ALL (t2))
3476 goto different_types; 3664 goto different_types;
3477 3665
3478 /* If one pointer points to an incomplete type variant of 3666 /* If one pointer points to an incomplete type variant of
3479 the other pointed-to type they are the same. */ 3667 the other pointed-to type they are the same. */
3480 if (TREE_CODE (TREE_TYPE (t1)) == TREE_CODE (TREE_TYPE (t2)) 3668 if (mode == GTC_DIAG
3481 && RECORD_OR_UNION_TYPE_P (TREE_TYPE (t1)) 3669 && gimple_compatible_complete_and_incomplete_subtype_p
3482 && (!COMPLETE_TYPE_P (TREE_TYPE (t1)) 3670 (TREE_TYPE (t1), TREE_TYPE (t2)))
3483 || !COMPLETE_TYPE_P (TREE_TYPE (t2))) 3671 goto same_types;
3484 && TYPE_QUALS (TREE_TYPE (t1)) == TYPE_QUALS (TREE_TYPE (t2))
3485 && compare_type_names_p (TYPE_MAIN_VARIANT (TREE_TYPE (t1)),
3486 TYPE_MAIN_VARIANT (TREE_TYPE (t2)), true))
3487 {
3488 /* Replace the pointed-to incomplete type with the
3489 complete one.
3490 ??? This simple name-based merging causes at least some
3491 of the ICEs in canonicalizing FIELD_DECLs during stmt
3492 read. For example in GCC we have two different struct deps
3493 and we mismatch the use in struct cpp_reader in sched-int.h
3494 vs. mkdeps.c. Of course the whole exercise is for TBAA
3495 with structs which contain pointers to incomplete types
3496 in one unit and to complete ones in another. So we
3497 probably should merge these types only with more context. */
3498 if (COMPLETE_TYPE_P (TREE_TYPE (t2)))
3499 TREE_TYPE (t1) = TREE_TYPE (t2);
3500 else
3501 TREE_TYPE (t2) = TREE_TYPE (t1);
3502 goto same_types;
3503 }
3504 3672
3505 /* Otherwise, pointer and reference types are the same if the 3673 /* Otherwise, pointer and reference types are the same if the
3506 pointed-to types are the same. */ 3674 pointed-to types are the same. */
3507 if (gimple_types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2))) 3675 if (gtc_visit (TREE_TYPE (t1), TREE_TYPE (t2), mode,
3676 state, sccstack, sccstate, sccstate_obstack))
3508 goto same_types; 3677 goto same_types;
3509 3678
3510 goto different_types; 3679 goto different_types;
3511 } 3680 }
3681
3682 case NULLPTR_TYPE:
3683 /* There is only one decltype(nullptr). */
3684 goto same_types;
3512 3685
3513 case INTEGER_TYPE: 3686 case INTEGER_TYPE:
3514 case BOOLEAN_TYPE: 3687 case BOOLEAN_TYPE:
3515 { 3688 {
3516 tree min1 = TYPE_MIN_VALUE (t1); 3689 tree min1 = TYPE_MIN_VALUE (t1);
3583 case UNION_TYPE: 3756 case UNION_TYPE:
3584 case QUAL_UNION_TYPE: 3757 case QUAL_UNION_TYPE:
3585 { 3758 {
3586 tree f1, f2; 3759 tree f1, f2;
3587 3760
3588 /* If one type requires structural equality checks and the
3589 other doesn't, do not merge the types. */
3590 if (TYPE_STRUCTURAL_EQUALITY_P (t1)
3591 != TYPE_STRUCTURAL_EQUALITY_P (t2))
3592 goto different_types;
3593
3594 /* The struct tags shall compare equal. */ 3761 /* The struct tags shall compare equal. */
3595 if (!compare_type_names_p (TYPE_MAIN_VARIANT (t1), 3762 if (mode == GTC_MERGE
3596 TYPE_MAIN_VARIANT (t2), false)) 3763 && !compare_type_names_p (TYPE_MAIN_VARIANT (t1),
3764 TYPE_MAIN_VARIANT (t2), false))
3597 goto different_types; 3765 goto different_types;
3598 3766
3599 /* For aggregate types, all the fields must be the same. */ 3767 /* For aggregate types, all the fields must be the same. */
3600 for (f1 = TYPE_FIELDS (t1), f2 = TYPE_FIELDS (t2); 3768 for (f1 = TYPE_FIELDS (t1), f2 = TYPE_FIELDS (t2);
3601 f1 && f2; 3769 f1 && f2;
3602 f1 = TREE_CHAIN (f1), f2 = TREE_CHAIN (f2)) 3770 f1 = TREE_CHAIN (f1), f2 = TREE_CHAIN (f2))
3603 { 3771 {
3604 /* The fields must have the same name, offset and type. */ 3772 /* The fields must have the same name, offset and type. */
3605 if (DECL_NAME (f1) != DECL_NAME (f2) 3773 if ((mode == GTC_MERGE
3774 && DECL_NAME (f1) != DECL_NAME (f2))
3606 || DECL_NONADDRESSABLE_P (f1) != DECL_NONADDRESSABLE_P (f2) 3775 || DECL_NONADDRESSABLE_P (f1) != DECL_NONADDRESSABLE_P (f2)
3607 || !gimple_compare_field_offset (f1, f2) 3776 || !gimple_compare_field_offset (f1, f2)
3608 || !gimple_types_compatible_p (TREE_TYPE (f1), 3777 || !gtc_visit (TREE_TYPE (f1), TREE_TYPE (f2), mode,
3609 TREE_TYPE (f2))) 3778 state, sccstack, sccstate, sccstate_obstack))
3610 goto different_types; 3779 goto different_types;
3611 } 3780 }
3612 3781
3613 /* If one aggregate has more fields than the other, they 3782 /* If one aggregate has more fields than the other, they
3614 are not the same. */ 3783 are not the same. */
3622 gcc_unreachable (); 3791 gcc_unreachable ();
3623 } 3792 }
3624 3793
3625 /* Common exit path for types that are not compatible. */ 3794 /* Common exit path for types that are not compatible. */
3626 different_types: 3795 different_types:
3627 p->same_p = 0; 3796 state->u.same_p = 0;
3628 return 0; 3797 goto pop;
3629 3798
3630 /* Common exit path for types that are compatible. */ 3799 /* Common exit path for types that are compatible. */
3631 same_types: 3800 same_types:
3632 p->same_p = 1; 3801 gcc_assert (state->u.same_p == 1);
3633 return 1; 3802
3634 } 3803 pop:
3635 3804 if (state->low == state->dfsnum)
3636 3805 {
3637 3806 type_pair_t x;
3638 3807
3639 /* Per pointer state for the SCC finding. The on_sccstack flag 3808 /* Pop off the SCC and set its cache values to the final
3640 is not strictly required, it is true when there is no hash value 3809 comparison result. */
3641 recorded for the type and false otherwise. But querying that 3810 do
3642 is slower. */ 3811 {
3643 3812 struct sccs *cstate;
3644 struct sccs 3813 x = VEC_pop (type_pair_t, *sccstack);
3645 { 3814 cstate = (struct sccs *)*pointer_map_contains (sccstate, x);
3646 unsigned int dfsnum; 3815 cstate->on_sccstack = false;
3647 unsigned int low; 3816 x->same_p[mode] = state->u.same_p;
3648 bool on_sccstack; 3817 }
3649 hashval_t hash; 3818 while (x != p);
3650 }; 3819 }
3651 3820
3652 static unsigned int next_dfs_num; 3821 return state->u.same_p;
3822 }
3823
3824 /* Return true iff T1 and T2 are structurally identical. When
3825 FOR_MERGING_P is true the an incomplete type and a complete type
3826 are considered different, otherwise they are considered compatible. */
3827
3828 bool
3829 gimple_types_compatible_p (tree t1, tree t2, enum gtc_mode mode)
3830 {
3831 VEC(type_pair_t, heap) *sccstack = NULL;
3832 struct pointer_map_t *sccstate;
3833 struct obstack sccstate_obstack;
3834 type_pair_t p = NULL;
3835 bool res;
3836
3837 /* Before starting to set up the SCC machinery handle simple cases. */
3838
3839 /* Check first for the obvious case of pointer identity. */
3840 if (t1 == t2)
3841 return true;
3842
3843 /* Check that we have two types to compare. */
3844 if (t1 == NULL_TREE || t2 == NULL_TREE)
3845 return false;
3846
3847 /* If the types have been previously registered and found equal
3848 they still are. */
3849 if (mode == GTC_MERGE)
3850 {
3851 tree leader1 = gimple_lookup_type_leader (t1);
3852 tree leader2 = gimple_lookup_type_leader (t2);
3853 if (leader1 == t2
3854 || t1 == leader2
3855 || (leader1 && leader1 == leader2))
3856 return true;
3857 }
3858 else if (mode == GTC_DIAG)
3859 {
3860 if (TYPE_CANONICAL (t1)
3861 && TYPE_CANONICAL (t1) == TYPE_CANONICAL (t2))
3862 return true;
3863 }
3864
3865 /* Can't be the same type if the types don't have the same code. */
3866 if (TREE_CODE (t1) != TREE_CODE (t2))
3867 return false;
3868
3869 /* Can't be the same type if they have different CV qualifiers. */
3870 if (TYPE_QUALS (t1) != TYPE_QUALS (t2))
3871 return false;
3872
3873 /* Void types are always the same. */
3874 if (TREE_CODE (t1) == VOID_TYPE)
3875 return true;
3876
3877 /* Do some simple checks before doing three hashtable queries. */
3878 if (INTEGRAL_TYPE_P (t1)
3879 || SCALAR_FLOAT_TYPE_P (t1)
3880 || FIXED_POINT_TYPE_P (t1)
3881 || TREE_CODE (t1) == VECTOR_TYPE
3882 || TREE_CODE (t1) == COMPLEX_TYPE
3883 || TREE_CODE (t1) == OFFSET_TYPE)
3884 {
3885 /* Can't be the same type if they have different alignment,
3886 sign, precision or mode. */
3887 if (TYPE_ALIGN (t1) != TYPE_ALIGN (t2)
3888 || TYPE_PRECISION (t1) != TYPE_PRECISION (t2)
3889 || TYPE_MODE (t1) != TYPE_MODE (t2)
3890 || TYPE_UNSIGNED (t1) != TYPE_UNSIGNED (t2))
3891 return false;
3892
3893 if (TREE_CODE (t1) == INTEGER_TYPE
3894 && (TYPE_IS_SIZETYPE (t1) != TYPE_IS_SIZETYPE (t2)
3895 || TYPE_STRING_FLAG (t1) != TYPE_STRING_FLAG (t2)))
3896 return false;
3897
3898 /* That's all we need to check for float and fixed-point types. */
3899 if (SCALAR_FLOAT_TYPE_P (t1)
3900 || FIXED_POINT_TYPE_P (t1))
3901 return true;
3902
3903 /* For integral types fall thru to more complex checks. */
3904 }
3905
3906 else if (AGGREGATE_TYPE_P (t1) || POINTER_TYPE_P (t1))
3907 {
3908 /* Can't be the same type if they have different alignment or mode. */
3909 if (TYPE_ALIGN (t1) != TYPE_ALIGN (t2)
3910 || TYPE_MODE (t1) != TYPE_MODE (t2))
3911 return false;
3912 }
3913
3914 /* If the hash values of t1 and t2 are different the types can't
3915 possibly be the same. This helps keeping the type-pair hashtable
3916 small, only tracking comparisons for hash collisions. */
3917 if (gimple_type_hash_1 (t1, mode) != gimple_type_hash_1 (t2, mode))
3918 return false;
3919
3920 /* If we've visited this type pair before (in the case of aggregates
3921 with self-referential types), and we made a decision, return it. */
3922 p = lookup_type_pair (t1, t2, &gtc_visited, &gtc_ob);
3923 if (p->same_p[mode] == 0 || p->same_p[mode] == 1)
3924 {
3925 /* We have already decided whether T1 and T2 are the
3926 same, return the cached result. */
3927 return p->same_p[mode] == 1;
3928 }
3929
3930 /* Now set up the SCC machinery for the comparison. */
3931 gtc_next_dfs_num = 1;
3932 sccstate = pointer_map_create ();
3933 gcc_obstack_init (&sccstate_obstack);
3934 res = gimple_types_compatible_p_1 (t1, t2, mode, p,
3935 &sccstack, sccstate, &sccstate_obstack);
3936 VEC_free (type_pair_t, heap, sccstack);
3937 pointer_map_destroy (sccstate);
3938 obstack_free (&sccstate_obstack, NULL);
3939
3940 return res;
3941 }
3942
3653 3943
3654 static hashval_t 3944 static hashval_t
3655 iterative_hash_gimple_type (tree, hashval_t, VEC(tree, heap) **, 3945 iterative_hash_gimple_type (tree, hashval_t, VEC(tree, heap) **,
3656 struct pointer_map_t *, struct obstack *); 3946 struct pointer_map_t *, struct obstack *,
3947 enum gtc_mode);
3657 3948
3658 /* DFS visit the edge from the callers type with state *STATE to T. 3949 /* DFS visit the edge from the callers type with state *STATE to T.
3659 Update the callers type hash V with the hash for T if it is not part 3950 Update the callers type hash V with the hash for T if it is not part
3660 of the SCC containing the callers type and return it. 3951 of the SCC containing the callers type and return it.
3661 SCCSTACK, SCCSTATE and SCCSTATE_OBSTACK are state for the DFS walk done. */ 3952 SCCSTACK, SCCSTATE and SCCSTATE_OBSTACK are state for the DFS walk done. */
3662 3953
3663 static hashval_t 3954 static hashval_t
3664 visit (tree t, struct sccs *state, hashval_t v, 3955 visit (tree t, struct sccs *state, hashval_t v,
3665 VEC (tree, heap) **sccstack, 3956 VEC (tree, heap) **sccstack,
3666 struct pointer_map_t *sccstate, 3957 struct pointer_map_t *sccstate,
3667 struct obstack *sccstate_obstack) 3958 struct obstack *sccstate_obstack, enum gtc_mode mode)
3668 { 3959 {
3669 struct sccs *cstate = NULL; 3960 struct sccs *cstate = NULL;
3961 struct tree_int_map m;
3670 void **slot; 3962 void **slot;
3671 3963
3672 /* If there is a hash value recorded for this type then it can't 3964 /* If there is a hash value recorded for this type then it can't
3673 possibly be part of our parent SCC. Simply mix in its hash. */ 3965 possibly be part of our parent SCC. Simply mix in its hash. */
3674 if ((slot = pointer_map_contains (type_hash_cache, t))) 3966 m.base.from = t;
3675 return iterative_hash_hashval_t ((hashval_t) (size_t) *slot, v); 3967 if ((slot = htab_find_slot (mode == GTC_MERGE
3968 ? type_hash_cache : canonical_type_hash_cache,
3969 &m, NO_INSERT))
3970 && *slot)
3971 return iterative_hash_hashval_t (((struct tree_int_map *) *slot)->to, v);
3676 3972
3677 if ((slot = pointer_map_contains (sccstate, t)) != NULL) 3973 if ((slot = pointer_map_contains (sccstate, t)) != NULL)
3678 cstate = (struct sccs *)*slot; 3974 cstate = (struct sccs *)*slot;
3679 if (!cstate) 3975 if (!cstate)
3680 { 3976 {
3681 hashval_t tem; 3977 hashval_t tem;
3682 /* Not yet visited. DFS recurse. */ 3978 /* Not yet visited. DFS recurse. */
3683 tem = iterative_hash_gimple_type (t, v, 3979 tem = iterative_hash_gimple_type (t, v,
3684 sccstack, sccstate, sccstate_obstack); 3980 sccstack, sccstate, sccstate_obstack,
3981 mode);
3685 if (!cstate) 3982 if (!cstate)
3686 cstate = (struct sccs *)* pointer_map_contains (sccstate, t); 3983 cstate = (struct sccs *)* pointer_map_contains (sccstate, t);
3687 state->low = MIN (state->low, cstate->low); 3984 state->low = MIN (state->low, cstate->low);
3688 /* If the type is no longer on the SCC stack and thus is not part 3985 /* If the type is no longer on the SCC stack and thus is not part
3689 of the parents SCC mix in its hash value. Otherwise we will 3986 of the parents SCC mix in its hash value. Otherwise we will
3730 4027
3731 static hashval_t 4028 static hashval_t
3732 iterative_hash_gimple_type (tree type, hashval_t val, 4029 iterative_hash_gimple_type (tree type, hashval_t val,
3733 VEC(tree, heap) **sccstack, 4030 VEC(tree, heap) **sccstack,
3734 struct pointer_map_t *sccstate, 4031 struct pointer_map_t *sccstate,
3735 struct obstack *sccstate_obstack) 4032 struct obstack *sccstate_obstack,
4033 enum gtc_mode mode)
3736 { 4034 {
3737 hashval_t v; 4035 hashval_t v;
3738 void **slot; 4036 void **slot;
3739 struct sccs *state; 4037 struct sccs *state;
3740 4038
3741 #ifdef ENABLE_CHECKING 4039 /* Not visited during this DFS walk. */
3742 /* Not visited during this DFS walk nor during previous walks. */ 4040 gcc_checking_assert (!pointer_map_contains (sccstate, type));
3743 gcc_assert (!pointer_map_contains (type_hash_cache, type)
3744 && !pointer_map_contains (sccstate, type));
3745 #endif
3746 state = XOBNEW (sccstate_obstack, struct sccs); 4041 state = XOBNEW (sccstate_obstack, struct sccs);
3747 *pointer_map_insert (sccstate, type) = state; 4042 *pointer_map_insert (sccstate, type) = state;
3748 4043
3749 VEC_safe_push (tree, heap, *sccstack, type); 4044 VEC_safe_push (tree, heap, *sccstack, type);
3750 state->dfsnum = next_dfs_num++; 4045 state->dfsnum = next_dfs_num++;
3779 { 4074 {
3780 if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (type))) 4075 if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (type)))
3781 { 4076 {
3782 v = iterative_hash_hashval_t (TREE_CODE (TREE_TYPE (type)), v); 4077 v = iterative_hash_hashval_t (TREE_CODE (TREE_TYPE (type)), v);
3783 v = iterative_hash_name 4078 v = iterative_hash_name
3784 (TYPE_NAME (TYPE_MAIN_VARIANT (TREE_TYPE (type))), v); 4079 (TYPE_NAME (TYPE_MAIN_VARIANT (TREE_TYPE (type))), v);
3785 } 4080 }
3786 else 4081 else
3787 v = visit (TREE_TYPE (type), state, v, 4082 v = visit (TREE_TYPE (type), state, v,
3788 sccstack, sccstate, sccstate_obstack); 4083 sccstack, sccstate, sccstate_obstack, mode);
3789 } 4084 }
3790 4085
3791 /* For integer types hash the types min/max values and the string flag. */ 4086 /* For integer types hash the types min/max values and the string flag. */
3792 if (TREE_CODE (type) == INTEGER_TYPE) 4087 if (TREE_CODE (type) == INTEGER_TYPE)
3793 { 4088 {
3804 if (TREE_CODE (type) == ARRAY_TYPE 4099 if (TREE_CODE (type) == ARRAY_TYPE
3805 && TYPE_DOMAIN (type)) 4100 && TYPE_DOMAIN (type))
3806 { 4101 {
3807 v = iterative_hash_hashval_t (TYPE_STRING_FLAG (type), v); 4102 v = iterative_hash_hashval_t (TYPE_STRING_FLAG (type), v);
3808 v = visit (TYPE_DOMAIN (type), state, v, 4103 v = visit (TYPE_DOMAIN (type), state, v,
3809 sccstack, sccstate, sccstate_obstack); 4104 sccstack, sccstate, sccstate_obstack, mode);
3810 } 4105 }
3811 4106
3812 /* Recurse for aggregates with a single element type. */ 4107 /* Recurse for aggregates with a single element type. */
3813 if (TREE_CODE (type) == ARRAY_TYPE 4108 if (TREE_CODE (type) == ARRAY_TYPE
3814 || TREE_CODE (type) == COMPLEX_TYPE 4109 || TREE_CODE (type) == COMPLEX_TYPE
3815 || TREE_CODE (type) == VECTOR_TYPE) 4110 || TREE_CODE (type) == VECTOR_TYPE)
3816 v = visit (TREE_TYPE (type), state, v, 4111 v = visit (TREE_TYPE (type), state, v,
3817 sccstack, sccstate, sccstate_obstack); 4112 sccstack, sccstate, sccstate_obstack, mode);
3818 4113
3819 /* Incorporate function return and argument types. */ 4114 /* Incorporate function return and argument types. */
3820 if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE) 4115 if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE)
3821 { 4116 {
3822 unsigned na; 4117 unsigned na;
3823 tree p; 4118 tree p;
3824 4119
3825 /* For method types also incorporate their parent class. */ 4120 /* For method types also incorporate their parent class. */
3826 if (TREE_CODE (type) == METHOD_TYPE) 4121 if (TREE_CODE (type) == METHOD_TYPE)
3827 v = visit (TYPE_METHOD_BASETYPE (type), state, v, 4122 v = visit (TYPE_METHOD_BASETYPE (type), state, v,
3828 sccstack, sccstate, sccstate_obstack); 4123 sccstack, sccstate, sccstate_obstack, mode);
3829 4124
3830 v = visit (TREE_TYPE (type), state, v, 4125 /* For result types allow mismatch in completeness. */
3831 sccstack, sccstate, sccstate_obstack); 4126 if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (type)))
4127 {
4128 v = iterative_hash_hashval_t (TREE_CODE (TREE_TYPE (type)), v);
4129 v = iterative_hash_name
4130 (TYPE_NAME (TYPE_MAIN_VARIANT (TREE_TYPE (type))), v);
4131 }
4132 else
4133 v = visit (TREE_TYPE (type), state, v,
4134 sccstack, sccstate, sccstate_obstack, mode);
3832 4135
3833 for (p = TYPE_ARG_TYPES (type), na = 0; p; p = TREE_CHAIN (p)) 4136 for (p = TYPE_ARG_TYPES (type), na = 0; p; p = TREE_CHAIN (p))
3834 { 4137 {
3835 v = visit (TREE_VALUE (p), state, v, 4138 /* For argument types allow mismatch in completeness. */
3836 sccstack, sccstate, sccstate_obstack); 4139 if (RECORD_OR_UNION_TYPE_P (TREE_VALUE (p)))
4140 {
4141 v = iterative_hash_hashval_t (TREE_CODE (TREE_VALUE (p)), v);
4142 v = iterative_hash_name
4143 (TYPE_NAME (TYPE_MAIN_VARIANT (TREE_VALUE (p))), v);
4144 }
4145 else
4146 v = visit (TREE_VALUE (p), state, v,
4147 sccstack, sccstate, sccstate_obstack, mode);
3837 na++; 4148 na++;
3838 } 4149 }
3839 4150
3840 v = iterative_hash_hashval_t (na, v); 4151 v = iterative_hash_hashval_t (na, v);
3841 } 4152 }
3845 || TREE_CODE (type) == QUAL_UNION_TYPE) 4156 || TREE_CODE (type) == QUAL_UNION_TYPE)
3846 { 4157 {
3847 unsigned nf; 4158 unsigned nf;
3848 tree f; 4159 tree f;
3849 4160
3850 v = iterative_hash_name (TYPE_NAME (TYPE_MAIN_VARIANT (type)), v); 4161 if (mode == GTC_MERGE)
4162 v = iterative_hash_name (TYPE_NAME (TYPE_MAIN_VARIANT (type)), v);
3851 4163
3852 for (f = TYPE_FIELDS (type), nf = 0; f; f = TREE_CHAIN (f)) 4164 for (f = TYPE_FIELDS (type), nf = 0; f; f = TREE_CHAIN (f))
3853 { 4165 {
3854 v = iterative_hash_name (DECL_NAME (f), v); 4166 if (mode == GTC_MERGE)
4167 v = iterative_hash_name (DECL_NAME (f), v);
3855 v = visit (TREE_TYPE (f), state, v, 4168 v = visit (TREE_TYPE (f), state, v,
3856 sccstack, sccstate, sccstate_obstack); 4169 sccstack, sccstate, sccstate_obstack, mode);
3857 nf++; 4170 nf++;
3858 } 4171 }
3859 4172
3860 v = iterative_hash_hashval_t (nf, v); 4173 v = iterative_hash_hashval_t (nf, v);
3861 } 4174 }
3862 4175
3863 /* Record hash for us. */ 4176 /* Record hash for us. */
3864 state->hash = v; 4177 state->u.hash = v;
3865 4178
3866 /* See if we found an SCC. */ 4179 /* See if we found an SCC. */
3867 if (state->low == state->dfsnum) 4180 if (state->low == state->dfsnum)
3868 { 4181 {
3869 tree x; 4182 tree x;
3870 4183
3871 /* Pop off the SCC and set its hash values. */ 4184 /* Pop off the SCC and set its hash values. */
3872 do 4185 do
3873 { 4186 {
3874 struct sccs *cstate; 4187 struct sccs *cstate;
4188 struct tree_int_map *m = ggc_alloc_cleared_tree_int_map ();
3875 x = VEC_pop (tree, *sccstack); 4189 x = VEC_pop (tree, *sccstack);
3876 gcc_assert (!pointer_map_contains (type_hash_cache, x));
3877 cstate = (struct sccs *)*pointer_map_contains (sccstate, x); 4190 cstate = (struct sccs *)*pointer_map_contains (sccstate, x);
3878 cstate->on_sccstack = false; 4191 cstate->on_sccstack = false;
3879 slot = pointer_map_insert (type_hash_cache, x); 4192 m->base.from = x;
3880 *slot = (void *) (size_t) cstate->hash; 4193 m->to = cstate->u.hash;
4194 slot = htab_find_slot (mode == GTC_MERGE
4195 ? type_hash_cache : canonical_type_hash_cache,
4196 m, INSERT);
4197 gcc_assert (!*slot);
4198 *slot = (void *) m;
3881 } 4199 }
3882 while (x != type); 4200 while (x != type);
3883 } 4201 }
3884 4202
3885 return iterative_hash_hashval_t (v, val); 4203 return iterative_hash_hashval_t (v, val);
3893 4211
3894 This function should produce the same hash value for two compatible 4212 This function should produce the same hash value for two compatible
3895 types according to gimple_types_compatible_p. */ 4213 types according to gimple_types_compatible_p. */
3896 4214
3897 static hashval_t 4215 static hashval_t
3898 gimple_type_hash (const void *p) 4216 gimple_type_hash_1 (const void *p, enum gtc_mode mode)
3899 { 4217 {
3900 const_tree t = (const_tree) p; 4218 const_tree t = (const_tree) p;
3901 VEC(tree, heap) *sccstack = NULL; 4219 VEC(tree, heap) *sccstack = NULL;
3902 struct pointer_map_t *sccstate; 4220 struct pointer_map_t *sccstate;
3903 struct obstack sccstate_obstack; 4221 struct obstack sccstate_obstack;
3904 hashval_t val; 4222 hashval_t val;
3905 void **slot; 4223 void **slot;
3906 4224 struct tree_int_map m;
3907 if (type_hash_cache == NULL) 4225
3908 type_hash_cache = pointer_map_create (); 4226 if (mode == GTC_MERGE
3909 4227 && type_hash_cache == NULL)
3910 if ((slot = pointer_map_contains (type_hash_cache, p)) != NULL) 4228 type_hash_cache = htab_create_ggc (512, tree_int_map_hash,
3911 return iterative_hash_hashval_t ((hashval_t) (size_t) *slot, 0); 4229 tree_int_map_eq, NULL);
4230 else if (mode == GTC_DIAG
4231 && canonical_type_hash_cache == NULL)
4232 canonical_type_hash_cache = htab_create_ggc (512, tree_int_map_hash,
4233 tree_int_map_eq, NULL);
4234
4235 m.base.from = CONST_CAST_TREE (t);
4236 if ((slot = htab_find_slot (mode == GTC_MERGE
4237 ? type_hash_cache : canonical_type_hash_cache,
4238 &m, NO_INSERT))
4239 && *slot)
4240 return iterative_hash_hashval_t (((struct tree_int_map *) *slot)->to, 0);
3912 4241
3913 /* Perform a DFS walk and pre-hash all reachable types. */ 4242 /* Perform a DFS walk and pre-hash all reachable types. */
3914 next_dfs_num = 1; 4243 next_dfs_num = 1;
3915 sccstate = pointer_map_create (); 4244 sccstate = pointer_map_create ();
3916 gcc_obstack_init (&sccstate_obstack); 4245 gcc_obstack_init (&sccstate_obstack);
3917 val = iterative_hash_gimple_type (CONST_CAST_TREE (t), 0, 4246 val = iterative_hash_gimple_type (CONST_CAST_TREE (t), 0,
3918 &sccstack, sccstate, &sccstate_obstack); 4247 &sccstack, sccstate, &sccstate_obstack,
4248 mode);
3919 VEC_free (tree, heap, sccstack); 4249 VEC_free (tree, heap, sccstack);
3920 pointer_map_destroy (sccstate); 4250 pointer_map_destroy (sccstate);
3921 obstack_free (&sccstate_obstack, NULL); 4251 obstack_free (&sccstate_obstack, NULL);
3922 4252
3923 return val; 4253 return val;
3924 } 4254 }
3925 4255
4256 static hashval_t
4257 gimple_type_hash (const void *p)
4258 {
4259 return gimple_type_hash_1 (p, GTC_MERGE);
4260 }
4261
4262 static hashval_t
4263 gimple_canonical_type_hash (const void *p)
4264 {
4265 return gimple_type_hash_1 (p, GTC_DIAG);
4266 }
4267
3926 4268
3927 /* Returns nonzero if P1 and P2 are equal. */ 4269 /* Returns nonzero if P1 and P2 are equal. */
3928 4270
3929 static int 4271 static int
3930 gimple_type_eq (const void *p1, const void *p2) 4272 gimple_type_eq (const void *p1, const void *p2)
3931 { 4273 {
3932 const_tree t1 = (const_tree) p1; 4274 const_tree t1 = (const_tree) p1;
3933 const_tree t2 = (const_tree) p2; 4275 const_tree t2 = (const_tree) p2;
3934 return gimple_types_compatible_p (CONST_CAST_TREE (t1), CONST_CAST_TREE (t2)); 4276 return gimple_types_compatible_p (CONST_CAST_TREE (t1),
4277 CONST_CAST_TREE (t2), GTC_MERGE);
3935 } 4278 }
3936 4279
3937 4280
3938 /* Register type T in the global type table gimple_types. 4281 /* Register type T in the global type table gimple_types.
3939 If another type T', compatible with T, already existed in 4282 If another type T', compatible with T, already existed in
3942 4285
3943 tree 4286 tree
3944 gimple_register_type (tree t) 4287 gimple_register_type (tree t)
3945 { 4288 {
3946 void **slot; 4289 void **slot;
4290 gimple_type_leader_entry *leader;
4291 tree mv_leader = NULL_TREE;
3947 4292
3948 gcc_assert (TYPE_P (t)); 4293 gcc_assert (TYPE_P (t));
4294
4295 if (!gimple_type_leader)
4296 gimple_type_leader = ggc_alloc_cleared_vec_gimple_type_leader_entry_s
4297 (GIMPLE_TYPE_LEADER_SIZE);
4298 /* If we registered this type before return the cached result. */
4299 leader = &gimple_type_leader[TYPE_UID (t) % GIMPLE_TYPE_LEADER_SIZE];
4300 if (leader->type == t)
4301 return leader->leader;
3949 4302
3950 /* Always register the main variant first. This is important so we 4303 /* Always register the main variant first. This is important so we
3951 pick up the non-typedef variants as canonical, otherwise we'll end 4304 pick up the non-typedef variants as canonical, otherwise we'll end
3952 up taking typedef ids for structure tags during comparison. */ 4305 up taking typedef ids for structure tags during comparison. */
3953 if (TYPE_MAIN_VARIANT (t) != t) 4306 if (TYPE_MAIN_VARIANT (t) != t)
3954 gimple_register_type (TYPE_MAIN_VARIANT (t)); 4307 mv_leader = gimple_register_type (TYPE_MAIN_VARIANT (t));
3955 4308
3956 if (gimple_types == NULL) 4309 if (gimple_types == NULL)
3957 gimple_types = htab_create (16381, gimple_type_hash, gimple_type_eq, 0); 4310 gimple_types = htab_create_ggc (16381, gimple_type_hash, gimple_type_eq, 0);
3958 4311
3959 slot = htab_find_slot (gimple_types, t, INSERT); 4312 slot = htab_find_slot (gimple_types, t, INSERT);
3960 if (*slot 4313 if (*slot
3961 && *(tree *)slot != t) 4314 && *(tree *)slot != t)
3962 { 4315 {
4008 TYPE_NEXT_REF_TO (tem) = TYPE_NEXT_REF_TO (t); 4361 TYPE_NEXT_REF_TO (tem) = TYPE_NEXT_REF_TO (t);
4009 } 4362 }
4010 TYPE_NEXT_REF_TO (t) = NULL_TREE; 4363 TYPE_NEXT_REF_TO (t) = NULL_TREE;
4011 } 4364 }
4012 4365
4366 leader->type = t;
4367 leader->leader = new_type;
4013 t = new_type; 4368 t = new_type;
4014 } 4369 }
4015 else 4370 else
4016 *slot = (void *) t; 4371 {
4372 leader->type = t;
4373 leader->leader = t;
4374 /* We're the type leader. Make our TYPE_MAIN_VARIANT valid. */
4375 if (TYPE_MAIN_VARIANT (t) != t
4376 && TYPE_MAIN_VARIANT (t) != mv_leader)
4377 {
4378 /* Remove us from our main variant list as we are not the variant
4379 leader and the variant leader will change. */
4380 tree tem = TYPE_MAIN_VARIANT (t);
4381 while (tem && TYPE_NEXT_VARIANT (tem) != t)
4382 tem = TYPE_NEXT_VARIANT (tem);
4383 if (tem)
4384 TYPE_NEXT_VARIANT (tem) = TYPE_NEXT_VARIANT (t);
4385 TYPE_NEXT_VARIANT (t) = NULL_TREE;
4386 /* Adjust our main variant. Linking us into its variant list
4387 will happen at fixup time. */
4388 TYPE_MAIN_VARIANT (t) = mv_leader;
4389 }
4390 *slot = (void *) t;
4391 }
4392
4393 return t;
4394 }
4395
4396
4397 /* Returns nonzero if P1 and P2 are equal. */
4398
4399 static int
4400 gimple_canonical_type_eq (const void *p1, const void *p2)
4401 {
4402 const_tree t1 = (const_tree) p1;
4403 const_tree t2 = (const_tree) p2;
4404 return gimple_types_compatible_p (CONST_CAST_TREE (t1),
4405 CONST_CAST_TREE (t2), GTC_DIAG);
4406 }
4407
4408 /* Register type T in the global type table gimple_types.
4409 If another type T', compatible with T, already existed in
4410 gimple_types then return T', otherwise return T. This is used by
4411 LTO to merge identical types read from different TUs. */
4412
4413 tree
4414 gimple_register_canonical_type (tree t)
4415 {
4416 void **slot;
4417 tree orig_t = t;
4418
4419 gcc_assert (TYPE_P (t));
4420
4421 if (TYPE_CANONICAL (t))
4422 return TYPE_CANONICAL (t);
4423
4424 /* Always register the type itself first so that if it turns out
4425 to be the canonical type it will be the one we merge to as well. */
4426 t = gimple_register_type (t);
4427
4428 /* Always register the main variant first. This is important so we
4429 pick up the non-typedef variants as canonical, otherwise we'll end
4430 up taking typedef ids for structure tags during comparison. */
4431 if (TYPE_MAIN_VARIANT (t) != t)
4432 gimple_register_canonical_type (TYPE_MAIN_VARIANT (t));
4433
4434 if (gimple_canonical_types == NULL)
4435 gimple_canonical_types = htab_create_ggc (16381, gimple_canonical_type_hash,
4436 gimple_canonical_type_eq, 0);
4437
4438 slot = htab_find_slot (gimple_canonical_types, t, INSERT);
4439 if (*slot
4440 && *(tree *)slot != t)
4441 {
4442 tree new_type = (tree) *((tree *) slot);
4443
4444 TYPE_CANONICAL (t) = new_type;
4445 t = new_type;
4446 }
4447 else
4448 {
4449 TYPE_CANONICAL (t) = t;
4450 *slot = (void *) t;
4451 }
4452
4453 /* Also cache the canonical type in the non-leaders. */
4454 TYPE_CANONICAL (orig_t) = t;
4017 4455
4018 return t; 4456 return t;
4019 } 4457 }
4020 4458
4021 4459
4032 (long) gimple_types->searches, 4470 (long) gimple_types->searches,
4033 (long) gimple_types->collisions, 4471 (long) gimple_types->collisions,
4034 htab_collisions (gimple_types)); 4472 htab_collisions (gimple_types));
4035 else 4473 else
4036 fprintf (stderr, "GIMPLE type table is empty\n"); 4474 fprintf (stderr, "GIMPLE type table is empty\n");
4475 if (type_hash_cache)
4476 fprintf (stderr, "GIMPLE type hash table: size %ld, %ld elements, "
4477 "%ld searches, %ld collisions (ratio: %f)\n",
4478 (long) htab_size (type_hash_cache),
4479 (long) htab_elements (type_hash_cache),
4480 (long) type_hash_cache->searches,
4481 (long) type_hash_cache->collisions,
4482 htab_collisions (type_hash_cache));
4483 else
4484 fprintf (stderr, "GIMPLE type hash table is empty\n");
4485 if (gimple_canonical_types)
4486 fprintf (stderr, "GIMPLE canonical type table: size %ld, %ld elements, "
4487 "%ld searches, %ld collisions (ratio: %f)\n",
4488 (long) htab_size (gimple_canonical_types),
4489 (long) htab_elements (gimple_canonical_types),
4490 (long) gimple_canonical_types->searches,
4491 (long) gimple_canonical_types->collisions,
4492 htab_collisions (gimple_canonical_types));
4493 else
4494 fprintf (stderr, "GIMPLE canonical type table is empty\n");
4495 if (canonical_type_hash_cache)
4496 fprintf (stderr, "GIMPLE canonical type hash table: size %ld, %ld elements, "
4497 "%ld searches, %ld collisions (ratio: %f)\n",
4498 (long) htab_size (canonical_type_hash_cache),
4499 (long) htab_elements (canonical_type_hash_cache),
4500 (long) canonical_type_hash_cache->searches,
4501 (long) canonical_type_hash_cache->collisions,
4502 htab_collisions (canonical_type_hash_cache));
4503 else
4504 fprintf (stderr, "GIMPLE canonical type hash table is empty\n");
4037 if (gtc_visited) 4505 if (gtc_visited)
4038 fprintf (stderr, "GIMPLE type comparison table: size %ld, %ld " 4506 fprintf (stderr, "GIMPLE type comparison table: size %ld, %ld "
4039 "elements, %ld searches, %ld collisions (ratio: %f)\n", 4507 "elements, %ld searches, %ld collisions (ratio: %f)\n",
4040 (long) htab_size (gtc_visited), 4508 (long) htab_size (gtc_visited),
4041 (long) htab_elements (gtc_visited), 4509 (long) htab_elements (gtc_visited),
4058 if (gimple_types) 4526 if (gimple_types)
4059 { 4527 {
4060 htab_delete (gimple_types); 4528 htab_delete (gimple_types);
4061 gimple_types = NULL; 4529 gimple_types = NULL;
4062 } 4530 }
4531 if (gimple_canonical_types)
4532 {
4533 htab_delete (gimple_canonical_types);
4534 gimple_canonical_types = NULL;
4535 }
4063 if (type_hash_cache) 4536 if (type_hash_cache)
4064 { 4537 {
4065 pointer_map_destroy (type_hash_cache); 4538 htab_delete (type_hash_cache);
4066 type_hash_cache = NULL; 4539 type_hash_cache = NULL;
4540 }
4541 if (canonical_type_hash_cache)
4542 {
4543 htab_delete (canonical_type_hash_cache);
4544 canonical_type_hash_cache = NULL;
4067 } 4545 }
4068 if (gtc_visited) 4546 if (gtc_visited)
4069 { 4547 {
4070 htab_delete (gtc_visited); 4548 htab_delete (gtc_visited);
4071 obstack_free (&gtc_ob, NULL); 4549 obstack_free (&gtc_ob, NULL);
4072 gtc_visited = NULL; 4550 gtc_visited = NULL;
4073 } 4551 }
4552 gimple_type_leader = NULL;
4074 } 4553 }
4075 4554
4076 4555
4077 /* Return a type the same as TYPE except unsigned or 4556 /* Return a type the same as TYPE except unsigned or
4078 signed according to UNSIGNEDP. */ 4557 signed according to UNSIGNEDP. */
4096 if (type1 == long_long_integer_type_node 4575 if (type1 == long_long_integer_type_node
4097 || type1 == long_long_unsigned_type_node) 4576 || type1 == long_long_unsigned_type_node)
4098 return unsignedp 4577 return unsignedp
4099 ? long_long_unsigned_type_node 4578 ? long_long_unsigned_type_node
4100 : long_long_integer_type_node; 4579 : long_long_integer_type_node;
4580 if (int128_integer_type_node && (type1 == int128_integer_type_node || type1 == int128_unsigned_type_node))
4581 return unsignedp
4582 ? int128_unsigned_type_node
4583 : int128_integer_type_node;
4101 #if HOST_BITS_PER_WIDE_INT >= 64 4584 #if HOST_BITS_PER_WIDE_INT >= 64
4102 if (type1 == intTI_type_node || type1 == unsigned_intTI_type_node) 4585 if (type1 == intTI_type_node || type1 == unsigned_intTI_type_node)
4103 return unsignedp ? unsigned_intTI_type_node : intTI_type_node; 4586 return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
4104 #endif 4587 #endif
4105 if (type1 == intDI_type_node || type1 == unsigned_intDI_type_node) 4588 if (type1 == intDI_type_node || type1 == unsigned_intDI_type_node)
4208 return unsignedp ? long_unsigned_type_node : long_integer_type_node; 4691 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
4209 if (TYPE_OK (long_long_integer_type_node)) 4692 if (TYPE_OK (long_long_integer_type_node))
4210 return (unsignedp 4693 return (unsignedp
4211 ? long_long_unsigned_type_node 4694 ? long_long_unsigned_type_node
4212 : long_long_integer_type_node); 4695 : long_long_integer_type_node);
4696 if (int128_integer_type_node && TYPE_OK (int128_integer_type_node))
4697 return (unsignedp
4698 ? int128_unsigned_type_node
4699 : int128_integer_type_node);
4213 4700
4214 #if HOST_BITS_PER_WIDE_INT >= 64 4701 #if HOST_BITS_PER_WIDE_INT >= 64
4215 if (TYPE_OK (intTI_type_node)) 4702 if (TYPE_OK (intTI_type_node))
4216 return unsignedp ? unsigned_intTI_type_node : intTI_type_node; 4703 return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
4217 #endif 4704 #endif
4293 4780
4294 /* t1 == t can happen for boolean nodes which are always unsigned. */ 4781 /* t1 == t can happen for boolean nodes which are always unsigned. */
4295 if (t1 != t) 4782 if (t1 != t)
4296 return get_alias_set (t1); 4783 return get_alias_set (t1);
4297 } 4784 }
4298 else if (POINTER_TYPE_P (t))
4299 {
4300 /* From the common C and C++ langhook implementation:
4301
4302 Unfortunately, there is no canonical form of a pointer type.
4303 In particular, if we have `typedef int I', then `int *', and
4304 `I *' are different types. So, we have to pick a canonical
4305 representative. We do this below.
4306
4307 Technically, this approach is actually more conservative that
4308 it needs to be. In particular, `const int *' and `int *'
4309 should be in different alias sets, according to the C and C++
4310 standard, since their types are not the same, and so,
4311 technically, an `int **' and `const int **' cannot point at
4312 the same thing.
4313
4314 But, the standard is wrong. In particular, this code is
4315 legal C++:
4316
4317 int *ip;
4318 int **ipp = &ip;
4319 const int* const* cipp = ipp;
4320 And, it doesn't make sense for that to be legal unless you
4321 can dereference IPP and CIPP. So, we ignore cv-qualifiers on
4322 the pointed-to types. This issue has been reported to the
4323 C++ committee. */
4324
4325 /* In addition to the above canonicalization issue with LTO
4326 we should also canonicalize `T (*)[]' to `T *' avoiding
4327 alias issues with pointer-to element types and pointer-to
4328 array types.
4329
4330 Likewise we need to deal with the situation of incomplete
4331 pointed-to types and make `*(struct X **)&a' and
4332 `*(struct X {} **)&a' alias. Otherwise we will have to
4333 guarantee that all pointer-to incomplete type variants
4334 will be replaced by pointer-to complete type variants if
4335 they are available.
4336
4337 With LTO the convenient situation of using `void *' to
4338 access and store any pointer type will also become
4339 more apparent (and `void *' is just another pointer-to
4340 incomplete type). Assigning alias-set zero to `void *'
4341 and all pointer-to incomplete types is a not appealing
4342 solution. Assigning an effective alias-set zero only
4343 affecting pointers might be - by recording proper subset
4344 relationships of all pointer alias-sets.
4345
4346 Pointer-to function types are another grey area which
4347 needs caution. Globbing them all into one alias-set
4348 or the above effective zero set would work. */
4349
4350 /* For now just assign the same alias-set to all pointers.
4351 That's simple and avoids all the above problems. */
4352 if (t != ptr_type_node)
4353 return get_alias_set (ptr_type_node);
4354 }
4355 4785
4356 return -1; 4786 return -1;
4357 } 4787 }
4358 4788
4359 4789
4382 { 4812 {
4383 *walk_subtrees = 0; 4813 *walk_subtrees = 0;
4384 return NULL_TREE; 4814 return NULL_TREE;
4385 } 4815 }
4386 4816
4387 if (INDIRECT_REF_P (*tp) && TREE_OPERAND (*tp, 0) == count_p->ptr) 4817 if (TREE_CODE (*tp) == MEM_REF && TREE_OPERAND (*tp, 0) == count_p->ptr)
4388 { 4818 {
4389 if (wi_p->is_lhs) 4819 if (wi_p->is_lhs)
4390 count_p->num_stores++; 4820 count_p->num_stores++;
4391 else 4821 else
4392 count_p->num_loads++; 4822 count_p->num_loads++;
4455 { 4885 {
4456 while (handled_component_p (op)) 4886 while (handled_component_p (op))
4457 op = TREE_OPERAND (op, 0); 4887 op = TREE_OPERAND (op, 0);
4458 if (DECL_P (op) 4888 if (DECL_P (op)
4459 || INDIRECT_REF_P (op) 4889 || INDIRECT_REF_P (op)
4890 || TREE_CODE (op) == MEM_REF
4460 || TREE_CODE (op) == TARGET_MEM_REF) 4891 || TREE_CODE (op) == TARGET_MEM_REF)
4461 return op; 4892 return op;
4462 return NULL_TREE; 4893 return NULL_TREE;
4463 } 4894 }
4464 4895
4492 if (visit_addr) 4923 if (visit_addr)
4493 { 4924 {
4494 if (TREE_CODE (rhs) == ADDR_EXPR) 4925 if (TREE_CODE (rhs) == ADDR_EXPR)
4495 ret |= visit_addr (stmt, TREE_OPERAND (rhs, 0), data); 4926 ret |= visit_addr (stmt, TREE_OPERAND (rhs, 0), data);
4496 else if (TREE_CODE (rhs) == TARGET_MEM_REF 4927 else if (TREE_CODE (rhs) == TARGET_MEM_REF
4497 && TMR_BASE (rhs) != NULL_TREE
4498 && TREE_CODE (TMR_BASE (rhs)) == ADDR_EXPR) 4928 && TREE_CODE (TMR_BASE (rhs)) == ADDR_EXPR)
4499 ret |= visit_addr (stmt, TREE_OPERAND (TMR_BASE (rhs), 0), data); 4929 ret |= visit_addr (stmt, TREE_OPERAND (TMR_BASE (rhs), 0), data);
4500 else if (TREE_CODE (rhs) == OBJ_TYPE_REF 4930 else if (TREE_CODE (rhs) == OBJ_TYPE_REF
4501 && TREE_CODE (OBJ_TYPE_REF_OBJECT (rhs)) == ADDR_EXPR) 4931 && TREE_CODE (OBJ_TYPE_REF_OBJECT (rhs)) == ADDR_EXPR)
4502 ret |= visit_addr (stmt, TREE_OPERAND (OBJ_TYPE_REF_OBJECT (rhs), 4932 ret |= visit_addr (stmt, TREE_OPERAND (OBJ_TYPE_REF_OBJECT (rhs),
4503 0), data); 4933 0), data);
4504 lhs = gimple_assign_lhs (stmt); 4934 lhs = gimple_assign_lhs (stmt);
4505 if (TREE_CODE (lhs) == TARGET_MEM_REF 4935 if (TREE_CODE (lhs) == TARGET_MEM_REF
4506 && TMR_BASE (lhs) != NULL_TREE
4507 && TREE_CODE (TMR_BASE (lhs)) == ADDR_EXPR) 4936 && TREE_CODE (TMR_BASE (lhs)) == ADDR_EXPR)
4508 ret |= visit_addr (stmt, TREE_OPERAND (TMR_BASE (lhs), 0), data); 4937 ret |= visit_addr (stmt, TREE_OPERAND (TMR_BASE (lhs), 0), data);
4509 } 4938 }
4510 if (visit_load) 4939 if (visit_load)
4511 { 4940 {
4715 } 5144 }
4716 5145
4717 return IDENTIFIER_POINTER (DECL_NAME (decl)); 5146 return IDENTIFIER_POINTER (DECL_NAME (decl));
4718 } 5147 }
4719 5148
5149 /* Return true when STMT is builtins call to CODE. */
5150
5151 bool
5152 gimple_call_builtin_p (gimple stmt, enum built_in_function code)
5153 {
5154 tree fndecl;
5155 return (is_gimple_call (stmt)
5156 && (fndecl = gimple_call_fndecl (stmt)) != NULL
5157 && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL
5158 && DECL_FUNCTION_CODE (fndecl) == code);
5159 }
5160
4720 #include "gt-gimple.h" 5161 #include "gt-gimple.h"