trans.h (caf_sync_memory): New function decl tree.
authorAlessandro Fanfarillo <fanfarillo.gcc@gmail.com>
Tue, 10 Mar 2015 17:58:01 +0000 (11:58 -0600)
committerTobias Burnus <burnus@gcc.gnu.org>
Tue, 10 Mar 2015 17:58:01 +0000 (18:58 +0100)
2015-03-10  Alessandro Fanfarillo  <fanfarillo.gcc@gmail.com>
            Tobias Burnus  <burnus@net-b.de>

        * trans.h (caf_sync_memory): New function decl tree.
        * trans-decl.c (gfc_build_builtin_function_decls): Define it.
        (create_main_function): Don't call sync_synchronize and leave
        it to the CAF library.
        * trans-stmt.c (gfc_trans_stop): Ditto.
        (gfc_trans_sync): Ditto; add call library call for sync memory.

        * gfortran.dg/coarray_sync_memory.f90: New.

        * caf/libcaf.h (_gfortran_caf_sync_memory): New prototype.
        * caf/single.c (_gfortran_caf_sync_memory): Implement.
        (_gfortran_caf_sync_all, _gfortran_caf_sync_image): Add
        __asm__ __volatile___ ("":::"memory").

Co-Authored-By: Tobias Burnus <burnus@net-b.de>
From-SVN: r221329

gcc/fortran/ChangeLog
gcc/fortran/trans-decl.c
gcc/fortran/trans-stmt.c
gcc/fortran/trans.h
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/coarray_sync_memory.f90 [new file with mode: 0644]
libgfortran/ChangeLog
libgfortran/caf/libcaf.h
libgfortran/caf/single.c

index 85eb3bb8fde06dbe3531d3858ac20be7b79c470b..ae6865eff416e507744ffb0efbf92db070a596f7 100644 (file)
@@ -1,3 +1,13 @@
+2015-03-10  Alessandro Fanfarillo  <fanfarillo.gcc@gmail.com>
+           Tobias Burnus  <burnus@net-b.de>
+
+       * trans.h (caf_sync_memory): New function decl tree.
+       * trans-decl.c (gfc_build_builtin_function_decls): Define it.
+       (create_main_function): Don't call sync_synchronize and leave
+       it to the CAF library.
+       * trans-stmt.c (gfc_trans_stop): Ditto.
+       (gfc_trans_sync): Ditto; add call library call for sync memory.
+
 2015-03-08  Mikael Morin  <mikael@gcc.gnu.org>
 
        PR fortran/60898
index 3664824ce09169e8949a0c5a571398dc1dc35a5f..769d487c7d9ea1a6d9dea2877f67cc507d539474 100644 (file)
@@ -153,6 +153,7 @@ tree gfor_fndecl_caf_get;
 tree gfor_fndecl_caf_send;
 tree gfor_fndecl_caf_sendget;
 tree gfor_fndecl_caf_sync_all;
+tree gfor_fndecl_caf_sync_memory;
 tree gfor_fndecl_caf_sync_images;
 tree gfor_fndecl_caf_error_stop;
 tree gfor_fndecl_caf_error_stop_str;
@@ -3451,6 +3452,10 @@ gfc_build_builtin_function_decls (void)
        get_identifier (PREFIX("caf_sync_all")), ".WW", void_type_node,
        3, pint_type, pchar_type_node, integer_type_node);
 
+      gfor_fndecl_caf_sync_memory = gfc_build_library_function_decl_with_spec (
+       get_identifier (PREFIX("caf_sync_memory")), ".WW", void_type_node,
+       3, pint_type, pchar_type_node, integer_type_node);
+
       gfor_fndecl_caf_sync_images = gfc_build_library_function_decl_with_spec (
        get_identifier (PREFIX("caf_sync_images")), ".RRWW", void_type_node,
        5, integer_type_node, pint_type, pint_type,
@@ -5583,12 +5588,6 @@ create_main_function (tree fndecl)
   /* Coarray: Call _gfortran_caf_finalize(void).  */
   if (flag_coarray == GFC_FCOARRAY_LIB)
     {
-      /* Per F2008, 8.5.1 END of the main program implies a
-        SYNC MEMORY.  */
-      tmp = builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE);
-      tmp = build_call_expr_loc (input_location, tmp, 0);
-      gfc_add_expr_to_block (&body, tmp);
-
       tmp = build_call_expr_loc (input_location, gfor_fndecl_caf_finalize, 0);
       gfc_add_expr_to_block (&body, tmp);
     }
