diff options
author | Hongren Zheng <i@zenithal.me> | 2024-12-26 19:58:11 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-26 12:58:11 +0100 |
commit | 698bb5f239f50e8217cbec1d19bf8e0bba8c5d11 (patch) | |
tree | 81fd2fe37d9dda96ab6a10296d3dce147deb92d3 /llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp | |
parent | cbe583b0bd8d46b4e5edda463e19e6a24c0817bc (diff) | |
download | llvm-698bb5f239f50e8217cbec1d19bf8e0bba8c5d11.zip llvm-698bb5f239f50e8217cbec1d19bf8e0bba8c5d11.tar.gz llvm-698bb5f239f50e8217cbec1d19bf8e0bba8c5d11.tar.bz2 |
[mlir][docs] Add C example for C-compatible wrapper for LLVM IR (#120955)
`TargetLLVMIR` documentation introduced the C-compatible wrapper
function for a MLIR function and ways to generate it, but did not
demonstrate the corresponding C function signature for them.
The C function signature is not obvious, in that
* `MemrefDescriptor` should be passed as _pointer_.
+ For example, MLIR function could return a new Descriptor, so pointer
is a must.
+ Surprisingly, directly pass the struct, by C convention, is also a
pointer so some function will work, but that is implicit and
error-prone.
* for `@foo() -> memref<>`, the return type becomes the first argument
in `_mlir_ciface_foo(%arg0: !llvm.ptr)`.
+ This is described in
https://github.com/llvm/llvm-project/blob/f70ab7d909d6861c7eec5ab40679bde16ab826c6/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp#L110-L167
Especially by code `size_t argOffset = resultStructType ? 1 : 0;` saying
the actual argument starts at 1 when result is a struct (memref)
Users using the wrong signature will get incorrect results. LLVM
discourse has some example of it
*
https://discourse.llvm.org/t/how-to-compile-and-link-with-other-c-c-programs/4835/10
*
https://discourse.llvm.org/t/segmentation-fault-on-memref-store/80286/3
* https://discourse.llvm.org/t/memref-store-storing-a-memref-load/80307
Cc @ftynse for relevent commit history. Cc @charitha22 and @Wheest from
discourse post.
Diffstat (limited to 'llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp')
0 files changed, 0 insertions, 0 deletions