* [COMMITTED] ada: Create operator nodes in functional style
@ 2022-11-07 8:39 Marc Poulhiès
0 siblings, 0 replies; only message in thread
From: Marc Poulhiès @ 2022-11-07 8:39 UTC (permalink / raw)
To: gcc-patches; +Cc: Piotr Trojanek
From: Piotr Trojanek <trojanek@adacore.com>
A recent patch removed two rewritings, where we kept the operator node
but replaced its operands. This patch removes explicit setting of the
operands; instead, the operator is already created together with its
operands, which seems a bit safer and more consistent with how we
typically create operator nodes.
It is a cleanup only; semantics is unaffected.
gcc/ada/
* exp_ch4.adb
(Expand_Modular_Addition): Rewrite using Make_XXX calls.
(Expand_Modular_Op): Likewise.
(Expand_Modular_Subtraction): Likewise.
* exp_imgv.adb
(Expand_User_Defined_Enumeration_Image): Likewise.
Tested on x86_64-pc-linux-gnu, committed on master.
---
gcc/ada/exp_ch4.adb | 122 +++++++++++++++++++++++--------------------
gcc/ada/exp_imgv.adb | 24 ++++-----
2 files changed, 76 insertions(+), 70 deletions(-)
diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
index bbbcf4f6952..b9433c358bf 100644
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -4154,39 +4154,42 @@ package body Exp_Ch4 is
Mod_Minus_Right : constant Uint :=
Modulus (Typ) - Intval (Right_Opnd (N));
- Exprs : constant List_Id := New_List;
- Cond_Expr : constant Node_Id := New_Op_Node (N_Op_Lt, Loc);
- Then_Expr : constant Node_Id := New_Op_Node (N_Op_Add, Loc);
- Else_Expr : constant Node_Id := New_Op_Node (N_Op_Subtract,
- Loc);
+ Cond_Expr : Node_Id;
+ Then_Expr : Node_Id;
+ Else_Expr : Node_Id;
begin
-- To prevent spurious visibility issues, convert all
-- operands to Standard.Unsigned.
- Set_Left_Opnd (Cond_Expr,
- Unchecked_Convert_To (Standard_Unsigned,
- New_Copy_Tree (Left_Opnd (N))));
- Set_Right_Opnd (Cond_Expr,
- Make_Integer_Literal (Loc, Mod_Minus_Right));
- Append_To (Exprs, Cond_Expr);
-
- Set_Left_Opnd (Then_Expr,
- Unchecked_Convert_To (Standard_Unsigned,
- New_Copy_Tree (Left_Opnd (N))));
- Set_Right_Opnd (Then_Expr,
- Make_Integer_Literal (Loc, Intval (Right_Opnd (N))));
- Append_To (Exprs, Then_Expr);
-
- Set_Left_Opnd (Else_Expr,
- Unchecked_Convert_To (Standard_Unsigned,
- New_Copy_Tree (Left_Opnd (N))));
- Set_Right_Opnd (Else_Expr,
- Make_Integer_Literal (Loc, Mod_Minus_Right));
- Append_To (Exprs, Else_Expr);
+ Cond_Expr :=
+ Make_Op_Lt (Loc,
+ Left_Opnd =>
+ Unchecked_Convert_To (Standard_Unsigned,
+ New_Copy_Tree (Left_Opnd (N))),
+ Right_Opnd =>
+ Make_Integer_Literal (Loc, Mod_Minus_Right));
+
+ Then_Expr :=
+ Make_Op_Add (Loc,
+ Left_Opnd =>
+ Unchecked_Convert_To (Standard_Unsigned,
+ New_Copy_Tree (Left_Opnd (N))),
+ Right_Opnd =>
+ Make_Integer_Literal (Loc, Intval (Right_Opnd (N))));
+
+ Else_Expr :=
+ Make_Op_Subtract (Loc,
+ Left_Opnd =>
+ Unchecked_Convert_To (Standard_Unsigned,
+ New_Copy_Tree (Left_Opnd (N))),
+ Right_Opnd =>
+ Make_Integer_Literal (Loc, Mod_Minus_Right));
Rewrite (N,
Unchecked_Convert_To (Typ,
- Make_If_Expression (Loc, Expressions => Exprs)));
+ Make_If_Expression (Loc,
+ Expressions =>
+ New_List (Cond_Expr, Then_Expr, Else_Expr))));
end;
end if;
end Expand_Modular_Addition;
@@ -4202,7 +4205,7 @@ package body Exp_Ch4 is
-- backend does not have to deal with nonbinary-modulus ops.
Op_Expr : constant Node_Id := New_Op_Node (Nkind (N), Loc);
- Mod_Expr : constant Node_Id := New_Op_Node (N_Op_Mod, Loc);
+ Mod_Expr : Node_Id;
Target_Type : Entity_Id;
begin
@@ -4297,10 +4300,10 @@ package body Exp_Ch4 is
Force_Evaluation (Op_Expr, Mode => Strict);
end if;
- Set_Left_Opnd (Mod_Expr, Op_Expr);
-
- Set_Right_Opnd (Mod_Expr,
- Make_Integer_Literal (Loc, Modulus (Typ)));
+ Mod_Expr :=
+ Make_Op_Mod (Loc,
+ Left_Opnd => Op_Expr,
+ Right_Opnd => Make_Integer_Literal (Loc, Modulus (Typ)));
Rewrite (N,
Unchecked_Convert_To (Typ, Mod_Expr));
@@ -4331,37 +4334,40 @@ package body Exp_Ch4 is
Mod_Minus_Right : constant Uint :=
Modulus (Typ) - Intval (Right_Opnd (N));
- Exprs : constant List_Id := New_List;
- Cond_Expr : constant Node_Id := New_Op_Node (N_Op_Lt, Loc);
- Then_Expr : constant Node_Id := New_Op_Node (N_Op_Add, Loc);
- Else_Expr : constant Node_Id := New_Op_Node (N_Op_Subtract,
- Loc);
+ Cond_Expr : Node_Id;
+ Then_Expr : Node_Id;
+ Else_Expr : Node_Id;
begin
- Set_Left_Opnd (Cond_Expr,
- Unchecked_Convert_To (Standard_Unsigned,
- New_Copy_Tree (Left_Opnd (N))));
- Set_Right_Opnd (Cond_Expr,
- Make_Integer_Literal (Loc, Intval (Right_Opnd (N))));
- Append_To (Exprs, Cond_Expr);
-
- Set_Left_Opnd (Then_Expr,
- Unchecked_Convert_To (Standard_Unsigned,
- New_Copy_Tree (Left_Opnd (N))));
- Set_Right_Opnd (Then_Expr,
- Make_Integer_Literal (Loc, Mod_Minus_Right));
- Append_To (Exprs, Then_Expr);
-
- Set_Left_Opnd (Else_Expr,
- Unchecked_Convert_To (Standard_Unsigned,
- New_Copy_Tree (Left_Opnd (N))));
- Set_Right_Opnd (Else_Expr,
- Unchecked_Convert_To (Standard_Unsigned,
- New_Copy_Tree (Right_Opnd (N))));
- Append_To (Exprs, Else_Expr);
+ Cond_Expr :=
+ Make_Op_Lt (Loc,
+ Left_Opnd =>
+ Unchecked_Convert_To (Standard_Unsigned,
+ New_Copy_Tree (Left_Opnd (N))),
+ Right_Opnd =>
+ Make_Integer_Literal (Loc, Intval (Right_Opnd (N))));
+
+ Then_Expr :=
+ Make_Op_Add (Loc,
+ Left_Opnd =>
+ Unchecked_Convert_To (Standard_Unsigned,
+ New_Copy_Tree (Left_Opnd (N))),
+ Right_Opnd =>
+ Make_Integer_Literal (Loc, Mod_Minus_Right));
+
+ Else_Expr :=
+ Make_Op_Subtract (Loc,
+ Left_Opnd =>
+ Unchecked_Convert_To (Standard_Unsigned,
+ New_Copy_Tree (Left_Opnd (N))),
+ Right_Opnd =>
+ Unchecked_Convert_To (Standard_Unsigned,
+ New_Copy_Tree (Right_Opnd (N))));
Rewrite (N,
Unchecked_Convert_To (Typ,
- Make_If_Expression (Loc, Expressions => Exprs)));
+ Make_If_Expression (Loc,
+ Expressions =>
+ New_List (Cond_Expr, Then_Expr, Else_Expr))));
end;
end if;
end Expand_Modular_Subtraction;
diff --git a/gcc/ada/exp_imgv.adb b/gcc/ada/exp_imgv.adb
index 51f1195a8c6..f2043f525d5 100644
--- a/gcc/ada/exp_imgv.adb
+++ b/gcc/ada/exp_imgv.adb
@@ -938,12 +938,12 @@ package body Exp_Imgv is
-- P3 : constant Natural := call_put_enumN (P1 + 1);
declare
- Add_Node : constant Node_Id := New_Op_Node (N_Op_Add, Loc);
+ Add_Node : constant Node_Id :=
+ Make_Op_Add (Loc,
+ Left_Opnd => New_Occurrence_Of (P1_Id, Loc),
+ Right_Opnd => Make_Integer_Literal (Loc, Uint_1));
begin
- Set_Left_Opnd (Add_Node, New_Occurrence_Of (P1_Id, Loc));
- Set_Right_Opnd (Add_Node, Make_Integer_Literal (Loc, 1));
-
Append_To (Ins_List,
Make_Object_Declaration (Loc,
Defining_Identifier => P3_Id,
@@ -963,12 +963,12 @@ package body Exp_Imgv is
-- P4 : String renames call_put_enumS (P2 .. P3 - 1);
declare
- Sub_Node : constant Node_Id := New_Op_Node (N_Op_Subtract, Loc);
+ Sub_Node : constant Node_Id :=
+ Make_Op_Subtract (Loc,
+ Left_Opnd => New_Occurrence_Of (P3_Id, Loc),
+ Right_Opnd => Make_Integer_Literal (Loc, Uint_1));
begin
- Set_Left_Opnd (Sub_Node, New_Occurrence_Of (P3_Id, Loc));
- Set_Right_Opnd (Sub_Node, Make_Integer_Literal (Loc, 1));
-
Append_To (Ins_List,
Make_Object_Renaming_Declaration (Loc,
Defining_Identifier => P4_Id,
@@ -988,12 +988,12 @@ package body Exp_Imgv is
-- subtype S1 is String (1 .. P3 - P2);
declare
- HB : constant Node_Id := New_Op_Node (N_Op_Subtract, Loc);
+ HB : constant Node_Id :=
+ Make_Op_Subtract (Loc,
+ Left_Opnd => New_Occurrence_Of (P3_Id, Loc),
+ Right_Opnd => New_Occurrence_Of (P2_Id, Loc));
begin
- Set_Left_Opnd (HB, New_Occurrence_Of (P3_Id, Loc));
- Set_Right_Opnd (HB, New_Occurrence_Of (P2_Id, Loc));
-
Append_To (Ins_List,
Make_Subtype_Declaration (Loc,
Defining_Identifier => S1_Id,
--
2.34.1
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-11-07 8:39 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-07 8:39 [COMMITTED] ada: Create operator nodes in functional style Marc Poulhiès
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).