浏览代码

gcc: Add `#pragma starpu release'.

* gcc-plugin/src/starpu.c (handle_pragma_release): New function.
  (register_pragmas): Register it for the `release' pragma.

* gcc-plugin/tests/mocks.h (struct data_release_arguments): New type.
  (data_release_calls): New variable.
  (starpu_data_release): New function.
* gcc-plugin/tests/release-errors.c, gcc-plugin/tests/release.c: New
  files.
* gcc-plugin/tests/Makefile.am (gcc_tests): Add them.
Ludovic Courtès 13 年之前
父节点
当前提交
7d3695ded6
共有 6 个文件被更改,包括 168 次插入3 次删除
  1. 1 0
      .gitignore
  2. 44 0
      gcc-plugin/src/starpu.c
  3. 2 0
      gcc-plugin/tests/Makefile.am
  4. 18 3
      gcc-plugin/tests/mocks.h
  5. 42 0
      gcc-plugin/tests/release-errors.c
  6. 61 0
      gcc-plugin/tests/release.c

+ 1 - 0
.gitignore

@@ -285,3 +285,4 @@ starpu.log
 /tests/main/wait_all_regenerable_tasks
 /tools/starpu_workers_activity
 /tests/datawizard/interfaces/copy_interfaces
+/gcc-plugin/tests/release

+ 44 - 0
gcc-plugin/src/starpu.c

@@ -908,6 +908,48 @@ handle_pragma_acquire (struct cpp_reader *reader)
 			     build_int_cst (integer_type_node, STARPU_RW)));
 }
 
+/* Process `#pragma starpu release VAR' and emit the corresponding
+   `starpu_data_release' call.  */
+
+static void
+handle_pragma_release (struct cpp_reader *reader)
+{
+  static tree release_fn;
+  LOOKUP_STARPU_FUNCTION (release_fn, "starpu_data_release");
+
+  tree args, var;
+  location_t loc;
+
+  loc = cpp_peek_token (reader, 0)->src_loc;
+
+  args = read_pragma_expressions ("release", loc);
+  if (args == NULL_TREE)
+    return;
+
+  var = TREE_VALUE (args);
+
+  if (var == error_mark_node)
+    return;
+  else if (TREE_CODE (TREE_TYPE (var)) != POINTER_TYPE
+	   && TREE_CODE (TREE_TYPE (var)) != ARRAY_TYPE)
+    {
+      error_at (loc, "%qE is neither a pointer nor an array", var);
+      return;
+    }
+  else if (TREE_CHAIN (args) != NULL_TREE)
+    error_at (loc, "junk after %<starpu release%> pragma");
+
+  /* If VAR is an array, take its address.  */
+  tree pointer =
+    POINTER_TYPE_P (TREE_TYPE (var))
+    ? var
+    : build_addr (var, current_function_decl);
+
+  /* Call `starpu_data_release (starpu_data_lookup (ptr))'.  */
+  add_stmt (build_call_expr (release_fn, 1,
+			     build_pointer_lookup (pointer)));
+}
+
 /* Process `#pragma starpu unregister VAR' and emit the corresponding
    `starpu_data_unregister' call.  */
 
@@ -984,6 +1026,8 @@ register_pragmas (void *gcc_data, void *user_data)
 				    handle_pragma_register);
   c_register_pragma_with_expansion (STARPU_PRAGMA_NAME_SPACE, "acquire",
 				    handle_pragma_acquire);
+  c_register_pragma_with_expansion (STARPU_PRAGMA_NAME_SPACE, "release",
+				    handle_pragma_release);
   c_register_pragma_with_expansion (STARPU_PRAGMA_NAME_SPACE, "unregister",
 				    handle_pragma_unregister);
   c_register_pragma (STARPU_PRAGMA_NAME_SPACE, "shutdown",

+ 2 - 0
gcc-plugin/tests/Makefile.am

@@ -23,6 +23,8 @@ gcc_tests =					\
   register-errors.c				\
   acquire.c					\
   acquire-errors.c				\
+  release.c					\
+  release-errors.c				\
   unregister.c					\
   unregister-errors.c				\
   task-errors.c					\

+ 18 - 3
gcc-plugin/tests/mocks.h

@@ -279,11 +279,19 @@ struct data_acquire_arguments
   void *pointer;
 };
 
