This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[java] Use fold_buildN


 Hi,

  This patch converts the java frontend to use fold_buildN.  This patch has
been bootstrapped and regtested on ia64-linux with no new regessions.  Ok
for mainline?

-- 
Thanks,
Jim

http://www.csclub.uwaterloo.ca/~ja2morri/
http://phython.blogspot.com
http://open.nit.ca/wiki/?page=jim

2005-08-18  James A. Morrison  <phython@gcc.gnu.org>

	* builtins.c (max_builtin, min_builtin, abs_builtin,
	java_build_function_call_expr): Use fold_buildN.
	* class.c (layout_class_method): Likewise.
	* expr.c (java_truthvalue_conversion, build_java_jsr,
	build_java_arrayaccess, expand_java_arrayload, expand_iinc,
	build_java_binop, build_field_ref, expand_compare,
	build_known_method_ref, build_invokevirtual,
	process_jvm_instruction): Likewise.
	* parse.y (patch_binop, patch_exit_expr): Likewise.
	* typeck.c (convert_ieee_real_to_integer): Likewise.
	(convert): Don't call fold after convert_ieee_real_to_integer.

Index: builtins.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/java/builtins.c,v
retrieving revision 1.33
diff -u -p -r1.33 builtins.c
--- builtins.c	25 Jun 2005 11:22:50 -0000	1.33
+++ builtins.c	19 Aug 2005 04:58:25 -0000
@@ -94,24 +94,24 @@ static GTY(()) struct builtin_record jav
 static tree
 max_builtin (tree method_return_type, tree method_arguments)
 {
-  return fold (build2 (MAX_EXPR, method_return_type,
-		       TREE_VALUE (method_arguments),
-		       TREE_VALUE (TREE_CHAIN (method_arguments))));
+  return fold_build2 (MAX_EXPR, method_return_type,
+		      TREE_VALUE (method_arguments),
+		      TREE_VALUE (TREE_CHAIN (method_arguments)));
 }
 
 static tree
 min_builtin (tree method_return_type, tree method_arguments)
 {
-  return fold (build2 (MIN_EXPR, method_return_type,
-		       TREE_VALUE (method_arguments),
-		       TREE_VALUE (TREE_CHAIN (method_arguments))));
+  return fold_build2 (MIN_EXPR, method_return_type,
+		      TREE_VALUE (method_arguments),
+		      TREE_VALUE (TREE_CHAIN (method_arguments)));
 }
 
 static tree
 abs_builtin (tree method_return_type, tree method_arguments)
 {
-  return fold (build1 (ABS_EXPR, method_return_type,
-		       TREE_VALUE (method_arguments)));
+  return fold_build1 (ABS_EXPR, method_return_type,
+		      TREE_VALUE (method_arguments));
 }
 
 /* Mostly copied from ../builtins.c.  */
@@ -121,10 +121,8 @@ java_build_function_call_expr (tree fn, 
   tree call_expr;
 
   call_expr = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (fn)), fn);
-  call_expr = build3 (CALL_EXPR, TREE_TYPE (TREE_TYPE (fn)),
+  return fold_build3 (CALL_EXPR, TREE_TYPE (TREE_TYPE (fn)),
 		      call_expr, arglist, NULL_TREE);
-  TREE_SIDE_EFFECTS (call_expr) = 1;
-  return fold (call_expr);
 }
 
 
Index: class.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/java/class.c,v
retrieving revision 1.239
diff -u -p -r1.239 class.c
--- class.c	17 Aug 2005 20:44:06 -0000	1.239
+++ class.c	19 Aug 2005 04:58:25 -0000
@@ -2380,8 +2380,8 @@ layout_class_method (tree this_class, tr
 	  /* We generate vtable entries for final methods because they
 	     may one day be changed to non-final.  */
 	  set_method_index (method_decl, dtable_count);
-	  dtable_count = fold (build2 (PLUS_EXPR, integer_type_node,
-				       dtable_count, integer_one_node));
+	  dtable_count = fold_build2 (PLUS_EXPR, integer_type_node,
+				      dtable_count, integer_one_node);
 	}
     }
 
