[SYCL] Emit vtables of classes with indirectly_callable virtual functions in every translation unit that references the vtable - #23059
Open
lbushi25 wants to merge 2 commits into
Open
Conversation
…ions Fixes intel#15071 and intel#15069. SYCLVirtualFunctionsAnalysisPass propagates the "calls-indirectly" attribute onto kernels by walking from a virtual function carrying "indirectly-callable" to the vtables which reference it, and from there to the kernels which reference those vtables. That only works if both the vtable initializer and the attribute are visible in the module being analyzed, which was not the case when a virtual function was defined out-of-line: * "indirectly-callable" was only attached to function definitions, so a translation unit which only saw a declaration lost the information; * ModuleBuilder::HandleVTable bailed out unconditionally for SYCL device compilation, so a vtable whose key function is defined in another translation unit was never emitted at all and the analysis had nothing to look at. As a result a kernel which merely constructed an object of a polymorphic class was not marked as using virtual functions, and runtime linking later failed with undefined references to the virtual functions from the vtable. This does the following, all restricted to SYCL device compilation and to classes which declare (or inherit) an 'indirectly_callable' virtual function: * attach compile-time properties to function declarations as well, not just to definitions; * force the vtable to be emitted in every translation unit which completes such a class, regardless of where the key function is defined; * give such vtables linkonce_odr linkage so that emitting them more than once is not a problem once all device code is linked together, and so that they can be duplicated across device images produced by device code split - which is what intel#15069 was about. Vtables of polymorphic classes unrelated to the virtual functions extension keep the previous behaviour of not being defined in device code at all. The three previously XFAILed end-to-end tests are un-XFAILed and gain -O0 RUN lines, since vtable linkage depends on the optimization level. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
lbushi25
marked this pull request as ready for review
August 31, 2026 19:36
YuriPlyakhin
approved these changes
Aug 31, 2026
YuriPlyakhin
left a comment
Contributor
There was a problem hiding this comment.
llvm/test/SYCLLowerIR/SYCLVirtualFunctionsAnalysis/calls-indirectly-propagation-5.ll LGTM
cperkinsintel
approved these changes
Sep 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SYCLVirtualFunctionsAnalysisPass propagates the "calls-indirectly" attribute onto kernels by walking from a virtual function carrying "indirectly-callable" to the vtables which reference it, and from there to the kernels which reference those vtables. That only works if both the vtable initializer and the attribute are visible in the module being analyzed, which was not the case when a virtual function was defined out-of-line:
As a result a kernel which merely constructed an object of a polymorphic class was not marked as using virtual functions, and runtime linking later failed with undefined references to the virtual functions from the vtable.
This does the following, all restricted to SYCL device compilation and to classes which declare (or inherit) an 'indirectly_callable' virtual function:
Vtables of polymorphic classes unrelated to the virtual functions extension keep the previous behaviour of not being defined in device code at all.
The three previously XFAILed end-to-end tests are un-XFAILed and gain -O0 RUN lines, since vtable linkage depends on the optimization level.
Closes: #15071
Closes: #15069