Skip to content

Commit 6ec1e90

Browse files
committed
review: remove redundant Index to Element mapping
1 parent 25a2948 commit 6ec1e90

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,9 +1086,8 @@ bool SemaHLSL::handleRootSignatureElements(
10861086
using RangeInfo = llvm::hlsl::rootsig::RangeInfo;
10871087
using OverlappingRanges = llvm::hlsl::rootsig::OverlappingRanges;
10881088

1089-
// Introduce a mapping from the collected RangeInfos back to the
1090-
// RootSignatureElement that will retain its diagnostics info
1091-
llvm::DenseMap<size_t, const hlsl::RootSignatureElement *> InfoIndexMap;
1089+
// Each RangeInfo will contain an index back to its associated
1090+
// RootSignatureElement in our Elements ArrayRef
10921091
size_t InfoIndex = 0;
10931092

10941093
// 1. Collect RangeInfos
@@ -1106,8 +1105,7 @@ bool SemaHLSL::handleRootSignatureElements(
11061105
Info.Space = Descriptor->Space;
11071106
Info.Visibility = Descriptor->Visibility;
11081107

1109-
Info.Index = InfoIndex++;
1110-
InfoIndexMap[Info.Index] = &RootSigElem;
1108+
Info.Index = InfoIndex;
11111109
Infos.push_back(Info);
11121110
} else if (const auto *Constants =
11131111
std::get_if<llvm::hlsl::rootsig::RootConstants>(&Elem)) {
@@ -1119,8 +1117,7 @@ bool SemaHLSL::handleRootSignatureElements(
11191117
Info.Space = Constants->Space;
11201118
Info.Visibility = Constants->Visibility;
11211119

1122-
Info.Index = InfoIndex++;
1123-
InfoIndexMap[Info.Index] = &RootSigElem;
1120+
Info.Index = InfoIndex;
11241121
Infos.push_back(Info);
11251122
} else if (const auto *Sampler =
11261123
std::get_if<llvm::hlsl::rootsig::StaticSampler>(&Elem)) {
@@ -1132,8 +1129,7 @@ bool SemaHLSL::handleRootSignatureElements(
11321129
Info.Space = Sampler->Space;
11331130
Info.Visibility = Sampler->Visibility;
11341131

1135-
Info.Index = InfoIndex++;
1136-
InfoIndexMap[Info.Index] = &RootSigElem;
1132+
Info.Index = InfoIndex;
11371133
Infos.push_back(Info);
11381134
} else if (const auto *Clause =
11391135
std::get_if<llvm::hlsl::rootsig::DescriptorTableClause>(
@@ -1150,8 +1146,7 @@ bool SemaHLSL::handleRootSignatureElements(
11501146
Info.Space = Clause->Space;
11511147

11521148
// Note: Clause does not hold the visibility this will need to
1153-
Info.Index = InfoIndex++;
1154-
InfoIndexMap[Info.Index] = &RootSigElem;
1149+
Info.Index = InfoIndex;
11551150
Infos.push_back(Info);
11561151
} else if (const auto *Table =
11571152
std::get_if<llvm::hlsl::rootsig::DescriptorTable>(&Elem)) {
@@ -1165,17 +1160,18 @@ bool SemaHLSL::handleRootSignatureElements(
11651160
for (RangeInfo &Info : TableInfos)
11661161
Info.Visibility = Table->Visibility;
11671162
}
1163+
1164+
InfoIndex++;
11681165
}
11691166

11701167
// Helper to report diagnostics
1171-
auto ReportOverlap = [this, &InfoIndexMap](OverlappingRanges Overlap) {
1168+
auto ReportOverlap = [this, &Elements](OverlappingRanges Overlap) {
11721169
const RangeInfo *Info = Overlap.A;
11731170
const RangeInfo *OInfo = Overlap.B;
11741171
auto CommonVis = Info->Visibility == llvm::dxbc::ShaderVisibility::All
11751172
? OInfo->Visibility
11761173
: Info->Visibility;
1177-
const hlsl::RootSignatureElement *Elem = InfoIndexMap.at(Info->Index);
1178-
SourceLocation InfoLoc = Elem->getLocation();
1174+
SourceLocation InfoLoc = Elements[Info->Index].getLocation();
11791175
this->Diag(InfoLoc, diag::err_hlsl_resource_range_overlap)
11801176
<< llvm::to_underlying(Info->Class) << Info->LowerBound
11811177
<< /*unbounded=*/(Info->UpperBound == RangeInfo::Unbounded)
@@ -1184,8 +1180,7 @@ bool SemaHLSL::handleRootSignatureElements(
11841180
<< /*unbounded=*/(OInfo->UpperBound == RangeInfo::Unbounded)
11851181
<< OInfo->UpperBound << Info->Space << CommonVis;
11861182

1187-
const hlsl::RootSignatureElement *OElem = InfoIndexMap.at(OInfo->Index);
1188-
SourceLocation OInfoLoc = OElem->getLocation();
1183+
SourceLocation OInfoLoc = Elements[OInfo->Index].getLocation();
11891184
this->Diag(OInfoLoc, diag::note_hlsl_resource_range_here);
11901185
};
11911186

0 commit comments

Comments
 (0)