diff options
author | Jan Hubicka <hubicka@ucw.cz> | 2021-10-11 18:43:26 +0200 |
---|---|---|
committer | Jan Hubicka <hubicka@ucw.cz> | 2021-10-11 18:43:26 +0200 |
commit | 008e7397dad971c03c08fc1b0a4a98fddccaaed8 (patch) | |
tree | 4a2b3b53633c275c20b3acf81a716c79a2cd57db /gcc/ipa-modref.c | |
parent | 0de8c2f8104b74f46e63d0d5d7b9e8fd3f04bb98 (diff) | |
download | gcc-008e7397dad971c03c08fc1b0a4a98fddccaaed8.zip gcc-008e7397dad971c03c08fc1b0a4a98fddccaaed8.tar.gz gcc-008e7397dad971c03c08fc1b0a4a98fddccaaed8.tar.bz2 |
Commonize ipa-pta constraint generation for calls
Commonize the three paths to produce constraints for function call
and makes it more flexible, so we can implement new features more easily. Main
idea is to not special case pure and const since we can now describe all of
pure/const via their EAF flags (implicit_const_eaf_flags and
implicit_pure_eaf_flags) and info on existence of global memory loads/stores in
function which is readily available in the modref tree.
While rewriting the function, I dropped some of optimizations in the way we
generate constraints. Some of them we may want to add back, but I think the
constraint solver should be fast to get rid of them quickly, so it looks like
bit of premature optimization.
We now always produce one additional PTA variable (callescape) for things that
escape into function call and thus can be stored to parameters or global memory
(if modified). This is no longer the same as global escape in case function is
not reading global memory. It is also not same as call use, since we now
understand the fact that interposable functions may use parameter in a way that
is not releavnt for PTA (so we can not optimize out stores initializing the
memory, but we can be safe about fact that pointers stored does not escape).
Compared to previous code we now handle correctly EAF_NOT_RETURNED in all cases
(previously we did so only when all parameters had the flag) and also handle
NOCLOBBER in more cases (since we make difference between global escape and
call escape). Because I commonized code handling args and static chains, we
could now easily extend modref to also track flags for static chain and return
slot which I plan to do next.
Otherwise I put some effort into producing constraints that produce similar
solutions as before (so it is harder to debug differences). For example if
global memory is written one can simply move callescape to escape rather then
making everything escape by its own constraints, but it affects ipa-pta
testcases.
gcc/ChangeLog:
* ipa-modref-tree.h (modref_tree::global_access_p): New member
function.
* ipa-modref.c:
(implicint_const_eaf_flags,implicit_pure_eaf_flags,
ignore_stores_eaf_flags): Move to ipa-modref.h
(remove_useless_eaf_flags): Remove early exit on NOCLOBBER.
(modref_summary::global_memory_read_p): New member function.
(modref_summary::global_memory_written_p): New member function.
* ipa-modref.h (modref_summary::global_memory_read_p,
modref_summary::global_memory_written_p): Declare.
(implicint_const_eaf_flags,implicit_pure_eaf_flags,
ignore_stores_eaf_flags): move here.
* tree-ssa-structalias.c: Include ipa-modref-tree.h, ipa-modref.h
and attr-fnspec.h.
(handle_rhs_call): Rewrite.
(handle_call_arg): New function.
(determine_global_memory_access): New function.
(handle_const_call): Remove
(handle_pure_call): Remove
(find_func_aliases_for_call): Update use of handle_rhs_call.
(compute_points_to_sets): Handle global memory acccesses
selectively
gcc/testsuite/ChangeLog:
* gcc.dg/torture/ssa-pta-fn-1.c: Fix template; add noipa.
* gcc.dg/tree-ssa/pta-callused.c: Fix template.
Diffstat (limited to 'gcc/ipa-modref.c')
-rw-r--r-- | gcc/ipa-modref.c | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/gcc/ipa-modref.c b/gcc/ipa-modref.c index 6d49cc1..0bbec8d 100644 --- a/gcc/ipa-modref.c +++ b/gcc/ipa-modref.c @@ -85,6 +85,7 @@ along with GCC; see the file COPYING3. If not see #include "ssa-iterators.h" #include "stringpool.h" #include "tree-ssanames.h" +#include "attribs.h" namespace { @@ -280,17 +281,6 @@ modref_summary::~modref_summary () ggc_delete (stores); } -/* All flags that are implied by the ECF_CONST functions. */ -const int implicit_const_eaf_flags = EAF_DIRECT | EAF_NOCLOBBER | EAF_NOESCAPE - | EAF_NODIRECTESCAPE | EAF_NOREAD; -/* All flags that are implied by the ECF_PURE function. */ -const int implicit_pure_eaf_flags = EAF_NOCLOBBER | EAF_NOESCAPE - | EAF_NODIRECTESCAPE; -/* All flags implied when we know we can ignore stores (i.e. when handling - call to noreturn). */ -const int ignore_stores_eaf_flags = EAF_DIRECT | EAF_NOCLOBBER | EAF_NOESCAPE - | EAF_NODIRECTESCAPE; - /* Remove all flags from EAF_FLAGS that are implied by ECF_FLAGS and not useful to track. If returns_void is true moreover clear EAF_NOT_RETURNED. */ @@ -305,10 +295,6 @@ remove_useless_eaf_flags (int eaf_flags, int ecf_flags, bool returns_void) eaf_flags &= ~implicit_pure_eaf_flags; else if ((ecf_flags & ECF_NORETURN) || returns_void) eaf_flags &= ~EAF_NOT_RETURNED; - /* Only NOCLOBBER or DIRECT flags alone are not useful (see comments - in tree-ssa-alias.c). Give up earlier. */ - if ((eaf_flags & ~(EAF_DIRECT | EAF_NOCLOBBER)) == 0) - return 0; return eaf_flags; } @@ -345,6 +331,26 @@ modref_summary::useful_p (int ecf_flags, bool check_flags) return stores && !stores->every_base; } +/* Return true if global memory is read + (that is loads summary contains global memory access). */ +bool +modref_summary::global_memory_read_p () +{ + if (!loads) + return true; + return loads->global_access_p (); +} + +/* Return true if global memory is written. */ +bool +modref_summary::global_memory_written_p () +{ + if (!stores) + return true; + return stores->global_access_p (); +} + + /* Single function summary used for LTO. */ typedef modref_tree <tree> modref_records_lto; @@ -2016,7 +2022,8 @@ analyze_function (function *f, bool ipa) DECL_PURE_P (current_function_decl) ? " (pure)" : ""); /* Don't analyze this function if it's compiled with -fno-strict-aliasing. */ - if (!flag_ipa_modref) + if (!flag_ipa_modref + || lookup_attribute ("noipa", DECL_ATTRIBUTES (current_function_decl))) return; /* Compute no-LTO summaries when local optimization is going to happen. */ |