[LLVMdev] Type strengthening and type weakening
talin at acm.org
Tue Sep 15 23:15:41 PDT 2009
Has anyone done any experiments with regards to type strengthening or
weakening in the context of LLVM?
For example, the GWT compiler does type strengthening - that is, if you
are calling a method on an interface or abstract type, and the compiler
determines through live variable analysis what the concrete type is,
then it goes ahead and re-writes the type information to be the stronger
type. The advantage is that it may then be able to do additional
optimizations, such as inlining the method or avoiding indirect dispatch.
Conversely, Java's "type erasure" is an extreme case of type weakening -
that is, if you have a bunch of functions which operate on similar types
(which might be produced through something like C++ template
instantiation), you can throw away all of the information about those
types that aren't relevant to those functions, and you may find as a
result that many of them become identical and can be merged into a
In the context of LLVM, it would be interesting to have a pass that
could go through a function and transform the types of the input
arguments to be opaque except where the function actually needs the type
information - so for example if a pointer argument is never dereferenced
it can be converted into a void *.
Similarly, a pass that would generate a hash value for a function, and
then see if functions with identical hashes could be merged.
The hardest part would be doing this in a way that preserves the ability
to debug the code.
More information about the llvm-dev