From 93f8cb4965cebee125f96376367f05e18ee5749b Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Tue, 4 May 2021 12:47:11 +0200 Subject: Reuse non-gimple_reg variable for inlining When a call to a function is inlined and takes a parameter whose type is not gimple_reg, a local variable is created in the caller to hold a copy of the argument passed in the call with the following comment: /* We may produce non-gimple trees by adding NOPs or introduce invalid sharing when operand is not really constant. It is not big deal to prohibit constant propagation here as we will constant propagate in DOM1 pass anyway. * Of course the second sentence of the comment does not apply to non-gimple_reg values, unless they get SRAed later, because we don't do constant propagation for them. This for example prevents two identical calls to a pure function from being merged in the attached Ada testcase. Therefore the attached patch attempts to reuse a read-only or non-addressable local DECL of the caller, the hitch being that expand_call_inline needs to be prevented from creating a CLOBBER for the case where it ends uo being reused. gcc/ * tree-inline.c (insert_debug_decl_map): Delete. (copy_debug_stmt): Minor tweak. (setup_one_parameter): Do not use a variable if the value is either a read-only DECL or a non-addressable local variable in the caller. In this case, insert the debug-only variable in the map manually. (expand_call_inline): Do not generate a CLOBBER for these values. * tree-inline.h (debug_map): Minor tweak. --- gcc/tree-inline.c | 56 +++++++++++++++++++++---------------------------------- 1 file changed, 21 insertions(+), 35 deletions(-) (limited to 'gcc/tree-inline.c') diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index 1dcb31c..49a5850 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -152,30 +152,6 @@ insert_decl_map (copy_body_data *id, tree key, tree value) id->decl_map->put (value, value); } -/* Insert a tree->tree mapping for ID. This is only used for - variables. */ - -static void -insert_debug_decl_map (copy_body_data *id, tree key, tree value) -{ - if (!gimple_in_ssa_p (id->src_cfun)) - return; - - if (!opt_for_fn (id->dst_fn, flag_var_tracking_assignments)) - return; - - if (!target_for_debug_bind (key)) - return; - - gcc_assert (TREE_CODE (key) == PARM_DECL); - gcc_assert (VAR_P (value)); - - if (!id->debug_map) - id->debug_map = new hash_map; - - id->debug_map->put (key, value); -} - /* If nonzero, we're remapping the contents of inlined debug statements. If negative, an error has occurred, such as a reference to a variable that isn't available in the inlined @@ -3190,7 +3166,8 @@ copy_debug_stmt (gdebug *stmt, copy_body_data *id) else gcc_unreachable (); - if (TREE_CODE (t) == PARM_DECL && id->debug_map + if (TREE_CODE (t) == PARM_DECL + && id->debug_map && (n = id->debug_map->get (t))) { gcc_assert (VAR_P (*n)); @@ -3460,16 +3437,18 @@ setup_one_parameter (copy_body_data *id, tree p, tree value, tree fn, value. */ if (TREE_READONLY (p) && !TREE_ADDRESSABLE (p) - && value && !TREE_SIDE_EFFECTS (value) + && value + && !TREE_SIDE_EFFECTS (value) && !def) { - /* We may produce non-gimple trees by adding NOPs or introduce - invalid sharing when operand is not really constant. - It is not big deal to prohibit constant propagation here as - we will constant propagate in DOM1 pass anyway. */ - if (is_gimple_min_invariant (value) - && useless_type_conversion_p (TREE_TYPE (p), - TREE_TYPE (value)) + /* We may produce non-gimple trees by adding NOPs or introduce invalid + sharing when the value is not constant or DECL. And we need to make + sure that it cannot be modified from another path in the callee. */ + if ((is_gimple_min_invariant (value) + || (DECL_P (value) && TREE_READONLY (value)) + || (auto_var_in_fn_p (value, id->src_fn) + && !TREE_ADDRESSABLE (value))) + && useless_type_conversion_p (TREE_TYPE (p), TREE_TYPE (value)) /* We have to be very careful about ADDR_EXPR. Make sure the base variable isn't a local variable of the inlined function, e.g., when doing recursive inlining, direct or @@ -3478,7 +3457,9 @@ setup_one_parameter (copy_body_data *id, tree p, tree value, tree fn, && ! self_inlining_addr_expr (value, fn)) { insert_decl_map (id, p, value); - insert_debug_decl_map (id, p, var); + if (!id->debug_map) + id->debug_map = new hash_map; + id->debug_map->put (p, var); return insert_init_debug_bind (id, bb, var, value, NULL); } } @@ -5128,8 +5109,13 @@ expand_call_inline (basic_block bb, gimple *stmt, copy_body_data *id, for (tree p = DECL_ARGUMENTS (id->src_fn); p; p = DECL_CHAIN (p)) if (!TREE_THIS_VOLATILE (p)) { + /* The value associated with P is a local temporary only if + there is no value associated with P in the debug map. */ tree *varp = id->decl_map->get (p); - if (varp && VAR_P (*varp) && !is_gimple_reg (*varp)) + if (varp + && VAR_P (*varp) + && !is_gimple_reg (*varp) + && !(id->debug_map && id->debug_map->get (p))) { tree clobber = build_clobber (TREE_TYPE (*varp)); gimple *clobber_stmt; -- cgit v1.1 From 1698f496c5ee96b980ba97f5cd5f56b633e4afe0 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Thu, 6 May 2021 09:44:49 +0200 Subject: Fix IPA SRA removal of DECL_BY_REFERENCE return While doing bogus call LHS removal I noticed that cloning with dropping a return value creates a bogus replacement for a DECL_BY_REFERENCE DECL_RESULT, resulting in MEM_REFs of aggregates rather than pointers. The following fixes this latent issue. 2021-05-06 Richard Biener * tree-inline.c (tree_function_versioning): Fix DECL_BY_REFERENCE return variable removal. --- gcc/tree-inline.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'gcc/tree-inline.c') diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index 49a5850..8f945b8 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -6367,6 +6367,8 @@ tree_function_versioning (tree old_decl, tree new_decl, tree resdecl_repl = copy_result_decl_to_var (DECL_RESULT (old_decl), &id); declare_inline_vars (NULL, resdecl_repl); + if (DECL_BY_REFERENCE (DECL_RESULT (old_decl))) + resdecl_repl = build_fold_addr_expr (resdecl_repl); insert_decl_map (&id, DECL_RESULT (old_decl), resdecl_repl); DECL_RESULT (new_decl) -- cgit v1.1 From 1d3707a52d6b8a3054248b4291719150937db309 Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Tue, 25 May 2021 16:51:05 +0200 Subject: Fix thinko in latest change to setup_one_parameter gcc/ * tree-inline.c (setup_one_parameter): Fix thinko in new condition. --- gcc/tree-inline.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gcc/tree-inline.c') diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index 8f945b8..1d13e7f 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -3446,7 +3446,7 @@ setup_one_parameter (copy_body_data *id, tree p, tree value, tree fn, sure that it cannot be modified from another path in the callee. */ if ((is_gimple_min_invariant (value) || (DECL_P (value) && TREE_READONLY (value)) - || (auto_var_in_fn_p (value, id->src_fn) + || (auto_var_in_fn_p (value, id->dst_fn) && !TREE_ADDRESSABLE (value))) && useless_type_conversion_p (TREE_TYPE (p), TREE_TYPE (value)) /* We have to be very careful about ADDR_EXPR. Make sure -- cgit v1.1 From 359c0a86e2974a9f3036bc05b6e6c661f2c463cf Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Fri, 28 May 2021 13:31:35 +0200 Subject: ipa/100791 - copy fntype when processing __builtin_va_arg_pack This missing copying exposed a type mismatch in the IL. 2021-05-28 Richard Biener PR ipa/100791 * tree-inline.c (copy_bb): When processing __builtin_va_arg_pack copy fntype from original call. * gcc.dg/pr100791.c: New testcase. --- gcc/tree-inline.c | 1 + 1 file changed, 1 insertion(+) (limited to 'gcc/tree-inline.c') diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index 1d13e7f..d38e861 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -2100,6 +2100,7 @@ copy_bb (copy_body_data *id, basic_block bb, GF_CALL_VA_ARG_PACK. */ gimple_call_copy_flags (new_call, call_stmt); gimple_call_set_va_arg_pack (new_call, false); + gimple_call_set_fntype (new_call, gimple_call_fntype (call_stmt)); /* location includes block. */ gimple_set_location (new_call, gimple_location (stmt)); gimple_call_set_lhs (new_call, gimple_call_lhs (call_stmt)); -- cgit v1.1 From 098f4e989beb1a1be1157430c56ea4f158c1d538 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Thu, 3 Jun 2021 10:38:08 +0200 Subject: openmp: Assorted depend/affinity/iterator related fixes [PR100859] The depend-iterator-3.C testcases shows various bugs. 1) tsubst_omp_clauses didn't handle OMP_CLAUSE_AFFINITY (should be handled like OMP_CLAUSE_DEPEND) 2) because locators can be arbitrary lvalue expressions, we need to allow for C++ array section base (especially when array section is just an array reference) FIELD_DECLs, handle them as this->member, but don't need to privatize in any way 3) similarly for this as base 4) depend(inout: this) is invalid, but for different reason than the reported one, again this is an expression, but not lvalue expression, so that should be reported 5) the ctor/dtor cloning in the C++ FE (which is using walk_tree with copy_tree_body_r) didn't handle iterators correctly, walk_tree normally doesn't walk TREE_PURPOSE of TREE_LIST, and in the iterator case that TREE_VEC contains also a BLOCK that needs special handling during copy_tree_body_r 2021-06-03 Jakub Jelinek PR c++/100859 gcc/ * tree-inline.c (copy_tree_body_r): Handle iterators on OMP_CLAUSE_AFFINITY or OMP_CLAUSE_DEPEND. gcc/c/ * c-typeck.c (c_finish_omp_clauses): Move OMP_CLAUSE_AFFINITY after depend only cases. gcc/cp/ * semantics.c (handle_omp_array_sections_1): For OMP_CLAUSE_{AFFINITY,DEPEND} handle FIELD_DECL base using finish_non_static_data_member and allow this as base. (finish_omp_clauses): Move OMP_CLAUSE_AFFINITY after depend only cases. Let this be diagnosed by !lvalue_p case for OMP_CLAUSE_{AFFINITY,DEPEND} and remove useless assert. * pt.c (tsubst_omp_clauses): Handle OMP_CLAUSE_AFFINITY. gcc/testsuite/ * g++.dg/gomp/depend-iterator-3.C: New test. * g++.dg/gomp/this-1.C: Don't expect any diagnostics for this as base expression of depend array section, expect a different error wording for this as depend locator and add testcases for affinity clauses. --- gcc/tree-inline.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'gcc/tree-inline.c') diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index d38e861..5396131 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -1453,6 +1453,27 @@ copy_tree_body_r (tree *tp, int *walk_subtrees, void *data) *walk_subtrees = 0; } + else if (TREE_CODE (*tp) == OMP_CLAUSE + && (OMP_CLAUSE_CODE (*tp) == OMP_CLAUSE_AFFINITY + || OMP_CLAUSE_CODE (*tp) == OMP_CLAUSE_DEPEND)) + { + tree t = OMP_CLAUSE_DECL (*tp); + if (TREE_CODE (t) == TREE_LIST + && TREE_PURPOSE (t) + && TREE_CODE (TREE_PURPOSE (t)) == TREE_VEC) + { + *walk_subtrees = 0; + OMP_CLAUSE_DECL (*tp) = copy_node (t); + t = OMP_CLAUSE_DECL (*tp); + TREE_PURPOSE (t) = copy_node (TREE_PURPOSE (t)); + for (int i = 0; i <= 4; i++) + walk_tree (&TREE_VEC_ELT (TREE_PURPOSE (t), i), + copy_tree_body_r, id, NULL); + if (TREE_VEC_ELT (TREE_PURPOSE (t), 5)) + remap_block (&TREE_VEC_ELT (TREE_PURPOSE (t), 5), id); + walk_tree (&TREE_VALUE (t), copy_tree_body_r, id, NULL); + } + } } /* Keep iterating. */ -- cgit v1.1 From ad085ef5fb4142df2027f81ea03992fdafc6e2f6 Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Thu, 3 Jun 2021 12:39:39 +0200 Subject: Tame fix for PR ipa/99122 The return part has a major performance impact in Ada where variable-sized types are first-class citizens, but it turns out that it is not exercized in the testsuite yet, so back it out for now. gcc/ PR ipa/99122 * tree-inline.c (inline_forbidden_p): Remove test on return type. gcc/testsuite/ * gnat.dg/inline22.adb: New test. --- gcc/tree-inline.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'gcc/tree-inline.c') diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index 5396131..05d1a25 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -4025,17 +4025,10 @@ inline_forbidden_p (tree fndecl) wi.info = (void *) fndecl; wi.pset = &visited_nodes; - /* We cannot inline a function with a VLA typed argument or result since - we have no implementation materializing a variable of such type in - the caller. */ - if (COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (fndecl))) - && !poly_int_tree_p (TYPE_SIZE (TREE_TYPE (TREE_TYPE (fndecl))))) - { - inline_forbidden_reason - = G_("function %q+F can never be inlined because " - "it has a VLA return argument"); - return true; - } + /* We cannot inline a function with a variable-sized parameter because we + cannot materialize a temporary of such a type in the caller if need be. + Note that the return case is not symmetrical because we can guarantee + that a temporary is not needed by means of CALL_EXPR_RETURN_SLOT_OPT. */ for (tree parm = DECL_ARGUMENTS (fndecl); parm; parm = DECL_CHAIN (parm)) if (!poly_int_tree_p (DECL_SIZE (parm))) { -- cgit v1.1 From d66a703c8ba86f3ca04cc10c3071696e6d014de6 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Mon, 7 Jun 2021 09:25:37 +0200 Subject: tree-inline: Fix up __builtin_va_arg_pack handling [PR100898] The following testcase ICEs, because gimple_call_arg_ptr (..., 0) asserts that there is at least one argument, while we were using it even if we didn't copy anything just to get a pointer from/to which the zero arguments should be copied. Fixed by guarding the memcpy calls. Also, the code was calling gimple_call_num_args too many times - 5 times instead of 2, so the patch adds two temporaries for those. 2021-06-07 Jakub Jelinek PR middle-end/100898 * tree-inline.c (copy_bb): Only use gimple_call_arg_ptr if memcpy should copy any arguments. Don't call gimple_call_num_args on id->call_stmt or call_stmt more than once. * g++.dg/ext/va-arg-pack-3.C: New test. --- gcc/tree-inline.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'gcc/tree-inline.c') diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index 05d1a25..4250fd8 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -2090,27 +2090,29 @@ copy_bb (copy_body_data *id, basic_block bb, tree p; gcall *new_call; vec argarray; - size_t nargs = gimple_call_num_args (id->call_stmt); - size_t n; + size_t nargs_caller = gimple_call_num_args (id->call_stmt); + size_t nargs = nargs_caller; for (p = DECL_ARGUMENTS (id->src_fn); p; p = DECL_CHAIN (p)) nargs--; /* Create the new array of arguments. */ - n = nargs + gimple_call_num_args (call_stmt); + size_t nargs_callee = gimple_call_num_args (call_stmt); + size_t n = nargs + nargs_callee; argarray.create (n); argarray.safe_grow_cleared (n, true); /* Copy all the arguments before '...' */ - memcpy (argarray.address (), - gimple_call_arg_ptr (call_stmt, 0), - gimple_call_num_args (call_stmt) * sizeof (tree)); + if (nargs_callee) + memcpy (argarray.address (), + gimple_call_arg_ptr (call_stmt, 0), + nargs_callee * sizeof (tree)); /* Append the arguments passed in '...' */ - memcpy (argarray.address () + gimple_call_num_args (call_stmt), - gimple_call_arg_ptr (id->call_stmt, 0) - + (gimple_call_num_args (id->call_stmt) - nargs), - nargs * sizeof (tree)); + if (nargs) + memcpy (argarray.address () + nargs_callee, + gimple_call_arg_ptr (id->call_stmt, 0) + + (nargs_caller - nargs), nargs * sizeof (tree)); new_call = gimple_build_call_vec (gimple_call_fn (call_stmt), argarray); -- cgit v1.1 From 8b4641033ab6901c18f68b98843f1038a9a52e03 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 8 Jun 2021 11:16:41 +0200 Subject: openmp: Fix ICE on depend(source) clause during cdtor cloning [PR100957] The depend(source) clause has NULL OMP_CLAUSE_DECL, it has just the depend kind specified and no arguments. So copy_tree_body_r shouldn't check TREE_CODE on it without checking it is non-NULL. 2021-06-08 Jakub Jelinek PR c++/100957 * tree-inline.c (copy_tree_body_r): For OMP_CLAUSE_DEPEND don't check TREE_CODE if OMP_CLAUSE_DECL is NULL. * g++.dg/gomp/doacross-2.C: New test. --- gcc/tree-inline.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'gcc/tree-inline.c') diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index 4250fd8..9eb08d2 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -1458,7 +1458,8 @@ copy_tree_body_r (tree *tp, int *walk_subtrees, void *data) || OMP_CLAUSE_CODE (*tp) == OMP_CLAUSE_DEPEND)) { tree t = OMP_CLAUSE_DECL (*tp); - if (TREE_CODE (t) == TREE_LIST + if (t + && TREE_CODE (t) == TREE_LIST && TREE_PURPOSE (t) && TREE_CODE (TREE_PURPOSE (t)) == TREE_VEC) { -- cgit v1.1 From 3f207ab314c071c6060c7c9a429fcf29fd87b594 Mon Sep 17 00:00:00 2001 From: Trevor Saunders Date: Fri, 11 Jun 2021 23:49:22 -0400 Subject: use range based for loops to iterate over vec<> This changes users of FOR_EACH_VEC_ELT to use range based for loops, where the index variables are otherwise unused. As such the index variables are all deleted, producing shorter and simpler code. Signed-off-by: Trevor Saunders gcc/analyzer/ChangeLog: * call-string.cc (call_string::call_string): Use range based for to iterate over vec<>. (call_string::to_json): Likewise. (call_string::hash): Likewise. (call_string::calc_recursion_depth): Likewise. * checker-path.cc (checker_path::fixup_locations): Likewise. * constraint-manager.cc (equiv_class::equiv_class): Likewise. (equiv_class::to_json): Likewise. (equiv_class::hash): Likewise. (constraint_manager::to_json): Likewise. * engine.cc (impl_region_model_context::on_svalue_leak): Likewise. (on_liveness_change): Likewise. (impl_region_model_context::on_unknown_change): Likewise. * program-state.cc (sm_state_map::set_state): Likewise. * region-model.cc (test_canonicalization_4): Likewise. gcc/ChangeLog: * attribs.c (find_attribute_namespace): Iterate over vec<> with range based for. * auto-profile.c (afdo_find_equiv_class): Likewise. * gcc.c (do_specs_vec): Likewise. (do_spec_1): Likewise. (driver::set_up_specs): Likewise. * gimple-loop-jam.c (any_access_function_variant_p): Likewise. * gimple-ssa-store-merging.c (compatible_load_p): Likewise. (imm_store_chain_info::try_coalesce_bswap): Likewise. (imm_store_chain_info::coalesce_immediate_stores): Likewise. (get_location_for_stmts): Likewise. * graphite-poly.c (print_iteration_domains): Likewise. (free_poly_bb): Likewise. (remove_gbbs_in_scop): Likewise. (free_scop): Likewise. (dump_gbb_cases): Likewise. (dump_gbb_conditions): Likewise. (print_pdrs): Likewise. (print_scop): Likewise. * ifcvt.c (cond_move_process_if_block): Likewise. * lower-subreg.c (decompose_multiword_subregs): Likewise. * regcprop.c (pass_cprop_hardreg::execute): Likewise. * sanopt.c (sanitize_rewrite_addressable_params): Likewise. * sel-sched-dump.c (dump_insn_vector): Likewise. * store-motion.c (store_ops_ok): Likewise. (store_killed_in_insn): Likewise. * timevar.c (timer::named_items::print): Likewise. * tree-cfgcleanup.c (cleanup_control_flow_pre): Likewise. (cleanup_tree_cfg_noloop): Likewise. * tree-data-ref.c (dump_data_references): Likewise. (print_dir_vectors): Likewise. (print_dist_vectors): Likewise. (dump_data_dependence_relations): Likewise. (dump_dist_dir_vectors): Likewise. (dump_ddrs): Likewise. (create_runtime_alias_checks): Likewise. (free_subscripts): Likewise. (save_dist_v): Likewise. (save_dir_v): Likewise. (invariant_access_functions): Likewise. (same_access_functions): Likewise. (access_functions_are_affine_or_constant_p): Likewise. (find_data_references_in_stmt): Likewise. (graphite_find_data_references_in_stmt): Likewise. (free_dependence_relations): Likewise. (free_data_refs): Likewise. * tree-inline.c (copy_debug_stmts): Likewise. * tree-into-ssa.c (dump_currdefs): Likewise. (rewrite_update_phi_arguments): Likewise. * tree-ssa-propagate.c (clean_up_loop_closed_phi): Likewise. * tree-vect-data-refs.c (vect_analyze_possibly_independent_ddr): Likewise. (vect_slp_analyze_node_dependences): Likewise. (vect_slp_analyze_instance_dependence): Likewise. (vect_record_base_alignments): Likewise. (vect_get_peeling_costs_all_drs): Likewise. (vect_peeling_supportable): Likewise. * tree-vectorizer.c (vec_info::~vec_info): Likewise. (vec_info::free_stmt_vec_infos): Likewise. gcc/cp/ChangeLog: * constexpr.c (cxx_eval_call_expression): Iterate over vec<> with range based for. (cxx_eval_store_expression): Likewise. (cxx_eval_loop_expr): Likewise. * decl.c (wrapup_namespace_globals): Likewise. (cp_finish_decl): Likewise. (cxx_simulate_enum_decl): Likewise. * parser.c (cp_parser_postfix_expression): Likewise. --- gcc/tree-inline.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'gcc/tree-inline.c') diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index 9eb08d2..4a0dc3b 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -3260,13 +3260,10 @@ copy_debug_stmt (gdebug *stmt, copy_body_data *id) static void copy_debug_stmts (copy_body_data *id) { - size_t i; - gdebug *stmt; - if (!id->debug_stmts.exists ()) return; - FOR_EACH_VEC_ELT (id->debug_stmts, i, stmt) + for (gdebug *stmt : id->debug_stmts) copy_debug_stmt (stmt, id); id->debug_stmts.release (); -- cgit v1.1 From 53330b7d6848209d658c02be76c36aa5475a88c9 Mon Sep 17 00:00:00 2001 From: Martin Jambor Date: Wed, 23 Jun 2021 18:46:04 +0200 Subject: tree-inline: Fix TREE_READONLY of parameter replacements tree-inline leaves behind VAR_DECLs which are TREE_READONLY (because they are copies of const parameters) but are written to because they need to be initialized. This patch resets the flag unconditionally so that this does not happen. There are other sources of variables which are incorrectly marked as TREE_READOLY, but with this patch and a verifier catching them I can at least compile the Ada run-time library. gcc/ChangeLog: 2021-06-22 Richard Biener Martin Jambor * tree-inline.c (setup_one_parameter): Set TREE_READONLY of the param replacement unconditionally. Adjust comment. --- gcc/tree-inline.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'gcc/tree-inline.c') diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index 4a0dc3b..c5f6ba5 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -3491,17 +3491,11 @@ setup_one_parameter (copy_body_data *id, tree p, tree value, tree fn, automatically replaced by the VAR_DECL. */ insert_decl_map (id, p, var); - /* Even if P was TREE_READONLY, the new VAR should not be. - In the original code, we would have constructed a - temporary, and then the function body would have never - changed the value of P. However, now, we will be - constructing VAR directly. The constructor body may - change its value multiple times as it is being - constructed. Therefore, it must not be TREE_READONLY; - the back-end assumes that TREE_READONLY variable is - assigned to only once. */ - if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (p))) - TREE_READONLY (var) = 0; + /* Even if P was TREE_READONLY, the new VAR should not be. In the original + code, we would have constructed a temporary, and then the function body + would have never changed the value of P. However, now, we will be + constructing VAR directly. Therefore, it must not be TREE_READONLY. */ + TREE_READONLY (var) = 0; tree rhs = value; if (value -- cgit v1.1 From e9e2bad7251477db92ab9ebcdc010f9282dd9890 Mon Sep 17 00:00:00 2001 From: Martin Sebor Date: Thu, 24 Jun 2021 19:22:06 -0600 Subject: middle-end: add support for per-location warning groups. gcc/ChangeLog: * builtins.c (warn_string_no_nul): Replace uses of TREE_NO_WARNING, gimple_no_warning_p and gimple_set_no_warning with warning_suppressed_p, and suppress_warning. (c_strlen): Same. (maybe_warn_for_bound): Same. (warn_for_access): Same. (check_access): Same. (expand_builtin_strncmp): Same. (fold_builtin_varargs): Same. * calls.c (maybe_warn_nonstring_arg): Same. (maybe_warn_rdwr_sizes): Same. * cfgexpand.c (expand_call_stmt): Same. * cgraphunit.c (check_global_declaration): Same. * fold-const.c (fold_undefer_overflow_warnings): Same. (fold_truth_not_expr): Same. (fold_unary_loc): Same. (fold_checksum_tree): Same. * gimple-array-bounds.cc (array_bounds_checker::check_array_ref): Same. (array_bounds_checker::check_mem_ref): Same. (array_bounds_checker::check_addr_expr): Same. (array_bounds_checker::check_array_bounds): Same. * gimple-expr.c (copy_var_decl): Same. * gimple-fold.c (gimple_fold_builtin_strcpy): Same. (gimple_fold_builtin_strncat): Same. (gimple_fold_builtin_stxcpy_chk): Same. (gimple_fold_builtin_stpcpy): Same. (gimple_fold_builtin_sprintf): Same. (fold_stmt_1): Same. * gimple-ssa-isolate-paths.c (diag_returned_locals): Same. * gimple-ssa-nonnull-compare.c (do_warn_nonnull_compare): Same. * gimple-ssa-sprintf.c (handle_printf_call): Same. * gimple-ssa-store-merging.c (imm_store_chain_info::output_merged_store): Same. * gimple-ssa-warn-restrict.c (maybe_diag_overlap): Same. * gimple-ssa-warn-restrict.h: Adjust declarations. (maybe_diag_access_bounds): Replace uses of TREE_NO_WARNING, gimple_no_warning_p and gimple_set_no_warning with warning_suppressed_p, and suppress_warning. (check_call): Same. (check_bounds_or_overlap): Same. * gimple.c (gimple_build_call_from_tree): Same. * gimplify.c (gimplify_return_expr): Same. (gimplify_cond_expr): Same. (gimplify_modify_expr_complex_part): Same. (gimplify_modify_expr): Same. (gimple_push_cleanup): Same. (gimplify_expr): Same. * omp-expand.c (expand_omp_for_generic): Same. (expand_omp_taskloop_for_outer): Same. * omp-low.c (lower_rec_input_clauses): Same. (lower_lastprivate_clauses): Same. (lower_send_clauses): Same. (lower_omp_target): Same. * tree-cfg.c (pass_warn_function_return::execute): Same. * tree-complex.c (create_one_component_var): Same. * tree-inline.c (remap_gimple_op_r): Same. (copy_tree_body_r): Same. (declare_return_variable): Same. (expand_call_inline): Same. * tree-nested.c (lookup_field_for_decl): Same. * tree-sra.c (create_access_replacement): Same. (generate_subtree_copies): Same. * tree-ssa-ccp.c (pass_post_ipa_warn::execute): Same. * tree-ssa-forwprop.c (combine_cond_expr_cond): Same. * tree-ssa-loop-ch.c (ch_base::copy_headers): Same. * tree-ssa-loop-im.c (execute_sm): Same. * tree-ssa-phiopt.c (cond_store_replacement): Same. * tree-ssa-strlen.c (maybe_warn_overflow): Same. (handle_builtin_strcpy): Same. (maybe_diag_stxncpy_trunc): Same. (handle_builtin_stxncpy_strncat): Same. (handle_builtin_strcat): Same. * tree-ssa-uninit.c (get_no_uninit_warning): Same. (set_no_uninit_warning): Same. (uninit_undefined_value_p): Same. (warn_uninit): Same. (maybe_warn_operand): Same. * tree-vrp.c (compare_values_warnv): Same. * vr-values.c (vr_values::extract_range_for_var_from_comparison_expr): Same. (test_for_singularity): Same. * gimple.h (warning_suppressed_p): New function. (suppress_warning): Same. (copy_no_warning): Same. (gimple_set_block): Call gimple_set_location. (gimple_set_location): Call copy_warning. --- gcc/tree-inline.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'gcc/tree-inline.c') diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index c5f6ba5..9e041ca 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -1116,7 +1116,7 @@ remap_gimple_op_r (tree *tp, int *walk_subtrees, void *data) *tp = fold_build2 (MEM_REF, type, ptr, TREE_OPERAND (*tp, 1)); TREE_THIS_VOLATILE (*tp) = TREE_THIS_VOLATILE (old); TREE_SIDE_EFFECTS (*tp) = TREE_SIDE_EFFECTS (old); - TREE_NO_WARNING (*tp) = TREE_NO_WARNING (old); + copy_warning (*tp, old); if (MR_DEPENDENCE_CLIQUE (old) != 0) { MR_DEPENDENCE_CLIQUE (*tp) @@ -1375,7 +1375,7 @@ copy_tree_body_r (tree *tp, int *walk_subtrees, void *data) *tp = fold_build2 (MEM_REF, type, ptr, TREE_OPERAND (*tp, 1)); TREE_THIS_VOLATILE (*tp) = TREE_THIS_VOLATILE (old); TREE_SIDE_EFFECTS (*tp) = TREE_SIDE_EFFECTS (old); - TREE_NO_WARNING (*tp) = TREE_NO_WARNING (old); + copy_warning (*tp, old); if (MR_DEPENDENCE_CLIQUE (old) != 0) { MR_DEPENDENCE_CLIQUE (*tp) @@ -3769,7 +3769,7 @@ declare_return_variable (copy_body_data *id, tree return_slot, tree modify_dest, /* Do not have the rest of GCC warn about this variable as it should not be visible to the user. */ - TREE_NO_WARNING (var) = 1; + suppress_warning (var /* OPT_Wuninitialized? */); declare_inline_vars (id->block, var); @@ -5027,7 +5027,7 @@ expand_call_inline (basic_block bb, gimple *stmt, copy_body_data *id, initialized. We do not want to issue a warning about that uninitialized variable. */ if (DECL_P (modify_dest)) - TREE_NO_WARNING (modify_dest) = 1; + suppress_warning (modify_dest, OPT_Wuninitialized); if (gimple_call_return_slot_opt_p (call_stmt)) { -- cgit v1.1 From 87467f45e831e8e943efdae8920453741986d355 Mon Sep 17 00:00:00 2001 From: Martin Jambor Date: Mon, 28 Jun 2021 18:20:00 +0200 Subject: ipa-sra: Restructure how cloning and call redirection communicate (PR 93385) I was asked by Richi to split my fix for PR 93385 for easier review into IPA-SRA materialization refactoring and the actual DCE addition. Fortunately it was mostly natural except for a temporary weird condition in ipa_param_body_adjustments::modify_call_stmt. Additionally. In addition to the patch I posted previously, this one also deallocated the newly added summary in toplev::finalize and fixes a mistakenly uninitialized field. This is the first part which basically replaces performed_splits in clone_info and the code which generates it, keeps it up-to-date and consumes it with new edge summaries which are much nicer. It simply contains 1) a mapping from the original argument indices to the actual indices in the call statement as it is now, 2) information needed to identify arguments representing pass-through IPA-SRA splits with which have been added to the call arguments in place of an original argument/reference and 3) a delta to the index where va_args may start - so basically directly all the information that the consumer of performed_splits had to compute and we also do not need the weird dummy declarations. The main disadvantage is that the information has to be created (and kept up-to-date) for all call graph edges associated with the given statement from all clones (including inline clones) of the clone where splitting or removal happened first. But all of this happens during clone materialization so the only effect on WPA memory consumption is the removal of a pointer from clone_info. The statement modification code also has to know the statement from the original function in order to be able to locate the edge summaries which at this point are still keyed to these. However, the code is already quite heavily dependant on how things are structured in tree-inline.c and in order to fix bugs like these it probably has to be. The subsequent patch needs this new information to be able to remove arguments from calls during materialization and communicate this information to the call redirection. gcc/ChangeLog: 2021-05-17 Martin Jambor PR ipa/93385 * symtab-clones.h (clone_info): Removed member param_adjustments. * ipa-param-manipulation.h: Adjust initial comment to reflect how we deal with pass-through splits now. (ipa_param_performed_split): Removed. (ipa_param_adjustments::modify_call): Adjusted parameters. (class ipa_param_body_adjustments): Adjusted parameters of register_replacement, modify_gimple_stmt and modify_call_stmt. (ipa_verify_edge_has_no_modifications): Declare. (ipa_edge_modifications_finalize): Declare. * cgraph.c (cgraph_edge::redirect_call_stmt_to_callee): Remove performed_splits processing, pas only edge to padjs->modify_call, check that call arguments were not modified if they should not have been. * cgraphclones.c (cgraph_node::create_clone): Do not copy performed splits. * ipa-param-manipulation.c (struct pass_through_split_map): New type. (ipa_edge_modification_info): Likewise. (ipa_edge_modification_sum): Likewise. (ipa_edge_modifications): New edge summary. (ipa_verify_edge_has_no_modifications): New function. (transitive_split_p): Removed. (transitive_split_map): Likewise. (init_transitive_splits): Likewise. (ipa_param_adjustments::modify_call): Adjusted to use the new edge summary instead of performed_splits. (ipa_param_body_adjustments::register_replacement): Drop dummy parameter, set base_index of the created ipa_param_body_replacement. (phi_arg_will_live_p): New function. (ipa_param_body_adjustments::common_initialization): Do not create IPA_SRA dummy decls. (simple_tree_swap_info): Removed. (remap_split_decl_to_dummy): Likewise. (record_argument_state_1): New function. (record_argument_state): Likewise. (ipa_param_body_adjustments::modify_call_stmt): New parameter orig_stmt. Do not work with dummy decls, save necessary info about changes to ipa_edge_modifications. (ipa_param_body_adjustments::modify_gimple_stmt): New parameter orig_stmt, pass it to modify_call_stmt. (ipa_param_body_adjustments::modify_cfun_body): Adjust call to modify_gimple_stmt. (ipa_edge_modifications_finalize): New function. * tree-inline.c (remap_gimple_stmt): Pass original statement to modify_gimple_stmt. (copy_phis_for_bb): Do not copy dead PHI nodes. (expand_call_inline): Do not remap performed_splits. (update_clone_info): Likewise. * toplev.c: Include ipa-param-manipulation.h. (toplev::finalize): Call ipa_edge_modifications_finalize. --- gcc/tree-inline.c | 103 +++--------------------------------------------------- 1 file changed, 4 insertions(+), 99 deletions(-) (limited to 'gcc/tree-inline.c') diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index 9e041ca..4f15e57 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -1922,7 +1922,7 @@ remap_gimple_stmt (gimple *stmt, copy_body_data *id) if (id->param_body_adjs) { gimple_seq extra_stmts = NULL; - id->param_body_adjs->modify_gimple_stmt (©, &extra_stmts); + id->param_body_adjs->modify_gimple_stmt (©, &extra_stmts, stmt); if (!gimple_seq_empty_p (extra_stmts)) { memset (&wi, 0, sizeof (wi)); @@ -4730,7 +4730,6 @@ expand_call_inline (basic_block bb, gimple *stmt, copy_body_data *id, use_operand_p use; gimple *simtenter_stmt = NULL; vec *simtvars_save; - clone_info *info; /* The gimplifier uses input_location in too many places, such as internal_get_tmp_var (). */ @@ -5055,40 +5054,6 @@ expand_call_inline (basic_block bb, gimple *stmt, copy_body_data *id, /* Add local vars in this inlined callee to caller. */ add_local_variables (id->src_cfun, cfun, id); - info = clone_info::get (id->src_node); - if (info && info->performed_splits) - { - clone_info *dst_info = clone_info::get_create (id->dst_node); - /* Any calls from the inlined function will be turned into calls from the - function we inline into. We must preserve notes about how to split - parameters such calls should be redirected/updated. */ - unsigned len = vec_safe_length (info->performed_splits); - for (unsigned i = 0; i < len; i++) - { - ipa_param_performed_split ps - = (*info->performed_splits)[i]; - ps.dummy_decl = remap_decl (ps.dummy_decl, id); - vec_safe_push (dst_info->performed_splits, ps); - } - - if (flag_checking) - { - len = vec_safe_length (dst_info->performed_splits); - for (unsigned i = 0; i < len; i++) - { - ipa_param_performed_split *ps1 - = &(*dst_info->performed_splits)[i]; - for (unsigned j = i + 1; j < len; j++) - { - ipa_param_performed_split *ps2 - = &(*dst_info->performed_splits)[j]; - gcc_assert (ps1->dummy_decl != ps2->dummy_decl - || ps1->unit_offset != ps2->unit_offset); - } - } - } - } - if (dump_enabled_p ()) { char buf[128]; @@ -6112,23 +6077,10 @@ tree_versionable_function_p (tree fndecl) static void update_clone_info (copy_body_data * id) { - clone_info *dst_info = clone_info::get (id->dst_node); - vec *cur_performed_splits - = dst_info ? dst_info->performed_splits : NULL; - if (cur_performed_splits) - { - unsigned len = cur_performed_splits->length (); - for (unsigned i = 0; i < len; i++) - { - ipa_param_performed_split *ps = &(*cur_performed_splits)[i]; - ps->dummy_decl = remap_decl (ps->dummy_decl, id); - } - } - - struct cgraph_node *node; - if (!id->dst_node->clones) + struct cgraph_node *this_node = id->dst_node; + if (!this_node->clones) return; - for (node = id->dst_node->clones; node != id->dst_node;) + for (cgraph_node *node = this_node->clones; node != this_node;) { /* First update replace maps to match the new body. */ clone_info *info = clone_info::get (node); @@ -6142,53 +6094,6 @@ update_clone_info (copy_body_data * id) walk_tree (&replace_info->new_tree, copy_tree_body_r, id, NULL); } } - if (info && info->performed_splits) - { - unsigned len = vec_safe_length (info->performed_splits); - for (unsigned i = 0; i < len; i++) - { - ipa_param_performed_split *ps - = &(*info->performed_splits)[i]; - ps->dummy_decl = remap_decl (ps->dummy_decl, id); - } - } - if (unsigned len = vec_safe_length (cur_performed_splits)) - { - /* We do not want to add current performed splits when we are saving - a copy of function body for later during inlining, that would just - duplicate all entries. So let's have a look whether anything - referring to the first dummy_decl is present. */ - if (!info) - info = clone_info::get_create (node); - unsigned dst_len = vec_safe_length (info->performed_splits); - ipa_param_performed_split *first = &(*cur_performed_splits)[0]; - for (unsigned i = 0; i < dst_len; i++) - if ((*info->performed_splits)[i].dummy_decl - == first->dummy_decl) - { - len = 0; - break; - } - - for (unsigned i = 0; i < len; i++) - vec_safe_push (info->performed_splits, - (*cur_performed_splits)[i]); - if (flag_checking) - { - for (unsigned i = 0; i < dst_len; i++) - { - ipa_param_performed_split *ps1 - = &(*info->performed_splits)[i]; - for (unsigned j = i + 1; j < dst_len; j++) - { - ipa_param_performed_split *ps2 - = &(*info->performed_splits)[j]; - gcc_assert (ps1->dummy_decl != ps2->dummy_decl - || ps1->unit_offset != ps2->unit_offset); - } - } - } - } if (node->clones) node = node->clones; -- cgit v1.1 From 2902991a6b61d473f7cb996a2b80eef4a90f8eda Mon Sep 17 00:00:00 2001 From: Martin Jambor Date: Mon, 28 Jun 2021 18:20:00 +0200 Subject: ipa-sra: Introduce a mini-DCE to tree-inline.c (PR 93385) I was asked by Richi to split my fix for PR 93385 for easier review into IPA-SRA materialization refactoring and the actual DCE addition. This is the second part that actually contains the DCE of statements that IPA-SRA should not leave behind because they can have problematic side effects, even if they are useless, so that we do not depend on tree-dce to remove them for correctness. The patch fixes the problem by doing a def-use walk when materializing clones, marking which statements should not be copied and which SSA_NAMEs do not need to be computed because eventually they would be DCEd. We do this on the original function body and tree-inline simply does not copy statements which are "dead." The only complication is removing dead argument calls because that needs to be communicated to callee redirection code using the infrastructure introduced by the previous patch. I added all testcases of the original patch to this one, although some probably test behavior introduced in the previous patch. gcc/ChangeLog: 2021-05-12 Martin Jambor PR ipa/93385 * ipa-param-manipulation.h (class ipa_param_body_adjustments): New members m_dead_stmts and m_dead_ssas. * ipa-param-manipulation.c (ipa_param_body_adjustments::mark_dead_statements): New function. (ipa_param_body_adjustments::common_initialization): Call it on all removed but not split parameters. (ipa_param_body_adjustments::ipa_param_body_adjustments): Initialize new mwmbers. (ipa_param_body_adjustments::modify_call_stmt): Remove arguments that are dead. * tree-inline.c (remap_gimple_stmt): Do not copy dead statements, reset dead debug statements. (copy_phis_for_bb): Do not copy dead PHI nodes. gcc/testsuite/ChangeLog: 2021-03-22 Martin Jambor PR ipa/93385 * gcc.dg/ipa/pr93385.c: New test. * gcc.dg/ipa/ipa-sra-23.c: Likewise. * gcc.dg/ipa/ipa-sra-24.c: Likewise. * g++.dg/ipa/ipa-sra-4.C: Likewise. --- gcc/tree-inline.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'gcc/tree-inline.c') diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index 4f15e57..f605e76 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -1526,6 +1526,11 @@ remap_gimple_stmt (gimple *stmt, copy_body_data *id) : !opt_for_fn (id->dst_fn, flag_var_tracking_assignments))) return NULL; + if (!is_gimple_debug (stmt) + && id->param_body_adjs + && id->param_body_adjs->m_dead_stmts.contains (stmt)) + return NULL; + /* Begin by recognizing trees that we'll completely rewrite for the inlining context. Our output for these trees is completely different from our input (e.g. RETURN_EXPR is deleted and morphs @@ -1790,10 +1795,15 @@ remap_gimple_stmt (gimple *stmt, copy_body_data *id) if (gimple_debug_bind_p (stmt)) { + tree value; + if (id->param_body_adjs + && id->param_body_adjs->m_dead_stmts.contains (stmt)) + value = NULL_TREE; + else + value = gimple_debug_bind_get_value (stmt); gdebug *copy = gimple_build_debug_bind (gimple_debug_bind_get_var (stmt), - gimple_debug_bind_get_value (stmt), - stmt); + value, stmt); if (id->reset_location) gimple_set_location (copy, input_location); id->debug_stmts.safe_push (copy); @@ -2675,7 +2685,9 @@ copy_phis_for_bb (basic_block bb, copy_body_data *id) phi = si.phi (); res = PHI_RESULT (phi); new_res = res; - if (!virtual_operand_p (res)) + if (!virtual_operand_p (res) + && (!id->param_body_adjs + || !id->param_body_adjs->m_dead_stmts.contains (phi))) { walk_tree (&new_res, copy_tree_body_r, id, NULL); if (EDGE_COUNT (new_bb->preds) == 0) -- cgit v1.1 From ce777eaedfdc55850b429f97b2093f2de5da09de Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Fri, 16 Jul 2021 12:02:25 +0200 Subject: Get rid of some gimple_expr_type uses This gets rid of a few gimple_expr_type uses. 2021-07-16 Richard Biener * gimple-fold.c (gimple_fold_stmt_to_constant_1): Use the type of the LHS. (gimple_assign_nonnegative_warnv_p): Likewise. (gimple_call_nonnegative_warnv_p): Likewise. Return false if the call has no LHS. * gimple.c (gimple_could_trap_p_1): Use the type of the LHS. * tree-eh.c (stmt_could_throw_1_p): Likewise. * tree-inline.c (insert_init_stmt): Likewise. * tree-ssa-loop-niter.c (get_val_for): Likewise. * tree-outof-ssa.c (ssa_is_replaceable_p): Use the type of the def. * tree-ssa-sccvn.c (init_vn_nary_op_from_stmt): Take a gassign *. Use the type of the lhs. (vn_nary_op_lookup_stmt): Adjust. (vn_nary_op_insert_stmt): Likewise. --- gcc/tree-inline.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gcc/tree-inline.c') diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index f605e76..8e6cdd3 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -3398,7 +3398,7 @@ insert_init_stmt (copy_body_data *id, basic_block bb, gimple *init_stmt) && gimple_assign_rhs_class (init_stmt) == GIMPLE_UNARY_RHS) { tree rhs = build1 (gimple_assign_rhs_code (init_stmt), - gimple_expr_type (init_stmt), + TREE_TYPE (gimple_assign_lhs (init_stmt)), gimple_assign_rhs1 (init_stmt)); rhs = force_gimple_operand_gsi (&si, rhs, true, NULL_TREE, false, GSI_NEW_STMT); -- cgit v1.1 From d0befed793b94f3f407be44e6f69f81a02f5f073 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Thu, 12 Aug 2021 22:41:17 +0200 Subject: openmp: Add support for OpenMP 5.1 masked construct This construct has been introduced as a replacement for master construct, but unlike that construct is slightly more general, has an optional clause which allows to choose which thread will be the one running the region, it can be some other thread than the master (primary) thread with number 0, or it could be no threads or multiple threads (then of course one needs to be careful about data races). It is way too early to deprecate the master construct though, we don't even have OpenMP 5.0 fully implemented, it has been deprecated in 5.1, will be also in 5.2 and removed in 6.0. But even then it will likely be a good idea to just -Wdeprecated warn about it and still accept it. The patch also contains something I should have done much earlier, for clauses that accept some integral expression where we only care about the value, forces during gimplification that value into either a min invariant (as before), SSA_NAME or a fresh temporary, but never e.g. a user VAR_DECL, so that for those clauses we don't need to worry about adjusting it. 2021-08-12 Jakub Jelinek gcc/ * tree.def (OMP_MASKED): New tree code. * tree-core.h (enum omp_clause_code): Add OMP_CLAUSE_FILTER. * tree.h (OMP_MASKED_BODY, OMP_MASKED_CLAUSES, OMP_MASKED_COMBINED, OMP_CLAUSE_FILTER_EXPR): Define. * tree.c (omp_clause_num_ops): Add OMP_CLAUSE_FILTER entry. (omp_clause_code_name): Likewise. (walk_tree_1): Handle OMP_CLAUSE_FILTER. * tree-nested.c (convert_nonlocal_omp_clauses, convert_local_omp_clauses): Handle OMP_CLAUSE_FILTER. (convert_nonlocal_reference_stmt, convert_local_reference_stmt, convert_gimple_call): Handle GIMPLE_OMP_MASTER. * tree-pretty-print.c (dump_omp_clause): Handle OMP_CLAUSE_FILTER. (dump_generic_node): Handle OMP_MASTER. * gimple.def (GIMPLE_OMP_MASKED): New gimple code. * gimple.c (gimple_build_omp_masked): New function. (gimple_copy): Handle GIMPLE_OMP_MASKED. * gimple.h (gimple_build_omp_masked): Declare. (gimple_has_substatements): Handle GIMPLE_OMP_MASKED. (gimple_omp_masked_clauses, gimple_omp_masked_clauses_ptr, gimple_omp_masked_set_clauses): New inline functions. (CASE_GIMPLE_OMP): Add GIMPLE_OMP_MASKED. * gimple-pretty-print.c (dump_gimple_omp_masked): New function. (pp_gimple_stmt_1): Handle GIMPLE_OMP_MASKED. * gimple-walk.c (walk_gimple_stmt): Likewise. * gimple-low.c (lower_stmt): Likewise. * gimplify.c (is_gimple_stmt): Handle OMP_MASTER. (gimplify_scan_omp_clauses): Handle OMP_CLAUSE_FILTER. For clauses that take one expression rather than decl or constant, force gimplification of that into a SSA_NAME or temporary unless min invariant. (gimplify_adjust_omp_clauses): Handle OMP_CLAUSE_FILTER. (gimplify_expr): Handle OMP_MASKED. * tree-inline.c (remap_gimple_stmt): Handle GIMPLE_OMP_MASKED. (estimate_num_insns): Likewise. * omp-low.c (scan_sharing_clauses): Handle OMP_CLAUSE_FILTER. (check_omp_nesting_restrictions): Handle GIMPLE_OMP_MASKED. Adjust diagnostics for existence of masked construct. (scan_omp_1_stmt, lower_omp_master, lower_omp_1, diagnose_sb_1, diagnose_sb_2): Handle GIMPLE_OMP_MASKED. * omp-expand.c (expand_omp_synch, expand_omp, omp_make_gimple_edges): Likewise. gcc/c-family/ * c-pragma.h (enum pragma_kind): Add PRAGMA_OMP_MASKED. (enum pragma_omp_clause): Add PRAGMA_OMP_CLAUSE_FILTER. * c-pragma.c (omp_pragmas_simd): Add masked construct. * c-common.h (enum c_omp_clause_split): Add C_OMP_CLAUSE_SPLIT_MASKED enumerator. (c_finish_omp_masked): Declare. * c-omp.c (c_finish_omp_masked): New function. (c_omp_split_clauses): Handle combined masked constructs. gcc/c/ * c-parser.c (c_parser_omp_clause_name): Parse filter clause name. (c_parser_omp_clause_filter): New function. (c_parser_omp_all_clauses): Handle PRAGMA_OMP_CLAUSE_FILTER. (OMP_MASKED_CLAUSE_MASK): Define. (c_parser_omp_masked): New function. (c_parser_omp_parallel): Handle parallel masked. (c_parser_omp_construct): Handle PRAGMA_OMP_MASKED. * c-typeck.c (c_finish_omp_clauses): Handle OMP_CLAUSE_FILTER. gcc/cp/ * parser.c (cp_parser_omp_clause_name): Parse filter clause name. (cp_parser_omp_clause_filter): New function. (cp_parser_omp_all_clauses): Handle PRAGMA_OMP_CLAUSE_FILTER. (OMP_MASKED_CLAUSE_MASK): Define. (cp_parser_omp_masked): New function. (cp_parser_omp_parallel): Handle parallel masked. (cp_parser_omp_construct, cp_parser_pragma): Handle PRAGMA_OMP_MASKED. * semantics.c (finish_omp_clauses): Handle OMP_CLAUSE_FILTER. * pt.c (tsubst_omp_clauses): Likewise. (tsubst_expr): Handle OMP_MASKED. gcc/testsuite/ * c-c++-common/gomp/clauses-1.c (bar): Add tests for combined masked constructs with clauses. * c-c++-common/gomp/clauses-5.c (foo): Add testcase for filter clause. * c-c++-common/gomp/clause-dups-1.c (f1): Likewise. * c-c++-common/gomp/masked-1.c: New test. * c-c++-common/gomp/masked-2.c: New test. * c-c++-common/gomp/masked-combined-1.c: New test. * c-c++-common/gomp/masked-combined-2.c: New test. * c-c++-common/goacc/uninit-if-clause.c: Remove xfails. * g++.dg/gomp/block-11.C: New test. * g++.dg/gomp/tpl-masked-1.C: New test. * g++.dg/gomp/attrs-1.C (bar): Add tests for masked construct and combined masked constructs with clauses in attribute syntax. * g++.dg/gomp/attrs-2.C (bar): Likewise. * gcc.dg/gomp/nesting-1.c (f1, f2): Add tests for masked construct nesting. * gfortran.dg/goacc/host_data-tree.f95: Allow also SSA_NAMEs in if clause. * gfortran.dg/goacc/kernels-tree.f95: Likewise. libgomp/ * testsuite/libgomp.c-c++-common/masked-1.c: New test. --- gcc/tree-inline.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'gcc/tree-inline.c') diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index 8e6cdd3..4ba48e0 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -1658,6 +1658,12 @@ remap_gimple_stmt (gimple *stmt, copy_body_data *id) copy = gimple_build_omp_master (s1); break; + case GIMPLE_OMP_MASKED: + s1 = remap_gimple_seq (gimple_omp_body (stmt), id); + copy = gimple_build_omp_masked + (s1, gimple_omp_masked_clauses (stmt)); + break; + case GIMPLE_OMP_TASKGROUP: s1 = remap_gimple_seq (gimple_omp_body (stmt), id); copy = gimple_build_omp_taskgroup @@ -4544,6 +4550,7 @@ estimate_num_insns (gimple *stmt, eni_weights *weights) case GIMPLE_OMP_TASK: case GIMPLE_OMP_CRITICAL: case GIMPLE_OMP_MASTER: + case GIMPLE_OMP_MASKED: case GIMPLE_OMP_TASKGROUP: case GIMPLE_OMP_ORDERED: case GIMPLE_OMP_SCAN: -- cgit v1.1 From e45483c7c4badc4bf2d6ced22360ce1ab172967f Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 17 Aug 2021 09:30:09 +0200 Subject: openmp: Implement OpenMP 5.1 scope construct This patch implements the OpenMP 5.1 scope construct, which is similar to worksharing constructs in many regards, but isn't one of them. The body of the construct is encountered by all threads though, it can be nested in itself or intermixed with taskgroup and worksharing etc. constructs can appear inside of it (but it can't be nested in worksharing etc. constructs). The main purpose of the construct is to allow reductions (normal and task ones) without the need to close the parallel and reopen another one. If it doesn't have task reductions, it can be implemented without any new library support, with nowait it just does the privatizations at the start if any and reductions before the end of the body, with without nowait emits a normal GOMP_barrier{,_cancel} at the end too. For task reductions, we need to ensure only one thread initializes the task reduction library data structures and other threads copy from that, so a new GOMP_scope_start routine is added to the library for that. It acts as if the start of the scope construct is a nowait worksharing construct (that is ok, it can't be nested in other worksharing constructs and all threads need to encounter the start in the same order) which does the task reduction initialization, but as the body can have other scope constructs and/or worksharing constructs, that is all where we use this dummy worksharing construct. With task reductions, the construct must not have nowait and ends with a GOMP_barrier{,_cancel}, followed by task reductions followed by GOMP_workshare_task_reduction_unregister. Only C/C++ FE support is done. 2021-08-17 Jakub Jelinek gcc/ * tree.def (OMP_SCOPE): New tree code. * tree.h (OMP_SCOPE_BODY, OMP_SCOPE_CLAUSES): Define. * tree-nested.c (convert_nonlocal_reference_stmt, convert_local_reference_stmt, convert_gimple_call): Handle GIMPLE_OMP_SCOPE. * tree-pretty-print.c (dump_generic_node): Handle OMP_SCOPE. * gimple.def (GIMPLE_OMP_SCOPE): New gimple code. * gimple.c (gimple_build_omp_scope): New function. (gimple_copy): Handle GIMPLE_OMP_SCOPE. * gimple.h (gimple_build_omp_scope): Declare. (gimple_has_substatements): Handle GIMPLE_OMP_SCOPE. (gimple_omp_scope_clauses, gimple_omp_scope_clauses_ptr, gimple_omp_scope_set_clauses): New inline functions. (CASE_GIMPLE_OMP): Add GIMPLE_OMP_SCOPE. * gimple-pretty-print.c (dump_gimple_omp_scope): New function. (pp_gimple_stmt_1): Handle GIMPLE_OMP_SCOPE. * gimple-walk.c (walk_gimple_stmt): Likewise. * gimple-low.c (lower_stmt): Likewise. * gimplify.c (is_gimple_stmt): Handle OMP_MASTER. (gimplify_scan_omp_clauses): For task reductions, handle OMP_SCOPE like ORT_WORKSHARE constructs. Adjust diagnostics for % allowing task reductions. Reject inscan reductions on scope. (omp_find_stores_stmt): Handle GIMPLE_OMP_SCOPE. (gimplify_omp_workshare, gimplify_expr): Handle OMP_SCOPE. * tree-inline.c (remap_gimple_stmt): Handle GIMPLE_OMP_SCOPE. (estimate_num_insns): Likewise. * omp-low.c (build_outer_var_ref): Look through GIMPLE_OMP_SCOPE contexts if var isn't privatized there. (check_omp_nesting_restrictions): Handle GIMPLE_OMP_SCOPE. (scan_omp_1_stmt): Likewise. (maybe_add_implicit_barrier_cancel): Look through outer scope constructs. (lower_omp_scope): New function. (lower_omp_task_reductions): Handle OMP_SCOPE. (lower_omp_1): Handle GIMPLE_OMP_SCOPE. (diagnose_sb_1, diagnose_sb_2): Likewise. * omp-expand.c (expand_omp_single): Support also GIMPLE_OMP_SCOPE. (expand_omp): Handle GIMPLE_OMP_SCOPE. (omp_make_gimple_edges): Likewise. * omp-builtins.def (BUILT_IN_GOMP_SCOPE_START): New built-in. gcc/c-family/ * c-pragma.h (enum pragma_kind): Add PRAGMA_OMP_SCOPE. * c-pragma.c (omp_pragmas): Add scope construct. * c-omp.c (omp_directives): Uncomment scope directive entry. gcc/c/ * c-parser.c (OMP_SCOPE_CLAUSE_MASK): Define. (c_parser_omp_scope): New function. (c_parser_omp_construct): Handle PRAGMA_OMP_SCOPE. gcc/cp/ * parser.c (OMP_SCOPE_CLAUSE_MASK): Define. (cp_parser_omp_scope): New function. (cp_parser_omp_construct, cp_parser_pragma): Handle PRAGMA_OMP_SCOPE. * pt.c (tsubst_expr): Handle OMP_SCOPE. gcc/testsuite/ * c-c++-common/gomp/nesting-2.c (foo): Add scope and masked construct tests. * c-c++-common/gomp/scan-1.c (f3): Add scope construct test.. * c-c++-common/gomp/cancel-1.c (f2): Add scope and masked construct tests. * c-c++-common/gomp/reduction-task-2.c (bar): Add scope construct test. Adjust diagnostics for the addition of scope. * c-c++-common/gomp/loop-1.c (f5): Add master, masked and scope construct tests. * c-c++-common/gomp/clause-dups-1.c (f1): Add scope construct test. * gcc.dg/gomp/nesting-1.c (f1, f2, f3): Add scope construct tests. * c-c++-common/gomp/scope-1.c: New test. * c-c++-common/gomp/scope-2.c: New test. * g++.dg/gomp/attrs-1.C (bar): Add scope construct tests. * g++.dg/gomp/attrs-2.C (bar): Likewise. * gfortran.dg/gomp/reduction4.f90: Adjust expected diagnostics. * gfortran.dg/gomp/reduction7.f90: Likewise. libgomp/ * Makefile.am (libgomp_la_SOURCES): Add scope.c * Makefile.in: Regenerated. * libgomp_g.h (GOMP_scope_start): Declare. * libgomp.map: Add GOMP_scope_start@@GOMP_5.1. * scope.c: New file. * testsuite/libgomp.c-c++-common/scope-1.c: New test. * testsuite/libgomp.c-c++-common/task-reduction-16.c: New test. --- gcc/tree-inline.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'gcc/tree-inline.c') diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index 4ba48e0..c5d6b1e 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -1664,6 +1664,12 @@ remap_gimple_stmt (gimple *stmt, copy_body_data *id) (s1, gimple_omp_masked_clauses (stmt)); break; + case GIMPLE_OMP_SCOPE: + s1 = remap_gimple_seq (gimple_omp_body (stmt), id); + copy = gimple_build_omp_scope + (s1, gimple_omp_scope_clauses (stmt)); + break; + case GIMPLE_OMP_TASKGROUP: s1 = remap_gimple_seq (gimple_omp_body (stmt), id); copy = gimple_build_omp_taskgroup @@ -4551,6 +4557,7 @@ estimate_num_insns (gimple *stmt, eni_weights *weights) case GIMPLE_OMP_CRITICAL: case GIMPLE_OMP_MASTER: case GIMPLE_OMP_MASKED: + case GIMPLE_OMP_SCOPE: case GIMPLE_OMP_TASKGROUP: case GIMPLE_OMP_ORDERED: case GIMPLE_OMP_SCAN: -- cgit v1.1 From 6bcbf80c6e2bd8a60d88bbcac3d70ffb67f4888f Mon Sep 17 00:00:00 2001 From: Alexandre Oliva Date: Sat, 24 Jul 2021 23:05:33 -0300 Subject: retain debug stmt order when moving to successors We iterate over debug stmts from the last one in new_bb, and we insert them before the first post-label stmt in each dest block, without moving the insertion iterator, so they end up reversed. Moving the insertion iterator fixes this. for gcc/ChangeLog * tree-inline.c (maybe_move_debug_stmts_to_successors): Don't reverse debug stmts. --- gcc/tree-inline.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gcc/tree-inline.c') diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index c5d6b1e..5955ff1 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -2880,7 +2880,7 @@ maybe_move_debug_stmts_to_successors (copy_body_data *id, basic_block new_bb) gimple_set_location (stmt, UNKNOWN_LOCATION); } gsi_remove (&si, false); - gsi_insert_before (&dsi, stmt, GSI_SAME_STMT); + gsi_insert_before (&dsi, stmt, GSI_NEW_STMT); continue; } @@ -2906,7 +2906,7 @@ maybe_move_debug_stmts_to_successors (copy_body_data *id, basic_block new_bb) new_stmt = as_a (gimple_copy (stmt)); else gcc_unreachable (); - gsi_insert_before (&dsi, new_stmt, GSI_SAME_STMT); + gsi_insert_before (&dsi, new_stmt, GSI_NEW_STMT); id->debug_stmts.safe_push (new_stmt); gsi_prev (&ssi); } -- cgit v1.1 From aa49a058081e38c610dfc3fb15aaf294752a627e Mon Sep 17 00:00:00 2001 From: Alexandre Oliva Date: Sat, 28 Aug 2021 00:40:14 -0300 Subject: fix latent bootstrap-debug issue I've hit a bootstrap-debug error involving large subprograms in gcc/ada/sem_ch12.adb. I'm afraid I couldn't narrow it down to a reasonable testcase. thread1 made different decisions about a block containing a builtin_eh_filter call because in one compilation, estimate_num_insns found a cgraph_node for the builtin and could thus get to the is_simple_builtin test, but in the other it didn't. With different insn counts, one stage jump-threaded and the other didn't, and the resulting code diverged quite a bit. The reason the builtin had a cgraph_node in one case but not the other was that modref got a chance to analyze the builtin call when it was the first stmt in the block, and that created the cgraph_node. However, when it was preceded by debug stmts, the loop in analyze_function was cut short after the first debug stmt, because the summary so far was not useful. This patch fixes both issues: skip debug stmts in the analyze_function loop, so as to prevent them from affecting any decisions in the loop, and enable the insn count estimator to get to the is_simple_builtin test when a cgraph_node has not been created for the builtin. for gcc/ChangeLog * ipa-modref.c (analyze_function): Skip debug stmts. * tree-inline.c (estimate_num_insn): Consider builtins even without a cgraph_node. --- gcc/tree-inline.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gcc/tree-inline.c') diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index 5955ff1..5e50e80 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -4436,8 +4436,8 @@ estimate_num_insns (gimple *stmt, eni_weights *weights) /* Do not special case builtins where we see the body. This just confuse inliner. */ struct cgraph_node *node; - if (!(node = cgraph_node::get (decl)) - || node->definition) + if ((node = cgraph_node::get (decl)) + && node->definition) ; /* For buitins that are likely expanded to nothing or inlined do not account operand costs. */ -- cgit v1.1