The two copies of a duplicated function are now available for joining.
authorJustin Seyster <jseyster@cs.sunysb.edu>
Thu, 12 Aug 2010 19:30:38 +0000 (15:30 -0400)
committerJustin Seyster <jseyster@cs.sunysb.edu>
Thu, 12 Aug 2010 19:30:38 +0000 (15:30 -0400)
The basic block pairs are now stored in globally accessible place and
are set up to get garbage collected when the pass ends.

src/aop-duplicate.c
src/aop-duplicate.h
src/aop-weave.c

index b7d19bd93bd3bf2cd1083fc599e2f520dd8a2efa..30723d94fcd07ecbef0f11fbc1c84c145ee8ca0e 100644 (file)
@@ -44,15 +44,29 @@ typedef struct label_pair {
 
 #define INITIAL_PAIRS 10
 
-/* TODO: This needs to be garbage collected. */
 DEF_VEC_O(label_pair);
 DEF_VEC_ALLOC_O(label_pair, heap);
 
-#define FOR_EACH_BB_PAIR(pairs, index, pair)   \
-       for ((index)=0; VEC_iterate(bb_pair, pairs, index, pair); (index)++)
-
 #define FOR_EACH_LABEL_PAIR(pairs, index, pair)        \
-       for ((index)=0; VEC_iterate(label_pair, pairs, index, pair); (index)++)
+  for ((index) = 0; VEC_iterate (label_pair, pairs, index, pair); (index)++)
+
+/* The last function duplicated.  Used to make sure we never try to
+   access duplicated basic blocks from an older function. */
+static struct function *duplicated_function = NULL;
+
+/* The distributor basic block for the current function (assuming that
+   the current function has been duplicated). */
+basic_block distributor_bb;
+
+/* The duplicated basic blocks for the current function (assuming that
+   the current function has been duplicated). */
+VEC(bb_pair, gc) *bb_pairs;
+
+bool
+is_current_func_duplicated ()
+{
+  return (cfun == duplicated_function);
+}
 
 static basic_block 
 new_bb_for_old(VEC(bb_pair, gc) *bb_pairs, basic_block old)
@@ -117,11 +131,8 @@ fix_labels(tree *label, int *walk_subtrees, void *arg)
    duty to further populate the distributor block.
  */
 void
-duplicate_function_body (VEC(bb_pair, gc) **bb_pairs_ptr,
-                        basic_block *distributor_bb_ptr,
-                        const char *tmpvar_name, gimple call)
+duplicate_function_body (const char *tmpvar_name, gimple call)
 {
-  VEC(bb_pair, gc) *bb_pairs;
   VEC(label_pair, heap) *label_pairs;
 
   unsigned int pair_index;
@@ -228,7 +239,6 @@ duplicate_function_body (VEC(bb_pair, gc) **bb_pairs_ptr,
 
       basic_block old_first_bb;
       basic_block new_first_bb;
-      basic_block distributor_bb;
 
       tree old_label;
       tree new_label;
@@ -296,13 +306,11 @@ duplicate_function_body (VEC(bb_pair, gc) **bb_pairs_ptr,
       remove_edge(single_succ_edge(distributor_bb));
       make_edge(distributor_bb, old_first_bb, EDGE_FALSE_VALUE);
       make_edge(distributor_bb, new_first_bb, EDGE_TRUE_VALUE);
-
-      *distributor_bb_ptr = distributor_bb;
     }
 
-  *bb_pairs_ptr = bb_pairs;
-
   free_original_copy_tables();
   VEC_free (label_pair, heap, label_pairs);
-  return;
+
+  /* Make a note that this function was duplicated. */
+  duplicated_function = cfun;
 }
index 878a5497a580c93b51e168746d9aa501c651f5fc..c87093bd2099b0779313b26f414d4751e7027e32 100644 (file)
@@ -26,8 +26,13 @@ typedef struct bb_pair {
 DEF_VEC_O(bb_pair);
 DEF_VEC_ALLOC_O(bb_pair, gc);
 
-extern void duplicate_function_body (VEC(bb_pair, gc) **bb_pairs_ptr,
-                                    basic_block *distributor_bb_ptr,
-                                    const char *tmpvar_name, gimple call);
+#define FOR_EACH_BB_PAIR(pairs, index, pair)   \
+  for ((index) = 0; VEC_iterate (bb_pair, pairs, index, pair); (index)++)
+
+extern basic_block distributor_bb;
+extern VEC(bb_pair, gc) *bb_pairs;
+
+extern bool is_current_func_duplicated ();
+extern void duplicate_function_body (const char *tmpvar_name, gimple call);
 
 #endif
index 2f84133f38e5b67d8ff2cc2879d9fee4de0b3ea6..19088d80874069f18376de504f5028e748e95477 100644 (file)
@@ -271,9 +271,6 @@ aop_duplicate (struct aop_joinpoint *jp, const char *func_name, ...)
   gimple func_call;
   struct aop_pointcut *pc;
 
-  VEC(bb_pair, gc) *bb_pairs;
-  basic_block distributor;
-
   pc = jp->pc;
 
   if (pc->kind != ATP_ENTRY)
@@ -288,5 +285,5 @@ aop_duplicate (struct aop_joinpoint *jp, const char *func_name, ...)
                              argp);
   va_end (argp);
 
-  duplicate_function_body (&bb_pairs, &distributor, "ia_body_index", func_call);
+  duplicate_function_body ("ia_body_index", func_call);
 }