gcc/gcc/tree-eh.h
Martin Jambor 36bbc05db8 Add a fun parameter to three stmt_could_throw... functions
This long patch only does one simple thing, adds an explicit function
parameter to predicates stmt_could_throw_p, stmt_can_throw_external
and stmt_can_throw_internal.

My motivation was ability to use stmt_can_throw_external in IPA
analysis phase without the need to push cfun.  As I have discovered,
we were already doing that in cgraph.c, which this patch avoids as
well.  In the process, I had to add a struct function parameter to
stmt_could_throw_p and decided to also change the interface of
stmt_can_throw_internal just for the sake of some minimal consistency.

In the process I have discovered that calling method
cgraph_node::create_version_clone_with_body (used by ipa-split,
ipa-sra, OMP simd and multiple_target) leads to calls of
stmt_can_throw_external with NULL cfun.  I have worked around this by
making stmt_can_throw_external and stmt_could_throw_p gracefully
accept NULL and just be pessimistic in that case.  The problem with
fixing this in a better way is that struct function for the clone is
created after cloning edges where we attempt to push the yet not
existing cfun, and moving it before would require a bit of surgery in
tree-inline.c.  A slightly hackish but simpler fix might be to
explicitely pass the "old" function to symbol_table::create_edge
because it should be just as good at that moment.  In any event, that
is a topic for another patch.

I believe that currently we incorrectly use cfun in
maybe_clean_eh_stmt_fn and maybe_duplicate_eh_stmt_fn, both in
tree-eh.c, and so I have fixed these cases too.  The bulk of other
changes is just mechanical adding of cfun to all users.

Bootstrapped and tested on x86_64-linux (also with extra NULLing and
restoring cfun to double check it is not used in a place I missed), OK
for trunk?

Thanks,

Martin

2018-10-22  Martin Jambor  <mjambor@suse.cz>

	* tree-eh.h (stmt_could_throw_p): Add function parameter.
	(stmt_can_throw_external): Likewise.
	(stmt_can_throw_internal): Likewise.
	* tree-eh.c (lower_eh_constructs_2): Pass cfun to stmt_could_throw_p.
	(lower_eh_constructs_2): Likewise.
	(stmt_could_throw_p): Add fun parameter, use it instead of cfun.
	(stmt_can_throw_external): Likewise.
	(stmt_can_throw_internal): Likewise.
	(maybe_clean_eh_stmt_fn): Pass cfun to stmt_could_throw_p.
	(maybe_clean_or_replace_eh_stmt): Pass cfun to stmt_could_throw_p.
	(maybe_duplicate_eh_stmt_fn): Pass new_fun to stmt_could_throw_p.
	(maybe_duplicate_eh_stmt): Pass cfun to stmt_could_throw_p.
	(pass_lower_eh_dispatch::execute): Pass cfun to
	stmt_can_throw_external.
	(cleanup_empty_eh): Likewise.
	(verify_eh_edges): Pass cfun to stmt_could_throw_p.
	* cgraph.c (cgraph_edge::set_call_stmt): Pass a function to
	stmt_can_throw_external instead of pushing it to cfun.
	(symbol_table::create_edge): Likewise.
	* gimple-fold.c (fold_builtin_atomic_compare_exchange): Pass cfun to
	stmt_can_throw_internal.
	* gimple-ssa-evrp.c (evrp_dom_walker::before_dom_children): Pass cfun
	to stmt_could_throw_p.
	* gimple-ssa-store-merging.c (handled_load): Pass cfun to
	stmt_can_throw_internal.
	(pass_store_merging::execute): Likewise.
	* gimple-ssa-strength-reduction.c
	(find_candidates_dom_walker::before_dom_children): Pass cfun to
	stmt_could_throw_p.
	* gimplify-me.c (gimple_regimplify_operands): Pass cfun to
	stmt_can_throw_internal.
	* ipa-pure-const.c (check_call): Pass cfun to stmt_could_throw_p and
	to stmt_can_throw_external.
	(check_stmt): Pass cfun to stmt_could_throw_p.
	(check_stmt): Pass cfun to stmt_can_throw_external.
	(pass_nothrow::execute): Likewise.
	* trans-mem.c (expand_call_tm): Pass cfun to stmt_can_throw_internal.
	* tree-cfg.c (is_ctrl_altering_stmt): Pass cfun to
	stmt_can_throw_internal.
	(verify_gimple_in_cfg): Pass cfun to stmt_could_throw_p.
	(stmt_can_terminate_bb_p): Pass cfun to stmt_can_throw_external.
	(gimple_purge_dead_eh_edges): Pass cfun to stmt_can_throw_internal.
	* tree-complex.c (expand_complex_libcall): Pass cfun to
	stmt_could_throw_p and to stmt_can_throw_internal.
	(expand_complex_multiplication): Pass cfun to stmt_can_throw_internal.
	* tree-inline.c (copy_edges_for_bb): Likewise.
	(maybe_move_debug_stmts_to_successors): Likewise.
	* tree-outof-ssa.c (ssa_is_replaceable_p): Pass cfun to
	stmt_could_throw_p.
	* tree-parloops.c (oacc_entry_exit_ok_1): Likewise.
	* tree-sra.c (scan_function): Pass cfun to stmt_can_throw_external.
	* tree-ssa-alias.c (stmt_kills_ref_p): Pass cfun to
	stmt_can_throw_internal.
	* tree-ssa-ccp.c (optimize_atomic_bit_test_and): Likewise.
	* tree-ssa-dce.c (mark_stmt_if_obviously_necessary): Pass cfun to
	stmt_could_throw_p.
	(mark_aliased_reaching_defs_necessary_1): Pass cfun to
	stmt_can_throw_internal.
	* tree-ssa-forwprop.c (pass_forwprop::execute): Likewise.
	* tree-ssa-loop-im.c (movement_possibility): Pass cfun to
	stmt_could_throw_p.
	* tree-ssa-loop-ivopts.c (find_givs_in_stmt_scev): Likewise.
	(add_autoinc_candidates): Pass cfun to stmt_can_throw_internal.
	* tree-ssa-math-opts.c (pass_cse_reciprocals::execute): Likewise.
	(convert_mult_to_fma_1): Likewise.
	(convert_to_divmod): Likewise.
	* tree-ssa-phiprop.c (propagate_with_phi): Likewise.
	* tree-ssa-pre.c (compute_avail): Pass cfun to stmt_could_throw_p.
	* tree-ssa-propagate.c
	(substitute_and_fold_dom_walker::before_dom_children): Likewise.
	* tree-ssa-reassoc.c (suitable_cond_bb): Likewise.
	(maybe_optimize_range_tests): Likewise.
	(linearize_expr_tree): Likewise.
	(reassociate_bb): Likewise.
	* tree-ssa-sccvn.c (copy_reference_ops_from_call): Likewise.
	* tree-ssa-scopedtables.c (hashable_expr_equal_p): Likewise.
	* tree-ssa-strlen.c (adjust_last_stmt): Likewise.
	(handle_char_store): Likewise.
	* tree-vect-data-refs.c (vect_find_stmt_data_reference): Pass cfun to
	stmt_can_throw_internal.
	* tree-vect-patterns.c (check_bool_pattern): Pass cfun to
	stmt_could_throw_p.
	* tree-vect-stmts.c (vect_finish_stmt_generation_1): Likewise.
	(vectorizable_call): Pass cfun to stmt_can_throw_internal.
	(vectorizable_simd_clone_call): Likewise.
	* value-prof.c (gimple_ic): Pass cfun to stmt_could_throw_p.
	(gimple_stringop_fixed_value): Likewise.

