Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions mlir/docs/TargetLLVMIR.md
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ Examples:
```mlir
func.func @qux(%arg0: memref<?x?xf32>)
func.func @qux(%arg0: memref<?x?xf32>) attributes {llvm.emit_c_interface}
// Gets converted into the following
// (using type alias for brevity):
Expand Down Expand Up @@ -683,8 +683,18 @@ llvm.func @qux(%arg0: !llvm.ptr, %arg1: !llvm.ptr,
llvm.func @_mlir_ciface_qux(!llvm.ptr)
```


```cpp
// The C function implementation for the interface function.
extern "C" {
void _mlir_ciface_qux(MemRefDescriptor<float, 2> *input) {
// detailed impl
}
}
```
```mlir
func.func @foo(%arg0: memref<?x?xf32>) {
func.func @foo(%arg0: memref<?x?xf32>) attributes {llvm.emit_c_interface} {
return
}
Expand Down Expand Up @@ -719,8 +729,15 @@ llvm.func @_mlir_ciface_foo(%arg0: !llvm.ptr) {
}
```

```cpp
// The C function signature for the interface function.
extern "C" {
void _mlir_ciface_foo(MemRefDescriptor<float, 2> *input);
}
```
```mlir
func.func @foo(%arg0: memref<?x?xf32>) -> memref<?x?xf32> {
func.func @foo(%arg0: memref<?x?xf32>) -> memref<?x?xf32> attributes {llvm.emit_c_interface} {
return %arg0 : memref<?x?xf32>
}
Expand All @@ -744,6 +761,7 @@ llvm.func @foo(%arg0: !llvm.ptr, %arg1: !llvm.ptr, %arg2: i64,
}
// Interface function callable from C.
// NOTE: the returned memref becomes the first argument
llvm.func @_mlir_ciface_foo(%arg0: !llvm.ptr, %arg1: !llvm.ptr) {
%0 = llvm.load %arg1 : !llvm.ptr
%1 = llvm.extractvalue %0[0] : !llvm.memref_2d
Expand All @@ -760,6 +778,14 @@ llvm.func @_mlir_ciface_foo(%arg0: !llvm.ptr, %arg1: !llvm.ptr) {
}
```

```cpp
// The C function signature for the interface function.
extern "C" {
void _mlir_ciface_foo(MemRefDescriptor<float, 2> *output,
MemRefDescriptor<float, 2> *input);
}
```
Rationale: Introducing auxiliary functions for C-compatible interfaces is
preferred to modifying the calling convention since it will minimize the effect
of C compatibility on intra-module calls or calls between MLIR-generated
Expand Down
Loading