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

login
register
mail settings
Submitter Jan Hubicka
Date Aug. 22, 2013, 9:59 a.m.
Message ID <20130822095937.GF16124@kam.mff.cuni.cz>
Download mbox | patch
Permalink /patch/269004/
State New
Headers show

Comments

Jan Hubicka - Aug. 22, 2013, 9:59 a.m.
Hi,
this patch moves CLASSTYPE_FINAL and DECL_FINAL_P to middle end trees,
so I can use them in my type inheritance analysis.
Incrementally I would like to introduce DECL_CPP_CONSTURCTOR_P/DESTRUCTOR,
too, since we need to know about their C++ specific semantics.  However
I failed to follow the same patch, since these predicates are often called
on TEMPLATE_DECL.  I wonder if those can ever be ctors/dtors?

Bootstrapped/regtested x86_64-linux, OK?

	* cp-tree.h (CLASSTYPE_FINAL): Define using TYPE_FINAL_P.
	(DECL_FINAL_P): Remove.
	* pt.c (instantiate_class_template_1): Guard that CLASSTYPE_FINAL
	is called on CLASS_TYPE_P.
	* tree.h (TYPE_FINAL_P, DECL_FINAL_P): New macros.
	(tree_decl_with_vis): Add FINAL field.
Jason Merrill - Aug. 22, 2013, 3:17 p.m.
On 08/22/2013 05:59 AM, Jan Hubicka wrote:
> +/* Nonzero if RECORD_TYPE represents a final derivation of class.  */
> +#define TYPE_FINAL_P(NODE) \
> +  (RECORD_OR_UNION_CHECK (NODE)->base.default_def_flag)

How about if we put this flag on the BINFO rather than the type itself?

Jason
Jan Hubicka - Aug. 22, 2013, 3:22 p.m.
> On 08/22/2013 05:59 AM, Jan Hubicka wrote:
> >+/* Nonzero if RECORD_TYPE represents a final derivation of class.  */
> >+#define TYPE_FINAL_P(NODE) \
> >+  (RECORD_OR_UNION_CHECK (NODE)->base.default_def_flag)
> 
> How about if we put this flag on the BINFO rather than the type itself?
No problem for me.  There is space in type flags and binfo flags, so whatever
seems more suitable.
This option did not occured to me and of course I would be bit fearing of C++ FE
not having binfos ready all the time it wants to touch the type.  But probably
you know if that can happen ;)

Honza
> 
> Jason
Paolo Carlini - Aug. 22, 2013, 4:05 p.m.
Hi,

On 08/22/2013 05:22 PM, Jan Hubicka wrote:
>> On 08/22/2013 05:59 AM, Jan Hubicka wrote:
>>> +/* Nonzero if RECORD_TYPE represents a final derivation of class.  */
>>> +#define TYPE_FINAL_P(NODE) \
>>> +  (RECORD_OR_UNION_CHECK (NODE)->base.default_def_flag)
>> How about if we put this flag on the BINFO rather than the type itself?
> No problem for me.  There is space in type flags and binfo flags, so whatever
> seems more suitable.
> This option did not occured to me and of course I would be bit fearing of C++ FE
> not having binfos ready all the time it wants to touch the type.  But probably
> you know if that can happen ;)
Sorry if I'm saying something rather vague: I suppose you mean 
BINFO_FLAG_6? Because it's the last one. I'm saying this because over 
the last week or so I wondered if we need a bit also to fix c++/15272. 
Can we give that a little thought before making the final (pun intended 
;) decision?

Thanks!
Paolo.
Jason Merrill - Aug. 23, 2013, 1:47 p.m.
On 08/22/2013 12:05 PM, Paolo Carlini wrote:
> Sorry if I'm saying something rather vague: I suppose you mean
> BINFO_FLAG_6? Because it's the last one.

No, that's a language-specific flag.

Jason
Paolo Carlini - Aug. 23, 2013, 1:51 p.m.
On 08/23/2013 03:47 PM, Jason Merrill wrote:
> On 08/22/2013 12:05 PM, Paolo Carlini wrote:
>> Sorry if I'm saying something rather vague: I suppose you mean
>> BINFO_FLAG_6? Because it's the last one.
>
> No, that's a language-specific flag.
Ah great. Thanks!

Paolo.
Jason Merrill - Aug. 23, 2013, 1:54 p.m.
On 08/22/2013 11:22 AM, Jan Hubicka wrote:
> This option did not occured to me and of course I would be bit fearing of C++ FE
> not having binfos ready all the time it wants to touch the type.  But probably
> you know if that can happen ;)

Classes (including struct and union) always have binfos.

Jason
Jan Hubicka - Aug. 23, 2013, 1:57 p.m.
> On 08/22/2013 11:22 AM, Jan Hubicka wrote:
> >This option did not occured to me and of course I would be bit fearing of C++ FE
> >not having binfos ready all the time it wants to touch the type.  But probably
> >you know if that can happen ;)
> 
> Classes (including struct and union) always have binfos.

