Skip to content

Commit 5258552

Browse files
committed
Updated CGOpenCLRuntime.cpp
Implemented sampled_image_cuda.cl
1 parent d4e7929 commit 5258552

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

clang/lib/CodeGen/CGOpenCLRuntime.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,28 @@ llvm::Type *CGOpenCLRuntime::convertOpenCLSpecificType(const Type *T) {
3737
llvm::LLVMContext& Ctx = CGM.getLLVMContext();
3838
uint32_t AddrSpc = CGM.getContext().getTargetAddressSpace(
3939
CGM.getContext().getOpenCLTypeAddrSpace(T));
40+
41+
if (CGM.getTriple().isNVPTX()) {
42+
switch (cast<BuiltinType>(T)->getKind()) {
43+
default:
44+
break;
45+
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
46+
case BuiltinType::Id: \
47+
return llvm::IntegerType::getInt64Ty(CGM.getLLVMContext());
48+
#include "clang/Basic/OpenCLImageTypes.def"
49+
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
50+
case BuiltinType::Sampled##Id: \
51+
return llvm::StructType::get( \
52+
llvm::IntegerType::getInt64Ty(CGM.getLLVMContext()), \
53+
llvm::IntegerType::getInt32Ty(CGM.getLLVMContext()));
54+
#define IMAGE_WRITE_TYPE(Type, Id, Ext)
55+
#define IMAGE_READ_WRITE_TYPE(Type, Id, Ext)
56+
#include "clang/Basic/OpenCLImageTypes.def"
57+
case BuiltinType::OCLSampler:
58+
return llvm::IntegerType::getInt32Ty(CGM.getLLVMContext());
59+
}
60+
}
61+
4062
switch (cast<BuiltinType>(T)->getKind()) {
4163
default:
4264
llvm_unreachable("Unexpected opencl builtin type!");
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %clang_cc1 %s -triple nvptx64-nvidia-cuda -O0 -emit-llvm -o - | FileCheck %s
2+
3+
__attribute__((overloadable)) void my_read_image(__ocl_sampled_image1d_ro_t img_ro);
4+
5+
__attribute__((overloadable)) __ocl_sampled_image1d_ro_t __spirv_SampledImage(read_only image1d_t img_wo, sampler_t sampl);
6+
7+
void test_read_image(__ocl_sampled_image1d_ro_t img_ro, read_only image1d_t img_wo, sampler_t sampl) {
8+
9+
// CHECK: call void @_Z13my_read_image32__spirv_SampledImage__image1d_ro(i64 %{{[a-zA-Z0-9]+}}, i32 %{{[a-zA-Z0-9]+}})
10+
my_read_image(img_ro);
11+
// CHECK: call { i64, i32 } @_Z20__spirv_SampledImage14ocl_image1d_ro11ocl_sampler(i64 %{{[a-zA-Z0-9]+}}, i32 %{{[a-zA-Z0-9]+}})
12+
__ocl_sampled_image1d_ro_t s_imag = __spirv_SampledImage(img_wo, sampl);
13+
// CHECK: call void @_Z13my_read_image32__spirv_SampledImage__image1d_ro(i64 %{{[a-zA-Z0-9]+}}, i32 %{{[a-zA-Z0-9]+}})
14+
my_read_image(s_imag);
15+
}

0 commit comments

Comments
 (0)