Skip to content

Commit dc0ffd7

Browse files
author
Mahmood Yassin
committed
[CIR][OpenCL] Support lowering of OCL opaque types
Implement handling for zero-initialization casts to OpenCL opaque types in CIR. This covers cases like `event_t e = async_work_group_copy(..., 0)`. - `VisitCastExpr`: CK_ZeroToOCLOpaqueType now returns a null pointer of the appropriate opaque type instead of `llvm_unreachable`. - `CIRGenTypes::convertType`: Added proper CIR type conversions for OpenCL opaque types including event, queue, and reserve_id types. - Provides consistent CIR representation for OpenCL opaque objects.
1 parent e392b11 commit dc0ffd7

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1945,8 +1945,18 @@ mlir::Value ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
19451945
return emitComplexToScalarConversion(CGF.getLoc(CE->getExprLoc()), V, Kind,
19461946
DestTy);
19471947
}
1948-
case CK_ZeroToOCLOpaqueType:
1949-
llvm_unreachable("NYI");
1948+
case CK_ZeroToOCLOpaqueType: {
1949+
// OpenCL: event_t e = async_work_group_copy(..., 0);
1950+
// The source is an integer constant zero; the destination is an OpenCL
1951+
// opaque type
1952+
mlir::Type destTy = CGF.convertType(DestTy);
1953+
auto PtrTy =
1954+
cir::PointerType::get(destTy, cir::AddressSpace::OffloadPrivate);
1955+
auto constNullPtrAttr = Builder.getConstNullPtrAttr(PtrTy);
1956+
auto nullVal =
1957+
Builder.getConstant(CGF.getLoc(E->getExprLoc()), constNullPtrAttr);
1958+
return nullVal;
1959+
}
19501960
case CK_IntToOCLSampler:
19511961
llvm_unreachable("NYI");
19521962

clang/lib/CIR/CodeGen/CIRGenTypes.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,8 +516,13 @@ mlir::Type CIRGenTypes::convertType(QualType T) {
516516
case BuiltinType::OCLEvent:
517517
case BuiltinType::OCLClkEvent:
518518
case BuiltinType::OCLQueue:
519+
ResultType = Builder.getVoidPtrTy();
520+
break;
519521
case BuiltinType::OCLReserveID:
520-
assert(0 && "not implemented");
522+
ResultType = cir::RecordType::get(
523+
&getMLIRContext(), {},
524+
mlir::StringAttr::get(&getMLIRContext(), "ocl_reserve_id"), false,
525+
false, cir::RecordType::Struct);
521526
break;
522527
case BuiltinType::SveInt8:
523528
case BuiltinType::SveUint8:

0 commit comments

Comments
 (0)