Patchwork Merge constructors and destructors

login
register
mail settings
Submitter Jan Hubicka
Date Aug. 26, 2010, 10:05 a.m.
Message ID <20100826100506.GA13676@atrey.karlin.mff.cuni.cz>
Download mbox | patch
Permalink /patch/62768/
State New
Headers show

Comments

Jan Hubicka - Aug. 26, 2010, 10:05 a.m.
Hi,
this is patch addressing the first Rth's comments, will reorganize the code to use vector of
cgraph nodes and order field as followup.
Bootstrapped/regtested x86_64-linux, seems sane?

	* ipa.c (build_cdtor): Accept VECtor; fix pasto in loop counting
	number of constructors of same type; simplify second loop.
	(build_cdtor_fns): Update call of build_cdtor.
Richard Henderson - Aug. 26, 2010, 3:20 p.m.
On 08/26/2010 03:05 AM, Jan Hubicka wrote:
> Hi, this is patch addressing the first Rth's comments, will
> reorganize the code to use vector of cgraph nodes and order field as
> followup. Bootstrapped/regtested x86_64-linux, seems sane?

Looks good, thanks.


r~

Patch

Index: ipa.c
===================================================================
--- ipa.c	(revision 163467)
+++ ipa.c	(working copy)
@@ -1420,9 +1420,10 @@  record_cdtor_fn (struct cgraph_node *nod
    they are destructors.  */
 
 static void
-build_cdtor (bool ctor_p, tree *cdtors, size_t len)
+build_cdtor (bool ctor_p, VEC (tree, heap) *cdtors)
 {
   size_t i,j;
+  size_t len = VEC_length (tree, cdtors);
 
   i = 0;
   while (i < len)
@@ -1437,7 +1438,7 @@  build_cdtor (bool ctor_p, tree *cdtors, 
       do
 	{
 	  priority_type p;
-	  fn = cdtors[i];
+	  fn = VEC_index (tree, cdtors, j);
 	  p = ctor_p ? DECL_INIT_PRIORITY (fn) : DECL_FINI_PRIORITY (fn);
 	  if (j == i)
 	    priority = p;
@@ -1447,7 +1448,7 @@  build_cdtor (bool ctor_p, tree *cdtors, 
 	}
       while (j < len);
 
-      /* When there is only once constructor and target supports them, do nothing.  */
+      /* When there is only one cdtor and target supports them, do nothing.  */
       if (j == i + 1
 	  && targetm.have_ctors_dtors)
 	{
@@ -1456,14 +1457,10 @@  build_cdtor (bool ctor_p, tree *cdtors, 
 	}
       /* Find the next batch of constructors/destructors with the same
 	 initialization priority.  */
-      do
+      for (;i < j; i++)
 	{
-	  priority_type p;
 	  tree call;
-	  fn = cdtors[i];
-	  p = ctor_p ? DECL_INIT_PRIORITY (fn) : DECL_FINI_PRIORITY (fn);
-	  if (p != priority)
-	    break;
+	  fn = VEC_index (tree, cdtors, i);
 	  call = build_call_expr (fn, 0);
 	  if (ctor_p)
 	    DECL_STATIC_CONSTRUCTOR (fn) = 0;
@@ -1474,7 +1471,6 @@  build_cdtor (bool ctor_p, tree *cdtors, 
 	     optimizing, we want user to be able to breakpoint in them.  */
 	  TREE_SIDE_EFFECTS (call) = 1;
 	  append_to_statement_list (call, &body);
-	  ++i;
 	}
       while (i < len);
       gcc_assert (body != NULL_TREE);
@@ -1551,10 +1547,7 @@  build_cdtor_fns (void)
 	     VEC_length (tree, static_ctors),
 	     sizeof (tree),
 	     compare_ctor);
-      build_cdtor (/*ctor_p=*/true,
-		   VEC_address (tree, static_ctors),
-		   VEC_length (tree, static_ctors));
-      VEC_truncate (tree, static_ctors, 0);
+      build_cdtor (/*ctor_p=*/true, static_ctors);
     }
 
   if (!VEC_empty (tree, static_dtors))
@@ -1564,10 +1557,7 @@  build_cdtor_fns (void)
 	     VEC_length (tree, static_dtors),
 	     sizeof (tree),
 	     compare_dtor);
-      build_cdtor (/*ctor_p=*/false,
-		   VEC_address (tree, static_dtors),
-		   VEC_length (tree, static_dtors));
-      VEC_truncate (tree, static_dtors, 0);
+      build_cdtor (/*ctor_p=*/false, static_dtors);
     }
 }