[07/10] value-relation.h: add 'final' and 'override' to relation_oracle vfunc impls

Message ID 20220523192834.3785673-8-dmalcolm@redhat.com
State Committed
Commit b06b84dbca5a11615da7193d74abfb74beaaf7ac
Headers
Series Add 'final' and 'override' where missing |

Commit Message

David Malcolm May 23, 2022, 7:28 p.m. UTC
  gcc/ChangeLog:
	* value-relation.h: Add "final" and "override" to relation_oracle
	vfunc implementations as appropriate.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
---
 gcc/value-relation.h | 38 +++++++++++++++++++++-----------------
 1 file changed, 21 insertions(+), 17 deletions(-)
  

Comments

David Malcolm June 13, 2022, 6:28 p.m. UTC | #1
Ping re this patch:
  https://gcc.gnu.org/pipermail/gcc-patches/2022-May/595438.html

OK for trunk?

Thanks
Dave


On Mon, 2022-05-23 at 15:28 -0400, David Malcolm wrote:
> gcc/ChangeLog:
>         * value-relation.h: Add "final" and "override" to
> relation_oracle
>         vfunc implementations as appropriate.
> 
> Signed-off-by: David Malcolm <dmalcolm@redhat.com>
> ---
>  gcc/value-relation.h | 38 +++++++++++++++++++++-----------------
>  1 file changed, 21 insertions(+), 17 deletions(-)
> 
> diff --git a/gcc/value-relation.h b/gcc/value-relation.h
> index 19762d8ce2b..478729be0bf 100644
> --- a/gcc/value-relation.h
> +++ b/gcc/value-relation.h
> @@ -130,14 +130,15 @@ public:
>    equiv_oracle ();
>    ~equiv_oracle ();
>  
> -  const_bitmap equiv_set (tree ssa, basic_block bb);
> +  const_bitmap equiv_set (tree ssa, basic_block bb) final override;
>    void register_relation (basic_block bb, relation_kind k, tree ssa1,
> -                         tree ssa2);
> +                         tree ssa2) override;
>  
> -  relation_kind query_relation (basic_block, tree, tree);
> -  relation_kind query_relation (basic_block, const_bitmap,
> const_bitmap);
> -  void dump (FILE *f, basic_block bb) const;
> -  void dump (FILE *f) const;
> +  relation_kind query_relation (basic_block, tree, tree) override;
> +  relation_kind query_relation (basic_block, const_bitmap,
> const_bitmap)
> +    override;
> +  void dump (FILE *f, basic_block bb) const override;
> +  void dump (FILE *f) const override;
>  
>  protected:
>    bitmap_obstack m_bitmaps;
> @@ -185,14 +186,16 @@ public:
>    dom_oracle ();
>    ~dom_oracle ();
>  
> -  void register_relation (basic_block bb, relation_kind k, tree op1,
> tree op2);
> +  void register_relation (basic_block bb, relation_kind k, tree op1,
> tree op2)
> +    final override;
>  
> -  relation_kind query_relation (basic_block bb, tree ssa1, tree ssa2);
> +  relation_kind query_relation (basic_block bb, tree ssa1, tree ssa2)
> +    final override;
>    relation_kind query_relation (basic_block bb, const_bitmap b1,
> -                                  const_bitmap b2);
> +                               const_bitmap b2) final override;
>  
> -  void dump (FILE *f, basic_block bb) const;
> -  void dump (FILE *f) const;
> +  void dump (FILE *f, basic_block bb) const final override;
> +  void dump (FILE *f) const final override;
>  private:
>    bitmap m_tmp, m_tmp2;
>    bitmap m_relation_set;  // Index by ssa-name. True if a relation
> exists
> @@ -229,15 +232,16 @@ class path_oracle : public relation_oracle
>  public:
>    path_oracle (relation_oracle *oracle = NULL);
>    ~path_oracle ();
> -  const_bitmap equiv_set (tree, basic_block);
> -  void register_relation (basic_block, relation_kind, tree, tree);
> +  const_bitmap equiv_set (tree, basic_block) final override;
> +  void register_relation (basic_block, relation_kind, tree, tree)
> final override;
>    void killing_def (tree);
> -  relation_kind query_relation (basic_block, tree, tree);
> -  relation_kind query_relation (basic_block, const_bitmap,
> const_bitmap);
> +  relation_kind query_relation (basic_block, tree, tree) final
> override;
> +  relation_kind query_relation (basic_block, const_bitmap,
> const_bitmap)
> +    final override;
>    void reset_path ();
>    void set_root_oracle (relation_oracle *oracle) { m_root = oracle; }
> -  void dump (FILE *, basic_block) const;
> -  void dump (FILE *) const;
> +  void dump (FILE *, basic_block) const final override;
> +  void dump (FILE *) const final override;
>  private:
>    void register_equiv (basic_block bb, tree ssa1, tree ssa2);
>    equiv_chain m_equiv;
  
Aldy Hernandez June 14, 2022, 12:45 a.m. UTC | #2
Final implies we can't further derive from the derived class, right? If so
we may want just override.

Andrew, what are your thoughts?

Thanks for doing this.

Aldy

On Mon, Jun 13, 2022, 14:28 David Malcolm <dmalcolm@redhat.com> wrote:

> Ping re this patch:
>   https://gcc.gnu.org/pipermail/gcc-patches/2022-May/595438.html
>
> OK for trunk?
>
> Thanks
> Dave
>
>
> On Mon, 2022-05-23 at 15:28 -0400, David Malcolm wrote:
> > gcc/ChangeLog:
> >         * value-relation.h: Add "final" and "override" to
> > relation_oracle
> >         vfunc implementations as appropriate.
> >
> > Signed-off-by: David Malcolm <dmalcolm@redhat.com>
> > ---
> >  gcc/value-relation.h | 38 +++++++++++++++++++++-----------------
> >  1 file changed, 21 insertions(+), 17 deletions(-)
> >
> > diff --git a/gcc/value-relation.h b/gcc/value-relation.h
> > index 19762d8ce2b..478729be0bf 100644
> > --- a/gcc/value-relation.h
> > +++ b/gcc/value-relation.h
> > @@ -130,14 +130,15 @@ public:
> >    equiv_oracle ();
> >    ~equiv_oracle ();
> >
> > -  const_bitmap equiv_set (tree ssa, basic_block bb);
> > +  const_bitmap equiv_set (tree ssa, basic_block bb) final override;
> >    void register_relation (basic_block bb, relation_kind k, tree ssa1,
> > -                         tree ssa2);
> > +                         tree ssa2) override;
> >
> > -  relation_kind query_relation (basic_block, tree, tree);
> > -  relation_kind query_relation (basic_block, const_bitmap,
> > const_bitmap);
> > -  void dump (FILE *f, basic_block bb) const;
> > -  void dump (FILE *f) const;
> > +  relation_kind query_relation (basic_block, tree, tree) override;
> > +  relation_kind query_relation (basic_block, const_bitmap,
> > const_bitmap)
> > +    override;
> > +  void dump (FILE *f, basic_block bb) const override;
> > +  void dump (FILE *f) const override;
> >
> >  protected:
> >    bitmap_obstack m_bitmaps;
> > @@ -185,14 +186,16 @@ public:
> >    dom_oracle ();
> >    ~dom_oracle ();
> >
> > -  void register_relation (basic_block bb, relation_kind k, tree op1,
> > tree op2);
> > +  void register_relation (basic_block bb, relation_kind k, tree op1,
> > tree op2)
> > +    final override;
> >
> > -  relation_kind query_relation (basic_block bb, tree ssa1, tree ssa2);
> > +  relation_kind query_relation (basic_block bb, tree ssa1, tree ssa2)
> > +    final override;
> >    relation_kind query_relation (basic_block bb, const_bitmap b1,
> > -                                  const_bitmap b2);
> > +                               const_bitmap b2) final override;
> >
> > -  void dump (FILE *f, basic_block bb) const;
> > -  void dump (FILE *f) const;
> > +  void dump (FILE *f, basic_block bb) const final override;
> > +  void dump (FILE *f) const final override;
> >  private:
> >    bitmap m_tmp, m_tmp2;
> >    bitmap m_relation_set;  // Index by ssa-name. True if a relation
> > exists
> > @@ -229,15 +232,16 @@ class path_oracle : public relation_oracle
> >  public:
> >    path_oracle (relation_oracle *oracle = NULL);
> >    ~path_oracle ();
> > -  const_bitmap equiv_set (tree, basic_block);
> > -  void register_relation (basic_block, relation_kind, tree, tree);
> > +  const_bitmap equiv_set (tree, basic_block) final override;
> > +  void register_relation (basic_block, relation_kind, tree, tree)
> > final override;
> >    void killing_def (tree);
> > -  relation_kind query_relation (basic_block, tree, tree);
> > -  relation_kind query_relation (basic_block, const_bitmap,
> > const_bitmap);
> > +  relation_kind query_relation (basic_block, tree, tree) final
> > override;
> > +  relation_kind query_relation (basic_block, const_bitmap,
> > const_bitmap)
> > +    final override;
> >    void reset_path ();
> >    void set_root_oracle (relation_oracle *oracle) { m_root = oracle; }
> > -  void dump (FILE *, basic_block) const;
> > -  void dump (FILE *) const;
> > +  void dump (FILE *, basic_block) const final override;
> > +  void dump (FILE *) const final override;
> >  private:
> >    void register_equiv (basic_block bb, tree ssa1, tree ssa2);
> >    equiv_chain m_equiv;
>
>
>
  
David Malcolm June 14, 2022, 1:24 a.m. UTC | #3
On Mon, 2022-06-13 at 20:45 -0400, Aldy Hernandez wrote:
> Final implies we can't further derive from the derived class, right?

"final" on a vfunc implies that nothing overrides that vfunc, but you
could still have further derived classes.

You can think of it as "nothing further overrides this vfunc", as both
a hint to the human reader, and an optimization hint to the compiler.  

You can always just remove the "final" if you want to override it in
the future (unless the override is happening in a plugin, I suppose).

> If so
> we may want just override.

"override" is indeed probably more useful, in that it documents to
compilers and human readers that you intend this to override a vfunc.

FWIW I wrote the patch by using both "final" and "override", and then
dropping the "final" everywhere I needed to to get it to compile.

Dave


> 
> Andrew, what are your thoughts?
> 
> Thanks for doing this.
> 
> Aldy
> 
> On Mon, Jun 13, 2022, 14:28 David Malcolm <dmalcolm@redhat.com> wrote:
> 
> > Ping re this patch:
> >   https://gcc.gnu.org/pipermail/gcc-patches/2022-May/595438.html
> > 
> > OK for trunk?
> > 
> > Thanks
> > Dave
> > 
> > 
> > On Mon, 2022-05-23 at 15:28 -0400, David Malcolm wrote:
> > > gcc/ChangeLog:
> > >         * value-relation.h: Add "final" and "override" to
> > > relation_oracle
> > >         vfunc implementations as appropriate.
> > > 
> > > Signed-off-by: David Malcolm <dmalcolm@redhat.com>
> > > ---
> > >  gcc/value-relation.h | 38 +++++++++++++++++++++-----------------
> > >  1 file changed, 21 insertions(+), 17 deletions(-)
> > > 
> > > diff --git a/gcc/value-relation.h b/gcc/value-relation.h
> > > index 19762d8ce2b..478729be0bf 100644
> > > --- a/gcc/value-relation.h
> > > +++ b/gcc/value-relation.h
> > > @@ -130,14 +130,15 @@ public:
> > >    equiv_oracle ();
> > >    ~equiv_oracle ();
> > > 
> > > -  const_bitmap equiv_set (tree ssa, basic_block bb);
> > > +  const_bitmap equiv_set (tree ssa, basic_block bb) final
> > > override;
> > >    void register_relation (basic_block bb, relation_kind k, tree
> > > ssa1,
> > > -                         tree ssa2);
> > > +                         tree ssa2) override;
> > > 
> > > -  relation_kind query_relation (basic_block, tree, tree);
> > > -  relation_kind query_relation (basic_block, const_bitmap,
> > > const_bitmap);
> > > -  void dump (FILE *f, basic_block bb) const;
> > > -  void dump (FILE *f) const;
> > > +  relation_kind query_relation (basic_block, tree, tree) override;
> > > +  relation_kind query_relation (basic_block, const_bitmap,
> > > const_bitmap)
> > > +    override;
> > > +  void dump (FILE *f, basic_block bb) const override;
> > > +  void dump (FILE *f) const override;
> > > 
> > >  protected:
> > >    bitmap_obstack m_bitmaps;
> > > @@ -185,14 +186,16 @@ public:
> > >    dom_oracle ();
> > >    ~dom_oracle ();
> > > 
> > > -  void register_relation (basic_block bb, relation_kind k, tree
> > > op1,
> > > tree op2);
> > > +  void register_relation (basic_block bb, relation_kind k, tree
> > > op1,
> > > tree op2)
> > > +    final override;
> > > 
> > > -  relation_kind query_relation (basic_block bb, tree ssa1, tree
> > > ssa2);
> > > +  relation_kind query_relation (basic_block bb, tree ssa1, tree
> > > ssa2)
> > > +    final override;
> > >    relation_kind query_relation (basic_block bb, const_bitmap b1,
> > > -                                  const_bitmap b2);
> > > +                               const_bitmap b2) final override;
> > > 
> > > -  void dump (FILE *f, basic_block bb) const;
> > > -  void dump (FILE *f) const;
> > > +  void dump (FILE *f, basic_block bb) const final override;
> > > +  void dump (FILE *f) const final override;
> > >  private:
> > >    bitmap m_tmp, m_tmp2;
> > >    bitmap m_relation_set;  // Index by ssa-name. True if a relation
> > > exists
> > > @@ -229,15 +232,16 @@ class path_oracle : public relation_oracle
> > >  public:
> > >    path_oracle (relation_oracle *oracle = NULL);
> > >    ~path_oracle ();
> > > -  const_bitmap equiv_set (tree, basic_block);
> > > -  void register_relation (basic_block, relation_kind, tree, tree);
> > > +  const_bitmap equiv_set (tree, basic_block) final override;
> > > +  void register_relation (basic_block, relation_kind, tree, tree)
> > > final override;
> > >    void killing_def (tree);
> > > -  relation_kind query_relation (basic_block, tree, tree);
> > > -  relation_kind query_relation (basic_block, const_bitmap,
> > > const_bitmap);
> > > +  relation_kind query_relation (basic_block, tree, tree) final
> > > override;
> > > +  relation_kind query_relation (basic_block, const_bitmap,
> > > const_bitmap)
> > > +    final override;
> > >    void reset_path ();
> > >    void set_root_oracle (relation_oracle *oracle) { m_root =
> > > oracle; }
> > > -  void dump (FILE *, basic_block) const;
> > > -  void dump (FILE *) const;
> > > +  void dump (FILE *, basic_block) const final override;
> > > +  void dump (FILE *) const final override;
> > >  private:
> > >    void register_equiv (basic_block bb, tree ssa1, tree ssa2);
> > >    equiv_chain m_equiv;
> > 
> > 
> >
  
Andrew MacLeod June 15, 2022, 1:33 p.m. UTC | #4
On 6/13/22 21:24, David Malcolm wrote:
> On Mon, 2022-06-13 at 20:45 -0400, Aldy Hernandez wrote:
>> Final implies we can't further derive from the derived class, right?
> "final" on a vfunc implies that nothing overrides that vfunc, but you
> could still have further derived classes.
>
> You can think of it as "nothing further overrides this vfunc", as both
> a hint to the human reader, and an optimization hint to the compiler.
>
> You can always just remove the "final" if you want to override it in
> the future (unless the override is happening in a plugin, I suppose).
>
>> If so
>> we may want just override.
> "override" is indeed probably more useful, in that it documents to
> compilers and human readers that you intend this to override a vfunc.
>
> FWIW I wrote the patch by using both "final" and "override", and then
> dropping the "final" everywhere I needed to to get it to compile.
>
> Dave
>
>
>> Andrew, what are your thoughts?
>>
>> Thanks for doing this.

OK by me.

Andrew
  
David Malcolm June 15, 2022, 9:58 p.m. UTC | #5
On Wed, 2022-06-15 at 09:33 -0400, Andrew MacLeod wrote:
> On 6/13/22 21:24, David Malcolm wrote:
> > On Mon, 2022-06-13 at 20:45 -0400, Aldy Hernandez wrote:
> > > Final implies we can't further derive from the derived class,
> > > right?
> > "final" on a vfunc implies that nothing overrides that vfunc, but you
> > could still have further derived classes.
> > 
> > You can think of it as "nothing further overrides this vfunc", as
> > both
> > a hint to the human reader, and an optimization hint to the compiler.
> > 
> > You can always just remove the "final" if you want to override it in
> > the future (unless the override is happening in a plugin, I suppose).
> > 
> > > If so
> > > we may want just override.
> > "override" is indeed probably more useful, in that it documents to
> > compilers and human readers that you intend this to override a vfunc.
> > 
> > FWIW I wrote the patch by using both "final" and "override", and then
> > dropping the "final" everywhere I needed to to get it to compile.
> > 
> > Dave
> > 
> > 
> > > Andrew, what are your thoughts?
> > > 
> > > Thanks for doing this.
> 
> OK by me.

Thanks; I've pushed this to trunk as r13-1118-gb06b84dbca5a11, after
retesting (bootstrapped & regrtested again on x86_64-pc-linux-gnu).

FWIW, as noted in 
  https://gcc.gnu.org/pipermail/gcc-patches/2022-May/595437.html
I tried hacking in -Werror=suggest-override to the Makefile, and there
were a bunch of places that it suggested could use "override" in
gcc/range.op.cc, but I decided not to touch that, because it seems to
be under heavy development by you (and also, frankly, out of laziness
on my part).  So maybe you might want to look at adding those at some
point, to avoid snafus where you meant to override something, but got
the signature slightly wrong, etc.

Dave
  

Patch

diff --git a/gcc/value-relation.h b/gcc/value-relation.h
index 19762d8ce2b..478729be0bf 100644
--- a/gcc/value-relation.h
+++ b/gcc/value-relation.h
@@ -130,14 +130,15 @@  public:
   equiv_oracle ();
   ~equiv_oracle ();
 
-  const_bitmap equiv_set (tree ssa, basic_block bb);
+  const_bitmap equiv_set (tree ssa, basic_block bb) final override;
   void register_relation (basic_block bb, relation_kind k, tree ssa1,
-			  tree ssa2);
+			  tree ssa2) override;
 
-  relation_kind query_relation (basic_block, tree, tree);
-  relation_kind query_relation (basic_block, const_bitmap, const_bitmap);
-  void dump (FILE *f, basic_block bb) const;
-  void dump (FILE *f) const;
+  relation_kind query_relation (basic_block, tree, tree) override;
+  relation_kind query_relation (basic_block, const_bitmap, const_bitmap)
+    override;
+  void dump (FILE *f, basic_block bb) const override;
+  void dump (FILE *f) const override;
 
 protected:
   bitmap_obstack m_bitmaps;
@@ -185,14 +186,16 @@  public:
   dom_oracle ();
   ~dom_oracle ();
 
-  void register_relation (basic_block bb, relation_kind k, tree op1, tree op2);
+  void register_relation (basic_block bb, relation_kind k, tree op1, tree op2)
+    final override;
 
-  relation_kind query_relation (basic_block bb, tree ssa1, tree ssa2);
+  relation_kind query_relation (basic_block bb, tree ssa1, tree ssa2)
+    final override;
   relation_kind query_relation (basic_block bb, const_bitmap b1,
-				   const_bitmap b2);
+				const_bitmap b2) final override;
 
-  void dump (FILE *f, basic_block bb) const;
-  void dump (FILE *f) const;
+  void dump (FILE *f, basic_block bb) const final override;
+  void dump (FILE *f) const final override;
 private:
   bitmap m_tmp, m_tmp2;
   bitmap m_relation_set;  // Index by ssa-name. True if a relation exists
@@ -229,15 +232,16 @@  class path_oracle : public relation_oracle
 public:
   path_oracle (relation_oracle *oracle = NULL);
   ~path_oracle ();
-  const_bitmap equiv_set (tree, basic_block);
-  void register_relation (basic_block, relation_kind, tree, tree);
+  const_bitmap equiv_set (tree, basic_block) final override;
+  void register_relation (basic_block, relation_kind, tree, tree) final override;
   void killing_def (tree);
-  relation_kind query_relation (basic_block, tree, tree);
-  relation_kind query_relation (basic_block, const_bitmap, const_bitmap);
+  relation_kind query_relation (basic_block, tree, tree) final override;
+  relation_kind query_relation (basic_block, const_bitmap, const_bitmap)
+    final override;
   void reset_path ();
   void set_root_oracle (relation_oracle *oracle) { m_root = oracle; }
-  void dump (FILE *, basic_block) const;
-  void dump (FILE *) const;
+  void dump (FILE *, basic_block) const final override;
+  void dump (FILE *) const final override;
 private:
   void register_equiv (basic_block bb, tree ssa1, tree ssa2);
   equiv_chain m_equiv;