From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa2.mentor.iphmx.com (esa2.mentor.iphmx.com [68.232.141.98]) by sourceware.org (Postfix) with ESMTPS id 226293882667; Tue, 5 Sep 2023 19:30:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 226293882667 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="6.02,229,1688457600"; d="scan'208";a="18105091" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 05 Sep 2023 11:30:15 -0800 IronPort-SDR: wYf8wMraZOc48qKyeKTNBrl8UF/59D4Bw8h9apar5ywS6bDDCKcTz9TeKs7IpxMs1PRdQnqTV6 398uqU8DCI/LUdtBsadRl+Ww/DDNdQsZyuQfNsVGP/0Rnq7Y3Yk6plIe4w/FJQDdyuKUH4Hxqs KpY5RmP0iH1yCxgTRGA9udFqcfpojFxduJpEgETyoYric6lepVtIBlnVCYR0gapTKyUPh6Q2Wx ftd8Y+aypyhxRHs0h8JC6gc/NE89TlhqX1j96GfnCvg11oRLH199ziRcNoTVqaX8WmV46hbvJI 9QI= From: Julian Brown To: CC: , , Subject: [PATCH 6/8] OpenMP, Fortran: Per-directive control for gfc_trans_omp_clauses Date: Tue, 5 Sep 2023 12:28:26 -0700 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-14.mgc.mentorg.com (139.181.222.14) To svr-ies-mbx-11.mgc.mentorg.com (139.181.222.11) X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,GIT_PATCH_0,HEADER_FROM_DIFFERENT_DOMAINS,KAM_DMARC_STATUS,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Some of the processing done by gfc_trans_omp_clauses depends on the directive that that clause is attached to. This patch refactors two booleans and one gfc_exec_op parameter for gfc_trans_omp_clauses into a single parameter of (new) enumerated type 'toc_directive'. The same parameter is also passed to gfc_trans_omp_array_section instead of a gfc_exec_op type parameter and an 'openmp' boolean. This is mostly done in aid of the patch later in the series implementing "declare mapper" support for Fortran. There shouldn't be any behavioural changes introduced by this patch. 2023-09-05 Julian Brown gcc/fortran/ * gfortran.h (toc_directive): New enum. * trans-openmp.cc (gfc_trans_omp_array_section): Take toc_directive parameter instead of gfc_exec_op and 'openmp' boolean. (gfc_trans_omp_clauses): Take toc_directive parameter instead of 'declare_simd', 'openacc' and gfc_exec_op 'op' parameters. (gfc_trans_oacc_construct, gfc_trans_oacc_executable_directive, gfc_trans_oacc_combined_directive, gfc_trans_omp_target_exit_data, gfc_trans_oacc_declare, gfc_trans_omp_declare_simd, gfc_trans_omp_declare_variant): Update calls to gfc_trans_omp_clauses. --- gcc/fortran/gfortran.h | 11 ++++++ gcc/fortran/trans-openmp.cc | 77 +++++++++++++++++++------------------ 2 files changed, 50 insertions(+), 38 deletions(-) diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h index 34ee800668ca..3070b4675e8e 100644 --- a/gcc/fortran/gfortran.h +++ b/gcc/fortran/gfortran.h @@ -3180,6 +3180,17 @@ typedef struct gfc_finalizer gfc_finalizer; #define gfc_get_finalizer() XCNEW (gfc_finalizer) +/* Control clause translation per-directive for gfc_trans_omp_clauses. Also + used for gfc_omp_instantiate_mappers. */ + +enum toc_directive +{ + TOC_OPENMP, + TOC_OPENMP_DECLARE_SIMD, + TOC_OPENMP_EXIT_DATA, + TOC_OPENACC, + TOC_OPENACC_DECLARE +}; /************************ Function prototypes *************************/ diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc index a9dc1a617be5..829b28b24c79 100644 --- a/gcc/fortran/trans-openmp.cc +++ b/gcc/fortran/trans-openmp.cc @@ -2404,11 +2404,13 @@ static vec *doacross_steps; /* Translate an array section or array element. */ static void -gfc_trans_omp_array_section (stmtblock_t *block, gfc_exec_op op, +gfc_trans_omp_array_section (stmtblock_t *block, toc_directive cd, gfc_omp_namelist *n, tree decl, bool element, - bool openmp, gomp_map_kind ptr_kind, tree &node, + gomp_map_kind ptr_kind, tree &node, tree &node2, tree &node3, tree &node4) { + bool openmp = (cd < TOC_OPENACC); + bool omp_exit_data = (cd == TOC_OPENMP_EXIT_DATA); gfc_se se; tree ptr, ptr2; tree elemsz = NULL_TREE; @@ -2460,7 +2462,7 @@ gfc_trans_omp_array_section (stmtblock_t *block, gfc_exec_op op, if (POINTER_TYPE_P (TREE_TYPE (decl)) && GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (TREE_TYPE (decl))) && ptr_kind == GOMP_MAP_POINTER - && op != EXEC_OMP_TARGET_EXIT_DATA + && !omp_exit_data && OMP_CLAUSE_MAP_KIND (node) != GOMP_MAP_RELEASE && OMP_CLAUSE_MAP_KIND (node) != GOMP_MAP_DELETE) @@ -2479,8 +2481,7 @@ gfc_trans_omp_array_section (stmtblock_t *block, gfc_exec_op op, gomp_map_kind map_kind; if (OMP_CLAUSE_MAP_KIND (node) == GOMP_MAP_DELETE) map_kind = OMP_CLAUSE_MAP_KIND (node); - else if (op == EXEC_OMP_TARGET_EXIT_DATA - || OMP_CLAUSE_MAP_KIND (node) == GOMP_MAP_RELEASE) + else if (omp_exit_data || OMP_CLAUSE_MAP_KIND (node) == GOMP_MAP_RELEASE) map_kind = GOMP_MAP_RELEASE; else map_kind = GOMP_MAP_TO; @@ -2499,11 +2500,10 @@ gfc_trans_omp_array_section (stmtblock_t *block, gfc_exec_op op, OMP_CLAUSE_SIZE (node2) = TYPE_SIZE_UNIT (type); if (OMP_CLAUSE_MAP_KIND (node) == GOMP_MAP_DELETE || OMP_CLAUSE_MAP_KIND (node) == GOMP_MAP_RELEASE - || op == EXEC_OMP_TARGET_EXIT_DATA) + || omp_exit_data) { - gomp_map_kind map_kind - = (op == EXEC_OMP_TARGET_EXIT_DATA) ? GOMP_MAP_RELEASE - : OMP_CLAUSE_MAP_KIND (node); + gomp_map_kind map_kind = omp_exit_data ? GOMP_MAP_RELEASE + : OMP_CLAUSE_MAP_KIND (node); OMP_CLAUSE_SET_MAP_KIND (node2, map_kind); OMP_CLAUSE_RELEASE_DESCRIPTOR (node2) = 1; } @@ -2681,9 +2681,11 @@ get_symbol_rooted_namelist (hash_map= TOC_OPENACC); + bool omp_exit_data = (cd == TOC_OPENMP_EXIT_DATA); tree omp_clauses = NULL_TREE, prev_clauses, chunk_size, c; tree iterator = NULL_TREE; tree tree_block = NULL_TREE; @@ -3250,7 +3252,7 @@ gfc_trans_omp_clauses (stmtblock_t *block, gfc_omp_clauses *clauses, && n->sym->ts.deferred && n->sym->attr.omp_declare_target && (always_modifier || n->sym->attr.pointer) - && op != EXEC_OMP_TARGET_EXIT_DATA + && !omp_exit_data && n->u.map_op != OMP_MAP_DELETE && n->u.map_op != OMP_MAP_RELEASE) { @@ -3313,14 +3315,13 @@ gfc_trans_omp_clauses (stmtblock_t *block, gfc_omp_clauses *clauses, NULL_TREE)); } /* For descriptor types, the unmapping happens below. */ - if (op != EXEC_OMP_TARGET_EXIT_DATA + if (!omp_exit_data || !GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (decl))) { enum gomp_map_kind gmk = GOMP_MAP_POINTER; - if (op == EXEC_OMP_TARGET_EXIT_DATA - && n->u.map_op == OMP_MAP_DELETE) + if (omp_exit_data && n->u.map_op == OMP_MAP_DELETE) gmk = GOMP_MAP_DELETE; - else if (op == EXEC_OMP_TARGET_EXIT_DATA) + else if (omp_exit_data) gmk = GOMP_MAP_RELEASE; tree size; if (gmk == GOMP_MAP_RELEASE || gmk == GOMP_MAP_DELETE) @@ -3340,10 +3341,9 @@ gfc_trans_omp_clauses (stmtblock_t *block, gfc_omp_clauses *clauses, || GFC_DECL_GET_SCALAR_ALLOCATABLE (orig_decl))) { enum gomp_map_kind gmk; - if (op == EXEC_OMP_TARGET_EXIT_DATA - && n->u.map_op == OMP_MAP_DELETE) + if (omp_exit_data && n->u.map_op == OMP_MAP_DELETE) gmk = GOMP_MAP_DELETE; - else if (op == EXEC_OMP_TARGET_EXIT_DATA) + else if (omp_exit_data) gmk = GOMP_MAP_RELEASE; else gmk = GOMP_MAP_POINTER; @@ -3375,14 +3375,13 @@ gfc_trans_omp_clauses (stmtblock_t *block, gfc_omp_clauses *clauses, OMP_CLAUSE_SIZE (node2) = TYPE_SIZE_UNIT (type); if (n->u.map_op == OMP_MAP_DELETE) map_kind = GOMP_MAP_DELETE; - else if (op == EXEC_OMP_TARGET_EXIT_DATA - || n->u.map_op == OMP_MAP_RELEASE) + else if (omp_exit_data || n->u.map_op == OMP_MAP_RELEASE) map_kind = GOMP_MAP_RELEASE; else map_kind = GOMP_MAP_TO_PSET; OMP_CLAUSE_SET_MAP_KIND (node2, map_kind); - if (op != EXEC_OMP_TARGET_EXIT_DATA + if (!omp_exit_data && n->u.map_op != OMP_MAP_DELETE && n->u.map_op != OMP_MAP_RELEASE) { @@ -3581,9 +3580,8 @@ gfc_trans_omp_clauses (stmtblock_t *block, gfc_omp_clauses *clauses, && !(POINTER_TYPE_P (type) && GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (type)))) k = GOMP_MAP_FIRSTPRIVATE_POINTER; - gfc_trans_omp_array_section (block, op, n, decl, element, - !openacc, k, node, node2, - node3, node4); + gfc_trans_omp_array_section (block, cd, n, decl, element, + k, node, node2, node3, node4); } else if (n->expr && n->expr->expr_type == EXPR_VARIABLE @@ -3643,7 +3641,7 @@ gfc_trans_omp_clauses (stmtblock_t *block, gfc_omp_clauses *clauses, gomp_map_kind kind; if (n->u.map_op == OMP_MAP_DELETE) kind = GOMP_MAP_DELETE; - else if (op == EXEC_OMP_TARGET_EXIT_DATA) + else if (omp_exit_data) kind = GOMP_MAP_RELEASE; else kind = GOMP_MAP_TO; @@ -3828,7 +3826,7 @@ gfc_trans_omp_clauses (stmtblock_t *block, gfc_omp_clauses *clauses, else if (n->u.map_op == OMP_MAP_RELEASE || n->u.map_op == OMP_MAP_DELETE) ; - else if (op == EXEC_OMP_TARGET_EXIT_DATA) + else if (omp_exit_data) map_kind = GOMP_MAP_RELEASE; else map_kind = GOMP_MAP_ALLOC; @@ -3968,9 +3966,9 @@ gfc_trans_omp_clauses (stmtblock_t *block, gfc_omp_clauses *clauses, /* An array element or section. */ bool element = lastref->u.ar.type == AR_ELEMENT; gomp_map_kind kind = GOMP_MAP_ATTACH_DETACH; - gfc_trans_omp_array_section (block, op, n, inner, element, - !openacc, kind, node, node2, - node3, node4); + gfc_trans_omp_array_section (block, cd, n, inner, element, + kind, node, node2, node3, + node4); } else gcc_unreachable (); @@ -4906,7 +4904,7 @@ gfc_trans_oacc_construct (gfc_code *code) gfc_start_block (&block); oacc_clauses = gfc_trans_omp_clauses (&block, code->ext.omp_clauses, - code->loc, false, true); + code->loc, TOC_OPENACC); pushlevel (); stmt = gfc_trans_omp_code (code->block->next, true); stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0)); @@ -4944,7 +4942,7 @@ gfc_trans_oacc_executable_directive (gfc_code *code) gfc_start_block (&block); oacc_clauses = gfc_trans_omp_clauses (&block, code->ext.omp_clauses, - code->loc, false, true, code->op); + code->loc, TOC_OPENACC); stmt = build1_loc (input_location, construct_code, void_type_node, oacc_clauses); gfc_add_expr_to_block (&block, stmt); @@ -6143,7 +6141,7 @@ gfc_trans_oacc_combined_directive (gfc_code *code) if (construct_code == OACC_KERNELS) construct_clauses.lists[OMP_LIST_REDUCTION] = NULL; oacc_clauses = gfc_trans_omp_clauses (&block, &construct_clauses, - code->loc, false, true); + code->loc, TOC_OPENACC); } if (!loop_clauses.seq) pblock = █ @@ -7889,7 +7887,7 @@ gfc_trans_omp_target_exit_data (gfc_code *code) gfc_start_block (&block); omp_clauses = gfc_trans_omp_clauses (&block, code->ext.omp_clauses, - code->loc, false, false, code->op); + code->loc, TOC_OPENMP_EXIT_DATA); stmt = build1_loc (input_location, OMP_TARGET_EXIT_DATA, void_type_node, omp_clauses); gfc_add_expr_to_block (&block, stmt); @@ -8088,7 +8086,7 @@ gfc_trans_oacc_declare (gfc_code *code) gfc_start_block (&block); oacc_clauses = gfc_trans_omp_clauses (&block, code->ext.oacc_declare->clauses, - code->loc, false, true); + code->loc, TOC_OPENACC_DECLARE); stmt = gfc_trans_omp_code (code->block->next, true); stmt = build2_loc (input_location, construct_code, void_type_node, stmt, oacc_clauses); @@ -8262,7 +8260,8 @@ gfc_trans_omp_declare_simd (gfc_namespace *ns) gfc_omp_declare_simd *ods; for (ods = ns->omp_declare_simd; ods; ods = ods->next) { - tree c = gfc_trans_omp_clauses (NULL, ods->clauses, ods->where, true); + tree c = gfc_trans_omp_clauses (NULL, ods->clauses, ods->where, + TOC_OPENMP_DECLARE_SIMD); tree fndecl = ns->proc_name->backend_decl; if (c != NULL_TREE) c = tree_cons (NULL_TREE, c, NULL_TREE); @@ -8389,8 +8388,10 @@ gfc_trans_omp_declare_variant (gfc_namespace *ns) } break; case CTX_PROPERTY_SIMD: - properties = gfc_trans_omp_clauses (NULL, otp->clauses, - odv->where, true); + properties + = gfc_trans_omp_clauses (NULL, otp->clauses, + odv->where, + TOC_OPENMP_DECLARE_SIMD); break; default: gcc_unreachable (); -- 2.41.0