[LLVMdev] LLVM for dynamic languages
Rayiner Hashem
gtg990h at mail.gatech.edu
Sun Sep 14 00:58:02 PDT 2003
> That said, many dynamic languages should be cleanly mappable to the LLVM
> layer. What are you thinking about in particular?
Not thinking of one in particular right now, but it would probably something
like an object-oriented Scheme.
> recommend writing some language tuned optimizations (as necessary) that
> would lower the dynamic objects into the primitives the optimizers
> already understand.
Yep. I'm assuming that a language-specific optimizer would handle things like
type inference, so the llvm code would either see plain primitives or a
dynamic representation:
struct object {
int typecode;
};
struct integer {
int typecode;
int value;
};
Thus, the calling code could manipulate integers with pointers to objects.
> If you can express the method dispatch in a way that is useful to the
> preexisting optimizations, of course, you wouldn't have to do anything
> special to support this (C++/Java v-tables fit into the catagory).
As far as I can see, casting needs to be done only once. All the calling code
knows is that it has a pointer to an object. After using the typecode to
lookup the method to call, it calls a given function, passing it the object
parameter. This function knows the precise llvm type of the object, so it
needs to cast the object* to (say) an integer*. Come to think of it, C++/Java
code needs to do the same thing, though the dispatch mechanism is different.
Since llvm doesn't appear to have any notion of inheritence, C++/Java virtual
methods should need to cast their 'this' pointer to the precise type. I
presume this doesn't interfere too much with the other optimizations?
Sincerely,
Rayiner Hashem
More information about the llvm-dev
mailing list