Question about llvm JIT

I have a function in llvm ir as follows:

def [2 x [3 x double]] @fun()
{
return [ … ]; // a [2 x [3 x double]] constant
}

I would like to JIT this function in C.

I first get the void pointer using:

void *FPtr = TheExecutionEngine->getPointerToFunction( func );

Then I need to conver this void pointer to the corresponding C function pointer
type, and then call the function pointer.

double a[2][3];

CType FP = (CType) FPtr;

a = FP();

My question is that:

  1. Is this JIT work flow supported by LLVM?

  2. If yes, what is correct CType for the JITted function?

  3. If not, what are requirements on the LLVM function IRs such that they could be JIT and called in C?

Thanks,
-Peng

I have a function in llvm ir as follows:

  def [2 x [3 x double]] @fun()
  {
    return [ ... ]; // a [2 x [3 x double]] constant
  }

I would like to JIT this function in C.

I first get the void pointer using:

  void *FPtr = TheExecutionEngine->getPointerToFunction( func );

Then I need to conver this void pointer to the corresponding C function
pointer
type, and then call the function pointer.

  double a[2][3];

  CType *FP = (CType*) FPtr;

  a = FP();

My question is that:

1. Is this JIT work flow supported by LLVM?

Sort of?

2. If yes, what is correct CType for the JITted function?

Probably "typedef void FPtr(double*);", but that's not guaranteed.

3. If not, what are requirements on the LLVM function IRs such that they
could be JIT and called in C?

If you want to generate functions which are easily callable from C,
make sure the return type and all the parameters are pointers or
simple values; otherwise, the correct rule for converting from C types
to IR types is complicated and platform-specific.

-Eli

Thanks!