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]

Patch: optimize goto-to-goto when generating bytecode


With my recent PR 4766 patch, we can generate a `goto' to a `goto'
when generating a `finally' clause.  I think this can happen in other
situations, too, but I haven't fully investigated.

With this patch, we optimize that case when generating relocs.  We
change `goto X; ... X: goto Y;' to `goto Y; ... X: goto Y'.

Ok to commit?

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>
	* jcf-write.c (perform_relocations): Optmize a goto to a goto.

2001-12-20  Tom Tromey  <tromey@redhat.com>

Index: jcf-write.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/jcf-write.c,v
retrieving revision 1.96
diff -u -r1.96 jcf-write.c
--- jcf-write.c 2001/12/16 16:23:49 1.96
+++ jcf-write.c 2001/12/20 18:14:16
@@ -2618,6 +2618,34 @@
 	  shrink += 3;
 	}
 
+      /* Optimize GOTO L; ... L: GOTO X by changing the first goto to
+	 jump directly to X.  */
+      while (reloc != NULL
+	     && reloc->kind == OPCODE_goto_w
+	     && reloc->label != block
+	     && reloc->label->v.chunk->data != NULL
+	     && reloc->label->v.chunk->data[0] == OPCODE_goto)
+	{
+	  /* Find the reloc for the first instruction of the
+	     destination block.  */
+	  struct jcf_relocation *first_reloc;
+	  for (first_reloc = reloc->label->u.relocations;
+	       first_reloc;
+	       first_reloc = first_reloc->next)
+	    {
+	      if (first_reloc->offset == 1
+		  && first_reloc->kind == OPCODE_goto_w)
+		{
+		  reloc->label = first_reloc->label;
+		  break;
+		}
+	    }
+
+	  /* If we didn't do anything, exit the loop.  */
+	  if (first_reloc == NULL)
+	    break;
+	}
+
       for (reloc = block->u.relocations;  reloc != NULL;  reloc = reloc->next)
 	{
 	  if (reloc->kind == SWITCH_ALIGN_RELOC)


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