-
Notifications
You must be signed in to change notification settings - Fork 798
[SYCL] Update vtable emission logic for device code #16932
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
base: sycl
Are you sure you want to change the base?
Conversation
// RUN: %{build} %S/Inputs/call.cpp -o %t.out %helper-includes %O0 | ||
// RUN: %{run} %t.out |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// RUN: %{build} %S/Inputs/call.cpp -o %t.out %helper-includes %O0 | |
// RUN: %{run} %t.out | |
// RUN: %{build} %S/Inputs/call.cpp -o %t2.out %helper-includes %O0 | |
// RUN: %{run} %t2.out |
// RUN: %{build} %S/Inputs/call.cpp %S/Inputs/vf.cpp -o %t.out %helper-includes %O0 | ||
// RUN: %{run} %t.out |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// RUN: %{build} %S/Inputs/call.cpp %S/Inputs/vf.cpp -o %t.out %helper-includes %O0 | |
// RUN: %{run} %t.out | |
// RUN: %{build} %S/Inputs/call.cpp %S/Inputs/vf.cpp -o %t2.out %helper-includes %O0 | |
// RUN: %{run} %t2.out |
// RUN: %{build} %S/Inputs/vf.cpp -o %t.out %helper-includes %O0 | ||
// RUN: %{run} %t.out |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// RUN: %{build} %S/Inputs/vf.cpp -o %t.out %helper-includes %O0 | |
// RUN: %{run} %t.out | |
// RUN: %{build} %S/Inputs/vf.cpp -o %t2.out %helper-includes %O0 | |
// RUN: %{run} %t2.out |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FE changes need to be accompanied by FE tests. Please add a few tests.
@@ -3283,6 +3283,18 @@ void CodeGenModule::SetFunctionAttributes(GlobalDecl GD, llvm::Function *F, | |||
if (const auto *A = FD->getAttr<SYCLUsesAspectsAttr>()) | |||
applySYCLAspectsMD(A, getContext(), getLLVMContext(), F, | |||
"sycl_used_aspects"); | |||
|
|||
if (getLangOpts().SYCLIsDevice && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am guessing we should not be adding this attribute in both SetFunctionAttributes
and StartFunction
. Have you checked if we're duplicating the attribute now? What happens when you remove the code in StartFunction
There PR aims to fix these two issues:
calls-indirectly
attribute propagation doesn't always happen as necessary #15071:separate-vf-defs.cpp
/separate-vf-defs-and-calls
- The construction kernels were not being recognized bySYCLVirtualFunctionsAnalysisPass
(i.e. attaching calls-indirectly to them). They were not being attached because the definitions for the vtables were not being emitted in those compilation units, andSYCLVirtualFunctionsAnalysisPass
can only correctly identifies construction kernels by analyzing the vtable definition referenced during object construction.separate-call.cpp
- when sycl-post-link was splitting, the vtables were duplicated in the device images. This caused multiple definition errors between the duplicated vtables.1 is fixed by using
MarkVTableUsed
on classes that have SYCLindirectly-callable
attribute on one of their members, allowing the vtable definition to be generated. (Note: I would have liked to do thisMarkVTableUsed
call is inSemaSYCL::addSYCLAddIRAttributesFunctionAttr
instead ofSema::CheckCompletedCXXClass
but I was having an issue thatMarkVTableUsed
did not updateVTablesUsed
correctly because at that point the class wasn't recognized as virtual). With this, the vtable definition will be generated, but there is another problem - the functions referenced in the vtables did not have the relevantindirectly-callable
attributes. These are usually attached by code gen if the function has a definition, but the definitions of the virtual functions do not necessarily need to be in the same compilation unit as the construction kernels. To fix this, a separate attribute attachment is added when code gen needs the pointer of some function. (Thesycl_used_aspects
metadata is attached at the same time.)Since the fix for 1 emit vtables in every device module, we need to change the linkage type of the vtables during device compilation to
linkonce_odr
, otherwise there could be multiple definition issues in the device link set. This change also happens to fix the issue of 2.