Today I wrote a GCC optimizer pass. The new pass is specific to gcj and does a simple form of devirtualization. The idea here is that if we have some extra information about a method call, we can turn an indirect virtual call into a direct call.
My pass does this in one particular case. If the "receiver"
object of a virtual call was allocated with new in the
current method, then we know its exact type, and we can devirtualize.
This is conceptually trivial on the SSA form.
I wrote this pass since I had been playing with similar code for my LLVM-based JIT, and I wanted to compare LLVM and GCC here -- I'd never written a GCC optimization pass and was curious about the effort involved.
It turns out to be simple. This pass is about 200 lines of code. And, when building libgcj, there were more than 6000 cases where it triggered. I'm encouraged by this and now I'm considering writing more gcj-specific optimization passes. Some ideas:
StringBuffer and
StringBuilder.checkcast calls,
and the like.