From patchwork Wed Nov 10 08:58:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Marie de Rodat X-Patchwork-Id: 47371 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 5439B3857C6C for ; Wed, 10 Nov 2021 09:06:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5439B3857C6C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1636535160; bh=3FQqBGAnEvAaIDxdf8o507on4rNgd5J2J/2pzqNpvuQ=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=R5p6d/LRsEbyLoD5VmZ7PlvdMOeWkJbJoYxNDBlJ3ySR4oXGAD4l17Essr3TL0ZiJ 3k1i7MmxEsEjvgiLtVNHWuAZNxUZgoW7gbDGWQ79sjEeLbpW/nGKjxACey9NJK1zFH VGTA9mLpjp4fm3HiwHz6xr9JIkUyQ9Q4QpoG6z3I= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by sourceware.org (Postfix) with ESMTPS id 6585C3857C63 for ; Wed, 10 Nov 2021 08:58:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6585C3857C63 Received: by mail-lj1-x22e.google.com with SMTP id m5so3912100ljp.4 for ; Wed, 10 Nov 2021 00:58:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=3FQqBGAnEvAaIDxdf8o507on4rNgd5J2J/2pzqNpvuQ=; b=ERoJHqwQFEAZVyV09ZhN+SU8HO54t1Sqnr3cXRmI4CxEg/1fdJGaY0m2N2a8F1zKQ5 sSoJTfIlepgWt0g6FoFRKg7CxxPpA13bIG33HYSw/eBhsTCB6rLS8UKz2O6n0luBUYSI nk34qZe0i1dtJi1zzPNMhsXNkotEjBgLnlyD62G0dk2fDAL0WoDgvJbP60bRKmSXxdzk 5YCuRVDlwv2MGAl9m04WIzHfwk1FiivHzVuJe4fL35uY2HPMDfXNoAim455YEcERFpZf qtX0jMOcBOf0gSopvx3P12VUEgw0OXy3j/rQQJJSzB0LR3/TdSegYdVppEkKjeyIPOJH gS1w== X-Gm-Message-State: AOAM530VTA6zagyBejawnj1ktG2BbeEKGKuLYR/IP6KC1smo5HqQBwFd GneHKQfo2D8Np2IljlwywDgT++VK0sa2oA== X-Google-Smtp-Source: ABdhPJw6AEm0/rPgjWz2uC3eOqsWNNDIN67NOb0a8waTjYfjNmA1ZoSWI+0bb9BcErF1fc5PTzdvLg== X-Received: by 2002:a2e:a90f:: with SMTP id j15mr7740317ljq.128.1636534719281; Wed, 10 Nov 2021 00:58:39 -0800 (PST) Received: from adacore.com ([2a02:2ab8:224:2ce:72b5:e8ff:feef:ee60]) by smtp.gmail.com with ESMTPSA id z12sm2400520lfs.101.2021.11.10.00.58.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Nov 2021 00:58:38 -0800 (PST) Date: Wed, 10 Nov 2021 08:58:37 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Don't carry action bodies for expansion of array equality Message-ID: <20211110085837.GA2811123@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, 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: Pierre-Marie de Rodat via Gcc-patches From: Pierre-Marie de Rodat Reply-To: Pierre-Marie de Rodat Cc: Piotr Trojanek Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Expansion of array equality creates a function, which needs to be inserted into the AST. The insertion point was carried from Expand_N_Op_Eq to Expand_Record_Equality and Expand_Array_Equality, which were mutually recursive (via Expand_Composite_Equality). Now these routines are no longer recursive, so there is no need to carry the insertion point between them. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * exp_ch3.adb (Make_Eq_Body): Adapt call to Expand_Record_Equality. * exp_ch4.ads, exp_ch4.adb (Expand_Composite_Equality): Remove Bodies parameter; adapt comment; fix style in body; adapt calls to Expand_Record_Equality. (Expand_Array_Equality): Adapt calls to Expand_Composite_Equality. (Expand_Record_Equality): Remove Bodies parameter; adapt comment; adapt call to Expand_Composite_Equality. * exp_ch8.adb (Build_Body_For_Renaming): Adapt call to Expand_Record_Equality. diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb --- a/gcc/ada/exp_ch3.adb +++ b/gcc/ada/exp_ch3.adb @@ -9864,10 +9864,9 @@ package body Exp_Ch3 is Expression => Expand_Record_Equality (Typ, - Typ => Typ, - Lhs => Make_Identifier (Loc, Name_X), - Rhs => Make_Identifier (Loc, Name_Y), - Bodies => Declarations (Decl)))); + Typ => Typ, + Lhs => Make_Identifier (Loc, Name_X), + Rhs => Make_Identifier (Loc, Name_Y)))); end if; Set_Handled_Statement_Sequence diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb --- a/gcc/ada/exp_ch4.adb +++ b/gcc/ada/exp_ch4.adb @@ -146,18 +146,14 @@ package body Exp_Ch4 is -- where we allow comparison of "out of range" values. function Expand_Composite_Equality - (Nod : Node_Id; - Typ : Entity_Id; - Lhs : Node_Id; - Rhs : Node_Id; - Bodies : List_Id) return Node_Id; + (Nod : Node_Id; + Typ : Entity_Id; + Lhs : Node_Id; + Rhs : Node_Id) return Node_Id; -- Local recursive function used to expand equality for nested composite - -- types. Used by Expand_Record/Array_Equality, Bodies is a list on which - -- to attach bodies of local functions that are created in the process. It - -- is the responsibility of the caller to insert those bodies at the right - -- place. Nod provides the Sloc value for generated code. Lhs and Rhs are - -- the left and right sides for the comparison, and Typ is the type of the - -- objects to compare. + -- types. Used by Expand_Record/Array_Equality. Nod provides the Sloc value + -- for generated code. Lhs and Rhs are the left and right sides for the + -- comparison, and Typ is the type of the objects to compare. procedure Expand_Concatenate (Cnode : Node_Id; Opnds : List_Id); -- Routine to expand concatenation of a sequence of two or more operands @@ -1722,8 +1718,7 @@ package body Exp_Ch4 is Prefix => Make_Identifier (Loc, Chars (B)), Expressions => Index_List2); - Test := Expand_Composite_Equality - (Nod, Component_Type (Typ), L, R, Decls); + Test := Expand_Composite_Equality (Nod, Component_Type (Typ), L, R); -- If some (sub)component is an unchecked_union, the whole operation -- will raise program error. @@ -2012,7 +2007,7 @@ package body Exp_Ch4 is Prefix => New_Copy_Tree (New_Rhs), Expressions => New_List (New_Copy_Tree (Low_B))); - TestL := Expand_Composite_Equality (Nod, Ctyp, L, R, Bodies); + TestL := Expand_Composite_Equality (Nod, Ctyp, L, R); L := Make_Indexed_Component (Loc, @@ -2024,7 +2019,7 @@ package body Exp_Ch4 is Prefix => New_Rhs, Expressions => New_List (New_Copy_Tree (High_B))); - TestH := Expand_Composite_Equality (Nod, Ctyp, L, R, Bodies); + TestH := Expand_Composite_Equality (Nod, Ctyp, L, R); return Make_And_Then (Loc, Left_Opnd => TestL, Right_Opnd => TestH); @@ -2437,18 +2432,15 @@ package body Exp_Ch4 is -- case because it is not possible to respect normal Ada visibility rules. function Expand_Composite_Equality - (Nod : Node_Id; - Typ : Entity_Id; - Lhs : Node_Id; - Rhs : Node_Id; - Bodies : List_Id) return Node_Id + (Nod : Node_Id; + Typ : Entity_Id; + Lhs : Node_Id; + Rhs : Node_Id) return Node_Id is Loc : constant Source_Ptr := Sloc (Nod); Full_Type : Entity_Id; Eq_Op : Entity_Id; - -- Start of processing for Expand_Composite_Equality - begin if Is_Private_Type (Typ) then Full_Type := Underlying_Type (Typ); @@ -2665,7 +2657,7 @@ package body Exp_Ch4 is end; else - return Expand_Record_Equality (Nod, Full_Type, Lhs, Rhs, Bodies); + return Expand_Record_Equality (Nod, Full_Type, Lhs, Rhs); end if; -- Case of non-record types (always use predefined equality) @@ -8640,10 +8632,8 @@ package body Exp_Ch4 is else Remove_Side_Effects (Lhs); Remove_Side_Effects (Rhs); - Rewrite (N, - Expand_Record_Equality (N, Typl, Lhs, Rhs, Bodies)); + Rewrite (N, Expand_Record_Equality (N, Typl, Lhs, Rhs)); - Insert_Actions (N, Bodies, Suppress => All_Checks); Analyze_And_Resolve (N, Standard_Boolean, Suppress => All_Checks); end if; @@ -8666,10 +8656,8 @@ package body Exp_Ch4 is Rewrite (N, Expand_Record_Equality (N, Typl, Unchecked_Convert_To (Typl, Lhs), - Unchecked_Convert_To (Typl, Rhs), - Bodies)); + Unchecked_Convert_To (Typl, Rhs))); - Insert_Actions (N, Bodies, Suppress => All_Checks); Analyze_And_Resolve (N, Standard_Boolean, Suppress => All_Checks); end if; @@ -12994,11 +12982,10 @@ package body Exp_Ch4 is -- otherwise the primitive "=" is used directly. function Expand_Record_Equality - (Nod : Node_Id; - Typ : Entity_Id; - Lhs : Node_Id; - Rhs : Node_Id; - Bodies : List_Id) return Node_Id + (Nod : Node_Id; + Typ : Entity_Id; + Lhs : Node_Id; + Rhs : Node_Id) return Node_Id is Loc : constant Source_Ptr := Sloc (Nod); @@ -13085,8 +13072,7 @@ package body Exp_Ch4 is Rhs => Make_Selected_Component (Loc, Prefix => New_Rhs, - Selector_Name => New_Occurrence_Of (C, Loc)), - Bodies => Bodies); + Selector_Name => New_Occurrence_Of (C, Loc))); -- If some (sub)component is an unchecked_union, the whole -- operation will raise program error. diff --git a/gcc/ada/exp_ch4.ads b/gcc/ada/exp_ch4.ads --- a/gcc/ada/exp_ch4.ads +++ b/gcc/ada/exp_ch4.ads @@ -89,20 +89,16 @@ package Exp_Ch4 is -- while for records without variants only a simple expression is needed. function Expand_Record_Equality - (Nod : Node_Id; - Typ : Entity_Id; - Lhs : Node_Id; - Rhs : Node_Id; - Bodies : List_Id) return Node_Id; + (Nod : Node_Id; + Typ : Entity_Id; + Lhs : Node_Id; + Rhs : Node_Id) return Node_Id; -- Expand a record equality into an expression that compares the fields -- individually to yield the required Boolean result. Loc is the -- location for the generated nodes. Typ is the type of the record, and -- Lhs, Rhs are the record expressions to be compared, these -- expressions need not to be analyzed but have to be side-effect free. - -- Bodies is a list on which to attach bodies of local functions that - -- are created in the process. This is the responsibility of the caller - -- to insert those bodies at the right place. Nod provides the Sloc - -- value for generated code. + -- Nod provides the Sloc value for generated code. procedure Expand_Set_Membership (N : Node_Id); -- For each choice of a set membership, we create a simple equality or diff --git a/gcc/ada/exp_ch8.adb b/gcc/ada/exp_ch8.adb --- a/gcc/ada/exp_ch8.adb +++ b/gcc/ada/exp_ch8.adb @@ -288,7 +288,6 @@ package body Exp_Ch8 is function Build_Body_For_Renaming (Typ : Entity_Id) return Node_Id is Left : constant Entity_Id := First_Formal (Id); Right : constant Entity_Id := Next_Formal (Left); - Bodies : List_Id; Body_Id : Entity_Id; Decl : Node_Id; @@ -318,12 +317,6 @@ package body Exp_Ch8 is -- subprogram. else - -- While expanding record equality we might create auxiliary - -- subprograms that will be placed in the declaration list of the - -- equality subprogram itself. - - Bodies := Empty_List; - Decl := Make_Subprogram_Body (Loc, Specification => @@ -332,7 +325,7 @@ package body Exp_Ch8 is Parameter_Specifications => Copy_Parameter_List (Id), Result_Definition => New_Occurrence_Of (Standard_Boolean, Loc)), - Declarations => Bodies, + Declarations => Empty_List, Handled_Statement_Sequence => Make_Handled_Sequence_Of_Statements (Loc, Statements => New_List ( @@ -340,10 +333,9 @@ package body Exp_Ch8 is Expression => Expand_Record_Equality (Id, - Typ => Typ, - Lhs => Make_Identifier (Loc, Chars (Left)), - Rhs => Make_Identifier (Loc, Chars (Right)), - Bodies => Bodies))))); + Typ => Typ, + Lhs => Make_Identifier (Loc, Chars (Left)), + Rhs => Make_Identifier (Loc, Chars (Right))))))); end if; return Decl;