Skip to content

Commit 9991904

Browse files
committed
pr-feedback
1 parent 75d9db5 commit 9991904

File tree

6 files changed

+55
-58
lines changed

6 files changed

+55
-58
lines changed

clang/include/clang/Sema/SemaHLSL.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ class SemaHLSL : public SemaBase {
154154
bool TransformInitList(const InitializedEntity &Entity,
155155
const InitializationKind &Kind, InitListExpr *Init);
156156

157+
void deduceAddressSpace(VarDecl *Decl);
158+
157159
private:
158160
// HLSL resource type attributes need to be processed all at once.
159161
// This is a list to collect them.

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,12 @@ void CodeGenFunction::FinishFunction(SourceLocation EndLoc) {
371371
assert(DeferredDeactivationCleanupStack.empty() &&
372372
"mismatched activate/deactivate of cleanups!");
373373

374+
if (CGM.shouldEmitConvergenceTokens()) {
375+
ConvergenceTokenStack.pop_back();
376+
assert(ConvergenceTokenStack.empty() &&
377+
"mismatched push/pop in convergence stack!");
378+
}
379+
374380
bool OnlySimpleReturnStmts = NumSimpleReturnExprs > 0
375381
&& NumSimpleReturnExprs == NumReturnExprs
376382
&& ReturnBlock.getBlock()->use_empty();
@@ -558,12 +564,6 @@ void CodeGenFunction::FinishFunction(SourceLocation EndLoc) {
558564
ReturnValue = Address::invalid();
559565
}
560566
}
561-
562-
if (CGM.shouldEmitConvergenceTokens()) {
563-
ConvergenceTokenStack.pop_back();
564-
assert(ConvergenceTokenStack.empty() &&
565-
"mismatched push/pop in convergence stack!");
566-
}
567567
}
568568

569569
/// ShouldInstrumentFunction - Return true if the current function should be

clang/lib/Sema/SemaDecl.cpp

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6888,42 +6888,6 @@ static void SetNestedNameSpecifier(Sema &S, DeclaratorDecl *DD, Declarator &D) {
68886888
DD->setQualifierInfo(SS.getWithLocInContext(S.Context));
68896889
}
68906890

