Skip to content

Commit d2f17eb

Browse files
committed
address comments
1 parent cd70254 commit d2f17eb

File tree

3 files changed

+13
-26
lines changed

3 files changed

+13
-26
lines changed

llvm/include/llvm/Analysis/DXILResource.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,11 @@ class DXILBindingMap {
446446
return Pos == CallMap.end() ? Infos.end() : (Infos.begin() + Pos->second);
447447
}
448448

449-
// Resoloves the use of a resource handle into the unique description of that
450-
// resource by deduping calls to create.
449+
/// Resolves a resource handle into a vector of ResourceBindingInfos that
450+
/// represent the possible unique creations of the handle. Certain cases are
451+
/// ambiguous so mulitple creation points may be returned. The resulting
452+
/// ResourceBindingInfo can be used to depuplicate unique handles that
453+
/// reference the same resource
451454
SmallVector<dxil::ResourceBindingInfo> findByUse(const Value *Key) const;
452455

453456
const_iterator find(const CallInst *Key) const {

llvm/lib/Analysis/DXILResource.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -772,8 +772,7 @@ void DXILBindingMap::print(raw_ostream &OS, DXILResourceTypeMap &DRTM,
772772

773773
SmallVector<dxil::ResourceBindingInfo>
774774
DXILBindingMap::findByUse(const Value *Key) const {
775-
const PHINode *Phi = dyn_cast<PHINode>(Key);
776-
if (Phi) {
775+
if (const PHINode *Phi = dyn_cast<PHINode>(Key)) {
777776
SmallVector<dxil::ResourceBindingInfo> Children;
778777
for (const Value *V : Phi->operands()) {
779778
Children.append(findByUse(V));
@@ -782,9 +781,8 @@ DXILBindingMap::findByUse(const Value *Key) const {
782781
}
783782

784783
const CallInst *CI = dyn_cast<CallInst>(Key);
785-
if (!CI) {
784+
if (!CI)
786785
return {};
787-
}
788786

789787
const Type *UseType = CI->getType();
790788

@@ -794,9 +792,8 @@ DXILBindingMap::findByUse(const Value *Key) const {
794792
case Intrinsic::not_intrinsic: {
795793
SmallVector<dxil::ResourceBindingInfo> Children;
796794
for (const Value *V : CI->args()) {
797-
if (V->getType() != UseType) {
795+
if (V->getType() != UseType)
798796
continue;
799-
}
800797

801798
Children.append(findByUse(V));
802799
}
@@ -806,8 +803,7 @@ DXILBindingMap::findByUse(const Value *Key) const {
806803
// Found the create, return the binding
807804
case Intrinsic::dx_resource_handlefrombinding:
808805
const auto *It = find(CI);
809-
if (It == Infos.end())
810-
return {};
806+
assert(It != Infos.end() && "HandleFromBinding must be in resource map");
811807
return {*It};
812808
}
813809

llvm/unittests/Target/DirectX/UniqueResourceFromUseTests.cpp

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,8 @@ declare void @a.func(target("dx.RawBuffer", float, 1, 0) %handle)
7171
unsigned CalledResources = 0;
7272

7373
for (const User *U : F.users()) {
74-
const CallInst *CI = dyn_cast<CallInst>(U);
75-
ASSERT_TRUE(CI) << "All users of @a.func must be CallInst";
76-
74+
const CallInst *CI = cast<CallInst>(U);
7775
const Value *Handle = CI->getArgOperand(0);
78-
7976
const auto Bindings = DBM.findByUse(Handle);
8077
ASSERT_EQ(Bindings.size(), 1u)
8178
<< "Handle should resolve into one resource";
@@ -124,11 +121,8 @@ declare target("dx.RawBuffer", float, 1, 0) @ind.func(target("dx.RawBuffer", flo
124121
unsigned CalledResources = 0;
125122

126123
for (const User *U : F.users()) {
127-
const CallInst *CI = dyn_cast<CallInst>(U);
128-
ASSERT_TRUE(CI) << "All users of @a.func must be CallInst";
129-
124+
const CallInst *CI = cast<CallInst>(U);
130125
const Value *Handle = CI->getArgOperand(0);
131-
132126
const auto Bindings = DBM.findByUse(Handle);
133127
ASSERT_EQ(Bindings.size(), 1u)
134128
<< "Handle should resolve into one resource";
@@ -180,11 +174,8 @@ declare target("dx.RawBuffer", float, 1, 0) @ind.func(target("dx.RawBuffer", flo
180174
unsigned CalledResources = 0;
181175

182176
for (const User *U : F.users()) {
183-
const CallInst *CI = dyn_cast<CallInst>(U);
184-
ASSERT_TRUE(CI) << "All users of @a.func must be CallInst";
185-
177+
const CallInst *CI = cast<CallInst>(U);
186178
const Value *Handle = CI->getArgOperand(0);
187-
188179
const auto Bindings = DBM.findByUse(Handle);
189180
ASSERT_EQ(Bindings.size(), 4u)
190181
<< "Handle should resolve into four resources";
@@ -263,11 +254,8 @@ declare target("dx.RawBuffer", float, 1, 0) @ind.func(target("dx.RawBuffer", flo
263254
unsigned CalledResources = 0;
264255

265256
for (const User *U : F.users()) {
266-
const CallInst *CI = dyn_cast<CallInst>(U);
267-
ASSERT_TRUE(CI) << "All users of @a.func must be CallInst";
268-
257+
const CallInst *CI = cast<CallInst>(U);
269258
const Value *Handle = CI->getArgOperand(0);
270-
271259
const auto Bindings = DBM.findByUse(Handle);
272260
ASSERT_EQ(Bindings.size(), 2u)
273261
<< "Handle should resolve into four resources";

0 commit comments

Comments
 (0)