[gomp] Add langhook, so that Fortran can privatize variables by reference
Jakub Jelinek
jakub@redhat.com
Tue Oct 18 08:45:00 GMT 2005
Hi!
>From my testing so far, all Fortran user vars that have POINTER_TYPE
type (in addition to the already handled REFERENCE_TYPE)
are supposed to be privatized with the type they point to rather than
just as a pointer type (Fortran POINTER, ALLOCATABLE and from what I saw,
also Cray pointers in the patch that is floating around, use either an
aggregate type or a simple INTEGER_TYPE).
Fixes reference2.f90 (and some tests in openmpbench_F_v2, though there are
still unrelated problems), approved privately by Richard, committed.
2005-10-18 Jakub Jelinek <jakub@redhat.com>
* langhooks.h (struct lang_hooks_for_decls): Add
omp_privatize_by_reference hook.
* langhooks-def.h (lhd_omp_privatize_by_reference): New prototype.
(LANG_HOOKS_OMP_PRIVATIZE_BY_REFERENCE): Define.
(LANG_HOOKS_DECLS): Add LANG_HOOKS_OMP_PRIVATIZE_BY_REFERENCE.
* langhooks.c (lhd_omp_privatize_by_reference): New function.
* omp-low.c (is_reference): Call omp_privatize_by_reference
langhook.
fortran/
* trans.h (gfc_omp_privatize_by_reference): New prototype.
* f95-lang.c (LANG_HOOKS_OMP_PRIVATIZE_BY_REFERENCE): Redefine
to gfc_omp_privatize_by_reference.
* trans-openmp.c (gfc_omp_privatize_by_reference): New function.
* trans-stmt.h (gfc_trans_omp_directive): Add comment.
--- gcc/omp-low.c.jj 2005-10-15 12:00:06.000000000 +0200
+++ gcc/omp-low.c 2005-10-18 08:46:23.000000000 +0200
@@ -126,7 +126,7 @@ is_variable_sized (tree expr)
static inline bool
is_reference (tree decl)
{
- return TREE_CODE (TREE_TYPE (decl)) == REFERENCE_TYPE;
+ return lang_hooks.decls.omp_privatize_by_reference (decl);
}
/* Lookup variables in the decl or field splay trees. The "maybe" form
--- gcc/langhooks.h.jj 2005-09-13 15:12:55.000000000 +0200
+++ gcc/langhooks.h 2005-10-18 08:46:23.000000000 +0200
@@ -192,6 +192,10 @@ struct lang_hooks_for_decls
value will be the string already stored in an
IDENTIFIER_NODE.) */
const char * (*comdat_group) (tree);
+
+ /* True if OpenMP should privatize what this DECL points to rather
+ than the DECL itself. */
+ bool (*omp_privatize_by_reference) (tree);
};
/* Language-specific hooks. See langhooks-def.h for defaults. */
--- gcc/fortran/trans.h.jj 2005-10-17 09:04:27.000000000 +0200
+++ gcc/fortran/trans.h 2005-10-18 08:46:23.000000000 +0200
@@ -440,6 +440,9 @@ tree gfc_truthvalue_conversion (tree);
tree builtin_function (const char *, tree, int, enum built_in_class,
const char *, tree);
+/* In trans-openmp.c */
+bool gfc_omp_privatize_by_reference (tree);
+
/* Runtime library function decls. */
extern GTY(()) tree gfor_fndecl_internal_malloc;
extern GTY(()) tree gfor_fndecl_internal_malloc64;
--- gcc/fortran/trans-openmp.c.jj 2005-10-12 15:29:25.000000000 +0200
+++ gcc/fortran/trans-openmp.c 2005-10-18 08:46:23.000000000 +0200
@@ -37,6 +37,24 @@ Software Foundation, 51 Franklin Street,
#include "arith.h"
+/* True if OpenMP should privatize what this DECL points to rather
+ than the DECL itself. */
+
+bool
+gfc_omp_privatize_by_reference (tree decl)
+{
+ tree type = TREE_TYPE (decl);
+
+ if (TREE_CODE (type) == REFERENCE_TYPE)
+ return true;
+
+ /* POINTER/ALLOCATABLE have aggregate types, all user variables
+ that have POINTER_TYPE type are supposed to be privatized
+ by reference. */
+ return !DECL_ARTIFICIAL (decl) && TREE_CODE (type) == POINTER_TYPE;
+}
+
+
static inline tree
gfc_trans_add_clause (tree node, tree tail)
{
--- gcc/fortran/trans-stmt.h.jj 2005-09-20 10:25:18.000000000 +0200
+++ gcc/fortran/trans-stmt.h 2005-10-18 08:46:23.000000000 +0200
@@ -50,6 +50,8 @@ tree gfc_trans_where (gfc_code *);
tree gfc_trans_allocate (gfc_code *);
tree gfc_trans_deallocate (gfc_code *);
tree gfc_trans_deallocate_array (tree);
+
+/* trans-openmp.c */
tree gfc_trans_omp_directive (gfc_code *);
/* trans-io.c */
--- gcc/fortran/f95-lang.c.jj 2005-10-17 09:04:26.000000000 +0200
+++ gcc/fortran/f95-lang.c 2005-10-18 08:46:23.000000000 +0200
@@ -116,6 +116,7 @@ static void gfc_expand_function (tree);
#undef LANG_HOOKS_SIGNED_OR_UNSIGNED_TYPE
#undef LANG_HOOKS_CALLGRAPH_EXPAND_FUNCTION
#undef LANG_HOOKS_CLEAR_BINDING_STACK
+#undef LANG_HOOKS_OMP_PRIVATIZE_BY_REFERENCE
/* Define lang hooks. */
#define LANG_HOOKS_NAME "GNU F95"
@@ -134,6 +135,7 @@ static void gfc_expand_function (tree);
#define LANG_HOOKS_SIGNED_OR_UNSIGNED_TYPE gfc_signed_or_unsigned_type
#define LANG_HOOKS_CALLGRAPH_EXPAND_FUNCTION gfc_expand_function
#define LANG_HOOKS_CLEAR_BINDING_STACK gfc_clear_binding_stack
+#define LANG_HOOKS_OMP_PRIVATIZE_BY_REFERENCE gfc_omp_privatize_by_reference
const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
--- gcc/langhooks.c.jj 2005-09-17 20:43:39.000000000 +0200
+++ gcc/langhooks.c 2005-10-18 08:50:13.000000000 +0200
@@ -456,6 +456,15 @@ lhd_comdat_group (tree decl)
return IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
}
+/* True if OpenMP should privatize what this DECL points to rather
+ than the DECL itself. */
+
+bool
+lhd_omp_privatize_by_reference (tree decl ATTRIBUTE_UNUSED)
+{
+ return false;
+}
+
/* lang_hooks.decls.final_write_globals: perform final processing on
global variables. */
void
--- gcc/langhooks-def.h.jj 2005-09-13 15:12:55.000000000 +0200
+++ gcc/langhooks-def.h 2005-10-18 08:46:23.000000000 +0200
@@ -70,6 +70,7 @@ extern tree lhd_expr_size (tree);
extern size_t lhd_tree_size (enum tree_code);
extern HOST_WIDE_INT lhd_to_target_charset (HOST_WIDE_INT);
extern tree lhd_expr_to_decl (tree, bool *, bool *, bool *);
+extern bool lhd_omp_privatize_by_reference (tree);
/* Declarations of default tree inlining hooks. */
extern tree lhd_tree_inlining_walk_subtrees (tree *, int *, walk_tree_fn,
@@ -239,6 +240,7 @@ extern tree lhd_make_node (enum tree_cod
#define LANG_HOOKS_PREPARE_ASSEMBLE_VARIABLE NULL
#define LANG_HOOKS_DECL_OK_FOR_SIBCALL lhd_decl_ok_for_sibcall
#define LANG_HOOKS_COMDAT_GROUP lhd_comdat_group
+#define LANG_HOOKS_OMP_PRIVATIZE_BY_REFERENCE lhd_omp_privatize_by_reference
#define LANG_HOOKS_DECLS { \
LANG_HOOKS_GLOBAL_BINDINGS_P, \
@@ -249,7 +251,8 @@ extern tree lhd_make_node (enum tree_cod
LANG_HOOKS_WRITE_GLOBALS, \
LANG_HOOKS_PREPARE_ASSEMBLE_VARIABLE, \
LANG_HOOKS_DECL_OK_FOR_SIBCALL, \
- LANG_HOOKS_COMDAT_GROUP \
+ LANG_HOOKS_COMDAT_GROUP, \
+ LANG_HOOKS_OMP_PRIVATIZE_BY_REFERENCE \
}
/* The whole thing. The structure is defined in langhooks.h. */
Jakub
More information about the Fortran
mailing list