Skip to content

Commit c278543

Browse files
committed
[SYCL] Implement SYCL address-space rules.
Signed-off-by: Vladimir Lazarev <[email protected]>
1 parent effac35 commit c278543

21 files changed

+337
-26
lines changed

clang/include/clang/AST/Type.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,13 @@ class Qualifiers {
473473
// Otherwise in OpenCLC v2.0 s6.5.5: every address space except
474474
// for __constant can be used as __generic.
475475
(getAddressSpace() == LangAS::opencl_generic &&
476-
other.getAddressSpace() != LangAS::opencl_constant);
476+
other.getAddressSpace() != LangAS::opencl_constant) ||
477+
(!hasAddressSpace() &&
478+
(other.getAddressSpace() == LangAS::sycl_private ||
479+
other.getAddressSpace() == LangAS::sycl_local ||
480+
other.getAddressSpace() == LangAS::sycl_global ||
481+
other.getAddressSpace() == LangAS::sycl_constant ||
482+
other.getAddressSpace() == LangAS::sycl_generic));
477483
}
478484

479485
/// Determines if these qualifiers compatibly include another set.

clang/include/clang/Basic/AddressSpaces.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ enum class LangAS : unsigned {
4343
cuda_constant,
4444
cuda_shared,
4545

46+
sycl_global,
47+
sycl_local,
48+
sycl_constant,
49+
sycl_private,
50+
// Likely never used, but useful in the future to reserve the spot in the
51+
// enum.
52+
sycl_generic,
4653
// This denotes the count of language-specific address spaces and also
4754
// the offset added to the target-specific address spaces, which are usually
4855
// specified by address space attributes __attribute__(address_space(n))).

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9482,4 +9482,7 @@ def err_builtin_launder_invalid_arg : Error<
94829482
"%select{non-pointer|function pointer|void pointer}0 argument to "
94839483
"'__builtin_launder' is not allowed">;
94849484

9485+
def err_sycl_attribute_address_space_invalid : Error<
9486+
"address space is outside the valid range of values">;
9487+
94859488
} // end of sema component.

clang/include/clang/Basic/TokenKinds.def

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ PUNCTUATOR(caretcaret, "^^")
248248
// MSVC <= v18.
249249
// KEYOPENCLC - This is a keyword in OpenCL C
250250
// KEYOPENCLCXX - This is a keyword in OpenCL C++
251+
// KEYSYCL - This is a keyword in SYCL C++
251252
// KEYNOOPENCL - This is a keyword that is not supported in OpenCL C
252253
// nor in OpenCL C++.
253254
// KEYALTIVEC - This is a keyword in AltiVec
@@ -530,10 +531,10 @@ KEYWORD(__unaligned , KEYMS)
530531
KEYWORD(__super , KEYMS)
531532

532533
// OpenCL address space qualifiers
533-
KEYWORD(__global , KEYOPENCLC | KEYOPENCLCXX)
534-
KEYWORD(__local , KEYOPENCLC | KEYOPENCLCXX)
535-
KEYWORD(__constant , KEYOPENCLC | KEYOPENCLCXX)
536-
KEYWORD(__private , KEYOPENCLC | KEYOPENCLCXX)
534+
KEYWORD(__global , KEYOPENCLC | KEYOPENCLCXX | KEYSYCL)
535+
KEYWORD(__local , KEYOPENCLC | KEYOPENCLCXX | KEYSYCL)
536+
KEYWORD(__constant , KEYOPENCLC | KEYOPENCLCXX | KEYSYCL)
537+
KEYWORD(__private , KEYOPENCLC | KEYOPENCLCXX | KEYSYCL)
537538
KEYWORD(__generic , KEYOPENCLC | KEYOPENCLCXX)
538539
ALIAS("global", __global , KEYOPENCLC)
539540
ALIAS("local", __local , KEYOPENCLC)

