trans-array.c (gfc_array_allocate): Rename allocatable_array
authorDaniel Carrera <dcarrera@gmail.com>
Wed, 6 Jul 2011 20:57:03 +0000 (20:57 +0000)
committerTobias Burnus <burnus@gcc.gnu.org>
Wed, 6 Jul 2011 20:57:03 +0000 (22:57 +0200)
2011-07-06  Daniel Carrera <dcarrera@gmail.com>

        * trans-array.c (gfc_array_allocate): Rename allocatable_array
        * to
        allocatable. Rename function gfc_allocate_array_with_status to
        gfc_allocate_allocatable_with_status. Update function call for
        gfc_allocate_with_status.
        * trans-opemp.c (gfc_omp_clause_default_ctor): Rename function
        gfc_allocate_array_with_status to gfc_allocate_allocatable_with_status.
        * trans-stmt.c (gfc_trans_allocate): Update function call for
        gfc_allocate_with_status. Rename function gfc_allocate_array_with_status
        to gfc_allocate_allocatable_with_status.
        * trans.c (gfc_call_malloc): Add new parameter
        * gfc_allocate_with_status
        so it uses the library for memory allocation when -fcoarray=lib.
        (gfc_allocate_allocatable_with_status): Renamed from
        gfc_allocate_array_with_status.
        (gfc_allocate_allocatable_with_status): Update function call for
        gfc_allocate_with_status.
        * trans.h (gfc_coarray_type): New enum.
        (gfc_allocate_with_status): Update prototype.
        (gfc_allocate_allocatable_with_status): Renamed from
        gfc_allocate_array_with_status.
        * trans-decl.c (generate_coarray_sym_init): Use the new constant
        GFC_CAF_COARRAY_ALLOC in the call to gfor_fndecl_caf_register.

From-SVN: r175937

gcc/fortran/ChangeLog
gcc/fortran/trans-array.c
gcc/fortran/trans-decl.c
gcc/fortran/trans-openmp.c
gcc/fortran/trans-stmt.c
gcc/fortran/trans.c
gcc/fortran/trans.h

index 90a95d031f838e57b5933acf9f915887f394c9f1..75693cc4a6090946397f2af682ec42338ae21034 100644 (file)
@@ -1,3 +1,27 @@
+2011-07-06  Daniel Carrera <dcarrera@gmail.com>
+
+       * trans-array.c (gfc_array_allocate): Rename allocatable_array to
+       allocatable. Rename function gfc_allocate_array_with_status to 
+       gfc_allocate_allocatable_with_status. Update function call for
+       gfc_allocate_with_status.
+       * trans-opemp.c (gfc_omp_clause_default_ctor): Rename function
+       gfc_allocate_array_with_status to gfc_allocate_allocatable_with_status.
+       * trans-stmt.c (gfc_trans_allocate): Update function call for
+       gfc_allocate_with_status. Rename function gfc_allocate_array_with_status
+       to gfc_allocate_allocatable_with_status.
+       * trans.c (gfc_call_malloc): Add new parameter gfc_allocate_with_status
+       so it uses the library for memory allocation when -fcoarray=lib.
+       (gfc_allocate_allocatable_with_status): Renamed from
+       gfc_allocate_array_with_status.
+       (gfc_allocate_allocatable_with_status): Update function call for
+       gfc_allocate_with_status.
+       * trans.h (gfc_coarray_type): New enum.
+       (gfc_allocate_with_status): Update prototype.
+       (gfc_allocate_allocatable_with_status): Renamed from
+       gfc_allocate_array_with_status.
+       * trans-decl.c (generate_coarray_sym_init): Use the new constant
+       GFC_CAF_COARRAY_ALLOC in the call to gfor_fndecl_caf_register.
+
 2011-07-06  Richard Guenther  <rguenther@suse.de>
 
        * f95-lang.c (gfc_init_decl_processing):
index 4c21389dcb3011500a3fdaaccacf6e8b8c24905f..f4f79f941617afe0f16966be35c2f5d505e11a48 100644 (file)
@@ -4381,7 +4381,7 @@ gfc_array_allocate (gfc_se * se, gfc_expr * expr, tree pstat)
   gfc_expr **lower;
   gfc_expr **upper;
   gfc_ref *ref, *prev_ref = NULL;
