[all-commits] [llvm/llvm-project] 698bb5: [mlir][docs] Add C example for C-compatible wrappe...
Hongren Zheng via All-commits
all-commits at lists.llvm.org
Thu Dec 26 03:58:34 PST 2024
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 698bb5f239f50e8217cbec1d19bf8e0bba8c5d11
https://github.com/llvm/llvm-project/commit/698bb5f239f50e8217cbec1d19bf8e0bba8c5d11
Author: Hongren Zheng <i at zenithal.me>
Date: 2024-12-26 (Thu, 26 Dec 2024)
Changed paths:
M mlir/docs/TargetLLVMIR.md
Log Message:
-----------
[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.
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list