[Mlir-commits] [mlir] eb6b7c5 - [MLIR][SPIRVToLLVM] Conversion of SPIR-V struct type without offset
George Mitenkov
llvmlistbot at llvm.org
Fri Jul 10 00:16:24 PDT 2020
Author: George Mitenkov
Date: 2020-07-10T10:15:45+03:00
New Revision: eb6b7c5d4fd4aeaf92d0ad560e0c078a95d66902
URL: https://github.com/llvm/llvm-project/commit/eb6b7c5d4fd4aeaf92d0ad560e0c078a95d66902
DIFF: https://github.com/llvm/llvm-project/commit/eb6b7c5d4fd4aeaf92d0ad560e0c078a95d66902.diff
LOG: [MLIR][SPIRVToLLVM] Conversion of SPIR-V struct type without offset
This patch introduces type conversion for SPIR-V structs. Since
handling offset case requires thorough testing, it was left out
for now. Hence, only structs with no offset are currently
supported. Also, structs containing member decorations cannot
be translated.
Reviewed By: antiagainst
Differential Revision: https://reviews.llvm.org/D83403
Added:
Modified:
mlir/lib/Conversion/SPIRVToLLVM/ConvertSPIRVToLLVM.cpp
mlir/test/Conversion/SPIRVToLLVM/spirv-types-to-llvm.invalid.mlir
mlir/test/Conversion/SPIRVToLLVM/spirv-types-to-llvm.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Conversion/SPIRVToLLVM/ConvertSPIRVToLLVM.cpp b/mlir/lib/Conversion/SPIRVToLLVM/ConvertSPIRVToLLVM.cpp
index 7755656ea3b8..5820d9022ae1 100644
--- a/mlir/lib/Conversion/SPIRVToLLVM/ConvertSPIRVToLLVM.cpp
+++ b/mlir/lib/Conversion/SPIRVToLLVM/ConvertSPIRVToLLVM.cpp
@@ -165,6 +165,17 @@ static Value processCountOrOffset(Location loc, Value value, Type srcType,
return optionallyTruncateOrExtend(loc, broadcasted, dstType, rewriter);
}
+/// Converts SPIR-V struct with no offset to packed LLVM struct.
+static Type convertStructTypePacked(spirv::StructType type,
+ LLVMTypeConverter &converter) {
+ auto elementsVector = llvm::to_vector<8>(
+ llvm::map_range(type.getElementTypes(), [&](Type elementType) {
+ return converter.convertType(elementType).cast<LLVM::LLVMType>();
+ }));
+ return LLVM::LLVMType::getStructTy(converter.getDialect(), elementsVector,
+ /*isPacked=*/true);
+}
+
//===----------------------------------------------------------------------===//
// Type conversion
//===----------------------------------------------------------------------===//
@@ -202,6 +213,17 @@ static Optional<Type> convertRuntimeArrayType(spirv::RuntimeArrayType type,
return LLVM::LLVMType::getArrayTy(elementType, 0);
}
+/// Converts SPIR-V struct to LLVM struct. There is no support of structs with
+/// member decorations or with offset.
+static Optional<Type> convertStructType(spirv::StructType type,
+ LLVMTypeConverter &converter) {
+ SmallVector<spirv::StructType::MemberDecorationInfo, 4> memberDecorations;
+ type.getMemberDecorations(memberDecorations);
+ if (type.hasOffset() || !memberDecorations.empty())
+ return llvm::None;
+ return convertStructTypePacked(type, converter);
+}
+
//===----------------------------------------------------------------------===//
// Operation conversion
//===----------------------------------------------------------------------===//
@@ -711,6 +733,9 @@ void mlir::populateSPIRVToLLVMTypeConversion(LLVMTypeConverter &typeConverter) {
typeConverter.addConversion([&](spirv::RuntimeArrayType type) {
return convertRuntimeArrayType(type, typeConverter);
});
+ typeConverter.addConversion([&](spirv::StructType type) {
+ return convertStructType(type, typeConverter);
+ });
}
void mlir::populateSPIRVToLLVMConversionPatterns(
diff --git a/mlir/test/Conversion/SPIRVToLLVM/spirv-types-to-llvm.invalid.mlir b/mlir/test/Conversion/SPIRVToLLVM/spirv-types-to-llvm.invalid.mlir
index 8115b973507b..96fb9f44af57 100644
--- a/mlir/test/Conversion/SPIRVToLLVM/spirv-types-to-llvm.invalid.mlir
+++ b/mlir/test/Conversion/SPIRVToLLVM/spirv-types-to-llvm.invalid.mlir
@@ -4,3 +4,24 @@
spv.func @array_with_stride(%arg: !spv.array<4 x f32, stride=4>) -> () "None" {
spv.Return
}
+
+// -----
+
+// expected-error at +1 {{failed to legalize operation 'spv.func' that was explicitly marked illegal}}
+spv.func @struct_with_offset1(%arg: !spv.struct<i32[0], i32[4]>) -> () "None" {
+ spv.Return
+}
+
+// -----
+
+// expected-error at +1 {{failed to legalize operation 'spv.func' that was explicitly marked illegal}}
+spv.func @struct_with_offset2(%arg: !spv.struct<i32[0], i32[8]>) -> () "None" {
+ spv.Return
+}
+
+// -----
+
+// expected-error at +1 {{failed to legalize operation 'spv.func' that was explicitly marked illegal}}
+spv.func @struct_with_decorations(%arg: !spv.struct<f32 [RelaxedPrecision]>) -> () "None" {
+ spv.Return
+}
diff --git a/mlir/test/Conversion/SPIRVToLLVM/spirv-types-to-llvm.mlir b/mlir/test/Conversion/SPIRVToLLVM/spirv-types-to-llvm.mlir
index d2bfdcd4c33d..466f8ad4a9ea 100644
--- a/mlir/test/Conversion/SPIRVToLLVM/spirv-types-to-llvm.mlir
+++ b/mlir/test/Conversion/SPIRVToLLVM/spirv-types-to-llvm.mlir
@@ -26,3 +26,13 @@ func @runtime_array_vector(!spv.rtarray< vector<4xf32> >) -> ()
// CHECK-LABEL: @runtime_array_scalar(!llvm<"[0 x float]">)
func @runtime_array_scalar(!spv.rtarray<f32>) -> ()
+
+//===----------------------------------------------------------------------===//
+// Struct type
+//===----------------------------------------------------------------------===//
+
+// CHECK-LABEL: @struct(!llvm<"<{ double }>">)
+func @struct(!spv.struct<f64>) -> ()
+
+// CHECK-LABEL: @struct_nested(!llvm<"<{ i32, <{ i64, i32 }> }>">)
+func @struct_nested(!spv.struct<i32, !spv.struct<i64, i32>>)
More information about the Mlir-commits
mailing list