OSDN Git Service

[mlir] support returning unranked memrefs
authorAlex Zinenko <zinenko@google.com>
Fri, 26 Jun 2020 12:34:00 +0000 (14:34 +0200)
committerAlex Zinenko <zinenko@google.com>
Fri, 26 Jun 2020 13:37:37 +0000 (15:37 +0200)
commit6323065fd6026de926b15bb609f4601e366a300c
treefc840241d05708df646bfa1f2e19b89110826182
parentbb91520e4fe89ad35bc89578601bf1c35bd9d2fc
[mlir] support returning unranked memrefs

Initially, unranked memref descriptors in the LLVM dialect were designed only
to be passed into functions. An assertion was guarding against returning
unranked memrefs from functions in the standard-to-LLVM conversion. This is
insufficient for functions that wish to return an unranked memref such that the
caller does not know the rank in advance, and hence cannot allocate the
descriptor and pass it in as an argument.

Introduce a calling convention for returning unranked memref descriptors as
follows. An unranked memref descriptor always points to a ranked memref
descriptor stored on stack of the current function. When an unranked memref
descriptor is returned from a function, the ranked memref descriptor it points
to is copied to dynamically allocated memory, the ownership of which is
transferred to the caller. The caller is responsible for deallocating the
dynamically allocated memory and for copying the pointed-to ranked memref
descriptor onto its stack.

Provide default lowerings for std.return, std.call and std.indirect_call that
maintain the conversion defined above.

This convention is additionally exercised by a runtime test to guard against
memory errors.

Differential Revision: https://reviews.llvm.org/D82647
mlir/docs/ConversionToLLVMDialect.md
mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h
mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp
mlir/test/Conversion/StandardToLLVM/calling-convention.mlir
mlir/test/Dialect/LLVMIR/roundtrip.mlir
mlir/test/Target/llvmir-intrinsics.mlir
mlir/test/mlir-cpu-runner/unranked_memref.mlir