Skip to content

Commit 6c39d06

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

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
@@ -800,9 +800,10 @@ HLSLSemanticAttr *SemaHLSL::createSemantic(const SemanticInfo &Info,
800800
return nullptr;
801801
}
802802

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

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

854-
bool SemaHLSL::determineActiveSemantic(FunctionDecl *FD, DeclaratorDecl *D,
855-
SemanticInfo &ActiveSemantic) {
847+
bool SemaHLSL::determineActiveSemantic(
848+
FunctionDecl *FD, DeclaratorDecl *D, SemanticInfo &ActiveSemantic,
849+
llvm::StringSet<> &ActiveInputSemantics) {
856850
if (ActiveSemantic.Semantic == nullptr) {
857851
ActiveSemantic.Semantic = D->getAttr<HLSLSemanticAttr>();
858852
if (ActiveSemantic.Semantic &&
@@ -863,12 +857,13 @@ bool SemaHLSL::determineActiveSemantic(FunctionDecl *FD, DeclaratorDecl *D,
863857
const Type *T = D->getType()->getUnqualifiedDesugaredType();
864858
const RecordType *RT = dyn_cast<RecordType>(T);
865859
if (!RT)
866-
return determineActiveSemanticOnScalar(FD, D, ActiveSemantic);
860+
return determineActiveSemanticOnScalar(FD, D, ActiveSemantic,
861+
ActiveInputSemantics);
867862

868863
const RecordDecl *RD = RT->getDecl();
869864
for (FieldDecl *Field : RD->fields()) {
870865
SemanticInfo Info = ActiveSemantic;
871-
if (!determineActiveSemantic(FD, Field, Info)) {
866+
if (!determineActiveSemantic(FD, Field, Info, ActiveInputSemantics)) {
872867
Diag(Field->getLocation(), diag::note_hlsl_semantic_used_here) << Field;
873868
return false;
874869
}
@@ -941,12 +936,14 @@ void SemaHLSL::CheckEntryPoint(FunctionDecl *FD) {
941936
llvm_unreachable("Unhandled environment in triple");
942937
}
943938

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

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

0 commit comments

Comments
 (0)