From d58e7173ef964ddac3ab3ad8cc97de8f9f3b32ee Mon Sep 17 00:00:00 2001 From: Tobias Burnus Date: Wed, 26 Aug 2020 09:32:40 +0200 Subject: Fortran: Add 'device_type' clause to OpenMP's declare target gcc/fortran/ChangeLog: * gfortran.h (enum gfc_omp_device_type): New. (symbol_attribute, gfc_omp_clauses, gfc_common_head): Use it. * module.c (enum ab_attribute): Add AB_OMP_DEVICE_TYPE_HOST, AB_OMP_DEVICE_TYPE_NOHOST and AB_OMP_DEVICE_TYPE_ANY. (attr_bits, mio_symbol_attribute): Handle it. (load_commons, write_common_0): Handle omp_device_type flag. * openmp.c (enum omp_mask1): Add OMP_CLAUSE_DEVICE_TYPE (OMP_DECLARE_TARGET_CLAUSES): Likewise. (gfc_match_omp_clauses): Match 'device_type'. (gfc_match_omp_declare_target): Handle it. * trans-common.c (build_common_decl): Write device-type clause. * trans-decl.c (add_attributes_to_decl): Likewise. gcc/testsuite/ChangeLog: * gfortran.dg/gomp/declare-target-4.f90: New test. * gfortran.dg/gomp/declare-target-5.f90: New test. --- gcc/fortran/module.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'gcc/fortran/module.c') diff --git a/gcc/fortran/module.c b/gcc/fortran/module.c index 5114d55..714fbd9 100644 --- a/gcc/fortran/module.c +++ b/gcc/fortran/module.c @@ -2051,7 +2051,8 @@ enum ab_attribute AB_OMP_REQ_REVERSE_OFFLOAD, AB_OMP_REQ_UNIFIED_ADDRESS, AB_OMP_REQ_UNIFIED_SHARED_MEMORY, AB_OMP_REQ_DYNAMIC_ALLOCATORS, AB_OMP_REQ_MEM_ORDER_SEQ_CST, AB_OMP_REQ_MEM_ORDER_ACQ_REL, - AB_OMP_REQ_MEM_ORDER_RELAXED + AB_OMP_REQ_MEM_ORDER_RELAXED, AB_OMP_DEVICE_TYPE_NOHOST, + AB_OMP_DEVICE_TYPE_HOST, AB_OMP_DEVICE_TYPE_ANY }; static const mstring attr_bits[] = @@ -2132,6 +2133,9 @@ static const mstring attr_bits[] = minit ("OMP_REQ_MEM_ORDER_SEQ_CST", AB_OMP_REQ_MEM_ORDER_SEQ_CST), minit ("OMP_REQ_MEM_ORDER_ACQ_REL", AB_OMP_REQ_MEM_ORDER_ACQ_REL), minit ("OMP_REQ_MEM_ORDER_RELAXED", AB_OMP_REQ_MEM_ORDER_RELAXED), + minit ("OMP_DEVICE_TYPE_HOST", AB_OMP_DEVICE_TYPE_HOST), + minit ("OMP_DEVICE_TYPE_NOHOST", AB_OMP_DEVICE_TYPE_NOHOST), + minit ("OMP_DEVICE_TYPE_ANYHOST", AB_OMP_DEVICE_TYPE_ANY), minit (NULL, -1) }; @@ -2397,6 +2401,22 @@ mio_symbol_attribute (symbol_attribute *attr) == OMP_REQ_ATOMIC_MEM_ORDER_RELAXED) MIO_NAME (ab_attribute) (AB_OMP_REQ_MEM_ORDER_RELAXED, attr_bits); } + switch (attr->omp_device_type) + { + case OMP_DEVICE_TYPE_UNSET: + break; + case OMP_DEVICE_TYPE_HOST: + MIO_NAME (ab_attribute) (AB_OMP_DEVICE_TYPE_HOST, attr_bits); + break; + case OMP_DEVICE_TYPE_NOHOST: + MIO_NAME (ab_attribute) (AB_OMP_DEVICE_TYPE_NOHOST, attr_bits); + break; + case OMP_DEVICE_TYPE_ANY: + MIO_NAME (ab_attribute) (AB_OMP_DEVICE_TYPE_ANY, attr_bits); + break; + default: + gcc_unreachable (); + } mio_rparen (); } else @@ -2661,6 +2681,15 @@ mio_symbol_attribute (symbol_attribute *attr) "relaxed", &gfc_current_locus, module_name); break; + case AB_OMP_DEVICE_TYPE_HOST: + attr->omp_device_type = OMP_DEVICE_TYPE_HOST; + break; + case AB_OMP_DEVICE_TYPE_NOHOST: + attr->omp_device_type = OMP_DEVICE_TYPE_NOHOST; + break; + case AB_OMP_DEVICE_TYPE_ANY: + attr->omp_device_type = OMP_DEVICE_TYPE_ANY; + break; } } } @@ -4849,6 +4878,7 @@ load_commons (void) p->saved = 1; if (flags & 2) p->threadprivate = 1; + p->omp_device_type = (gfc_omp_device_type) ((flags >> 2) & 3); p->use_assoc = 1; /* Get whether this was a bind(c) common or not. */ @@ -5713,6 +5743,7 @@ write_common_0 (gfc_symtree *st, bool this_module) flags = p->saved ? 1 : 0; if (p->threadprivate) flags |= 2; + flags |= p->omp_device_type << 2; mio_integer (&flags); /* Write out whether the common block is bind(c) or not. */ -- cgit v1.1