From: "Marc Poulhiès" <poulhies@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Piotr Trojanek <trojanek@adacore.com>
Subject: [COMMITTED] ada: Create operator nodes in functional style
Date: Mon, 7 Nov 2022 09:39:34 +0100 [thread overview]
Message-ID: <20221107083934.150530-1-poulhies@adacore.com> (raw)
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
reply other threads:[~2022-11-07 8:39 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221107083934.150530-1-poulhies@adacore.com \
--to=poulhies@adacore.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=trojanek@adacore.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).