Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1945,8 +1945,18 @@ mlir::Value ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
return emitComplexToScalarConversion(CGF.getLoc(CE->getExprLoc()), V, Kind,
DestTy);
}
case CK_ZeroToOCLOpaqueType:
llvm_unreachable("NYI");
case CK_ZeroToOCLOpaqueType: {
// OpenCL: event_t e = async_work_group_copy(..., 0);
// The source is an integer constant zero; the destination is an OpenCL
// opaque type
mlir::Type destTy = CGF.convertType(DestTy);
auto PtrTy =
cir::PointerType::get(destTy, cir::AddressSpace::OffloadPrivate);
auto constNullPtrAttr = Builder.getConstNullPtrAttr(PtrTy);
auto nullVal =
Builder.getConstant(CGF.getLoc(E->getExprLoc()), constNullPtrAttr);
return nullVal;
}
case CK_IntToOCLSampler:
llvm_unreachable("NYI");

Expand Down
7 changes: 6 additions & 1 deletion clang/lib/CIR/CodeGen/CIRGenTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,13 @@ mlir::Type CIRGenTypes::convertType(QualType T) {
case BuiltinType::OCLEvent:
case BuiltinType::OCLClkEvent:
case BuiltinType::OCLQueue:
ResultType = Builder.getVoidPtrTy();
break;
case BuiltinType::OCLReserveID:
assert(0 && "not implemented");
ResultType = cir::RecordType::get(
&getMLIRContext(), {},
mlir::StringAttr::get(&getMLIRContext(), "ocl_reserve_id"), false,
false, cir::RecordType::Struct);
break;
case BuiltinType::SveInt8:
case BuiltinType::SveUint8:
Expand Down
25 changes: 25 additions & 0 deletions clang/test/CIR/CodeGen/OpenCL/async_copy.cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// RUN: %clang -cc1 -triple spirv64-unknown-unknown -cl-std=CL2.0 -finclude-default-header -emit-cir -o - %s -fclangir | FileCheck %s --check-prefix=CIR
// RUN: %clang -cc1 -triple spirv64-unknown-unknown -cl-std=CL2.0 -finclude-default-header -emit-llvm -o - %s -fclangir | FileCheck %s --check-prefix=LLVM
// RUN: %clang -cc1 -triple spirv64-unknown-unknown -cl-std=CL2.0 -finclude-default-header -emit-llvm -o - %s | FileCheck %s --check-prefix=OG-LLVM

// Simple kernel using async_work_group_copy + wait_group_events

__kernel void test_async_copy(__global int *g_in, __local int *l_in, int size) {
// int gid = get_global_id(0);

// Trigger async copy: global to local
// event_t e_in =
async_work_group_copy(
l_in, // local destination
g_in,// + gid * size, // global source
size, // number of elements
(event_t)0 // no dependency
);

// Wait for the async operation to complete
// wait_group_events(1, &e_in);
}

// CIR: cir.call @_Z21async_work_group_copyPU3AS3iPU3AS1Kim9ocl_event(%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}) : (!cir.ptr<!s32i, addrspace(offload_local)>, !cir.ptr<!s32i, addrspace(offload_global)>, !u64i, !cir.ptr<!void>) -> !cir.ptr<!void>
// LLVM: call spir_func ptr @_Z21async_work_group_copyPU3AS3iPU3AS1Kim9ocl_event(ptr addrspace(3) %{{.*}}, ptr addrspace(1) %{{.*}}, i64 %{{.*}}, ptr null)
// OG-LLVM: call spir_func target("spirv.Event") @_Z21async_work_group_copyPU3AS3iPU3AS1Kim9ocl_event(ptr addrspace(3) noundef %{{.*}}, ptr addrspace(1) noundef %{{.*}}, i64 noundef %{{.*}}, target("spirv.Event") zeroinitializer
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a difference between ours and the original LLVM (target("spirv.Event") vs ptr addrspace(0)). Is this expected? (I believe the assertion about address space cast you encountered is also a little alarm for us.)

Simply using ptr addrspace(0) here usually works. But the original RFC of LLVM opaque types mentions that it's actually undefined behavior in LLVM IR.

Loading