Index: expr.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/java/expr.c,v
retrieving revision 1.235
diff -u -p -r1.235 expr.c
--- expr.c	16 Aug 2005 16:06:43 -0000	1.235
+++ expr.c	19 Aug 2005 04:58:25 -0000
@@ -192,10 +192,9 @@ java_truthvalue_conversion (tree expr)
 
     case COND_EXPR:
       /* Distribute the conversion into the arms of a COND_EXPR.  */
-      return fold
-	       (build3 (COND_EXPR, boolean_type_node, TREE_OPERAND (expr, 0),
-			java_truthvalue_conversion (TREE_OPERAND (expr, 1)),
-			java_truthvalue_conversion (TREE_OPERAND (expr, 2))));
+      return fold_build3 (COND_EXPR, boolean_type_node, TREE_OPERAND (expr, 0),
+			  java_truthvalue_conversion (TREE_OPERAND (expr, 1)),
+			  java_truthvalue_conversion (TREE_OPERAND (expr, 2)));
 
     case NOP_EXPR:
       /* If this is widening the argument, we can ignore it.  */
@@ -205,8 +204,8 @@ java_truthvalue_conversion (tree expr)
       /* fall through to default */
 
     default:
-      return fold (build2 (NE_EXPR, boolean_type_node,
-			   expr, boolean_false_node));
+      return fold_build2 (NE_EXPR, boolean_type_node,
+			  expr, boolean_false_node);
     }
 }
 
