Skip to content

Commit cf26a2e

Browse files
committed
Address Comments
1 parent 6640a01 commit cf26a2e

File tree

3 files changed

+27
-20
lines changed

3 files changed

+27
-20
lines changed

llvm/include/llvm/Analysis/DXILResource.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,12 @@ class DXILResourceMap {
439439
unsigned FirstCBuffer = 0;
440440
unsigned FirstSampler = 0;
441441

442-
/// Populate the map given the resource binding calls in the given module.
442+
/// Populate all the resource instance data.
443443
void populate(Module &M, DXILResourceTypeMap &DRTM);
444+
/// Populate the map given the resource binding calls in the given module.
445+
void populateResourceInfos(Module &M, DXILResourceTypeMap &DRTM);
446+
/// Analyze and populate the directions of the resource counters.
447+
void populateCounterDirections(Module &M);
444448

445449
public:
446450
using iterator = SmallVector<dxil::ResourceInfo>::iterator;

llvm/lib/Analysis/DXILResource.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,8 @@ static bool isUpdateCounterIntrinsic(Function &F) {
701701
return F.getIntrinsicID() == Intrinsic::dx_resource_updatecounter;
702702
}
703703

704-
void DXILResourceMap::populate(Module &M, DXILResourceTypeMap &DRTM) {
704+
void DXILResourceMap::populateResourceInfos(Module &M,
705+
DXILResourceTypeMap &DRTM) {
705706
SmallVector<std::tuple<CallInst *, ResourceInfo, ResourceTypeInfo>> CIToInfos;
706707

707708
for (Function &F : M.functions()) {
@@ -778,7 +779,9 @@ void DXILResourceMap::populate(Module &M, DXILResourceTypeMap &DRTM) {
778779
// Adjust the resource binding to use the next ID.
779780
RI.setBindingID(NextID++);
780781
}
782+
}
781783

784+
void DXILResourceMap::populateCounterDirections(Module &M) {
782785
for (Function &F : M.functions()) {
783786
if (!isUpdateCounterIntrinsic(F))
784787
continue;
@@ -806,16 +809,20 @@ void DXILResourceMap::populate(Module &M, DXILResourceTypeMap &DRTM) {
806809
Value *HandleArg = CI->getArgOperand(0);
807810
SmallVector<ResourceInfo *> RBInfos = findByUse(HandleArg);
808811
for (ResourceInfo *RBInfo : RBInfos) {
809-
if (RBInfo->CounterDirection == ResourceCounterDirection::Unknown ||
810-
RBInfo->CounterDirection == Direction)
812+
if (RBInfo->CounterDirection == ResourceCounterDirection::Unknown)
811813
RBInfo->CounterDirection = Direction;
812-
else
814+
else if (RBInfo->CounterDirection != Direction)
813815
RBInfo->CounterDirection = ResourceCounterDirection::Invalid;
814816
}
815817
}
816818
}
817819
}
818820

821+
void DXILResourceMap::populate(Module &M, DXILResourceTypeMap &DRTM) {
822+
populateResourceInfos(M, DRTM);
823+
populateCounterDirections(M);
824+
}
825+
819826
void DXILResourceMap::print(raw_ostream &OS, DXILResourceTypeMap &DRTM,
820827
const DataLayout &DL) const {
821828
for (unsigned I = 0, E = Infos.size(); I != E; ++I) {
@@ -849,9 +856,8 @@ SmallVector<dxil::ResourceInfo *> DXILResourceMap::findByUse(const Value *Key) {
849856
// Found the create, return the binding
850857
case Intrinsic::dx_resource_handlefrombinding: {
851858
auto Pos = CallMap.find(CI);
852-
ResourceInfo *It = &Infos[Pos->second];
853-
assert(It != Infos.end() && "HandleFromBinding must be in resource map");
854-
return {It};
859+
assert(Pos != CallMap.end() && "HandleFromBinding must be in resource map");
860+
return {&Infos[Pos->second]};
855861
}
856862
default:
857863
break;

llvm/unittests/Target/DirectX/UniqueResourceFromUseTests.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,8 @@ define void @main() {
293293
DXILResourceMap &DRM = MAM->getResult<DXILResourceAnalysis>(*M);
294294

295295
for (const Function &F : M->functions()) {
296-
if (F.getIntrinsicID() != Intrinsic::dx_resource_handlefrombinding) {
296+
if (F.getIntrinsicID() != Intrinsic::dx_resource_handlefrombinding)
297297
continue;
298-
}
299298

300299
for (const User *U : F.users()) {
301300
const CallInst *CI = cast<CallInst>(U);
@@ -324,9 +323,8 @@ define void @main() {
324323
DXILResourceMap &DRM = MAM->getResult<DXILResourceAnalysis>(*M);
325324

326325
for (const Function &F : M->functions()) {
327-
if (F.getIntrinsicID() != Intrinsic::dx_resource_handlefrombinding) {
326+
if (F.getIntrinsicID() != Intrinsic::dx_resource_handlefrombinding)
328327
continue;
329-
}
330328

331329
for (const User *U : F.users()) {
332330
const CallInst *CI = cast<CallInst>(U);
@@ -352,9 +350,8 @@ define void @main() {
352350
DXILResourceMap &DRM = MAM->getResult<DXILResourceAnalysis>(*M);
353351

354352
for (const Function &F : M->functions()) {
355-
if (F.getIntrinsicID() != Intrinsic::dx_resource_handlefrombinding) {
353+
if (F.getIntrinsicID() != Intrinsic::dx_resource_handlefrombinding)
356354
continue;
357-
}
358355

359356
for (const User *U : F.users()) {
360357
const CallInst *CI = cast<CallInst>(U);
@@ -387,15 +384,16 @@ define void @main() {
387384
ResourceCounterDirection *Dir = Dirs;
388385

389386
for (const Function &F : M->functions()) {
390-
if (F.getIntrinsicID() != Intrinsic::dx_resource_handlefrombinding) {
387+
if (F.getIntrinsicID() != Intrinsic::dx_resource_handlefrombinding)
391388
continue;
392-
}
393389

390+
uint32_t ExpectedDirsIndex = 0;
394391
for (const User *U : F.users()) {
395392
const CallInst *CI = cast<CallInst>(U);
396393
const auto *const Binding = DRM.find(CI);
397-
ASSERT_EQ(Binding->CounterDirection, *Dir);
398-
Dir++;
394+
ASSERT_TRUE(ExpectedDirsIndex < 2);
395+
ASSERT_EQ(Binding->CounterDirection, Dir[ExpectedDirsIndex]);
396+
ExpectedDirsIndex++;
399397
}
400398
}
401399
}
@@ -417,9 +415,8 @@ define void @main() {
417415
DXILResourceMap &DRM = MAM->getResult<DXILResourceAnalysis>(*M);
418416

419417
for (const Function &F : M->functions()) {
420-
if (F.getIntrinsicID() != Intrinsic::dx_resource_handlefrombinding) {
418+
if (F.getIntrinsicID() != Intrinsic::dx_resource_handlefrombinding)
421419
continue;
422-
}
423420

424421
for (const User *U : F.users()) {
425422
const CallInst *CI = cast<CallInst>(U);

0 commit comments

Comments
 (0)