-  bool allocatable_array, coarray;
+  bool allocatable, coarray;
 
   ref = expr->ref;
 
@@ -4399,12 +4399,12 @@ gfc_array_allocate (gfc_se * se, gfc_expr * expr, tree pstat)
 
   if (!prev_ref)
     {
-      allocatable_array = expr->symtree->n.sym->attr.allocatable;
+      allocatable = expr->symtree->n.sym->attr.allocatable;
       coarray = expr->symtree->n.sym->attr.codimension;
     }
   else
     {
-      allocatable_array = prev_ref->u.c.component->attr.allocatable;
+      allocatable = prev_ref->u.c.component->attr.allocatable;
       coarray = prev_ref->u.c.component->attr.codimension;
     }
 
@@ -4485,10 +4485,11 @@ gfc_array_allocate (gfc_se * se, gfc_expr * expr, tree pstat)
   STRIP_NOPS (pointer);
 
   /* The allocate_array variants take the old pointer as first argument.  */
-  if (allocatable_array)
-    tmp = gfc_allocate_array_with_status (&elseblock, pointer, size, pstat, expr);
+  if (allocatable)
+    tmp = gfc_allocate_allocatable_with_status (&elseblock,
+                                               pointer, size, pstat, expr);
   else
-    tmp = gfc_allocate_with_status (&elseblock, size, pstat);
+    tmp = gfc_allocate_with_status (&elseblock, size, pstat, false);
   tmp = fold_build2_loc (input_location, MODIFY_EXPR, void_type_node, pointer,
                         tmp);
 
index cca1beb2ce8cb7f07a801afc8e28a587321977d5..ddc7c36d98fb97a419bf577f9297a5fd60ef4736 100644 (file)
@@ -4167,7 +4167,8 @@ generate_coarray_sym_init (gfc_symbol *sym)
                               GFC_TYPE_ARRAY_CAF_TOKEN (TREE_TYPE(decl)));
 
   tmp = build_call_expr_loc (input_location, gfor_fndecl_caf_register, 6, size,
-                            build_int_cst (integer_type_node, 0), /* type.  */
+                            build_int_cst (integer_type_node,
+                                           GFC_CAF_COARRAY_ALLOC), /* type.  */
                             token, null_pointer_node, /* token, stat.  */
                             null_pointer_node, /* errgmsg, errmsg_len.  */
                             build_int_cst (integer_type_node, 0));
index 9677659fd4795faab7da9d2cfb86965503d71ea0..aff8554009ce127d924088e284c5751b650cc50b 100644 (file)
@@ -188,9 +188,9 @@ gfc_omp_clause_default_ctor (tree clause, tree decl, tree outer)
   size = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type,
                          size, esize);
   size = gfc_evaluate_now (fold_convert (size_type_node, size), &cond_block);
-  ptr = gfc_allocate_array_with_status (&cond_block,
-                                       build_int_cst (pvoid_type_node, 0),
-                                       size, NULL, NULL);
+  ptr = gfc_allocate_allocatable_with_status (&cond_block,
+                                             build_int_cst (pvoid_type_node, 0),
+                                             size, NULL, NULL);
   gfc_conv_descriptor_data_set (&cond_block, decl, ptr);
   then_b = gfc_finish_block (&cond_block);
 
@@ -241,9 +241,9 @@ gfc_omp_clause_copy_ctor (tree clause, tree dest, tree src)
   size = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type,
                          size, esize);
   size = gfc_evaluate_now (fold_convert (size_type_node, size), &block);
-  ptr = gfc_allocate_array_with_status (&block,
-                                       build_int_cst (pvoid_type_node, 0),
-                                       size, NULL, NULL);
+  ptr = gfc_allocate_allocatable_with_status (&block,
+                                             build_int_cst (pvoid_type_node, 0),
+                                             size, NULL, NULL);
   gfc_conv_descriptor_data_set (&block, dest, ptr);
   call = build_call_expr_loc (input_location,
                          built_in_decls[BUILT_IN_MEMCPY], 3, ptr,
@@ -663,9 +663,9 @@ gfc_trans_omp_array_reduction (tree c, gfc_symbol *sym, locus where)
       size = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type,
                              size, esize);
       size = gfc_evaluate_now (fold_convert (size_type_node, size), &block);