@@ -724,7 +723,7 @@ build_java_jsr (int target_pc, int retur
 {
   tree where =  lookup_label (target_pc);
   tree ret = lookup_label (return_pc);
-  tree ret_label = fold (build1 (ADDR_EXPR, return_address_type_node, ret));
+  tree ret_label = fold_build1 (ADDR_EXPR, return_address_type_node, ret);
   push_value (ret_label);
   flush_quick_stack ();
   java_add_stmt (build1 (GOTO_EXPR, void_type_node, where));
@@ -891,9 +890,9 @@ build_java_arrayaccess (tree array, tree
       tree test;
       tree len = convert (unsigned_int_type_node,
 			  build_java_array_length_access (array));
-      test = fold (build2 (GE_EXPR, boolean_type_node, 
-			   convert (unsigned_int_type_node, index),
-			   len));
+      test = fold_build2 (GE_EXPR, boolean_type_node, 
+			  convert (unsigned_int_type_node, index),
+			  len);
       if (! integer_zerop (test))
 	{
 	  throw = build2 (TRUTH_ANDIF_EXPR, int_type_node, test,
@@ -1185,7 +1184,7 @@ expand_java_arrayload (tree lhs_type_nod
 				      lhs_type_node,
 				      index_node);
   if (INTEGRAL_TYPE_P (lhs_type_node) && TYPE_PRECISION (lhs_type_node) <= 32)
-    load_node = fold (build1 (NOP_EXPR, int_type_node, load_node));
+    load_node = fold_build1 (NOP_EXPR, int_type_node, load_node);
   push_value (load_node);
 }
 
@@ -1446,7 +1445,7 @@ expand_iinc (unsigned int local_var_inde
   flush_quick_stack ();
   local_var = find_local_variable (local_var_index, int_type_node, pc);
   constant_value = build_int_cst (NULL_TREE, ival);
-  res = fold (build2 (PLUS_EXPR, int_type_node, local_var, constant_value));
+  res = fold_build2 (PLUS_EXPR, int_type_node, local_var, constant_value);
   java_add_stmt (build2 (MODIFY_EXPR, TREE_TYPE (local_var), local_var, res));
   update_aliases (local_var, local_var_index, pc);
 }
@@ -1517,36 +1516,36 @@ build_java_binop (enum tree_code op, tre
     case RSHIFT_EXPR:
       mask = build_int_cst (NULL_TREE,
 			    TYPE_PRECISION (TREE_TYPE (arg1)) - 1);
-      arg2 = fold (build2 (BIT_AND_EXPR, int_type_node, arg2, mask));
+      arg2 = fold_build2 (BIT_AND_EXPR, int_type_node, arg2, mask);
       break;
 
     case COMPARE_L_EXPR:  /* arg1 > arg2 ?  1 : arg1 == arg2 ? 0 : -1 */
     case COMPARE_G_EXPR:  /* arg1 < arg2 ? -1 : arg1 == arg2 ? 0 :  1 */
       arg1 = save_expr (arg1);  arg2 = save_expr (arg2);
       {
-	tree ifexp1 = fold (build2 (op == COMPARE_L_EXPR ? GT_EXPR : LT_EXPR,
-				    boolean_type_node, arg1, arg2));
-	tree ifexp2 = fold (build2 (EQ_EXPR, boolean_type_node, arg1, arg2));
-	tree second_compare = fold (build3 (COND_EXPR, int_type_node,
-					    ifexp2, integer_zero_node,
-					    op == COMPARE_L_EXPR
-					    ? integer_minus_one_node
-					    : integer_one_node));
-	return fold (build3 (COND_EXPR, int_type_node, ifexp1,
-			     op == COMPARE_L_EXPR ? integer_one_node
-			     : integer_minus_one_node,
-			     second_compare));
+	tree ifexp1 = fold_build2 (op == COMPARE_L_EXPR ? GT_EXPR : LT_EXPR,
+				   boolean_type_node, arg1, arg2);
+	tree ifexp2 = fold_build2 (EQ_EXPR, boolean_type_node, arg1, arg2);
+	tree second_compare = fold_build3 (COND_EXPR, int_type_node,
+					   ifexp2, integer_zero_node,
+					   op == COMPARE_L_EXPR
+					   ? integer_minus_one_node
+					   : integer_one_node);
+	return fold_build3 (COND_EXPR, int_type_node, ifexp1,
+			    op == COMPARE_L_EXPR ? integer_one_node
+			    : integer_minus_one_node,
+			    second_compare);
       }
     case COMPARE_EXPR:
       arg1 = save_expr (arg1);  arg2 = save_expr (arg2);
       {
-	tree ifexp1 = fold (build2 (LT_EXPR, boolean_type_node, arg1, arg2));
-	tree ifexp2 = fold (build2 (GT_EXPR, boolean_type_node, arg1, arg2));
-	tree second_compare = fold (build3 (COND_EXPR, int_type_node,
-					    ifexp2, integer_one_node,
-					    integer_zero_node));
-	return fold (build3 (COND_EXPR, int_type_node,
-			     ifexp1, integer_minus_one_node, second_compare));
+	tree ifexp1 = fold_build2 (LT_EXPR, boolean_type_node, arg1, arg2);
+	tree ifexp2 = fold_build2 (GT_EXPR, boolean_type_node, arg1, arg2);
+	tree second_compare = fold_build3 (COND_EXPR, int_type_node,
+					   ifexp2, integer_one_node,
+					   integer_zero_node);
+	return fold_build3 (COND_EXPR, int_type_node,
+			    ifexp1, integer_minus_one_node, second_compare);
       }      
     case TRUNC_DIV_EXPR:
     case TRUNC_MOD_EXPR:
@@ -1577,7 +1576,7 @@ build_java_binop (enum tree_code op, tre
       break;
     default:  ;
     }
-  return fold (build2 (op, type, arg1, arg2));
+  return fold_build2 (op, type, arg1, arg2);
 }
 
 static void
@@ -1687,7 +1686,7 @@ build_field_ref (tree self_value, tree s
 
       tree base_type = promote_type (base_class);
       if (base_type != TREE_TYPE (self_value))
-	self_value = fold (build1 (NOP_EXPR, base_type, self_value));
+	self_value = fold_build1 (NOP_EXPR, base_type, self_value);
       if (! flag_syntax_only && flag_indirect_dispatch)
 	{
 	  tree otable_index
@@ -1701,16 +1700,16 @@ build_field_ref (tree self_value, tree s
 
 	  field_offset = fold (convert (sizetype, field_offset));
 	  address 
-	    = fold (build2 (PLUS_EXPR, 
-			    build_pointer_type (TREE_TYPE (field_decl)),
-			    self_value, field_offset));
-	  return fold (build1 (INDIRECT_REF, TREE_TYPE (field_decl), address));
+	    = fold_build2 (PLUS_EXPR, 
+			   build_pointer_type (TREE_TYPE (field_decl)),
+			   self_value, field_offset);
+	  return fold_build1 (INDIRECT_REF, TREE_TYPE (field_decl), address);
 	}
 
       self_value = build_java_indirect_ref (TREE_TYPE (TREE_TYPE (self_value)),
 					    self_value, check);
-      return fold (build3 (COMPONENT_REF, TREE_TYPE (field_decl),
-			   self_value, field_decl, NULL_TREE));
+      return fold_build3 (COMPONENT_REF, TREE_TYPE (field_decl),
+			  self_value, field_decl, NULL_TREE);
     }
 }
 
@@ -1776,7 +1775,7 @@ expand_compare (enum tree_code condition
 		int target_pc)
 {
   tree target = lookup_label (target_pc);
-  tree cond = fold (build2 (condition, boolean_type_node, value1, value2));
+  tree cond = fold_build2 (condition, boolean_type_node, value1, value2);
   java_add_stmt 
     (build3 (COND_EXPR, void_type_node, java_truthvalue_conversion (cond),
 	     build1 (GOTO_EXPR, void_type_node, target), 
@@ -2056,8 +2055,8 @@ build_known_method_ref (tree method, tre
 	  method_index++;
 	}
       method_index *= int_size_in_bytes (method_type_node);
-      ref = fold (build2 (PLUS_EXPR, method_ptr_type_node,
-			  ref, build_int_cst (NULL_TREE, method_index)));
+      ref = fold_build2 (PLUS_EXPR, method_ptr_type_node,
+			 ref, build_int_cst (NULL_TREE, method_index));
       ref = build1 (INDIRECT_REF, method_type_node, ref);
       func = build3 (COMPONENT_REF, nativecode_ptr_type_node,
 		     ref, lookup_field (&method_type_node, ncode_ident),
@@ -2160,8 +2159,8 @@ build_invokevirtual (tree dtable, tree m
 				   size_int (TARGET_VTABLE_USES_DESCRIPTORS));
     }
 
-  func = fold (build2 (PLUS_EXPR, nativecode_ptr_ptr_type_node, dtable,
-		       convert (nativecode_ptr_ptr_type_node, method_index)));
+  func = fold_build2 (PLUS_EXPR, nativecode_ptr_ptr_type_node, dtable,
+		      convert (nativecode_ptr_ptr_type_node, method_index));
 
   if (TARGET_VTABLE_USES_DESCRIPTORS)
     func = build1 (NOP_EXPR, nativecode_ptr_type_node, func);
@@ -3177,8 +3176,8 @@ process_jvm_instruction (int PC, const u
   }
 
 #define UNOP(OPERAND_TYPE, OPERAND_VALUE) \
-  push_value (fold (build1 (NEGATE_EXPR, OPERAND_TYPE##_type_node, \
-			    pop_value (OPERAND_TYPE##_type_node))));
+  push_value (fold_build1 (NEGATE_EXPR, OPERAND_TYPE##_type_node, \
+			   pop_value (OPERAND_TYPE##_type_node)));
 
 #define CONVERT2(FROM_TYPE, TO_TYPE)					 \
   {									 \
Index: parse.y
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.552
diff -u -p -r1.552 parse.y
--- parse.y	16 Aug 2005 18:22:31 -0000	1.552
+++ parse.y	19 Aug 2005 04:58:25 -0000
@@ -13664,11 +13664,11 @@ patch_binop (tree node, tree wfl_op1, tr
 
       /* Shift int only up to 0x1f and long up to 0x3f */
       if (prom_type == int_type_node)
-	op2 = fold (build2 (BIT_AND_EXPR, int_type_node, op2,
-			    build_int_cst (NULL_TREE, 0x1f)));
+	op2 = fold_build2 (BIT_AND_EXPR, int_type_node, op2,
+			   build_int_cst (NULL_TREE, 0x1f));
       else
-	op2 = fold (build2 (BIT_AND_EXPR, int_type_node, op2,
-			    build_int_cst (NULL_TREE, 0x3f)));
+	op2 = fold_build2 (BIT_AND_EXPR, int_type_node, op2,
+			   build_int_cst (NULL_TREE, 0x3f));
 
       /* The >>> operator is a >> operating on unsigned quantities */
       if (code == URSHIFT_EXPR && (folding || ! flag_emit_class_files))
@@ -15443,7 +15443,7 @@ patch_exit_expr (tree node)
   /* Now we know things are allright, invert the condition, fold and
      return */
   TREE_OPERAND (node, 0) =
-    fold (build1 (TRUTH_NOT_EXPR, boolean_type_node, expression));
+    fold_build1 (TRUTH_NOT_EXPR, boolean_type_node, expression);
 
   if (! integer_zerop (TREE_OPERAND (node, 0))
       && ctxp->current_loop != NULL_TREE
Index: typeck.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/java/typeck.c,v
retrieving revision 1.79
diff -u -p -r1.79 typeck.c
--- typeck.c	25 Jun 2005 00:33:05 -0000	1.79
+++ typeck.c	19 Aug 2005 04:58:25 -0000
@@ -83,24 +83,24 @@ convert_ieee_real_to_integer (tree type,
   tree result;
   expr = save_expr (expr);
 
-  result = fold (build3 (COND_EXPR, type,
-			 fold (build2 (NE_EXPR, boolean_type_node, expr, expr)),
+  result = fold_build3 (COND_EXPR, type,
+			fold_build2 (NE_EXPR, boolean_type_node, expr, expr),
 			 convert (type, integer_zero_node),
-			 convert_to_integer (type, expr)));
+			 convert_to_integer (type, expr));
   
-  result = fold (build3 (COND_EXPR, type, 
-			 fold (build2 (LE_EXPR, boolean_type_node, expr, 
-				       convert (TREE_TYPE (expr), 
-						TYPE_MIN_VALUE (type)))),
-			 TYPE_MIN_VALUE (type),
-			 result));
+  result = fold_build3 (COND_EXPR, type, 
+			fold_build2 (LE_EXPR, boolean_type_node, expr, 
+				     convert (TREE_TYPE (expr), 
+					      TYPE_MIN_VALUE (type))),
+			TYPE_MIN_VALUE (type),
+			result);
   
-  result = fold (build3 (COND_EXPR, type,
-			 fold (build2 (GE_EXPR, boolean_type_node, expr, 
-				       convert (TREE_TYPE (expr), 
-						TYPE_MAX_VALUE (type)))),
-			 TYPE_MAX_VALUE (type),
-			 result));
+  result = fold_build3 (COND_EXPR, type,
+			fold_build2 (GE_EXPR, boolean_type_node, expr, 
+				     convert (TREE_TYPE (expr), 
+					      TYPE_MAX_VALUE (type))),
+			TYPE_MAX_VALUE (type),
+			result);
 
   return result;
 }  
@@ -135,7 +135,7 @@ convert (tree type, tree expr)
 	       && ! flag_emit_class_files))
 	  && TREE_CODE (TREE_TYPE (expr)) == REAL_TYPE
 	  && TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT)
-	return fold (convert_ieee_real_to_integer (type, expr));
+	return convert_ieee_real_to_integer (type, expr);
       else
 	{
 	  /* fold very helpfully sets the overflow status if a type

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]