From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-3f4c6c4b425so43222905e9.2 for ; Tue, 16 May 2023 01:39:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1684226398; x=1686818398; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=vNeg/90JG4Twp730R0f6qJ6+jXxqdBFZvlvNk8ZVDr0=; b=YJMLw6PRGufbL7yXMiShakmKjbNg66DlR0hCnGelW5UXKY48UWldAwgB/B5pXnHWDw 6JfTiD8f9U7+0dI41UoNjG9OEAlBlMCuRK3bpOoa+jo7EZ3+2heunVBEBRfFWci3QhPM Pi9i5QEOGWF/3IrMOa/jn0sLBsl8qFRJlrDVgjGz78PzhpWczBUH6cOIX1/gateKQa+k YgM/1ZKhl1WBi7q81KX+MKCssTSWbIX2Fhy/wMjFG6Fnf6mF94m4evQ0Yehp8XhoIj9F PhN0ojJ6n4Mr8J2oXs/eg6A91A0YKOhRumdUJ+bdkDytLXo2J57uORYSs5tvb8KADKcd jffg== 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-Google-Smtp-Source: ACHHUZ78NxiY7CLSxR24/2bNUTptIe/4LyA4V7SB9zBLf2Z7OEAvq+gD92opSWRYa4ShIRC620bZAQ== 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) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= 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 Content-Transfer-Encoding: 8bit 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 List-Id: 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 -- 2.40.0