Skip to content

Commit c25495c

Browse files
whitneywhtsangetiotto
authored andcommitted
Add type converter for sycl::ArrayType (#46)
The runtime class of `sycl::ArrayType`: ``` template <int dimensions = 1> class array { … size_t common_array[dimensions]; … } ``` Signed-off-by: Tsang, Whitney <whitney.tsang@intel.com>
1 parent 178e944 commit c25495c

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

mlir-sycl/lib/Conversion/SYCLToLLVM/SYCLToLLVM.cpp

+15-2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,20 @@ static Optional<Type> getArrayTy(MLIRContext &context, unsigned dimNum,
5050
// Type conversion
5151
//===----------------------------------------------------------------------===//
5252

53+
/// Converts SYCL array type to LLVM type.
54+
static Optional<Type> convertArrayType(sycl::ArrayType type,
55+
LLVMTypeConverter &converter) {
56+
assert(type.getBody().size() == 1 &&
57+
"Expecting SYCL array body to have size 1");
58+
assert(type.getBody()[0].isa<MemRefType>() &&
59+
"Expecting SYCL array body entry to be MemRefType");
60+
assert(type.getBody()[0].cast<MemRefType>().getElementType() ==
61+
converter.getIndexType() &&
62+
"Expecting SYCL array body entry element type to be the index type");
63+
return getArrayTy(converter.getContext(), type.getDimension(),
64+
converter.getIndexType());
65+
}
66+
5367
/// Converts SYCL range or id type to LLVM type, given \p dimNum - number of
5468
/// dimensions, \p name - the expected LLVM type name, \p converter - LLVM type
5569
/// converter.
@@ -127,8 +141,7 @@ void mlir::sycl::populateSYCLToLLVMTypeConversion(
127141
return convertAccessorType(type, typeConverter);
128142
});
129143
typeConverter.addConversion([&](sycl::ArrayType type) {
130-
llvm_unreachable("SYCLToLLVM - sycl::ArrayType not handle (yet)");
131-
return llvm::None;
144+
return convertArrayType(type, typeConverter);
132145
});
133146
typeConverter.addConversion([&](sycl::GroupType type) {
134147
llvm_unreachable("SYCLToLLVM - sycl::GroupType not handle (yet)");

polygeist/tools/cgeist/Test/Verification/sycl/SYCLToLLVM/types.mlir

+8
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
// CHECK-DAG: [[ACCESSORIMPLDEVICE_2:%"class.cl::sycl::detail::AccessorImplDevice.*]] = type { [[ID_2]], [[RANGE_2]], [[RANGE_2]] }
2121
// CHECK-DAG: [[ACCESSOR_1:%"class.cl::sycl::accessor.*]] = type { [[ACCESSORIMPLDEVICE_1]], { i32 addrspace(1)* } }
2222
// CHECK-DAG: [[ACCESSOR_2:%"class.cl::sycl::accessor.*]] = type { [[ACCESSORIMPLDEVICE_2]], { i64 addrspace(1)* } }
23+
// CHECK: define void @test_array.1([[ARRAY_1]] %0)
24+
// CHECK: define void @test_array.2([[ARRAY_2]] %0)
2325
// CHECK: define void @test_id([[ID_1]] %0, [[ID_1]] %1)
2426
// CHECK: define void @test_range.1([[RANGE_1]] %0)
2527
// CHECK: define void @test_range.2([[RANGE_2]] %0)
@@ -28,6 +30,12 @@
2830
// CEHCK: define void @test_accessor.2([[ACCESSOR_2]] %0)
2931

3032
module {
33+
func.func @test_array.1(%arg0: !sycl.array<[1], (memref<1xi64>)>) {
34+
return
35+
}
36+
func.func @test_array.2(%arg0: !sycl.array<[2], (memref<2xi64>)>) {
37+
return
38+
}
3139
func.func @test_id(%arg0: !sycl.id<1>, %arg1: !sycl.id<1>) {
3240
return
3341
}

0 commit comments

Comments
 (0)