This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] Do not generate both XVS and XVE type


There is no need to generate both an XVS and an XVE type for the same record 
type; we can limit ourselves to the XVS type, which is the simplest of the two 
types.

Tested on i586-suse-linux, applied on the mainline.


2012-03-25  Eric Botcazou  <ebotcazou@adacore.com>

	* gcc-interface/utils.c (add_parallel_type): Take a TYPE instead of a
	DECL and adjust.  Move around.
	(has_parallel_type): New predicate.
	(rest_of_record_type_compilation): Return early if the type already
	has a parallel type.
	* gcc-interface/gigi.h (add_parallel_type): Adjust.
	* gcc-interface/decl.c (gnat_to_gnu_entity): Adjust for above changes.


-- 
Eric Botcazou
Index: gcc-interface/utils.c
===================================================================
--- gcc-interface/utils.c	(revision 185778)
+++ gcc-interface/utils.c	(working copy)
@@ -855,6 +855,29 @@ finish_record_type (tree record_type, tr
     rest_of_record_type_compilation (record_type);
 }
 
+/* Append PARALLEL_TYPE on the chain of parallel types of TYPE.  */
+
+void
+add_parallel_type (tree type, tree parallel_type)
+{
+  tree decl = TYPE_STUB_DECL (type);
+
+  while (DECL_PARALLEL_TYPE (decl))
+    decl = TYPE_STUB_DECL (DECL_PARALLEL_TYPE (decl));
+
+  SET_DECL_PARALLEL_TYPE (decl, parallel_type);
+}
+
+/* Return true if TYPE has a parallel type.  */
+
+static bool
+has_parallel_type (tree type)
+{
+  tree decl = TYPE_STUB_DECL (type);
+
+  return DECL_PARALLEL_TYPE (decl) != NULL_TREE;
+}
+
 /* Wrap up compilation of RECORD_TYPE, i.e. output all the debug information
    associated with it.  It need not be invoked directly in most cases since
    finish_record_type takes care of doing so, but this can be necessary if
@@ -871,6 +894,10 @@ rest_of_record_type_compilation (tree re
   if (TYPE_IS_PADDING_P (record_type))
     return;
 
+  /* If the type already has a parallel type (XVS type), then we're done.  */
+  if (has_parallel_type (record_type))
+    return;
+
   for (field = TYPE_FIELDS (record_type); field; field = DECL_CHAIN (field))
     {
       /* We need to make an XVE/XVU record if any field has variable size,
@@ -1054,23 +1081,10 @@ rest_of_record_type_compilation (tree re
 
       TYPE_FIELDS (new_record_type) = nreverse (TYPE_FIELDS (new_record_type));
 
-      add_parallel_type (TYPE_STUB_DECL (record_type), new_record_type);
+      add_parallel_type (record_type, new_record_type);
     }
 }
 
-/* Append PARALLEL_TYPE on the chain of parallel types for decl.  */
-
-void
-add_parallel_type (tree decl, tree parallel_type)
-{
-  tree d = decl;
-
-  while (DECL_PARALLEL_TYPE (d))
-    d = TYPE_STUB_DECL (DECL_PARALLEL_TYPE (d));
-
-  SET_DECL_PARALLEL_TYPE (d, parallel_type);
-}
-
 /* Utility function of above to merge LAST_SIZE, the previous size of a record
    with FIRST_BIT and SIZE that describe a field.  SPECIAL is true if this
    represents a QUAL_UNION_TYPE in which case we must look for COND_EXPRs and
Index: gcc-interface/decl.c
===================================================================
--- gcc-interface/decl.c	(revision 185742)
+++ gcc-interface/decl.c	(working copy)
@@ -1779,7 +1779,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entit
       if (debug_info_p
 	  && Is_Packed_Array_Type (gnat_entity)
 	  && present_gnu_tree (Original_Array_Type (gnat_entity)))
-	add_parallel_type (TYPE_STUB_DECL (gnu_type),
+	add_parallel_type (gnu_type,
 			   gnat_to_gnu_type
 			   (Original_Array_Type (gnat_entity)));
 
@@ -1854,7 +1854,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entit
 	    {
 	      /* Make the original array type a parallel type.  */
 	      if (present_gnu_tree (Original_Array_Type (gnat_entity)))
-		add_parallel_type (TYPE_STUB_DECL (gnu_type),
+		add_parallel_type (gnu_type,
 				   gnat_to_gnu_type
 				   (Original_Array_Type (gnat_entity)));
 
@@ -2637,7 +2637,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entit
 		}
 
 	      finish_record_type (gnu_bound_rec, gnu_field_list, 0, true);
-	      add_parallel_type (TYPE_STUB_DECL (gnu_type), gnu_bound_rec);
+	      add_parallel_type (gnu_type, gnu_bound_rec);
 	    }
 
 	  /* If this is a packed array type, make the original array type a
@@ -2647,7 +2647,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entit
 	    {
 	      if (Is_Packed_Array_Type (gnat_entity)
 		  && present_gnu_tree (Original_Array_Type (gnat_entity)))
-		add_parallel_type (TYPE_STUB_DECL (gnu_type),
+		add_parallel_type (gnu_type,
 				   gnat_to_gnu_type
 				   (Original_Array_Type (gnat_entity)));
 	      else
@@ -2655,7 +2655,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entit
 		  tree gnu_base_decl
 		    = gnat_to_gnu_entity (Etype (gnat_entity), NULL_TREE, 0);
 		  if (!DECL_ARTIFICIAL (gnu_base_decl))
-		    add_parallel_type (TYPE_STUB_DECL (gnu_type),
+		    add_parallel_type (gnu_type,
 				       TREE_TYPE (TREE_TYPE (gnu_base_decl)));
 		}
 	    }
@@ -3529,8 +3529,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entit
 							 0, 0),
 				      0, true);
 
-		  add_parallel_type (TYPE_STUB_DECL (gnu_type),
-				     gnu_subtype_marker);
+		  add_parallel_type (gnu_type, gnu_subtype_marker);
 
 		  if (definition
 		      && TREE_CODE (gnu_size_unit) != INTEGER_CST
@@ -6643,7 +6642,7 @@ maybe_pad_type (tree type, tree size, un
 					     0, 0),
 			  0, true);
 
-      add_parallel_type (TYPE_STUB_DECL (record), marker);
+      add_parallel_type (record, marker);
 
       if (definition && size && TREE_CODE (size) != INTEGER_CST)
 	TYPE_SIZE_UNIT (marker)
Index: gcc-interface/gigi.h
===================================================================
--- gcc-interface/gigi.h	(revision 185742)
+++ gcc-interface/gigi.h	(working copy)
@@ -560,8 +560,8 @@ extern void finish_record_type (tree rec
    a parallel type is to be attached to the record type.  */
 extern void rest_of_record_type_compilation (tree record_type);
 
-/* Append PARALLEL_TYPE on the chain of parallel types for decl.  */
-extern void add_parallel_type (tree decl, tree parallel_type);
+/* Append PARALLEL_TYPE on the chain of parallel types for TYPE.  */
+extern void add_parallel_type (tree type, tree parallel_type);
 
 /* Return a FUNCTION_TYPE node.  RETURN_TYPE is the type returned by the
    subprogram.  If it is VOID_TYPE, then we are dealing with a procedure,

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]