From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7871) id 8CFDB3858418; Mon, 7 Nov 2022 08:38:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8CFDB3858418 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667810301; bh=Z7dp9//JdhWf5y2IWMNGd6Y7G9EeYQbCuzw+s4dDoHw=; h=From:To:Subject:Date:From; b=YdgP7rOXz8qQa6D0qwMcXUHRcNHgvEOqdO0QgWzJBjY6ufwj+b7Hoka2x1+zWnCED CCLbpVr8xwRftvnWrlRwTm3aSCyeA/JaENpeLmEYYju2YoOqLbaEGRgqG04VFmFF6P Q2VvFArDF8H/Gej1m8Xt5VaZkphJE3e37UV6z/+k= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Marc Poulhi?s To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-3722] ada: Create operator nodes in functional style X-Act-Checkin: gcc X-Git-Author: Piotr Trojanek X-Git-Refname: refs/heads/master X-Git-Oldrev: 03b4e4ae3b0d647a44c3dac09e27ab4151a84e85 X-Git-Newrev: c7e9b5e2d5c7b0e57b127d5c6bb57d3b5bfb6ce1 Message-Id: <20221107083821.8CFDB3858418@sourceware.org> Date: Mon, 7 Nov 2022 08:38:21 +0000 (GMT) List-Id: https://gcc.gnu.org/g:c7e9b5e2d5c7b0e57b127d5c6bb57d3b5bfb6ce1 commit r13-3722-gc7e9b5e2d5c7b0e57b127d5c6bb57d3b5bfb6ce1 Author: Piotr Trojanek Date: Fri Sep 2 13:32:27 2022 +0200 ada: Create operator nodes in functional style 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. Diff: --- 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,