I want to use LLVM to JIT compile some code in my game using the LLVM C/C++ API. The JIT compiled functions should be able to effect the physics of the world, which is handled by bullet3.
To do so I need/want to allocate some space on the stack for a btVector3. This class is not simply a four element array of floats, but fulfills many alignment and SIMD properties, so I think manually creating a struct type would be hard and difficult to maintain.
Is there a way to load the definitions from the btVector3.h file into a LLVM module?
I already tried a few things:
- I tried to compile the
btVector3.hfile into a shared object file usingg++. This does not work as neithernmnorreadelfrecognize the resulting file as a valid object. - I tried compiling the
btVector3.hfile into a.bcfile usingclang++ -c -emit-llvm. This also faces the same issue when usingllvm-nmto check the resulting file. - I also tried to create a proxy file that uses all necessary functions and then compile the proxy. This works for accessing functions like
btVector3::x()in the resulting shared object file, but does not allow me to access the definition of the structure itself.
I can work around the issue by simplifying the btVector3 object to a 16bit align float array, and then every time I want to pass a vector to an extern function void foo(btVector3&) I could call a function like:
void _foo(float* p)
{
btVector3 v(p[0], p[1], p[2]);
foo(v);
p[0] = v.x();
p[1] = v.y();
p[2] = v.z();
}
which I compile into a shared object file beforehand. This feels bad, but would fix the problem and I could even imagine that the JIT optimizer would inline this function, which could fix the problem.
I would be happy about either a way to directly incorporate the definitions as I have stated in the beginning. I would also be happy about any other work around ideas.
StructType *btVector3Ty = StructType::create(context, btVector3). But to my knowlage there is no such constructor.getIfExists()? If I try to look for"btVector3"it will always return null because I did not manually register it yet, no?StructType, including one that loaded a previously writtenModulefrom a file and implicitly created all of the types used in that file. If you know that you'll never load aModulefrom file, you shouldn't needgetIfExists().