Skip to content

[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
intel:syclfrom
lbushi25:fix-15071-vtable-emission
Open

[SYCL] Emit vtables of classes with indirectly_callable virtual functions in every translation unit that references the vtable#23059
lbushi25 wants to merge 2 commits into
intel:syclfrom
lbushi25:fix-15071-vtable-emission

Conversation

@lbushi25

@lbushi25 lbushi25 commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

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:

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

…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 lbushi25 changed the title [SYCL] Emit vtables of classes with indirectly_callable virtual funct… [SYCL] Emit vtables of classes with indirectly_callable virtual functions Aug 31, 2026
@lbushi25
lbushi25 marked this pull request as ready for review August 31, 2026 19:36
@lbushi25
lbushi25 requested review from a team as code owners August 31, 2026 19:36
@lbushi25
lbushi25 requested a review from cperkinsintel August 31, 2026 19:36
@lbushi25 lbushi25 changed the title [SYCL] Emit vtables of classes with indirectly_callable virtual functions [SYCL] Emit vtables of classes with indirectly_callable virtual functions in every translation unit that references the vtable Aug 31, 2026

@YuriPlyakhin YuriPlyakhin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

llvm/test/SYCLLowerIR/SYCLVirtualFunctionsAnalysis/calls-indirectly-propagation-5.ll LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants