-
Notifications
You must be signed in to change notification settings - Fork 768
[SYCL] Do not emit unneeded static initializations in sycl device code #1774
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
96ef141
[SYCL] Do not emit unneeded static initializations in sycl device code
premanandrao 016d98c
[SYCL] Do not emit unneeded static initializations in sycl device code
premanandrao 283a81f
[SYCL] Do not emit unneeded static initializations in sycl device code
premanandrao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1276,7 +1276,12 @@ void CodeGenModule::EmitCtorList(CtorList &Fns, const char *GlobalName) { | |
ctor.addInt(Int32Ty, I.Priority); | ||
ctor.add(llvm::ConstantExpr::getBitCast(I.Initializer, CtorPFTy)); | ||
if (I.AssociatedData) | ||
ctor.add(llvm::ConstantExpr::getBitCast(I.AssociatedData, VoidPtrTy)); | ||
if (I.AssociatedData->getType()->getPointerAddressSpace() != | ||
VoidPtrTy->getAddressSpace()) | ||
ctor.add( | ||
llvm::ConstantExpr::getAddrSpaceCast(I.AssociatedData, VoidPtrTy)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are adding a new address space cast, but I don't see any address space casts in the test. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, I will modify the test to show this. |
||
else | ||
ctor.add(llvm::ConstantExpr::getBitCast(I.AssociatedData, VoidPtrTy)); | ||
else | ||
ctor.addNullPointer(VoidPtrTy); | ||
ctor.finishAndAddTo(ctors); | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// RUN: %clang_cc1 -fsycl -fsycl-is-device -triple spir64-unknown-unknown-sycldevice -disable-llvm-passes %s -emit-llvm -o - | FileCheck %s | ||
// Test that static initializers do not force the emission of globals on sycl device | ||
|
||
// CHECK: %struct._ZTS16RegisterBaseInit.RegisterBaseInit = type { i8 } | ||
// CHECK-NOT: $_ZN8BaseInitI12TestBaseTypeE15s_regbase_ncsdmE = comdat any | ||
// CHECK: $_ZN8BaseInitI12TestBaseTypeE3varE = comdat any | ||
// CHECK: @_ZN8BaseInitI12TestBaseTypeE9s_regbaseE = {{.*}} global %struct._ZTS16RegisterBaseInit.RegisterBaseInit | ||
// CHECK-NOT: @_ZN8BaseInitI12TestBaseTypeE15s_regbase_ncsdmE = weak_odr addrspace(1) global %struct._ZTS16RegisterBaseInit.RegisterBaseInit zeroinitializer, comdat, align 1 | ||
// CHECK: @_ZN8BaseInitI12TestBaseTypeE3varE = weak_odr addrspace(1) constant i32 9, comdat, align 4 | ||
// CHECK-NOT: @_ZGVN8BaseInitI12TestBaseTypeE15s_regbase_ncsdmE = weak_odr global i64 0, comdat($_ZN8BaseInitI12TestBaseTypeE9s_regbaseE), align 8 | ||
// CHECK: define spir_kernel void @_ZTSZ4mainE11fake_kernel() | ||
// CHECK: call spir_func void @"_ZZ4mainENK3$_0clE16RegisterBaseInit | ||
// CHECK: declare spir_func void @_ZN16RegisterBaseInit3fooEv | ||
|
||
struct TestBaseType {}; | ||
struct RegisterBaseInit { | ||
__attribute__((sycl_device)) void foo(); | ||
RegisterBaseInit(); | ||
}; | ||
template <class T> | ||
struct BaseInit { | ||
static const RegisterBaseInit s_regbase; | ||
static RegisterBaseInit s_regbase_ncsdm; | ||
static const int var; | ||
}; | ||
template <class T> | ||
const RegisterBaseInit BaseInit<T>::s_regbase; | ||
template <class T> | ||
RegisterBaseInit BaseInit<T>::s_regbase_ncsdm; | ||
template <class T> | ||
const int BaseInit<T>::var = 9; | ||
template struct BaseInit<TestBaseType>; | ||
template <typename name, typename Func> | ||
__attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) { | ||
kernelFunc(BaseInit<TestBaseType>::s_regbase); | ||
Fznamznon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
int main() { | ||
kernel_single_task<class fake_kernel>([=](RegisterBaseInit s) { | ||
s.foo(); | ||
}); | ||
return 0; | ||
} |
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.
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.
Should we check that it is correct to do address space cast here?
Like this check
llvm/clang/lib/CodeGen/CGExprScalar.cpp
Line 2996 in ccefc93
@asavonic ?
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.
Yes, we have to ensure that an addrspace cast 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.
Okay, will add this check.
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.
In the cases above, it looks like they values are both cast to the generic address space, to ensure sameness. This does not seem to be needed here, as the cast is to address space 0. However, I have changed the call to use an existing routine (which does the check as well) which is called in few other places, instead of checking it directly how I had it before.