Skip to content

Commit c073c22

Browse files
authored
[HLSL] Use hlsl_device address space for getpointer. (llvm#127675)
We add the hlsl_device address space to represent the device memory space as defined in section 1.7.1.3 of the [HLSL spec](https://microsoft.github.io/hlsl-specs/specs/hlsl.pdf). Fixes llvm#127075
1 parent 5e101de commit c073c22

21 files changed

+124
-65
lines changed

clang/include/clang/Basic/AddressSpaces.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ enum class LangAS : unsigned {
6060
hlsl_groupshared,
6161
hlsl_constant,
6262
hlsl_private,
63+
hlsl_device,
6364

6465
// Wasm specific address spaces.
6566
wasm_funcref,

clang/lib/AST/Type.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,12 @@ bool Qualifiers::isTargetAddressSpaceSupersetOf(LangAS A, LangAS B,
9494
(A == LangAS::Default &&
9595
(B == LangAS::cuda_constant || B == LangAS::cuda_device ||
9696
B == LangAS::cuda_shared)) ||
97-
// `this` overloading depending on address space is not ready,
98-
// so this is a hack to allow generating addrspacecasts.
99-
// IR legalization will be required when this address space is used.
97+
// In HLSL, the this pointer for member functions points to the default
98+
// address space. This causes a problem if the structure is in
99+
// a different address space. We want to allow casting from these
100+
// address spaces to default to work around this problem.
100101
(A == LangAS::Default && B == LangAS::hlsl_private) ||
102+
(A == LangAS::Default && B == LangAS::hlsl_device) ||
101103
// Conversions from target specific address spaces may be legal
102104
// depending on the target information.
103105
Ctx.getTargetInfo().isAddressSpaceSupersetOf(A, B);

clang/lib/AST/TypePrinter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2617,6 +2617,8 @@ std::string Qualifiers::getAddrSpaceAsString(LangAS AS) {
26172617
return "hlsl_constant";
26182618
case LangAS::hlsl_private:
26192619
return "hlsl_private";
2620+
case LangAS::hlsl_device:
2621+
return "hlsl_device";
26202622
case LangAS::wasm_funcref:
26212623
return "__funcref";
26222624
default:

clang/lib/Basic/Targets/AArch64.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ static const unsigned ARM64AddrSpaceMap[] = {
4646
0, // hlsl_groupshared
4747
0, // hlsl_constant
4848
0, // hlsl_private
49+
0, // hlsl_device
4950
// Wasm address space values for this target are dummy values,
5051
// as it is only enabled for Wasm targets.
5152
20, // wasm_funcref

clang/lib/Basic/Targets/AMDGPU.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ const LangASMap AMDGPUTargetInfo::AMDGPUDefIsGenMap = {
6363
// FIXME(pr/122103): hlsl_private -> PRIVATE is wrong, but at least this
6464
// will break loudly.
6565
llvm::AMDGPUAS::PRIVATE_ADDRESS, // hlsl_private
66+
llvm::AMDGPUAS::GLOBAL_ADDRESS, // hlsl_device
6667
};
6768

6869
const LangASMap AMDGPUTargetInfo::AMDGPUDefIsPrivMap = {
@@ -89,6 +90,7 @@ const LangASMap AMDGPUTargetInfo::AMDGPUDefIsPrivMap = {
8990
llvm::AMDGPUAS::FLAT_ADDRESS, // hlsl_groupshared
9091
llvm::AMDGPUAS::CONSTANT_ADDRESS, // hlsl_constant
9192
llvm::AMDGPUAS::PRIVATE_ADDRESS, // hlsl_private
93+
llvm::AMDGPUAS::GLOBAL_ADDRESS, // hlsl_device
9294
};
9395
} // namespace targets
9496
} // namespace clang

clang/lib/Basic/Targets/DirectX.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ static const unsigned DirectXAddrSpaceMap[] = {
4444
3, // hlsl_groupshared
4545
2, // hlsl_constant
4646
0, // hlsl_private
47+
0, // hlsl_device
4748
// Wasm address space values for this target are dummy values,
4849
// as it is only enabled for Wasm targets.
4950
20, // wasm_funcref

clang/lib/Basic/Targets/NVPTX.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ static const unsigned NVPTXAddrSpaceMap[] = {
4848
0, // hlsl_groupshared
4949
0, // hlsl_constant
5050
0, // hlsl_private
51+
0, // hlsl_device
5152
// Wasm address space values for this target are dummy values,
5253
// as it is only enabled for Wasm targets.
5354
20, // wasm_funcref

clang/lib/Basic/Targets/SPIR.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ static const unsigned SPIRDefIsPrivMap[] = {
4949
0, // hlsl_groupshared
5050
2, // hlsl_constant
5151
10, // hlsl_private
52+
11, // hlsl_device
5253
// Wasm address space values for this target are dummy values,
5354
// as it is only enabled for Wasm targets.
5455
20, // wasm_funcref
@@ -84,6 +85,7 @@ static const unsigned SPIRDefIsGenMap[] = {
8485
0, // hlsl_groupshared
8586
0, // hlsl_constant
8687
10, // hlsl_private
88+
11, // hlsl_device
8789
// Wasm address space values for this target are dummy values,
8890
// as it is only enabled for Wasm targets.
8991
20, // wasm_funcref

clang/lib/Basic/Targets/SystemZ.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ static const unsigned ZOSAddressMap[] = {
4444
0, // hlsl_groupshared
4545
0, // hlsl_constant
4646
0, // hlsl_private
47+
0, // hlsl_device
4748
0 // wasm_funcref
4849
};
4950

clang/lib/Basic/Targets/TCE.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ static const unsigned TCEOpenCLAddrSpaceMap[] = {
5353
0, // hlsl_groupshared
5454
0, // hlsl_constant
5555
0, // hlsl_private
56+
0, // hlsl_device
5657
// Wasm address space values for this target are dummy values,
5758
// as it is only enabled for Wasm targets.
5859
20, // wasm_funcref

0 commit comments

Comments
 (0)