Skip to content

Conversation

AlexeySachkov
Copy link
Contributor

constexpr variables are not forward-declarable so if one is used as a template parameter of a free function kernel argument, we cannot reference the variable, but must inline the value into the integration header.

…ions

`constexpr` variables are not forward-declarable so if one is used as a
template parameter of a free function kernel argument, we cannot
reference the variable, but must inline the value into the integration
header.
@AlexeySachkov AlexeySachkov requested a review from a team as a code owner September 24, 2025 13:58
[[__sycl_detail__::add_ir_attributes_function("sycl-nd-range-kernel", 2)]]
void constexpr_v(Arg<A>) {}

// CHECK: void constexpr_v(Arg<2> );
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note for reviewers: we used to print Arg<A> here where A isn't forward-declared in the integration header (because we can't do for constexpr variables) which caused compilation errors.

Copy link
Contributor

Choose a reason for hiding this comment

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

What about putting constexpr function calls there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added such test in e502a1b


auto TemplateArgPrinter = [&](const TemplateArgument &Arg) {
if (Arg.getKind() != TemplateArgument::ArgKind::Expression ||
Arg.isInstantiationDependent()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can Arg.isInstantiationDependent() ever be true in SemaSYCL?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it can. This extra check was prompted by

template <int ArrSize>                                                       
[[__sycl_detail__::add_ir_attributes_function("sycl-single-task-kernel", 0)]]
void ff_7(KArgWithPtrArray<ArrSize> KArg) {                                  
  for (int j = 0; j < ArrSize; j++)                                          
    for (int i = KArg.start[j]; i <= KArg.end[j]; i++)                       
      KArg.data[j][i] = KArg.start[j] + KArg.end[j];                         
}                                                                            

(snippet from clang/test/CodeGenSYCL/free_function_int_header.cpp).

ArrSize template argument is instantiation dependent here

return;
}

Expr *E = Arg.getAsExpr();
Copy link
Contributor

Choose a reason for hiding this comment

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

Can E end up being null?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It shouldn't be because I check the argument kind above, but I added an assertion just in case (and to help static analyzers)

[[__sycl_detail__::add_ir_attributes_function("sycl-nd-range-kernel", 2)]]
void constexpr_v(Arg<A>) {}

// CHECK: void constexpr_v(Arg<2> );
Copy link
Contributor

Choose a reason for hiding this comment

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

What about putting constexpr function calls there?

Copy link
Contributor

@intel/llvm-gatekeepers please consider merging

@AlexeySachkov AlexeySachkov merged commit 6db442a into intel:sycl Sep 25, 2025
45 of 46 checks passed
@AlexeySachkov AlexeySachkov deleted the private/asachkov/one-more-free-function-kernels-fix branch September 25, 2025 08:09
AlexeySachkov added a commit to AlexeySachkov/llvm that referenced this pull request Sep 29, 2025
…sions (intel#20187)

`constexpr` variables are not forward-declarable so if one is used as a
template parameter of a free function kernel argument, we cannot
reference the variable, but must inline the value into the integration
header.
AlexeySachkov added a commit that referenced this pull request Sep 30, 2025
This is joined cherry-pick of #20187 and #20123

---

[SYCL] Allow free function kernel args be templated on integer
expressions (#20187)

`constexpr` variables are not forward-declarable so if one is used as a
template parameter of a free function kernel argument, we cannot
reference the variable, but must inline the value into the integration
header.

---

[SYCL] Fix error with type aliases used as free function kernel args
(#20123)

This PR fixes type name that is being printed as free function kernel
argument type in its forward-declaration in the integration header.

Before the change, we used the original argument type name, which could
be an alias - this patch makes use of the canonical type's name to make
sure that all type aliases are "unwrapped".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants