Patchwork [C++] Move FINAL flag to middle-end trees.

login
register
mail settings
Submitter Jan Hubicka
Date Aug. 25, 2013, 3:38 p.m.
Message ID <20130825153809.GC9318@atrey.karlin.mff.cuni.cz>
Download mbox | patch
Permalink /patch/269708/
State New
Headers show

Comments

Jan Hubicka - Aug. 25, 2013, 3:38 p.m.
> On 08/24/2013 05:18 AM, Jan Hubicka wrote:
> >In the next step I would like to introduce the DECL_CPP_CONSTRUCTOR/DESTRUCTOR macro.
> >The catch I run into is that these flags are tested on TEMPLATE_DECL so the middle-end
> >macro bombs on type checking.  I wonder what is best approach here.
> 
> I think fix the front end to use STRIP_TEMPLATE to make sure we're
> checking/setting the flag on a FUNCTION_DECL.

Thank you!
I did not know the FUNCTION_DECLs are already there.  The following patch seems
to work.  Of course if it seems cleaner, I can update the users of the CPP
macros into the expanded variants.  I want to have CPP in name in middle-end to
signify that we actually understand language specific properties of these
functions (so constructors/destructors in other languages probably don't
want to do that).

Bootstrapped/regtested ppc64-linux, OK?

	* tree.h (tree_decl_with_vis): Add cpp_constructor and cpp_destructor.
	(DECL_CPP_CONSTRUCTOR_P, DECL_CPP_DESTRUCTOR_P): New macros.

	* cp-tree.h (DECL_CONSTRUCTOR_P, DECL_DESTRUCTOR_P): Change to
	strip templates and set the middle-end flag.
Gabriel Dos Reis - Aug. 25, 2013, 3:43 p.m.
On Sun, Aug 25, 2013 at 10:38 AM, Jan Hubicka <hubicka@ucw.cz> wrote:
>> On 08/24/2013 05:18 AM, Jan Hubicka wrote:
>> >In the next step I would like to introduce the DECL_CPP_CONSTRUCTOR/DESTRUCTOR macro.
>> >The catch I run into is that these flags are tested on TEMPLATE_DECL so the middle-end
>> >macro bombs on type checking.  I wonder what is best approach here.
>>
>> I think fix the front end to use STRIP_TEMPLATE to make sure we're
>> checking/setting the flag on a FUNCTION_DECL.
>
> Thank you!
> I did not know the FUNCTION_DECLs are already there.  The following patch seems
> to work.  Of course if it seems cleaner, I can update the users of the CPP
> macros into the expanded variants.  I want to have CPP in name in middle-end to
> signify that we actually understand language specific properties of these
> functions (so constructors/destructors in other languages probably don't
> want to do that).
>
> Bootstrapped/regtested ppc64-linux, OK?
>
>         * tree.h (tree_decl_with_vis): Add cpp_constructor and cpp_destructor.
>         (DECL_CPP_CONSTRUCTOR_P, DECL_CPP_DESTRUCTOR_P): New macros.
>
>         * cp-tree.h (DECL_CONSTRUCTOR_P, DECL_DESTRUCTOR_P): Change to
>         strip templates and set the middle-end flag.
> Index: tree.h
> ===================================================================
> --- tree.h      (revision 201977)
> +++ tree.h      (working copy)
> @@ -3232,8 +3232,12 @@ struct GTY(()) tree_decl_with_vis {
>   /* Used by C++ only.  Might become a generic decl flag.  */
>   unsigned shadowed_for_var_p : 1;
>   /* Belong to FUNCTION_DECL exclusively.  */
> + unsigned cpp_constructor : 1;
> + /* Belong to FUNCTION_DECL exclusively.  */
> + unsigned cpp_destructor : 1;
> + /* Belong to FUNCTION_DECL exclusively.  */

Naming suggestion:  we already use cpp_ as prefix for the C preprocessor.
Could we please not use it for C++, given that tree is used by so
many clients for just about anything.   cxx_ is a good alternative.

>   unsigned final : 1;
> - /* 13 unused bits. */
> + /* 11 unused bits. */
>  };
>
>  extern tree decl_debug_expr_lookup (tree);
> @@ -3483,6 +3487,18 @@ extern vec<tree, va_gc> **decl_debug_arg
>  #define DECL_FUNCTION_VERSIONED(NODE)\
>     (FUNCTION_DECL_CHECK (NODE)->function_decl.versioned_function)
>
> +/* In FUNCTION_DECL, this is set if this function is a C++ constructor.
> +   Devirtualization machinery uses this knowledge for determing type of the
> +   object constructed.  Also we assume that constructor address is not
> +   important.  */
> +#define DECL_CPP_CONSTRUCTOR_P(NODE)\

Same here.

> +   (FUNCTION_DECL_CHECK (NODE)->decl_with_vis.cpp_constructor)
> +
> +/* In FUNCTION_DECL, this is set if this function is a C++ destructor.
> +   Devirtualization machinery uses this to track types in destruction.  */
> +#define DECL_CPP_DESTRUCTOR_P(NODE)\
> +   (FUNCTION_DECL_CHECK (NODE)->decl_with_vis.cpp_destructor)
> +

Likewise.

>  /* In FUNCTION_DECL that represent an virtual method this is set when
>     the method is final.  */
>  #define DECL_FINAL_P(NODE)\
> Index: cp/cp-tree.h
> ===================================================================
> --- cp/cp-tree.h        (revision 201977)
> +++ cp/cp-tree.h        (working copy)
> @@ -2121,9 +2121,10 @@ struct GTY((variable_size)) lang_decl {
>  #define SET_DECL_LANGUAGE(NODE, LANGUAGE) \
>    (DECL_LANG_SPECIFIC (NODE)->u.base.language = (LANGUAGE))
>
> -/* For FUNCTION_DECLs: nonzero means that this function is a constructor.  */
> +/* For FUNCTION_DECLs and TEMPLATE_DECLs: nonzero means that this function
> +   is a constructor.  */
>  #define DECL_CONSTRUCTOR_P(NODE) \
> -  (LANG_DECL_FN_CHECK (NODE)->constructor_attr)
> +  DECL_CPP_CONSTRUCTOR_P (STRIP_TEMPLATE (NODE))
>
>  /* Nonzero if NODE (a FUNCTION_DECL) is a constructor for a complete
>     object.  */
> @@ -2152,9 +2153,10 @@ struct GTY((variable_size)) lang_decl {
>  #define DECL_MOVE_CONSTRUCTOR_P(NODE) \
>    (DECL_CONSTRUCTOR_P (NODE) && move_fn_p (NODE))
>
> -/* Nonzero if NODE is a destructor.  */
> +/* Nonzero if NODE (a FUNCTION_DECL or TEMPLATE_DECL)
> +   is a destructor.  */
>  #define DECL_DESTRUCTOR_P(NODE)                                \
> -  (LANG_DECL_FN_CHECK (NODE)->destructor_attr)
> +  DECL_CPP_DESTRUCTOR_P (STRIP_TEMPLATE (NODE))
>
>  /* Nonzero if NODE (a FUNCTION_DECL) is a destructor, but not the
>     specialized in-charge constructor, in-charge deleting constructor,
Jan Hubicka - Aug. 25, 2013, 3:48 p.m.
> Naming suggestion:  we already use cpp_ as prefix for the C preprocessor.
> Could we please not use it for C++, given that tree is used by so
> many clients for just about anything.   cxx_ is a good alternative.

CXX is fine with me.  I updated by local copy.

Honza
> 
> >   unsigned final : 1;
> > - /* 13 unused bits. */
> > + /* 11 unused bits. */
> >  };
> >
> >  extern tree decl_debug_expr_lookup (tree);
> > @@ -3483,6 +3487,18 @@ extern vec<tree, va_gc> **decl_debug_arg
> >  #define DECL_FUNCTION_VERSIONED(NODE)\
> >     (FUNCTION_DECL_CHECK (NODE)->function_decl.versioned_function)
> >
> > +/* In FUNCTION_DECL, this is set if this function is a C++ constructor.
> > +   Devirtualization machinery uses this knowledge for determing type of the
> > +   object constructed.  Also we assume that constructor address is not
> > +   important.  */
> > +#define DECL_CPP_CONSTRUCTOR_P(NODE)\
> 
> Same here.
> 
> > +   (FUNCTION_DECL_CHECK (NODE)->decl_with_vis.cpp_constructor)
> > +
> > +/* In FUNCTION_DECL, this is set if this function is a C++ destructor.
> > +   Devirtualization machinery uses this to track types in destruction.  */
> > +#define DECL_CPP_DESTRUCTOR_P(NODE)\
> > +   (FUNCTION_DECL_CHECK (NODE)->decl_with_vis.cpp_destructor)
> > +
> 
> Likewise.
> 
> >  /* In FUNCTION_DECL that represent an virtual method this is set when
> >     the method is final.  */
> >  #define DECL_FINAL_P(NODE)\
> > Index: cp/cp-tree.h
> > ===================================================================
> > --- cp/cp-tree.h        (revision 201977)
> > +++ cp/cp-tree.h        (working copy)
> > @@ -2121,9 +2121,10 @@ struct GTY((variable_size)) lang_decl {
> >  #define SET_DECL_LANGUAGE(NODE, LANGUAGE) \
> >    (DECL_LANG_SPECIFIC (NODE)->u.base.language = (LANGUAGE))
> >
> > -/* For FUNCTION_DECLs: nonzero means that this function is a constructor.  */
> > +/* For FUNCTION_DECLs and TEMPLATE_DECLs: nonzero means that this function
> > +   is a constructor.  */
> >  #define DECL_CONSTRUCTOR_P(NODE) \
> > -  (LANG_DECL_FN_CHECK (NODE)->constructor_attr)
> > +  DECL_CPP_CONSTRUCTOR_P (STRIP_TEMPLATE (NODE))
> >
> >  /* Nonzero if NODE (a FUNCTION_DECL) is a constructor for a complete
> >     object.  */
> > @@ -2152,9 +2153,10 @@ struct GTY((variable_size)) lang_decl {
> >  #define DECL_MOVE_CONSTRUCTOR_P(NODE) \
> >    (DECL_CONSTRUCTOR_P (NODE) && move_fn_p (NODE))
> >
> > -/* Nonzero if NODE is a destructor.  */
> > +/* Nonzero if NODE (a FUNCTION_DECL or TEMPLATE_DECL)
> > +   is a destructor.  */
> >  #define DECL_DESTRUCTOR_P(NODE)                                \
> > -  (LANG_DECL_FN_CHECK (NODE)->destructor_attr)
> > +  DECL_CPP_DESTRUCTOR_P (STRIP_TEMPLATE (NODE))
> >
> >  /* Nonzero if NODE (a FUNCTION_DECL) is a destructor, but not the
> >     specialized in-charge constructor, in-charge deleting constructor,
Jason Merrill - Aug. 26, 2013, 12:30 a.m.
OK.

Jason

Patch

Index: tree.h
===================================================================
--- tree.h	(revision 201977)
+++ tree.h	(working copy)
@@ -3232,8 +3232,12 @@  struct GTY(()) tree_decl_with_vis {
  /* Used by C++ only.  Might become a generic decl flag.  */
  unsigned shadowed_for_var_p : 1;
  /* Belong to FUNCTION_DECL exclusively.  */
+ unsigned cpp_constructor : 1;
+ /* Belong to FUNCTION_DECL exclusively.  */
+ unsigned cpp_destructor : 1;
+ /* Belong to FUNCTION_DECL exclusively.  */
  unsigned final : 1;
- /* 13 unused bits. */
+ /* 11 unused bits. */
 };
 
 extern tree decl_debug_expr_lookup (tree);
@@ -3483,6 +3487,18 @@  extern vec<tree, va_gc> **decl_debug_arg
 #define DECL_FUNCTION_VERSIONED(NODE)\
    (FUNCTION_DECL_CHECK (NODE)->function_decl.versioned_function)
 
+/* In FUNCTION_DECL, this is set if this function is a C++ constructor.
+   Devirtualization machinery uses this knowledge for determing type of the
+   object constructed.  Also we assume that constructor address is not
+   important.  */
+#define DECL_CPP_CONSTRUCTOR_P(NODE)\
+   (FUNCTION_DECL_CHECK (NODE)->decl_with_vis.cpp_constructor)
+
+/* In FUNCTION_DECL, this is set if this function is a C++ destructor.
+   Devirtualization machinery uses this to track types in destruction.  */
+#define DECL_CPP_DESTRUCTOR_P(NODE)\
+   (FUNCTION_DECL_CHECK (NODE)->decl_with_vis.cpp_destructor)
+
 /* In FUNCTION_DECL that represent an virtual method this is set when
    the method is final.  */
 #define DECL_FINAL_P(NODE)\
Index: cp/cp-tree.h
===================================================================
--- cp/cp-tree.h	(revision 201977)
+++ cp/cp-tree.h	(working copy)
@@ -2121,9 +2121,10 @@  struct GTY((variable_size)) lang_decl {
 #define SET_DECL_LANGUAGE(NODE, LANGUAGE) \
   (DECL_LANG_SPECIFIC (NODE)->u.base.language = (LANGUAGE))
 
-/* For FUNCTION_DECLs: nonzero means that this function is a constructor.  */
+/* For FUNCTION_DECLs and TEMPLATE_DECLs: nonzero means that this function
+   is a constructor.  */
 #define DECL_CONSTRUCTOR_P(NODE) \
-  (LANG_DECL_FN_CHECK (NODE)->constructor_attr)
+  DECL_CPP_CONSTRUCTOR_P (STRIP_TEMPLATE (NODE))
 
 /* Nonzero if NODE (a FUNCTION_DECL) is a constructor for a complete
    object.  */
@@ -2152,9 +2153,10 @@  struct GTY((variable_size)) lang_decl {
 #define DECL_MOVE_CONSTRUCTOR_P(NODE) \
   (DECL_CONSTRUCTOR_P (NODE) && move_fn_p (NODE))
 
-/* Nonzero if NODE is a destructor.  */
+/* Nonzero if NODE (a FUNCTION_DECL or TEMPLATE_DECL)
+   is a destructor.  */
 #define DECL_DESTRUCTOR_P(NODE)				\
-  (LANG_DECL_FN_CHECK (NODE)->destructor_attr)
+  DECL_CPP_DESTRUCTOR_P (STRIP_TEMPLATE (NODE))
 
 /* Nonzero if NODE (a FUNCTION_DECL) is a destructor, but not the
    specialized in-charge constructor, in-charge deleting constructor,