Mercurial > hg > CbC > CbC_gcc
diff gcc/gimple.c @ 146:351920fa3827
merge
author | anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 01 Mar 2020 16:13:28 +0900 |
parents | 4e440907fcbf 1830386684a0 |
children |
line wrap: on
line diff
--- a/gcc/gimple.c Sun Dec 23 21:23:56 2018 +0900 +++ b/gcc/gimple.c Sun Mar 01 16:13:28 2020 +0900 @@ -1,6 +1,6 @@ /* Gimple IR support functions. - Copyright (C) 2007-2018 Free Software Foundation, Inc. + Copyright (C) 2007-2020 Free Software Foundation, Inc. Contributed by Aldy Hernandez <aldyh@redhat.com> This file is part of GCC. @@ -47,6 +47,8 @@ #ifndef noCbC #include "c/cbc-tree.h" #endif +#include "langhooks.h" + /* All the tuples have their operand vector (if present) at the very bottom of the structure. Therefore, the offset required to find the @@ -111,10 +113,27 @@ /* Return the number of bytes needed to hold a GIMPLE statement with code CODE. */ -static inline size_t -gimple_size (enum gimple_code code) +size_t +gimple_size (enum gimple_code code, unsigned num_ops) { - return gsstruct_code_size[gss_for_code (code)]; + size_t size = gsstruct_code_size[gss_for_code (code)]; + if (num_ops > 0) + size += (sizeof (tree) * (num_ops - 1)); + return size; +} + +/* Initialize GIMPLE statement G with CODE and NUM_OPS. */ + +void +gimple_init (gimple *g, enum gimple_code code, unsigned num_ops) +{ + gimple_set_code (g, code); + gimple_set_num_ops (g, num_ops); + + /* Do not call gimple_set_modified here as it has other side + effects and this tuple is still not completely built. */ + g->modified = 1; + gimple_init_singleton (g); } /* Allocate memory for a GIMPLE statement with code CODE and NUM_OPS @@ -126,10 +145,7 @@ size_t size; gimple *stmt; - size = gimple_size (code); - if (num_ops > 0) - size += sizeof (tree) * (num_ops - 1); - + size = gimple_size (code, num_ops); if (GATHER_STATISTICS) { enum gimple_alloc_kind kind = gimple_alloc_kind (code); @@ -138,14 +154,7 @@ } stmt = ggc_alloc_cleared_gimple_statement_stat (size PASS_MEM_STAT); - gimple_set_code (stmt, code); - gimple_set_num_ops (stmt, num_ops); - - /* Do not call gimple_set_modified here as it has other side - effects and this tuple is still not completely built. */ - stmt->modified = 1; - gimple_init_singleton (stmt); - + gimple_init (stmt, code, num_ops); return stmt; } @@ -929,7 +938,7 @@ BODY is sequence of statements inside the for loop. KIND is the `for' variant. - CLAUSES, are any of the construct's clauses. + CLAUSES are any of the construct's clauses. COLLAPSE is the collapse count. PRE_BODY is the sequence of statements that are loop invariant. */ @@ -955,7 +964,7 @@ /* Build a GIMPLE_OMP_PARALLEL statement. BODY is sequence of statements which are executed in parallel. - CLAUSES, are the OMP parallel construct's clauses. + CLAUSES are the OMP parallel construct's clauses. CHILD_FN is the function created for the parallel threads to execute. DATA_ARG are the shared data argument(s). */ @@ -978,7 +987,7 @@ /* Build a GIMPLE_OMP_TASK statement. BODY is sequence of statements which are executed by the explicit task. - CLAUSES, are the OMP parallel construct's clauses. + CLAUSES are the OMP task construct's clauses. CHILD_FN is the function created for the parallel threads to execute. DATA_ARG are the shared data argument(s). COPY_FN is the optional function for firstprivate initialization. @@ -1049,12 +1058,14 @@ /* Build a GIMPLE_OMP_TASKGROUP statement. BODY is the sequence of statements to be executed by the taskgroup - construct. */ + construct. + CLAUSES are any of the construct's clauses. */ gimple * -gimple_build_omp_taskgroup (gimple_seq body) +gimple_build_omp_taskgroup (gimple_seq body, tree clauses) { gimple *p = gimple_alloc (GIMPLE_OMP_TASKGROUP, 0); + gimple_omp_taskgroup_set_clauses (p, clauses); if (body) gimple_omp_set_body (p, body); @@ -1110,6 +1121,25 @@ } +/* Build a GIMPLE_OMP_SCAN statement. + + BODY is the sequence of statements to be executed by the scan + construct. + CLAUSES are any of the construct's clauses. */ + +gomp_scan * +gimple_build_omp_scan (gimple_seq body, tree clauses) +{ + gomp_scan *p + = as_a <gomp_scan *> (gimple_alloc (GIMPLE_OMP_SCAN, 0)); + gimple_omp_scan_set_clauses (p, clauses); + if (body) + gimple_omp_set_body (p, body); + + return p; +} + + /* Build a GIMPLE_OMP_SECTIONS statement. BODY is a sequence of section statements. @@ -1197,12 +1227,13 @@ /* Build a GIMPLE_OMP_ATOMIC_LOAD statement. */ gomp_atomic_load * -gimple_build_omp_atomic_load (tree lhs, tree rhs) +gimple_build_omp_atomic_load (tree lhs, tree rhs, enum omp_memory_order mo) { gomp_atomic_load *p = as_a <gomp_atomic_load *> (gimple_alloc (GIMPLE_OMP_ATOMIC_LOAD, 0)); gimple_omp_atomic_load_set_lhs (p, lhs); gimple_omp_atomic_load_set_rhs (p, rhs); + gimple_omp_atomic_set_memory_order (p, mo); return p; } @@ -1211,11 +1242,12 @@ VAL is the value we are storing. */ gomp_atomic_store * -gimple_build_omp_atomic_store (tree val) +gimple_build_omp_atomic_store (tree val, enum omp_memory_order mo) { gomp_atomic_store *p = as_a <gomp_atomic_store *> (gimple_alloc (GIMPLE_OMP_ATOMIC_STORE, 0)); gimple_omp_atomic_store_set_val (p, val); + gimple_omp_atomic_set_memory_order (p, mo); return p; } @@ -1447,15 +1479,17 @@ int gimple_call_flags (const gimple *stmt) { - int flags; - tree decl = gimple_call_fndecl (stmt); - - if (decl) - flags = flags_from_decl_or_type (decl); - else if (gimple_call_internal_p (stmt)) + int flags = 0; + + if (gimple_call_internal_p (stmt)) flags = internal_fn_flags (gimple_call_internal_fn (stmt)); else - flags = flags_from_decl_or_type (gimple_call_fntype (stmt)); + { + tree decl = gimple_call_fndecl (stmt); + if (decl) + flags = flags_from_decl_or_type (decl); + flags |= flags_from_decl_or_type (gimple_call_fntype (stmt)); + } if (stmt->subcode & GF_CALL_NOTHROW) flags |= ECF_NOTHROW; @@ -1562,7 +1596,7 @@ if (!fndecl) return false; if (flag_delete_null_pointer_checks && !flag_check_new - && DECL_IS_OPERATOR_NEW (fndecl) + && DECL_IS_OPERATOR_NEW_P (fndecl) && !TREE_NOTHROW (fndecl)) return true; @@ -1728,16 +1762,15 @@ { unsigned new_rhs_ops = get_gimple_rhs_num_ops (code); gimple *stmt = gsi_stmt (*gsi); + gimple *old_stmt = stmt; /* If the new CODE needs more operands, allocate a new statement. */ if (gimple_num_ops (stmt) < new_rhs_ops + 1) { - tree lhs = gimple_assign_lhs (stmt); - gimple *new_stmt = gimple_alloc (gimple_code (stmt), new_rhs_ops + 1); - memcpy (new_stmt, stmt, gimple_size (gimple_code (stmt))); - gimple_init_singleton (new_stmt); - gsi_replace (gsi, new_stmt, false); - stmt = new_stmt; + tree lhs = gimple_assign_lhs (old_stmt); + stmt = gimple_alloc (gimple_code (old_stmt), new_rhs_ops + 1); + memcpy (stmt, old_stmt, gimple_size (gimple_code (old_stmt))); + gimple_init_singleton (stmt); /* The LHS needs to be reset as this also changes the SSA name on the LHS. */ @@ -1751,6 +1784,8 @@ gimple_assign_set_rhs2 (stmt, op2); if (new_rhs_ops > 2) gimple_assign_set_rhs3 (stmt, op3); + if (stmt != old_stmt) + gsi_replace (gsi, stmt, false); } @@ -1768,6 +1803,8 @@ return gimple_assign_lhs (stmt); else if (code == GIMPLE_CALL) return gimple_call_lhs (stmt); + else if (code == GIMPLE_PHI) + return gimple_phi_result (stmt); else return NULL_TREE; } @@ -1940,6 +1977,17 @@ gimple_omp_ordered_set_clauses (as_a <gomp_ordered *> (copy), t); goto copy_omp_body; + case GIMPLE_OMP_SCAN: + t = gimple_omp_scan_clauses (as_a <gomp_scan *> (stmt)); + t = unshare_expr (t); + gimple_omp_scan_set_clauses (as_a <gomp_scan *> (copy), t); + goto copy_omp_body; + + case GIMPLE_OMP_TASKGROUP: + t = unshare_expr (gimple_omp_taskgroup_clauses (stmt)); + gimple_omp_taskgroup_set_clauses (copy, t); + goto copy_omp_body; + case GIMPLE_OMP_SECTIONS: t = unshare_expr (gimple_omp_sections_clauses (stmt)); gimple_omp_sections_set_clauses (copy, t); @@ -1976,7 +2024,6 @@ case GIMPLE_OMP_SECTION: case GIMPLE_OMP_MASTER: - case GIMPLE_OMP_TASKGROUP: case GIMPLE_OMP_GRID_BODY: copy_omp_body: new_seq = gimple_seq_copy (gimple_omp_body (stmt)); @@ -2025,6 +2072,18 @@ return copy; } +/* Move OLD_STMT's vuse and vdef operands to NEW_STMT, on the assumption + that OLD_STMT is about to be removed. */ + +void +gimple_move_vops (gimple *new_stmt, gimple *old_stmt) +{ + tree vdef = gimple_vdef (old_stmt); + gimple_set_vuse (new_stmt, gimple_vuse (old_stmt)); + gimple_set_vdef (new_stmt, vdef); + if (vdef && TREE_CODE (vdef) == SSA_NAME) + SSA_NAME_DEF_STMT (vdef) = new_stmt; +} /* Return true if statement S has side-effects. We consider a statement to have side effects if: @@ -2096,10 +2155,22 @@ return false; case GIMPLE_ASSIGN: - t = gimple_expr_type (s); op = gimple_assign_rhs_code (s); + + /* For COND_EXPR and VEC_COND_EXPR only the condition may trap. */ + if (op == COND_EXPR || op == VEC_COND_EXPR) + return tree_could_trap_p (gimple_assign_rhs1 (s)); + + /* For comparisons we need to check rhs operand types instead of rhs type + (which is BOOLEAN_TYPE). */ + if (TREE_CODE_CLASS (op) == tcc_comparison) + t = TREE_TYPE (gimple_assign_rhs1 (s)); + else + t = gimple_expr_type (s); + if (get_gimple_rhs_class (op) == GIMPLE_BINARY_RHS) div = gimple_assign_rhs2 (s); + return (operation_could_trap_p (op, FLOAT_TYPE_P (t), (INTEGRAL_TYPE_P (t) && TYPE_OVERFLOW_TRAPS (t)), @@ -2154,15 +2225,16 @@ fprintf (stderr, "---------------------------------------\n"); for (i = 0; i < (int) gimple_alloc_kind_all; ++i) { - fprintf (stderr, "%-20s %7" PRIu64 " %10" PRIu64 "\n", - gimple_alloc_kind_names[i], gimple_alloc_counts[i], - gimple_alloc_sizes[i]); + fprintf (stderr, "%-20s %7" PRIu64 "%c %10" PRIu64 "%c\n", + gimple_alloc_kind_names[i], + SIZE_AMOUNT (gimple_alloc_counts[i]), + SIZE_AMOUNT (gimple_alloc_sizes[i])); total_tuples += gimple_alloc_counts[i]; total_bytes += gimple_alloc_sizes[i]; } fprintf (stderr, "---------------------------------------\n"); - fprintf (stderr, "%-20s %7" PRIu64 " %10" PRIu64 "\n", "Total", - total_tuples, total_bytes); + fprintf (stderr, "%-20s %7" PRIu64 "%c %10" PRIu64 "%c\n", "Total", + SIZE_AMOUNT (total_tuples), SIZE_AMOUNT (total_bytes)); fprintf (stderr, "---------------------------------------\n"); } @@ -2173,16 +2245,18 @@ unsigned get_gimple_rhs_num_ops (enum tree_code code) { - enum gimple_rhs_class rhs_class = get_gimple_rhs_class (code); - - if (rhs_class == GIMPLE_UNARY_RHS || rhs_class == GIMPLE_SINGLE_RHS) - return 1; - else if (rhs_class == GIMPLE_BINARY_RHS) - return 2; - else if (rhs_class == GIMPLE_TERNARY_RHS) - return 3; - else - gcc_unreachable (); + switch (get_gimple_rhs_class (code)) + { + case GIMPLE_UNARY_RHS: + case GIMPLE_SINGLE_RHS: + return 1; + case GIMPLE_BINARY_RHS: + return 2; + case GIMPLE_TERNARY_RHS: + return 3; + default: + gcc_unreachable (); + } } #define DEFTREECODE(SYM, STRING, TYPE, NARGS) \ @@ -2584,6 +2658,16 @@ return get_alias_set (t1); } + /* Allow aliasing between enumeral types and the underlying + integer type. This is required for C since those are + compatible types. */ + else if (TREE_CODE (t) == ENUMERAL_TYPE) + { + tree t1 = lang_hooks.types.type_for_size (tree_to_uhwi (TYPE_SIZE (t)), + false /* short-cut above */); + return get_alias_set (t1); + } + return -1; } @@ -2656,6 +2740,18 @@ return true; } +/* Return true when STMT is operator delete call. */ + +bool +gimple_call_operator_delete_p (const gcall *stmt) +{ + tree fndecl; + + if ((fndecl = gimple_call_fndecl (stmt)) != NULL_TREE) + return DECL_IS_OPERATOR_DELETE_P (fndecl); + return false; +} + /* Return true when STMT is builtins call. */ bool