-      ptr = gfc_allocate_array_with_status (&block,
-                                           build_int_cst (pvoid_type_node, 0),
-                                           size, NULL, NULL);
+      ptr = gfc_allocate_allocatable_with_status (&block,
+                                                 build_int_cst (pvoid_type_node, 0),
+                                                 size, NULL, NULL);
       gfc_conv_descriptor_data_set (&block, decl, ptr);
       gfc_add_expr_to_block (&block, gfc_trans_assignment (e1, e2, false,
                             false));
index f3347a6a238a9b49b68545e0229a74be592a3180..88fdcd182d0add26e469ae071fd3e1456d6edb92 100644 (file)
@@ -4847,10 +4847,10 @@ gfc_trans_allocate (gfc_code * code)
 
          /* Allocate - for non-pointers with re-alloc checking.  */
          if (gfc_expr_attr (expr).allocatable)
-           tmp = gfc_allocate_array_with_status (&se.pre, se.expr, memsz,
-                                                 pstat, expr);
+           tmp = gfc_allocate_allocatable_with_status (&se.pre, se.expr, memsz,
+                                                       pstat, expr);
          else
-           tmp = gfc_allocate_with_status (&se.pre, memsz, pstat);
+           tmp = gfc_allocate_with_status (&se.pre, memsz, pstat, false);
 
          tmp = fold_build2_loc (input_location, MODIFY_EXPR, void_type_node,
                                 se.expr,
index 33593c5626adb85f0fd52e9436d2acc493fa9344..683e3f1e48bb7773b53f0e56e0248379635fde55 100644 (file)
@@ -585,7 +585,8 @@ gfc_call_malloc (stmtblock_t * block, tree type, tree size)
       return newmem;
     }  */
 tree
