aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2023-01-18 20:52:03 +0100
committerMarc Poulhiès <poulhies@adacore.com>2023-05-16 10:30:56 +0200
commit4b8f39b21e27919c6de00e65b0ba29222c057d26 (patch)
treec7f53c775f22c4b84318d66dc487d2ca560cd04e
parentb92d0c4564a2d9b942bedad3dd1fb2887239020e (diff)
downloadgcc-4b8f39b21e27919c6de00e65b0ba29222c057d26.zip
gcc-4b8f39b21e27919c6de00e65b0ba29222c057d26.tar.gz
gcc-4b8f39b21e27919c6de00e65b0ba29222c057d26.tar.bz2
ada: Introduce Cannot_Be_Superflat flag on N_Range nodes
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.
-rw-r--r--gcc/ada/exp_ch4.adb20
-rw-r--r--gcc/ada/gen_il-fields.ads1
-rw-r--r--gcc/ada/gen_il-gen-gen_nodes.adb3
-rw-r--r--gcc/ada/sinfo.ads7
4 files changed, 22 insertions, 9 deletions
diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
index c1fe02d..9558596 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 458219c..582837c 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 44da1d1..a330f69 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 c25db08..6cacebe 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