[LLVMdev] Optimizing class casts away

Alysson alysson.pina at gmail.com
Mon Nov 9 12:22:01 PST 2009


Dear all,

   I am trying to remove some instanceof tests from bc code that is produced
by vmkit. For instance:

1 if (o instanceof String) {
2   String s = (String)o;
3 }

Vmkit seems to be inserting two tests into the bc code: one for the test in
line 1, and another, implicit, that would lunch perhaps
JavaClassCastException if the cast fails at runtime.
   Would it be possible for some of you guys more familiar with vmkit to
explain me how it produces code for these casts and tests? I have separated
two CFG's. The first
here<http://www2.dcc.ufmg.br/laboratorios/llp/wiki/lib/exe/fetch.php?media=cfg_for_j2_.pdf>is
for the program below:

public class J2 {
 Object o = new String;
}

The second CFG here<http://www2.dcc.ufmg.br/laboratorios/llp/wiki/lib/exe/fetch.php?media=cfg_for_j1.pdf>is
for the same program, without the cast:

public class J1 {
 Object o = new String;
 String s = (String)o;
}

Could some of you give me an idea of how the extra code would look like? It
seems that the CFG's are a bit big for such small programs.

All the best,
Alysson
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20091109/72b9ffb6/attachment.html>


More information about the llvm-dev mailing list