Mercurial > hg > CbC > CbC_gcc
comparison gcc/gimple.c @ 131:84e7813d76e9
gcc-8.2
author | mir3636 |
---|---|
date | Thu, 25 Oct 2018 07:37:49 +0900 |
parents | 04ced10e8804 |
children | d34655255c78 1830386684a0 |
comparison
equal
deleted
inserted
replaced
111:04ced10e8804 | 131:84e7813d76e9 |
---|---|
1 /* Gimple IR support functions. | 1 /* Gimple IR support functions. |
2 | 2 |
3 Copyright (C) 2007-2017 Free Software Foundation, Inc. | 3 Copyright (C) 2007-2018 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 |
75 }; | 75 }; |
76 #undef DEFGSCODE | 76 #undef DEFGSCODE |
77 | 77 |
78 /* Gimple stats. */ | 78 /* Gimple stats. */ |
79 | 79 |
80 int gimple_alloc_counts[(int) gimple_alloc_kind_all]; | 80 uint64_t gimple_alloc_counts[(int) gimple_alloc_kind_all]; |
81 int gimple_alloc_sizes[(int) gimple_alloc_kind_all]; | 81 uint64_t gimple_alloc_sizes[(int) gimple_alloc_kind_all]; |
82 | 82 |
83 /* Keep in sync with gimple.h:enum gimple_alloc_kind. */ | 83 /* Keep in sync with gimple.h:enum gimple_alloc_kind. */ |
84 static const char * const gimple_alloc_kind_names[] = { | 84 static const char * const gimple_alloc_kind_names[] = { |
85 "assignments", | 85 "assignments", |
86 "phi nodes", | 86 "phi nodes", |
348 gcall * | 348 gcall * |
349 gimple_build_call_from_tree (tree t, tree fnptrtype) | 349 gimple_build_call_from_tree (tree t, tree fnptrtype) |
350 { | 350 { |
351 unsigned i, nargs; | 351 unsigned i, nargs; |
352 gcall *call; | 352 gcall *call; |
353 tree fndecl = get_callee_fndecl (t); | |
354 | 353 |
355 gcc_assert (TREE_CODE (t) == CALL_EXPR); | 354 gcc_assert (TREE_CODE (t) == CALL_EXPR); |
356 | 355 |
357 nargs = call_expr_nargs (t); | 356 nargs = call_expr_nargs (t); |
358 call = gimple_build_call_1 (fndecl ? fndecl : CALL_EXPR_FN (t), nargs); | 357 |
358 tree fndecl = NULL_TREE; | |
359 if (CALL_EXPR_FN (t) == NULL_TREE) | |
360 call = gimple_build_call_internal_1 (CALL_EXPR_IFN (t), nargs); | |
361 else | |
362 { | |
363 fndecl = get_callee_fndecl (t); | |
364 call = gimple_build_call_1 (fndecl ? fndecl : CALL_EXPR_FN (t), nargs); | |
365 } | |
359 | 366 |
360 for (i = 0; i < nargs; i++) | 367 for (i = 0; i < nargs; i++) |
361 gimple_call_set_arg (call, i, CALL_EXPR_ARG (t, i)); | 368 gimple_call_set_arg (call, i, CALL_EXPR_ARG (t, i)); |
362 | 369 |
363 gimple_set_block (call, TREE_BLOCK (t)); | 370 gimple_set_block (call, TREE_BLOCK (t)); |
371 gimple_set_location (call, EXPR_LOCATION (t)); | |
364 | 372 |
365 /* Carry all the CALL_EXPR flags to the new GIMPLE_CALL. */ | 373 /* Carry all the CALL_EXPR flags to the new GIMPLE_CALL. */ |
366 gimple_call_set_chain (call, CALL_EXPR_STATIC_CHAIN (t)); | 374 gimple_call_set_chain (call, CALL_EXPR_STATIC_CHAIN (t)); |
367 gimple_call_set_tail (call, CALL_EXPR_TAILCALL (t)); | 375 gimple_call_set_tail (call, CALL_EXPR_TAILCALL (t)); |
368 gimple_call_set_must_tail (call, CALL_EXPR_MUST_TAIL_CALL (t)); | 376 gimple_call_set_must_tail (call, CALL_EXPR_MUST_TAIL_CALL (t)); |
369 gimple_call_set_return_slot_opt (call, CALL_EXPR_RETURN_SLOT_OPT (t)); | 377 gimple_call_set_return_slot_opt (call, CALL_EXPR_RETURN_SLOT_OPT (t)); |
370 if (fndecl | 378 if (fndecl |
371 && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL | 379 && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL) |
372 && ALLOCA_FUNCTION_CODE_P (DECL_FUNCTION_CODE (fndecl))) | 380 && ALLOCA_FUNCTION_CODE_P (DECL_FUNCTION_CODE (fndecl))) |
373 gimple_call_set_alloca_for_var (call, CALL_ALLOCA_FOR_VAR_P (t)); | 381 gimple_call_set_alloca_for_var (call, CALL_ALLOCA_FOR_VAR_P (t)); |
374 else | 382 else |
375 gimple_call_set_from_thunk (call, CALL_FROM_THUNK_P (t)); | 383 gimple_call_set_from_thunk (call, CALL_FROM_THUNK_P (t)); |
376 gimple_call_set_va_arg_pack (call, CALL_EXPR_VA_ARG_PACK (t)); | 384 gimple_call_set_va_arg_pack (call, CALL_EXPR_VA_ARG_PACK (t)); |
377 gimple_call_set_nothrow (call, TREE_NOTHROW (t)); | 385 gimple_call_set_nothrow (call, TREE_NOTHROW (t)); |
378 gimple_call_set_by_descriptor (call, CALL_EXPR_BY_DESCRIPTOR (t)); | 386 gimple_call_set_by_descriptor (call, CALL_EXPR_BY_DESCRIPTOR (t)); |
379 gimple_set_no_warning (call, TREE_NO_WARNING (t)); | 387 gimple_set_no_warning (call, TREE_NO_WARNING (t)); |
380 gimple_call_set_with_bounds (call, CALL_WITH_BOUNDS_P (t)); | |
381 | 388 |
382 if (fnptrtype) | 389 if (fnptrtype) |
383 { | 390 { |
384 gimple_call_set_fntype (call, TREE_TYPE (fnptrtype)); | 391 gimple_call_set_fntype (call, TREE_TYPE (fnptrtype)); |
385 | 392 |
845 | 852 |
846 gimple_debug_source_bind_set_var (p, var); | 853 gimple_debug_source_bind_set_var (p, var); |
847 gimple_debug_source_bind_set_value (p, value); | 854 gimple_debug_source_bind_set_value (p, value); |
848 if (stmt) | 855 if (stmt) |
849 gimple_set_location (p, gimple_location (stmt)); | 856 gimple_set_location (p, gimple_location (stmt)); |
857 | |
858 return p; | |
859 } | |
860 | |
861 | |
862 /* Build a new GIMPLE_DEBUG_BEGIN_STMT statement in BLOCK at | |
863 LOCATION. */ | |
864 | |
865 gdebug * | |
866 gimple_build_debug_begin_stmt (tree block, location_t location | |
867 MEM_STAT_DECL) | |
868 { | |
869 gdebug *p | |
870 = as_a <gdebug *> ( | |
871 gimple_build_with_ops_stat (GIMPLE_DEBUG, | |
872 (unsigned)GIMPLE_DEBUG_BEGIN_STMT, 0 | |
873 PASS_MEM_STAT)); | |
874 | |
875 gimple_set_location (p, location); | |
876 gimple_set_block (p, block); | |
877 cfun->debug_marker_count++; | |
878 | |
879 return p; | |
880 } | |
881 | |
882 | |
883 /* Build a new GIMPLE_DEBUG_INLINE_ENTRY statement in BLOCK at | |
884 LOCATION. The BLOCK links to the inlined function. */ | |
885 | |
886 gdebug * | |
887 gimple_build_debug_inline_entry (tree block, location_t location | |
888 MEM_STAT_DECL) | |
889 { | |
890 gdebug *p | |
891 = as_a <gdebug *> ( | |
892 gimple_build_with_ops_stat (GIMPLE_DEBUG, | |
893 (unsigned)GIMPLE_DEBUG_INLINE_ENTRY, 0 | |
894 PASS_MEM_STAT)); | |
895 | |
896 gimple_set_location (p, location); | |
897 gimple_set_block (p, block); | |
898 cfun->debug_marker_count++; | |
850 | 899 |
851 return p; | 900 return p; |
852 } | 901 } |
853 | 902 |
854 | 903 |
1494 | 1543 |
1495 case '.': | 1544 case '.': |
1496 default: | 1545 default: |
1497 return 0; | 1546 return 0; |
1498 } | 1547 } |
1548 } | |
1549 | |
1550 | |
1551 /* Return true if call STMT is known to return a non-zero result. */ | |
1552 | |
1553 bool | |
1554 gimple_call_nonnull_result_p (gcall *call) | |
1555 { | |
1556 tree fndecl = gimple_call_fndecl (call); | |
1557 if (!fndecl) | |
1558 return false; | |
1559 if (flag_delete_null_pointer_checks && !flag_check_new | |
1560 && DECL_IS_OPERATOR_NEW (fndecl) | |
1561 && !TREE_NOTHROW (fndecl)) | |
1562 return true; | |
1563 | |
1564 /* References are always non-NULL. */ | |
1565 if (flag_delete_null_pointer_checks | |
1566 && TREE_CODE (TREE_TYPE (fndecl)) == REFERENCE_TYPE) | |
1567 return true; | |
1568 | |
1569 if (flag_delete_null_pointer_checks | |
1570 && lookup_attribute ("returns_nonnull", | |
1571 TYPE_ATTRIBUTES (gimple_call_fntype (call)))) | |
1572 return true; | |
1573 return gimple_alloca_call_p (call); | |
1574 } | |
1575 | |
1576 | |
1577 /* If CALL returns a non-null result in an argument, return that arg. */ | |
1578 | |
1579 tree | |
1580 gimple_call_nonnull_arg (gcall *call) | |
1581 { | |
1582 tree fndecl = gimple_call_fndecl (call); | |
1583 if (!fndecl) | |
1584 return NULL_TREE; | |
1585 | |
1586 unsigned rf = gimple_call_return_flags (call); | |
1587 if (rf & ERF_RETURNS_ARG) | |
1588 { | |
1589 unsigned argnum = rf & ERF_RETURN_ARG_MASK; | |
1590 if (argnum < gimple_call_num_args (call)) | |
1591 { | |
1592 tree arg = gimple_call_arg (call, argnum); | |
1593 if (SSA_VAR_P (arg) | |
1594 && infer_nonnull_range_by_attribute (call, arg)) | |
1595 return arg; | |
1596 } | |
1597 } | |
1598 return NULL_TREE; | |
1499 } | 1599 } |
1500 | 1600 |
1501 | 1601 |
1502 /* Return true if GS is a copy assignment. */ | 1602 /* Return true if GS is a copy assignment. */ |
1503 | 1603 |
1912 | 2012 |
1913 /* SSA operands need to be updated. */ | 2013 /* SSA operands need to be updated. */ |
1914 gimple_set_modified (copy, true); | 2014 gimple_set_modified (copy, true); |
1915 } | 2015 } |
1916 | 2016 |
2017 if (gimple_debug_nonbind_marker_p (stmt)) | |
2018 cfun->debug_marker_count++; | |
2019 | |
1917 return copy; | 2020 return copy; |
1918 } | 2021 } |
1919 | 2022 |
1920 | 2023 |
1921 /* Return true if statement S has side-effects. We consider a | 2024 /* Return true if statement S has side-effects. We consider a |
2030 /* Print debugging information for gimple stmts generated. */ | 2133 /* Print debugging information for gimple stmts generated. */ |
2031 | 2134 |
2032 void | 2135 void |
2033 dump_gimple_statistics (void) | 2136 dump_gimple_statistics (void) |
2034 { | 2137 { |
2035 int i, total_tuples = 0, total_bytes = 0; | 2138 int i; |
2139 uint64_t total_tuples = 0, total_bytes = 0; | |
2036 | 2140 |
2037 if (! GATHER_STATISTICS) | 2141 if (! GATHER_STATISTICS) |
2038 { | 2142 { |
2039 fprintf (stderr, "No gimple statistics\n"); | 2143 fprintf (stderr, "No GIMPLE statistics\n"); |
2040 return; | 2144 return; |
2041 } | 2145 } |
2042 | 2146 |
2043 fprintf (stderr, "\nGIMPLE statements\n"); | 2147 fprintf (stderr, "\nGIMPLE statements\n"); |
2044 fprintf (stderr, "Kind Stmts Bytes\n"); | 2148 fprintf (stderr, "Kind Stmts Bytes\n"); |
2045 fprintf (stderr, "---------------------------------------\n"); | 2149 fprintf (stderr, "---------------------------------------\n"); |
2046 for (i = 0; i < (int) gimple_alloc_kind_all; ++i) | 2150 for (i = 0; i < (int) gimple_alloc_kind_all; ++i) |
2047 { | 2151 { |
2048 fprintf (stderr, "%-20s %7d %10d\n", gimple_alloc_kind_names[i], | 2152 fprintf (stderr, "%-20s %7" PRIu64 " %10" PRIu64 "\n", |
2049 gimple_alloc_counts[i], gimple_alloc_sizes[i]); | 2153 gimple_alloc_kind_names[i], gimple_alloc_counts[i], |
2154 gimple_alloc_sizes[i]); | |
2050 total_tuples += gimple_alloc_counts[i]; | 2155 total_tuples += gimple_alloc_counts[i]; |
2051 total_bytes += gimple_alloc_sizes[i]; | 2156 total_bytes += gimple_alloc_sizes[i]; |
2052 } | 2157 } |
2053 fprintf (stderr, "---------------------------------------\n"); | 2158 fprintf (stderr, "---------------------------------------\n"); |
2054 fprintf (stderr, "%-20s %7d %10d\n", "Total", total_tuples, total_bytes); | 2159 fprintf (stderr, "%-20s %7" PRIu64 " %10" PRIu64 "\n", "Total", |
2160 total_tuples, total_bytes); | |
2055 fprintf (stderr, "---------------------------------------\n"); | 2161 fprintf (stderr, "---------------------------------------\n"); |
2056 } | 2162 } |
2057 | 2163 |
2058 | 2164 |
2059 /* Return the number of operands needed on the RHS of a GIMPLE | 2165 /* Return the number of operands needed on the RHS of a GIMPLE |
2092 || (SYM) == DOT_PROD_EXPR \ | 2198 || (SYM) == DOT_PROD_EXPR \ |
2093 || (SYM) == SAD_EXPR \ | 2199 || (SYM) == SAD_EXPR \ |
2094 || (SYM) == REALIGN_LOAD_EXPR \ | 2200 || (SYM) == REALIGN_LOAD_EXPR \ |
2095 || (SYM) == VEC_COND_EXPR \ | 2201 || (SYM) == VEC_COND_EXPR \ |
2096 || (SYM) == VEC_PERM_EXPR \ | 2202 || (SYM) == VEC_PERM_EXPR \ |
2097 || (SYM) == BIT_INSERT_EXPR \ | 2203 || (SYM) == BIT_INSERT_EXPR) ? GIMPLE_TERNARY_RHS \ |
2098 || (SYM) == FMA_EXPR) ? GIMPLE_TERNARY_RHS \ | |
2099 : ((SYM) == CONSTRUCTOR \ | 2204 : ((SYM) == CONSTRUCTOR \ |
2100 || (SYM) == OBJ_TYPE_REF \ | 2205 || (SYM) == OBJ_TYPE_REF \ |
2101 || (SYM) == ASSERT_EXPR \ | 2206 || (SYM) == ASSERT_EXPR \ |
2102 || (SYM) == ADDR_EXPR \ | 2207 || (SYM) == ADDR_EXPR \ |
2103 || (SYM) == WITH_SIZE_EXPR \ | 2208 || (SYM) == WITH_SIZE_EXPR \ |
2574 gimple_call_builtin_p (const gimple *stmt, enum built_in_function code) | 2679 gimple_call_builtin_p (const gimple *stmt, enum built_in_function code) |
2575 { | 2680 { |
2576 tree fndecl; | 2681 tree fndecl; |
2577 if (is_gimple_call (stmt) | 2682 if (is_gimple_call (stmt) |
2578 && (fndecl = gimple_call_fndecl (stmt)) != NULL_TREE | 2683 && (fndecl = gimple_call_fndecl (stmt)) != NULL_TREE |
2579 && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL | 2684 && fndecl_built_in_p (fndecl, code)) |
2580 && DECL_FUNCTION_CODE (fndecl) == code) | |
2581 return gimple_builtin_call_types_compatible_p (stmt, fndecl); | 2685 return gimple_builtin_call_types_compatible_p (stmt, fndecl); |
2582 return false; | 2686 return false; |
2583 } | 2687 } |
2584 | 2688 |
2585 /* If CALL is a call to a combined_fn (i.e. an internal function or | 2689 /* If CALL is a call to a combined_fn (i.e. an internal function or |
2594 if (gimple_call_internal_p (call)) | 2698 if (gimple_call_internal_p (call)) |
2595 return as_combined_fn (gimple_call_internal_fn (call)); | 2699 return as_combined_fn (gimple_call_internal_fn (call)); |
2596 | 2700 |
2597 tree fndecl = gimple_call_fndecl (stmt); | 2701 tree fndecl = gimple_call_fndecl (stmt); |
2598 if (fndecl | 2702 if (fndecl |
2599 && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL | 2703 && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL) |
2600 && gimple_builtin_call_types_compatible_p (stmt, fndecl)) | 2704 && gimple_builtin_call_types_compatible_p (stmt, fndecl)) |
2601 return as_combined_fn (DECL_FUNCTION_CODE (fndecl)); | 2705 return as_combined_fn (DECL_FUNCTION_CODE (fndecl)); |
2602 } | 2706 } |
2603 return CFN_LAST; | 2707 return CFN_LAST; |
2604 } | 2708 } |
3097 | 3201 |
3098 static void | 3202 static void |
3099 verify_gimple_pp (const char *expected, gimple *stmt) | 3203 verify_gimple_pp (const char *expected, gimple *stmt) |
3100 { | 3204 { |
3101 pretty_printer pp; | 3205 pretty_printer pp; |
3102 pp_gimple_stmt_1 (&pp, stmt, 0 /* spc */, 0 /* flags */); | 3206 pp_gimple_stmt_1 (&pp, stmt, 0 /* spc */, TDF_NONE /* flags */); |
3103 ASSERT_STREQ (expected, pp_formatted_text (&pp)); | 3207 ASSERT_STREQ (expected, pp_formatted_text (&pp)); |
3104 } | 3208 } |
3105 | 3209 |
3106 /* Build a GIMPLE_ASSIGN equivalent to | 3210 /* Build a GIMPLE_ASSIGN equivalent to |
3107 tmp = 5; | 3211 tmp = 5; |