public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Java: Use TREE_THIS_NOTRAP where possible
@ 2004-06-11 19:37 Andrew Haley
  0 siblings, 0 replies; only message in thread
From: Andrew Haley @ 2004-06-11 19:37 UTC (permalink / raw)
  To: gcc-patches, java-patches

This marks operands of pointer type that cannot trap.  This will
improve scheduling, reduce the number of abnormal edges in the flow
graph, reduce the size of the exception table, ect, ect.

Andrew.



2004-06-11  Andrew Haley  <aph@redhat.com>

	* expr.c (build_java_nontrapping_ref): New function.
	(build_java_indirect_ref): Mark TREE_THIS_NOTRAP when appropriate.
	Fold.
	(build_field_ref, build_known_method_ref, build_invokevirtual,
	emit_init_test_initialization, build_get_class): Use
	build_java_nontrapping_ref, not build (INDIRECT_REF).
	* except.c (build_exception_object_ref): Likewise.
	* class.c (build_static_field_ref): Likewise.

Index: class.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/class.c,v
retrieving revision 1.184
diff -u -w -r1.184 class.c
--- class.c	13 May 2004 06:40:34 -0000	1.184
+++ class.c	11 Jun 2004 18:03:18 -0000
@@ -1089,8 +1089,8 @@
       tree field_address
 	= build (ARRAY_REF, build_pointer_type (TREE_TYPE (fdecl)), 
 		 TYPE_ATABLE_DECL (output_class), table_index);
-      return fold (build1 (INDIRECT_REF, TREE_TYPE (fdecl), 
-			   field_address));
+      return build_java_nontrapping_ref (TREE_TYPE (fdecl), 
+					 field_address);
     }
   else  
     {
@@ -1099,7 +1099,7 @@
       tree ref = build_class_ref (fclass);
       tree fld;
       int field_index = 0;
-      ref = build1 (INDIRECT_REF, class_type_node, ref);
+      ref = build_java_nontrapping_ref (class_type_node, ref);
       ref = build (COMPONENT_REF, field_ptr_type_node, ref,
 		   lookup_field (&class_type_node, fields_ident));
 
@@ -1116,12 +1116,12 @@
       field_index *= int_size_in_bytes (field_type_node);
       ref = fold (build (PLUS_EXPR, field_ptr_type_node,
 			 ref, build_int_2 (field_index, 0)));
-      ref = build1 (INDIRECT_REF, field_type_node, ref);
+      ref = build_java_nontrapping_ref (field_type_node, ref);
       ref = build (COMPONENT_REF, field_info_union_node,
 		   ref, lookup_field (&field_type_node, info_ident));
       ref = build (COMPONENT_REF, ptr_type_node,
 		   ref, TREE_CHAIN (TYPE_FIELDS (field_info_union_node)));
-      return fold (build1 (INDIRECT_REF, TREE_TYPE(fdecl), ref));
+      return build_java_nontrapping_ref (TREE_TYPE(fdecl), ref);
     }
 }
 
Index: except.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/except.c,v
retrieving revision 1.43
diff -u -w -r1.43 except.c
--- except.c	13 May 2004 06:40:34 -0000	1.43
+++ except.c	11 Jun 2004 18:03:18 -0000
@@ -421,7 +421,7 @@
   obj = build (EXC_PTR_EXPR, build_pointer_type (type));
   obj = build (MINUS_EXPR, TREE_TYPE (obj), obj,
 	       TYPE_SIZE_UNIT (TREE_TYPE (obj)));
-  obj = build1 (INDIRECT_REF, type, obj);
+  obj = build_java_nontrapping_ref (type, obj);
 
   return obj;
 }
Index: expr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/expr.c,v
retrieving revision 1.192
diff -u -w -r1.192 expr.c
--- expr.c	8 Jun 2004 13:27:38 -0000	1.192
+++ expr.c	11 Jun 2004 18:03:19 -0000
@@ -721,18 +733,31 @@
 
