Selaa lähdekoodia

gcc: Fill in the `modes' field of `starpu_codelet'.

* gcc-plugin/src/starpu.c (output_parameter_p): Remove.
  (output_type_p, access_mode): New functions.
  (build_codelet_initializer)[access_mode_array]: New function.  Use it
  to initialize the `modes' field.
  (build_task_body): Use `access_mode'.

* gcc-plugin/tests/mocks.h (starpu_insert_task): Compare TYPE against
  `cl->modes[_]'.
Ludovic Courtès 13 vuotta sitten
vanhempi
commit
e63751e09f
2 muutettua tiedostoa jossa 50 lisäystä ja 17 poistoa
  1. 46 15
      gcc-plugin/src/starpu.c
  2. 4 2
      gcc-plugin/tests/mocks.h

+ 46 - 15
gcc-plugin/src/starpu.c

@@ -1,5 +1,5 @@
 /* GCC-StarPU
 /* GCC-StarPU
-   Copyright (C) 2011 Institut National de Recherche en Informatique et Automatique
+   Copyright (C) 2011, 2012 Institut National de Recherche en Informatique et Automatique
 
 
    GCC-StarPU is free software: you can redistribute it and/or modify
    GCC-StarPU is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    it under the terms of the GNU General Public License as published by
@@ -1024,16 +1024,29 @@ task_implementation_wrapper (const_tree task_impl)
   return TREE_VALUE (attr);
   return TREE_VALUE (attr);
 }
 }
 
 
-/* Return true if DECL is a parameter whose type is `output'-qualified.  */
+/* Return true if TYPE is `output'-qualified.  */
 
 
 static bool
 static bool
-output_parameter_p (const_tree decl)
+output_type_p (const_tree type)
 {
 {
-  return (TREE_CODE (decl) == PARM_DECL &&
-	  lookup_attribute (output_attribute_name,
-			    TYPE_ATTRIBUTES (TREE_TYPE (decl))) != NULL_TREE);
+  return (lookup_attribute (output_attribute_name,
+			    TYPE_ATTRIBUTES (type)) != NULL_TREE);
 }
 }
 
 
+/* Return the access mode for POINTER, a PARM_DECL of a task.  */
+
+static enum starpu_access_mode
+access_mode (const_tree type)
+{
+  gcc_assert (POINTER_TYPE_P (type));
+
+  /* If TYPE points to a const-qualified type, then mark the data as
+     read-only; if is has the `output' attribute, then mark it as write-only;
+     otherwise default to read-write.  */
+  return ((TYPE_QUALS (TREE_TYPE (type)) & TYPE_QUAL_CONST)
+	  ? STARPU_R
+	  : (output_type_p (type) ? STARPU_W : STARPU_RW));
+}
 
 
 static void
 static void
 register_task_attributes (void *gcc_data, void *user_data)
 register_task_attributes (void *gcc_data, void *user_data)
@@ -1485,6 +1498,30 @@ build_codelet_initializer (tree task_decl)
     return build_int_cstu (integer_type_node, len);
     return build_int_cstu (integer_type_node, len);
   }
   }
 
 
+  tree access_mode_array (void)
+  {
+    const_tree type;
+    tree modes;
+    size_t index;
+
+    for (type = task_pointer_parameter_types (task_decl),
+	   modes = NULL_TREE, index = 0;
+	 type != NULL_TREE;
+	 type = TREE_CHAIN (type), index++)
+      {
+	tree value = build_int_cst (integer_type_node,
+				    access_mode (TREE_VALUE (type)));
+
+	modes = tree_cons (size_int (index), value, modes);
+      }
+
+    tree index_type = build_index_type (size_int (list_length (modes)));
+
+    return build_constructor_from_list (build_array_type (integer_type_node,
+							  index_type),
+					nreverse (modes));
+  }
+
   printf ("implementations for `%s':\n",
   printf ("implementations for `%s':\n",
 	  IDENTIFIER_POINTER (DECL_NAME (task_decl)));
 	  IDENTIFIER_POINTER (DECL_NAME (task_decl)));
 
 
@@ -1495,6 +1532,7 @@ build_codelet_initializer (tree task_decl)
   inits =
   inits =
     chain_trees (field_initializer ("where", where_init (impls)),
     chain_trees (field_initializer ("where", where_init (impls)),
 		 field_initializer ("nbuffers", pointer_arg_count ()),
 		 field_initializer ("nbuffers", pointer_arg_count ()),
+		 field_initializer ("modes", access_mode_array ()),
 		 field_initializer ("cpu_funcs",
 		 field_initializer ("cpu_funcs",
 				    implementation_pointers (impls,
 				    implementation_pointers (impls,
 							     STARPU_CPU)),
 							     STARPU_CPU)),
@@ -1642,16 +1680,9 @@ build_task_body (const_tree task_decl)
 	  /* A pointer: the arguments will be:
 	  /* A pointer: the arguments will be:
 	     `STARPU_RW, ptr' or similar.  */
 	     `STARPU_RW, ptr' or similar.  */
 
 
-	  /* If TYPE points to a const-qualified type, then mark the data as
-	     read-only; if is has the `output' attribute, then mark it as
-	     write-only; otherwise default to read-write.  */
-	  int mode =
-	    (TYPE_QUALS (TREE_TYPE (type)) & TYPE_QUAL_CONST)
-	    ? STARPU_R
-	    : (output_parameter_p (p) ? STARPU_W : STARPU_RW);
-
 	  VEC_safe_push (tree, gc, args,
 	  VEC_safe_push (tree, gc, args,
-			 build_int_cst (integer_type_node, mode));
+			 build_int_cst (integer_type_node,
+					access_mode (type)));
 	  VEC_safe_push (tree, gc, args, build_pointer_lookup (p));
 	  VEC_safe_push (tree, gc, args, build_pointer_lookup (p));
 	}
 	}
       else
       else

+ 4 - 2
gcc-plugin/tests/mocks.h

@@ -1,5 +1,5 @@
 /* GCC-StarPU
 /* GCC-StarPU
-   Copyright (C) 2011 Institut National de Recherche en Informatique et Automatique
+   Copyright (C) 2011, 2012 Institut National de Recherche en Informatique et Automatique
 
 
    GCC-StarPU is free software: you can redistribute it and/or modify
    GCC-StarPU is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    it under the terms of the GNU General Public License as published by
@@ -66,11 +66,12 @@ starpu_insert_task (struct starpu_codelet *cl, ...)
   assert (cl->cuda_funcs[0] == NULL);
   assert (cl->cuda_funcs[0] == NULL);
 
 
   va_list args;
   va_list args;
+  size_t pointer_arg;
 
 
   va_start (args, cl);
   va_start (args, cl);
 
 
   const struct insert_task_argument *expected;
   const struct insert_task_argument *expected;
-  for (expected = expected_insert_task_arguments;
+  for (expected = expected_insert_task_arguments, pointer_arg = 0;
        expected->type != 0;
        expected->type != 0;
        expected++)
        expected++)
     {
     {
@@ -101,6 +102,7 @@ starpu_insert_task (struct starpu_codelet *cl, ...)
 	  {
 	  {
 	    starpu_data_handle_t handle;
 	    starpu_data_handle_t handle;
 	    handle = starpu_data_lookup (expected->pointer);
 	    handle = starpu_data_lookup (expected->pointer);
+	    assert (type == cl->modes[pointer_arg++]);
 	    assert (va_arg (args, void *) == handle);
 	    assert (va_arg (args, void *) == handle);
 	    break;
 	    break;
 	  }
 	  }