]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Introduce Cannot_Be_Superflat flag on N_Range nodes
authorEric Botcazou <ebotcazou@adacore.com>
Wed, 18 Jan 2023 19:52:03 +0000 (20:52 +0100)
committerMarc Poulhiès <poulhies@adacore.com>
Tue, 16 May 2023 08:30:56 +0000 (10:30 +0200)
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.

gcc/ada/exp_ch4.adb
gcc/ada/gen_il-fields.ads
gcc/ada/gen_il-gen-gen_nodes.adb
gcc/ada/sinfo.ads

index c1fe02d60c15b5373f8cebd6457f1155006c98eb..9558596ffa0bca4f6e251f378ce522b95f9d7e89 100644 (file)
@@ -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);
index 458219c6853f8eaa3d66111a77d9f421a55df395..582837cb7ecc6427bd363ebd776e8b7584743bb9 100644 (file)
@@ -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,
index 44da1d1d924ba5c5b34c77ccc852ff0b0a163841..a330f6913c5ca81c2a6fcb76b3c23b42698971ae 100644 (file)
@@ -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)));
index c25db08bc964d5df8c90382657c3f878953a96de..6cacebe777573d6be98bd634f69d81c41572017c 100644 (file)
@@ -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