-
Notifications
You must be signed in to change notification settings - Fork 770
[SYCL] Add clang support for device_global #5597
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
Changes from 3 commits
0251bfb
117de59
a96d57a
f2230af
0fb176d
e4c15c4
af8a294
feb841b
df337a7
748e8ce
d84428c
0343158
6d6d7dd
679b5f0
5ecd545
e51530d
aef34f9
4cac80e
3f79c5e
2664869
0469d18
d25c816
19f62a5
0354ea5
b45159d
3baff38
5bced1a
505a4f2
4905d70
3817bf0
1c53934
e489d50
0709448
d4647f6
ef0f5d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7099,6 +7099,17 @@ def warn_format_nonliteral : Warning< | |
"format string is not a string literal">, | ||
InGroup<FormatNonLiteral>, DefaultIgnore; | ||
|
||
def err_non_static_member_use_not_allowed : Error< | ||
"use of non-static member variable %0 is not allowed">; | ||
schittir marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def err_not_publicly_accessible: Error< | ||
"member variable %0 not publicly accessible">; | ||
schittir marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def err_array_of_device_global_not_allowed : Error< | ||
"array of device_global %0 is not allowed">; | ||
schittir marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def err_shadow_variable_within_same_namespace: Error< | ||
"shadow variable %0 not allowed withing the same enclosing namespace scope">; | ||
def err_namespace_name_shadows_namespace_containing_device_global : Error< | ||
"not allowed: namespace name shadows %0 namespace which contains device_global">; | ||
schittir marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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. Yeah, so as I suggested, let's focus on the functional part described by the design doc first. I'll take a closer look tomorrow on how we can implement diagnosing. But now, I'm not even sure how to do that, since the attribute applies to the class, but the restrictions are applied to a concrete object of that class. 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. Sema::ActOnVariableDeclarator in SemaDecl.cpp looks promising |
||
def err_unexpected_interface : Error< | ||
"unexpected interface name %0: expected expression">; | ||
def err_ref_non_value : Error<"%0 does not refer to a value">; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2839,6 +2839,15 @@ void CodeGenModule::AddGlobalAnnotations(const ValueDecl *D, | |
Annotations.push_back(EmitAnnotateAttr(GV, I, D->getLocation())); | ||
} | ||
|
||
void CodeGenModule::addSYCLUniqueID(llvm::GlobalVariable *GV, | ||
const RecordDecl *RD) { | ||
const auto *A = RD->getAttr<SYCLDetailDeviceGlobalAttr>(); | ||
assert(A && "no device_global attribute"); | ||
const VarDecl *VD = dyn_cast<VarDecl>(RD->getParent()); | ||
auto builtinString = SYCLUniqueStableIdExpr::ComputeName(Context, VD); | ||
schittir marked this conversation as resolved.
Show resolved
Hide resolved
|
||
GV->addAttribute("sycl-unique-id", builtinString); | ||
} | ||
|
||
bool CodeGenModule::isInNoSanitizeList(SanitizerMask Kind, llvm::Function *Fn, | ||
SourceLocation Loc) const { | ||
const auto &NoSanitizeL = getContext().getNoSanitizeList(); | ||
|
@@ -4927,6 +4936,12 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D, | |
if (getLangOpts().SYCLIsDevice) | ||
addGlobalIntelFPGAAnnotation(D, GV); | ||
|
||
if (getLangOpts().SYCLIsDevice) { | ||
schittir marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const RecordDecl *RD = D->getType()->getAsRecordDecl(); | ||
if (RD && RD->hasAttr<SYCLDetailDeviceGlobalAttr>()) | ||
addSYCLUniqueID(GV, RD); | ||
} | ||
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. Yeah, I think this how I would do that. We need the tests though. |
||
|
||
if (D->getType().isRestrictQualified()) { | ||
llvm::LLVMContext &Context = getLLVMContext(); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown-sycldevice -std=c++17 -emit-llvm %s -o - | FileCheck %s | ||
#include "Inputs/sycl.hpp" | ||
|
||
using namespace sycl::ext::oneapi; | ||
static device_global<int> Foo; | ||
|
||
device_global<int> a; // OK | ||
static device_global<int> b; // OK | ||
//inline device_global<int> c; // OK | ||
|
||
struct Foo { | ||
static device_global<int> d; // OK | ||
}; | ||
device_global<int> Foo::d; | ||
|
||
struct Bar { | ||
device_global<int> e; // ILLEGAL: non-static member variable not | ||
}; // allowed | ||
|
||
//struct Baz { | ||
// private: | ||
// static device_global<int> f; // ILLEGAL: not publicly accessible from | ||
//}; // namespace scope | ||
//device_global<int> Baz::f; | ||
|
||
//device_global<int[4]> g; // OK | ||
//device_global<int> h[4]; // ILLEGAL: array of "device_global" not | ||
// allowed | ||
|
||
//device_global<int> same_name; // OK | ||
//namespace foo { | ||
// device_global<int> same_name; // OK | ||
//} | ||
//namespace { | ||
// device_global<int> same_name; // OK | ||
//} | ||
|
||
//inline namespace other { | ||
// device_global<int> same_name; // ILLEGAL: shadows "device_global" variable | ||
//} // with same name in enclosing namespace scope | ||
|
||
//inline namespace { | ||
// namespace foo { // ILLEGAL: namespace name shadows "::foo" | ||
// } // namespace which contains "device_global" | ||
// variable. | ||
//} |
Uh oh!
There was an error while loading. Please reload this page.