This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC 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]

Re: java aliasing rules


Tom Tromey wrote:

>Bryce> I implemented java_get_alias_set() by simply assigning a new
>Bryce> alias set to every unique field, storing it in
>Bryce> DECL_POINTER_ALIAS_SET for each FIELD_DECL. This managed to
>Bryce> eliminate some redundant loads in my tests, but didn't cause
>Bryce> any measurable improvements in benchmark scores so I didn't get
>Bryce> too excited about it
>
>This sounds like a nice approach.
>My only question is how it handles the length field of an array.
>
>Object[].length and Foo[].length can alias.
>But int[].length and Object[].length cannot.
>

I believe the array length field is not important for aliasing purposes 
because it is read-only.

>Similarly for the interior of arrays.
>
>Maybe we could squeeze out some tiny percentage improvement by taking
>this into account too?
>

I think we can make sure arrays of different primitive types get 
different alias sets. It might also be possible to make sure that A[] 
and B[] are known not to alias when A and B do not extend each other.

For Dan's test case, I can get optimal code simply by setting 
DECL_NONADDRESSABLE_P on all Java FIELD_DECLS (see the patch below), 
there's doesn't seem to be any need for java_get_alias_set or changes to 
the generic alias code to get this.

On PowerPC, before this patch I got:

t.f(first, second):
        lhz 9,10(4)      #  <variable>.f1
        addi 9,9,1
        sth 9,10(4)      #  <variable>.f1
        lhz 11,6(5)      #  <variable>.f2
        addi 11,11,1
        sth 11,6(5)      #  <variable>.f2
        lhz 9,10(4)      #  <variable>.f1
        addi 9,9,1
        sth 9,10(4)      #  <variable>.f1
        lhz 11,6(5)      #  <variable>.f2
        addi 11,11,1
        sth 11,6(5)      #  <variable>.f2
        blr

and with DECL_NONADDRESSABLE_P:

t.f(first, second):
        lhz 9,10(4)      #  <variable>.f1
        lhz 11,6(5)      #  <variable>.f2
        addi 9,9,2
        addi 11,11,2
        sth 9,10(4)      #  <variable>.f1
        sth 11,6(5)      #  <variable>.f2
        blr

regards

Bryce.

Index: class.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/java/class.c,v
retrieving revision 1.130
diff -u -r1.130 class.c
--- class.c	2002/03/03 14:07:32	1.130
+++ class.c	2002/03/29 05:36:33
@@ -762,6 +762,10 @@
   TREE_CHAIN (field) = TYPE_FIELDS (class);
   TYPE_FIELDS (class) = field;
   DECL_CONTEXT (field) = class;
+  
+  /* It is not possible to take the address of a field. */
+  if (TREE_CODE (field) == FIELD_DECL)
+    DECL_NONADDRESSABLE_P (field) = 1;
 
   if (flags & ACC_PUBLIC) FIELD_PUBLIC (field) = 1;
   if (flags & ACC_PROTECTED) FIELD_PROTECTED (field) = 1;
@@ -1858,6 +1862,7 @@
 	  TREE_CHAIN (dummy) = tmp_field;
 	  DECL_CONTEXT (tmp_field) = dtype;
 	  DECL_ARTIFICIAL (tmp_field) = 1;
+	  DECL_NONADDRESSABLE_P (tmp_field) = 1;
 	  dummy = tmp_field;
 	}
 
@@ -1868,6 +1873,7 @@
 	  TREE_CHAIN (dummy) = tmp_field;
 	  DECL_CONTEXT (tmp_field) = dtype;
 	  DECL_ARTIFICIAL (tmp_field) = 1;
+	  DECL_NONADDRESSABLE_P (tmp_field) = 1;
 	  dummy = tmp_field;
 	}
 
@@ -1903,6 +1909,7 @@
   TYPE_FIELDS (this_class) = base_decl;
   DECL_SIZE (base_decl) = TYPE_SIZE (super_class);
   DECL_SIZE_UNIT (base_decl) = TYPE_SIZE_UNIT (super_class);
+  DECL_NONADDRESSABLE_P (base_decl) = 1;
 }
 
 /* Handle the different manners we may have to lay out a super class.  */
Index: java-tree.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/java/java-tree.h,v
retrieving revision 1.142
diff -u -r1.142 java-tree.h
--- java-tree.h	2002/03/27 18:28:02	1.142
+++ java-tree.h	2002/03/29 05:36:39
@@ -1592,6 +1592,7 @@
   else TREE_CHAIN(FIELD) = tmp_field; \
   DECL_CONTEXT (tmp_field) = RTYPE; \
   DECL_ARTIFICIAL (tmp_field) = 1; \
+  DECL_NONADDRESSABLE_P (tmp_field) = 1; \
   FIELD = tmp_field; }
 
 #define FINISH_RECORD(RTYPE) layout_type (RTYPE)
Index: typeck.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/java/typeck.c,v
retrieving revision 1.44
diff -u -r1.44 typeck.c
--- typeck.c	2001/12/03 23:09:42	1.44
+++ typeck.c	2002/03/29 05:37:07
@@ -433,12 +433,15 @@
   FIELD_PUBLIC (fld) = 1;
   FIELD_FINAL (fld) = 1;
   TREE_READONLY (fld) = 1;
+  DECL_NONADDRESSABLE_P (fld) = 1;
 
   atype = build_prim_array_type (element_type, length);
   arfld = build_decl (FIELD_DECL, get_identifier ("data"), atype);
   DECL_CONTEXT (arfld) = t;
   TREE_CHAIN (fld) = arfld;
   DECL_ALIGN (arfld) = TYPE_ALIGN (element_type);
+  DECL_NONADDRESSABLE_P (arfld) = 1;
+  TYPE_NONALIASED_COMPONENT (atype) = 1;
 
   /* We could layout_class, but that loads java.lang.Object prematurely.
    * This is called by the parser, and it is a bad idea to do load_class

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