From patchwork Tue May 16 08:39:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Patchwork-Id: 94518 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp270831vqo; Tue, 16 May 2023 01:43:28 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7Yr0a+gWPZ8WfP2XaJfR0sEZxGWWcZVMz7ty2JmRHmbJeMWrsTSrxMomY+brgvbGUjhxPU X-Received: by 2002:a05:6402:1a48:b0:50c:d5d:c960 with SMTP id bf8-20020a0564021a4800b0050c0d5dc960mr28853123edb.38.1684226608182; Tue, 16 May 2023 01:43:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684226608; cv=none; d=google.com; s=arc-20160816; b=PRuVIIQRZTFiYHVs+AMHPKf8obzj+uj5t0ILamH+Pk32cVsv1FQ8j+AW/TaGj33rnc /jXjjnMnJf5rhn4zju5w8gAjMXBsa9IFT1Qkpmt3zoghPGwgBorp7pliusWd2C2wdgrV G2Qi5qO3Pn52I8DSA+y5c+UUYCzMgodkKeKD5SIj5KINNQ9SKqwQjFDYs2zvytrQxPDs 9HlNAPndx7XH0hw5jrEdZ+3snJ+xdUb+ZENLifynuOB/ZxXNgN8eYGmU4S20uqnzhRsj v020+lUggriByn38Dntw32Vrpo4r3JTKr9D0HyOPzTOXAfzVoJ89nmy3NqJ2cLwVBxQG VAKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=vNeg/90JG4Twp730R0f6qJ6+jXxqdBFZvlvNk8ZVDr0=; b=NwVMgCwJMN7RKfkJ6UZeR9IMjssY6vbTnhdm6NwctXjKd/hlFDC7EfNOFb6tNEOyUs 5D6OjMhXbI1Ji5Z8pOl6l1FN0O3rwpwxzNCNNak9VdScb5QAnWcRD94kiDJkgH0g7G4O zPuu9FND13SspMxjCUhdRB+dbss5xmJxPUgUF6bTh8ucDCB3F6JeXCzobjuyWDTU67NH NT8WrDAoX5nttARV+jATHG3IbMrQ7Q6EnXtlhir55a0CifW2Bjx/nCvhvD0pwEurbl3D Dlc+GRcsq/2InFmUKJp4TG3H37/cPu5qnLXgztuqK06hjRLsjNzRrBr/sh100RbsuW3m hgZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="e1lb7/kQ"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id f13-20020a05640214cd00b0050bc5ffdee1si12048696edx.462.2023.05.16.01.43.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 May 2023 01:43:28 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="e1lb7/kQ"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EDF0E3881D15 for ; Tue, 16 May 2023 08:41:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EDF0E3881D15 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684226493; bh=vNeg/90JG4Twp730R0f6qJ6+jXxqdBFZvlvNk8ZVDr0=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=e1lb7/kQT988GnzEJYkwuCp2pJojZwuEVR47X+XSgJVXqtSmoAphJuTXy3654/zKx 7HygqKaZrRakqdyCHCb4+twhBdygBJJCgmnooRVGOQxvJ9S/Ch8vxU210OsJESfnrw IT9gcu9M2j0sPxu737QiwXjsgVQ78hLFyCUdRDxY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by sourceware.org (Postfix) with ESMTPS id BE1CA385354C for ; Tue, 16 May 2023 08:39:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BE1CA385354C Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-3f4c6c4b425so43222905e9.2 for ; Tue, 16 May 2023 01:39:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684226398; x=1686818398; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=vNeg/90JG4Twp730R0f6qJ6+jXxqdBFZvlvNk8ZVDr0=; b=Mdskki4rMGjrRIcubwBHwNlViKP0V2PIphcXt0V+aQ9Dh9n4CabubqUPzyvL0AbZyb t9Sxbs3NZqoKQnDMXgLGTaLsIJ1RYuBQe/WiRgWXHWqZGg0hPUDxcLMs4QZDzEpF+Isj C1lgPZDpg4u2HwtbLhg0lrn4OrPUZI2HWd9kF0F7scs3wA90SXwIx63Q2YFGW45asSsw tn42UI3x/DeOG0qDs4fRu7QY6rK7uNSPDuPQujRhYbeF8/pco6slEybv/1KYsHeCDVcg RJVeOOaKShE+LrFR7SG/xQJtzPHU3vn3lEciPgk1rhHcXiy8WsfInunykleNNSRPiAup nuAA== X-Gm-Message-State: AC+VfDyz4AglKVlqvTVCR1RHge7N4emNpYWJbJpTKe6zNZI4YOoiUUNR SWnGilp8IuHrvJK0TvIhtBCZuKoMTmCNBSnP4e7hAA== X-Received: by 2002:a05:600c:243:b0:3f4:2b72:eaa9 with SMTP id 3-20020a05600c024300b003f42b72eaa9mr17377946wmj.8.1684226398576; Tue, 16 May 2023 01:39:58 -0700 (PDT) Received: from poulhies-Precision-5550.telnowedge.local (lmontsouris-659-1-24-67.w81-250.abo.wanadoo.fr. [81.250.175.67]) by smtp.gmail.com with ESMTPSA id k5-20020a5d5185000000b0030497b3224bsm1774212wrv.64.2023.05.16.01.39.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 May 2023 01:39:57 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED] ada: Introduce Cannot_Be_Superflat flag on N_Range nodes Date: Tue, 16 May 2023 10:39:56 +0200 Message-Id: <20230516083956.1501148-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.5 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: =?utf-8?q?Marc_Poulhi=C3=A8s_via_Gcc-patches?= From: =?utf-8?q?Marc_Poulhi=C3=A8s?= Reply-To: =?utf-8?q?Marc_Poulhi=C3=A8s?= Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766039600182055684?= X-GMAIL-MSGID: =?utf-8?q?1766039600182055684?= From: Eric Botcazou The support of superflat arrays in the language generates an overhead that the code generator attempts to minimize, but it cannot handle too complex cases and it would be helpful if the front-end could lend a hand. This change introduces the Cannot_Be_Superflat flag on N_Range nodes for this purpose, and sets it on the result of string concatenations when it is guaranteed to be nonnull. gcc/ada/ * gen_il-fields.ads (Opt_Field_Enum): Add Cannot_Be_Superflat. * gen_il-gen-gen_nodes.adb (N_Range): Add Cannot_Be_Superflat as semantical flag and change Includes_Infinities to semantical. * sinfo.ads (Cannot_Be_Superflat): Document it for N_Range. * exp_ch4.adb (Expand_Concatenate): Set Cannot_Be_Superflat on the range of the result if the result cannot be null. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/exp_ch4.adb | 20 ++++++++++++-------- gcc/ada/gen_il-fields.ads | 1 + gcc/ada/gen_il-gen-gen_nodes.adb | 3 ++- gcc/ada/sinfo.ads | 7 +++++++ 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb index c1fe02d60c1..9558596ffa0 100644 --- a/gcc/ada/exp_ch4.adb +++ b/gcc/ada/exp_ch4.adb @@ -2536,7 +2536,7 @@ package body Exp_Ch4 is -- Reset to False if at least one operand is encountered which is known -- at compile time to be non-null. Used for handling the special case -- of setting the high bound to the last operand high bound for a null - -- result, thus ensuring a proper high bound in the super-flat case. + -- result, thus ensuring a proper high bound in the superflat case. N : constant Nat := List_Length (Opnds); -- Number of concatenation operands including possibly null operands @@ -2726,8 +2726,9 @@ package body Exp_Ch4 is -- Local Declarations Opnd_Typ : Entity_Id; - Slice_Rng : Entity_Id; - Subtyp_Ind : Entity_Id; + Slice_Rng : Node_Id; + Subtyp_Ind : Node_Id; + Subtyp_Rng : Node_Id; Ent : Entity_Id; Len : Unat; J : Nat; @@ -3184,7 +3185,7 @@ package body Exp_Ch4 is -- Handle the exceptional case where the result is null, in which case -- case the bounds come from the last operand (so that we get the proper - -- bounds if the last operand is super-flat). + -- bounds if the last operand is superflat). if Result_May_Be_Null then Low_Bound := @@ -3239,6 +3240,12 @@ package body Exp_Ch4 is Slice_Rng := Empty; end if; + Subtyp_Rng := Make_Range (Loc, Low_Bound, High_Bound); + + -- If the result cannot be null then the range cannot be superflat + + Set_Cannot_Be_Superflat (Subtyp_Rng, not Result_May_Be_Null); + -- Now we construct an array object with appropriate bounds. We mark -- the target as internal to prevent useless initialization when -- Initialize_Scalars is enabled. Also since this is the actual result @@ -3249,10 +3256,7 @@ package body Exp_Ch4 is Subtype_Mark => New_Occurrence_Of (Atyp, Loc), Constraint => Make_Index_Or_Discriminant_Constraint (Loc, - Constraints => New_List ( - Make_Range (Loc, - Low_Bound => Low_Bound, - High_Bound => High_Bound)))); + Constraints => New_List (Subtyp_Rng))); Ent := Make_Temporary (Loc, 'S'); Set_Is_Internal (Ent); diff --git a/gcc/ada/gen_il-fields.ads b/gcc/ada/gen_il-fields.ads index 458219c6853..582837cb7ec 100644 --- a/gcc/ada/gen_il-fields.ads +++ b/gcc/ada/gen_il-fields.ads @@ -87,6 +87,7 @@ package Gen_IL.Fields is Body_Required, Body_To_Inline, Box_Present, + Cannot_Be_Superflat, Char_Literal_Value, Chars, Check_Address_Alignment, diff --git a/gcc/ada/gen_il-gen-gen_nodes.adb b/gcc/ada/gen_il-gen-gen_nodes.adb index 44da1d1d924..a330f6913c5 100644 --- a/gcc/ada/gen_il-gen-gen_nodes.adb +++ b/gcc/ada/gen_il-gen-gen_nodes.adb @@ -531,7 +531,8 @@ begin -- Gen_IL.Gen.Gen_Nodes Cc (N_Range, N_Subexpr, (Sy (Low_Bound, Node_Id), Sy (High_Bound, Node_Id), - Sy (Includes_Infinities, Flag))); + Sm (Cannot_Be_Superflat, Flag), + Sm (Includes_Infinities, Flag))); Cc (N_Reference, N_Subexpr, (Sy (Prefix, Node_Id))); diff --git a/gcc/ada/sinfo.ads b/gcc/ada/sinfo.ads index c25db08bc96..6cacebe7775 100644 --- a/gcc/ada/sinfo.ads +++ b/gcc/ada/sinfo.ads @@ -932,6 +932,12 @@ package Sinfo is -- a pragma Import or Interface applies, in which case no body is -- permitted (in Ada 83 or Ada 95). + -- Cannot_Be_Superflat + -- This flag is present in N_Range nodes. It is set if the range is of a + -- discrete type and cannot be superflat, i.e. it is guaranteed that the + -- inequality High_Bound >= Low_Bound - 1 is true. At the time of this + -- writing, it is only used by the code generator to streamline things. + -- Cleanup_Actions -- Present in block statements created for transient blocks, contains -- additional cleanup actions carried over from the transient scope. @@ -3081,6 +3087,7 @@ package Sinfo is -- Sloc points to .. -- Low_Bound -- High_Bound + -- Cannot_Be_Superflat -- Includes_Infinities -- plus fields for expression