diff mbox

[Cilkplus] Patch to fix spawn bug in templates

Message ID BF230D13CA30DD48930C31D40993300005A9B9@FMSMSX102.amr.corp.intel.com
State New
Headers show

Commit Message

Iyer, Balaji V March 16, 2012, 11 p.m. UTC
Hello Everyone,
   This patch is for the Cilkplus branch, mainly affecting the C++ compiler. This patch will fix a bug when spawn is used inside template functions.

Thanks,

Balaji V. Iyer.
diff mbox

Patch

diff --git a/gcc/ChangeLog.cilk b/gcc/ChangeLog.cilk
index 3667c75..f1935d2 100644
--- a/gcc/ChangeLog.cilk
+++ b/gcc/ChangeLog.cilk
@@ -1,3 +1,13 @@ 
+2012-03-16  Balaji V. Iyer  <balaji.v.iyer@intel.com>
+
+	* cilk-spawn.c (cilk_valid_spawn): Unwrapped the call_expr from expr
+	and cleanup point statements.
+	(gimplify_cilk_spawn): Likewise.
+	* function.c (allocate_struct_function): Initialized calls_spawns
+	correctly.
+	* tree.h: Removed cilk_hyper_flag and replaced with cilk_has_spawn.
+	Also added DECL_HAS_SPAWN_P and removed DECL_HYPER_LOOKUP_P.
+
 2012-03-12  Balaji V. Iyer  <balaji.v.iyer@intel.com>
 
 	* c-typeck.c (convert_arguments): Added array notation check for
diff --git a/gcc/cilk-spawn.c b/gcc/cilk-spawn.c
index 3ba1051..3a29250 100644
--- a/gcc/cilk-spawn.c
+++ b/gcc/cilk-spawn.c
@@ -295,6 +295,10 @@  cilk_valid_spawn (tree exp0)
   if (exp == NULL_TREE)
     return false; /* happens with C++ TARGET_EXPR */
 
+  while (TREE_CODE (exp) == CLEANUP_POINT_EXPR
+	 || TREE_CODE (exp) == EXPR_STMT)
+    exp = TREE_OPERAND (exp, 0);
+  
   /* Now we have a call, or this isn't a valid spawn. */
   /* XXX This will reject any outer non-spawn AGGR_INIT_EXPR
      that is valid because of a spawn inside.  Are there any
@@ -394,7 +398,11 @@  gimplify_cilk_spawn (tree *spawn_p, gimple_seq *before ATTRIBUTE_UNUSED,
       *spawn_p = build_empty_stmt (UNKNOWN_LOCATION);
       return;
     }
-
+  /* Remove cleanup point expr and expr stmt from *spawn_p */
+  while (TREE_CODE (expr) == CLEANUP_POINT_EXPR
+	 || TREE_CODE (expr) == EXPR_STMT)
+    expr = TREE_OPERAND (expr, 0);
+  
   new_args = NULL;
   function = build_cilk_wrapper (expr, &new_args);
 
diff --git a/gcc/cp/ChangeLog.cilk b/gcc/cp/ChangeLog.cilk
index 28bd0e1..0970089 100644
--- a/gcc/cp/ChangeLog.cilk
+++ b/gcc/cp/ChangeLog.cilk
@@ -1,3 +1,11 @@ 
+2012-03-16  Balaji V. Iyer  <balaji.v.iyer@intel.com>
+
+	* decl.c (finish_function_body): called DECL_HAS_SPAWN_P and set it to
+	calls_spawns.
+	* pt.c (tsubst_copy): Carried the spawn call information from one
+	call expression to another.
+	(tsubst_copy_and_build): Likewise.
+	
 2012-02-14  Balaji V. Iyer  <balaji.v.iyer@intel.com>
 
 	* parser.c (cp_parser_compound_stmt): Added a check to see if the
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 5b67c6d..71dfc8e 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -13402,6 +13402,7 @@  finish_function_body (tree compstmt)
 
   if (cfun->calls_spawn)
     cfun->cilk_frame_decl = cp_make_cilk_frame ();
+  DECL_HAS_SPAWN_P (cfun->decl) = cfun->calls_spawn;
 
   /* Close the block.  */
   finish_compound_stmt (compstmt);
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 9fb8573..5ca8aa7 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -12383,6 +12383,7 @@  tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl)
 	for (i = 0; i < n; i++)
 	  TREE_OPERAND (t, i) = tsubst_copy (TREE_OPERAND (t, i), args,
 					     complain, in_decl);
+	SPAWN_CALL_P (result) = SPAWN_CALL_P (t);
 	return result;
       }
 
@@ -13901,7 +13902,7 @@  tsubst_copy_and_build (tree t,
 					      in_decl,
 					      !qualified_p,
 					      integral_constant_expression_p);
-
+	    SPAWN_CALL_P (function) = SPAWN_CALL_P (t);
 	    if (BASELINK_P (function))
 	      qualified_p = true;
 	  }
diff --git a/gcc/function.c b/gcc/function.c
index ed07a83..a8acd39 100644
--- a/gcc/function.c
+++ b/gcc/function.c
@@ -4420,6 +4420,7 @@  allocate_struct_function (tree fndecl, bool abstract_p)
       cfun->can_throw_non_call_exceptions = flag_non_call_exceptions;
 
       cfun->elem_fn_already_cloned = false;
+      cfun->calls_spawn = DECL_HAS_SPAWN_P (fndecl);
     }
 }
 
diff --git a/gcc/tree.h b/gcc/tree.h
index 1d4b18c..b204e30 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -3564,8 +3564,8 @@  struct GTY(())
 
 /* In a FUNCTION_DECL for a Cilk function, indicates that the
    function is a hyperobject lookup. */
-#define DECL_HYPER_LOOKUP_P(NODE)				\
-  (FUNCTION_DECL_CHECK (NODE)->function_decl.cilk_hyper_flag)
+#define DECL_HAS_SPAWN_P(NODE) \
+  (FUNCTION_DECL_CHECK (NODE)->function_decl.cilk_has_spawn)
 
 /* In a FUNCTION_DECL with a nonzero DECL_CONTEXT, indicates that
    the static chain is an explicit argument.  */
@@ -3573,8 +3573,6 @@  struct GTY(())
   (FUNCTION_DECL_CHECK (NODE)->function_decl.explicit_static_chain_flag)
 
 
-
-
 /* In a FUNCTION_DECL indicates that a static chain is needed.  */
 #define DECL_STATIC_CHAIN(NODE) \
   (FUNCTION_DECL_CHECK (NODE)->function_decl.regdecl_flag)
@@ -3707,7 +3705,7 @@  struct GTY(()) tree_function_decl {
   unsigned looping_const_or_pure_flag : 1;
   unsigned has_debug_args_flag : 1;
   unsigned cilk_knot_type : 2;
-  unsigned cilk_hyper_flag : 1;
+  unsigned cilk_has_spawn : 1;
   signed int kills_registers : DECL_KILLS_REGISTERS_BITS;
   unsigned tm_clone_flag : 1;