Skip to content

Conversation

@steffenlarsen
Copy link
Contributor

This commit adds the implementation logic for merging sycl_detail::add_ir_attributes_* attributes, which will enable the ability to apply multiple of the same attribute to the same declaration/definition, as long as the values associated to the same names in the attributes do not conflict.

This is needed for SYCL free function support as the way SYCL properties are applied are through macros expanding to
sycl_detail::add_ir_attributes_* with a single name-value-pair.

This commit adds the implementation logic for merging
__sycl_detail__::add_ir_attributes_* attributes, which will enable the
ability to apply multiple of the same attribute to the same
declaration/definition, as long as the values associated to the same
names in the attributes do not conflict.

This is needed for SYCL free function support as the way SYCL properties
are applied are through macros expanding to
__sycl_detail__::add_ir_attributes_* with a single name-value-pair.

Signed-off-by: Larsen, Steffen <[email protected]>
Signed-off-by: Larsen, Steffen <[email protected]>
Signed-off-by: Larsen, Steffen <[email protected]>
Signed-off-by: Larsen, Steffen <[email protected]>
[[__sycl_detail__::add_ir_attributes_function({"Attr1", "Attr3"}, "Attr2", "Attr1", true, 1)]] void FunctionRedecl3();
[[__sycl_detail__::add_ir_attributes_function({"Attr3", "Attr1"}, "Attr1", "Attr2", 1, true)]] void FunctionRedecl3(); // expected-note {{conflicting attribute is here}}
[[__sycl_detail__::add_ir_attributes_function({"Attr3", "Attr1"}, "Attr1", "Attr2", 1, true)]] void FunctionRedecl3();
[[__sycl_detail__::add_ir_attributes_function({"Attr1", "Attr3"}, "Attr1", "Attr2", 1, false)]] void FunctionRedecl3(); // expected-error {{attribute '__sycl_detail__::add_ir_attributes_function' is already applied with different arguments}} expected-note {{conflicting attribute is here}}
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry what is the conflict here? I might just be misunderstanding how filters work, but you said only the attributes in the filter list are applied, which means only Attr1 is applied right? Isn't it's value 1 in all cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We resolve conflicts without applying the filter. The argument is that from clang's point-of-view, the values are still conflicting, even if they don't end up producing IR attributes. I don't think this behavior is necessarily strictly needed, but I like to think it fits the mental model.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm....functionally that is questionable to me. If filters determine what the attributes are why should we care if non-applied attributes conflict?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem with applying the filters when merging is that we lose the information about the values before we would normally apply the filters. We don't currently use the filters all that much, but I also don't see a use-case for us where we would want to allow conflicting values, even for the ones we filter out.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok. I defer to you since I am not very familiar with the usage/functionality of these attributes. Please add AST tests though and maybe a comment somewhere how filters work in this context. It is not intuitive.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The new tests are in 7c7173d

Signed-off-by: Larsen, Steffen <[email protected]>
Signed-off-by: Larsen, Steffen <[email protected]>
Signed-off-by: Larsen, Steffen <[email protected]>
@github-actions
Copy link
Contributor

github-actions bot commented Nov 6, 2025

@intel/llvm-gatekeepers please consider merging

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