Skip to content

Commit f8f9d09

Browse files
committed
fixup: Store ResourceBindingInfo directly rather than a smaller type
1 parent 305a0f5 commit f8f9d09

File tree

5 files changed

+28
-56
lines changed

5 files changed

+28
-56
lines changed

llvm/include/llvm/Analysis/DXILResource.h

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,9 @@ class ResourceTypeInfo {
293293
dxil::ResourceClass getResourceClass() const { return RC; }
294294
dxil::ResourceKind getResourceKind() const { return Kind; }
295295

296+
void setGloballyCoherent(bool V) { GloballyCoherent = V; }
297+
void setHasCounter(bool V) { HasCounter = V; }
298+
296299
bool operator==(const ResourceTypeInfo &RHS) const;
297300
bool operator!=(const ResourceTypeInfo &RHS) const { return !(*this == RHS); }
298301
bool operator<(const ResourceTypeInfo &RHS) const;
@@ -341,13 +344,10 @@ class ResourceBindingInfo {
341344
return "";
342345
}
343346

344-
MDTuple *getAsMetadata(Module &M, DXILResourceTypeMap &DRTM) const;
345-
MDTuple *getAsMetadata(Module &M, dxil::ResourceTypeInfo RTI) const;
347+
MDTuple *getAsMetadata(Module &M, dxil::ResourceTypeInfo &RTI) const;
346348

347349
std::pair<uint32_t, uint32_t>
348-
getAnnotateProps(Module &M, DXILResourceTypeMap &DRTM) const;
349-
std::pair<uint32_t, uint32_t>
350-
getAnnotateProps(Module &M, dxil::ResourceTypeInfo RTI) const;
350+
getAnnotateProps(Module &M, dxil::ResourceTypeInfo &RTI) const;
351351

352352
bool operator==(const ResourceBindingInfo &RHS) const {
353353
return std::tie(Binding, HandleTy) == std::tie(RHS.Binding, RHS.HandleTy);
@@ -359,9 +359,7 @@ class ResourceBindingInfo {
359359
return Binding < RHS.Binding;
360360
}
361361

362-
void print(raw_ostream &OS, DXILResourceTypeMap &DRTM,
363-
const DataLayout &DL) const;
364-
void print(raw_ostream &OS, dxil::ResourceTypeInfo RTI,
362+
void print(raw_ostream &OS, dxil::ResourceTypeInfo &RTI,
365363
const DataLayout &DL) const;
366364
};
367365

@@ -370,30 +368,18 @@ class ResourceBindingInfo {
370368
//===----------------------------------------------------------------------===//
371369

372370
class DXILResourceTypeMap {
373-
struct Info {
374-
dxil::ResourceClass RC;
375-
dxil::ResourceKind Kind;
376-
bool GloballyCoherent;
377-
bool HasCounter;
378-
};
379-
DenseMap<TargetExtType *, Info> Infos;
371+
DenseMap<TargetExtType *, dxil::ResourceTypeInfo> Infos;
380372

381373
public:
382374
bool invalidate(Module &M, const PreservedAnalyses &PA,
383375
ModuleAnalysisManager::Invalidator &Inv);
384376

385-
dxil::ResourceTypeInfo operator[](TargetExtType *Ty) {
386-
Info I = Infos[Ty];
387-
return dxil::ResourceTypeInfo(Ty, I.RC, I.Kind, I.GloballyCoherent,
388-
I.HasCounter);
389-
}
390-
391-
void setGloballyCoherent(TargetExtType *Ty, bool GloballyCoherent) {
392-
Infos[Ty].GloballyCoherent = GloballyCoherent;
393-
}
394-
395-
void setHasCounter(TargetExtType *Ty, bool HasCounter) {
396-
Infos[Ty].HasCounter = HasCounter;
377+
dxil::ResourceTypeInfo &operator[](TargetExtType *Ty) {
378+
auto It = Infos.find(Ty);
379+
if (It != Infos.end())
380+
return It->second;
381+
auto [NewIt, Inserted] = Infos.try_emplace(Ty, Ty);
382+
return NewIt->second;
397383
}
398384
};
399385

llvm/lib/Analysis/DXILResource.cpp

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -450,12 +450,7 @@ void ResourceTypeInfo::print(raw_ostream &OS, const DataLayout &DL) const {
450450
}
451451

452452
MDTuple *ResourceBindingInfo::getAsMetadata(Module &M,
453-
DXILResourceTypeMap &DRTM) const {
454-
return getAsMetadata(M, DRTM[getHandleTy()]);
455-
}
456-
457-
MDTuple *ResourceBindingInfo::getAsMetadata(Module &M,
458-
dxil::ResourceTypeInfo RTI) const {
453+
dxil::ResourceTypeInfo &RTI) const {
459454
LLVMContext &Ctx = M.getContext();
460455
const DataLayout &DL = M.getDataLayout();
461456

@@ -529,13 +524,7 @@ MDTuple *ResourceBindingInfo::getAsMetadata(Module &M,
529524

530525
std::pair<uint32_t, uint32_t>
531526
ResourceBindingInfo::getAnnotateProps(Module &M,
532-
DXILResourceTypeMap &DRTM) const {
533-
return getAnnotateProps(M, DRTM[getHandleTy()]);
534-
}
535-
536-
std::pair<uint32_t, uint32_t>
537-
ResourceBindingInfo::getAnnotateProps(Module &M,
538-
dxil::ResourceTypeInfo RTI) const {
527+
dxil::ResourceTypeInfo &RTI) const {
539528
const DataLayout &DL = M.getDataLayout();
540529

541530
uint32_t ResourceKind = llvm::to_underlying(RTI.getResourceKind());
@@ -582,12 +571,7 @@ ResourceBindingInfo::getAnnotateProps(Module &M,
582571
return {Word0, Word1};
583572
}
584573

585-
void ResourceBindingInfo::print(raw_ostream &OS, DXILResourceTypeMap &DRTM,
586-
const DataLayout &DL) const {
587-
print(OS, DRTM[getHandleTy()], DL);
588-
}
589-
590-
void ResourceBindingInfo::print(raw_ostream &OS, dxil::ResourceTypeInfo RTI,
574+
void ResourceBindingInfo::print(raw_ostream &OS, dxil::ResourceTypeInfo &RTI,
591575
const DataLayout &DL) const {
592576
OS << " Binding:\n"
593577
<< " Record ID: " << Binding.RecordID << "\n"
@@ -623,7 +607,7 @@ void DXILBindingMap::populate(Module &M, DXILResourceTypeMap &DRTM) {
623607
continue;
624608
case Intrinsic::dx_handle_fromBinding: {
625609
auto *HandleTy = cast<TargetExtType>(F.getReturnType());
626-
ResourceTypeInfo RTI = DRTM[HandleTy];
610+
ResourceTypeInfo &RTI = DRTM[HandleTy];
627611

628612
for (User *U : F.users())
629613
if (CallInst *CI = dyn_cast<CallInst>(U)) {
@@ -667,7 +651,7 @@ void DXILBindingMap::populate(Module &M, DXILResourceTypeMap &DRTM) {
667651
uint32_t NextID = 0;
668652
for (unsigned I = 0, E = Size; I != E; ++I) {
669653
ResourceBindingInfo &RBI = Infos[I];
670-
ResourceTypeInfo RTI = DRTM[RBI.getHandleTy()];
654+
ResourceTypeInfo &RTI = DRTM[RBI.getHandleTy()];
671655
if (RTI.isUAV() && FirstUAV == Size) {
672656
FirstUAV = I;
673657
NextID = 0;
@@ -688,7 +672,8 @@ void DXILBindingMap::print(raw_ostream &OS, DXILResourceTypeMap &DRTM,
688672
const DataLayout &DL) const {
689673
for (unsigned I = 0, E = Infos.size(); I != E; ++I) {
690674
OS << "Binding " << I << ":\n";
691-
Infos[I].print(OS, DRTM, DL);
675+
const dxil::ResourceBindingInfo &RBI = Infos[I];
676+
RBI.print(OS, DRTM[RBI.getHandleTy()], DL);
692677
OS << "\n";
693678
}
694679

llvm/lib/Target/DirectX/DXContainerGlobals.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ void DXContainerGlobals::addResourcesForPSV(Module &M, PSVRuntimeInfo &PSV) {
158158
BindInfo.UpperBound = Binding.LowerBound + Binding.Size - 1;
159159
BindInfo.Space = Binding.Space;
160160

161-
dxil::ResourceTypeInfo TypeInfo = DRTM[RBI.getHandleTy()];
161+
dxil::ResourceTypeInfo &TypeInfo = DRTM[RBI.getHandleTy()];
162162
dxbc::PSV::ResourceType ResType = dxbc::PSV::ResourceType::Invalid;
163163
bool IsUAV = TypeInfo.getResourceClass() == dxil::ResourceClass::UAV;
164164
switch (TypeInfo.getResourceKind()) {

llvm/lib/Target/DirectX/DXILOpLowering.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,15 +302,16 @@ class OpLowerer {
302302
dxil::ResourceBindingInfo &RI = *It;
303303

304304
const auto &Binding = RI.getBinding();
305-
dxil::ResourceClass RC = DRTM[RI.getHandleTy()].getResourceClass();
305+
dxil::ResourceTypeInfo &RTI = DRTM[RI.getHandleTy()];
306+
dxil::ResourceClass RC = RTI.getResourceClass();
306307

307308
Value *IndexOp = CI->getArgOperand(3);
308309
if (Binding.LowerBound != 0)
309310
IndexOp = IRB.CreateAdd(IndexOp,
310311
ConstantInt::get(Int32Ty, Binding.LowerBound));
311312

312313
std::pair<uint32_t, uint32_t> Props =
313-
RI.getAnnotateProps(*F.getParent(), DRTM);
314+
RI.getAnnotateProps(*F.getParent(), RTI);
314315

315316
// For `CreateHandleFromBinding` we need the upper bound rather than the
316317
// size, so we need to be careful about the difference for "unbounded".

llvm/lib/Target/DirectX/DXILTranslateMetadata.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ static NamedMDNode *emitResourceMetadata(Module &M, DXILBindingMap &DBM,
7979

8080
SmallVector<Metadata *> SRVs, UAVs, CBufs, Smps;
8181
for (const ResourceBindingInfo &RI : DBM.srvs())
82-
SRVs.push_back(RI.getAsMetadata(M, DRTM));
82+
SRVs.push_back(RI.getAsMetadata(M, DRTM[RI.getHandleTy()]));
8383
for (const ResourceBindingInfo &RI : DBM.uavs())
84-
UAVs.push_back(RI.getAsMetadata(M, DRTM));
84+
UAVs.push_back(RI.getAsMetadata(M, DRTM[RI.getHandleTy()]));
8585
for (const ResourceBindingInfo &RI : DBM.cbuffers())
86-
CBufs.push_back(RI.getAsMetadata(M, DRTM));
86+
CBufs.push_back(RI.getAsMetadata(M, DRTM[RI.getHandleTy()]));
8787
for (const ResourceBindingInfo &RI : DBM.samplers())
88-
Smps.push_back(RI.getAsMetadata(M, DRTM));
88+
Smps.push_back(RI.getAsMetadata(M, DRTM[RI.getHandleTy()]));
8989

9090
Metadata *SRVMD = SRVs.empty() ? nullptr : MDNode::get(Context, SRVs);
9191
Metadata *UAVMD = UAVs.empty() ? nullptr : MDNode::get(Context, UAVs);

0 commit comments

Comments
 (0)