From patchwork Thu Oct 28 23:52:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernhard Reutner-Fischer X-Patchwork-Id: 1547731 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=O72k58fM; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HgMqz0y1Kz9ssD for ; Fri, 29 Oct 2021 10:55:11 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 57D5D3857C74 for ; Thu, 28 Oct 2021 23:55:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 57D5D3857C74 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1635465308; bh=HhVd7nQqPz5bznOf1LQv9pcUWB8zGSLDCg1OC3u1LxI=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=O72k58fMwXlAb9Z1nI5w4CS2+iQ1EB+RWQDjVjqjdQyJaBPIYytOE5ax0Onxn/cRJ RJlQogo39IaPLxzGi3xrmrjfln3FSj5pgN60/eBEqC/VdaK+TOWU8k6Me5/BprhPTk HBKelm/jFvtSOnZuOzSaH2sTljxiJlxMCY8gZtng= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by sourceware.org (Postfix) with ESMTPS id 962A03858410; Thu, 28 Oct 2021 23:53:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 962A03858410 Received: by mail-wm1-x32e.google.com with SMTP id 71so5044060wma.4; Thu, 28 Oct 2021 16:53:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=HhVd7nQqPz5bznOf1LQv9pcUWB8zGSLDCg1OC3u1LxI=; b=qCX4Ma0mrvxnaQSFTrX3SHTgOFqRHn+d81YWataiYIeq8I0qe8+2Y9BB6I8uSe8UaX J/6Vok8KR/ffiEJsxMvAe6XvZ51AE1t51XdbZRzJparuabjFkJlGVO8ODF80Hl5jTOzQ gjZUPTfy9RegNxteP3FSxJqJtVk/JozYShQCcoxK8IZ2L4EzEWUUk9sk/hmQD7b2v78v AF6dhJ3Q76yV9myzuMOY1/hSPDYVcYzv/mra4Kja9MJK9yV90EFQiK3xHkiTwV0+lTmY YGfrHzpYotP5jEeMQdt7QuVeU79NPgy1uOuBWmYxa46UdOZ+aPVzLvWKJxFnYBq5fun7 ix1w== X-Gm-Message-State: AOAM531aCP7r+S+0WjvoIjInAoaqAY+ev+MOhMfoXxALoeFpnDiHu7l1 RCWdvPtE/KKq2pVoLqNoUB0= X-Google-Smtp-Source: ABdhPJyNpM9nQgYQuCO3uboO2G+EG31Fj8+Ymyvfl+4WUjbd5Yp6a3BJTAPWhhvc226e2kYoaddcDA== X-Received: by 2002:a7b:c31a:: with SMTP id k26mr15576562wmj.187.1635465198732; Thu, 28 Oct 2021 16:53:18 -0700 (PDT) Received: from nbbrfq.weghof (dynamic-2bq7di4u2lfl4qjka9-pd01.res.v6.highway.a1.net. [2001:871:227:33a8:f6a3:c58c:7641:e771]) by smtp.gmail.com with ESMTPSA id p21sm3664429wmc.11.2021.10.28.16.53.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Oct 2021 16:53:18 -0700 (PDT) Received: from b by nbbrfq.weghof with local (Exim 4.95) (envelope-from ) id 1mgFCv-005wW0-2n; Fri, 29 Oct 2021 01:53:17 +0200 To: gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org Subject: [PATCH,Fortran 1/2] Add uop/name helpers Date: Fri, 29 Oct 2021 01:52:58 +0200 Message-Id: <20211028235259.1411169-1-rep.dot.nop@gmail.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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: , X-Patchwork-Original-From: Bernhard Reutner-Fischer via Gcc-patches From: Bernhard Reutner-Fischer Reply-To: Bernhard Reutner-Fischer Cc: Jakub Jelinek , Bernhard Reutner-Fischer Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" From: Bernhard Reutner-Fischer Introduce a helper to construct a user operator from a name and the reverse operation, i.e. a helper to construct a name from a user operator. Cc: Jakub Jelinek gcc/fortran/ChangeLog: 2017-10-29 Bernhard Reutner-Fischer * gfortran.h (gfc_get_uop_from_name, gfc_get_name_from_uop): Declare. * symbol.c (gfc_get_uop_from_name, gfc_get_name_from_uop): Define. * module.c (load_omp_udrs): Use them. --- gcc/fortran/gfortran.h | 2 ++ gcc/fortran/module.c | 21 +++------------------ gcc/fortran/symbol.c | 21 +++++++++++++++++++++ 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h index 9378b4b8a24..afe9f2354ee 100644 --- a/gcc/fortran/gfortran.h +++ b/gcc/fortran/gfortran.h @@ -3399,6 +3399,8 @@ void gfc_delete_symtree (gfc_symtree **, const char *); gfc_symtree *gfc_get_unique_symtree (gfc_namespace *); gfc_user_op *gfc_get_uop (const char *); gfc_user_op *gfc_find_uop (const char *, gfc_namespace *); +const char *gfc_get_uop_from_name (const char*); +const char *gfc_get_name_from_uop (const char*); void gfc_free_symbol (gfc_symbol *&); void gfc_release_symbol (gfc_symbol *&); gfc_symbol *gfc_new_symbol (const char *, gfc_namespace *); diff --git a/gcc/fortran/module.c b/gcc/fortran/module.c index 7b98ba539d6..1328414e4f7 100644 --- a/gcc/fortran/module.c +++ b/gcc/fortran/module.c @@ -5027,7 +5027,7 @@ load_omp_udrs (void) while (peek_atom () != ATOM_RPAREN) { const char *name = NULL, *newname; - char *altname; + const char *altname = NULL; gfc_typespec ts; gfc_symtree *st; gfc_omp_reduction_op rop = OMP_REDUCTION_USER; @@ -5054,15 +5054,8 @@ load_omp_udrs (void) else if (strcmp (p, ".neqv.") == 0) rop = OMP_REDUCTION_NEQV; } - altname = NULL; if (rop == OMP_REDUCTION_USER && name[0] == '.') - { - size_t len = strlen (name + 1); - altname = XALLOCAVEC (char, len); - gcc_assert (name[len] == '.'); - memcpy (altname, name + 1, len - 1); - altname[len - 1] = '\0'; - } + altname = gfc_get_name_from_uop (name); newname = name; if (rop == OMP_REDUCTION_USER) newname = find_use_name (altname ? altname : name, !!altname); @@ -5074,15 +5067,7 @@ load_omp_udrs (void) continue; } if (altname && newname != altname) - { - size_t len = strlen (newname); - altname = XALLOCAVEC (char, len + 3); - altname[0] = '.'; - memcpy (altname + 1, newname, len); - altname[len + 1] = '.'; - altname[len + 2] = '\0'; - name = gfc_get_string ("%s", altname); - } + name = altname = gfc_get_uop_from_name (newname); st = gfc_find_symtree (gfc_current_ns->omp_udr_root, name); gfc_omp_udr *udr = gfc_omp_udr_find (st, &ts); if (udr) diff --git a/gcc/fortran/symbol.c b/gcc/fortran/symbol.c index 289d85734bd..900ab49c478 100644 --- a/gcc/fortran/symbol.c +++ b/gcc/fortran/symbol.c @@ -3044,6 +3044,27 @@ gfc_find_uop (const char *name, gfc_namespace *ns) return (st == NULL) ? NULL : st->n.uop; } +/* Given a name return a string usable as user operator name. */ +const char * +gfc_get_uop_from_name (const char* name) { + gcc_assert (name[0] != '.'); + return gfc_get_string (".%s.", name); +} + +/* Given a user operator name return a string usable as name. */ +const char * +gfc_get_name_from_uop (const char* name) { + gcc_assert (name[0] == '.'); + const size_t len = strlen (name) - 1; + gcc_assert (len > 1); + gcc_assert (name[len] == '.'); + char *buffer = XNEWVEC (char, len); + memcpy (buffer, name + 1, len - 1); + buffer[len - 1] = '\0'; + const char *ret = gfc_get_string ("%s", buffer); + XDELETEVEC (buffer); + return ret; +} /* Update a symbol's common_block field, and take care of the associated memory management. */