clang/lib/AST/ASTContext.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,12 @@ static const LangASMap *getAddressSpaceMap(const TargetInfo &T,
760760
4, // opencl_generic
761761
5, // cuda_device
762762
6, // cuda_constant
763-
7 // cuda_shared
763+
7, // cuda_shared
764+
1, // sycl_global
765+
3, // sycl_local
766+
2, // sycl_constant
767+
5, // sycl_private
768+
4, // sycl_generic
764769
};
765770
return &FakeAddrSpaceMap;
766771
} else {

clang/lib/AST/ItaniumMangle.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2224,7 +2224,7 @@ void CXXNameMangler::mangleQualifiers(Qualifiers Quals, const DependentAddressSp
22242224
if (Context.getASTContext().addressSpaceMapManglingFor(AS)) {
22252225
// <target-addrspace> ::= "AS" <address-space-number>
22262226
unsigned TargetAS = Context.getASTContext().getTargetAddressSpace(AS);
2227-
if (TargetAS != 0)
2227+
if (TargetAS != 0 || (Context.getASTContext().getLangOpts().SYCL))
22282228
ASString = "AS" + llvm::utostr(TargetAS);
22292229
} else {
22302230
switch (AS) {

clang/lib/AST/TypePrinter.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,15 +1747,21 @@ void Qualifiers::print(raw_ostream &OS, const PrintingPolicy& Policy,
17471747
addSpace = true;
17481748
switch (addrspace) {
17491749
case LangAS::opencl_global:
1750+
case LangAS::sycl_global:
17501751
OS << "__global";
17511752
break;
17521753
case LangAS::opencl_local:
1754+
case LangAS::sycl_local:
17531755
OS << "__local";
17541756
break;
17551757
case LangAS::opencl_private:
17561758
break;
1759+
case LangAS::sycl_private:
1760+
OS << "__private";
1761+
break;
17571762
case LangAS::opencl_constant:
17581763
case LangAS::cuda_constant:
1764+
case LangAS::sycl_constant:
17591765
OS << "__constant";
17601766
break;
17611767
case LangAS::opencl_generic:

clang/lib/Basic/IdentifierTable.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,9 @@ namespace {
100100
KEYMODULES = 0x100000,
101101
KEYCXX2A = 0x200000,
102102
KEYOPENCLCXX = 0x400000,
103-
KEYALLCXX = KEYCXX | KEYCXX11 | KEYCXX2A,
104-
KEYALL = (0xffffff & ~KEYNOMS18 &
103+
KEYSYCL = 0x1000000,
104+
KEYALLCXX = KEYSYCL | KEYCXX | KEYCXX11 | KEYCXX2A,
105+
KEYALL = (0x1ffffff & ~KEYNOMS18 &
105106
~KEYNOOPENCL) // KEYNOMS18 and KEYNOOPENCL are used to exclude.
106107
};
107108

@@ -136,6 +137,7 @@ static KeywordStatus getKeywordStatus(const LangOptions &LangOpts,
136137
if (LangOpts.OpenCL && !LangOpts.OpenCLCPlusPlus && (Flags & KEYOPENCLC))
137138
return KS_Enabled;
138139
if (LangOpts.OpenCLCPlusPlus && (Flags & KEYOPENCLCXX)) return KS_Enabled;
140+
if (LangOpts.SYCL && (Flags & KEYSYCL)) return KS_Enabled;
139141
if (!LangOpts.CPlusPlus && (Flags & KEYNOCXX)) return KS_Enabled;
140142
if (LangOpts.C11 && (Flags & KEYC11)) return KS_Enabled;
141143
// We treat bridge casts as objective-C keywords so we can warn on them

clang/lib/Basic/Targets/AMDGPU.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@ const LangASMap AMDGPUTargetInfo::AMDGPUDefIsGenMap = {
4646
Generic, // opencl_generic
4747
Global, // cuda_device
4848
Constant, // cuda_constant
49-
Local // cuda_shared
49+
Local, // cuda_shared
50+
Global, // sycl_global
51+
Local, // sycl_local
52+
Constant, // sycl_constant
53+
Private, // sycl_private
54+
Generic, // sycl_generic
5055
};
5156

5257
const LangASMap AMDGPUTargetInfo::AMDGPUDefIsPrivMap = {
@@ -58,7 +63,12 @@ const LangASMap AMDGPUTargetInfo::AMDGPUDefIsPrivMap = {
5863
Generic, // opencl_generic
5964
Global, // cuda_device
6065
Constant, // cuda_constant
61-
Local // cuda_shared
66+
Local, // cuda_shared
67+
Global, // sycl_global
68+
Local, // sycl_local
69+
Constant, // sycl_constant
70+
Private, // sycl_private
71+
Generic, // sycl_generic
6272
};
6373
} // namespace targets
6474
} // namespace clang

clang/lib/Basic/Targets/NVPTX.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ static const unsigned NVPTXAddrSpaceMap[] = {
3434
1, // cuda_device
3535
4, // cuda_constant
3636
3, // cuda_shared
37+
1, // sycl_global
38+
3, // sycl_local
39+
4, // sycl_constant
40+
5, // sycl_private
41+
// FIXME: generic has to be added to the target
42+
0, // sycl_generic
3743
};
3844

3945
class LLVM_LIBRARY_VISIBILITY NVPTXTargetInfo : public TargetInfo {

0 commit comments

Comments
 (0)