]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Come up with -fipa-reference-addressable flag.
authormarxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 9 Nov 2018 15:04:52 +0000 (15:04 +0000)
committermarxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 9 Nov 2018 15:04:52 +0000 (15:04 +0000)
2018-11-09  Martin Liska  <mliska@suse.cz>

* 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  <mliska@suse.cz>

* gcc.dg/tree-ssa/writeonly-2.c: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@265969 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/cgraph.h
gcc/common.opt
gcc/doc/invoke.texi
gcc/ipa-reference.c
gcc/ipa-visibility.c
gcc/ipa.c
gcc/opts.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/writeonly-2.c [new file with mode: 0644]

index 6bdbaae01923a77f94a03e5ac6608ad9dfc51c3d..6a30303c99bfa2b499985974738f90349db928a1 100644 (file)
@@ -1,3 +1,20 @@
+2018-11-09  Martin Liska  <mliska@suse.cz>
+
+       * 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  <dmalcolm@redhat.com>
 
        * json.cc (selftest::test_writing_literals): Fix comment.
index 021552251c4fe0de87c674a2f50beba5dc79f672..dd1e8fdbe4a3d92c2f21d8d71df685829f9c981d 100644 (file)
@@ -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);
index 99489fbd5538b956fc1511b9805d80b5ee5b645b..cba516e7c6e80a8b5977d412ca37bd9fad4e2754 100644 (file)
@@ -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
index 028a8962fd2daaf3d0a1ae9198e167982aeaf898..e510fefe64b14ee04195a7f03eddf30874734922 100644 (file)
@@ -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
index 43bbdae5d6638df4404ae4611241d8b4804c3f67..6242aef11e690dba976f3693fc834187de40d000 100644 (file)
@@ -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
index 000207fa31b846b389d28a1f70caf0d896716ddb..35de913175381ca9b5e1c6c8f054d989bb93d12a 100644 (file)
@@ -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;
 }
 
index 3b6b5e5c8d4c63bc5a32be142022a9ac8bf8faca..22c21354f7521e6e1346baf682657732bd1894ba 100644 (file)
--- 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)
index f094f5f125187a277eede0a01928cae399febbc0..e21967ba84dde8d1c67aee0742e98d58c9f7ebd4 100644 (file)
@@ -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 },
index 8fa0c47a90b704b6f119303780108bb0e34a8b41..6dd28ffb7e8d4cc6a11692239b0fd0b2fef326ad 100644 (file)
@@ -1,3 +1,7 @@
+2018-11-09  Martin Liska  <mliska@suse.cz>
+
+       * gcc.dg/tree-ssa/writeonly-2.c: New test.
+
 2018-11-09  Jakub Jelinek  <jakub@redhat.com>
 
        * 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 (file)
index 0000000..2272d15
--- /dev/null
@@ -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"} } */