Skip to content

Commit 80ee245

Browse files
committed
review: remove redundant Index to Element mapping
1 parent 9436edf commit 80ee245

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,9 +1107,8 @@ bool SemaHLSL::handleRootSignatureElements(
11071107
using ResourceRange = llvm::hlsl::rootsig::ResourceRange;
11081108
using GroupT = std::pair<ResourceClass, /*Space*/ uint32_t>;
11091109

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

11151114
// 1. Collect RangeInfos
@@ -1127,8 +1126,7 @@ bool SemaHLSL::handleRootSignatureElements(
11271126
Info.Space = Descriptor->Space;
11281127
Info.Visibility = Descriptor->Visibility;
11291128

1130-
Info.Index = InfoIndex++;
1131-
InfoIndexMap[Info.Index] = &RootSigElem;
1129+
Info.Index = InfoIndex;
11321130
Infos.push_back(Info);
11331131
} else if (const auto *Constants =
11341132
std::get_if<llvm::hlsl::rootsig::RootConstants>(&Elem)) {
@@ -1140,8 +1138,7 @@ bool SemaHLSL::handleRootSignatureElements(
11401138
Info.Space = Constants->Space;
11411139
Info.Visibility = Constants->Visibility;
11421140

1143-
Info.Index = InfoIndex++;
1144-
InfoIndexMap[Info.Index] = &RootSigElem;
1141+
Info.Index = InfoIndex;
11451142
Infos.push_back(Info);
11461143
} else if (const auto *Sampler =
11471144
std::get_if<llvm::hlsl::rootsig::StaticSampler>(&Elem)) {
@@ -1153,8 +1150,7 @@ bool SemaHLSL::handleRootSignatureElements(
11531150
Info.Space = Sampler->Space;
11541151
Info.Visibility = Sampler->Visibility;
11551152

1156-
Info.Index = InfoIndex++;
1157-
InfoIndexMap[Info.Index] = &RootSigElem;
1153+
Info.Index = InfoIndex;
11581154
Infos.push_back(Info);
11591155
} else if (const auto *Clause =
11601156
std::get_if<llvm::hlsl::rootsig::DescriptorTableClause>(
@@ -1171,8 +1167,7 @@ bool SemaHLSL::handleRootSignatureElements(
11711167
Info.Space = Clause->Space;
11721168

11731169
// Note: Clause does not hold the visibility this will need to
1174-
Info.Index = InfoIndex++;
1175-
InfoIndexMap[Info.Index] = &RootSigElem;
1170+
Info.Index = InfoIndex;
11761171
Infos.push_back(Info);
11771172
} else if (const auto *Table =
11781173
std::get_if<llvm::hlsl::rootsig::DescriptorTable>(&Elem)) {
@@ -1186,6 +1181,8 @@ bool SemaHLSL::handleRootSignatureElements(
11861181
for (RangeInfo &Info : TableInfos)
11871182
Info.Visibility = Table->Visibility;
11881183
}
1184+
1185+
InfoIndex++;
11891186
}
11901187

11911188
// 2. Sort the RangeInfo's by their GroupT to form groupings
@@ -1219,14 +1216,13 @@ bool SemaHLSL::handleRootSignatureElements(
12191216
};
12201217

12211218
// Helper to report diagnostics
1222-
auto ReportOverlap = [this, InfoIndexMap, &HadOverlap](
1223-
const RangeInfo *Info, const RangeInfo *OInfo) {
1219+
auto ReportOverlap = [this, &Elements, &HadOverlap](const RangeInfo *Info,
1220+
const RangeInfo *OInfo) {
12241221
HadOverlap = true;
12251222
auto CommonVis = Info->Visibility == llvm::dxbc::ShaderVisibility::All
12261223
? OInfo->Visibility
12271224
: Info->Visibility;
1228-
const hlsl::RootSignatureElement *Elem = InfoIndexMap.at(Info->Index);
1229-
SourceLocation InfoLoc = Elem->getLocation();
1225+
SourceLocation InfoLoc = Elements[Info->Index].getLocation();
12301226
this->Diag(InfoLoc, diag::err_hlsl_resource_range_overlap)
12311227
<< llvm::to_underlying(Info->Class) << Info->LowerBound
12321228
<< /*unbounded=*/(Info->UpperBound == RangeInfo::Unbounded)
@@ -1235,8 +1231,7 @@ bool SemaHLSL::handleRootSignatureElements(
12351231
<< /*unbounded=*/(OInfo->UpperBound == RangeInfo::Unbounded)
12361232
<< OInfo->UpperBound << Info->Space << CommonVis;
12371233

1238-
const hlsl::RootSignatureElement *OElem = InfoIndexMap.at(OInfo->Index);
1239-
SourceLocation OInfoLoc = OElem->getLocation();
1234+
SourceLocation OInfoLoc = Elements[OInfo->Index].getLocation();
12401235
this->Diag(OInfoLoc, diag::note_hlsl_resource_range_here);
12411236
};
12421237

0 commit comments

Comments
 (0)