-
Notifications
You must be signed in to change notification settings - Fork 787
[SYCL][Clang] Permit virtual functions in SYCL #7255
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
[SYCL][Clang] Permit virtual functions in SYCL #7255
Conversation
To enable virtual functions support in SYCL we need to change virtual table variables address space, so llvm-spirv translator is able to generate valid SPIR-V modules.
@intel/dpcpp-cfe-reviewers could you please take a look? It's a draft because there is no test and lot of lit-test failures. I will add a test and fix failures if this patch is valid. |
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.
Quick review.
E2E is in the progress |
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.
OK for driver
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.
Please add a test.
clang/lib/CodeGen/ItaniumCXXABI.cpp
Outdated
static_cast<unsigned>(LangAS::opencl_global)) | ||
: CGM.Int8PtrTy; | ||
if (!VTable) { | ||
if (VTableTy == CGM.Int8PtrTy) { |
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.
VTableTy is Int8PtrTy
for both SYCL and non-SYCL case above right? So what is the else
for?
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 believe Int8PtrTy
and Int8PtrTy(LangAS::opencl_global)
are different, am I wrong?
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 not sure but in any case, I think it is better to guard this using SYCLIsDevice
.
I am not familiar with this code so I may be wrong but do we need the call back function? Won't global variable be constructed with modified VTableTy without the callback back? Or do default constructors not consider address space?
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 think all new changes need to be guarded with SYCLIsDevice
if as well as SYCLAllowVirtualFunctions
.
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.
Smth like
if (!VTable) {
Type *VTableTy = CGM.Int8PtrTy;
if (CGM.getLangOpts().SYCLIsDevice &&
CGM.getLangOpts().SYCLAllowVirtualFunctions &&
(VTableName == ClassTypeInfo || VTableName == SIClassTypeInfo)) {
VTableTy =
CGM.Int8Ty->getPointerTo(static_cast<unsigned>(LangAS::opencl_global))
VTable =
CGM.getModule().getOrInsertGlobal(VTableName, VTableTy, [&] {
return new llvm::GlobalVariable(
CGM.getModule(), VTableTy, false,
llvm::GlobalVariable::ExternalLinkage, nullptr, VTableName,
nullptr, llvm::GlobalValue::ThreadLocalMode::NotThreadLocal,
llvm::Optional<unsigned>(
static_cast<unsigned>(LangAS::opencl_global)));
});
} else {
VTable = CGM.getModule().getOrInsertGlobal(VTableName, VTableTy);
}
}
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.
Are you ok with c810c23 or you don't want to see VTableTy
with opencl_global
outside of this guards?
…ita/llvm into virtual-function-crash
clang/lib/CodeGen/ItaniumCXXABI.cpp
Outdated
static_cast<unsigned>(LangAS::opencl_global)) | ||
: CGM.Int8PtrTy; | ||
if (!VTable) { | ||
if (VTableTy == CGM.Int8PtrTy) { |
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 think all new changes need to be guarded with SYCLIsDevice
if as well as SYCLAllowVirtualFunctions
.
clang/lib/CodeGen/ItaniumCXXABI.cpp
Outdated
static_cast<unsigned>(LangAS::opencl_global)) | ||
: CGM.Int8PtrTy; | ||
if (!VTable) { | ||
if (VTableTy == CGM.Int8PtrTy) { |
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.
Smth like
if (!VTable) {
Type *VTableTy = CGM.Int8PtrTy;
if (CGM.getLangOpts().SYCLIsDevice &&
CGM.getLangOpts().SYCLAllowVirtualFunctions &&
(VTableName == ClassTypeInfo || VTableName == SIClassTypeInfo)) {
VTableTy =
CGM.Int8Ty->getPointerTo(static_cast<unsigned>(LangAS::opencl_global))
VTable =
CGM.getModule().getOrInsertGlobal(VTableName, VTableTy, [&] {
return new llvm::GlobalVariable(
CGM.getModule(), VTableTy, false,
llvm::GlobalVariable::ExternalLinkage, nullptr, VTableName,
nullptr, llvm::GlobalValue::ThreadLocalMode::NotThreadLocal,
llvm::Optional<unsigned>(
static_cast<unsigned>(LangAS::opencl_global)));
});
} else {
VTable = CGM.getModule().getOrInsertGlobal(VTableName, VTableTy);
}
}
Also, I believe @elizabethandrews means clang LIT test. E2E test only won't be enough. |
Co-authored-by: Alexey Sachkov <[email protected]>
Co-authored-by: Alexey Sachkov <[email protected]>
Co-authored-by: premanandrao <[email protected]>
…ita/llvm into virtual-function-crash
Co-authored-by: Alexey Bader <[email protected]>
@intel/llvm-gatekeepers |
Failures unrelated:
|
To enable virtual functions support in SYCL we need to change virtual table variables address space, so llvm-spirv translator is able to generate valid SPIR-V modules.