From patchwork Wed Jun 1 08:45:08 2022 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: 1637835 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=x3QgD1g4; 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 (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LCjny31Pdz9s0w for ; Wed, 1 Jun 2022 19:02:14 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B2EEA3834E7A for ; Wed, 1 Jun 2022 09:02:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B2EEA3834E7A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1654074131; bh=sI+kK9I1iOVO1/6EnFm88Im0aioRYprhTfIrrbCPD9s=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=x3QgD1g46X1htGKSsOmMqxvE9/pN/adosbJMs7WHS4UD0WEQGDL44ypw8rp5ASecB axtUT7RneTUCOJuocIXwMVluLzbB5R3ad07xNsVTMVHRbqLRLBE/2cLJ9T5WdgAQ5/ aAiCwyJldF9mhUC8jez1RfTsKStLqUE/A+CHpmsI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by sourceware.org (Postfix) with ESMTPS id A4DB73834F15 for ; Wed, 1 Jun 2022 08:45:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A4DB73834F15 Received: by mail-ej1-x62f.google.com with SMTP id q1so2247084ejz.9 for ; Wed, 01 Jun 2022 01:45:10 -0700 (PDT) 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=sI+kK9I1iOVO1/6EnFm88Im0aioRYprhTfIrrbCPD9s=; b=QlZAGSfvhgmLYQysN3jA1fvno2QiyYVqixCEoqY75uBWoJ+dqNWfYTFm4G+sxQsJ2F whoXDx5ip+wrphTJ46pZse6F/3aYIEURqzLHskGMkWZSN4vyEX1NxJvs+LFQuKvtc8cz uoGyKt/5DfXQ1qyzv5kn7nIMSM4rxk+QoGge1NIYXoxYHxa5p8ieGaeBDRaSufIhs/QD VSyOQ1YJxdw0hIpU23mpcurnfnIiDgnVYTBrT/TM6LpVmP+c5NkPWldIDjDOAWnbbHi6 7v/Pj1XmXRgUg7Dnh6bIZMblL8ApKDILiBq2W9Q32wvSZ7Y3yuyhnRhrTocqI19+lZCp xjQw== X-Gm-Message-State: AOAM533mk6MIbhRkSoxM3ougQinEEWyO06XB0syoTUf6lsS9hXChZyrw N0t1SiBt4CzV0cxnL80OBpZP5M2TkfZJwQ== X-Google-Smtp-Source: ABdhPJxgUnF2CffAL4xagsLt6bLebAMdk2rUrudoaDkg1NbSfp+q/a286oNhQEbnNPNfUPI1Vm2omw== X-Received: by 2002:a17:907:a424:b0:702:f94a:a897 with SMTP id sg36-20020a170907a42400b00702f94aa897mr5457583ejc.255.1654073110180; Wed, 01 Jun 2022 01:45:10 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id u18-20020a170906069200b006f3ef214e13sm441432ejb.121.2022.06.01.01.45.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 01:45:09 -0700 (PDT) Date: Wed, 1 Jun 2022 08:45:08 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Get rid of secondary stack for controlled components of limited types Message-ID: <20220601084508.GA1247206@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-13.2 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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Eric Botcazou Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" The initial work didn't change anything for limited types because they use a specific return mechanism for functions called build-in-place where there is no anonymous return object, so the secondary stack was used only for the sake of consistency with the nonlimited case. This change aligns the limited case with the nonlimited case, i.e. either they both use the primary stack or they both use the secondary stack. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * exp_ch6.adb (Caller_Known_Size): Call Returns_On_Secondary_Stack instead of Requires_Transient_Scope and tidy up. (Needs_BIP_Alloc_Form): Likewise. * exp_util.adb (Initialized_By_Aliased_BIP_Func_Call): Also return true if the build-in-place function call has no BIPalloc parameter. (Is_Finalizable_Transient): Remove redundant test. diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb --- a/gcc/ada/exp_ch6.adb +++ b/gcc/ada/exp_ch6.adb @@ -1055,11 +1055,12 @@ package body Exp_Ch6 is (Func_Call : Node_Id; Result_Subt : Entity_Id) return Boolean is + Ctrl : constant Node_Id := Controlling_Argument (Func_Call); + Utyp : constant Entity_Id := Underlying_Type (Result_Subt); + begin - return - (Is_Definite_Subtype (Underlying_Type (Result_Subt)) - and then No (Controlling_Argument (Func_Call))) - or else not Requires_Transient_Scope (Underlying_Type (Result_Subt)); + return (No (Ctrl) and then Is_Definite_Subtype (Utyp)) + or else not Returns_On_Secondary_Stack (Utyp); end Caller_Known_Size; ----------------------- @@ -10218,7 +10219,7 @@ package body Exp_Ch6 is pragma Assert (Is_Build_In_Place_Function (Func_Id)); Func_Typ : constant Entity_Id := Underlying_Type (Etype (Func_Id)); begin - return Requires_Transient_Scope (Func_Typ); + return Returns_On_Secondary_Stack (Func_Typ); end Needs_BIP_Alloc_Form; ------------------------------------- diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb --- a/gcc/ada/exp_util.adb +++ b/gcc/ada/exp_util.adb @@ -8368,9 +8368,10 @@ package body Exp_Util is function Initialized_By_Aliased_BIP_Func_Call (Trans_Id : Entity_Id) return Boolean; -- Determine whether transient object Trans_Id is initialized by a - -- build-in-place function call where the BIPalloc parameter is of - -- value 1 and BIPaccess is not null. This case creates an aliasing - -- between the returned value and the value denoted by BIPaccess. + -- build-in-place function call where the BIPalloc parameter either + -- does not exist or is Caller_Allocation, and BIPaccess is not null. + -- This case creates an aliasing between the returned value and the + -- value denoted by BIPaccess. function Is_Aliased (Trans_Id : Entity_Id; @@ -8427,11 +8428,14 @@ package body Exp_Util is if Is_Build_In_Place_Function_Call (Call) then declare + Caller_Allocation_Val : constant Uint := + UI_From_Int (BIP_Allocation_Form'Pos (Caller_Allocation)); + Access_Nam : Name_Id := No_Name; Access_OK : Boolean := False; Actual : Node_Id; Alloc_Nam : Name_Id := No_Name; - Alloc_OK : Boolean := False; + Alloc_OK : Boolean := True; Formal : Node_Id; Func_Id : Entity_Id; Param : Node_Id; @@ -8466,7 +8470,7 @@ package body Exp_Util is BIP_Formal_Suffix (BIP_Alloc_Form)); end if; - -- A match for BIPaccess => Temp has been found + -- A nonnull BIPaccess has been found if Chars (Formal) = Access_Nam and then Nkind (Actual) /= N_Null @@ -8474,13 +8478,12 @@ package body Exp_Util is Access_OK := True; end if; - -- A match for BIPalloc => 1 has been found + -- A BIPalloc has been found if Chars (Formal) = Alloc_Nam and then Nkind (Actual) = N_Integer_Literal - and then Intval (Actual) = Uint_1 then - Alloc_OK := True; + Alloc_OK := Intval (Actual) = Caller_Allocation_Val; end if; end if; @@ -8767,7 +8770,6 @@ package body Exp_Util is return Ekind (Obj_Id) in E_Constant | E_Variable and then Needs_Finalization (Desig) - and then Requires_Transient_Scope (Desig) and then Nkind (Rel_Node) /= N_Simple_Return_Statement and then not Is_Part_Of_BIP_Return_Statement (Rel_Node)