comparison gcc/gimple.c @ 69:1b10fe6932e1

merge 69
author Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
date Sun, 21 Aug 2011 07:53:12 +0900
parents 5b5b9ea5b220 f6334be47118
children b81903832de2
comparison
equal deleted inserted replaced
66:b362627d71ba 69:1b10fe6932e1
1 /* Gimple IR support functions. 1 /* Gimple IR support functions.
2 2
3 Copyright 2007, 2008, 2009 Free Software Foundation, Inc. 3 Copyright 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
4 Contributed by Aldy Hernandez <aldyh@redhat.com> 4 Contributed by Aldy Hernandez <aldyh@redhat.com>
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
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 #ifndef noCbC 36 #ifndef noCbC
38 #include "cbc-tree.h" 37 #include "cbc-tree.h"
39 #endif 38 #endif
40 #include "alias.h" 39 #include "alias.h"
41 #include "demangle.h" 40 #include "demangle.h"
41 #include "langhooks.h"
42 42
43 /* Global type table. FIXME lto, it should be possible to re-use some 43 /* Global type table. FIXME lto, it should be possible to re-use some
44 of the type hashing routines in tree.c (type_hash_canon, type_hash_lookup, 44 of the type hashing routines in tree.c (type_hash_canon, type_hash_lookup,
45 etc), but those assume that types were built with the various 45 etc), but those assume that types were built with the various
46 build_*_type routines which is not the case with the streamer. */ 46 build_*_type routines which is not the case with the streamer. */
47 static htab_t gimple_types; 47 static GTY((if_marked ("ggc_marked_p"), param_is (union tree_node)))
48 static struct pointer_map_t *type_hash_cache; 48 htab_t gimple_types;
49 49 static GTY((if_marked ("ggc_marked_p"), param_is (union tree_node)))
50 /* Global type comparison cache. */ 50 htab_t gimple_canonical_types;
51 static GTY((if_marked ("tree_int_map_marked_p"), param_is (struct tree_int_map)))
52 htab_t type_hash_cache;
53 static GTY((if_marked ("tree_int_map_marked_p"), param_is (struct tree_int_map)))
54 htab_t canonical_type_hash_cache;
55
56 /* Global type comparison cache. This is by TYPE_UID for space efficiency
57 and thus cannot use and does not need GC. */
51 static htab_t gtc_visited; 58 static htab_t gtc_visited;
52 static struct obstack gtc_ob; 59 static struct obstack gtc_ob;
53 60
54 /* All the tuples have their operand vector (if present) at the very bottom 61 /* All the tuples have their operand vector (if present) at the very bottom
55 of the structure. Therefore, the offset required to find the 62 of the structure. Therefore, the offset required to find the
146 gimple_alloc_counts[(int) kind]++; 153 gimple_alloc_counts[(int) kind]++;
147 gimple_alloc_sizes[(int) kind] += size; 154 gimple_alloc_sizes[(int) kind] += size;
148 } 155 }
149 #endif 156 #endif
150 157
151 stmt = (gimple) ggc_alloc_cleared_stat (size PASS_MEM_STAT); 158 stmt = ggc_alloc_cleared_gimple_statement_d_stat (size PASS_MEM_STAT);
152 gimple_set_code (stmt, code); 159 gimple_set_code (stmt, code);
153 gimple_set_num_ops (stmt, num_ops); 160 gimple_set_num_ops (stmt, num_ops);
154 161
155 /* Do not call gimple_set_modified here as it has other side 162 /* Do not call gimple_set_modified here as it has other side
156 effects and this tuple is still not completely built. */ 163 effects and this tuple is still not completely built. */
199 if (retval) 206 if (retval)
200 gimple_return_set_retval (s, retval); 207 gimple_return_set_retval (s, retval);
201 return s; 208 return s;
202 } 209 }
203 210
211 /* Reset alias information on call S. */
212
213 void
214 gimple_call_reset_alias_info (gimple s)
215 {
216 if (gimple_call_flags (s) & ECF_CONST)
217 memset (gimple_call_use_set (s), 0, sizeof (struct pt_solution));
218 else
219 pt_solution_reset (gimple_call_use_set (s));
220 if (gimple_call_flags (s) & (ECF_CONST|ECF_PURE|ECF_NOVOPS))
221 memset (gimple_call_clobber_set (s), 0, sizeof (struct pt_solution));
222 else
223 pt_solution_reset (gimple_call_clobber_set (s));
224 }
225
204 /* Helper for gimple_build_call, gimple_build_call_vec and 226 /* Helper for gimple_build_call, gimple_build_call_vec and
205 gimple_build_call_from_tree. Build the basic components of a 227 gimple_build_call_from_tree. Build the basic components of a
206 GIMPLE_CALL statement to function FN with NARGS arguments. */ 228 GIMPLE_CALL statement to function FN with NARGS arguments. */
207 229
208 static inline gimple 230 static inline gimple
210 { 232 {
211 gimple s = gimple_build_with_ops (GIMPLE_CALL, ERROR_MARK, nargs + 3); 233 gimple s = gimple_build_with_ops (GIMPLE_CALL, ERROR_MARK, nargs + 3);
212 if (TREE_CODE (fn) == FUNCTION_DECL) 234 if (TREE_CODE (fn) == FUNCTION_DECL)
213 fn = build_fold_addr_expr (fn); 235 fn = build_fold_addr_expr (fn);
214 gimple_set_op (s, 1, fn); 236 gimple_set_op (s, 1, fn);
237 gimple_call_reset_alias_info (s);
215 return s; 238 return s;
216 } 239 }
217 240
218 241
219 /* Build a GIMPLE_CALL statement to function FN with the arguments 242 /* Build a GIMPLE_CALL statement to function FN with the arguments
285 gimple_call_set_from_thunk (call, CALL_FROM_THUNK_P (t)); 308 gimple_call_set_from_thunk (call, CALL_FROM_THUNK_P (t));
286 gimple_call_set_va_arg_pack (call, CALL_EXPR_VA_ARG_PACK (t)); 309 gimple_call_set_va_arg_pack (call, CALL_EXPR_VA_ARG_PACK (t));
287 #ifndef noCbC 310 #ifndef noCbC
288 gimple_call_set_cbc_goto (call, CALL_EXPR_CbC_GOTO (t)); 311 gimple_call_set_cbc_goto (call, CALL_EXPR_CbC_GOTO (t));
289 #endif 312 #endif
313 gimple_call_set_nothrow (call, TREE_NOTHROW (t));
290 gimple_set_no_warning (call, TREE_NO_WARNING (t)); 314 gimple_set_no_warning (call, TREE_NO_WARNING (t));
291 315
292 return call; 316 return call;
293 } 317 }
294 318
295 319
296 /* Extract the operands and code for expression EXPR into *SUBCODE_P, 320 /* Extract the operands and code for expression EXPR into *SUBCODE_P,
297 *OP1_P and *OP2_P respectively. */ 321 *OP1_P, *OP2_P and *OP3_P respectively. */
298 322
299 void 323 void
300 extract_ops_from_tree (tree expr, enum tree_code *subcode_p, tree *op1_p, 324 extract_ops_from_tree_1 (tree expr, enum tree_code *subcode_p, tree *op1_p,
301 tree *op2_p) 325 tree *op2_p, tree *op3_p)
302 { 326 {
303 enum gimple_rhs_class grhs_class; 327 enum gimple_rhs_class grhs_class;
304 328
305 *subcode_p = TREE_CODE (expr); 329 *subcode_p = TREE_CODE (expr);
306 grhs_class = get_gimple_rhs_class (*subcode_p); 330 grhs_class = get_gimple_rhs_class (*subcode_p);
307 331
308 if (grhs_class == GIMPLE_BINARY_RHS) 332 if (grhs_class == GIMPLE_TERNARY_RHS)
309 { 333 {
310 *op1_p = TREE_OPERAND (expr, 0); 334 *op1_p = TREE_OPERAND (expr, 0);
311 *op2_p = TREE_OPERAND (expr, 1); 335 *op2_p = TREE_OPERAND (expr, 1);
336 *op3_p = TREE_OPERAND (expr, 2);
337 }
338 else if (grhs_class == GIMPLE_BINARY_RHS)
339 {
340 *op1_p = TREE_OPERAND (expr, 0);
341 *op2_p = TREE_OPERAND (expr, 1);
342 *op3_p = NULL_TREE;
312 } 343 }
313 else if (grhs_class == GIMPLE_UNARY_RHS) 344 else if (grhs_class == GIMPLE_UNARY_RHS)
314 { 345 {
315 *op1_p = TREE_OPERAND (expr, 0); 346 *op1_p = TREE_OPERAND (expr, 0);
316 *op2_p = NULL_TREE; 347 *op2_p = NULL_TREE;
348 *op3_p = NULL_TREE;
317 } 349 }
318 else if (grhs_class == GIMPLE_SINGLE_RHS) 350 else if (grhs_class == GIMPLE_SINGLE_RHS)
319 { 351 {
320 *op1_p = expr; 352 *op1_p = expr;
321 *op2_p = NULL_TREE; 353 *op2_p = NULL_TREE;
354 *op3_p = NULL_TREE;
322 } 355 }
323 else 356 else
324 gcc_unreachable (); 357 gcc_unreachable ();
325 } 358 }
326 359
332 365
333 gimple 366 gimple
334 gimple_build_assign_stat (tree lhs, tree rhs MEM_STAT_DECL) 367 gimple_build_assign_stat (tree lhs, tree rhs MEM_STAT_DECL)
335 { 368 {
336 enum tree_code subcode; 369 enum tree_code subcode;
337 tree op1, op2; 370 tree op1, op2, op3;
338 371
339 extract_ops_from_tree (rhs, &subcode, &op1, &op2); 372 extract_ops_from_tree_1 (rhs, &subcode, &op1, &op2, &op3);
340 return gimple_build_assign_with_ops_stat (subcode, lhs, op1, op2 373 return gimple_build_assign_with_ops_stat (subcode, lhs, op1, op2, op3
341 PASS_MEM_STAT); 374 PASS_MEM_STAT);
342 } 375 }
343 376
344 377
345 /* Build a GIMPLE_ASSIGN statement with sub-code SUBCODE and operands 378 /* Build a GIMPLE_ASSIGN statement with sub-code SUBCODE and operands
346 OP1 and OP2. If OP2 is NULL then SUBCODE must be of class 379 OP1 and OP2. If OP2 is NULL then SUBCODE must be of class
347 GIMPLE_UNARY_RHS or GIMPLE_SINGLE_RHS. */ 380 GIMPLE_UNARY_RHS or GIMPLE_SINGLE_RHS. */
348 381
349 gimple 382 gimple
350 gimple_build_assign_with_ops_stat (enum tree_code subcode, tree lhs, tree op1, 383 gimple_build_assign_with_ops_stat (enum tree_code subcode, tree lhs, tree op1,
351 tree op2 MEM_STAT_DECL) 384 tree op2, tree op3 MEM_STAT_DECL)
352 { 385 {
353 unsigned num_ops; 386 unsigned num_ops;
354 gimple p; 387 gimple p;
355 388
356 /* Need 1 operand for LHS and 1 or 2 for the RHS (depending on the 389 /* Need 1 operand for LHS and 1 or 2 for the RHS (depending on the
363 gimple_assign_set_rhs1 (p, op1); 396 gimple_assign_set_rhs1 (p, op1);
364 if (op2) 397 if (op2)
365 { 398 {
366 gcc_assert (num_ops > 2); 399 gcc_assert (num_ops > 2);
367 gimple_assign_set_rhs2 (p, op2); 400 gimple_assign_set_rhs2 (p, op2);
401 }
402
403 if (op3)
404 {
405 gcc_assert (num_ops > 3);
406 gimple_assign_set_rhs3 (p, op3);
368 } 407 }
369 408
370 return p; 409 return p;
371 } 410 }
372 411
415 454
416 void 455 void
417 gimple_cond_get_ops_from_tree (tree cond, enum tree_code *code_p, 456 gimple_cond_get_ops_from_tree (tree cond, enum tree_code *code_p,
418 tree *lhs_p, tree *rhs_p) 457 tree *lhs_p, tree *rhs_p)
419 { 458 {
420 location_t loc = EXPR_LOCATION (cond);
421 gcc_assert (TREE_CODE_CLASS (TREE_CODE (cond)) == tcc_comparison 459 gcc_assert (TREE_CODE_CLASS (TREE_CODE (cond)) == tcc_comparison
422 || TREE_CODE (cond) == TRUTH_NOT_EXPR 460 || TREE_CODE (cond) == TRUTH_NOT_EXPR
423 || is_gimple_min_invariant (cond) 461 || is_gimple_min_invariant (cond)
424 || SSA_VAR_P (cond)); 462 || SSA_VAR_P (cond));
425 463
428 /* Canonicalize conditionals of the form 'if (!VAL)'. */ 466 /* Canonicalize conditionals of the form 'if (!VAL)'. */
429 if (*code_p == TRUTH_NOT_EXPR) 467 if (*code_p == TRUTH_NOT_EXPR)
430 { 468 {
431 *code_p = EQ_EXPR; 469 *code_p = EQ_EXPR;
432 gcc_assert (*lhs_p && *rhs_p == NULL_TREE); 470 gcc_assert (*lhs_p && *rhs_p == NULL_TREE);
433 *rhs_p = fold_convert_loc (loc, TREE_TYPE (*lhs_p), integer_zero_node); 471 *rhs_p = build_zero_cst (TREE_TYPE (*lhs_p));
434 } 472 }
435 /* Canonicalize conditionals of the form 'if (VAL)' */ 473 /* Canonicalize conditionals of the form 'if (VAL)' */
436 else if (TREE_CODE_CLASS (*code_p) != tcc_comparison) 474 else if (TREE_CODE_CLASS (*code_p) != tcc_comparison)
437 { 475 {
438 *code_p = NE_EXPR; 476 *code_p = NE_EXPR;
439 gcc_assert (*lhs_p && *rhs_p == NULL_TREE); 477 gcc_assert (*lhs_p && *rhs_p == NULL_TREE);
440 *rhs_p = fold_convert_loc (loc, TREE_TYPE (*lhs_p), integer_zero_node); 478 *rhs_p = build_zero_cst (TREE_TYPE (*lhs_p));
441 } 479 }
442 } 480 }
443 481
444 482
445 /* Build a GIMPLE_COND statement from the conditional expression tree 483 /* Build a GIMPLE_COND statement from the conditional expression tree
624 /* Build a GIMPLE_EH_MUST_NOT_THROW statement. */ 662 /* Build a GIMPLE_EH_MUST_NOT_THROW statement. */
625 663
626 gimple 664 gimple
627 gimple_build_eh_must_not_throw (tree decl) 665 gimple_build_eh_must_not_throw (tree decl)
628 { 666 {
629 gimple p = gimple_alloc (GIMPLE_EH_MUST_NOT_THROW, 1); 667 gimple p = gimple_alloc (GIMPLE_EH_MUST_NOT_THROW, 0);
630 668
631 gcc_assert (TREE_CODE (decl) == FUNCTION_DECL); 669 gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
632 gcc_assert (flags_from_decl_or_type (decl) & ECF_NORETURN); 670 gcc_assert (flags_from_decl_or_type (decl) & ECF_NORETURN);
633 gimple_eh_must_not_throw_set_fndecl (p, decl); 671 gimple_eh_must_not_throw_set_fndecl (p, decl);
634 672
811 gimple p = gimple_alloc (GIMPLE_OMP_FOR, 0); 849 gimple p = gimple_alloc (GIMPLE_OMP_FOR, 0);
812 if (body) 850 if (body)
813 gimple_omp_set_body (p, body); 851 gimple_omp_set_body (p, body);
814 gimple_omp_for_set_clauses (p, clauses); 852 gimple_omp_for_set_clauses (p, clauses);
815 p->gimple_omp_for.collapse = collapse; 853 p->gimple_omp_for.collapse = collapse;
816 p->gimple_omp_for.iter = GGC_CNEWVEC (struct gimple_omp_for_iter, collapse); 854 p->gimple_omp_for.iter
855 = ggc_alloc_cleared_vec_gimple_omp_for_iter (collapse);
817 if (pre_body) 856 if (pre_body)
818 gimple_omp_for_set_pre_body (p, pre_body); 857 gimple_omp_for_set_pre_body (p, pre_body);
819 858
820 return p; 859 return p;
821 } 860 }
1061 gcc_assert (gimple_seq_cache != seq); 1100 gcc_assert (gimple_seq_cache != seq);
1062 memset (seq, 0, sizeof (*seq)); 1101 memset (seq, 0, sizeof (*seq));
1063 } 1102 }
1064 else 1103 else
1065 { 1104 {
1066 seq = (gimple_seq) ggc_alloc_cleared (sizeof (*seq)); 1105 seq = ggc_alloc_cleared_gimple_seq_d ();
1067 #ifdef GATHER_STATISTICS 1106 #ifdef GATHER_STATISTICS
1068 gimple_alloc_counts[(int) gimple_alloc_kind_seq]++; 1107 gimple_alloc_counts[(int) gimple_alloc_kind_seq]++;
1069 gimple_alloc_sizes[(int) gimple_alloc_kind_seq] += sizeof (*seq); 1108 gimple_alloc_sizes[(int) gimple_alloc_kind_seq] += sizeof (*seq);
1070 #endif 1109 #endif
1071 } 1110 }
1301 operands are not scanned. 1340 operands are not scanned.
1302 1341
1303 The return value is that returned by the last call to walk_tree, or 1342 The return value is that returned by the last call to walk_tree, or
1304 NULL_TREE if no CALLBACK_OP is specified. */ 1343 NULL_TREE if no CALLBACK_OP is specified. */
1305 1344
1306 inline tree 1345 tree
1307 walk_gimple_op (gimple stmt, walk_tree_fn callback_op, 1346 walk_gimple_op (gimple stmt, walk_tree_fn callback_op,
1308 struct walk_stmt_info *wi) 1347 struct walk_stmt_info *wi)
1309 { 1348 {
1310 struct pointer_set_t *pset = (wi) ? wi->pset : NULL; 1349 struct pointer_set_t *pset = (wi) ? wi->pset : NULL;
1311 unsigned i; 1350 unsigned i;
1312 tree ret = NULL_TREE; 1351 tree ret = NULL_TREE;
1313 1352
1314 switch (gimple_code (stmt)) 1353 switch (gimple_code (stmt))
1315 { 1354 {
1316 case GIMPLE_ASSIGN: 1355 case GIMPLE_ASSIGN:
1317 /* Walk the RHS operands. A formal temporary LHS may use a 1356 /* Walk the RHS operands. If the LHS is of a non-renamable type or
1318 COMPONENT_REF RHS. */ 1357 is a register variable, we may use a COMPONENT_REF on the RHS. */
1319 if (wi) 1358 if (wi)
1320 wi->val_only = !is_gimple_reg (gimple_assign_lhs (stmt)) 1359 {
1321 || !gimple_assign_single_p (stmt); 1360 tree lhs = gimple_assign_lhs (stmt);
1361 wi->val_only
1362 = (is_gimple_reg_type (TREE_TYPE (lhs)) && !is_gimple_reg (lhs))
1363 || !gimple_assign_single_p (stmt);
1364 }
1322 1365
1323 for (i = 1; i < gimple_num_ops (stmt); i++) 1366 for (i = 1; i < gimple_num_ops (stmt); i++)
1324 { 1367 {
1325 ret = walk_tree (gimple_op_ptr (stmt, i), callback_op, wi, 1368 ret = walk_tree (gimple_op_ptr (stmt, i), callback_op, wi,
1326 pset); 1369 pset);
1350 } 1393 }
1351 break; 1394 break;
1352 1395
1353 case GIMPLE_CALL: 1396 case GIMPLE_CALL:
1354 if (wi) 1397 if (wi)
1355 wi->is_lhs = false; 1398 {
1399 wi->is_lhs = false;
1400 wi->val_only = true;
1401 }
1356 1402
1357 ret = walk_tree (gimple_call_chain_ptr (stmt), callback_op, wi, pset); 1403 ret = walk_tree (gimple_call_chain_ptr (stmt), callback_op, wi, pset);
1358 if (ret) 1404 if (ret)
1359 return ret; 1405 return ret;
1360 1406
1361 ret = walk_tree (gimple_call_fn_ptr (stmt), callback_op, wi, pset); 1407 ret = walk_tree (gimple_call_fn_ptr (stmt), callback_op, wi, pset);
1362 if (ret) 1408 if (ret)
1363 return ret; 1409 return ret;
1364 1410
1365 for (i = 0; i < gimple_call_num_args (stmt); i++) 1411 for (i = 0; i < gimple_call_num_args (stmt); i++)
1366 { 1412 {
1367 ret = walk_tree (gimple_call_arg_ptr (stmt, i), callback_op, wi, 1413 if (wi)
1368 pset); 1414 wi->val_only = is_gimple_reg_type (gimple_call_arg (stmt, i));
1369 if (ret) 1415 ret = walk_tree (gimple_call_arg_ptr (stmt, i), callback_op, wi,
1370 return ret; 1416 pset);
1371 } 1417 if (ret)
1418 return ret;
1419 }
1420
1421 if (gimple_call_lhs (stmt))
1422 {
1423 if (wi)
1424 {
1425 wi->is_lhs = true;
1426 wi->val_only = is_gimple_reg_type (gimple_call_lhs (stmt));
1427 }
1428
1429 ret = walk_tree (gimple_call_lhs_ptr (stmt), callback_op, wi, pset);
1430 if (ret)
1431 return ret;
1432 }
1372 1433
1373 if (wi) 1434 if (wi)
1374 wi->is_lhs = true; 1435 {
1375 1436 wi->is_lhs = false;
1376 ret = walk_tree (gimple_call_lhs_ptr (stmt), callback_op, wi, pset); 1437 wi->val_only = true;
1377 if (ret) 1438 }
1378 return ret;
1379
1380 if (wi)
1381 wi->is_lhs = false;
1382 break; 1439 break;
1383 1440
1384 case GIMPLE_CATCH: 1441 case GIMPLE_CATCH:
1385 ret = walk_tree (gimple_catch_types_ptr (stmt), callback_op, wi, 1442 ret = walk_tree (gimple_catch_types_ptr (stmt), callback_op, wi,
1386 pset); 1443 pset);
1698 else 1755 else
1699 fn->gimple_body = seq; 1756 fn->gimple_body = seq;
1700 } 1757 }
1701 1758
1702 1759
1703 /* Return the body of GIMPLE statements for function FN. */ 1760 /* Return the body of GIMPLE statements for function FN. After the
1761 CFG pass, the function body doesn't exist anymore because it has
1762 been split up into basic blocks. In this case, it returns
1763 NULL. */
1704 1764
1705 gimple_seq 1765 gimple_seq
1706 gimple_body (tree fndecl) 1766 gimple_body (tree fndecl)
1707 { 1767 {
1708 struct function *fn = DECL_STRUCT_FUNCTION (fndecl); 1768 struct function *fn = DECL_STRUCT_FUNCTION (fndecl);
1737 flags = flags_from_decl_or_type (TREE_TYPE (t)); 1797 flags = flags_from_decl_or_type (TREE_TYPE (t));
1738 else 1798 else
1739 flags = 0; 1799 flags = 0;
1740 } 1800 }
1741 1801
1802 if (stmt->gsbase.subcode & GF_CALL_NOTHROW)
1803 flags |= ECF_NOTHROW;
1804
1742 return flags; 1805 return flags;
1806 }
1807
1808 /* Detects argument flags for argument number ARG on call STMT. */
1809
1810 int
1811 gimple_call_arg_flags (const_gimple stmt, unsigned arg)
1812 {
1813 tree type = TREE_TYPE (TREE_TYPE (gimple_call_fn (stmt)));
1814 tree attr = lookup_attribute ("fn spec", TYPE_ATTRIBUTES (type));
1815 if (!attr)
1816 return 0;
1817
1818 attr = TREE_VALUE (TREE_VALUE (attr));
1819 if (1 + arg >= (unsigned) TREE_STRING_LENGTH (attr))
1820 return 0;
1821
1822 switch (TREE_STRING_POINTER (attr)[1 + arg])
1823 {
1824 case 'x':
1825 case 'X':
1826 return EAF_UNUSED;
1827
1828 case 'R':
1829 return EAF_DIRECT | EAF_NOCLOBBER | EAF_NOESCAPE;
1830
1831 case 'r':
1832 return EAF_NOCLOBBER | EAF_NOESCAPE;
1833
1834 case 'W':
1835 return EAF_DIRECT | EAF_NOESCAPE;
1836
1837 case 'w':
1838 return EAF_NOESCAPE;
1839
1840 case '.':
1841 default:
1842 return 0;
1843 }
1844 }
1845
1846 /* Detects return flags for the call STMT. */
1847
1848 int
1849 gimple_call_return_flags (const_gimple stmt)
1850 {
1851 tree type;
1852 tree attr = NULL_TREE;
1853
1854 if (gimple_call_flags (stmt) & ECF_MALLOC)
1855 return ERF_NOALIAS;
1856
1857 type = TREE_TYPE (TREE_TYPE (gimple_call_fn (stmt)));
1858 attr = lookup_attribute ("fn spec", TYPE_ATTRIBUTES (type));
1859 if (!attr)
1860 return 0;
1861
1862 attr = TREE_VALUE (TREE_VALUE (attr));
1863 if (TREE_STRING_LENGTH (attr) < 1)
1864 return 0;
1865
1866 switch (TREE_STRING_POINTER (attr)[0])
1867 {
1868 case '1':
1869 case '2':
1870 case '3':
1871 case '4':
1872 return ERF_RETURNS_ARG | (TREE_STRING_POINTER (attr)[0] - '1');
1873
1874 case 'm':
1875 return ERF_NOALIAS;
1876
1877 case '.':
1878 default:
1879 return 0;
1880 }
1743 } 1881 }
1744 1882
1745 1883
1746 /* Return true if GS is a copy assignment. */ 1884 /* Return true if GS is a copy assignment. */
1747 1885
1748 bool 1886 bool
1749 gimple_assign_copy_p (gimple gs) 1887 gimple_assign_copy_p (gimple gs)
1750 { 1888 {
1751 return gimple_code (gs) == GIMPLE_ASSIGN 1889 return (gimple_assign_single_p (gs)
1752 && get_gimple_rhs_class (gimple_assign_rhs_code (gs)) 1890 && is_gimple_val (gimple_op (gs, 1)));
1753 == GIMPLE_SINGLE_RHS
1754 && is_gimple_val (gimple_op (gs, 1));
1755 } 1891 }
1756 1892
1757 1893
1758 /* Return true if GS is a SSA_NAME copy assignment. */ 1894 /* Return true if GS is a SSA_NAME copy assignment. */
1759 1895
1760 bool 1896 bool
1761 gimple_assign_ssa_name_copy_p (gimple gs) 1897 gimple_assign_ssa_name_copy_p (gimple gs)
1762 { 1898 {
1763 return (gimple_code (gs) == GIMPLE_ASSIGN 1899 return (gimple_assign_single_p (gs)
1764 && (get_gimple_rhs_class (gimple_assign_rhs_code (gs)) 1900 && TREE_CODE (gimple_assign_lhs (gs)) == SSA_NAME
1765 == GIMPLE_SINGLE_RHS) 1901 && TREE_CODE (gimple_assign_rhs1 (gs)) == SSA_NAME);
1766 && TREE_CODE (gimple_assign_lhs (gs)) == SSA_NAME 1902 }
1767 && TREE_CODE (gimple_assign_rhs1 (gs)) == SSA_NAME); 1903
1768 }
1769
1770
1771 /* Return true if GS is an assignment with a singleton RHS, i.e.,
1772 there is no operator associated with the assignment itself.
1773 Unlike gimple_assign_copy_p, this predicate returns true for
1774 any RHS operand, including those that perform an operation
1775 and do not have the semantics of a copy, such as COND_EXPR. */
1776
1777 bool
1778 gimple_assign_single_p (gimple gs)
1779 {
1780 return (gimple_code (gs) == GIMPLE_ASSIGN
1781 && get_gimple_rhs_class (gimple_assign_rhs_code (gs))
1782 == GIMPLE_SINGLE_RHS);
1783 }
1784 1904
1785 /* Return true if GS is an assignment with a unary RHS, but the 1905 /* Return true if GS is an assignment with a unary RHS, but the
1786 operator has no effect on the assigned value. The logic is adapted 1906 operator has no effect on the assigned value. The logic is adapted
1787 from STRIP_NOPS. This predicate is intended to be used in tuplifying 1907 from STRIP_NOPS. This predicate is intended to be used in tuplifying
1788 instances in which STRIP_NOPS was previously applied to the RHS of 1908 instances in which STRIP_NOPS was previously applied to the RHS of
1797 treatment of unary NOPs is appropriate. */ 1917 treatment of unary NOPs is appropriate. */
1798 1918
1799 bool 1919 bool
1800 gimple_assign_unary_nop_p (gimple gs) 1920 gimple_assign_unary_nop_p (gimple gs)
1801 { 1921 {
1802 return (gimple_code (gs) == GIMPLE_ASSIGN 1922 return (is_gimple_assign (gs)
1803 && (CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (gs)) 1923 && (CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (gs))
1804 || gimple_assign_rhs_code (gs) == NON_LVALUE_EXPR) 1924 || gimple_assign_rhs_code (gs) == NON_LVALUE_EXPR)
1805 && gimple_assign_rhs1 (gs) != error_mark_node 1925 && gimple_assign_rhs1 (gs) != error_mark_node
1806 && (TYPE_MODE (TREE_TYPE (gimple_assign_lhs (gs))) 1926 && (TYPE_MODE (TREE_TYPE (gimple_assign_lhs (gs)))
1807 == TYPE_MODE (TREE_TYPE (gimple_assign_rhs1 (gs))))); 1927 == TYPE_MODE (TREE_TYPE (gimple_assign_rhs1 (gs)))));
1839 VEC_replace (basic_block, label_to_block_map, uid, bb); 1959 VEC_replace (basic_block, label_to_block_map, uid, bb);
1840 } 1960 }
1841 } 1961 }
1842 1962
1843 1963
1844 /* Fold the expression computed by STMT. If the expression can be
1845 folded, return the folded result, otherwise return NULL. STMT is
1846 not modified. */
1847
1848 tree
1849 gimple_fold (const_gimple stmt)
1850 {
1851 location_t loc = gimple_location (stmt);
1852 switch (gimple_code (stmt))
1853 {
1854 case GIMPLE_COND:
1855 return fold_binary_loc (loc, gimple_cond_code (stmt),
1856 boolean_type_node,
1857 gimple_cond_lhs (stmt),
1858 gimple_cond_rhs (stmt));
1859
1860 case GIMPLE_ASSIGN:
1861 switch (get_gimple_rhs_class (gimple_assign_rhs_code (stmt)))
1862 {
1863 case GIMPLE_UNARY_RHS:
1864 return fold_unary_loc (loc, gimple_assign_rhs_code (stmt),
1865 TREE_TYPE (gimple_assign_lhs (stmt)),
1866 gimple_assign_rhs1 (stmt));
1867 case GIMPLE_BINARY_RHS:
1868 return fold_binary_loc (loc, gimple_assign_rhs_code (stmt),
1869 TREE_TYPE (gimple_assign_lhs (stmt)),
1870 gimple_assign_rhs1 (stmt),
1871 gimple_assign_rhs2 (stmt));
1872 case GIMPLE_SINGLE_RHS:
1873 return fold (gimple_assign_rhs1 (stmt));
1874 default:;
1875 }
1876 break;
1877
1878 case GIMPLE_SWITCH:
1879 return gimple_switch_index (stmt);
1880
1881 case GIMPLE_CALL:
1882 return NULL_TREE;
1883
1884 default:
1885 break;
1886 }
1887
1888 gcc_unreachable ();
1889 }
1890
1891
1892 /* Modify the RHS of the assignment pointed-to by GSI using the 1964 /* Modify the RHS of the assignment pointed-to by GSI using the
1893 operands in the expression tree EXPR. 1965 operands in the expression tree EXPR.
1894 1966
1895 NOTE: The statement pointed-to by GSI may be reallocated if it 1967 NOTE: The statement pointed-to by GSI may be reallocated if it
1896 did not have enough operand slots. 1968 did not have enough operand slots.
1908 1980
1909 void 1981 void
1910 gimple_assign_set_rhs_from_tree (gimple_stmt_iterator *gsi, tree expr) 1982 gimple_assign_set_rhs_from_tree (gimple_stmt_iterator *gsi, tree expr)
1911 { 1983 {
1912 enum tree_code subcode; 1984 enum tree_code subcode;
1913 tree op1, op2; 1985 tree op1, op2, op3;
1914 1986
1915 extract_ops_from_tree (expr, &subcode, &op1, &op2); 1987 extract_ops_from_tree_1 (expr, &subcode, &op1, &op2, &op3);
1916 gimple_assign_set_rhs_with_ops (gsi, subcode, op1, op2); 1988 gimple_assign_set_rhs_with_ops_1 (gsi, subcode, op1, op2, op3);
1917 } 1989 }
1918 1990
1919 1991
1920 /* Set the RHS of assignment statement pointed-to by GSI to CODE with 1992 /* Set the RHS of assignment statement pointed-to by GSI to CODE with
1921 operands OP1 and OP2. 1993 operands OP1, OP2 and OP3.
1922 1994
1923 NOTE: The statement pointed-to by GSI may be reallocated if it 1995 NOTE: The statement pointed-to by GSI may be reallocated if it
1924 did not have enough operand slots. */ 1996 did not have enough operand slots. */
1925 1997
1926 void 1998 void
1927 gimple_assign_set_rhs_with_ops (gimple_stmt_iterator *gsi, enum tree_code code, 1999 gimple_assign_set_rhs_with_ops_1 (gimple_stmt_iterator *gsi, enum tree_code code,
1928 tree op1, tree op2) 2000 tree op1, tree op2, tree op3)
1929 { 2001 {
1930 unsigned new_rhs_ops = get_gimple_rhs_num_ops (code); 2002 unsigned new_rhs_ops = get_gimple_rhs_num_ops (code);
1931 gimple stmt = gsi_stmt (*gsi); 2003 gimple stmt = gsi_stmt (*gsi);
1932 2004
1933 /* If the new CODE needs more operands, allocate a new statement. */ 2005 /* If the new CODE needs more operands, allocate a new statement. */
1947 gimple_set_num_ops (stmt, new_rhs_ops + 1); 2019 gimple_set_num_ops (stmt, new_rhs_ops + 1);
1948 gimple_set_subcode (stmt, code); 2020 gimple_set_subcode (stmt, code);
1949 gimple_assign_set_rhs1 (stmt, op1); 2021 gimple_assign_set_rhs1 (stmt, op1);
1950 if (new_rhs_ops > 1) 2022 if (new_rhs_ops > 1)
1951 gimple_assign_set_rhs2 (stmt, op2); 2023 gimple_assign_set_rhs2 (stmt, op2);
2024 if (new_rhs_ops > 2)
2025 gimple_assign_set_rhs3 (stmt, op3);
1952 } 2026 }
1953 2027
1954 2028
1955 /* Return the LHS of a statement that performs an assignment, 2029 /* Return the LHS of a statement that performs an assignment,
1956 either a GIMPLE_ASSIGN or a GIMPLE_CALL. Returns NULL_TREE 2030 either a GIMPLE_ASSIGN or a GIMPLE_CALL. Returns NULL_TREE
2041 { 2115 {
2042 gimple_seq new_seq; 2116 gimple_seq new_seq;
2043 tree t; 2117 tree t;
2044 2118
2045 switch (gimple_code (stmt)) 2119 switch (gimple_code (stmt))
2046 { 2120 {
2047 case GIMPLE_BIND: 2121 case GIMPLE_BIND:
2048 new_seq = gimple_seq_copy (gimple_bind_body (stmt)); 2122 new_seq = gimple_seq_copy (gimple_bind_body (stmt));
2049 gimple_bind_set_body (copy, new_seq); 2123 gimple_bind_set_body (copy, new_seq);
2050 gimple_bind_set_vars (copy, unshare_expr (gimple_bind_vars (stmt))); 2124 gimple_bind_set_vars (copy, unshare_expr (gimple_bind_vars (stmt)));
2051 gimple_bind_set_block (copy, gimple_bind_block (stmt)); 2125 gimple_bind_set_block (copy, gimple_bind_block (stmt));
2052 break; 2126 break;
2053 2127
2054 case GIMPLE_CATCH: 2128 case GIMPLE_CATCH:
2055 new_seq = gimple_seq_copy (gimple_catch_handler (stmt)); 2129 new_seq = gimple_seq_copy (gimple_catch_handler (stmt));
2056 gimple_catch_set_handler (copy, new_seq); 2130 gimple_catch_set_handler (copy, new_seq);
2057 t = unshare_expr (gimple_catch_types (stmt)); 2131 t = unshare_expr (gimple_catch_types (stmt));
2058 gimple_catch_set_types (copy, t); 2132 gimple_catch_set_types (copy, t);
2059 break; 2133 break;
2060 2134
2061 case GIMPLE_EH_FILTER: 2135 case GIMPLE_EH_FILTER:
2062 new_seq = gimple_seq_copy (gimple_eh_filter_failure (stmt)); 2136 new_seq = gimple_seq_copy (gimple_eh_filter_failure (stmt));
2063 gimple_eh_filter_set_failure (copy, new_seq); 2137 gimple_eh_filter_set_failure (copy, new_seq);
2064 t = unshare_expr (gimple_eh_filter_types (stmt)); 2138 t = unshare_expr (gimple_eh_filter_types (stmt));
2065 gimple_eh_filter_set_types (copy, t); 2139 gimple_eh_filter_set_types (copy, t);
2066 break; 2140 break;
2067 2141
2068 case GIMPLE_TRY: 2142 case GIMPLE_TRY:
2069 new_seq = gimple_seq_copy (gimple_try_eval (stmt)); 2143 new_seq = gimple_seq_copy (gimple_try_eval (stmt));
2070 gimple_try_set_eval (copy, new_seq); 2144 gimple_try_set_eval (copy, new_seq);
2071 new_seq = gimple_seq_copy (gimple_try_cleanup (stmt)); 2145 new_seq = gimple_seq_copy (gimple_try_cleanup (stmt));
2072 gimple_try_set_cleanup (copy, new_seq); 2146 gimple_try_set_cleanup (copy, new_seq);
2073 break; 2147 break;
2074 2148
2075 case GIMPLE_OMP_FOR: 2149 case GIMPLE_OMP_FOR:
2076 new_seq = gimple_seq_copy (gimple_omp_for_pre_body (stmt)); 2150 new_seq = gimple_seq_copy (gimple_omp_for_pre_body (stmt));
2077 gimple_omp_for_set_pre_body (copy, new_seq); 2151 gimple_omp_for_set_pre_body (copy, new_seq);
2078 t = unshare_expr (gimple_omp_for_clauses (stmt)); 2152 t = unshare_expr (gimple_omp_for_clauses (stmt));
2079 gimple_omp_for_set_clauses (copy, t); 2153 gimple_omp_for_set_clauses (copy, t);
2080 copy->gimple_omp_for.iter 2154 copy->gimple_omp_for.iter
2081 = GGC_NEWVEC (struct gimple_omp_for_iter, 2155 = ggc_alloc_vec_gimple_omp_for_iter
2082 gimple_omp_for_collapse (stmt)); 2156 (gimple_omp_for_collapse (stmt));
2083 for (i = 0; i < gimple_omp_for_collapse (stmt); i++) 2157 for (i = 0; i < gimple_omp_for_collapse (stmt); i++)
2084 { 2158 {
2085 gimple_omp_for_set_cond (copy, i, 2159 gimple_omp_for_set_cond (copy, i,
2086 gimple_omp_for_cond (stmt, i)); 2160 gimple_omp_for_cond (stmt, i));
2087 gimple_omp_for_set_index (copy, i, 2161 gimple_omp_for_set_index (copy, i,
2088 gimple_omp_for_index (stmt, i)); 2162 gimple_omp_for_index (stmt, i));
2089 t = unshare_expr (gimple_omp_for_initial (stmt, i)); 2163 t = unshare_expr (gimple_omp_for_initial (stmt, i));
2090 gimple_omp_for_set_initial (copy, i, t); 2164 gimple_omp_for_set_initial (copy, i, t);
2091 t = unshare_expr (gimple_omp_for_final (stmt, i)); 2165 t = unshare_expr (gimple_omp_for_final (stmt, i));
2092 gimple_omp_for_set_final (copy, i, t); 2166 gimple_omp_for_set_final (copy, i, t);
2093 t = unshare_expr (gimple_omp_for_incr (stmt, i)); 2167 t = unshare_expr (gimple_omp_for_incr (stmt, i));
2094 gimple_omp_for_set_incr (copy, i, t); 2168 gimple_omp_for_set_incr (copy, i, t);
2095 } 2169 }
2096 goto copy_omp_body; 2170 goto copy_omp_body;
2097 2171
2098 case GIMPLE_OMP_PARALLEL: 2172 case GIMPLE_OMP_PARALLEL:
2099 t = unshare_expr (gimple_omp_parallel_clauses (stmt)); 2173 t = unshare_expr (gimple_omp_parallel_clauses (stmt));
2100 gimple_omp_parallel_set_clauses (copy, t); 2174 gimple_omp_parallel_set_clauses (copy, t);
2101 t = unshare_expr (gimple_omp_parallel_child_fn (stmt)); 2175 t = unshare_expr (gimple_omp_parallel_child_fn (stmt));
2102 gimple_omp_parallel_set_child_fn (copy, t); 2176 gimple_omp_parallel_set_child_fn (copy, t);
2103 t = unshare_expr (gimple_omp_parallel_data_arg (stmt)); 2177 t = unshare_expr (gimple_omp_parallel_data_arg (stmt));
2104 gimple_omp_parallel_set_data_arg (copy, t); 2178 gimple_omp_parallel_set_data_arg (copy, t);
2105 goto copy_omp_body; 2179 goto copy_omp_body;
2106 2180
2107 case GIMPLE_OMP_TASK: 2181 case GIMPLE_OMP_TASK:
2108 t = unshare_expr (gimple_omp_task_clauses (stmt)); 2182 t = unshare_expr (gimple_omp_task_clauses (stmt));
2109 gimple_omp_task_set_clauses (copy, t); 2183 gimple_omp_task_set_clauses (copy, t);
2110 t = unshare_expr (gimple_omp_task_child_fn (stmt)); 2184 t = unshare_expr (gimple_omp_task_child_fn (stmt));
2111 gimple_omp_task_set_child_fn (copy, t); 2185 gimple_omp_task_set_child_fn (copy, t);
2112 t = unshare_expr (gimple_omp_task_data_arg (stmt)); 2186 t = unshare_expr (gimple_omp_task_data_arg (stmt));
2113 gimple_omp_task_set_data_arg (copy, t); 2187 gimple_omp_task_set_data_arg (copy, t);
2114 t = unshare_expr (gimple_omp_task_copy_fn (stmt)); 2188 t = unshare_expr (gimple_omp_task_copy_fn (stmt));
2115 gimple_omp_task_set_copy_fn (copy, t); 2189 gimple_omp_task_set_copy_fn (copy, t);
2116 t = unshare_expr (gimple_omp_task_arg_size (stmt)); 2190 t = unshare_expr (gimple_omp_task_arg_size (stmt));
2117 gimple_omp_task_set_arg_size (copy, t); 2191 gimple_omp_task_set_arg_size (copy, t);
2118 t = unshare_expr (gimple_omp_task_arg_align (stmt)); 2192 t = unshare_expr (gimple_omp_task_arg_align (stmt));
2119 gimple_omp_task_set_arg_align (copy, t); 2193 gimple_omp_task_set_arg_align (copy, t);
2120 goto copy_omp_body; 2194 goto copy_omp_body;
2121 2195
2122 case GIMPLE_OMP_CRITICAL: 2196 case GIMPLE_OMP_CRITICAL:
2123 t = unshare_expr (gimple_omp_critical_name (stmt)); 2197 t = unshare_expr (gimple_omp_critical_name (stmt));
2124 gimple_omp_critical_set_name (copy, t); 2198 gimple_omp_critical_set_name (copy, t);
2125 goto copy_omp_body; 2199 goto copy_omp_body;
2126 2200
2127 case GIMPLE_OMP_SECTIONS: 2201 case GIMPLE_OMP_SECTIONS:
2128 t = unshare_expr (gimple_omp_sections_clauses (stmt)); 2202 t = unshare_expr (gimple_omp_sections_clauses (stmt));
2129 gimple_omp_sections_set_clauses (copy, t); 2203 gimple_omp_sections_set_clauses (copy, t);
2130 t = unshare_expr (gimple_omp_sections_control (stmt)); 2204 t = unshare_expr (gimple_omp_sections_control (stmt));
2131 gimple_omp_sections_set_control (copy, t); 2205 gimple_omp_sections_set_control (copy, t);
2132 /* FALLTHRU */ 2206 /* FALLTHRU */
2133 2207
2134 case GIMPLE_OMP_SINGLE: 2208 case GIMPLE_OMP_SINGLE:
2135 case GIMPLE_OMP_SECTION: 2209 case GIMPLE_OMP_SECTION:
2136 case GIMPLE_OMP_MASTER: 2210 case GIMPLE_OMP_MASTER:
2137 case GIMPLE_OMP_ORDERED: 2211 case GIMPLE_OMP_ORDERED:
2138 copy_omp_body: 2212 copy_omp_body:
2139 new_seq = gimple_seq_copy (gimple_omp_body (stmt)); 2213 new_seq = gimple_seq_copy (gimple_omp_body (stmt));
2140 gimple_omp_set_body (copy, new_seq); 2214 gimple_omp_set_body (copy, new_seq);
2141 break; 2215 break;
2142 2216
2143 case GIMPLE_WITH_CLEANUP_EXPR: 2217 case GIMPLE_WITH_CLEANUP_EXPR:
2144 new_seq = gimple_seq_copy (gimple_wce_cleanup (stmt)); 2218 new_seq = gimple_seq_copy (gimple_wce_cleanup (stmt));
2145 gimple_wce_set_cleanup (copy, new_seq); 2219 gimple_wce_set_cleanup (copy, new_seq);
2146 break; 2220 break;
2147 2221
2148 default: 2222 default:
2149 gcc_unreachable (); 2223 gcc_unreachable ();
2150 } 2224 }
2151 } 2225 }
2152 2226
2153 /* Make copy of operands. */ 2227 /* Make copy of operands. */
2154 if (num_ops > 0) 2228 if (num_ops > 0)
2155 { 2229 {
2318 } 2392 }
2319 2393
2320 return false; 2394 return false;
2321 } 2395 }
2322 2396
2323
2324 /* Helper for gimple_could_trap_p and gimple_assign_rhs_could_trap_p. 2397 /* Helper for gimple_could_trap_p and gimple_assign_rhs_could_trap_p.
2325 Return true if S can trap. If INCLUDE_LHS is true and S is a 2398 Return true if S can trap. When INCLUDE_MEM is true, check whether
2326 GIMPLE_ASSIGN, the LHS of the assignment is also checked. 2399 the memory operations could trap. When INCLUDE_STORES is true and
2327 Otherwise, only the RHS of the assignment is checked. */ 2400 S is a GIMPLE_ASSIGN, the LHS of the assignment is also checked. */
2328 2401
2329 static bool 2402 bool
2330 gimple_could_trap_p_1 (gimple s, bool include_lhs) 2403 gimple_could_trap_p_1 (gimple s, bool include_mem, bool include_stores)
2331 { 2404 {
2332 unsigned i, start;
2333 tree t, div = NULL_TREE; 2405 tree t, div = NULL_TREE;
2334 enum tree_code op; 2406 enum tree_code op;
2335 2407
2336 start = (is_gimple_assign (s) && !include_lhs) ? 1 : 0; 2408 if (include_mem)
2337 2409 {
2338 for (i = start; i < gimple_num_ops (s); i++) 2410 unsigned i, start = (is_gimple_assign (s) && !include_stores) ? 1 : 0;
2339 if (tree_could_trap_p (gimple_op (s, i))) 2411
2340 return true; 2412 for (i = start; i < gimple_num_ops (s); i++)
2413 if (tree_could_trap_p (gimple_op (s, i)))
2414 return true;
2415 }
2341 2416
2342 switch (gimple_code (s)) 2417 switch (gimple_code (s))
2343 { 2418 {
2344 case GIMPLE_ASM: 2419 case GIMPLE_ASM:
2345 return gimple_asm_volatile_p (s); 2420 return gimple_asm_volatile_p (s);
2364 default: 2439 default:
2365 break; 2440 break;
2366 } 2441 }
2367 2442
2368 return false; 2443 return false;
2369 2444 }
2370 }
2371
2372 2445
2373 /* Return true if statement S can trap. */ 2446 /* Return true if statement S can trap. */
2374 2447
2375 bool 2448 bool
2376 gimple_could_trap_p (gimple s) 2449 gimple_could_trap_p (gimple s)
2377 { 2450 {
2378 return gimple_could_trap_p_1 (s, true); 2451 return gimple_could_trap_p_1 (s, true, true);
2379 } 2452 }
2380
2381 2453
2382 /* Return true if RHS of a GIMPLE_ASSIGN S can trap. */ 2454 /* Return true if RHS of a GIMPLE_ASSIGN S can trap. */
2383 2455
2384 bool 2456 bool
2385 gimple_assign_rhs_could_trap_p (gimple s) 2457 gimple_assign_rhs_could_trap_p (gimple s)
2386 { 2458 {
2387 gcc_assert (is_gimple_assign (s)); 2459 gcc_assert (is_gimple_assign (s));
2388 return gimple_could_trap_p_1 (s, false); 2460 return gimple_could_trap_p_1 (s, true, false);
2389 } 2461 }
2390 2462
2391 2463
2392 /* Print debugging information for gimple stmts generated. */ 2464 /* Print debugging information for gimple stmts generated. */
2393 2465
2426 2498
2427 if (rhs_class == GIMPLE_UNARY_RHS || rhs_class == GIMPLE_SINGLE_RHS) 2499 if (rhs_class == GIMPLE_UNARY_RHS || rhs_class == GIMPLE_SINGLE_RHS)
2428 return 1; 2500 return 1;
2429 else if (rhs_class == GIMPLE_BINARY_RHS) 2501 else if (rhs_class == GIMPLE_BINARY_RHS)
2430 return 2; 2502 return 2;
2503 else if (rhs_class == GIMPLE_TERNARY_RHS)
2504 return 3;
2431 else 2505 else
2432 gcc_unreachable (); 2506 gcc_unreachable ();
2433 } 2507 }
2434 2508
2435 #define DEFTREECODE(SYM, STRING, TYPE, NARGS) \ 2509 #define DEFTREECODE(SYM, STRING, TYPE, NARGS) \
2436 (unsigned char) \ 2510 (unsigned char) \
2437 ((TYPE) == tcc_unary ? GIMPLE_UNARY_RHS \ 2511 ((TYPE) == tcc_unary ? GIMPLE_UNARY_RHS \
2438 : ((TYPE) == tcc_binary \ 2512 : ((TYPE) == tcc_binary \
2439 || (TYPE) == tcc_comparison) ? GIMPLE_BINARY_RHS \ 2513 || (TYPE) == tcc_comparison) ? GIMPLE_BINARY_RHS \
2440 : ((TYPE) == tcc_constant \ 2514 : ((TYPE) == tcc_constant \
2441 || (TYPE) == tcc_declaration \ 2515 || (TYPE) == tcc_declaration \
2442 || (TYPE) == tcc_reference) ? GIMPLE_SINGLE_RHS \ 2516 || (TYPE) == tcc_reference) ? GIMPLE_SINGLE_RHS \
2443 : ((SYM) == TRUTH_AND_EXPR \ 2517 : ((SYM) == TRUTH_AND_EXPR \
2444 || (SYM) == TRUTH_OR_EXPR \ 2518 || (SYM) == TRUTH_OR_EXPR \
2445 || (SYM) == TRUTH_XOR_EXPR) ? GIMPLE_BINARY_RHS \ 2519 || (SYM) == TRUTH_XOR_EXPR) ? GIMPLE_BINARY_RHS \
2446 : (SYM) == TRUTH_NOT_EXPR ? GIMPLE_UNARY_RHS \ 2520 : (SYM) == TRUTH_NOT_EXPR ? GIMPLE_UNARY_RHS \
2447 : ((SYM) == COND_EXPR \ 2521 : ((SYM) == WIDEN_MULT_PLUS_EXPR \
2448 || (SYM) == CONSTRUCTOR \ 2522 || (SYM) == WIDEN_MULT_MINUS_EXPR \
2449 || (SYM) == OBJ_TYPE_REF \ 2523 || (SYM) == FMA_EXPR) ? GIMPLE_TERNARY_RHS \
2450 || (SYM) == ASSERT_EXPR \ 2524 : ((SYM) == COND_EXPR \
2451 || (SYM) == ADDR_EXPR \ 2525 || (SYM) == CONSTRUCTOR \
2452 || (SYM) == WITH_SIZE_EXPR \ 2526 || (SYM) == OBJ_TYPE_REF \
2453 || (SYM) == SSA_NAME \ 2527 || (SYM) == ASSERT_EXPR \
2454 || (SYM) == POLYNOMIAL_CHREC \ 2528 || (SYM) == ADDR_EXPR \
2455 || (SYM) == DOT_PROD_EXPR \ 2529 || (SYM) == WITH_SIZE_EXPR \
2456 || (SYM) == VEC_COND_EXPR \ 2530 || (SYM) == SSA_NAME \
2457 || (SYM) == REALIGN_LOAD_EXPR) ? GIMPLE_SINGLE_RHS \ 2531 || (SYM) == POLYNOMIAL_CHREC \
2532 || (SYM) == DOT_PROD_EXPR \
2533 || (SYM) == VEC_COND_EXPR \
2534 || (SYM) == REALIGN_LOAD_EXPR) ? GIMPLE_SINGLE_RHS \
2458 : GIMPLE_INVALID_RHS), 2535 : GIMPLE_INVALID_RHS),
2459 #define END_OF_BASE_TREE_CODES (unsigned char) GIMPLE_INVALID_RHS, 2536 #define END_OF_BASE_TREE_CODES (unsigned char) GIMPLE_INVALID_RHS,
2460 2537
2461 const unsigned char gimple_rhs_class_table[] = { 2538 const unsigned char gimple_rhs_class_table[] = {
2462 #include "all-tree.def" 2539 #include "all-tree.def"
2466 #undef END_OF_BASE_TREE_CODES 2543 #undef END_OF_BASE_TREE_CODES
2467 2544
2468 /* For the definitive definition of GIMPLE, see doc/tree-ssa.texi. */ 2545 /* For the definitive definition of GIMPLE, see doc/tree-ssa.texi. */
2469 2546
2470 /* Validation of GIMPLE expressions. */ 2547 /* Validation of GIMPLE expressions. */
2471
2472 /* Return true if OP is an acceptable tree node to be used as a GIMPLE
2473 operand. */
2474
2475 bool
2476 is_gimple_operand (const_tree op)
2477 {
2478 return op && get_gimple_rhs_class (TREE_CODE (op)) == GIMPLE_SINGLE_RHS;
2479 }
2480 2548
2481 /* Returns true iff T is a valid RHS for an assignment to a renamed 2549 /* Returns true iff T is a valid RHS for an assignment to a renamed
2482 user -- or front-end generated artificial -- variable. */ 2550 user -- or front-end generated artificial -- variable. */
2483 2551
2484 bool 2552 bool
2527 /* Return true if T is something whose address can be taken. */ 2595 /* Return true if T is something whose address can be taken. */
2528 2596
2529 bool 2597 bool
2530 is_gimple_addressable (tree t) 2598 is_gimple_addressable (tree t)
2531 { 2599 {
2532 return (is_gimple_id (t) || handled_component_p (t) || INDIRECT_REF_P (t)); 2600 return (is_gimple_id (t) || handled_component_p (t)
2601 || TREE_CODE (t) == MEM_REF);
2533 } 2602 }
2534 2603
2535 /* Return true if T is a valid gimple constant. */ 2604 /* Return true if T is a valid gimple constant. */
2536 2605
2537 bool 2606 bool
2578 return false; 2647 return false;
2579 2648
2580 op = TREE_OPERAND (op, 0); 2649 op = TREE_OPERAND (op, 0);
2581 } 2650 }
2582 2651
2583 if (CONSTANT_CLASS_P (op) || INDIRECT_REF_P (op)) 2652 if (CONSTANT_CLASS_P (op) || TREE_CODE (op) == MEM_REF)
2584 return true; 2653 return true;
2585 2654
2586 switch (TREE_CODE (op)) 2655 switch (TREE_CODE (op))
2587 { 2656 {
2588 case PARM_DECL: 2657 case PARM_DECL:
2638 2707
2639 if (TREE_CODE (t) != ADDR_EXPR) 2708 if (TREE_CODE (t) != ADDR_EXPR)
2640 return false; 2709 return false;
2641 2710
2642 op = strip_invariant_refs (TREE_OPERAND (t, 0)); 2711 op = strip_invariant_refs (TREE_OPERAND (t, 0));
2643 2712 if (!op)
2644 return op && (CONSTANT_CLASS_P (op) || decl_address_invariant_p (op)); 2713 return false;
2714
2715 if (TREE_CODE (op) == MEM_REF)
2716 {
2717 const_tree op0 = TREE_OPERAND (op, 0);
2718 return (TREE_CODE (op0) == ADDR_EXPR
2719 && (CONSTANT_CLASS_P (TREE_OPERAND (op0, 0))
2720 || decl_address_invariant_p (TREE_OPERAND (op0, 0))));
2721 }
2722
2723 return CONSTANT_CLASS_P (op) || decl_address_invariant_p (op);
2645 } 2724 }
2646 2725
2647 /* Return true if T is a gimple invariant address at IPA level 2726 /* Return true if T is a gimple invariant address at IPA level
2648 (so addresses of variables on stack are not allowed). */ 2727 (so addresses of variables on stack are not allowed). */
2649 2728
2856 bool 2935 bool
2857 is_gimple_min_lval (tree t) 2936 is_gimple_min_lval (tree t)
2858 { 2937 {
2859 if (!(t = CONST_CAST_TREE (strip_invariant_refs (t)))) 2938 if (!(t = CONST_CAST_TREE (strip_invariant_refs (t))))
2860 return false; 2939 return false;
2861 return (is_gimple_id (t) || TREE_CODE (t) == INDIRECT_REF); 2940 return (is_gimple_id (t) || TREE_CODE (t) == MEM_REF);
2862 }
2863
2864 /* Return true if T is a typecast operation. */
2865
2866 bool
2867 is_gimple_cast (tree t)
2868 {
2869 return (CONVERT_EXPR_P (t)
2870 || TREE_CODE (t) == FIX_TRUNC_EXPR);
2871 } 2941 }
2872 2942
2873 /* Return true if T is a valid function operand of a CALL_EXPR. */ 2943 /* Return true if T is a valid function operand of a CALL_EXPR. */
2874 2944
2875 bool 2945 bool
2876 is_gimple_call_addr (tree t) 2946 is_gimple_call_addr (tree t)
2877 { 2947 {
2878 return (TREE_CODE (t) == OBJ_TYPE_REF || is_gimple_val (t)); 2948 return (TREE_CODE (t) == OBJ_TYPE_REF || is_gimple_val (t));
2949 }
2950
2951 /* Return true if T is a valid address operand of a MEM_REF. */
2952
2953 bool
2954 is_gimple_mem_ref_addr (tree t)
2955 {
2956 return (is_gimple_reg (t)
2957 || TREE_CODE (t) == INTEGER_CST
2958 || (TREE_CODE (t) == ADDR_EXPR
2959 && (CONSTANT_CLASS_P (TREE_OPERAND (t, 0))
2960 || decl_address_invariant_p (TREE_OPERAND (t, 0)))));
2879 } 2961 }
2880 2962
2881 /* If T makes a function call, return the corresponding CALL_EXPR operand. 2963 /* If T makes a function call, return the corresponding CALL_EXPR operand.
2882 Otherwise, return NULL_TREE. */ 2964 Otherwise, return NULL_TREE. */
2883 2965
2907 get_base_address (tree t) 2989 get_base_address (tree t)
2908 { 2990 {
2909 while (handled_component_p (t)) 2991 while (handled_component_p (t))
2910 t = TREE_OPERAND (t, 0); 2992 t = TREE_OPERAND (t, 0);
2911 2993
2912 if (SSA_VAR_P (t) 2994 if ((TREE_CODE (t) == MEM_REF
2995 || TREE_CODE (t) == TARGET_MEM_REF)
2996 && TREE_CODE (TREE_OPERAND (t, 0)) == ADDR_EXPR)
2997 t = TREE_OPERAND (TREE_OPERAND (t, 0), 0);
2998
2999 if (TREE_CODE (t) == SSA_NAME
3000 || DECL_P (t)
2913 || TREE_CODE (t) == STRING_CST 3001 || TREE_CODE (t) == STRING_CST
2914 || TREE_CODE (t) == CONSTRUCTOR 3002 || TREE_CODE (t) == CONSTRUCTOR
2915 || INDIRECT_REF_P (t)) 3003 || INDIRECT_REF_P (t)
3004 || TREE_CODE (t) == MEM_REF
3005 || TREE_CODE (t) == TARGET_MEM_REF)
2916 return t; 3006 return t;
2917 else 3007 else
2918 return NULL_TREE; 3008 return NULL_TREE;
2919 } 3009 }
2920 3010
3038 gimple_set_vdef (new_stmt, gimple_vdef (stmt)); 3128 gimple_set_vdef (new_stmt, gimple_vdef (stmt));
3039 3129
3040 gimple_set_block (new_stmt, gimple_block (stmt)); 3130 gimple_set_block (new_stmt, gimple_block (stmt));
3041 if (gimple_has_location (stmt)) 3131 if (gimple_has_location (stmt))
3042 gimple_set_location (new_stmt, gimple_location (stmt)); 3132 gimple_set_location (new_stmt, gimple_location (stmt));
3043 3133 gimple_call_copy_flags (new_stmt, stmt);
3044 /* Carry all the flags to the new GIMPLE_CALL. */
3045 gimple_call_set_chain (new_stmt, gimple_call_chain (stmt)); 3134 gimple_call_set_chain (new_stmt, gimple_call_chain (stmt));
3046 gimple_call_set_tail (new_stmt, gimple_call_tail_p (stmt));
3047 gimple_call_set_cannot_inline (new_stmt, gimple_call_cannot_inline_p (stmt));
3048 gimple_call_set_return_slot_opt (new_stmt, gimple_call_return_slot_opt_p (stmt));
3049 gimple_call_set_from_thunk (new_stmt, gimple_call_from_thunk_p (stmt));
3050 gimple_call_set_va_arg_pack (new_stmt, gimple_call_va_arg_pack_p (stmt));
3051 #ifndef noCbC 3135 #ifndef noCbC
3052 gimple_call_set_cbc_goto (new_stmt, gimple_call_cbc_goto_p (stmt)); 3136 gimple_call_set_cbc_goto (new_stmt, gimple_call_cbc_goto_p (stmt));
3053 #endif 3137 #endif
3054 3138
3055 gimple_set_modified (new_stmt, true); 3139 gimple_set_modified (new_stmt, true);
3056 return new_stmt; 3140 return new_stmt;
3057 } 3141 }
3058 3142
3059 3143
3060 static hashval_t gimple_type_hash (const void *); 3144 static hashval_t gimple_type_hash_1 (const void *, enum gtc_mode);
3061 3145
3062 /* Structure used to maintain a cache of some type pairs compared by 3146 /* Structure used to maintain a cache of some type pairs compared by
3063 gimple_types_compatible_p when comparing aggregate types. There are 3147 gimple_types_compatible_p when comparing aggregate types. There are
3064 four possible values for SAME_P: 3148 three possible values for SAME_P:
3065 3149
3066 -2: The pair (T1, T2) has just been inserted in the table. 3150 -2: The pair (T1, T2) has just been inserted in the table.
3067 -1: The pair (T1, T2) is currently being compared. 3151 0: T1 and T2 are different types.
3068 0: T1 and T2 are different types. 3152 1: T1 and T2 are the same type.
3069 1: T1 and T2 are the same type. 3153
3070 3154 The two elements in the SAME_P array are indexed by the comparison
3071 This table is only used when comparing aggregate types to avoid 3155 mode gtc_mode. */
3072 infinite recursion due to self-referential types. */ 3156
3073 struct type_pair_d 3157 struct type_pair_d
3074 { 3158 {
3075 unsigned int uid1; 3159 unsigned int uid1;
3076 unsigned int uid2; 3160 unsigned int uid2;
3077 int same_p; 3161 signed char same_p[2];
3078 }; 3162 };
3079 typedef struct type_pair_d *type_pair_t; 3163 typedef struct type_pair_d *type_pair_t;
3164
3165 DEF_VEC_P(type_pair_t);
3166 DEF_VEC_ALLOC_P(type_pair_t,heap);
3080 3167
3081 /* Return a hash value for the type pair pointed-to by P. */ 3168 /* Return a hash value for the type pair pointed-to by P. */
3082 3169
3083 static hashval_t 3170 static hashval_t
3084 type_pair_hash (const void *p) 3171 type_pair_hash (const void *p)
3126 else 3213 else
3127 { 3214 {
3128 p = XOBNEW (ob_p, struct type_pair_d); 3215 p = XOBNEW (ob_p, struct type_pair_d);
3129 p->uid1 = TYPE_UID (t1); 3216 p->uid1 = TYPE_UID (t1);
3130 p->uid2 = TYPE_UID (t2); 3217 p->uid2 = TYPE_UID (t2);
3131 p->same_p = -2; 3218 p->same_p[0] = -2;
3219 p->same_p[1] = -2;
3132 *slot = (void *) p; 3220 *slot = (void *) p;
3133 } 3221 }
3134 3222
3135 return p; 3223 return p;
3136 } 3224 }
3137 3225
3226 /* Per pointer state for the SCC finding. The on_sccstack flag
3227 is not strictly required, it is true when there is no hash value
3228 recorded for the type and false otherwise. But querying that
3229 is slower. */
3230
3231 struct sccs
3232 {
3233 unsigned int dfsnum;
3234 unsigned int low;
3235 bool on_sccstack;
3236 union {
3237 hashval_t hash;
3238 signed char same_p;
3239 } u;
3240 };
3241
3242 static unsigned int next_dfs_num;
3243 static unsigned int gtc_next_dfs_num;
3244
3245
3246 /* GIMPLE type merging cache. A direct-mapped cache based on TYPE_UID. */
3247
3248 typedef struct GTY(()) gimple_type_leader_entry_s {
3249 tree type;
3250 tree leader;
3251 } gimple_type_leader_entry;
3252
3253 #define GIMPLE_TYPE_LEADER_SIZE 16381
3254 static GTY((length("GIMPLE_TYPE_LEADER_SIZE"))) gimple_type_leader_entry
3255 *gimple_type_leader;
3256
3257 /* Lookup an existing leader for T and return it or NULL_TREE, if
3258 there is none in the cache. */
3259
3260 static tree
3261 gimple_lookup_type_leader (tree t)
3262 {
3263 gimple_type_leader_entry *leader;
3264
3265 if (!gimple_type_leader)
3266 return NULL_TREE;
3267
3268 leader = &gimple_type_leader[TYPE_UID (t) % GIMPLE_TYPE_LEADER_SIZE];
3269 if (leader->type != t)
3270 return NULL_TREE;
3271
3272 return leader->leader;
3273 }
3138 3274
3139 /* Return true if T1 and T2 have the same name. If FOR_COMPLETION_P is 3275 /* Return true if T1 and T2 have the same name. If FOR_COMPLETION_P is
3140 true then if any type has no name return false, otherwise return 3276 true then if any type has no name return false, otherwise return
3141 true if both types have no names. */ 3277 true if both types have no names. */
3142 3278
3175 return true; 3311 return true;
3176 3312
3177 return false; 3313 return false;
3178 } 3314 }
3179 3315
3180 /* Return true if the field decls F1 and F2 are at the same offset. */ 3316 /* Return true if the field decls F1 and F2 are at the same offset.
3317
3318 This is intended to be used on GIMPLE types only. In order to
3319 compare GENERIC types, use fields_compatible_p instead. */
3181 3320
3182 bool 3321 bool
3183 compare_field_offset (tree f1, tree f2) 3322 gimple_compare_field_offset (tree f1, tree f2)
3184 { 3323 {
3185 if (DECL_OFFSET_ALIGN (f1) == DECL_OFFSET_ALIGN (f2)) 3324 if (DECL_OFFSET_ALIGN (f1) == DECL_OFFSET_ALIGN (f2))
3186 return (operand_equal_p (DECL_FIELD_OFFSET (f1), 3325 {
3187 DECL_FIELD_OFFSET (f2), 0) 3326 tree offset1 = DECL_FIELD_OFFSET (f1);
3188 && tree_int_cst_equal (DECL_FIELD_BIT_OFFSET (f1), 3327 tree offset2 = DECL_FIELD_OFFSET (f2);
3189 DECL_FIELD_BIT_OFFSET (f2))); 3328 return ((offset1 == offset2
3329 /* Once gimplification is done, self-referential offsets are
3330 instantiated as operand #2 of the COMPONENT_REF built for
3331 each access and reset. Therefore, they are not relevant
3332 anymore and fields are interchangeable provided that they
3333 represent the same access. */
3334 || (TREE_CODE (offset1) == PLACEHOLDER_EXPR
3335 && TREE_CODE (offset2) == PLACEHOLDER_EXPR
3336 && (DECL_SIZE (f1) == DECL_SIZE (f2)
3337 || (TREE_CODE (DECL_SIZE (f1)) == PLACEHOLDER_EXPR
3338 && TREE_CODE (DECL_SIZE (f2)) == PLACEHOLDER_EXPR)
3339 || operand_equal_p (DECL_SIZE (f1), DECL_SIZE (f2), 0))
3340 && DECL_ALIGN (f1) == DECL_ALIGN (f2))
3341 || operand_equal_p (offset1, offset2, 0))
3342 && tree_int_cst_equal (DECL_FIELD_BIT_OFFSET (f1),
3343 DECL_FIELD_BIT_OFFSET (f2)));
3344 }
3190 3345
3191 /* Fortran and C do not always agree on what DECL_OFFSET_ALIGN 3346 /* Fortran and C do not always agree on what DECL_OFFSET_ALIGN
3192 should be, so handle differing ones specially by decomposing 3347 should be, so handle differing ones specially by decomposing
3193 the offset into a byte and bit offset manually. */ 3348 the offset into a byte and bit offset manually. */
3194 if (host_integerp (DECL_FIELD_OFFSET (f1), 0) 3349 if (host_integerp (DECL_FIELD_OFFSET (f1), 0)
3208 } 3363 }
3209 3364
3210 return false; 3365 return false;
3211 } 3366 }
3212 3367
3213 /* Return 1 iff T1 and T2 are structurally identical. 3368 /* If the type T1 and the type T2 are a complete and an incomplete
3214 Otherwise, return 0. */ 3369 variant of the same type return true. */
3215 3370
3216 static int 3371 static bool
3217 gimple_types_compatible_p (tree t1, tree t2) 3372 gimple_compatible_complete_and_incomplete_subtype_p (tree t1, tree t2)
3218 { 3373 {
3219 type_pair_t p = NULL; 3374 /* If one pointer points to an incomplete type variant of
3375 the other pointed-to type they are the same. */
3376 if (TREE_CODE (t1) == TREE_CODE (t2)
3377 && RECORD_OR_UNION_TYPE_P (t1)
3378 && (!COMPLETE_TYPE_P (t1)
3379 || !COMPLETE_TYPE_P (t2))
3380 && TYPE_QUALS (t1) == TYPE_QUALS (t2)
3381 && compare_type_names_p (TYPE_MAIN_VARIANT (t1),
3382 TYPE_MAIN_VARIANT (t2), true))
3383 return true;
3384 return false;
3385 }
3386
3387 static bool
3388 gimple_types_compatible_p_1 (tree, tree, enum gtc_mode, type_pair_t,
3389 VEC(type_pair_t, heap) **,
3390 struct pointer_map_t *, struct obstack *);
3391
3392 /* DFS visit the edge from the callers type pair with state *STATE to
3393 the pair T1, T2 while operating in FOR_MERGING_P mode.
3394 Update the merging status if it is not part of the SCC containing the
3395 callers pair and return it.
3396 SCCSTACK, SCCSTATE and SCCSTATE_OBSTACK are state for the DFS walk done. */
3397
3398 static bool
3399 gtc_visit (tree t1, tree t2, enum gtc_mode mode,
3400 struct sccs *state,
3401 VEC(type_pair_t, heap) **sccstack,
3402 struct pointer_map_t *sccstate,
3403 struct obstack *sccstate_obstack)
3404 {
3405 struct sccs *cstate = NULL;
3406 type_pair_t p;
3407 void **slot;
3220 3408
3221 /* Check first for the obvious case of pointer identity. */ 3409 /* Check first for the obvious case of pointer identity. */
3222 if (t1 == t2) 3410 if (t1 == t2)
3223 return 1; 3411 return true;
3224 3412
3225 /* Check that we have two types to compare. */ 3413 /* Check that we have two types to compare. */
3226 if (t1 == NULL_TREE || t2 == NULL_TREE) 3414 if (t1 == NULL_TREE || t2 == NULL_TREE)
3227 return 0; 3415 return false;
3416
3417 /* If the types have been previously registered and found equal
3418 they still are. */
3419 if (mode == GTC_MERGE)
3420 {
3421 tree leader1 = gimple_lookup_type_leader (t1);
3422 tree leader2 = gimple_lookup_type_leader (t2);
3423 if (leader1 == t2
3424 || t1 == leader2
3425 || (leader1 && leader1 == leader2))
3426 return true;
3427 }
3428 else if (mode == GTC_DIAG)
3429 {
3430 if (TYPE_CANONICAL (t1)
3431 && TYPE_CANONICAL (t1) == TYPE_CANONICAL (t2))
3432 return true;
3433 }
3228 3434
3229 /* Can't be the same type if the types don't have the same code. */ 3435 /* Can't be the same type if the types don't have the same code. */
3230 if (TREE_CODE (t1) != TREE_CODE (t2)) 3436 if (TREE_CODE (t1) != TREE_CODE (t2))
3231 return 0; 3437 return false;
3232 3438
3233 /* Can't be the same type if they have different CV qualifiers. */ 3439 /* Can't be the same type if they have different CV qualifiers. */
3234 if (TYPE_QUALS (t1) != TYPE_QUALS (t2)) 3440 if (TYPE_QUALS (t1) != TYPE_QUALS (t2))
3235 return 0; 3441 return false;
3236 3442
3237 /* Void types are always the same. */ 3443 /* Void types are always the same. */
3238 if (TREE_CODE (t1) == VOID_TYPE) 3444 if (TREE_CODE (t1) == VOID_TYPE)
3239 return 1; 3445 return true;
3240 3446
3241 /* For numerical types do some simple checks before doing three 3447 /* Do some simple checks before doing three hashtable queries. */
3242 hashtable queries. */
3243 if (INTEGRAL_TYPE_P (t1) 3448 if (INTEGRAL_TYPE_P (t1)
3244 || SCALAR_FLOAT_TYPE_P (t1) 3449 || SCALAR_FLOAT_TYPE_P (t1)
3245 || FIXED_POINT_TYPE_P (t1) 3450 || FIXED_POINT_TYPE_P (t1)
3246 || TREE_CODE (t1) == VECTOR_TYPE 3451 || TREE_CODE (t1) == VECTOR_TYPE
3247 || TREE_CODE (t1) == COMPLEX_TYPE 3452 || TREE_CODE (t1) == COMPLEX_TYPE
3248 || TREE_CODE (t1) == OFFSET_TYPE) 3453 || TREE_CODE (t1) == OFFSET_TYPE)
3249 { 3454 {
3250 /* Can't be the same type if they have different alignment, 3455 /* Can't be the same type if they have different alignment,
3251 sign, precision or mode. */ 3456 sign, precision or mode. */
3252 if (TYPE_ALIGN (t1) != TYPE_ALIGN (t2) 3457 if (TYPE_ALIGN (t1) != TYPE_ALIGN (t2)
3253 || TYPE_PRECISION (t1) != TYPE_PRECISION (t2) 3458 || TYPE_PRECISION (t1) != TYPE_PRECISION (t2)
3254 || TYPE_MODE (t1) != TYPE_MODE (t2) 3459 || TYPE_MODE (t1) != TYPE_MODE (t2)
3255 || TYPE_UNSIGNED (t1) != TYPE_UNSIGNED (t2)) 3460 || TYPE_UNSIGNED (t1) != TYPE_UNSIGNED (t2))
3256 return 0; 3461 return false;
3257 3462
3258 if (TREE_CODE (t1) == INTEGER_TYPE 3463 if (TREE_CODE (t1) == INTEGER_TYPE
3259 && (TYPE_IS_SIZETYPE (t1) != TYPE_IS_SIZETYPE (t2) 3464 && (TYPE_IS_SIZETYPE (t1) != TYPE_IS_SIZETYPE (t2)
3260 || TYPE_STRING_FLAG (t1) != TYPE_STRING_FLAG (t2))) 3465 || TYPE_STRING_FLAG (t1) != TYPE_STRING_FLAG (t2)))
3261 return 0; 3466 return false;
3262 3467
3263 /* That's all we need to check for float and fixed-point types. */ 3468 /* That's all we need to check for float and fixed-point types. */
3264 if (SCALAR_FLOAT_TYPE_P (t1) 3469 if (SCALAR_FLOAT_TYPE_P (t1)
3265 || FIXED_POINT_TYPE_P (t1)) 3470 || FIXED_POINT_TYPE_P (t1))
3266 return 1; 3471 return true;
3267
3268 /* Perform cheap tail-recursion for vector and complex types. */
3269 if (TREE_CODE (t1) == VECTOR_TYPE
3270 || TREE_CODE (t1) == COMPLEX_TYPE)
3271 return gimple_types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2));
3272 3472
3273 /* For integral types fall thru to more complex checks. */ 3473 /* For integral types fall thru to more complex checks. */
3474 }
3475
3476 else if (AGGREGATE_TYPE_P (t1) || POINTER_TYPE_P (t1))
3477 {
3478 /* Can't be the same type if they have different alignment or mode. */
3479 if (TYPE_ALIGN (t1) != TYPE_ALIGN (t2)
3480 || TYPE_MODE (t1) != TYPE_MODE (t2))
3481 return false;
3274 } 3482 }
3275 3483
3276 /* If the hash values of t1 and t2 are different the types can't 3484 /* If the hash values of t1 and t2 are different the types can't
3277 possibly be the same. This helps keeping the type-pair hashtable 3485 possibly be the same. This helps keeping the type-pair hashtable
3278 small, only tracking comparisons for hash collisions. */ 3486 small, only tracking comparisons for hash collisions. */
3279 if (gimple_type_hash (t1) != gimple_type_hash (t2)) 3487 if (gimple_type_hash_1 (t1, mode) != gimple_type_hash_1 (t2, mode))
3280 return 0; 3488 return false;
3281 3489
3282 /* If we've visited this type pair before (in the case of aggregates 3490 /* Allocate a new cache entry for this comparison. */
3283 with self-referential types), and we made a decision, return it. */
3284 p = lookup_type_pair (t1, t2, &gtc_visited, &gtc_ob); 3491 p = lookup_type_pair (t1, t2, &gtc_visited, &gtc_ob);
3285 if (p->same_p == 0 || p->same_p == 1) 3492 if (p->same_p[mode] == 0 || p->same_p[mode] == 1)
3286 { 3493 {
3287 /* We have already decided whether T1 and T2 are the 3494 /* We have already decided whether T1 and T2 are the
3288 same, return the cached result. */ 3495 same, return the cached result. */
3289 return p->same_p == 1; 3496 return p->same_p[mode] == 1;
3290 } 3497 }
3291 else if (p->same_p == -1) 3498
3292 { 3499 if ((slot = pointer_map_contains (sccstate, p)) != NULL)
3293 /* We are currently comparing this pair of types, assume 3500 cstate = (struct sccs *)*slot;
3294 that they are the same and let the caller decide. */ 3501 /* Not yet visited. DFS recurse. */
3295 return 1; 3502 if (!cstate)
3296 } 3503 {
3297 3504 gimple_types_compatible_p_1 (t1, t2, mode, p,
3298 gcc_assert (p->same_p == -2); 3505 sccstack, sccstate, sccstate_obstack);
3299 3506 cstate = (struct sccs *)* pointer_map_contains (sccstate, p);
3300 /* Mark the (T1, T2) comparison in progress. */ 3507 state->low = MIN (state->low, cstate->low);
3301 p->same_p = -1; 3508 }
3509 /* If the type is still on the SCC stack adjust the parents low. */
3510 if (cstate->dfsnum < state->dfsnum
3511 && cstate->on_sccstack)
3512 state->low = MIN (cstate->dfsnum, state->low);
3513
3514 /* Return the current lattice value. We start with an equality
3515 assumption so types part of a SCC will be optimistically
3516 treated equal unless proven otherwise. */
3517 return cstate->u.same_p;
3518 }
3519
3520 /* Worker for gimple_types_compatible.
3521 SCCSTACK, SCCSTATE and SCCSTATE_OBSTACK are state for the DFS walk done. */
3522
3523 static bool
3524 gimple_types_compatible_p_1 (tree t1, tree t2, enum gtc_mode mode,
3525 type_pair_t p,
3526 VEC(type_pair_t, heap) **sccstack,
3527 struct pointer_map_t *sccstate,
3528 struct obstack *sccstate_obstack)
3529 {
3530 struct sccs *state;
3531
3532 gcc_assert (p->same_p[mode] == -2);
3533
3534 state = XOBNEW (sccstate_obstack, struct sccs);
3535 *pointer_map_insert (sccstate, p) = state;
3536
3537 VEC_safe_push (type_pair_t, heap, *sccstack, p);
3538 state->dfsnum = gtc_next_dfs_num++;
3539 state->low = state->dfsnum;
3540 state->on_sccstack = true;
3541 /* Start with an equality assumption. As we DFS recurse into child
3542 SCCs this assumption may get revisited. */
3543 state->u.same_p = 1;
3302 3544
3303 /* If their attributes are not the same they can't be the same type. */ 3545 /* If their attributes are not the same they can't be the same type. */
3304 if (!attribute_list_equal (TYPE_ATTRIBUTES (t1), TYPE_ATTRIBUTES (t2))) 3546 if (!attribute_list_equal (TYPE_ATTRIBUTES (t1), TYPE_ATTRIBUTES (t2)))
3305 goto different_types; 3547 goto different_types;
3306 3548
3307 /* Do type-specific comparisons. */ 3549 /* Do type-specific comparisons. */
3308 switch (TREE_CODE (t1)) 3550 switch (TREE_CODE (t1))
3309 { 3551 {
3552 case VECTOR_TYPE:
3553 case COMPLEX_TYPE:
3554 if (!gtc_visit (TREE_TYPE (t1), TREE_TYPE (t2), mode,
3555 state, sccstack, sccstate, sccstate_obstack))
3556 goto different_types;
3557 goto same_types;
3558
3310 case ARRAY_TYPE: 3559 case ARRAY_TYPE:
3311 /* Array types are the same if the element types are the same and 3560 /* Array types are the same if the element types are the same and
3312 the number of elements are the same. */ 3561 the number of elements are the same. */
3313 if (!gimple_types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2)) 3562 if (!gtc_visit (TREE_TYPE (t1), TREE_TYPE (t2), mode,
3314 || TYPE_STRING_FLAG (t1) != TYPE_STRING_FLAG (t2) 3563 state, sccstack, sccstate, sccstate_obstack)
3315 || TYPE_NONALIASED_COMPONENT (t1) != TYPE_NONALIASED_COMPONENT (t2)) 3564 || TYPE_STRING_FLAG (t1) != TYPE_STRING_FLAG (t2)
3316 goto different_types; 3565 || TYPE_NONALIASED_COMPONENT (t1) != TYPE_NONALIASED_COMPONENT (t2))
3566 goto different_types;
3317 else 3567 else
3318 { 3568 {
3319 tree i1 = TYPE_DOMAIN (t1); 3569 tree i1 = TYPE_DOMAIN (t1);
3320 tree i2 = TYPE_DOMAIN (t2); 3570 tree i2 = TYPE_DOMAIN (t2);
3321 3571
3322 /* For an incomplete external array, the type domain can be 3572 /* For an incomplete external array, the type domain can be
3323 NULL_TREE. Check this condition also. */ 3573 NULL_TREE. Check this condition also. */
3324 if (i1 == NULL_TREE && i2 == NULL_TREE) 3574 if (i1 == NULL_TREE && i2 == NULL_TREE)
3325 goto same_types; 3575 goto same_types;
3326 else if (i1 == NULL_TREE || i2 == NULL_TREE) 3576 else if (i1 == NULL_TREE || i2 == NULL_TREE)
3327 goto different_types; 3577 goto different_types;
3328 /* If for a complete array type the possibly gimplified sizes 3578 /* If for a complete array type the possibly gimplified sizes
3329 are different the types are different. */ 3579 are different the types are different. */
3330 else if (((TYPE_SIZE (i1) != NULL) ^ (TYPE_SIZE (i2) != NULL)) 3580 else if (((TYPE_SIZE (i1) != NULL) ^ (TYPE_SIZE (i2) != NULL))
3331 || (TYPE_SIZE (i1) 3581 || (TYPE_SIZE (i1)
3332 && TYPE_SIZE (i2) 3582 && TYPE_SIZE (i2)
3333 && !operand_equal_p (TYPE_SIZE (i1), TYPE_SIZE (i2), 0))) 3583 && !operand_equal_p (TYPE_SIZE (i1), TYPE_SIZE (i2), 0)))
3334 goto different_types; 3584 goto different_types;
3335 else 3585 else
3336 { 3586 {
3337 tree min1 = TYPE_MIN_VALUE (i1); 3587 tree min1 = TYPE_MIN_VALUE (i1);
3338 tree min2 = TYPE_MIN_VALUE (i2); 3588 tree min2 = TYPE_MIN_VALUE (i2);
3339 tree max1 = TYPE_MAX_VALUE (i1); 3589 tree max1 = TYPE_MAX_VALUE (i1);
3340 tree max2 = TYPE_MAX_VALUE (i2); 3590 tree max2 = TYPE_MAX_VALUE (i2);
3341 3591
3342 /* The minimum/maximum values have to be the same. */ 3592 /* The minimum/maximum values have to be the same. */
3343 if ((min1 == min2 3593 if ((min1 == min2
3344 || (min1 && min2 && operand_equal_p (min1, min2, 0))) 3594 || (min1 && min2
3345 && (max1 == max2 3595 && ((TREE_CODE (min1) == PLACEHOLDER_EXPR
3346 || (max1 && max2 && operand_equal_p (max1, max2, 0)))) 3596 && TREE_CODE (min2) == PLACEHOLDER_EXPR)
3347 goto same_types; 3597 || operand_equal_p (min1, min2, 0))))
3348 else 3598 && (max1 == max2
3349 goto different_types; 3599 || (max1 && max2
3350 } 3600 && ((TREE_CODE (max1) == PLACEHOLDER_EXPR
3351 } 3601 && TREE_CODE (max2) == PLACEHOLDER_EXPR)
3602 || operand_equal_p (max1, max2, 0)))))
3603 goto same_types;
3604 else
3605 goto different_types;
3606 }
3607 }
3352 3608
3353 case METHOD_TYPE: 3609 case METHOD_TYPE:
3354 /* Method types should belong to the same class. */ 3610 /* Method types should belong to the same class. */
3355 if (!gimple_types_compatible_p (TYPE_METHOD_BASETYPE (t1), 3611 if (!gtc_visit (TYPE_METHOD_BASETYPE (t1), TYPE_METHOD_BASETYPE (t2),
3356 TYPE_METHOD_BASETYPE (t2))) 3612 mode, state, sccstack, sccstate, sccstate_obstack))
3357 goto different_types; 3613 goto different_types;
3358 3614
3359 /* Fallthru */ 3615 /* Fallthru */
3360 3616
3361 case FUNCTION_TYPE: 3617 case FUNCTION_TYPE:
3362 /* Function types are the same if the return type and arguments types 3618 /* Function types are the same if the return type and arguments types
3363 are the same. */ 3619 are the same. */
3364 if (!gimple_types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2))) 3620 if ((mode != GTC_DIAG
3365 goto different_types; 3621 || !gimple_compatible_complete_and_incomplete_subtype_p
3622 (TREE_TYPE (t1), TREE_TYPE (t2)))
3623 && !gtc_visit (TREE_TYPE (t1), TREE_TYPE (t2), mode,
3624 state, sccstack, sccstate, sccstate_obstack))
3625 goto different_types;
3626
3627 if (!targetm.comp_type_attributes (t1, t2))
3628 goto different_types;
3629
3630 if (TYPE_ARG_TYPES (t1) == TYPE_ARG_TYPES (t2))
3631 goto same_types;
3366 else 3632 else
3367 { 3633 {
3368 if (!targetm.comp_type_attributes (t1, t2)) 3634 tree parms1, parms2;
3369 goto different_types; 3635
3370 3636 for (parms1 = TYPE_ARG_TYPES (t1), parms2 = TYPE_ARG_TYPES (t2);
3371 if (TYPE_ARG_TYPES (t1) == TYPE_ARG_TYPES (t2)) 3637 parms1 && parms2;
3372 goto same_types; 3638 parms1 = TREE_CHAIN (parms1), parms2 = TREE_CHAIN (parms2))
3373 else 3639 {
3374 { 3640 if ((mode == GTC_MERGE
3375 tree parms1, parms2; 3641 || !gimple_compatible_complete_and_incomplete_subtype_p
3376 3642 (TREE_VALUE (parms1), TREE_VALUE (parms2)))
3377 for (parms1 = TYPE_ARG_TYPES (t1), parms2 = TYPE_ARG_TYPES (t2); 3643 && !gtc_visit (TREE_VALUE (parms1), TREE_VALUE (parms2), mode,
3378 parms1 && parms2; 3644 state, sccstack, sccstate, sccstate_obstack))
3379 parms1 = TREE_CHAIN (parms1), parms2 = TREE_CHAIN (parms2)) 3645 goto different_types;
3380 { 3646 }
3381 if (!gimple_types_compatible_p (TREE_VALUE (parms1), 3647
3382 TREE_VALUE (parms2))) 3648 if (parms1 || parms2)
3383 goto different_types; 3649 goto different_types;
3384 } 3650
3385 3651 goto same_types;
3386 if (parms1 || parms2) 3652 }
3387 goto different_types;
3388
3389 goto same_types;
3390 }
3391 }
3392 3653
3393 case OFFSET_TYPE: 3654 case OFFSET_TYPE:
3394 { 3655 {
3395 if (!gimple_types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2)) 3656 if (!gtc_visit (TREE_TYPE (t1), TREE_TYPE (t2), mode,
3396 || !gimple_types_compatible_p (TYPE_OFFSET_BASETYPE (t1), 3657 state, sccstack, sccstate, sccstate_obstack)
3397 TYPE_OFFSET_BASETYPE (t2))) 3658 || !gtc_visit (TYPE_OFFSET_BASETYPE (t1),
3398 goto different_types; 3659 TYPE_OFFSET_BASETYPE (t2), mode,
3399 3660 state, sccstack, sccstate, sccstate_obstack))
3400 goto same_types; 3661 goto different_types;
3662
3663 goto same_types;
3401 } 3664 }
3402 3665
3403 case POINTER_TYPE: 3666 case POINTER_TYPE:
3404 case REFERENCE_TYPE: 3667 case REFERENCE_TYPE:
3405 { 3668 {
3406 /* If the two pointers have different ref-all attributes, 3669 /* If the two pointers have different ref-all attributes,
3407 they can't be the same type. */ 3670 they can't be the same type. */
3408 if (TYPE_REF_CAN_ALIAS_ALL (t1) != TYPE_REF_CAN_ALIAS_ALL (t2)) 3671 if (TYPE_REF_CAN_ALIAS_ALL (t1) != TYPE_REF_CAN_ALIAS_ALL (t2))
3409 goto different_types; 3672 goto different_types;
3410 3673
3411 /* If one pointer points to an incomplete type variant of 3674 /* If one pointer points to an incomplete type variant of
3412 the other pointed-to type they are the same. */ 3675 the other pointed-to type they are the same. */
3413 if (TREE_CODE (TREE_TYPE (t1)) == TREE_CODE (TREE_TYPE (t2)) 3676 if (mode == GTC_DIAG
3414 && RECORD_OR_UNION_TYPE_P (TREE_TYPE (t1)) 3677 && gimple_compatible_complete_and_incomplete_subtype_p
3415 && (!COMPLETE_TYPE_P (TREE_TYPE (t1)) 3678 (TREE_TYPE (t1), TREE_TYPE (t2)))
3416 || !COMPLETE_TYPE_P (TREE_TYPE (t2))) 3679 goto same_types;
3417 && compare_type_names_p (TYPE_MAIN_VARIANT (TREE_TYPE (t1)), 3680
3418 TYPE_MAIN_VARIANT (TREE_TYPE (t2)), true)) 3681 /* Otherwise, pointer and reference types are the same if the
3419 { 3682 pointed-to types are the same. */
3420 /* Replace the pointed-to incomplete type with the 3683 if (gtc_visit (TREE_TYPE (t1), TREE_TYPE (t2), mode,
3421 complete one. */ 3684 state, sccstack, sccstate, sccstate_obstack))
3422 if (COMPLETE_TYPE_P (TREE_TYPE (t2))) 3685 goto same_types;
3423 TREE_TYPE (t1) = TREE_TYPE (t2); 3686
3424 else 3687 goto different_types;
3425 TREE_TYPE (t2) = TREE_TYPE (t1);
3426 goto same_types;
3427 } 3688 }
3428 3689
3429 /* Otherwise, pointer and reference types are the same if the 3690 case NULLPTR_TYPE:
3430 pointed-to types are the same. */ 3691 /* There is only one decltype(nullptr). */
3431 if (gimple_types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2)))
3432 goto same_types; 3692 goto same_types;
3433
3434 goto different_types;
3435 }
3436 3693
3437 case INTEGER_TYPE: 3694 case INTEGER_TYPE:
3438 case BOOLEAN_TYPE: 3695 case BOOLEAN_TYPE:
3439 { 3696 {
3440 tree min1 = TYPE_MIN_VALUE (t1); 3697 tree min1 = TYPE_MIN_VALUE (t1);
3505 3762
3506 case RECORD_TYPE: 3763 case RECORD_TYPE:
3507 case UNION_TYPE: 3764 case UNION_TYPE:
3508 case QUAL_UNION_TYPE: 3765 case QUAL_UNION_TYPE:
3509 { 3766 {
3510 tree f1, f2; 3767 tree f1, f2;
3511 3768
3512 /* If one type requires structural equality checks and the 3769 /* The struct tags shall compare equal. */
3513 other doesn't, do not merge the types. */ 3770 if (mode == GTC_MERGE
3514 if (TYPE_STRUCTURAL_EQUALITY_P (t1) 3771 && !compare_type_names_p (TYPE_MAIN_VARIANT (t1),
3515 != TYPE_STRUCTURAL_EQUALITY_P (t2)) 3772 TYPE_MAIN_VARIANT (t2), false))
3516 goto different_types; 3773 goto different_types;
3517 3774
3518 /* The struct tags shall compare equal. */ 3775 /* For aggregate types, all the fields must be the same. */
3519 if (!compare_type_names_p (TYPE_MAIN_VARIANT (t1), 3776 for (f1 = TYPE_FIELDS (t1), f2 = TYPE_FIELDS (t2);
3520 TYPE_MAIN_VARIANT (t2), false)) 3777 f1 && f2;
3521 goto different_types; 3778 f1 = TREE_CHAIN (f1), f2 = TREE_CHAIN (f2))
3522 3779 {
3523 /* For aggregate types, all the fields must be the same. */ 3780 /* The fields must have the same name, offset and type. */
3524 for (f1 = TYPE_FIELDS (t1), f2 = TYPE_FIELDS (t2); 3781 if ((mode == GTC_MERGE
3525 f1 && f2; 3782 && DECL_NAME (f1) != DECL_NAME (f2))
3526 f1 = TREE_CHAIN (f1), f2 = TREE_CHAIN (f2)) 3783 || DECL_NONADDRESSABLE_P (f1) != DECL_NONADDRESSABLE_P (f2)
3527 { 3784 || !gimple_compare_field_offset (f1, f2)
3528 /* The fields must have the same name, offset and type. */ 3785 || !gtc_visit (TREE_TYPE (f1), TREE_TYPE (f2), mode,
3529 if (DECL_NAME (f1) != DECL_NAME (f2) 3786 state, sccstack, sccstate, sccstate_obstack))
3530 || DECL_NONADDRESSABLE_P (f1) != DECL_NONADDRESSABLE_P (f2) 3787 goto different_types;
3531 || !compare_field_offset (f1, f2) 3788 }
3532 || !gimple_types_compatible_p (TREE_TYPE (f1), 3789
3533 TREE_TYPE (f2))) 3790 /* If one aggregate has more fields than the other, they
3534 goto different_types; 3791 are not the same. */
3535 } 3792 if (f1 || f2)
3536 3793 goto different_types;
3537 /* If one aggregate has more fields than the other, they 3794
3538 are not the same. */ 3795 goto same_types;
3539 if (f1 || f2)
3540 goto different_types;
3541
3542 goto same_types;
3543 } 3796 }
3544 3797
3545 default: 3798 default:
3546 gcc_unreachable (); 3799 gcc_unreachable ();
3547 } 3800 }
3548 3801
3549 /* Common exit path for types that are not compatible. */ 3802 /* Common exit path for types that are not compatible. */
3550 different_types: 3803 different_types:
3551 p->same_p = 0; 3804 state->u.same_p = 0;
3552 return 0; 3805 goto pop;
3553 3806
3554 /* Common exit path for types that are compatible. */ 3807 /* Common exit path for types that are compatible. */
3555 same_types: 3808 same_types:
3556 p->same_p = 1; 3809 gcc_assert (state->u.same_p == 1);
3557 return 1; 3810
3558 } 3811 pop:
3559 3812 if (state->low == state->dfsnum)
3560 3813 {
3561 3814 type_pair_t x;
3562 3815
3563 /* Per pointer state for the SCC finding. The on_sccstack flag 3816 /* Pop off the SCC and set its cache values to the final
3564 is not strictly required, it is true when there is no hash value 3817 comparison result. */
3565 recorded for the type and false otherwise. But querying that 3818 do
3566 is slower. */ 3819 {
3567 3820 struct sccs *cstate;
3568 struct sccs 3821 x = VEC_pop (type_pair_t, *sccstack);
3569 { 3822 cstate = (struct sccs *)*pointer_map_contains (sccstate, x);
3570 unsigned int dfsnum; 3823 cstate->on_sccstack = false;
3571 unsigned int low; 3824 x->same_p[mode] = state->u.same_p;
3572 bool on_sccstack; 3825 }
3573 hashval_t hash; 3826 while (x != p);
3574 }; 3827 }
3575 3828
3576 static unsigned int next_dfs_num; 3829 return state->u.same_p;
3830 }
3831
3832 /* Return true iff T1 and T2 are structurally identical. When
3833 FOR_MERGING_P is true the an incomplete type and a complete type
3834 are considered different, otherwise they are considered compatible. */
3835
3836 bool
3837 gimple_types_compatible_p (tree t1, tree t2, enum gtc_mode mode)
3838 {
3839 VEC(type_pair_t, heap) *sccstack = NULL;
3840 struct pointer_map_t *sccstate;
3841 struct obstack sccstate_obstack;
3842 type_pair_t p = NULL;
3843 bool res;
3844
3845 /* Before starting to set up the SCC machinery handle simple cases. */
3846
3847 /* Check first for the obvious case of pointer identity. */
3848 if (t1 == t2)
3849 return true;
3850
3851 /* Check that we have two types to compare. */
3852 if (t1 == NULL_TREE || t2 == NULL_TREE)
3853 return false;
3854
3855 /* If the types have been previously registered and found equal
3856 they still are. */
3857 if (mode == GTC_MERGE)
3858 {
3859 tree leader1 = gimple_lookup_type_leader (t1);
3860 tree leader2 = gimple_lookup_type_leader (t2);
3861 if (leader1 == t2
3862 || t1 == leader2
3863 || (leader1 && leader1 == leader2))
3864 return true;
3865 }
3866 else if (mode == GTC_DIAG)
3867 {
3868 if (TYPE_CANONICAL (t1)
3869 && TYPE_CANONICAL (t1) == TYPE_CANONICAL (t2))
3870 return true;
3871 }
3872
3873 /* Can't be the same type if the types don't have the same code. */
3874 if (TREE_CODE (t1) != TREE_CODE (t2))
3875 return false;
3876
3877 /* Can't be the same type if they have different CV qualifiers. */
3878 if (TYPE_QUALS (t1) != TYPE_QUALS (t2))
3879 return false;
3880
3881 /* Void types are always the same. */
3882 if (TREE_CODE (t1) == VOID_TYPE)
3883 return true;
3884
3885 /* Do some simple checks before doing three hashtable queries. */
3886 if (INTEGRAL_TYPE_P (t1)
3887 || SCALAR_FLOAT_TYPE_P (t1)
3888 || FIXED_POINT_TYPE_P (t1)
3889 || TREE_CODE (t1) == VECTOR_TYPE
3890 || TREE_CODE (t1) == COMPLEX_TYPE
3891 || TREE_CODE (t1) == OFFSET_TYPE)
3892 {
3893 /* Can't be the same type if they have different alignment,
3894 sign, precision or mode. */
3895 if (TYPE_ALIGN (t1) != TYPE_ALIGN (t2)
3896 || TYPE_PRECISION (t1) != TYPE_PRECISION (t2)
3897 || TYPE_MODE (t1) != TYPE_MODE (t2)
3898 || TYPE_UNSIGNED (t1) != TYPE_UNSIGNED (t2))
3899 return false;
3900
3901 if (TREE_CODE (t1) == INTEGER_TYPE
3902 && (TYPE_IS_SIZETYPE (t1) != TYPE_IS_SIZETYPE (t2)
3903 || TYPE_STRING_FLAG (t1) != TYPE_STRING_FLAG (t2)))
3904 return false;
3905
3906 /* That's all we need to check for float and fixed-point types. */
3907 if (SCALAR_FLOAT_TYPE_P (t1)
3908 || FIXED_POINT_TYPE_P (t1))
3909 return true;
3910
3911 /* For integral types fall thru to more complex checks. */
3912 }
3913
3914 else if (AGGREGATE_TYPE_P (t1) || POINTER_TYPE_P (t1))
3915 {
3916 /* Can't be the same type if they have different alignment or mode. */
3917 if (TYPE_ALIGN (t1) != TYPE_ALIGN (t2)
3918 || TYPE_MODE (t1) != TYPE_MODE (t2))
3919 return false;
3920 }
3921
3922 /* If the hash values of t1 and t2 are different the types can't
3923 possibly be the same. This helps keeping the type-pair hashtable
3924 small, only tracking comparisons for hash collisions. */
3925 if (gimple_type_hash_1 (t1, mode) != gimple_type_hash_1 (t2, mode))
3926 return false;
3927
3928 /* If we've visited this type pair before (in the case of aggregates
3929 with self-referential types), and we made a decision, return it. */
3930 p = lookup_type_pair (t1, t2, &gtc_visited, &gtc_ob);
3931 if (p->same_p[mode] == 0 || p->same_p[mode] == 1)
3932 {
3933 /* We have already decided whether T1 and T2 are the
3934 same, return the cached result. */
3935 return p->same_p[mode] == 1;
3936 }
3937
3938 /* Now set up the SCC machinery for the comparison. */
3939 gtc_next_dfs_num = 1;
3940 sccstate = pointer_map_create ();
3941 gcc_obstack_init (&sccstate_obstack);
3942 res = gimple_types_compatible_p_1 (t1, t2, mode, p,
3943 &sccstack, sccstate, &sccstate_obstack);
3944 VEC_free (type_pair_t, heap, sccstack);
3945 pointer_map_destroy (sccstate);
3946 obstack_free (&sccstate_obstack, NULL);
3947
3948 return res;
3949 }
3950
3577 3951
3578 static hashval_t 3952 static hashval_t
3579 iterative_hash_gimple_type (tree, hashval_t, VEC(tree, heap) **, 3953 iterative_hash_gimple_type (tree, hashval_t, VEC(tree, heap) **,
3580 struct pointer_map_t *, struct obstack *); 3954 struct pointer_map_t *, struct obstack *,
3955 enum gtc_mode);
3581 3956
3582 /* DFS visit the edge from the callers type with state *STATE to T. 3957 /* DFS visit the edge from the callers type with state *STATE to T.
3583 Update the callers type hash V with the hash for T if it is not part 3958 Update the callers type hash V with the hash for T if it is not part
3584 of the SCC containing the callers type and return it. 3959 of the SCC containing the callers type and return it.
3585 SCCSTACK, SCCSTATE and SCCSTATE_OBSTACK are state for the DFS walk done. */ 3960 SCCSTACK, SCCSTATE and SCCSTATE_OBSTACK are state for the DFS walk done. */
3586 3961
3587 static hashval_t 3962 static hashval_t
3588 visit (tree t, struct sccs *state, hashval_t v, 3963 visit (tree t, struct sccs *state, hashval_t v,
3589 VEC (tree, heap) **sccstack, 3964 VEC (tree, heap) **sccstack,
3590 struct pointer_map_t *sccstate, 3965 struct pointer_map_t *sccstate,
3591 struct obstack *sccstate_obstack) 3966 struct obstack *sccstate_obstack, enum gtc_mode mode)
3592 { 3967 {
3593 struct sccs *cstate = NULL; 3968 struct sccs *cstate = NULL;
3969 struct tree_int_map m;
3594 void **slot; 3970 void **slot;
3595 3971
3596 /* If there is a hash value recorded for this type then it can't 3972 /* If there is a hash value recorded for this type then it can't
3597 possibly be part of our parent SCC. Simply mix in its hash. */ 3973 possibly be part of our parent SCC. Simply mix in its hash. */
3598 if ((slot = pointer_map_contains (type_hash_cache, t))) 3974 m.base.from = t;
3599 return iterative_hash_hashval_t ((hashval_t) (size_t) *slot, v); 3975 if ((slot = htab_find_slot (mode == GTC_MERGE
3976 ? type_hash_cache : canonical_type_hash_cache,
3977 &m, NO_INSERT))
3978 && *slot)
3979 return iterative_hash_hashval_t (((struct tree_int_map *) *slot)->to, v);
3600 3980
3601 if ((slot = pointer_map_contains (sccstate, t)) != NULL) 3981 if ((slot = pointer_map_contains (sccstate, t)) != NULL)
3602 cstate = (struct sccs *)*slot; 3982 cstate = (struct sccs *)*slot;
3603 if (!cstate) 3983 if (!cstate)
3604 { 3984 {
3605 hashval_t tem; 3985 hashval_t tem;
3606 /* Not yet visited. DFS recurse. */ 3986 /* Not yet visited. DFS recurse. */
3607 tem = iterative_hash_gimple_type (t, v, 3987 tem = iterative_hash_gimple_type (t, v,
3608 sccstack, sccstate, sccstate_obstack); 3988 sccstack, sccstate, sccstate_obstack,
3989 mode);
3609 if (!cstate) 3990 if (!cstate)
3610 cstate = (struct sccs *)* pointer_map_contains (sccstate, t); 3991 cstate = (struct sccs *)* pointer_map_contains (sccstate, t);
3611 state->low = MIN (state->low, cstate->low); 3992 state->low = MIN (state->low, cstate->low);
3612 /* If the type is no longer on the SCC stack and thus is not part 3993 /* If the type is no longer on the SCC stack and thus is not part
3613 of the parents SCC mix in its hash value. Otherwise we will 3994 of the parents SCC mix in its hash value. Otherwise we will
3652 all. To make this work we have to delay setting the hash 4033 all. To make this work we have to delay setting the hash
3653 values of the SCC until it is complete. */ 4034 values of the SCC until it is complete. */
3654 4035
3655 static hashval_t 4036 static hashval_t
3656 iterative_hash_gimple_type (tree type, hashval_t val, 4037 iterative_hash_gimple_type (tree type, hashval_t val,
3657 VEC(tree, heap) **sccstack, 4038 VEC(tree, heap) **sccstack,
3658 struct pointer_map_t *sccstate, 4039 struct pointer_map_t *sccstate,
3659 struct obstack *sccstate_obstack) 4040 struct obstack *sccstate_obstack,
4041 enum gtc_mode mode)
3660 { 4042 {
3661 hashval_t v; 4043 hashval_t v;
3662 void **slot; 4044 void **slot;
3663 struct sccs *state; 4045 struct sccs *state;
3664 4046
3665 #ifdef ENABLE_CHECKING 4047 /* Not visited during this DFS walk. */
3666 /* Not visited during this DFS walk nor during previous walks. */ 4048 gcc_checking_assert (!pointer_map_contains (sccstate, type));
3667 gcc_assert (!pointer_map_contains (type_hash_cache, type)
3668 && !pointer_map_contains (sccstate, type));
3669 #endif
3670 state = XOBNEW (sccstate_obstack, struct sccs); 4049 state = XOBNEW (sccstate_obstack, struct sccs);
3671 *pointer_map_insert (sccstate, type) = state; 4050 *pointer_map_insert (sccstate, type) = state;
3672 4051
3673 VEC_safe_push (tree, heap, *sccstack, type); 4052 VEC_safe_push (tree, heap, *sccstack, type);
3674 state->dfsnum = next_dfs_num++; 4053 state->dfsnum = next_dfs_num++;
3700 pointed to but do not recurse into possibly incomplete types to 4079 pointed to but do not recurse into possibly incomplete types to
3701 avoid hash differences for complete vs. incomplete types. */ 4080 avoid hash differences for complete vs. incomplete types. */
3702 if (POINTER_TYPE_P (type)) 4081 if (POINTER_TYPE_P (type))
3703 { 4082 {
3704 if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (type))) 4083 if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (type)))
3705 { 4084 {
3706 v = iterative_hash_hashval_t (TREE_CODE (TREE_TYPE (type)), v); 4085 v = iterative_hash_hashval_t (TREE_CODE (TREE_TYPE (type)), v);
3707 v = iterative_hash_name 4086 v = iterative_hash_name
3708 (TYPE_NAME (TYPE_MAIN_VARIANT (TREE_TYPE (type))), v); 4087 (TYPE_NAME (TYPE_MAIN_VARIANT (TREE_TYPE (type))), v);
3709 } 4088 }
3710 else 4089 else
3711 v = visit (TREE_TYPE (type), state, v, 4090 v = visit (TREE_TYPE (type), state, v,
3712 sccstack, sccstate, sccstate_obstack); 4091 sccstack, sccstate, sccstate_obstack, mode);
3713 } 4092 }
3714 4093
3715 /* For integer types hash the types min/max values and the string flag. */ 4094 /* For integer types hash the types min/max values and the string flag. */
3716 if (TREE_CODE (type) == INTEGER_TYPE) 4095 if (TREE_CODE (type) == INTEGER_TYPE)
3717 { 4096 {
3718 v = iterative_hash_expr (TYPE_MIN_VALUE (type), v); 4097 /* OMP lowering can introduce error_mark_node in place of
3719 v = iterative_hash_expr (TYPE_MAX_VALUE (type), v); 4098 random local decls in types. */
4099 if (TYPE_MIN_VALUE (type) != error_mark_node)
4100 v = iterative_hash_expr (TYPE_MIN_VALUE (type), v);
4101 if (TYPE_MAX_VALUE (type) != error_mark_node)
4102 v = iterative_hash_expr (TYPE_MAX_VALUE (type), v);
3720 v = iterative_hash_hashval_t (TYPE_STRING_FLAG (type), v); 4103 v = iterative_hash_hashval_t (TYPE_STRING_FLAG (type), v);
3721 } 4104 }
3722 4105
3723 /* For array types hash their domain and the string flag. */ 4106 /* For array types hash their domain and the string flag. */
3724 if (TREE_CODE (type) == ARRAY_TYPE 4107 if (TREE_CODE (type) == ARRAY_TYPE
3725 && TYPE_DOMAIN (type)) 4108 && TYPE_DOMAIN (type))
3726 { 4109 {
3727 v = iterative_hash_hashval_t (TYPE_STRING_FLAG (type), v); 4110 v = iterative_hash_hashval_t (TYPE_STRING_FLAG (type), v);
3728 v = visit (TYPE_DOMAIN (type), state, v, 4111 v = visit (TYPE_DOMAIN (type), state, v,
3729 sccstack, sccstate, sccstate_obstack); 4112 sccstack, sccstate, sccstate_obstack, mode);
3730 } 4113 }
3731 4114
3732 /* Recurse for aggregates with a single element type. */ 4115 /* Recurse for aggregates with a single element type. */
3733 if (TREE_CODE (type) == ARRAY_TYPE 4116 if (TREE_CODE (type) == ARRAY_TYPE
3734 || TREE_CODE (type) == COMPLEX_TYPE 4117 || TREE_CODE (type) == COMPLEX_TYPE
3735 || TREE_CODE (type) == VECTOR_TYPE) 4118 || TREE_CODE (type) == VECTOR_TYPE)
3736 v = visit (TREE_TYPE (type), state, v, 4119 v = visit (TREE_TYPE (type), state, v,
3737 sccstack, sccstate, sccstate_obstack); 4120 sccstack, sccstate, sccstate_obstack, mode);
3738 4121
3739 /* Incorporate function return and argument types. */ 4122 /* Incorporate function return and argument types. */
3740 if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE) 4123 if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE)
3741 { 4124 {
3742 unsigned na; 4125 unsigned na;
3743 tree p; 4126 tree p;
3744 4127
3745 /* For method types also incorporate their parent class. */ 4128 /* For method types also incorporate their parent class. */
3746 if (TREE_CODE (type) == METHOD_TYPE) 4129 if (TREE_CODE (type) == METHOD_TYPE)
3747 v = visit (TYPE_METHOD_BASETYPE (type), state, v, 4130 v = visit (TYPE_METHOD_BASETYPE (type), state, v,
3748 sccstack, sccstate, sccstate_obstack); 4131 sccstack, sccstate, sccstate_obstack, mode);
3749 4132
3750 v = visit (TREE_TYPE (type), state, v, 4133 /* For result types allow mismatch in completeness. */
3751 sccstack, sccstate, sccstate_obstack); 4134 if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (type)))
4135 {
4136 v = iterative_hash_hashval_t (TREE_CODE (TREE_TYPE (type)), v);
4137 v = iterative_hash_name
4138 (TYPE_NAME (TYPE_MAIN_VARIANT (TREE_TYPE (type))), v);
4139 }
4140 else
4141 v = visit (TREE_TYPE (type), state, v,
4142 sccstack, sccstate, sccstate_obstack, mode);
3752 4143
3753 for (p = TYPE_ARG_TYPES (type), na = 0; p; p = TREE_CHAIN (p)) 4144 for (p = TYPE_ARG_TYPES (type), na = 0; p; p = TREE_CHAIN (p))
3754 { 4145 {
3755 v = visit (TREE_VALUE (p), state, v, 4146 /* For argument types allow mismatch in completeness. */
3756 sccstack, sccstate, sccstate_obstack); 4147 if (RECORD_OR_UNION_TYPE_P (TREE_VALUE (p)))
3757 na++; 4148 {
3758 } 4149 v = iterative_hash_hashval_t (TREE_CODE (TREE_VALUE (p)), v);
4150 v = iterative_hash_name
4151 (TYPE_NAME (TYPE_MAIN_VARIANT (TREE_VALUE (p))), v);
4152 }
4153 else
4154 v = visit (TREE_VALUE (p), state, v,
4155 sccstack, sccstate, sccstate_obstack, mode);
4156 na++;
4157 }
3759 4158
3760 v = iterative_hash_hashval_t (na, v); 4159 v = iterative_hash_hashval_t (na, v);
3761 } 4160 }
3762 4161
3763 if (TREE_CODE (type) == RECORD_TYPE 4162 if (TREE_CODE (type) == RECORD_TYPE
3765 || TREE_CODE (type) == QUAL_UNION_TYPE) 4164 || TREE_CODE (type) == QUAL_UNION_TYPE)
3766 { 4165 {
3767 unsigned nf; 4166 unsigned nf;
3768 tree f; 4167 tree f;
3769 4168
3770 v = iterative_hash_name (TYPE_NAME (TYPE_MAIN_VARIANT (type)), v); 4169 if (mode == GTC_MERGE)
4170 v = iterative_hash_name (TYPE_NAME (TYPE_MAIN_VARIANT (type)), v);
3771 4171
3772 for (f = TYPE_FIELDS (type), nf = 0; f; f = TREE_CHAIN (f)) 4172 for (f = TYPE_FIELDS (type), nf = 0; f; f = TREE_CHAIN (f))
3773 { 4173 {
3774 v = iterative_hash_name (DECL_NAME (f), v); 4174 if (mode == GTC_MERGE)
3775 v = visit (TREE_TYPE (f), state, v, 4175 v = iterative_hash_name (DECL_NAME (f), v);
3776 sccstack, sccstate, sccstate_obstack); 4176 v = visit (TREE_TYPE (f), state, v,
3777 nf++; 4177 sccstack, sccstate, sccstate_obstack, mode);
3778 } 4178 nf++;
4179 }
3779 4180
3780 v = iterative_hash_hashval_t (nf, v); 4181 v = iterative_hash_hashval_t (nf, v);
3781 } 4182 }
3782 4183
3783 /* Record hash for us. */ 4184 /* Record hash for us. */
3784 state->hash = v; 4185 state->u.hash = v;
3785 4186
3786 /* See if we found an SCC. */ 4187 /* See if we found an SCC. */
3787 if (state->low == state->dfsnum) 4188 if (state->low == state->dfsnum)
3788 { 4189 {
3789 tree x; 4190 tree x;
3790 4191
3791 /* Pop off the SCC and set its hash values. */ 4192 /* Pop off the SCC and set its hash values. */
3792 do 4193 do
3793 { 4194 {
3794 struct sccs *cstate; 4195 struct sccs *cstate;
3795 x = VEC_pop (tree, *sccstack); 4196 struct tree_int_map *m = ggc_alloc_cleared_tree_int_map ();
3796 gcc_assert (!pointer_map_contains (type_hash_cache, x)); 4197 x = VEC_pop (tree, *sccstack);
3797 cstate = (struct sccs *)*pointer_map_contains (sccstate, x); 4198 cstate = (struct sccs *)*pointer_map_contains (sccstate, x);
3798 cstate->on_sccstack = false; 4199 cstate->on_sccstack = false;
3799 slot = pointer_map_insert (type_hash_cache, x); 4200 m->base.from = x;
3800 *slot = (void *) (size_t) cstate->hash; 4201 m->to = cstate->u.hash;
3801 } 4202 slot = htab_find_slot (mode == GTC_MERGE
4203 ? type_hash_cache : canonical_type_hash_cache,
4204 m, INSERT);
4205 gcc_assert (!*slot);
4206 *slot = (void *) m;
4207 }
3802 while (x != type); 4208 while (x != type);
3803 } 4209 }
3804 4210
3805 return iterative_hash_hashval_t (v, val); 4211 return iterative_hash_hashval_t (v, val);
3806 } 4212 }
3813 4219
3814 This function should produce the same hash value for two compatible 4220 This function should produce the same hash value for two compatible
3815 types according to gimple_types_compatible_p. */ 4221 types according to gimple_types_compatible_p. */
3816 4222
3817 static hashval_t 4223 static hashval_t
3818 gimple_type_hash (const void *p) 4224 gimple_type_hash_1 (const void *p, enum gtc_mode mode)
3819 { 4225 {
3820 const_tree t = (const_tree) p; 4226 const_tree t = (const_tree) p;
3821 VEC(tree, heap) *sccstack = NULL; 4227 VEC(tree, heap) *sccstack = NULL;
3822 struct pointer_map_t *sccstate; 4228 struct pointer_map_t *sccstate;
3823 struct obstack sccstate_obstack; 4229 struct obstack sccstate_obstack;
3824 hashval_t val; 4230 hashval_t val;
3825 void **slot; 4231 void **slot;
3826 4232 struct tree_int_map m;
3827 if (type_hash_cache == NULL) 4233
3828 type_hash_cache = pointer_map_create (); 4234 if (mode == GTC_MERGE
3829 4235 && type_hash_cache == NULL)
3830 if ((slot = pointer_map_contains (type_hash_cache, p)) != NULL) 4236 type_hash_cache = htab_create_ggc (512, tree_int_map_hash,
3831 return iterative_hash_hashval_t ((hashval_t) (size_t) *slot, 0); 4237 tree_int_map_eq, NULL);
4238 else if (mode == GTC_DIAG
4239 && canonical_type_hash_cache == NULL)
4240 canonical_type_hash_cache = htab_create_ggc (512, tree_int_map_hash,
4241 tree_int_map_eq, NULL);
4242
4243 m.base.from = CONST_CAST_TREE (t);
4244 if ((slot = htab_find_slot (mode == GTC_MERGE
4245 ? type_hash_cache : canonical_type_hash_cache,
4246 &m, NO_INSERT))
4247 && *slot)
4248 return iterative_hash_hashval_t (((struct tree_int_map *) *slot)->to, 0);
3832 4249
3833 /* Perform a DFS walk and pre-hash all reachable types. */ 4250 /* Perform a DFS walk and pre-hash all reachable types. */
3834 next_dfs_num = 1; 4251 next_dfs_num = 1;
3835 sccstate = pointer_map_create (); 4252 sccstate = pointer_map_create ();
3836 gcc_obstack_init (&sccstate_obstack); 4253 gcc_obstack_init (&sccstate_obstack);
3837 val = iterative_hash_gimple_type (CONST_CAST_TREE (t), 0, 4254 val = iterative_hash_gimple_type (CONST_CAST_TREE (t), 0,
3838 &sccstack, sccstate, &sccstate_obstack); 4255 &sccstack, sccstate, &sccstate_obstack,
4256 mode);
3839 VEC_free (tree, heap, sccstack); 4257 VEC_free (tree, heap, sccstack);
3840 pointer_map_destroy (sccstate); 4258 pointer_map_destroy (sccstate);
3841 obstack_free (&sccstate_obstack, NULL); 4259 obstack_free (&sccstate_obstack, NULL);
3842 4260
3843 return val; 4261 return val;
3844 } 4262 }
3845 4263
4264 static hashval_t
4265 gimple_type_hash (const void *p)
4266 {
4267 return gimple_type_hash_1 (p, GTC_MERGE);
4268 }
4269
4270 static hashval_t
4271 gimple_canonical_type_hash (const void *p)
4272 {
4273 return gimple_type_hash_1 (p, GTC_DIAG);
4274 }
4275
3846 4276
3847 /* Returns nonzero if P1 and P2 are equal. */ 4277 /* Returns nonzero if P1 and P2 are equal. */
3848 4278
3849 static int 4279 static int
3850 gimple_type_eq (const void *p1, const void *p2) 4280 gimple_type_eq (const void *p1, const void *p2)
3851 { 4281 {
3852 const_tree t1 = (const_tree) p1; 4282 const_tree t1 = (const_tree) p1;
3853 const_tree t2 = (const_tree) p2; 4283 const_tree t2 = (const_tree) p2;
3854 return gimple_types_compatible_p (CONST_CAST_TREE (t1), CONST_CAST_TREE (t2)); 4284 return gimple_types_compatible_p (CONST_CAST_TREE (t1),
4285 CONST_CAST_TREE (t2), GTC_MERGE);
3855 } 4286 }
3856 4287
3857 4288
3858 /* Register type T in the global type table gimple_types. 4289 /* Register type T in the global type table gimple_types.
3859 If another type T', compatible with T, already existed in 4290 If another type T', compatible with T, already existed in
3862 4293
3863 tree 4294 tree
3864 gimple_register_type (tree t) 4295 gimple_register_type (tree t)
3865 { 4296 {
3866 void **slot; 4297 void **slot;
4298 gimple_type_leader_entry *leader;
4299 tree mv_leader = NULL_TREE;
3867 4300
3868 gcc_assert (TYPE_P (t)); 4301 gcc_assert (TYPE_P (t));
4302
4303 if (!gimple_type_leader)
4304 gimple_type_leader = ggc_alloc_cleared_vec_gimple_type_leader_entry_s
4305 (GIMPLE_TYPE_LEADER_SIZE);
4306 /* If we registered this type before return the cached result. */
4307 leader = &gimple_type_leader[TYPE_UID (t) % GIMPLE_TYPE_LEADER_SIZE];
4308 if (leader->type == t)
4309 return leader->leader;
3869 4310
3870 /* Always register the main variant first. This is important so we 4311 /* Always register the main variant first. This is important so we
3871 pick up the non-typedef variants as canonical, otherwise we'll end 4312 pick up the non-typedef variants as canonical, otherwise we'll end
3872 up taking typedef ids for structure tags during comparison. */ 4313 up taking typedef ids for structure tags during comparison. */
3873 if (TYPE_MAIN_VARIANT (t) != t) 4314 if (TYPE_MAIN_VARIANT (t) != t)
3874 gimple_register_type (TYPE_MAIN_VARIANT (t)); 4315 mv_leader = gimple_register_type (TYPE_MAIN_VARIANT (t));
3875 4316
3876 if (gimple_types == NULL) 4317 if (gimple_types == NULL)
3877 gimple_types = htab_create (16381, gimple_type_hash, gimple_type_eq, 0); 4318 gimple_types = htab_create_ggc (16381, gimple_type_hash, gimple_type_eq, 0);
3878 4319
3879 slot = htab_find_slot (gimple_types, t, INSERT); 4320 slot = htab_find_slot (gimple_types, t, INSERT);
3880 if (*slot 4321 if (*slot
3881 && *(tree *)slot != t) 4322 && *(tree *)slot != t)
3882 { 4323 {
3928 TYPE_NEXT_REF_TO (tem) = TYPE_NEXT_REF_TO (t); 4369 TYPE_NEXT_REF_TO (tem) = TYPE_NEXT_REF_TO (t);
3929 } 4370 }
3930 TYPE_NEXT_REF_TO (t) = NULL_TREE; 4371 TYPE_NEXT_REF_TO (t) = NULL_TREE;
3931 } 4372 }
3932 4373
4374 leader->type = t;
4375 leader->leader = new_type;
3933 t = new_type; 4376 t = new_type;
3934 } 4377 }
3935 else 4378 else
3936 *slot = (void *) t; 4379 {
4380 leader->type = t;
4381 leader->leader = t;
4382 /* We're the type leader. Make our TYPE_MAIN_VARIANT valid. */
4383 if (TYPE_MAIN_VARIANT (t) != t
4384 && TYPE_MAIN_VARIANT (t) != mv_leader)
4385 {
4386 /* Remove us from our main variant list as we are not the variant
4387 leader and the variant leader will change. */
4388 tree tem = TYPE_MAIN_VARIANT (t);
4389 while (tem && TYPE_NEXT_VARIANT (tem) != t)
4390 tem = TYPE_NEXT_VARIANT (tem);
4391 if (tem)
4392 TYPE_NEXT_VARIANT (tem) = TYPE_NEXT_VARIANT (t);
4393 TYPE_NEXT_VARIANT (t) = NULL_TREE;
4394 /* Adjust our main variant. Linking us into its variant list
4395 will happen at fixup time. */
4396 TYPE_MAIN_VARIANT (t) = mv_leader;
4397 }
4398 *slot = (void *) t;
4399 }
4400
4401 return t;
4402 }
4403
4404
4405 /* Returns nonzero if P1 and P2 are equal. */
4406
4407 static int
4408 gimple_canonical_type_eq (const void *p1, const void *p2)
4409 {
4410 const_tree t1 = (const_tree) p1;
4411 const_tree t2 = (const_tree) p2;
4412 return gimple_types_compatible_p (CONST_CAST_TREE (t1),
4413 CONST_CAST_TREE (t2), GTC_DIAG);
4414 }
4415
4416 /* Register type T in the global type table gimple_types.
4417 If another type T', compatible with T, already existed in
4418 gimple_types then return T', otherwise return T. This is used by
4419 LTO to merge identical types read from different TUs. */
4420
4421 tree
4422 gimple_register_canonical_type (tree t)
4423 {
4424 void **slot;
4425 tree orig_t = t;
4426
4427 gcc_assert (TYPE_P (t));
4428
4429 if (TYPE_CANONICAL (t))
4430 return TYPE_CANONICAL (t);
4431
4432 /* Always register the type itself first so that if it turns out
4433 to be the canonical type it will be the one we merge to as well. */
4434 t = gimple_register_type (t);
4435
4436 /* Always register the main variant first. This is important so we
4437 pick up the non-typedef variants as canonical, otherwise we'll end
4438 up taking typedef ids for structure tags during comparison. */
4439 if (TYPE_MAIN_VARIANT (t) != t)
4440 gimple_register_canonical_type (TYPE_MAIN_VARIANT (t));
4441
4442 if (gimple_canonical_types == NULL)
4443 gimple_canonical_types = htab_create_ggc (16381, gimple_canonical_type_hash,
4444 gimple_canonical_type_eq, 0);
4445
4446 slot = htab_find_slot (gimple_canonical_types, t, INSERT);
4447 if (*slot
4448 && *(tree *)slot != t)
4449 {
4450 tree new_type = (tree) *((tree *) slot);
4451
4452 TYPE_CANONICAL (t) = new_type;
4453 t = new_type;
4454 }
4455 else
4456 {
4457 TYPE_CANONICAL (t) = t;
4458 *slot = (void *) t;
4459 }
4460
4461 /* Also cache the canonical type in the non-leaders. */
4462 TYPE_CANONICAL (orig_t) = t;
3937 4463
3938 return t; 4464 return t;
3939 } 4465 }
3940 4466
3941 4467
3952 (long) gimple_types->searches, 4478 (long) gimple_types->searches,
3953 (long) gimple_types->collisions, 4479 (long) gimple_types->collisions,
3954 htab_collisions (gimple_types)); 4480 htab_collisions (gimple_types));
3955 else 4481 else
3956 fprintf (stderr, "GIMPLE type table is empty\n"); 4482 fprintf (stderr, "GIMPLE type table is empty\n");
4483 if (type_hash_cache)
4484 fprintf (stderr, "GIMPLE type hash table: size %ld, %ld elements, "
4485 "%ld searches, %ld collisions (ratio: %f)\n",
4486 (long) htab_size (type_hash_cache),
4487 (long) htab_elements (type_hash_cache),
4488 (long) type_hash_cache->searches,
4489 (long) type_hash_cache->collisions,
4490 htab_collisions (type_hash_cache));
4491 else
4492 fprintf (stderr, "GIMPLE type hash table is empty\n");
4493 if (gimple_canonical_types)
4494 fprintf (stderr, "GIMPLE canonical type table: size %ld, %ld elements, "
4495 "%ld searches, %ld collisions (ratio: %f)\n",
4496 (long) htab_size (gimple_canonical_types),
4497 (long) htab_elements (gimple_canonical_types),
4498 (long) gimple_canonical_types->searches,
4499 (long) gimple_canonical_types->collisions,
4500 htab_collisions (gimple_canonical_types));
4501 else
4502 fprintf (stderr, "GIMPLE canonical type table is empty\n");
4503 if (canonical_type_hash_cache)
4504 fprintf (stderr, "GIMPLE canonical type hash table: size %ld, %ld elements, "
4505 "%ld searches, %ld collisions (ratio: %f)\n",
4506 (long) htab_size (canonical_type_hash_cache),
4507 (long) htab_elements (canonical_type_hash_cache),
4508 (long) canonical_type_hash_cache->searches,
4509 (long) canonical_type_hash_cache->collisions,
4510 htab_collisions (canonical_type_hash_cache));
4511 else
4512 fprintf (stderr, "GIMPLE canonical type hash table is empty\n");
3957 if (gtc_visited) 4513 if (gtc_visited)
3958 fprintf (stderr, "GIMPLE type comparison table: size %ld, %ld " 4514 fprintf (stderr, "GIMPLE type comparison table: size %ld, %ld "
3959 "elements, %ld searches, %ld collisions (ratio: %f)\n", 4515 "elements, %ld searches, %ld collisions (ratio: %f)\n",
3960 (long) htab_size (gtc_visited), 4516 (long) htab_size (gtc_visited),
3961 (long) htab_elements (gtc_visited), 4517 (long) htab_elements (gtc_visited),
3978 if (gimple_types) 4534 if (gimple_types)
3979 { 4535 {
3980 htab_delete (gimple_types); 4536 htab_delete (gimple_types);
3981 gimple_types = NULL; 4537 gimple_types = NULL;
3982 } 4538 }
4539 if (gimple_canonical_types)
4540 {
4541 htab_delete (gimple_canonical_types);
4542 gimple_canonical_types = NULL;
4543 }
3983 if (type_hash_cache) 4544 if (type_hash_cache)
3984 { 4545 {
3985 pointer_map_destroy (type_hash_cache); 4546 htab_delete (type_hash_cache);
3986 type_hash_cache = NULL; 4547 type_hash_cache = NULL;
4548 }
4549 if (canonical_type_hash_cache)
4550 {
4551 htab_delete (canonical_type_hash_cache);
4552 canonical_type_hash_cache = NULL;
3987 } 4553 }
3988 if (gtc_visited) 4554 if (gtc_visited)
3989 { 4555 {
3990 htab_delete (gtc_visited); 4556 htab_delete (gtc_visited);
3991 obstack_free (&gtc_ob, NULL); 4557 obstack_free (&gtc_ob, NULL);
3992 gtc_visited = NULL; 4558 gtc_visited = NULL;
3993 } 4559 }
4560 gimple_type_leader = NULL;
3994 } 4561 }
3995 4562
3996 4563
3997 /* Return a type the same as TYPE except unsigned or 4564 /* Return a type the same as TYPE except unsigned or
3998 signed according to UNSIGNEDP. */ 4565 signed according to UNSIGNEDP. */
4015 return unsignedp ? long_unsigned_type_node : long_integer_type_node; 4582 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
4016 if (type1 == long_long_integer_type_node 4583 if (type1 == long_long_integer_type_node
4017 || type1 == long_long_unsigned_type_node) 4584 || type1 == long_long_unsigned_type_node)
4018 return unsignedp 4585 return unsignedp
4019 ? long_long_unsigned_type_node 4586 ? long_long_unsigned_type_node
4020 : long_long_integer_type_node; 4587 : long_long_integer_type_node;
4588 if (int128_integer_type_node && (type1 == int128_integer_type_node || type1 == int128_unsigned_type_node))
4589 return unsignedp
4590 ? int128_unsigned_type_node
4591 : int128_integer_type_node;
4021 #if HOST_BITS_PER_WIDE_INT >= 64 4592 #if HOST_BITS_PER_WIDE_INT >= 64
4022 if (type1 == intTI_type_node || type1 == unsigned_intTI_type_node) 4593 if (type1 == intTI_type_node || type1 == unsigned_intTI_type_node)
4023 return unsignedp ? unsigned_intTI_type_node : intTI_type_node; 4594 return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
4024 #endif 4595 #endif
4025 if (type1 == intDI_type_node || type1 == unsigned_intDI_type_node) 4596 if (type1 == intDI_type_node || type1 == unsigned_intDI_type_node)
4126 return unsignedp ? short_unsigned_type_node : short_integer_type_node; 4697 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
4127 if (TYPE_OK (long_integer_type_node)) 4698 if (TYPE_OK (long_integer_type_node))
4128 return unsignedp ? long_unsigned_type_node : long_integer_type_node; 4699 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
4129 if (TYPE_OK (long_long_integer_type_node)) 4700 if (TYPE_OK (long_long_integer_type_node))
4130 return (unsignedp 4701 return (unsignedp
4131 ? long_long_unsigned_type_node 4702 ? long_long_unsigned_type_node
4132 : long_long_integer_type_node); 4703 : long_long_integer_type_node);
4704 if (int128_integer_type_node && TYPE_OK (int128_integer_type_node))
4705 return (unsignedp
4706 ? int128_unsigned_type_node
4707 : int128_integer_type_node);
4133 4708
4134 #if HOST_BITS_PER_WIDE_INT >= 64 4709 #if HOST_BITS_PER_WIDE_INT >= 64
4135 if (TYPE_OK (intTI_type_node)) 4710 if (TYPE_OK (intTI_type_node))
4136 return unsignedp ? unsigned_intTI_type_node : intTI_type_node; 4711 return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
4137 #endif 4712 #endif
4213 4788
4214 /* t1 == t can happen for boolean nodes which are always unsigned. */ 4789 /* t1 == t can happen for boolean nodes which are always unsigned. */
4215 if (t1 != t) 4790 if (t1 != t)
4216 return get_alias_set (t1); 4791 return get_alias_set (t1);
4217 } 4792 }
4218 else if (POINTER_TYPE_P (t))
4219 {
4220 /* From the common C and C++ langhook implementation:
4221
4222 Unfortunately, there is no canonical form of a pointer type.
4223 In particular, if we have `typedef int I', then `int *', and
4224 `I *' are different types. So, we have to pick a canonical
4225 representative. We do this below.
4226
4227 Technically, this approach is actually more conservative that
4228 it needs to be. In particular, `const int *' and `int *'
4229 should be in different alias sets, according to the C and C++
4230 standard, since their types are not the same, and so,
4231 technically, an `int **' and `const int **' cannot point at
4232 the same thing.
4233
4234 But, the standard is wrong. In particular, this code is
4235 legal C++:
4236
4237 int *ip;
4238 int **ipp = &ip;
4239 const int* const* cipp = ipp;
4240 And, it doesn't make sense for that to be legal unless you
4241 can dereference IPP and CIPP. So, we ignore cv-qualifiers on
4242 the pointed-to types. This issue has been reported to the
4243 C++ committee. */
4244
4245 /* In addition to the above canonicalization issue with LTO
4246 we should also canonicalize `T (*)[]' to `T *' avoiding
4247 alias issues with pointer-to element types and pointer-to
4248 array types.
4249
4250 Likewise we need to deal with the situation of incomplete
4251 pointed-to types and make `*(struct X **)&a' and
4252 `*(struct X {} **)&a' alias. Otherwise we will have to
4253 guarantee that all pointer-to incomplete type variants
4254 will be replaced by pointer-to complete type variants if
4255 they are available.
4256
4257 With LTO the convenient situation of using `void *' to
4258 access and store any pointer type will also become
4259 more apparent (and `void *' is just another pointer-to
4260 incomplete type). Assigning alias-set zero to `void *'
4261 and all pointer-to incomplete types is a not appealing
4262 solution. Assigning an effective alias-set zero only
4263 affecting pointers might be - by recording proper subset
4264 relationships of all pointer alias-sets.
4265
4266 Pointer-to function types are another grey area which
4267 needs caution. Globbing them all into one alias-set
4268 or the above effective zero set would work. */
4269
4270 /* For now just assign the same alias-set to all pointers.
4271 That's simple and avoids all the above problems. */
4272 if (t != ptr_type_node)
4273 return get_alias_set (ptr_type_node);
4274 }
4275 4793
4276 return -1; 4794 return -1;
4277 } 4795 }
4278 4796
4279 4797
4302 { 4820 {
4303 *walk_subtrees = 0; 4821 *walk_subtrees = 0;
4304 return NULL_TREE; 4822 return NULL_TREE;
4305 } 4823 }
4306 4824
4307 if (INDIRECT_REF_P (*tp) && TREE_OPERAND (*tp, 0) == count_p->ptr) 4825 if (TREE_CODE (*tp) == MEM_REF && TREE_OPERAND (*tp, 0) == count_p->ptr)
4308 { 4826 {
4309 if (wi_p->is_lhs) 4827 if (wi_p->is_lhs)
4310 count_p->num_stores++; 4828 count_p->num_stores++;
4311 else 4829 else
4312 count_p->num_loads++; 4830 count_p->num_loads++;
4375 { 4893 {
4376 while (handled_component_p (op)) 4894 while (handled_component_p (op))
4377 op = TREE_OPERAND (op, 0); 4895 op = TREE_OPERAND (op, 0);
4378 if (DECL_P (op) 4896 if (DECL_P (op)
4379 || INDIRECT_REF_P (op) 4897 || INDIRECT_REF_P (op)
4898 || TREE_CODE (op) == MEM_REF
4380 || TREE_CODE (op) == TARGET_MEM_REF) 4899 || TREE_CODE (op) == TARGET_MEM_REF)
4381 return op; 4900 return op;
4382 return NULL_TREE; 4901 return NULL_TREE;
4383 } 4902 }
4384 4903
4408 } 4927 }
4409 rhs = gimple_assign_rhs1 (stmt); 4928 rhs = gimple_assign_rhs1 (stmt);
4410 while (handled_component_p (rhs)) 4929 while (handled_component_p (rhs))
4411 rhs = TREE_OPERAND (rhs, 0); 4930 rhs = TREE_OPERAND (rhs, 0);
4412 if (visit_addr) 4931 if (visit_addr)
4413 { 4932 {
4414 if (TREE_CODE (rhs) == ADDR_EXPR) 4933 if (TREE_CODE (rhs) == ADDR_EXPR)
4415 ret |= visit_addr (stmt, TREE_OPERAND (rhs, 0), data); 4934 ret |= visit_addr (stmt, TREE_OPERAND (rhs, 0), data);
4416 else if (TREE_CODE (rhs) == TARGET_MEM_REF 4935 else if (TREE_CODE (rhs) == TARGET_MEM_REF
4417 && TMR_BASE (rhs) != NULL_TREE 4936 && TREE_CODE (TMR_BASE (rhs)) == ADDR_EXPR)
4418 && TREE_CODE (TMR_BASE (rhs)) == ADDR_EXPR) 4937 ret |= visit_addr (stmt, TREE_OPERAND (TMR_BASE (rhs), 0), data);
4419 ret |= visit_addr (stmt, TREE_OPERAND (TMR_BASE (rhs), 0), data); 4938 else if (TREE_CODE (rhs) == OBJ_TYPE_REF
4420 else if (TREE_CODE (rhs) == OBJ_TYPE_REF 4939 && TREE_CODE (OBJ_TYPE_REF_OBJECT (rhs)) == ADDR_EXPR)
4421 && TREE_CODE (OBJ_TYPE_REF_OBJECT (rhs)) == ADDR_EXPR) 4940 ret |= visit_addr (stmt, TREE_OPERAND (OBJ_TYPE_REF_OBJECT (rhs),
4422 ret |= visit_addr (stmt, TREE_OPERAND (OBJ_TYPE_REF_OBJECT (rhs), 4941 0), data);
4423 0), data);
4424 lhs = gimple_assign_lhs (stmt); 4942 lhs = gimple_assign_lhs (stmt);
4425 if (TREE_CODE (lhs) == TARGET_MEM_REF 4943 if (TREE_CODE (lhs) == TARGET_MEM_REF
4426 && TMR_BASE (lhs) != NULL_TREE
4427 && TREE_CODE (TMR_BASE (lhs)) == ADDR_EXPR) 4944 && TREE_CODE (TMR_BASE (lhs)) == ADDR_EXPR)
4428 ret |= visit_addr (stmt, TREE_OPERAND (TMR_BASE (lhs), 0), data); 4945 ret |= visit_addr (stmt, TREE_OPERAND (TMR_BASE (lhs), 0), data);
4429 } 4946 }
4430 if (visit_load) 4947 if (visit_load)
4431 { 4948 {
4582 static bool 5099 static bool
4583 gimple_ior_addresses_taken_1 (gimple stmt ATTRIBUTE_UNUSED, 5100 gimple_ior_addresses_taken_1 (gimple stmt ATTRIBUTE_UNUSED,
4584 tree addr, void *data) 5101 tree addr, void *data)
4585 { 5102 {
4586 bitmap addresses_taken = (bitmap)data; 5103 bitmap addresses_taken = (bitmap)data;
4587 while (handled_component_p (addr)) 5104 addr = get_base_address (addr);
4588 addr = TREE_OPERAND (addr, 0); 5105 if (addr
4589 if (DECL_P (addr)) 5106 && DECL_P (addr))
4590 { 5107 {
4591 bitmap_set_bit (addresses_taken, DECL_UID (addr)); 5108 bitmap_set_bit (addresses_taken, DECL_UID (addr));
4592 return true; 5109 return true;
4593 } 5110 }
4594 return false; 5111 return false;
4609 /* Return a printable name for symbol DECL. */ 5126 /* Return a printable name for symbol DECL. */
4610 5127
4611 const char * 5128 const char *
4612 gimple_decl_printable_name (tree decl, int verbosity) 5129 gimple_decl_printable_name (tree decl, int verbosity)
4613 { 5130 {
4614 gcc_assert (decl && DECL_NAME (decl)); 5131 if (!DECL_NAME (decl))
5132 return NULL;
4615 5133
4616 if (DECL_ASSEMBLER_NAME_SET_P (decl)) 5134 if (DECL_ASSEMBLER_NAME_SET_P (decl))
4617 { 5135 {
4618 const char *str, *mangled_str; 5136 const char *str, *mangled_str;
4619 int dmgl_opts = DMGL_NO_OPTS; 5137 int dmgl_opts = DMGL_NO_OPTS;
4634 } 5152 }
4635 5153
4636 return IDENTIFIER_POINTER (DECL_NAME (decl)); 5154 return IDENTIFIER_POINTER (DECL_NAME (decl));
4637 } 5155 }
4638 5156
4639 5157 /* Return true when STMT is builtins call to CODE. */
4640 /* Fold a OBJ_TYPE_REF expression to the address of a function. 5158
4641 KNOWN_TYPE carries the true type of OBJ_TYPE_REF_OBJECT(REF). Adapted 5159 bool
4642 from cp_fold_obj_type_ref, but it tolerates types with no binfo 5160 gimple_call_builtin_p (gimple stmt, enum built_in_function code)
4643 data. */ 5161 {
4644
4645 tree
4646 gimple_fold_obj_type_ref (tree ref, tree known_type)
4647 {
4648 HOST_WIDE_INT index;
4649 HOST_WIDE_INT i;
4650 tree v;
4651 tree fndecl; 5162 tree fndecl;
4652 5163 return (is_gimple_call (stmt)
4653 if (TYPE_BINFO (known_type) == NULL_TREE) 5164 && (fndecl = gimple_call_fndecl (stmt)) != NULL
4654 return NULL_TREE; 5165 && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL
4655 5166 && DECL_FUNCTION_CODE (fndecl) == code);
4656 v = BINFO_VIRTUALS (TYPE_BINFO (known_type));
4657 index = tree_low_cst (OBJ_TYPE_REF_TOKEN (ref), 1);
4658 i = 0;
4659 while (i != index)
4660 {
4661 i += (TARGET_VTABLE_USES_DESCRIPTORS
4662 ? TARGET_VTABLE_USES_DESCRIPTORS : 1);
4663 v = TREE_CHAIN (v);
4664 }
4665
4666 fndecl = TREE_VALUE (v);
4667
4668 #ifdef ENABLE_CHECKING
4669 gcc_assert (tree_int_cst_equal (OBJ_TYPE_REF_TOKEN (ref),
4670 DECL_VINDEX (fndecl)));
4671 #endif
4672
4673 cgraph_node (fndecl)->local.vtable_method = true;
4674
4675 return build_fold_addr_expr (fndecl);
4676 } 5167 }
4677 5168
4678 #include "gt-gimple.h" 5169 #include "gt-gimple.h"