From: Martin Liska Date: Fri, 9 Nov 2018 15:04:52 +0000 (+0100) Subject: Come up with -fipa-reference-addressable flag. X-Git-Tag: basepoints/gcc-10~3187 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2e14744fcd7820033b91c9516e22eb42b02b5290;p=thirdparty%2Fgcc.git Come up with -fipa-reference-addressable flag. 2018-11-09 Martin Liska * cgraph.h (ipa_discover_readonly_nonaddressable_vars): Rename to ... (ipa_discover_variable_flags): ... this. * common.opt: Come up with new flag -fipa-reference-addressable. * doc/invoke.texi: Document it. * ipa-reference.c (propagate): Call the renamed fn. * ipa-visibility.c (whole_program_function_and_variable_visibility): Likewise. * ipa.c (ipa_discover_readonly_nonaddressable_vars): Renamed to ... (ipa_discover_variable_flags): ... this. Discover non-addressable variables only with the newly added flag. * opts.c: Enable the newly added flag with -O1 and higher optimization level. 2018-11-09 Martin Liska * gcc.dg/tree-ssa/writeonly-2.c: New test. From-SVN: r265969 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 6bdbaae01923..6a30303c99bf 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,20 @@ +2018-11-09 Martin Liska + + * cgraph.h (ipa_discover_readonly_nonaddressable_vars): Rename + to ... + (ipa_discover_variable_flags): ... this. + * common.opt: Come up with new flag -fipa-reference-addressable. + * doc/invoke.texi: Document it. + * ipa-reference.c (propagate): Call the renamed fn. + * ipa-visibility.c (whole_program_function_and_variable_visibility): + Likewise. + * ipa.c (ipa_discover_readonly_nonaddressable_vars): Renamed to + ... + (ipa_discover_variable_flags): ... this. Discover + non-addressable variables only with the newly added flag. + * opts.c: Enable the newly added flag with -O1 and higher + optimization level. + 2018-11-09 David Malcolm * json.cc (selftest::test_writing_literals): Fix comment. diff --git a/gcc/cgraph.h b/gcc/cgraph.h index 021552251c4f..dd1e8fdbe4a3 100644 --- a/gcc/cgraph.h +++ b/gcc/cgraph.h @@ -2403,7 +2403,7 @@ void record_references_in_initializer (tree, bool); /* In ipa.c */ void cgraph_build_static_cdtor (char which, tree body, int priority); -bool ipa_discover_readonly_nonaddressable_vars (void); +bool ipa_discover_variable_flags (void); /* In varpool.c */ tree ctor_for_folding (tree); diff --git a/gcc/common.opt b/gcc/common.opt index 99489fbd5538..cba516e7c6e8 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -1722,7 +1722,11 @@ Perform Identical Code Folding for variables. fipa-reference Common Report Var(flag_ipa_reference) Init(0) Optimization -Discover readonly and non addressable static variables. +Discover read-only and non addressable static variables. + +fipa-reference-addressable +Common Report Var(flag_ipa_reference_addressable) Init(0) Optimization +Discover read-only, write-only and non-addressable static variables. fipa-matrix-reorg Common Ignore diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 028a8962fd2d..e510fefe64b1 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -413,8 +413,8 @@ Objective-C and Objective-C++ Dialects}. -finline-functions -finline-functions-called-once -finline-limit=@var{n} @gol -finline-small-functions -fipa-cp -fipa-cp-clone @gol -fipa-bit-cp -fipa-vrp @gol --fipa-pta -fipa-profile -fipa-pure-const -fipa-reference -fipa-icf @gol --fira-algorithm=@var{algorithm} @gol +-fipa-pta -fipa-profile -fipa-pure-const -fipa-reference -fipa-reference-addressable @gol +-fipa-icf -fira-algorithm=@var{algorithm} @gol -fira-region=@var{region} -fira-hoist-pressure @gol -fira-loop-pressure -fno-ira-share-save-slots @gol -fno-ira-share-spill-slots @gol @@ -7882,6 +7882,7 @@ compilation time. -fipa-pure-const @gol -fipa-profile @gol -fipa-reference @gol +-fipa-reference-addressable @gol -fmerge-constants @gol -fmove-loop-invariants @gol -fomit-frame-pointer @gol @@ -8911,6 +8912,11 @@ Discover which static variables do not escape the compilation unit. Enabled by default at @option{-O} and higher. +@item -fipa-reference-addressable +@opindex fipa-reference-addressable +Discover read-only, write-only and non-addressable static variables. +Enabled by default at @option{-O} and higher. + @item -fipa-pta @opindex fipa-pta Perform interprocedural pointer analysis and interprocedural modification diff --git a/gcc/ipa-reference.c b/gcc/ipa-reference.c index 43bbdae5d663..6242aef11e69 100644 --- a/gcc/ipa-reference.c +++ b/gcc/ipa-reference.c @@ -705,7 +705,7 @@ propagate (void) if (dump_file) cgraph_node::dump_cgraph (dump_file); - remove_p = ipa_discover_readonly_nonaddressable_vars (); + remove_p = ipa_discover_variable_flags (); generate_summary (); /* Propagate the local information through the call graph to produce diff --git a/gcc/ipa-visibility.c b/gcc/ipa-visibility.c index 000207fa31b8..35de91317538 100644 --- a/gcc/ipa-visibility.c +++ b/gcc/ipa-visibility.c @@ -911,7 +911,7 @@ whole_program_function_and_variable_visibility (void) { function_and_variable_visibility (flag_whole_program); if (optimize || in_lto_p) - ipa_discover_readonly_nonaddressable_vars (); + ipa_discover_variable_flags (); return 0; } diff --git a/gcc/ipa.c b/gcc/ipa.c index 3b6b5e5c8d4c..22c21354f752 100644 --- a/gcc/ipa.c +++ b/gcc/ipa.c @@ -752,10 +752,10 @@ clear_addressable_bit (varpool_node *vnode, void *data ATTRIBUTE_UNUSED) return false; } -/* Discover variables that have no longer address taken or that are read only - and update their flags. +/* Discover variables that have no longer address taken, are read-only or + write-only and update their flags. - Return true when unreachable symbol removan should be done. + Return true when unreachable symbol removal should be done. FIXME: This can not be done in between gimplify and omp_expand since readonly flag plays role on what is shared and what is not. Currently we do @@ -764,8 +764,11 @@ clear_addressable_bit (varpool_node *vnode, void *data ATTRIBUTE_UNUSED) make sense to do it before early optimizations. */ bool -ipa_discover_readonly_nonaddressable_vars (void) +ipa_discover_variable_flags (void) { + if (!flag_ipa_reference_addressable) + return false; + bool remove_p = false; varpool_node *vnode; if (dump_file) diff --git a/gcc/opts.c b/gcc/opts.c index f094f5f12518..e21967ba84dd 100644 --- a/gcc/opts.c +++ b/gcc/opts.c @@ -451,6 +451,7 @@ static const struct default_options default_options_table[] = { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fif_conversion2, NULL, 1 }, { OPT_LEVELS_1_PLUS, OPT_fipa_pure_const, NULL, 1 }, { OPT_LEVELS_1_PLUS, OPT_fipa_reference, NULL, 1 }, + { OPT_LEVELS_1_PLUS, OPT_fipa_reference_addressable, NULL, 1 }, { OPT_LEVELS_1_PLUS, OPT_fipa_profile, NULL, 1 }, { OPT_LEVELS_1_PLUS, OPT_fmerge_constants, NULL, 1 }, { OPT_LEVELS_1_PLUS, OPT_freorder_blocks, NULL, 1 }, diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8fa0c47a90b7..6dd28ffb7e8d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2018-11-09 Martin Liska + + * gcc.dg/tree-ssa/writeonly-2.c: New test. + 2018-11-09 Jakub Jelinek * gcc.dg/gomp/workshare-reduction-1.c: New test. diff --git a/gcc/testsuite/gcc.dg/tree-ssa/writeonly-2.c b/gcc/testsuite/gcc.dg/tree-ssa/writeonly-2.c new file mode 100644 index 000000000000..2272d15b171d --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/writeonly-2.c @@ -0,0 +1,20 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -fdump-tree-optimized -fno-ipa-reference-addressable" } */ +static struct a {int magic1,b;} a; +volatile int magic2; +static struct b {int a,b,c,d,e,f;} magic3; + +struct b foo(); + +void +t() +{ + a.magic1 = 1; + magic2 = 1; + magic3 = foo(); +} +/* { dg-final { scan-tree-dump "magic1" "optimized"} } */ +/* { dg-final { scan-tree-dump "magic3" "optimized"} } */ +/* { dg-final { scan-tree-dump "magic2" "optimized"} } */ +/* { dg-final { scan-tree-dump "foo" "optimized"} } */ +