6891-
void Sema::deduceHLSLAddressSpace(VarDecl *Decl) {
6892-
// The variable already has an address space (groupshared for ex).
6893-
if (Decl->getType().hasAddressSpace())
6894-
return;
6895-
6896-
if (Decl->getType()->isDependentType())
6897-
return;
6898-
6899-
QualType Type = Decl->getType();
6900-
if (Type->isSamplerT() || Type->isVoidType())
6901-
return;
6902-
6903-
// Template instantiations can lack definition. In such case,
6904-
// we cannot deduce the AS.
6905-
// FIXME: figure out why RWBuffer<float> yields such declaration.
6906-
if (const RecordType *RT =
6907-
dyn_cast<RecordType>(Type->getUnqualifiedDesugaredType())) {
6908-
CXXRecordDecl *RD = Type->getAsCXXRecordDecl();
6909-
if (RD && !RD->isCompleteDefinition())
6910-
return;
6911-
}
6912-
6913-
// Resource handles.
6914-
if (Type->isHLSLIntangibleType())
6915-
return;
6916-
6917-
// Only static globals belong to the Private address space.
6918-
// Non-static globals belongs to the cbuffer.
6919-
if (Decl->getStorageClass() != SC_Static && !Decl->isStaticDataMember())
6920-
return;
6921-
6922-
LangAS ImplAS = LangAS::hlsl_private;
6923-
Type = Context.getAddrSpaceQualType(Type, ImplAS);
6924-
Decl->setType(Type);
6925-
}
6926-
69276891
void Sema::deduceOpenCLAddressSpace(ValueDecl *Decl) {
69286892
if (Decl->getType().hasAddressSpace())
69296893
return;
@@ -8011,10 +7975,8 @@ NamedDecl *Sema::ActOnVariableDeclarator(
80117975
// Handle attributes prior to checking for duplicates in MergeVarDecl
80127976
ProcessDeclAttributes(S, NewVD, D);
80137977

8014-
if (getLangOpts().HLSL) {
7978+
if (getLangOpts().HLSL)
80157979
HLSL().ActOnVariableDeclarator(NewVD);
8016-
deduceHLSLAddressSpace(NewVD);
8017-
}
80187980

80197981
if (getLangOpts().OpenACC)
80207982
OpenACC().ActOnVariableDeclarator(NewVD);
@@ -13171,7 +13133,7 @@ bool Sema::DeduceVariableDeclarationType(VarDecl *VDecl, bool DirectInit,
1317113133
deduceOpenCLAddressSpace(VDecl);
1317213134

1317313135
if (getLangOpts().HLSL)
13174-
deduceHLSLAddressSpace(VDecl);
13136+
HLSL().deduceAddressSpace(VDecl);
1317513137

1317613138
// If this is a redeclaration, check that the type we just deduced matches
1317713139
// the previously declared type.

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3138,6 +3138,43 @@ static bool IsDefaultBufferConstantDecl(VarDecl *VD) {
31383138
!isInvalidConstantBufferLeafElementType(QT.getTypePtr());
31393139
}
31403140

3141+
void SemaHLSL::deduceAddressSpace(VarDecl *Decl) {
3142+
// The variable already has an address space (groupshared for ex).
3143+
if (Decl->getType().hasAddressSpace())
3144+
return;
3145+
3146+
if (Decl->getType()->isDependentType())
3147+
return;
3148+
3149+
QualType Type = Decl->getType();
3150+
if (Type->isSamplerT() || Type->isVoidType())
3151+
return;
3152+
3153+
// Template instantiations can lack definition. In such case,
3154+
// we cannot deduce the AS.
3155+
// FIXME: figure out why RWBuffer<float> yields such declaration.
3156+
if (const RecordType *RT =
3157+
dyn_cast<RecordType>(Type->getUnqualifiedDesugaredType())) {
3158+
CXXRecordDecl *RD = Type->getAsCXXRecordDecl();
3159+
if (RD && !RD->isCompleteDefinition())
3160+
return;
3161+
}
3162+
3163+
// Resource handles.
3164+
if (isResourceRecordTypeOrArrayOf(Type->getUnqualifiedDesugaredType()))
3165+
return;
3166+
3167+
// Only static globals belong to the Private address space.
3168+
// Non-static globals belongs to the cbuffer.
3169+
if (Decl->getStorageClass() != SC_Static && !Decl->isStaticDataMember())
3170+
return;
3171+
3172+
LangAS ImplAS = LangAS::hlsl_private;
3173+
Type = SemaRef.getASTContext().getAddrSpaceQualType(Type, ImplAS);
3174+
Decl->setType(Type);
3175+
}
3176+
3177+
31413178
void SemaHLSL::ActOnVariableDeclarator(VarDecl *VD) {
31423179
if (VD->hasGlobalStorage()) {
31433180
// make sure the declaration has a complete type
@@ -3146,6 +3183,7 @@ void SemaHLSL::ActOnVariableDeclarator(VarDecl *VD) {
31463183
SemaRef.getASTContext().getBaseElementType(VD->getType()),
31473184
diag::err_typecheck_decl_incomplete_type)) {
31483185
VD->setInvalidDecl();
3186+
deduceAddressSpace(VD);
31493187
return;
31503188
}
31513189

@@ -3177,6 +3215,8 @@ void SemaHLSL::ActOnVariableDeclarator(VarDecl *VD) {
31773215
// process explicit bindings
31783216
processExplicitBindingsOnDecl(VD);
31793217
}
3218+
3219+
deduceAddressSpace(VD);
31803220
}
31813221

31823222
// Walks though the global variable declaration, collects all resource binding
Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// RUN: %clang_cc1 -triple spirv-unknown-vulkan1.3-compute -x hlsl -emit-llvm -disable-llvm-passes %s -o - | FileCheck %s --check-prefixes=CHECK,SPIRV
2-
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -x hlsl -emit-llvm -disable-llvm-passes %s -o - | FileCheck %s --check-prefixes=CHECK,DXIL
1+
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -x hlsl -emit-llvm -disable-llvm-passes %s -o - | FileCheck %s
32

43
RWBuffer<float> Buffer;
54

@@ -11,13 +10,7 @@ void main(unsigned GI : SV_GroupIndex) {}
1110
// CHECK-NOT:@llvm.global_dtors
1211
//CHECK: define void @main()
1312
//CHECK-NEXT: entry:
14-
15-
//SPIRV-NEXT: %0 = call token @llvm.experimental.convergence.entry()
16-
//SPIRV-NEXT: call spir_func void @_GLOBAL__sub_I_GlobalConstructors.hlsl() [ "convergencectrl"(token %0) ]
17-
//SPIRV-NEXT: %1 = call i32 @llvm.spv.flattened.thread.id.in.group()
18-
//SPIRV-NEXT: call spir_func void @_Z4mainj(i32 %1) [ "convergencectrl"(token %0) ]
19-
20-
//DXIL-NEXT: call void @_GLOBAL__sub_I_GlobalConstructors.hlsl()
21-
//DXIL-NEXT: %0 = call i32 @llvm.dx.flattened.thread.id.in.group()
22-
//DXIL-NEXT: call void @_Z4mainj(i32 %0)
13+
//CHECK-NEXT: call void @_GLOBAL__sub_I_GlobalConstructors.hlsl()
14+
//CHECK-NEXT: %0 = call i32 @llvm.dx.flattened.thread.id.in.group()
15+
//CHECK-NEXT: call void @_Z4mainj(i32 %0)
2316
//CHECK-NEXT: ret void

clang/test/CodeGenHLSL/GlobalDestructors.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ void main(unsigned GI : SV_GroupIndex) {
8787
// NOINLINE-SPIRV: define internal spir_func void @_GLOBAL__D_a() [[IntAttr:\#[0-9]+]]
8888
// NOINLINE-SPIRV-NEXT: entry:
8989
// NOINLINE-SPIRV-NEXT: %0 = call token @llvm.experimental.convergence.entry()
90-
// NOINLINE-SPIRV-NEXT: call spir_func void @_ZN4TailD1Ev(ptr @_ZZ3WagvE1T) [ "convergencectrl"(token %0) ]
90+
// NOINLINE-SPIRV-NEXT: call spir_func void @_ZN4TailD1Ev(ptr addrspacecast (ptr addrspace(10) @_ZZ3WagvE1T to ptr)) [ "convergencectrl"(token %0) ]
9191
// NOINLINE-SPIRV-NEXT: call spir_func void @_ZN6PupperD1Ev(ptr @GlobalPup) [ "convergencectrl"(token %0) ]
9292
// NOINLINE-SPIRV-NEXT: ret void
9393

0 commit comments

Comments
 (0)