From patchwork Thu Feb 17 12:33:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Schwinge X-Patchwork-Id: 51182 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 980D33858027 for ; Thu, 17 Feb 2022 12:34:11 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa1.mentor.iphmx.com (esa1.mentor.iphmx.com [68.232.129.153]) by sourceware.org (Postfix) with ESMTPS id 1A3293858D20 for ; Thu, 17 Feb 2022 12:33:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1A3293858D20 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com IronPort-SDR: EelHxpi5CQDulzI5JVREVC6mahgDO/uZgQG16QH4I/vRf8M0XDX5dXAMS1GEv5J1w6U5vXmFVU xKSIkwDalGRPxUBaqeZiQ2I7hBDBeaPHyx8A5bDvJeC5+u1QFM3c0AuPaktinIkcw/kvQEzNlY 3Oqx8iQjfHYk+jkfOCW4XyYfJGmGEv5g548EiWdYrlaK0/4k2prEJHRjUBuanpVWw6IaYnLZnZ b0AH57+LghaSYJwcDArZlBkSQqFJL0aBruvllYSBsyK/Qhp+sj1yf1HhD7aQT8qsS6tZw9+/nS roHKs/nIox3oxdI1vutEoTbL X-IronPort-AV: E=Sophos;i="5.88,375,1635235200"; d="scan'208,223";a="74667889" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 17 Feb 2022 04:33:53 -0800 IronPort-SDR: SLDqYrvDAoOEbwJZj8RX4Wsd3L8JpKLtyD0wQqOc12O5hVfd5rpvt6KQDFHAp6XSBXrQjwCV4s WDBqCU2Td2dTdljqZ3pn8Afons7egC1Y93BYpNn0iylW4iOyyU4aO1DGyeEAvyvGOnOryfX0NS LsTMZLLlwHfEvBd1N6C9GWTqKzRltY0t9POhWiGjvbyLS+S3jG0TVMlJormbQgd+UazaIjLgzl K3Jkbr6emXbEzxkYvX+7yhwGRlfDjBVjXfqwb7bb/ZsQ4V+qmO9Ap8JeCdB/I/9X4jx6a3ttNy cQQ= From: Thomas Schwinge To: Jakub Jelinek , Subject: Add 'gcc/tree.cc:user_omp_clause_code_name' [PR65095] (was: [PATCH 1/4] Add function for pretty-printing OpenACC clause names) In-Reply-To: <878spiw84d.fsf@euler.schwinge.homeip.net> References: <20191006223237.81842-1-julian@codesourcery.com> <20191006223237.81842-2-julian@codesourcery.com> <878spiw84d.fsf@euler.schwinge.homeip.net> User-Agent: Notmuch/0.29.3+94~g74c3f1b (https://notmuchmail.org) Emacs/27.1 (x86_64-pc-linux-gnu) Date: Thu, 17 Feb 2022 13:33:45 +0100 Message-ID: <875ypdpt92.fsf@euler.schwinge.homeip.net> MIME-Version: 1.0 X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-12.mgc.mentorg.com (139.181.222.12) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_SHORT, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Julian Brown Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi! On 2019-10-18T14:28:18+0200, I wrote: > On 2019-10-06T15:32:34-0700, Julian Brown wrote: >> This patch adds a function to pretty-print OpenACC clause names from >> OMP_CLAUSE_MAP_KINDs, for error output. > > Indeed talking about (OpenMP) 'map' clauses in an OpenACC context is not > quite ideal -- that's what PR65095 is about >> Previously approved as part of: >> >> https://gcc.gnu.org/ml/gcc-patches/2018-12/msg01292.html > A few more comments, for later: > >> gcc/c-family/c-common.h | 1 + >> gcc/c-family/c-omp.c | 33 +++++++++++++++++++++++++++++++++ > > As I'd mentioned before: 'Eventually (that is, later), this should move > into generic code, next to the other "clause printing". As part of an ICE bug fix that I'm working on, I now need to use this in GCC middle end code. Once tested, OK to push the attached "Add 'gcc/tree.cc:user_omp_clause_code_name' [PR65095]"? Grüße Thomas > Also to be > shared with Fortran.' > >> --- a/gcc/c-family/c-omp.c >> +++ b/gcc/c-family/c-omp.c > >> +/* For OpenACC, the OMP_CLAUSE_MAP_KIND of an OMP_CLAUSE_MAP is used internally >> + to distinguish clauses as seen by the user. Return the "friendly" clause >> + name for error messages etc., where possible. See also >> + c/c-parser.c:c_parser_oacc_data_clause and >> + cp/parser.c:cp_parser_oacc_data_clause. */ >> + >> +const char * >> +c_omp_map_clause_name (tree clause, bool oacc) >> +{ >> + if (oacc && OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_MAP) >> + switch (OMP_CLAUSE_MAP_KIND (clause)) >> + { >> + case GOMP_MAP_FORCE_ALLOC: >> + case GOMP_MAP_ALLOC: return "create"; >> + case GOMP_MAP_FORCE_TO: >> + case GOMP_MAP_TO: return "copyin"; >> + case GOMP_MAP_FORCE_FROM: >> + case GOMP_MAP_FROM: return "copyout"; >> + case GOMP_MAP_FORCE_TOFROM: >> + case GOMP_MAP_TOFROM: return "copy"; >> + case GOMP_MAP_RELEASE: return "delete"; >> + case GOMP_MAP_FORCE_PRESENT: return "present"; >> + case GOMP_MAP_ATTACH: return "attach"; >> + case GOMP_MAP_FORCE_DETACH: >> + case GOMP_MAP_DETACH: return "detach"; >> + case GOMP_MAP_DEVICE_RESIDENT: return "device_resident"; >> + case GOMP_MAP_LINK: return "link"; >> + case GOMP_MAP_FORCE_DEVICEPTR: return "deviceptr"; >> + default: break; >> + } >> + return omp_clause_code_name[OMP_CLAUSE_CODE (clause)]; >> +} > > Indeed nearby (after) the 'omp_clause_code_name' definition in > 'gcc/tree.c' would probably be a better place for this, as that's where > the current clause names are coming from. > > I did wonder whether we need to explicitly translate from (OpenMP) "'map' > clause" into (OpenACC) "'create' clause" etc., or if a generic (OpenACC) > "data clause" would be sufficient? (After all, in diagnostics we also > print out the original code, so the user can then see which specific data > clause is being complained about. But -- somewhat funnily! -- the way > you're doing this might actually be better in terms of translatability in > diagnostics printing: "%qs clause" might require a different translation > when its "%s" can be "'map'" (doesn't get translated) vs. "data" (gets > translated), but remains the same when "%s" is "'map'" vs. "'create'" > etc. > > Do we at all still generate 'GOMP_MAP_FORCE_*' anywhere, or should these > in fact be 'gcc_unreachable'? > > Generally, I prefer if all possible 'case's are listed explicitly, and > then the 'default' (and here OpenMP-only ones, too) be 'gcc_unreachable', > so that we easily catch the case that new 'GOMP_MAP_*' get added but such > functions not updated, for example. > > > Grüße > Thomas ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955 From 741a15e861fb97f720d527f917b5888c2b9324e9 Mon Sep 17 00:00:00 2001 From: Thomas Schwinge Date: Thu, 17 Feb 2022 12:46:57 +0100 Subject: [PATCH] Add 'gcc/tree.cc:user_omp_clause_code_name' [PR65095] Re PR65095 "Adapt OpenMP diagnostic messages for OpenACC", move 'gcc/c-family/c-omp.cc:c_omp_map_clause_name' C/C++ front end to 'gcc/tree.cc:user_omp_clause_code_name' middle end. No functional change. PR other/65095 TODO --- gcc/c-family/c-common.h | 1 - gcc/c-family/c-omp.cc | 33 --------------------------------- gcc/c/c-typeck.cc | 4 ++-- gcc/cp/semantics.cc | 4 ++-- gcc/tree-core.h | 1 + gcc/tree.cc | 36 ++++++++++++++++++++++++++++++++++++ 6 files changed, 41 insertions(+), 38 deletions(-) diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index ee0c4de2a05..09e4c378cb9 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -1249,7 +1249,6 @@ extern enum omp_clause_default_kind c_omp_predetermined_sharing (tree); extern enum omp_clause_defaultmap_kind c_omp_predetermined_mapping (tree); extern tree c_omp_check_context_selector (location_t, tree); extern void c_omp_mark_declare_variant (location_t, tree, tree); -extern const char *c_omp_map_clause_name (tree, bool); extern void c_omp_adjust_map_clauses (tree, bool); enum c_omp_directive_kind { diff --git a/gcc/c-family/c-omp.cc b/gcc/c-family/c-omp.cc index cd9d86641e1..777cdc65572 100644 --- a/gcc/c-family/c-omp.cc +++ b/gcc/c-family/c-omp.cc @@ -2996,39 +2996,6 @@ c_omp_predetermined_mapping (tree decl) } -/* For OpenACC, the OMP_CLAUSE_MAP_KIND of an OMP_CLAUSE_MAP is used internally - to distinguish clauses as seen by the user. Return the "friendly" clause - name for error messages etc., where possible. See also - c/c-parser.cc:c_parser_oacc_data_clause and - cp/parser.cc:cp_parser_oacc_data_clause. */ - -const char * -c_omp_map_clause_name (tree clause, bool oacc) -{ - if (oacc && OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_MAP) - switch (OMP_CLAUSE_MAP_KIND (clause)) - { - case GOMP_MAP_FORCE_ALLOC: - case GOMP_MAP_ALLOC: return "create"; - case GOMP_MAP_FORCE_TO: - case GOMP_MAP_TO: return "copyin"; - case GOMP_MAP_FORCE_FROM: - case GOMP_MAP_FROM: return "copyout"; - case GOMP_MAP_FORCE_TOFROM: - case GOMP_MAP_TOFROM: return "copy"; - case GOMP_MAP_RELEASE: return "delete"; - case GOMP_MAP_FORCE_PRESENT: return "present"; - case GOMP_MAP_ATTACH: return "attach"; - case GOMP_MAP_FORCE_DETACH: - case GOMP_MAP_DETACH: return "detach"; - case GOMP_MAP_DEVICE_RESIDENT: return "device_resident"; - case GOMP_MAP_LINK: return "link"; - case GOMP_MAP_FORCE_DEVICEPTR: return "deviceptr"; - default: break; - } - return omp_clause_code_name[OMP_CLAUSE_CODE (clause)]; -} - /* Used to merge map clause information in c_omp_adjust_map_clauses. */ struct map_clause { diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc index 61bc4f6efe7..2b3773a4303 100644 --- a/gcc/c/c-typeck.cc +++ b/gcc/c/c-typeck.cc @@ -13368,7 +13368,7 @@ handle_omp_array_sections_1 (tree c, tree t, vec &types, { error_at (OMP_CLAUSE_LOCATION (c), "expected single pointer in %qs clause", - c_omp_map_clause_name (c, ort == C_ORT_ACC)); + user_omp_clause_code_name (c, ort == C_ORT_ACC)); return error_mark_node; } } @@ -14091,7 +14091,7 @@ c_oacc_check_attachments (tree c) if (TREE_CODE (TREE_TYPE (t)) != POINTER_TYPE) { error_at (OMP_CLAUSE_LOCATION (c), "expected pointer in %qs clause", - c_omp_map_clause_name (c, true)); + user_omp_clause_code_name (c, true)); return true; } } diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 066320e9b7c..7666b08f518 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -5199,7 +5199,7 @@ handle_omp_array_sections_1 (tree c, tree t, vec &types, { error_at (OMP_CLAUSE_LOCATION (c), "expected single pointer in %qs clause", - c_omp_map_clause_name (c, ort == C_ORT_ACC)); + user_omp_clause_code_name (c, ort == C_ORT_ACC)); return error_mark_node; } } @@ -6657,7 +6657,7 @@ cp_oacc_check_attachments (tree c) if (TREE_CODE (type) != POINTER_TYPE) { error_at (OMP_CLAUSE_LOCATION (c), "expected pointer in %qs clause", - c_omp_map_clause_name (c, true)); + user_omp_clause_code_name (c, true)); return true; } } diff --git a/gcc/tree-core.h b/gcc/tree-core.h index 2682d2ceb7f..61106f2a49b 100644 --- a/gcc/tree-core.h +++ b/gcc/tree-core.h @@ -2270,6 +2270,7 @@ extern const char * built_in_names[(int) END_BUILTINS]; /* Number of operands and names for each OMP_CLAUSE node. */ extern unsigned const char omp_clause_num_ops[]; extern const char * const omp_clause_code_name[]; +extern const char *user_omp_clause_code_name (tree, bool); /* A vector of all translation-units. */ extern GTY (()) vec *all_translation_units; diff --git a/gcc/tree.cc b/gcc/tree.cc index 307b1f6b0b3..95226781b4e 100644 --- a/gcc/tree.cc +++ b/gcc/tree.cc @@ -69,6 +69,7 @@ along with GCC; see the file COPYING3. If not see #include "gimple-fold.h" #include "escaped_string.h" #include "gimple-range.h" +#include "gomp-constants.h" /* Tree code classes. */ @@ -456,6 +457,41 @@ const char * const omp_clause_code_name[] = "nohost", }; +/* Unless specific to OpenACC, we tend to internally maintain OpenMP-centric + clause names, but for use in diagnostics etc. would like to use the "user" + clause names. */ + +const char * +user_omp_clause_code_name (tree clause, bool oacc) +{ + /* For OpenACC, the 'OMP_CLAUSE_MAP_KIND' of an 'OMP_CLAUSE_MAP' is used to + distinguish clauses as seen by the user. See also where front ends do + 'build_omp_clause' with 'OMP_CLAUSE_MAP'. */ + if (oacc && OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_MAP) + switch (OMP_CLAUSE_MAP_KIND (clause)) + { + case GOMP_MAP_FORCE_ALLOC: + case GOMP_MAP_ALLOC: return "create"; + case GOMP_MAP_FORCE_TO: + case GOMP_MAP_TO: return "copyin"; + case GOMP_MAP_FORCE_FROM: + case GOMP_MAP_FROM: return "copyout"; + case GOMP_MAP_FORCE_TOFROM: + case GOMP_MAP_TOFROM: return "copy"; + case GOMP_MAP_RELEASE: return "delete"; + case GOMP_MAP_FORCE_PRESENT: return "present"; + case GOMP_MAP_ATTACH: return "attach"; + case GOMP_MAP_FORCE_DETACH: + case GOMP_MAP_DETACH: return "detach"; + case GOMP_MAP_DEVICE_RESIDENT: return "device_resident"; + case GOMP_MAP_LINK: return "link"; + case GOMP_MAP_FORCE_DEVICEPTR: return "deviceptr"; + default: break; + } + + return omp_clause_code_name[OMP_CLAUSE_CODE (clause)]; +} + /* Return the tree node structure used by tree code CODE. */ -- 2.34.1