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.h
file into a shared object file usingg++
. This does not work as neithernm
norreadelf
recognize the resulting file as a valid object. - I tried compiling the
btVector3.h
file into a.bc
file usingclang++ -c -emit-llvm
. This also faces the same issue when usingllvm-nm
to 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 a 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.
Lessthan314 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.