소스 검색

gcc: Add support for `#pragma starpu unregister VAR'.

* gcc-plugin/src/starpu.c (handle_pragma_unregister): New function.
  (register_pragmas): Register it.

* gcc-plugin/tests/Makefile.am (gcc_tests): Add `unregister.c' and
  `unregister-errors.c'.

* gcc-plugin/tests/lib.h (struct data_unregister_arguments): New struct.
  (data_unregister_calls, expected_unregister_arguments): New variables.
  (starpu_data_unregister): New function.

* gcc-plugin/tests/unregister-errors.c, gcc-plugin/tests/unregister.c:
  New files.
Ludovic Courtès 14 년 전
부모
커밋
f9e6bec364
6개의 변경된 파일160개의 추가작업 그리고 3개의 파일을 삭제
  1. 1 0
      .gitignore
  2. 34 0
      gcc-plugin/src/starpu.c
  3. 2 0
      gcc-plugin/tests/Makefile.am
  4. 25 3
      gcc-plugin/tests/lib.h
  5. 47 0
      gcc-plugin/tests/unregister-errors.c
  6. 51 0
      gcc-plugin/tests/unregister.c

+ 1 - 0
.gitignore

@@ -181,3 +181,4 @@ starpu.log
 /gcc-plugin/tests/run-test
 /gcc-plugin/tests/register-errors
 /gcc-plugin/tests/acquire
+/gcc-plugin/tests/unregister

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

@@ -540,6 +540,38 @@ handle_pragma_acquire (struct cpp_reader *reader)
 			     build_int_cst (integer_type_node, STARPU_RW)));
 }
 
+/* Process `#pragma starpu unregister VAR' and emit the corresponding
+   `starpu_data_unregister' call.  */
+
+static void
+handle_pragma_unregister (struct cpp_reader *reader)
+{
+  static tree unregister_fn;
+  LOOKUP_STARPU_FUNCTION (unregister_fn, "starpu_data_unregister");
+
+  tree token, var;
+  location_t loc;
+
+  loc = cpp_peek_token (reader, 0)->src_loc;
+
+  var = read_pragma_pointer_variable ("unregister", loc);
+  if (var == NULL_TREE)
+    return;
+
+  if (pragma_lex (&token) != CPP_EOF)
+    error_at (loc, "junk after %<starpu unregister%> 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_unregister (starpu_data_lookup (ptr))'.  */
+  add_stmt (build_call_expr (unregister_fn, 1,
+			     build_pointer_lookup (pointer)));
+}
+
 static void
 register_pragmas (void *gcc_data, void *user_data)
 {
@@ -553,6 +585,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, "unregister",
+				    handle_pragma_unregister);
 }
 
 

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

@@ -21,6 +21,8 @@ gcc_tests =					\
   register-errors.c				\
   acquire.c					\
   acquire-errors.c				\
+  unregister.c					\
+  unregister-errors.c				\
   task-errors.c					\
   scalar-tasks.c				\
   pointer-tasks.c				\

+ 25 - 3
gcc-plugin/tests/lib.h

@@ -228,11 +228,10 @@ struct data_acquire_arguments
   void *pointer;
 };
 
-/* Number of `starpu_vector_data_acquire' calls.  */
+/* Number of `starpu_data_acquire' calls.  */
 static unsigned int data_acquire_calls;
 
-/* Variable describing the expected `starpu_vector_data_acquire'
-   arguments.  */
+/* Variable describing the expected `starpu_data_acquire' arguments.  */
 struct data_acquire_arguments expected_acquire_arguments;
 
 int
@@ -249,6 +248,29 @@ starpu_data_acquire (starpu_data_handle handle, starpu_access_mode mode)
 }
 
 
+/* Data acquisition.  */
+
+struct data_unregister_arguments
+{
+  /* Pointer to the data being unregistered.  */
+  void *pointer;
+};
+
+/* Number of `starpu_data_unregister' calls.  */
+static unsigned int data_unregister_calls;
+
+/* Variable describing the expected `starpu_data_unregister' arguments.  */
+struct data_unregister_arguments expected_unregister_arguments;
+
+void
+starpu_data_unregister (starpu_data_handle handle)
+{
+  assert (dummy_handle_to_pointer (handle)
+	  == expected_unregister_arguments.pointer);
+  data_unregister_calls++;
+}
+
+
 /* Initialization.  */
 
 static int initialized;

+ 47 - 0
gcc-plugin/tests/unregister-errors.c

@@ -0,0 +1,47 @@
+/* GCC-StarPU
+   Copyright (C) 2011 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 unregister /* (error "unterminated") */
+#pragma starpu unregister 123 /* (error "identifier expected") */
+#pragma starpu unregister does_not_exit /* (error "unbound variable") */
+
+#pragma starpu unregister argc /* (error "neither a pointer nor an array") */
+#pragma starpu unregister y
+#pragma starpu unregister x
+
+  /* XXX: Uncomment below when this is supported.  */
+#if 0
+#pragma starpu unregister z /* error "not registered" */
+#pragma starpu unregister a /* error "not registered" */
+#pragma starpu unregister argv /* error "not registered" */
+#endif
+
+  return 1;
+}

+ 51 - 0
gcc-plugin/tests/unregister.c

@@ -0,0 +1,51 @@
+/* GCC-StarPU
+   Copyright (C) 2011 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 unregister ...' generates the right code.  */
+
+#undef NDEBUG
+
+#include <lib.h>
+
+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_unregister_arguments.pointer = x;
+#pragma starpu unregister 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_unregister_arguments.pointer = z;
+#pragma starpu unregister z
+
+  assert (data_register_calls == 2);
+  assert (data_unregister_calls == 2);
+
+  return EXIT_SUCCESS;
+}