From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) by sourceware.org (Postfix) with ESMTPS id 835523858D1E; Fri, 8 Sep 2023 21:22:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 835523858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmx.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1694208165; x=1694812965; i=anlauf@gmx.de; bh=ID5AB7uunWfsPBSntBWrP+8Eni+Yy1mSN3YX9Q3B424=; h=X-UI-Sender-Class:Date:Subject:To:References:From:In-Reply-To; b=ZrdEDvDcHKEj62D0Xh4mi1/eamcjfSfiIdI3skbwXgPWn7BjyMS+jAEXrZfdBDgHmqxs/aI jL2MZUbka111/MxvmfcPUc9O7o4+V3OYlk5Nm3xxQmjxinTI2j+q7Bdw8UHfsGirxtwKoCjfN fdKtfdzwXMSZHf8oWHywj7Pu+CoLB8a8xxWN8WT4Hg6hllE9I5dJBDHt/Z943AKmcc2d/4HF4 VonlMl2ZnlBAnzKyzxu5LMttu5ljaw4U6WZ9I6+mWADOSl2UUph+i+fZKsiySOICndG7s1uOI BbdF/ybw9jo5tezZOvhbtGaNl/A4gpY1uUxF6EdgbyiB8p/Y2yQw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [192.168.178.29] ([79.251.10.65]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MNKhm-1qG2QA3eWI-00Ors6; Fri, 08 Sep 2023 23:22:44 +0200 Message-ID: <7538c30a-e595-41fc-be35-653a3371f95e@gmx.de> Date: Fri, 8 Sep 2023 23:22:43 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] fortran: Remove redundant tree walk to delete element To: Mikael Morin , gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org Newsgroups: gmane.comp.gcc.patches,gmane.comp.gcc.fortran References: <20230908100434.541577-1-mikael@gcc.gnu.org> Content-Language: en-US From: Harald Anlauf In-Reply-To: <20230908100434.541577-1-mikael@gcc.gnu.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:4EGuyxxQnUX+T1TqC7tYBD+oY0/v3op9WBM0rJGJVF5jy/Ddf7d cK8j7ecG+NKFwkV7IIMbJuxMQjtEWEFTmpBB4RzoMYA627QCpSKm0KZNVZ4vSc7HQtWRz9Q vSDTVAyx9XbqN6SppVlVLoPi/rKgwB8vPoNZmYfadqFMTXvn8NnCHcDSWTdQjRZvhiGBRpR gsQHpmcxwY7uz5fTFRfUg== UI-OutboundReport: notjunk:1;M01:P0:JGl2JX0mSlU=;JDlbMZ/MvOABMf1tAp9EGZ98PG9 p4v0tol44sVohR5iDQZm2+1HUls8gv5hsHvWHbR+Q4D9IMJpkk1oDsLUcmspaMxNHi0fWP/PC BvxFrq6UjbOAXHFGr+STRzq4aK+/3M45/9I8wg6EG1QxVayrULp6NieQ3np4BOtopsDLdM9zp QStauW0AWWlxcPiEeRB74AVDiNt8DQeutwVvguG8zpGhM6I3l0sZvQKzRUcNwsx7wE0Mj3d6f HZthsCFS5dsT0eiRBsRG7zMXEp93syHrqIFyPDpdCDn8OPQzxk0YmQDqMeqew4wn/OaGs8wM/ 53+UhOZLC09kGXU2x/zJQQi2l+dGRlzb+OVOTJBpOQlV76BwECcg+Cu3Txxn7Greco/QWn07z 5clI0GM+v1EobH2YrA3znKMFtykFz1F3IfFo0TcpddMXK6h+41hNiCiA3iRTfOk4mBdAJHc8w EeT9DHlgLSkw70disgJ6TRxpQTq+Ys1BqldfHFENn91ED5eyNIyOKsx9kBKpfxWgomoZOF+FQ WcsxDrw7KuuLiaw/7gQRfIBBsVA68IoFPST0pQIqIqrhjLIU/+SlCmN3I6Zwb/7+SSE0WEMax 2Vustyz86A4BX0p+oTmvpsa/jVkXNJHf0ty154XMGZ3D02FoRxrcGtKCRQXCgDx7lJ598Lsik lUDtpPqOaKjefemUpLLCujlsMqXSU83Y+XQFtQQPIyNljX241+UDRfMTk2NqT4j7k24T3lBCD tXCBpjW+s6S3IRN8jDy3rk6Z+st8OegoJ+nylMUlnuDQ7hjLd9DlVoKRVSzgwRvZhhQx6CvRs YJ/V6s4Gh9DieVUr3FzFze9EdVbXGpI2ItSvBwhuG+3XrtRVNiNH6yGwhJE7qDkx6U3tInvU+ JJLMh7OYNyUQeiIv1vZ4EfE8Sj6DiJFMaTRYXse5eQPFC+ftFI3Ybedzs2bdTEscO2Aj0TfQ1 UYCfq9sTwTXxb6eIiRjG1ogv+dE= X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,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: Am 08.09.23 um 12:04 schrieb Mikael Morin via Gcc-patches: > Hello, > > this avoids some redundant work in the symbol deletion code, which is > used a lot by the parser to cancel statements that fail to match in the > end. > I haven't tried to measure the performance effect, if any, on a patholog= ical example; > just passed the fortran testsuite on x86_64-pc-linux-gnu. > OK for master? This is OK. Thanks, Harald > -- >8 -- > > Remove preliminary walk of the symbol tree when we are about to remove a= n > element. This preliminary walk was necessary because the deletion funct= ion > updated the tree without reporting back to the caller the element it had > removed. But knowing that element is necessary to free its memory, so o= ne > had to first get that element before it was removed from the tree. > > This change updates the main deletion function delete_treap and its publ= ic > wrapper gfc_delete_bbt so that the removed element can be known by the > caller. This makes the preliminary walk in gfc_delete_symtree redundant= , > permitting its removal. > > gcc/fortran/ChangeLog: > > * bbt.cc (delete_treap): Add argument REMOVED, set it to the removed > element from the tree. Change NULL to nullptr. > (gfc_delete_bbt): Return the removed element from the tree. > * gfortran.h (gfc_delete_symtree): Remove prototype. > (gfc_delete_bbt): Set return type to pointer. > * symbol.cc (gfc_delete_symtree): Make static. Get the element to be > freed from the result of gfc_delete_bbt. Remove the preliminary walk t= o > get it. > --- > gcc/fortran/bbt.cc | 27 +++++++++++++++++++-------- > gcc/fortran/gfortran.h | 3 +-- > gcc/fortran/symbol.cc | 6 ++---- > 3 files changed, 22 insertions(+), 14 deletions(-) > > diff --git a/gcc/fortran/bbt.cc b/gcc/fortran/bbt.cc > index 851e5e92c7b..2a032083c5c 100644 > --- a/gcc/fortran/bbt.cc > +++ b/gcc/fortran/bbt.cc > @@ -168,31 +168,42 @@ delete_root (gfc_bbt *t) > Returns the new root node of the tree. */ > > static gfc_bbt * > -delete_treap (gfc_bbt *old, gfc_bbt *t, compare_fn compare) > +delete_treap (gfc_bbt *old, gfc_bbt *t, compare_fn compare, gfc_bbt **r= emoved) > { > int c; > > - if (t =3D=3D NULL) > - return NULL; > + if (t =3D=3D nullptr) > + { > + if (removed) > + *removed =3D nullptr; > + return nullptr; > + } > > c =3D (*compare) (old, t); > > if (c < 0) > - t->left =3D delete_treap (old, t->left, compare); > + t->left =3D delete_treap (old, t->left, compare, removed); > if (c > 0) > - t->right =3D delete_treap (old, t->right, compare); > + t->right =3D delete_treap (old, t->right, compare, removed); > if (c =3D=3D 0) > - t =3D delete_root (t); > + { > + if (removed) > + *removed =3D t; > + t =3D delete_root (t); > + } > > return t; > } > > > -void > +void * > gfc_delete_bbt (void *root, void *old, compare_fn compare) > { > gfc_bbt **t; > + gfc_bbt *removed; > > t =3D (gfc_bbt **) root; > - *t =3D delete_treap ((gfc_bbt *) old, *t, compare); > + *t =3D delete_treap ((gfc_bbt *) old, *t, compare, &removed); > + > + return (void *) removed; > } > diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h > index b37c6bb9ad4..371f8743312 100644 > --- a/gcc/fortran/gfortran.h > +++ b/gcc/fortran/gfortran.h > @@ -3510,7 +3510,6 @@ bool gfc_reference_st_label (gfc_st_label *, gfc_s= l_type); > gfc_namespace *gfc_get_namespace (gfc_namespace *, int); > gfc_symtree *gfc_new_symtree (gfc_symtree **, const char *); > gfc_symtree *gfc_find_symtree (gfc_symtree *, const char *); > -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 *); > @@ -3911,7 +3910,7 @@ bool gfc_inline_intrinsic_function_p (gfc_expr *); > /* bbt.cc */ > typedef int (*compare_fn) (void *, void *); > void gfc_insert_bbt (void *, void *, compare_fn); > -void gfc_delete_bbt (void *, void *, compare_fn); > +void * gfc_delete_bbt (void *, void *, compare_fn); > > /* dump-parse-tree.cc */ > void gfc_dump_parse_tree (gfc_namespace *, FILE *); > diff --git a/gcc/fortran/symbol.cc b/gcc/fortran/symbol.cc > index aa3cdc98c86..2cba2ea0bed 100644 > --- a/gcc/fortran/symbol.cc > +++ b/gcc/fortran/symbol.cc > @@ -2948,7 +2948,7 @@ gfc_new_symtree (gfc_symtree **root, const char *n= ame) > > /* Delete a symbol from the tree. Does not free the symbol itself! *= / > > -void > +static void > gfc_delete_symtree (gfc_symtree **root, const char *name) > { > gfc_symtree st, *st0; > @@ -2963,10 +2963,8 @@ gfc_delete_symtree (gfc_symtree **root, const cha= r *name) > else > p =3D name; > > - st0 =3D gfc_find_symtree (*root, p); > - > st.name =3D gfc_get_string ("%s", p); > - gfc_delete_bbt (root, &st, compare_symtree); > + st0 =3D (gfc_symtree *) gfc_delete_bbt (root, &st, compare_symtree); > > free (st0); > }