-/* Number of `starpu_data_acquire' calls.  */
-static unsigned int data_acquire_calls;
+struct data_release_arguments
+{
+  /* Pointer to the data being released.  */
+  void *pointer;
+};
 
-/* Variable describing the expected `starpu_data_acquire' arguments.  */
+/* Number of `starpu_data_{acquire,release}' calls.  */
+static unsigned int data_acquire_calls, data_release_calls;
+
+/* Variable describing the expected `starpu_data_{acquire,release}'
+   arguments.  */
 struct data_acquire_arguments expected_acquire_arguments;
+struct data_release_arguments expected_release_arguments;
 
 int
 starpu_data_acquire (starpu_data_handle_t handle, enum starpu_access_mode mode)
@@ -297,6 +305,13 @@ starpu_data_acquire (starpu_data_handle_t handle, enum starpu_access_mode mode)
   return 0;
 }
 
+void
+starpu_data_release (starpu_data_handle_t handle)
+{
+  assert (handle_to_pointer (handle) == expected_release_arguments.pointer);
+  data_release_calls++;
+}
+
 
 /* Data acquisition.  */
 

+ 42 - 0
gcc-plugin/tests/release-errors.c

@@ -0,0 +1,42 @@
+/* GCC-StarPU
+   Copyright (C) 2011, 2012 Institut National de Recherche en Informatique et Automatique
+
+   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
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   GCC-StarPU is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GCC-StarPU.  If not, see <http://www.gnu.org/licenses/>.  */
+
+extern float *y;
+
+static const double a[123];
+
+int
+main (int argc, char *argv[])
+{
+#pragma starpu initialize
+
+  int x[123] __attribute__ ((unused));
+  static char z[345] __attribute__ ((unused));
+
+#pragma starpu register x
+
+#pragma starpu release /* (error "parse error") */
+#pragma starpu release 123 /* (error "neither a pointer nor an array") */
+#pragma starpu release does_not_exit /* (error "unbound variable") */
+
+#pragma starpu release argc /* (error "neither a pointer nor an array") */
+#pragma starpu release y
+#pragma starpu release x
+
+#pragma starpu release x z			  /* (error "junk after") */
+
+  return 1;
+}

+ 61 - 0
gcc-plugin/tests/release.c

@@ -0,0 +1,61 @@
+/* GCC-StarPU
+   Copyright (C) 2012 Institut National de Recherche en Informatique et Automatique
+
+   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
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   GCC-StarPU is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GCC-StarPU.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Test whether `#pragma starpu release ...' generates the right code.  */
+
+#undef NDEBUG
+
+#include <mocks.h>
+
+static void
+foo (char *x, int foo)
+{
+  expected_release_arguments.pointer = x;
+#pragma starpu release x
+}
+
+
+int
+main (int argc, char *argv[])
+{
+#pragma starpu initialize
+
+  int x[123];
+  static char z[345];
+
+  expected_register_arguments.pointer = x;
+  expected_register_arguments.elements = 123;
+  expected_register_arguments.element_size = sizeof x[0];
+#pragma starpu register x
+
+  expected_release_arguments.pointer = x;
+#pragma starpu release x
+
+  expected_register_arguments.pointer = z;
+  expected_register_arguments.elements = sizeof z;
+  expected_register_arguments.element_size = sizeof z[0];
+#pragma starpu register z
+
+  expected_release_arguments.pointer = z;
+#pragma starpu release z
+
+  foo (z, 345);
+
+  assert (data_register_calls == 2);
+  assert (data_release_calls == 3);
+
+  return EXIT_SUCCESS;
+}