-gfc_allocate_with_status (stmtblock_t * block, tree size, tree status)
+gfc_allocate_with_status (stmtblock_t * block, tree size, tree status,
+                         bool coarray_lib)
 {
   stmtblock_t alloc_block;
   tree res, tmp, msg, cond;
@@ -616,14 +617,29 @@ gfc_allocate_with_status (stmtblock_t * block, tree size, tree status)
 
   /* The allocation itself.  */
   gfc_start_block (&alloc_block);
-  gfc_add_modify (&alloc_block, res,
-                 fold_convert (prvoid_type_node,
-                               build_call_expr_loc (input_location,
-                                  built_in_decls[BUILT_IN_MALLOC], 1,
-                                       fold_build2_loc (input_location,
-                                           MAX_EXPR, size_type_node, size,
-                                           build_int_cst (size_type_node,
-                                                          1)))));
+  if (coarray_lib)
+    {
+      gfc_add_modify (&alloc_block, res,
+             fold_convert (prvoid_type_node,
+                   build_call_expr_loc (input_location,
+                        gfor_fndecl_caf_register, 3,
+                        fold_build2_loc (input_location,
+                                 MAX_EXPR, size_type_node, size,
+                                 build_int_cst (size_type_node, 1)),
+                        build_int_cst (integer_type_node,
+                                       GFC_CAF_COARRAY_ALLOC),
+                        null_pointer_node)));  /* Token */
+    }
+  else
+    {
+      gfc_add_modify (&alloc_block, res,
+             fold_convert (prvoid_type_node,
+                   build_call_expr_loc (input_location,
+                        built_in_decls[BUILT_IN_MALLOC], 1,
+                        fold_build2_loc (input_location,
+                                 MAX_EXPR, size_type_node, size,
+                                 build_int_cst (size_type_node, 1)))));
+    }
 
   msg = gfc_build_addr_expr (pchar_type_node, gfc_build_localized_cstring_const
                             ("Allocation would exceed memory limit"));
@@ -658,13 +674,13 @@ gfc_allocate_with_status (stmtblock_t * block, tree size, tree status)
 
 
 /* Generate code for an ALLOCATE statement when the argument is an
-   allocatable array.  If the array is currently allocated, it is an
+   allocatable variable.  If the variable is currently allocated, it is an
    error to allocate it again.
  
    This function follows the following pseudo-code:
   
     void *
-    allocate_array (void *mem, size_t size, integer_type *stat)
+    allocate_allocatable (void *mem, size_t size, integer_type *stat)
     {
       if (mem == NULL)
        return allocate (size, stat);
@@ -685,8 +701,8 @@ gfc_allocate_with_status (stmtblock_t * block, tree size, tree status)
     expr must be set to the original expression being allocated for its locus
     and variable name in case a runtime error has to be printed.  */
 tree
-gfc_allocate_array_with_status (stmtblock_t * block, tree mem, tree size,
-                               tree status, gfc_expr* expr)
+gfc_allocate_allocatable_with_status (stmtblock_t * block, tree mem, tree size,
+                                     tree status, gfc_expr* expr)
 {
   stmtblock_t alloc_block;
   tree res, tmp, null_mem, alloc, error;
@@ -703,11 +719,15 @@ gfc_allocate_array_with_status (stmtblock_t * block, tree mem, tree size,
 
   /* If mem is NULL, we call gfc_allocate_with_status.  */
   gfc_start_block (&alloc_block);
-  tmp = gfc_allocate_with_status (&alloc_block, size, status);
+  tmp = gfc_allocate_with_status (&alloc_block, size, status,
+                                 gfc_option.coarray == GFC_FCOARRAY_LIB
+                                 && gfc_expr_attr (expr).codimension);
+
   gfc_add_modify (&alloc_block, res, fold_convert (type, tmp));
   alloc = gfc_finish_block (&alloc_block);
 
-  /* Otherwise, we issue a runtime error or set the status variable.  */
+  /* If mem is not NULL, we issue a runtime error or set the
+     status variable.  */
   if (expr)
     {
       tree varname;
@@ -737,7 +757,7 @@ gfc_allocate_array_with_status (stmtblock_t * block, tree mem, tree size,
                             fold_convert (pvoid_type_node, mem));
       gfc_add_expr_to_block (&set_status_block, tmp);
 
-      tmp = gfc_allocate_with_status (&set_status_block, size, status);
+      tmp = gfc_allocate_with_status (&set_status_block, size, status, false);
       gfc_add_modify (&set_status_block, res, fold_convert (type, tmp));
 
       gfc_add_modify (&set_status_block,
index e14e41f8a25db91d7883ad144e4259904e1f2df9..c56aff8ddd088a6dfcdc1b46d92e03bd5132e021 100644 (file)
@@ -94,6 +94,18 @@ typedef struct gfc_se
 gfc_se;
 
 
+/* Denotes different types of coarray.
+   Please keep in sync with libgfortran/caf/libcaf.h.  */
+typedef enum 
+{
+  GFC_CAF_COARRAY_STATIC,
+  GFC_CAF_COARRAY_ALLOC,
+  GFC_CAF_LOCK,
+  GFC_CAF_LOCK_COMP
+}
+gfc_coarray_type;
+
+
 /* Scalarization State chain.  Created by walking an expression tree before
    creating the scalarization loops. Then passed as part of a gfc_se structure
    to translate the expression inside the loop.  Note that these chains are
@@ -528,11 +540,12 @@ tree gfc_call_malloc (stmtblock_t *, tree, tree);
 /* Build a memcpy call.  */
 tree gfc_build_memcpy_call (tree, tree, tree);
 
-/* Allocate memory for arrays, with optional status variable.  */
-tree gfc_allocate_array_with_status (stmtblock_t*, tree, tree, tree, gfc_expr*);
+/* Allocate memory for allocatable variables, with optional status variable.  */
+tree gfc_allocate_allocatable_with_status (stmtblock_t*,
+                                          tree, tree, tree, gfc_expr*);
 
 /* Allocate memory, with optional status variable.  */
-tree gfc_allocate_with_status (stmtblock_t *, tree, tree);
+tree gfc_allocate_with_status (stmtblock_t *, tree, tree, bool);
 
 /* Generate code to deallocate an array.  */
 tree gfc_deallocate_with_status (tree, tree, bool, gfc_expr*);