在 LLVM 中的 JIT 期间找出预编译函数的函数签名

Figure out function signatures of precompiled functions during JIT in LLVM

我目前正致力于使用 LLVM 实现 JIT 编译器。 我遇到的问题是编译器运行时的一部分是用 C 实现的。

从我的中间表示,我可以生成所有本机函数。但是,语言中的某些操作需要调用这些外部 C 函数。

我遇到的问题是,我的 IR 并不知道传递给这些函数的参数的确切类型,它们可能采用 int,也可能采用 float。之前的代码生成是基于 C 的,C 的弱类型允许毫不费力地调用这些函数。但是,在生成 LLVM-IR 时,我需要知道这些预编译函数的签名,有没有办法使用 orc-API 或其他方法找出签名,或者只是更好硬编码每个必要功能的配置?

我针对这个问题实施的解决方案遵循以下简单方案。

在对这些函数的编译调用过程中,签名仅基于传递给相关预编译函数的参数和 return 值。

这对我的示例很有效,因为我将 C 调用约定与 LLVM 结合使用。引用 LLVM 主页的 C 调用约定容忍不匹配:

"This calling convention (the default if no other calling convention is specified) matches the target C calling conventions. This calling convention supports varargs function calls and tolerates some mismatch in the declared prototype and implemented declaration of the function (as does normal C)." [1]: https://llvm.org/docs/LangRef.html#calling-conventions