* jcf-write.c (perform_relocations): Optmize a goto to a goto.
authorTom Tromey <tromey@redhat.com>
Tue, 4 Jun 2002 22:09:43 +0000 (22:09 +0000)
committerTom Tromey <tromey@gcc.gnu.org>
Tue, 4 Jun 2002 22:09:43 +0000 (22:09 +0000)
From-SVN: r54264

gcc/java/ChangeLog
gcc/java/jcf-write.c

index e05dba1504f677ad0905c5d543dd808b57b0cea5..10a4746a8d095c6468afd8d5ad6993ccc6af516d 100644 (file)
@@ -1,3 +1,7 @@
+2002-06-04  Tom Tromey  <tromey@redhat.com>
+
+       * jcf-write.c (perform_relocations): Optmize a goto to a goto.
+
 2002-06-04  Michael Koch  <konqueror@gmx.de>
 
        * gcj.texi (Input Options): Fixed typo.
index 7ddca448448fdec0af86c5f2ff69d234c9376a77..f419e9f7ad388f100c25cda12432f2ba4824e808 100644 (file)
@@ -2677,6 +2677,37 @@ perform_relocations (state)
          shrink += 3;
        }
 
+      /* Optimize GOTO L; ... L: GOTO X by changing the first goto to
+        jump directly to X.  We're careful here to avoid an infinite
+        loop if the `goto's themselves form one.  We do this
+        optimization because we can generate a goto-to-goto for some
+        try/finally blocks.  */
+      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)