[LLVMdev] Type strengthening and type weakening
sebastian.redl at getdesigned.at
Wed Sep 16 00:12:49 PDT 2009
> 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
> single function.
> 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 *.
Given that LLVM doesn't have much information about the relationships
between types, would this be worth it? Such an optimization should IMO
be done by the front-end, which has higher-level information about
types, such as class hierarchies.
More information about the llvm-dev