Skip to content

Commit 548df7d

Browse files
committed
rework gatherglobalswithinitializers to create separate subobj list
1 parent e38d869 commit 548df7d

1 file changed

Lines changed: 27 additions & 23 deletions

File tree

tools/clang/lib/Sema/SemaHLSLDiagnoseTU.cpp

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,8 @@ std::vector<FunctionDecl *> GetAllExportedFDecls(clang::Sema *self) {
301301
}
302302

303303
void GatherGlobalsWithInitializers(
304-
DeclContext *DC, llvm::SmallVectorImpl<VarDecl *> &GlobalsWithInit) {
304+
DeclContext *DC, llvm::SmallVectorImpl<VarDecl *> &GlobalsWithInit,
305+
llvm::SmallVectorImpl<VarDecl *> &SubObjects) {
305306
for (auto *D : DC->decls()) {
306307
// Skip built-ins and function decls.
307308
if (D->isImplicit() || isa<FunctionDecl>(D))
@@ -310,11 +311,19 @@ void GatherGlobalsWithInitializers(
310311
// Add if user-defined static or groupshared global with initializer.
311312
if (VD->hasInit() && VD->hasGlobalStorage() &&
312313
(VD->getStorageClass() == SC_Static ||
313-
VD->hasAttr<HLSLGroupSharedAttr>()))
314-
GlobalsWithInit.push_back(VD);
314+
VD->hasAttr<HLSLGroupSharedAttr>())) {
315+
// Place subobjects in a separate collection.
316+
QualType QT = VD->getType();
317+
if (const RecordType *RT = QT->getAs<RecordType>()) {
318+
RecordDecl *RD = RT->getDecl();
319+
if (RD->hasAttr<HLSLSubObjectAttr>())
320+
SubObjects.push_back(VD);
321+
} else
322+
GlobalsWithInit.push_back(VD);
323+
}
315324
} else if (auto *DC = dyn_cast<DeclContext>(D)) {
316325
// Recurse into DeclContexts like namespace, cbuffer, class/struct, etc.
317-
GatherGlobalsWithInitializers(DC, GlobalsWithInit);
326+
GatherGlobalsWithInitializers(DC, GlobalsWithInit, SubObjects);
318327
}
319328
}
320329
}
@@ -592,14 +601,25 @@ void hlsl::DiagnoseTranslationUnit(clang::Sema *self) {
592601
hlsl::ShaderModel::GetByName(self->getLangOpts().HLSLProfile.c_str());
593602

594603
llvm::SmallVector<VarDecl *, 16> GlobalsWithInit;
595-
GatherGlobalsWithInitializers(self->getASTContext().getTranslationUnitDecl(),
596-
GlobalsWithInit);
597-
604+
llvm::SmallVector<VarDecl *, 16> SubObjects;
598605
std::set<FunctionDecl *> DiagnosedRecursiveDecls;
599606
llvm::SmallPtrSet<CallExpr *, 16> DiagnosedCalls;
600607
llvm::SmallPtrSet<DeclRefExpr *, 16> DeclAvailabilityChecked;
601608
llvm::SmallSet<SourceLocation, 16> DiagnosedTypeLocs;
602609

610+
GatherGlobalsWithInitializers(self->getASTContext().getTranslationUnitDecl(),
611+
GlobalsWithInit, SubObjects);
612+
613+
if (shaderModel->GetKind() == DXIL::ShaderKind::Library) {
614+
for (VarDecl *VD : SubObjects) {
615+
DXIL::NodeLaunchType NodeLaunchTy = DXIL::NodeLaunchType::Invalid;
616+
HLSLReachableDiagnoseVisitor Visitor(
617+
self, shaderModel, shaderModel->GetKind(), NodeLaunchTy, nullptr,
618+
DiagnosedCalls, DeclAvailabilityChecked, DiagnosedTypeLocs);
619+
Visitor.TraverseDecl(VD);
620+
}
621+
}
622+
603623
// for each FDecl, check for recursion
604624
for (FunctionDecl *FDecl : FDeclsToCheck) {
605625
CallGraphWithRecurseGuard callGraph;
@@ -732,20 +752,4 @@ void hlsl::DiagnoseTranslationUnit(clang::Sema *self) {
732752
for (FunctionDecl *FD : callGraph.GetVisitedFunctions())
733753
Visitor.TraverseDecl(FD);
734754
}
735-
736-
if (shaderModel->GetKind() == DXIL::ShaderKind::Library) {
737-
for (VarDecl *VD : GlobalsWithInit) {
738-
DXIL::NodeLaunchType NodeLaunchTy = DXIL::NodeLaunchType::Invalid;
739-
HLSLReachableDiagnoseVisitor Visitor(
740-
self, shaderModel, shaderModel->GetKind(), NodeLaunchTy, nullptr,
741-
DiagnosedCalls, DeclAvailabilityChecked, DiagnosedTypeLocs);
742-
QualType QT = VD->getType();
743-
if (const RecordType *RT = QT->getAs<RecordType>()) {
744-
RecordDecl *RD = RT->getDecl();
745-
if (!RD->hasAttr<HLSLSubObjectAttr>())
746-
continue;
747-
Visitor.TraverseDecl(VD);
748-
}
749-
}
750-
}
751755
}

0 commit comments

Comments
 (0)