-
Notifications
You must be signed in to change notification settings - Fork 751
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SYCL] Implement virtual-table prohibit in SYCL device code.
According to SYCL specification, virtual tables are illegal in device code. This accomplishes that in a couple of ways. First, there is a code-gen assert that will prevent emission of virtual tables always. Second, it prevents virtual tables from being 'used', so non-SYCL kernel code cannot cause v-tables to be emitted. Finally, SYCL-specific functions are checked for usage of polymorphic functions and a diagnostic is emitted. Signed-off-by: Vladimir Lazarev <vladimir.lazarev@intel.com>
- Loading branch information
1 parent
33ff936
commit 08b20c1
Showing
8 changed files
with
252 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,30 @@ | ||
// RUN: %clang_cc1 -fsycl-is-device -verify -fsyntax-only -x c++ -emit-llvm-only %s | ||
// expected-no-diagnostics | ||
// Should never fail, since the type is never used in kernel code. | ||
|
||
struct Base { | ||
virtual void f(){} | ||
}; | ||
|
||
struct Inherit : Base { | ||
virtual void f() override {} | ||
}; | ||
|
||
void always_uses() { | ||
Inherit u; | ||
} | ||
|
||
void usage() { | ||
} | ||
|
||
|
||
template <typename name, typename Func> | ||
__attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) { | ||
kernelFunc(); | ||
} | ||
int main() { | ||
always_uses(); | ||
kernel_single_task<class fake_kernel>([]() { usage(); }); | ||
return 0; | ||
} | ||
|
This file contains 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,49 @@ | ||
// RUN: %clang_cc1 -fsycl-is-device -Wno-return-type -verify -fsyntax-only -x c++ -emit-llvm-only %s | ||
|
||
struct Base { | ||
virtual void f() const {} | ||
}; | ||
|
||
// expected-error@+1 9{{No class with a vtable can be used in a SYCL kernel or any code included in the kernel}} | ||
struct Inherit : Base { | ||
virtual void f() const override {} | ||
}; | ||
|
||
Inherit always_uses() { | ||
Inherit u; | ||
} | ||
|
||
static constexpr Inherit IH; | ||
|
||
// expected-note@+1{{used here}} | ||
Inherit *usage_child(){} | ||
|
||
// expected-note@+1{{used here}} | ||
Inherit usage() { | ||
// expected-note@+1{{used here}} | ||
Inherit u; | ||
// expected-note@+1{{used here}} | ||
Inherit *u_ptr; | ||
|
||
// expected-note@+1{{used here}} | ||
using foo = Inherit; | ||
// expected-note@+1{{used here}} | ||
typedef Inherit bar; | ||
// expected-note@+1{{used here}} | ||
IH.f(); | ||
|
||
// expected-note@+1{{used here}} | ||
usage_child(); | ||
} | ||
|
||
|
||
template <typename name, typename Func> | ||
__attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) { | ||
kernelFunc(); | ||
} | ||
int main() { | ||
// expected-note@+1{{used here}} | ||
kernel_single_task<class fake_kernel>([]() { usage(); }); | ||
return 0; | ||
} | ||
|
This file contains 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-is-device -Wno-return-type -verify -fsyntax-only -x c++ -emit-llvm-only %s | ||
|
||
struct Base { | ||
virtual void f() const {} | ||
}; | ||
|
||
// expected-error@+1 3{{No class with a vtable can be used in a SYCL kernel or any code included in the kernel}} | ||
struct Inherit : Base { | ||
virtual void f() const override {} | ||
}; | ||
|
||
struct Wrapper{ | ||
Wrapper() { | ||
// expected-note@+1{{used here}} | ||
Inherit IH; | ||
} | ||
|
||
void Func() { | ||
// expected-note@+1{{used here}} | ||
Inherit IH; | ||
} | ||
|
||
~Wrapper() { | ||
// expected-note@+1{{used here}} | ||
Inherit IH; | ||
} | ||
}; | ||
|
||
void usage() { | ||
Wrapper WR; | ||
WR.Func(); | ||
} | ||
|
||
template <typename name, typename Func> | ||
__attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) { | ||
kernelFunc(); | ||
} | ||
int main() { | ||
kernel_single_task<class fake_kernel>([]() { usage(); }); | ||
return 0; | ||
} | ||
|
This file contains 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,30 @@ | ||
// RUN: %clang_cc1 -fsycl-is-device -Wno-return-type -verify -fsyntax-only -x c++ -emit-llvm-only %s | ||
|
||
struct Base { | ||
virtual void f() const {} | ||
}; | ||
|
||
// expected-error@+1{{No class with a vtable can be used in a SYCL kernel or any code included in the kernel}} | ||
struct Inherit : Base { | ||
virtual void f() const override {} | ||
}; | ||
|
||
struct Wrapper{ | ||
// expected-note@+1{{used here}} | ||
Inherit I; | ||
}; | ||
|
||
void usage() { | ||
// expected-note@+1{{used here}} | ||
Wrapper WR; | ||
} | ||
|
||
template <typename name, typename Func> | ||
__attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) { | ||
kernelFunc(); | ||
} | ||
int main() { | ||
kernel_single_task<class fake_kernel>([]() { usage(); }); | ||
return 0; | ||
} | ||
|