Ok, I will prepare variant using public_flag of BINFO that seeems unused.
I.e. having BINFO_FINAL_P and C++ specific macro 
CLASSTYPE_FINAL(t) as BINFO_FINAL_P (TYPE_BINFO (t)).
Or shall I go ahead and update all users of CLASSTYPE_FINAL?

Thank you,
Honza
Jason Merrill - Aug. 23, 2013, 2:25 p.m.
On 08/23/2013 09:57 AM, Jan Hubicka wrote:
> Ok, I will prepare variant using public_flag of BINFO that seeems unused.
> I.e. having BINFO_FINAL_P and C++ specific macro
> CLASSTYPE_FINAL(t) as BINFO_FINAL_P (TYPE_BINFO (t)).

Sounds good.

Jason

Patch

Index: cp/cp-tree.h
===================================================================
--- cp/cp-tree.h	(revision 201910)
+++ cp/cp-tree.h	(working copy)
@@ -1535,7 +1535,7 @@  struct GTY((variable_size)) lang_type {
 
 /* Nonzero means that NODE (a class type) is final */
 #define CLASSTYPE_FINAL(NODE) \
-  (LANG_TYPE_CLASS_CHECK (NODE)->is_final)
+  TYPE_FINAL_P (NODE)
 
 
 /* Nonzero means that this _CLASSTYPE node overloads operator=(X&).  */
@@ -2400,10 +2400,6 @@  struct GTY((variable_size)) lang_decl {
    an override virt-specifier */
 #define DECL_OVERRIDE_P(NODE) (TREE_LANG_FLAG_0 (NODE))
 
-/* True (in a FUNCTION_DECL) if NODE is a function declared with
-   a final virt-specifier */
-#define DECL_FINAL_P(NODE) (TREE_LANG_FLAG_1 (NODE))
-
 /* The thunks associated with NODE, a FUNCTION_DECL.  */
 #define DECL_THUNKS(NODE) \
   (DECL_VIRTUAL_P (NODE) ? LANG_DECL_FN_CHECK (NODE)->context : NULL_TREE)
Index: cp/pt.c
===================================================================
--- cp/pt.c	(revision 201910)
+++ cp/pt.c	(working copy)
@@ -8730,7 +8730,8 @@  instantiate_class_template_1 (tree type)
       /* Adjust visibility for template arguments.  */
       determine_visibility (TYPE_MAIN_DECL (type));
     }
-  CLASSTYPE_FINAL (type) = CLASSTYPE_FINAL (pattern);
+  if (CLASS_TYPE_P (type))
+    CLASSTYPE_FINAL (type) = CLASSTYPE_FINAL (pattern);
 
   pbinfo = TYPE_BINFO (pattern);
 
Index: tree.h
===================================================================
--- tree.h	(revision 201910)
+++ tree.h	(working copy)
@@ -715,6 +715,9 @@  struct GTY(()) tree_base {
 
        DECL_NONLOCAL_FRAME in
 	   VAR_DECL
+
+       TYPE_FINAL_P in
+	   RECORD_TYPE, UNION_TYPE and QUAL_UNION_TYPE
 */
 
 struct GTY(()) tree_typed {
@@ -2314,6 +2317,10 @@  enum cv_qualifier
 #define TYPE_CONTAINS_PLACEHOLDER_INTERNAL(NODE) \
   (TYPE_CHECK (NODE)->type_common.contains_placeholder_bits)
 
+/* Nonzero if RECORD_TYPE represents a final derivation of class.  */
+#define TYPE_FINAL_P(NODE) \
+  (RECORD_OR_UNION_CHECK (NODE)->base.default_def_flag)
+
 /* The debug output functions use the symtab union field to store
    information specific to the debugging format.  The different debug
    output hooks store different types in the union field.  These three
@@ -3224,7 +3231,9 @@  struct GTY(()) tree_decl_with_vis {
  unsigned init_priority_p : 1;
  /* Used by C++ only.  Might become a generic decl flag.  */
  unsigned shadowed_for_var_p : 1;
- /* 14 unused bits. */
+ /* Belong to FUNCTION_DECL exclusively.  */
+ unsigned final : 1;
+ /* 13 unused bits. */
 };
 
 extern tree decl_debug_expr_lookup (tree);
@@ -3474,6 +3483,11 @@  extern vec<tree, va_gc> **decl_debug_arg
 #define DECL_FUNCTION_VERSIONED(NODE)\
    (FUNCTION_DECL_CHECK (NODE)->function_decl.versioned_function)
 
+/* In FUNCTION_DECL that represent an virtual method this is set when
+   the method is final.  */
+#define DECL_FINAL_P(NODE)\
+   (FUNCTION_DECL_CHECK (NODE)->decl_with_vis.final)
+
 /* FUNCTION_DECL inherits from DECL_NON_COMMON because of the use of the
    arguments/result/saved_tree fields by front ends.   It was either inherit
    FUNCTION_DECL from non_common, or inherit non_common from FUNCTION_DECL,