-/* Reference an object: just like an INDIRECT_REF, but with checking.  */
+/* Reference an object: just like an INDIRECT_REF, but with optional
+   null pointer checking.  */
 
 tree
 build_java_indirect_ref (tree type, tree expr, int check)
 {
   tree t;
   t = java_check_reference (expr, check);
+  if (check)
+    TREE_THIS_NOTRAP (t) = true;
   t = convert (build_pointer_type (type), t);
-  return build1 (INDIRECT_REF, type, t);
+  return fold (build1 (INDIRECT_REF, type, t));
+}
+
+/* Identical to an INDIRECT_REF, but we mark the expr to show that an
+   indirect reference from it cannot trap.  */
+
+tree
+build_java_nontrapping_ref (tree type, tree expr)
+{
+  TREE_THIS_NOTRAP (expr) = true;
+  return build1 (INDIRECT_REF, type, expr);
 }
 
 /* Implement array indexing (either as l-value or r-value).
@@ -1177,7 +1202,7 @@
   tree vtable_field = lookup_field (&object_type_node,
 				    get_identifier ("vtable"));
   return build (COMPONENT_REF, class_ptr_type,
-		build1 (INDIRECT_REF, dtable_type,
+		build_java_nontrapping_ref (dtable_type,
 			build (COMPONENT_REF, dtable_ptr_type,
 			       build_java_indirect_ref (object_type_node, value,
 							flag_check_references),
@@ -1543,7 +1568,7 @@
 	    = fold (build (PLUS_EXPR, 
 			   build_pointer_type (TREE_TYPE (field_decl)),
 			   self_value, field_offset));
-	  return fold (build1 (INDIRECT_REF, TREE_TYPE (field_decl), address));
+	  return build_java_nontrapping_ref (TREE_TYPE (field_decl), address);
 	}
 
       self_value = build_java_indirect_ref (TREE_TYPE (TREE_TYPE (self_value)),
@@ -1852,7 +1877,7 @@
 	 where the method is.  */
       self_type = DECL_CONTEXT (method);
       ref = build_class_ref (self_type);
-      ref = build1 (INDIRECT_REF, class_type_node, ref);
+      ref = build_java_nontrapping_ref (class_type_node, ref);
       if (ncode_ident == NULL_TREE)
 	ncode_ident = get_identifier ("ncode");
       if (methods_ident == NULL_TREE)
@@ -1872,7 +1897,7 @@
       method_index *= int_size_in_bytes (method_type_node);
       ref = fold (build (PLUS_EXPR, method_ptr_type_node,
 			 ref, build_int_2 (method_index, 0)));
-      ref = build1 (INDIRECT_REF, method_type_node, ref);
+      ref = build_java_nontrapping_ref (method_type_node, ref);
       func = build (COMPONENT_REF, nativecode_ptr_type_node,
 		    ref,
 		    lookup_field (&method_type_node, ncode_ident));
@@ -1977,7 +2002,7 @@
   if (TARGET_VTABLE_USES_DESCRIPTORS)
     func = build1 (NOP_EXPR, nativecode_ptr_type_node, func);
   else
-    func = build1 (INDIRECT_REF, nativecode_ptr_type_node, func);
+    func = build_java_nontrapping_ref (nativecode_ptr_type_node, func);
 
   return func;
 }
@@ -3458,7 +3483,7 @@
   else
     rhs = build (GE_EXPR, boolean_type_node,
 		 build (COMPONENT_REF, byte_type_node,
-			build1 (INDIRECT_REF, class_type_node, klass),
+			build_java_nontrapping_ref (class_type_node, klass),
 			lookup_field (&class_type_node,
 				      get_identifier ("state"))),
 		 build_int_2 (JV_STATE_DONE, 0));
Index: java-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/java-tree.h,v
retrieving revision 1.201
diff -u -w -r1.201 java-tree.h
--- java-tree.h	29 May 2004 05:11:41 -0000	1.201
+++ java-tree.h	11 Jun 2004 18:03:20 -0000
@@ -1216,6 +1216,7 @@
 extern tree build_java_array_length_access (tree);
 extern tree build_java_arraynull_check (tree, tree, tree);
 extern tree build_java_indirect_ref (tree, tree, int);
+extern tree build_java_nontrapping_ref (tree, tree);
 extern tree java_check_reference (tree, int);
 extern tree build_get_class (tree);
 extern tree build_instanceof (tree, tree);

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2004-06-11 18:20 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-11 19:37 Java: Use TREE_THIS_NOTRAP where possible Andrew Haley

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).