[LLVMdev] Proposal: function prefix data
Peter Collingbourne
peter at pcc.me.uk
Thu Jul 18 12:30:59 PDT 2013
On Thu, Jul 18, 2013 at 03:23:19PM -0400, Tyler Hardin wrote:
> As much as I like this idea for it's use in languages with type systems
> like Haskell and Scheme, this proposal would limit LLVM to non-Harvard
> architectures. That's generally a really small minority of all processors,
> but it would mean there could never be a clang-avr.
Not really. It just would mean that the prefix data feature would not exist
(or at least would not be usable) on such architectures.
> An alternative you could use is, instead of using the function pointer as
> the variable where you are referring to a function, you could have the
> variable be a pointer to a static struct with the data and the actual
> function pointer. Basically, it's like how static class variables as
> handled in C++.
>
> I don't know LLVM IR, so I'll use C to explain.
>
> Instead of this:
>
> void func(void){}
>
> int main(){
> func();
> return 0;
> }
>
> You could do this:
>
> void func(void){}
>
> /* You have to initialize this at compile time. */
> struct {
> char* data;
> int len;
> void (*ptr)(void) = func;
> } func_data;
>
> int main(){
> func_data.ptr();
> return 0;
> }
You could certainly use something like this to implement runtime
function metadata on Harvard architectures (the existing LLVM GHC
backend must already do something like this), and (optionally, as an
optimisation) prefix data on all other architectures.
Thanks,
--
Peter
More information about the llvm-dev
mailing list