index 505f9052cf693ce779bfa90f1a41d0207572cf15..6450a0ecec2df541821d2a7f69092ac10956765e 100644 (file)
@@ -639,17 +639,6 @@ gfc_trans_stop (gfc_code *code, bool error_stop)
   gfc_init_se (&se, NULL);
   gfc_start_block (&se.pre);
 
-  if (flag_coarray == GFC_FCOARRAY_LIB && !error_stop)
-    {
-      /* Per F2008, 8.5.1 STOP implies a SYNC MEMORY.  */
-      tmp = builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE);
-      tmp = build_call_expr_loc (input_location, tmp, 0);
-      gfc_add_expr_to_block (&se.pre, tmp);
-
-      tmp = build_call_expr_loc (input_location, gfor_fndecl_caf_finalize, 0);
-      gfc_add_expr_to_block (&se.pre, tmp);
-    }
-
   if (code->expr1 == NULL)
     {
       tmp = build_int_cst (gfc_int4_type_node, 0);
@@ -768,8 +757,7 @@ gfc_trans_sync (gfc_code *code, gfc_exec_op type)
   else
     stat = null_pointer_node;
 
-  if (code->expr3 && flag_coarray == GFC_FCOARRAY_LIB
-      && type != EXEC_SYNC_MEMORY)
+  if (code->expr3 && flag_coarray == GFC_FCOARRAY_LIB)
     {
       gcc_assert (code->expr3->expr_type == EXPR_VARIABLE);
       gfc_init_se (&argse, NULL);
@@ -778,7 +766,7 @@ gfc_trans_sync (gfc_code *code, gfc_exec_op type)
       errmsg = gfc_build_addr_expr (NULL, argse.expr);
       errmsglen = argse.string_length;
     }
-  else if (flag_coarray == GFC_FCOARRAY_LIB && type != EXEC_SYNC_MEMORY)
+  else if (flag_coarray == GFC_FCOARRAY_LIB)
     {
       errmsg = null_pointer_node;
       errmsglen = build_int_cst (integer_type_node, 0);
@@ -813,22 +801,13 @@ gfc_trans_sync (gfc_code *code, gfc_exec_op type)
                               fold_convert (integer_type_node, images));
     }
 
-   /* Per F2008, 8.5.1, a SYNC MEMORY is implied by calling the
-      image control statements SYNC IMAGES and SYNC ALL.  */
-   if (flag_coarray == GFC_FCOARRAY_LIB)
-     {
-       tmp = builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE);
-       tmp = build_call_expr_loc (input_location, tmp, 0);
-       gfc_add_expr_to_block (&se.pre, tmp);
-     }
-
-  if (flag_coarray != GFC_FCOARRAY_LIB || type == EXEC_SYNC_MEMORY)
+  if (flag_coarray != GFC_FCOARRAY_LIB)
     {
       /* Set STAT to zero.  */
       if (code->expr2)
        gfc_add_modify (&se.pre, stat, build_int_cst (TREE_TYPE (stat), 0));
     }
