Skip to content

[SYCL] Add special type parameter support for free function kernels #17789

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
b83903a
Do not use entire sycl/sycl.hpp in small tests
lbushi25 Feb 14, 2025
8f10be9
Merge branch 'sycl' of https://github.com/lbushi25/llvm into sycl
lbushi25 Feb 26, 2025
a91ba9d
Merge branch 'sycl' of https://github.com/lbushi25/llvm into sycl
lbushi25 Mar 11, 2025
ff1c3b4
Remove enable_if in get_kernel_id for free function kernel
lbushi25 Mar 11, 2025
9c3cae8
Add special type parameter support for free function kernels
lbushi25 Mar 27, 2025
e44de79
Merge branch 'sycl' of https://github.com/lbushi25/llvm into sycl
lbushi25 Mar 27, 2025
8cff614
Add special type support for free function kernel
lbushi25 Mar 31, 2025
b4f18e1
Fix merge conflict in handler.cpp
lbushi25 Mar 31, 2025
b23734f
Add tests for free function kernel special type arguments
lbushi25 Apr 1, 2025
d78b932
Improve tests for special type parameters for free function kernels
lbushi25 Apr 1, 2025
435402b
Formatting and remove warnings
lbushi25 Apr 3, 2025
ee9e906
Formatting and remove warnings
lbushi25 Apr 3, 2025
18adbbc
More formatting
lbushi25 Apr 3, 2025
917695a
More formatting
lbushi25 Apr 3, 2025
50c881d
Add default constructor for local_accessor in CodeGenSYCL
lbushi25 Apr 3, 2025
e93a408
Add runtime test for changes and apply suggestions
lbushi25 Apr 9, 2025
9c3d471
Merge branch 'sycl' into special_type_argument_free_function_kernel
lbushi25 Apr 9, 2025
7dcef46
Improve tests and apply more suggestions
lbushi25 Apr 9, 2025
553219a
Merge branch 'special_type_argument_free_function_kernel' of https://…
lbushi25 Apr 9, 2025
b1c3d48
Resolve merge conflict
lbushi25 Apr 9, 2025
a68f354
Formatting changes
lbushi25 Apr 9, 2025
ba2a3c1
Improve comments
lbushi25 Apr 9, 2025
c7b468b
Resolve precommit failures
lbushi25 Apr 9, 2025
c576d45
Fix merge conflicts and formatting
lbushi25 Apr 10, 2025
026a84c
Fix pre-commit failures
lbushi25 Apr 10, 2025
63befeb
Formatting
lbushi25 Apr 10, 2025
7825a52
Update debug-info-srcpos-kernel.cpp
lbushi25 Apr 10, 2025
1cc2d7a
Minor refactoring
lbushi25 Apr 10, 2025
2300351
Merge branch 'special_type_argument_free_function_kernel' of https://…
lbushi25 Apr 10, 2025
ba0b7b0
Fix pre-commit failures
lbushi25 Apr 10, 2025
43e5a6a
Add XFAIL for test
lbushi25 Apr 10, 2025
7c61469
Update SemaSYCL.cpp
lbushi25 Apr 10, 2025
f0f8bc8
Update SemaSYCL.cpp
lbushi25 Apr 10, 2025
051e472
Update SemaSYCL.cpp
lbushi25 Apr 10, 2025
a729737
Update free_function_kernel_params.cpp
lbushi25 Apr 11, 2025
0caa0e5
Fix formatting
lbushi25 Apr 11, 2025
787239a
Provide accessor support
lbushi25 Apr 11, 2025
139e1d7
Merge branch 'special_type_argument_free_function_kernel' of https://…
lbushi25 Apr 11, 2025
87afab0
Add a new printing policy flag to control enumerators name printing
lbushi25 Apr 11, 2025
613085b
Improve accessor support
lbushi25 Apr 11, 2025
8ca6758
Update PrettyPrinter.h
lbushi25 Apr 11, 2025
ddcf366
Formatting changes
lbushi25 Apr 11, 2025
2ae1b3f
Merge branch 'special_type_argument_free_function_kernel' of https://…
lbushi25 Apr 11, 2025
2d4bb14
Fix pre-commit failures
lbushi25 Apr 11, 2025
a695ca0
Formatting
lbushi25 Apr 11, 2025
15a82df
Update SemaSYCL.cpp
lbushi25 Apr 11, 2025
68ad97d
Change definition of target enum
lbushi25 Apr 14, 2025
4b50452
Merge branch 'special_type_argument_free_function_kernel' of https://…
lbushi25 Apr 14, 2025
538cd68
Resolve pre-commit failures
lbushi25 Apr 15, 2025
c793280
Resolve pre-commit failures
lbushi25 Apr 15, 2025
a9350fb
Resolve pre-commit failures
lbushi25 Apr 15, 2025
ecd9443
Resolve pre-commit failures
lbushi25 Apr 15, 2025
f9baae7
Resolve pre-commit failures
lbushi25 Apr 15, 2025
198fafe
Merge branch 'sycl' into special_type_argument_free_function_kernel
lbushi25 May 12, 2025
4ddbd5f
Fix pre-commit failures
lbushi25 May 12, 2025
29c48af
Update clang/lib/AST/TemplateBase.cpp
lbushi25 May 13, 2025
bb682d0
Fix pre-commit failures
lbushi25 May 13, 2025
b01bbda
Fix pre-commit failures
lbushi25 May 13, 2025
d6632ff
Merge branch 'special_type_argument_free_function_kernel' of https://…
lbushi25 May 13, 2025
aef7353
Update debug-info-srcpos-kernel.cpp
lbushi25 May 13, 2025
b47ea3d
Add check that wrapped accessor is not allowed
lbushi25 May 13, 2025
de227ec
Merge branch 'special_type_argument_free_function_kernel' of https://…
lbushi25 May 13, 2025
987c6e3
Update TemplateBase.cpp
lbushi25 May 13, 2025
d1d1777
Add check that wrapped accessor is not allowed
lbushi25 May 13, 2025
1f42732
Merge branch 'special_type_argument_free_function_kernel' of https://…
lbushi25 May 13, 2025
08cea6d
Update debug-info-srcpos-kernel.cpp
lbushi25 May 13, 2025
b9f49d8
Update free_function_errors.cpp
lbushi25 May 13, 2025
c51e897
Update free_function_errors.cpp
lbushi25 May 14, 2025
2b71a25
Merge branch 'intel:sycl' into special_type_argument_free_function_ke…
lbushi25 May 14, 2025
eacf30d
Update SemaSYCL.cpp
lbushi25 May 14, 2025
6e5a42f
Update SemaSYCL.cpp
lbushi25 May 14, 2025
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
9 changes: 8 additions & 1 deletion clang/include/clang/AST/PrettyPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ struct PrintingPolicy {
PrintInjectedClassNameWithArguments(true), UsePreferredNames(true),
AlwaysIncludeTypeForTemplateArgument(false),
CleanUglifiedParameters(false), EntireContentsOfLargeArray(true),
UseEnumerators(true), UseHLSLTypes(LO.HLSL) {}
UseEnumerators(true), UseFullyQualifiedEnumerators(false),
UseHLSLTypes(LO.HLSL) {}

/// Adjust this printing policy for cases where it's known that we're
/// printing C++ code (for instance, if AST dumping reaches a C++-only
Expand Down Expand Up @@ -419,6 +420,12 @@ struct PrintingPolicy {
LLVM_PREFERRED_TYPE(bool)
unsigned UseEnumerators : 1;

/// Whether to print the names of enumerator non-type template parameters
/// with all the namespace scope qualifiers regardless of the way the user
/// wrote them in the source code. No effect if UseEnumerators is not set.
LLVM_PREFERRED_TYPE(bool)
unsigned UseFullyQualifiedEnumerators : 1;

/// Whether or not we're printing known HLSL code and should print HLSL
/// sugared types when possible.
LLVM_PREFERRED_TYPE(bool)
Expand Down
5 changes: 4 additions & 1 deletion clang/lib/AST/TemplateBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ static void printIntegral(const TemplateArgument &TemplArg, raw_ostream &Out,
// may create a size difference between the enum value and template
// argument value, requiring isSameValue here instead of operator==.
if (llvm::APSInt::isSameValue(ECD->getInitVal(), Val)) {
ECD->printQualifiedName(Out, Policy);
PrintingPolicy NewPolicy = Policy;
if (Policy.UseFullyQualifiedEnumerators)
NewPolicy.PrintCanonicalTypes = true;
ECD->printQualifiedName(Out, NewPolicy);
return;
}
}
Expand Down
194 changes: 104 additions & 90 deletions clang/lib/Sema/SemaSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1080,8 +1080,7 @@ static ParamDesc makeParamDesc(ASTContext &Ctx, StringRef Name, QualType Ty) {
}

static void unsupportedFreeFunctionParamType() {
llvm::report_fatal_error("Only scalars and pointers are permitted as "
"free function parameters");
llvm::report_fatal_error("Unsupported free kernel parameter type!");
}

class MarkWIScopeFnVisitor : public RecursiveASTVisitor<MarkWIScopeFnVisitor> {
Expand Down Expand Up @@ -2080,13 +2079,7 @@ class SyclKernelFieldChecker : public SyclKernelFieldHandler {
}

bool handleSyclSpecialType(ParmVarDecl *PD, QualType ParamTy) final {
if (!SemaSYCL::isSyclType(ParamTy, SYCLTypeAttr::work_group_memory) &&
!SemaSYCL::isSyclType(ParamTy,
SYCLTypeAttr::dynamic_work_group_memory)) {
Diag.Report(PD->getLocation(), diag::err_bad_kernel_param_type)
<< ParamTy;
IsInvalid = true;
}
IsInvalid |= checkSyclSpecialType(ParamTy, PD->getLocation());
return isValid();
}

Expand Down Expand Up @@ -2238,10 +2231,7 @@ class SyclKernelUnionChecker : public SyclKernelFieldHandler {
}

bool handleSyclSpecialType(ParmVarDecl *PD, QualType ParamTy) final {
if (!SemaSYCL::isSyclType(ParamTy, SYCLTypeAttr::work_group_memory) &&
!SemaSYCL::isSyclType(ParamTy, SYCLTypeAttr::dynamic_work_group_memory))
unsupportedFreeFunctionParamType(); // TODO
return true;
return checkType(PD->getLocation(), ParamTy);
}

bool handleSyclSpecialType(const CXXRecordDecl *, const CXXBaseSpecifier &BS,
Expand Down Expand Up @@ -2830,23 +2820,34 @@ class SyclKernelDeclCreator : public SyclKernelFieldHandler {
// kernel parameters from __init method parameters. We will use __init method
// and kernel parameters which we build here to initialize special objects in
// the kernel body.
bool handleSpecialType(FieldDecl *FD, QualType FieldTy) {
const auto *RecordDecl = FieldTy->getAsCXXRecordDecl();
assert(RecordDecl && "The type must be a RecordDecl");
// ParentDecl parameterizes whether we are in a free function kernel or a
// lambda kernel by taking the value ParmVarDecl or FieldDecl respectively.
template <typename ParentDecl>
bool handleSpecialType(ParentDecl *decl, QualType Ty) {
const auto *RD = Ty->getAsCXXRecordDecl();
assert(RD && "The type must be a RecordDecl");
llvm::StringLiteral MethodName =
KernelDecl->hasAttr<SYCLSimdAttr>() && isSyclAccessorType(FieldTy)
KernelDecl->hasAttr<SYCLSimdAttr>() && isSyclAccessorType(Ty)
? InitESIMDMethodName
: InitMethodName;
CXXMethodDecl *InitMethod = getMethodByName(RecordDecl, MethodName);
CXXMethodDecl *InitMethod = getMethodByName(RD, MethodName);
assert(InitMethod && "The type must have the __init method");

// Don't do -1 here because we count on this to be the first parameter added
// (if any).
size_t ParamIndex = Params.size();
for (const ParmVarDecl *Param : InitMethod->parameters()) {
QualType ParamTy = Param->getType();
addParam(FD, ParamTy.getCanonicalType());

// For lambda kernels the arguments to the OpenCL kernel are named
// based on the position they have as fields in the definition of the
// special type structure i.e __arg_field1, __arg_field2 and so on.
// For free function kernels the arguments are named in direct mapping
// with the names they have in the __init method i.e __arg_Ptr for work
// group memory since its init function takes a parameter with Ptr name.
if constexpr (std::is_same_v<ParentDecl, FieldDecl>)
addParam(decl, ParamTy.getCanonicalType());
else
addParam(Param, ParamTy.getCanonicalType());
// Propagate add_ir_attributes_kernel_parameter attribute.
if (const auto *AddIRAttr =
Param->getAttr<SYCLAddIRAttributesKernelParameterAttr>())
Expand All @@ -2858,8 +2859,8 @@ class SyclKernelDeclCreator : public SyclKernelFieldHandler {
// handleAccessorPropertyList. If new classes with property list are
// added, this code needs to be refactored to call
// handleAccessorPropertyList for each class which requires it.
if (ParamTy.getTypePtr()->isPointerType() && isSyclAccessorType(FieldTy))
handleAccessorType(FieldTy, RecordDecl, FD->getBeginLoc());
if (ParamTy.getTypePtr()->isPointerType() && isSyclAccessorType(Ty))
handleAccessorType(Ty, RD, decl->getBeginLoc());
}
LastParamIndex = ParamIndex;
return true;
Expand Down Expand Up @@ -3026,28 +3027,7 @@ class SyclKernelDeclCreator : public SyclKernelFieldHandler {
}

bool handleSyclSpecialType(ParmVarDecl *PD, QualType ParamTy) final {
if (SemaSYCL::isSyclType(ParamTy, SYCLTypeAttr::work_group_memory) ||
SemaSYCL::isSyclType(ParamTy,
SYCLTypeAttr::dynamic_work_group_memory)) {
const auto *RecordDecl = ParamTy->getAsCXXRecordDecl();
assert(RecordDecl && "The type must be a RecordDecl");
CXXMethodDecl *InitMethod = getMethodByName(RecordDecl, InitMethodName);
assert(InitMethod && "The type must have the __init method");
// Don't do -1 here because we count on this to be the first parameter
// added (if any).
size_t ParamIndex = Params.size();
for (const ParmVarDecl *Param : InitMethod->parameters()) {
QualType ParamTy = Param->getType();
addParam(Param, ParamTy.getCanonicalType());
// Propagate add_ir_attributes_kernel_parameter attribute.
if (const auto *AddIRAttr =
Param->getAttr<SYCLAddIRAttributesKernelParameterAttr>())
Params.back()->addAttr(AddIRAttr->clone(SemaSYCLRef.getASTContext()));
}
LastParamIndex = ParamIndex;
} else // TODO
unsupportedFreeFunctionParamType();
return true;
return handleSpecialType(PD, ParamTy);
}

RecordDecl *wrapField(FieldDecl *Field, QualType FieldTy) {
Expand Down Expand Up @@ -4540,47 +4520,48 @@ class FreeFunctionKernelBodyCreator : public SyclKernelFieldHandler {
// TODO: Revisit this approach once https://github.com/intel/llvm/issues/16061
// is closed.
bool handleSyclSpecialType(ParmVarDecl *PD, QualType ParamTy) final {
if (SemaSYCL::isSyclType(ParamTy, SYCLTypeAttr::work_group_memory) ||
SemaSYCL::isSyclType(ParamTy,
SYCLTypeAttr::dynamic_work_group_memory)) {
const auto *RecordDecl = ParamTy->getAsCXXRecordDecl();
AccessSpecifier DefaultConstructorAccess;
auto DefaultConstructor =
std::find_if(RecordDecl->ctor_begin(), RecordDecl->ctor_end(),
[](auto it) { return it->isDefaultConstructor(); });
DefaultConstructorAccess = DefaultConstructor->getAccess();
DefaultConstructor->setAccess(AS_public);

QualType Ty = PD->getOriginalType();
ASTContext &Ctx = SemaSYCLRef.SemaRef.getASTContext();
VarDecl *WorkGroupMemoryClone = VarDecl::Create(
Ctx, DeclCreator.getKernelDecl(), FreeFunctionSrcLoc,
FreeFunctionSrcLoc, PD->getIdentifier(), PD->getType(),
Ctx.getTrivialTypeSourceInfo(Ty), SC_None);
InitializedEntity VarEntity =
InitializedEntity::InitializeVariable(WorkGroupMemoryClone);
InitializationKind InitKind =
InitializationKind::CreateDefault(FreeFunctionSrcLoc);
InitializationSequence InitSeq(SemaSYCLRef.SemaRef, VarEntity, InitKind,
std::nullopt);
ExprResult Init = InitSeq.Perform(SemaSYCLRef.SemaRef, VarEntity,
InitKind, std::nullopt);
WorkGroupMemoryClone->setInit(
SemaSYCLRef.SemaRef.MaybeCreateExprWithCleanups(Init.get()));
WorkGroupMemoryClone->setInitStyle(VarDecl::CallInit);
DefaultConstructor->setAccess(DefaultConstructorAccess);

Stmt *DS = new (SemaSYCLRef.getASTContext())
DeclStmt(DeclGroupRef(WorkGroupMemoryClone), FreeFunctionSrcLoc,
FreeFunctionSrcLoc);
BodyStmts.push_back(DS);
Expr *MemberBaseExpr = SemaSYCLRef.SemaRef.BuildDeclRefExpr(
WorkGroupMemoryClone, Ty, VK_PRValue, FreeFunctionSrcLoc);
createSpecialMethodCall(RecordDecl, InitMethodName, MemberBaseExpr,
BodyStmts);
ArgExprs.push_back(MemberBaseExpr);
} else // TODO
unsupportedFreeFunctionParamType();
// The code produced looks like this in the case of a work group memory
// parameter:
// void auto_generated_kernel(__local int * arg) {
// work_group_memory wgm;
// wgm.__init(arg);
// user_kernel(some arguments..., wgm, some arguments...);
// }
const auto *RecordDecl = ParamTy->getAsCXXRecordDecl();
AccessSpecifier DefaultConstructorAccess;
auto DefaultConstructor =
std::find_if(RecordDecl->ctor_begin(), RecordDecl->ctor_end(),
[](auto it) { return it->isDefaultConstructor(); });
DefaultConstructorAccess = DefaultConstructor->getAccess();
DefaultConstructor->setAccess(AS_public);

ASTContext &Ctx = SemaSYCLRef.SemaRef.getASTContext();
VarDecl *SpecialObjectClone =
VarDecl::Create(Ctx, DeclCreator.getKernelDecl(), FreeFunctionSrcLoc,
FreeFunctionSrcLoc, PD->getIdentifier(), ParamTy,
Ctx.getTrivialTypeSourceInfo(ParamTy), SC_None);
InitializedEntity VarEntity =
InitializedEntity::InitializeVariable(SpecialObjectClone);
InitializationKind InitKind =
InitializationKind::CreateDefault(FreeFunctionSrcLoc);
InitializationSequence InitSeq(SemaSYCLRef.SemaRef, VarEntity, InitKind,
std::nullopt);
ExprResult Init =
InitSeq.Perform(SemaSYCLRef.SemaRef, VarEntity, InitKind, std::nullopt);
SpecialObjectClone->setInit(
SemaSYCLRef.SemaRef.MaybeCreateExprWithCleanups(Init.get()));
SpecialObjectClone->setInitStyle(VarDecl::CallInit);
DefaultConstructor->setAccess(DefaultConstructorAccess);

Stmt *DS = new (SemaSYCLRef.getASTContext())
DeclStmt(DeclGroupRef(SpecialObjectClone), FreeFunctionSrcLoc,
FreeFunctionSrcLoc);
BodyStmts.push_back(DS);
Expr *MemberBaseExpr = SemaSYCLRef.SemaRef.BuildDeclRefExpr(
SpecialObjectClone, ParamTy, VK_PRValue, FreeFunctionSrcLoc);
createSpecialMethodCall(RecordDecl, InitMethodName, MemberBaseExpr,
BodyStmts);
ArgExprs.push_back(MemberBaseExpr);
return true;
}

Expand Down Expand Up @@ -4874,14 +4855,45 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler {
}

bool handleSyclSpecialType(ParmVarDecl *PD, QualType ParamTy) final {
if (SemaSYCL::isSyclType(ParamTy, SYCLTypeAttr::work_group_memory))
const auto *ClassTy = ParamTy->getAsCXXRecordDecl();
assert(ClassTy && "Type must be a C++ record type");
if (isSyclAccessorType(ParamTy)) {
const auto *AccTy =
cast<ClassTemplateSpecializationDecl>(ParamTy->getAsRecordDecl());
assert(AccTy->getTemplateArgs().size() >= 2 &&
"Incorrect template args for Accessor Type");
int Dims = static_cast<int>(
AccTy->getTemplateArgs()[1].getAsIntegral().getExtValue());
int Info = getAccessTarget(ParamTy, AccTy) | (Dims << 11);
Header.addParamDesc(SYCLIntegrationHeader::kind_accessor, Info,
CurOffset);
} else if (SemaSYCL::isSyclType(ParamTy, SYCLTypeAttr::stream)) {
addParam(PD, ParamTy, SYCLIntegrationHeader::kind_stream);
} else if (SemaSYCL::isSyclType(ParamTy, SYCLTypeAttr::work_group_memory)) {
addParam(PD, ParamTy, SYCLIntegrationHeader::kind_work_group_memory);
else if (SemaSYCL::isSyclType(ParamTy,
SYCLTypeAttr::dynamic_work_group_memory))
} else if (SemaSYCL::isSyclType(ParamTy, SYCLTypeAttr::sampler) ||
SemaSYCL::isSyclType(ParamTy, SYCLTypeAttr::annotated_ptr) ||
SemaSYCL::isSyclType(ParamTy, SYCLTypeAttr::annotated_arg)) {
CXXMethodDecl *InitMethod = getMethodByName(ClassTy, InitMethodName);
assert(InitMethod && "type must have __init method");
const ParmVarDecl *InitArg = InitMethod->getParamDecl(0);
assert(InitArg && "Init method must have arguments");
QualType T = InitArg->getType();
SYCLIntegrationHeader::kernel_param_kind_t ParamKind =
SemaSYCL::isSyclType(ParamTy, SYCLTypeAttr::sampler)
? SYCLIntegrationHeader::kind_sampler
: (T->isPointerType() ? SYCLIntegrationHeader::kind_pointer
: SYCLIntegrationHeader::kind_std_layout);
addParam(PD, ParamTy, ParamKind);
} else if (SemaSYCL::isSyclType(ParamTy,
SYCLTypeAttr::dynamic_work_group_memory))
addParam(PD, ParamTy,
SYCLIntegrationHeader::kind_dynamic_work_group_memory);
else
unsupportedFreeFunctionParamType(); // TODO

else {
llvm_unreachable(
"Unexpected SYCL special class when generating integration header");
}
return true;
}

Expand Down Expand Up @@ -6666,6 +6678,7 @@ void SYCLIntegrationHeader::emit(raw_ostream &O) {
O << "#include <sycl/detail/defines_elementary.hpp>\n";
O << "#include <sycl/detail/kernel_desc.hpp>\n";
O << "#include <sycl/ext/oneapi/experimental/free_function_traits.hpp>\n";
O << "#include <sycl/access/access.hpp>\n";
O << "\n";

LangOptions LO;
Expand Down Expand Up @@ -6977,6 +6990,7 @@ void SYCLIntegrationHeader::emit(raw_ostream &O) {
Policy.PolishForDeclaration = true;
Policy.FullyQualifiedName = true;
Policy.EnforceScopeForElaboratedTypes = true;
Policy.UseFullyQualifiedEnumerators = true;

// Now we need to print the declaration of the kernel itself.
// Example:
Expand Down
21 changes: 17 additions & 4 deletions clang/test/CodeGenSYCL/Inputs/sycl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class __attribute__((sycl_special_class)) __SYCL_TYPE(sampler) sampler {

public:
void use(void) const {}
#ifdef __SYCL_DEVICE_ONLY__
sampler() = default;
#endif
};

template <int dimensions = 1>
Expand Down Expand Up @@ -327,6 +330,9 @@ template <typename dataT, int dimensions, access::mode accessmode,
class __attribute__((sycl_special_class)) __SYCL_TYPE(accessor) accessor {

public:
#ifdef __SYCL_DEVICE_ONLY__
accessor() = default;
#endif
void use(void) const {}
template <typename... T>
void use(T... args) {}
Expand Down Expand Up @@ -420,6 +426,9 @@ local_accessor: public accessor<dataT,
dimensions, access::mode::read_write,
access::target::local> {
public:
#ifdef __SYCL_DEVICE_ONLY__
local_accessor() = default;
#endif
void use(void) const {}
template <typename... T>
void use(T... args) {}
Expand Down Expand Up @@ -487,17 +496,21 @@ int printf(const __SYCL_CONSTANT_AS char *__format, Args... args) {
template <typename T, typename... Props>
class __attribute__((sycl_special_class)) __SYCL_TYPE(annotated_arg) annotated_arg {
T obj;
#ifdef __SYCL_DEVICE_ONLY__
#ifdef __SYCL_DEVICE_ONLY__
void __init(T _obj) {}
#endif
public:
annotated_arg() = default;
#endif
};

template <typename T, typename... Props>
class __attribute__((sycl_special_class)) __SYCL_TYPE(annotated_ptr) annotated_ptr {
T* obj;
#ifdef __SYCL_DEVICE_ONLY__
#ifdef __SYCL_DEVICE_ONLY__
void __init(T* _obj) {}
#endif
public:
annotated_ptr() = default;
#endif
};

} // namespace experimental
Expand Down
5 changes: 3 additions & 2 deletions clang/test/CodeGenSYCL/debug-info-srcpos-kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ int main() {
// CHECK: call spir_func void {{.*}}6__init{{.*}} !dbg [[LINE_A0]]
// CHECK: call spir_func void @_ZZ4mainENKUlvE_clEv{{.*}} !dbg [[LINE_B0:![0-9]+]]
// CHECK: ret void, !dbg [[LINE_C0:![0-9]+]]
// CHECK: !DIFile(filename: "{{.*}}debug-info-srcpos-kernel.cpp"{{.*}})
Copy link
Contributor

Choose a reason for hiding this comment

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

Is that change in this test due to a default constructor of the sampler?
I don't know debug info well enough, but I see that we did not check DIFile metadata two times before the patch. Now we do. @bwyma , @stevemerr , could you please confirm that this test still makes sense?

Copy link
Contributor

Choose a reason for hiding this comment

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

@bwyma , ... could you please confirm that this test still makes sense?

There is a bug where two DIFile entries are being emitted for the same file. It is a pre-existing issue.
The correct DIFile used to be emitted immediately following the "use_kernel_for_test" DISubprogram so it was easy to identify. I suspect something with this patch caused this DIFile to be emitted earlier in the printed IR and the only way to distinguish between the two DIFile entries in this test is to check for both.

Copy link
Contributor Author

@lbushi25 lbushi25 May 14, 2025

Choose a reason for hiding this comment

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

Thanks for the input @bwyma . Yeah, that's exactly what happened, the DIFile got reordered and now there are two before DISubprogram. I've identified the culprit as the default constructor I added to the sampler for some reason. Could you please confirm that this test change is ok by giving an approval?

// CHECK: [[FILE:![0-9]+]] = !DIFile(filename: "{{.*}}debug-info-srcpos-kernel.cpp"{{.*}})
// CHECK: [[KERNEL]] = {{.*}}!DISubprogram(name: "{{.*}}19use_kernel_for_test"
// CHECK-SAME: scope: [[FILE:![0-9]+]],
// CHECK-SAME: scope: [[FILE]],
// CHECK-SAME: file: [[FILE]],
// CHECK-SAME: flags: DIFlagArtificial | DIFlagPrototyped
// CHECK: [[FILE]] = !DIFile(filename: "{{.*}}debug-info-srcpos-kernel.cpp"{{.*}})
// CHECK: [[LINE_A0]] = !DILocation(line: 15,{{.*}}scope: [[KERNEL]]
// CHECK: [[LINE_B0]] = !DILocation(line: 16,{{.*}}scope: [[BLOCK:![0-9]+]]
// CHECK: [[BLOCK]] = distinct !DILexicalBlock(scope: [[KERNEL]]
Expand Down
Loading