forked from OSchip/llvm-project
[MLIR][SPIRVToLLVM] SPIR-V function call conversion pattern
Added conversion pattern for SPIR-V `FunctionCallOp`. Based on specification, it returns no results or a single result, so can be mapped directly to LLVM dialect's `llvm.call`. Reviewed By: antiagainst, ftynse Differential Revision: https://reviews.llvm.org/D83030
This commit is contained in:
parent
03fe7eb16f
commit
8119a374bc
|
@ -248,6 +248,28 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
class FunctionCallPattern
|
||||
: public SPIRVToLLVMConversion<spirv::FunctionCallOp> {
|
||||
public:
|
||||
using SPIRVToLLVMConversion<spirv::FunctionCallOp>::SPIRVToLLVMConversion;
|
||||
|
||||
LogicalResult
|
||||
matchAndRewrite(spirv::FunctionCallOp callOp, ArrayRef<Value> operands,
|
||||
ConversionPatternRewriter &rewriter) const override {
|
||||
if (callOp.getNumResults() == 0) {
|
||||
rewriter.replaceOpWithNewOp<LLVM::CallOp>(callOp, llvm::None, operands,
|
||||
callOp.getAttrs());
|
||||
return success();
|
||||
}
|
||||
|
||||
// Function returns a single result.
|
||||
auto dstType = this->typeConverter.convertType(callOp.getType(0));
|
||||
rewriter.replaceOpWithNewOp<LLVM::CallOp>(callOp, dstType, operands,
|
||||
callOp.getAttrs());
|
||||
return success();
|
||||
}
|
||||
};
|
||||
|
||||
/// Converts SPIR-V floating-point comparisons to llvm.fcmp "predicate"
|
||||
template <typename SPIRVOp, LLVM::FCmpPredicate predicate>
|
||||
class FComparePattern : public SPIRVToLLVMConversion<SPIRVOp> {
|
||||
|
@ -551,6 +573,9 @@ void mlir::populateSPIRVToLLVMConversionPatterns(
|
|||
IComparePattern<spirv::ULessThanEqualOp, LLVM::ICmpPredicate::ule>,
|
||||
IComparePattern<spirv::ULessThanOp, LLVM::ICmpPredicate::ult>,
|
||||
|
||||
// Function Call op
|
||||
FunctionCallPattern,
|
||||
|
||||
// Logical ops
|
||||
DirectConversionPattern<spirv::LogicalAndOp, LLVM::AndOp>,
|
||||
DirectConversionPattern<spirv::LogicalOrOp, LLVM::OrOp>,
|
||||
|
|
|
@ -58,5 +58,36 @@ spv.func @vector_types(%arg0: vector<2xi64>, %arg1: vector<2xi64>) -> vector<2xi
|
|||
spv.ReturnValue %0 : vector<2xi64>
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// spv.FunctionCall
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// CHECK-LABEL: llvm.func @function_calls
|
||||
// CHECK-SAME: %[[ARG0:.*]]: !llvm.i32, %[[ARG1:.*]]: !llvm.i1, %[[ARG2:.*]]: !llvm.double, %[[ARG3:.*]]: !llvm<"<2 x i64>">, %[[ARG4:.*]]: !llvm<"<2 x float>">
|
||||
spv.func @function_calls(%arg0: i32, %arg1: i1, %arg2: f64, %arg3: vector<2xi64>, %arg4: vector<2xf32>) -> () "None" {
|
||||
// CHECK: llvm.call @void_1() : () -> ()
|
||||
spv.FunctionCall @void_1() : () -> ()
|
||||
// CHECK: llvm.call @void_2(%[[ARG3]]) : (!llvm<"<2 x i64>">) -> ()
|
||||
spv.FunctionCall @void_2(%arg3) : (vector<2xi64>) -> ()
|
||||
// CHECK: %{{.*}} = llvm.call @value_scalar(%[[ARG0]], %[[ARG1]], %[[ARG2]]) : (!llvm.i32, !llvm.i1, !llvm.double) -> !llvm.i32
|
||||
%0 = spv.FunctionCall @value_scalar(%arg0, %arg1, %arg2) : (i32, i1, f64) -> i32
|
||||
// CHECK: %{{.*}} = llvm.call @value_vector(%[[ARG3]], %[[ARG4]]) : (!llvm<"<2 x i64>">, !llvm<"<2 x float>">) -> !llvm<"<2 x float>">
|
||||
%1 = spv.FunctionCall @value_vector(%arg3, %arg4) : (vector<2xi64>, vector<2xf32>) -> vector<2xf32>
|
||||
spv.Return
|
||||
}
|
||||
|
||||
spv.func @void_1() -> () "None" {
|
||||
spv.Return
|
||||
}
|
||||
|
||||
spv.func @void_2(%arg0: vector<2xi64>) -> () "None" {
|
||||
spv.Return
|
||||
}
|
||||
|
||||
spv.func @value_scalar(%arg0: i32, %arg1: i1, %arg2: f64) -> i32 "None" {
|
||||
spv.ReturnValue %arg0: i32
|
||||
}
|
||||
|
||||
spv.func @value_vector(%arg0: vector<2xi64>, %arg1: vector<2xf32>) -> vector<2xf32> "None" {
|
||||
spv.ReturnValue %arg1: vector<2xf32>
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue