Skip to content

Commit 3d813ec

Browse files
committed
code review feedback
- preserve init and use externally_initialized - update tests and add SPIRV variant - reorder switch in TypePrinter.cpp
1 parent ac04912 commit 3d813ec

File tree

8 files changed

+55
-15
lines changed

8 files changed

+55
-15
lines changed

clang/lib/AST/TypePrinter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2552,12 +2552,12 @@ std::string Qualifiers::getAddrSpaceAsString(LangAS AS) {
25522552
return "__uptr __ptr32";
25532553
case LangAS::ptr64:
25542554
return "__ptr64";
2555-
case LangAS::wasm_funcref:
2556-
return "__funcref";
25572555
case LangAS::hlsl_groupshared:
25582556
return "groupshared";
25592557
case LangAS::hlsl_constant:
25602558
return "hlsl_constant";
2559+
case LangAS::wasm_funcref:
2560+
return "__funcref";
25612561
default:
25622562
return std::to_string(toTargetAddressSpace(AS));
25632563
}

clang/lib/Basic/Targets/AMDGPU.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ const LangASMap AMDGPUTargetInfo::AMDGPUDefIsGenMap = {
5959
llvm::AMDGPUAS::FLAT_ADDRESS, // ptr32_uptr
6060
llvm::AMDGPUAS::FLAT_ADDRESS, // ptr64
6161
llvm::AMDGPUAS::FLAT_ADDRESS, // hlsl_groupshared
62+
llvm::AMDGPUAS::FLAT_ADDRESS, // hlsl_constant
6263
};
6364

6465
const LangASMap AMDGPUTargetInfo::AMDGPUDefIsPrivMap = {
@@ -84,7 +85,6 @@ const LangASMap AMDGPUTargetInfo::AMDGPUDefIsPrivMap = {
8485
llvm::AMDGPUAS::FLAT_ADDRESS, // ptr64
8586
llvm::AMDGPUAS::FLAT_ADDRESS, // hlsl_groupshared
8687
llvm::AMDGPUAS::FLAT_ADDRESS, // hlsl_constant
87-
8888
};
8989
} // namespace targets
9090
} // namespace clang

clang/lib/CodeGen/CGHLSLRuntime.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ void CGHLSLRuntime::addConstant(VarDecl *D, Buffer &CB) {
128128
}
129129

130130
auto *GV = cast<GlobalVariable>(CGM.GetAddrOfGlobalVar(D));
131+
GV->setExternallyInitialized(true);
131132
// Add debug info for constVal.
132133
if (CGDebugInfo *DI = CGM.getModuleDebugInfo())
133134
if (CGM.getCodeGenOpts().getDebugInfo() >=
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// RUN: %clang_cc1 -Wdocumentation -ast-dump=json -x hlsl -triple dxil-pc-shadermodel6.3-library %s | FileCheck %s --check-prefix=JSON
2+
// RUN: %clang_cc1 -Wdocumentation -ast-dump -x hlsl -triple dxil-pc-shadermodel6.3-library %s | FileCheck %s --check-prefix=AST
3+
4+
// JSON:"kind": "HLSLBufferDecl",
5+
// JSON:"name": "A",
6+
// JSON-NEXT:"bufferKind": "cbuffer",
7+
// JSON:"kind": "TextComment",
8+
// JSON:"text": " CBuffer decl."
9+
10+
/// CBuffer decl.
11+
cbuffer A {
12+
// JSON: "kind": "VarDecl",
13+
// JSON: "name": "a",
14+
// JSON: "qualType": "hlsl_constant float"
15+
float a;
16+
// JSON: "kind": "VarDecl",
17+
// JSON: "name": "b",
18+
// JSON: "qualType": "hlsl_constant int"
19+
int b;
20+
}
21+
22+
// AST: HLSLBufferDecl {{.*}} line:11:9 cbuffer A
23+
// AST-NEXT: HLSLResourceClassAttr {{.*}} Implicit CBuffer
24+
// AST-NEXT: HLSLResourceAttr {{.*}} Implicit CBuffer
25+
// AST-NEXT: FullComment
26+
// AST-NEXT: ParagraphComment
27+
// AST-NEXT: TextComment {{.*}} Text=" CBuffer decl."
28+
// AST-NEXT: VarDecl {{.*}} a 'hlsl_constant float'
29+
// AST-NEXT: VarDecl {{.*}} b 'hlsl_constant int'
30+
// AST-NEXT: CXXRecordDecl {{.*}} implicit class __layout.A definition
31+
// AST: FieldDecl {{.*}} a 'float'
32+
// AST-NEXT: FieldDecl {{.*}} b 'int'

clang/test/CodeGenHLSL/cbuf.hlsl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
2-
// RUN: dxil-pc-shadermodel6.3-library %s \
1+
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.3-library %s \
32
// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s
43

5-
// CHECK: @a = external addrspace(2) global float, align 4
6-
// CHECK: @b = external addrspace(2) global double, align 8
7-
// CHECK: @c = external addrspace(2) global float, align 4
8-
// CHECK: @d = external addrspace(2) global double, align 8
4+
// RUN: %clang_cc1 -finclude-default-header -triple spirv-pc-vulkan-library %s \
5+
// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s
6+
7+
// CHECK: @a = external addrspace(2) externally_initialized global float, align 4
8+
// CHECK: @b = external addrspace(2) externally_initialized global double, align 8
9+
// CHECK: @c = external addrspace(2) externally_initialized global float, align 4
10+
// CHECK: @d = external addrspace(2) externally_initialized global double, align 8
911

1012
// CHECK: @[[CB:.+]] = external constant { float, double }
1113
cbuffer A : register(b0, space2) {

clang/test/CodeGenHLSL/cbuf_in_namespace.hlsl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
2-
// RUN: dxil-pc-shadermodel6.3-library %s \
1+
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.3-library %s \
2+
// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s
3+
4+
// RUN: %clang_cc1 -finclude-default-header -triple spirv-pc-vulkan-library %s \
35
// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s
46

57
// Make sure cbuffer inside namespace works.
68

7-
// CHECK: @_ZN2n02n11aE = external addrspace(2) global float, align 4
8-
// CHECK: @_ZN2n01bE = external addrspace(2) global float, align 4
9+
// CHECK: @_ZN2n02n11aE = external addrspace(2) externally_initialized global float, align 4
10+
// CHECK: @_ZN2n01bE = external addrspace(2) externally_initialized global float, align 4
911

1012
// CHECK: @[[CB:.+]] = external constant { float }
1113
// CHECK: @[[TB:.+]] = external constant { float }

clang/test/CodeGenHLSL/static_global_and_function_in_cb.hlsl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.3-library %s \
22
// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s
33

4+
// RUN: %clang_cc1 -finclude-default-header -triple spirv-pc-vulkan-library %s \
5+
// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s
6+
47
cbuffer A {
5-
// CHECK: @a = external addrspace(2) global float, align 4
8+
// CHECK: @a = external addrspace(2) externally_initialized global float, align 4
69
float a;
710
// CHECK: @_ZL1b = internal global float 3.000000e+00, align 4
811
static float b = 3;

clang/test/SemaTemplate/address_space-dependent.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void neg() {
4343

4444
template <long int I>
4545
void tooBig() {
46-
__attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388586)}}
46+
__attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388585)}}
4747
}
4848

4949
template <long int I>

0 commit comments

Comments
 (0)