-  else if (type == EXEC_SYNC_ALL)
+  else if (type == EXEC_SYNC_ALL || type == EXEC_SYNC_MEMORY)
     {
       /* SYNC ALL           =>   stat == null_pointer_node
         SYNC ALL(stat=s)   =>   stat has an integer type
@@ -840,8 +819,13 @@ gfc_trans_sync (gfc_code *code, gfc_exec_op type)
          if (TREE_TYPE (stat) == integer_type_node)
            stat = gfc_build_addr_expr (NULL, stat);
 
-         tmp = build_call_expr_loc (input_location, gfor_fndecl_caf_sync_all,
-                                    3, stat, errmsg, errmsglen);
+         if(type == EXEC_SYNC_MEMORY)
+           tmp = build_call_expr_loc (input_location, gfor_fndecl_caf_sync_memory,
+                                      3, stat, errmsg, errmsglen);
+         else
+           tmp = build_call_expr_loc (input_location, gfor_fndecl_caf_sync_all,
+                                      3, stat, errmsg, errmsglen);
+
          gfc_add_expr_to_block (&se.pre, tmp);
        }
       else
index bd1520aeada83e9b40a71366c791c2801b9669ab..3ba2f88f0fddd4c8b9e98b33e5245cd5288f87f3 100644 (file)
@@ -731,6 +731,7 @@ extern GTY(()) tree gfor_fndecl_caf_get;
 extern GTY(()) tree gfor_fndecl_caf_send;
 extern GTY(()) tree gfor_fndecl_caf_sendget;
 extern GTY(()) tree gfor_fndecl_caf_sync_all;
+extern GTY(()) tree gfor_fndecl_caf_sync_memory;
 extern GTY(()) tree gfor_fndecl_caf_sync_images;
 extern GTY(()) tree gfor_fndecl_caf_error_stop;
 extern GTY(()) tree gfor_fndecl_caf_error_stop_str;
index 869dee04e653266ae7532d3ffe420f4e7958a514..b85edda7464a19f8f54353d87c6a40a7df2c497d 100644 (file)
@@ -1,3 +1,8 @@
+2015-03-10  Alessandro Fanfarillo  <fanfarillo.gcc@gmail.com>
+           Tobias Burnus  <burnus@net-b.de>
+
+       * gfortran.dg/coarray_sync_memory.f90: New.
+
 2015-03-10  Marek Polacek  <polacek@redhat.com>
 
        PR sanitizer/65367
diff --git a/gcc/testsuite/gfortran.dg/coarray_sync_memory.f90 b/gcc/testsuite/gfortran.dg/coarray_sync_memory.f90
new file mode 100644 (file)
index 0000000..6e1aee3
--- /dev/null
@@ -0,0 +1,19 @@
+! { dg-do compile }
+! { dg-options "-fdump-tree-original -fcoarray=lib" }
+!
+! Coarray sync memory managed by the external library
+!
+implicit none
+integer :: stat
+character(len=42) :: msg
+sync memory
+sync memory(stat=stat)
+sync memory(errmsg=msg)
+sync memory(errmsg=msg, stat=stat)
+end
+
+! { dg-final { scan-tree-dump-times "_gfortran_caf_sync_memory \\(0B, 0B, 0\\);" 1 "original" } }
+! { dg-final { scan-tree-dump-times "_gfortran_caf_sync_memory \\(&stat, 0B, 0\\);" 1 "original" } }
+! { dg-final { scan-tree-dump-times "_gfortran_caf_sync_memory \\(0B, &&msg, 42\\);" 1 "original" } }
+! { dg-final { scan-tree-dump-times "_gfortran_caf_sync_memory \\(&stat, &&msg, 42\\);" 1 "original" } }
+! { dg-final { cleanup-tree-dump "original" } }
index 612ed81a0398f4b40c04b67c4f8d92e20883b71c..184338aaede17def35542af022d6f1814685e384 100644 (file)
@@ -1,3 +1,11 @@
+2015-03-10  Alessandro Fanfarillo  <fanfarillo.gcc@gmail.com>
+           Tobias Burnus  <burnus@net-b.de>
+
+       * caf/libcaf.h (_gfortran_caf_sync_memory): New prototype.
+       * caf/single.c (_gfortran_caf_sync_memory): Implement.
+       (_gfortran_caf_sync_all, _gfortran_caf_sync_image): Add
+       __asm__ __volatile___ ("":::"memory").
+
 2015-02-10 Jerry DeLisle  <jvdelisle@gcc.gnu.org>
 
        PR libgfortran/57822
index bd5c9c62cbeb42ca2f1ee9d56a8135f78b468579..660bd7c094543a0c23174af4648841b3926e81af 100644 (file)
@@ -100,6 +100,7 @@ void *_gfortran_caf_register (size_t, caf_register_t, caf_token_t *, int *,
 void _gfortran_caf_deregister (caf_token_t *, int *, char *, int);
 
 void _gfortran_caf_sync_all (int *, char *, int);
+void _gfortran_caf_sync_memory (int *, char *, int);
 void _gfortran_caf_sync_images (int, int[], int *, char *, int);
 
 void _gfortran_caf_error_stop_str (const char *, int32_t)
index 7405c91846cad65da5e2bc4bfff97e4e56ab7fb0..daef281ef2ed19d68d9cfd70ee96869a064ef675 100644 (file)
@@ -162,6 +162,18 @@ _gfortran_caf_sync_all (int *stat,
                        char *errmsg __attribute__ ((unused)),
                        int errmsg_len __attribute__ ((unused)))
 {
+  __asm__ __volatile__ ("":::"memory");
+  if (stat)
+    *stat = 0;
+}
+
+
+void
+_gfortran_caf_sync_memory (int *stat,
+                          char *errmsg __attribute__ ((unused)),
+                          int errmsg_len __attribute__ ((unused)))
+{
+  __asm__ __volatile__ ("":::"memory");
   if (stat)
     *stat = 0;
 }
@@ -186,6 +198,7 @@ _gfortran_caf_sync_images (int count __attribute__ ((unused)),
       }
 #endif
 
+  __asm__ __volatile__ ("":::"memory");
   if (stat)
     *stat = 0;
 }