From-SVN: r265372
2018-10-22 10:27:50 +02:00

56 lines
2.3 KiB
C

/* Header file for exception handling.
Copyright (C) 2013-2018 Free Software Foundation, Inc.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
#ifndef GCC_TREE_EH_H
#define GCC_TREE_EH_H
typedef struct eh_region_d *eh_region;
extern void using_eh_for_cleanups (void);
extern void add_stmt_to_eh_lp (gimple *, int);
extern bool remove_stmt_from_eh_lp_fn (struct function *, gimple *);
extern bool remove_stmt_from_eh_lp (gimple *);
extern int lookup_stmt_eh_lp_fn (struct function *, gimple *);
extern int lookup_stmt_eh_lp (gimple *);
extern bool make_eh_dispatch_edges (geh_dispatch *);
extern void make_eh_edges (gimple *);
extern edge redirect_eh_edge (edge, basic_block);
extern void redirect_eh_dispatch_edge (geh_dispatch *, edge, basic_block);
extern bool operation_could_trap_helper_p (enum tree_code, bool, bool, bool,
bool, tree, bool *);
extern bool operation_could_trap_p (enum tree_code, bool, bool, tree);
extern bool tree_could_trap_p (tree);
extern tree rewrite_to_non_trapping_overflow (tree);
extern bool stmt_could_throw_p (function *, gimple *);
extern bool tree_could_throw_p (tree);
extern bool stmt_can_throw_external (function *, gimple *);
extern bool stmt_can_throw_internal (function *, gimple *);
extern bool maybe_clean_eh_stmt_fn (struct function *, gimple *);
extern bool maybe_clean_eh_stmt (gimple *);
extern bool maybe_clean_or_replace_eh_stmt (gimple *, gimple *);
extern bool maybe_duplicate_eh_stmt_fn (struct function *, gimple *,
struct function *, gimple *,
hash_map<void *, void *> *, int);
extern bool maybe_duplicate_eh_stmt (gimple *, gimple *);
extern void maybe_remove_unreachable_handlers (void);
extern bool verify_eh_edges (gimple *);
extern bool verify_eh_dispatch_edge (geh_dispatch *);
#endif /* GCC_TREE_EH_H */