Skip to content

Commit b95c89a

Browse files
committed
remove the need for ActiveInputSemantics attribute
Each function is independent, no need to keep this across calls.
1 parent b18199f commit b95c89a

File tree

2 files changed

+18
-21
lines changed

2 files changed

+18
-21
lines changed

clang/include/clang/Sema/SemaHLSL.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,6 @@ class SemaHLSL : public SemaBase {
246246

247247
IdentifierInfo *RootSigOverrideIdent = nullptr;
248248

249-
llvm::DenseMap<FunctionDecl *, llvm::StringSet<>> ActiveInputSemantics;
250-
251249
struct SemanticInfo {
252250
HLSLSemanticAttr *Semantic;
253251
std::optional<uint32_t> Index;
@@ -263,9 +261,11 @@ class SemaHLSL : public SemaBase {
263261
HLSLSemanticAttr *createSemantic(const SemanticInfo &Semantic,
264262
DeclaratorDecl *TargetDecl);
265263
bool determineActiveSemanticOnScalar(FunctionDecl *FD, DeclaratorDecl *D,
266-
SemanticInfo &ActiveSemantic);
264+
SemanticInfo &ActiveSemantic,
265+
llvm::StringSet<> &ActiveInputSemantics);
267266
bool determineActiveSemantic(FunctionDecl *FD, DeclaratorDecl *D,
268-
SemanticInfo &ActiveSemantic);
267+
SemanticInfo &ActiveSemantic,
268+
llvm::StringSet<> &ActiveInputSemantics);
269269

270270
void processExplicitBindingsOnDecl(VarDecl *D);
271271

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -801,9 +801,10 @@ HLSLSemanticAttr *SemaHLSL::createSemantic(const SemanticInfo &Info,
801801
return nullptr;
802802
}
803803

804-
bool SemaHLSL::determineActiveSemanticOnScalar(FunctionDecl *FD,
805-
DeclaratorDecl *D,
806-
SemanticInfo &ActiveSemantic) {
804+
bool SemaHLSL::determineActiveSemanticOnScalar(
805+
FunctionDecl *FD, DeclaratorDecl *D, SemanticInfo &ActiveSemantic,
806+
llvm::StringSet<> &ActiveInputSemantics) {
807+
807808
if (ActiveSemantic.Semantic == nullptr) {
808809
ActiveSemantic.Semantic = D->getAttr<HLSLSemanticAttr>();
809810
if (ActiveSemantic.Semantic &&
@@ -833,15 +834,7 @@ bool SemaHLSL::determineActiveSemanticOnScalar(FunctionDecl *FD,
833834
for (unsigned I = 0; I < ElementCount; ++I) {
834835
Twine VariableName = BaseName.concat(Twine(Location + I));
835836

836-
auto It = ActiveInputSemantics.find(FD);
837-
if (It == ActiveInputSemantics.end()) {
838-
llvm::StringSet<> Set({VariableName.str()});
839-
auto Item = std::make_pair(FD, std::move(Set));
840-
ActiveInputSemantics.insert(std::move(Item));
841-
continue;
842-
}
843-
844-
auto [_, Inserted] = ActiveInputSemantics[FD].insert(VariableName.str());
837+
auto [_, Inserted] = ActiveInputSemantics.insert(VariableName.str());
845838
if (!Inserted) {
846839
Diag(D->getLocation(), diag::err_hlsl_semantic_index_overlap)
847840
<< VariableName.str();
@@ -852,8 +845,9 @@ bool SemaHLSL::determineActiveSemanticOnScalar(FunctionDecl *FD,
852845
return true;
853846
}
854847

855-
bool SemaHLSL::determineActiveSemantic(FunctionDecl *FD, DeclaratorDecl *D,
856-
SemanticInfo &ActiveSemantic) {
848+
bool SemaHLSL::determineActiveSemantic(
849+
FunctionDecl *FD, DeclaratorDecl *D, SemanticInfo &ActiveSemantic,
850+
llvm::StringSet<> &ActiveInputSemantics) {
857851
if (ActiveSemantic.Semantic == nullptr) {
858852
ActiveSemantic.Semantic = D->getAttr<HLSLSemanticAttr>();
859853
if (ActiveSemantic.Semantic &&
@@ -864,12 +858,13 @@ bool SemaHLSL::determineActiveSemantic(FunctionDecl *FD, DeclaratorDecl *D,
864858
const Type *T = D->getType()->getUnqualifiedDesugaredType();
865859
const RecordType *RT = dyn_cast<RecordType>(T);
866860
if (!RT)
867-
return determineActiveSemanticOnScalar(FD, D, ActiveSemantic);
861+
return determineActiveSemanticOnScalar(FD, D, ActiveSemantic,
862+
ActiveInputSemantics);
868863

869864
const RecordDecl *RD = RT->getDecl();
870865
for (FieldDecl *Field : RD->fields()) {
871866
SemanticInfo Info = ActiveSemantic;
872-
if (!determineActiveSemantic(FD, Field, Info)) {
867+
if (!determineActiveSemantic(FD, Field, Info, ActiveInputSemantics)) {
873868
Diag(Field->getLocation(), diag::note_hlsl_semantic_used_here) << Field;
874869
return false;
875870
}
@@ -942,12 +937,14 @@ void SemaHLSL::CheckEntryPoint(FunctionDecl *FD) {
942937
llvm_unreachable("Unhandled environment in triple");
943938
}
944939

940+
llvm::StringSet<> ActiveInputSemantics;
945941
for (ParmVarDecl *Param : FD->parameters()) {
946942
SemanticInfo ActiveSemantic;
947943
ActiveSemantic.Semantic = nullptr;
948944
ActiveSemantic.Index = std::nullopt;
949945

950-
if (!determineActiveSemantic(FD, Param, ActiveSemantic)) {
946+
if (!determineActiveSemantic(FD, Param, ActiveSemantic,
947+
ActiveInputSemantics)) {
951948
Diag(Param->getLocation(), diag::note_previous_decl) << Param;
952949
FD->setInvalidDecl();
953950
}

0 commit comments

Comments
 (0)