Skip to content

Commit f7b82c0

Browse files
committed
address comments
1 parent 1f011b7 commit f7b82c0

File tree

1 file changed

+15
-31
lines changed

1 file changed

+15
-31
lines changed

llvm/unittests/Target/DirectX/UniqueResourceFromUseTests.cpp

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "llvm/AsmParser/Parser.h"
1212
#include "llvm/CodeGen/CommandFlags.h"
1313
#include "llvm/IR/Instructions.h"
14+
#include "llvm/IR/IntrinsicsDirectX.h"
1415
#include "llvm/IR/LLVMContext.h"
1516
#include "llvm/IR/Module.h"
1617
#include "llvm/IR/Type.h"
@@ -287,11 +288,8 @@ define void @main() {
287288
call i32 @llvm.dx.resource.updatecounter(target("dx.RawBuffer", float, 1, 0) %handle, i8 -1)
288289
call i32 @llvm.dx.resource.updatecounter(target("dx.RawBuffer", float, 1, 0) %handle, i8 -1)
289290
call i32 @llvm.dx.resource.updatecounter(target("dx.RawBuffer", float, 1, 0) %handle, i8 -1)
290-
call void @a.func(target("dx.RawBuffer", float, 1, 0) %handle)
291291
ret void
292292
}
293-
294-
declare void @a.func(target("dx.RawBuffer", float, 1, 0) %handle)
295293
)";
296294

297295
LLVMContext Context;
@@ -304,14 +302,13 @@ declare void @a.func(target("dx.RawBuffer", float, 1, 0) %handle)
304302
MAM->getResult<DXILResourceCounterDirectionAnalysis>(*M);
305303

306304
for (const Function &F : M->functions()) {
307-
if (F.getName() != "a.func") {
305+
if (F.getIntrinsicID() != Intrinsic::dx_resource_handlefrombinding) {
308306
continue;
309307
}
310308

311309
for (const User *U : F.users()) {
312310
const CallInst *CI = cast<CallInst>(U);
313-
const Value *Handle = CI->getArgOperand(0);
314-
const auto Bindings = DBM.findByUse(Handle);
311+
const auto Bindings = DBM.findByUse(CI);
315312
ASSERT_EQ(Bindings.size(), 1u);
316313
ASSERT_EQ(DCDM[Bindings.front()], ResourceCounterDirection::Decrement);
317314
}
@@ -328,11 +325,8 @@ define void @main() {
328325
call i32 @llvm.dx.resource.updatecounter(target("dx.RawBuffer", float, 1, 0) %handle, i8 1)
329326
call i32 @llvm.dx.resource.updatecounter(target("dx.RawBuffer", float, 1, 0) %handle, i8 1)
330327
call i32 @llvm.dx.resource.updatecounter(target("dx.RawBuffer", float, 1, 0) %handle, i8 1)
331-
call void @a.func(target("dx.RawBuffer", float, 1, 0) %handle)
332328
ret void
333329
}
334-
335-
declare void @a.func(target("dx.RawBuffer", float, 1, 0) %handle)
336330
)";
337331

338332
LLVMContext Context;
@@ -345,14 +339,13 @@ declare void @a.func(target("dx.RawBuffer", float, 1, 0) %handle)
345339
MAM->getResult<DXILResourceCounterDirectionAnalysis>(*M);
346340

347341
for (const Function &F : M->functions()) {
348-
if (F.getName() != "a.func") {
342+
if (F.getIntrinsicID() != Intrinsic::dx_resource_handlefrombinding) {
349343
continue;
350344
}
351345

352346
for (const User *U : F.users()) {
353347
const CallInst *CI = cast<CallInst>(U);
354-
const Value *Handle = CI->getArgOperand(0);
355-
const auto Bindings = DBM.findByUse(Handle);
348+
const auto Bindings = DBM.findByUse(CI);
356349
ASSERT_EQ(Bindings.size(), 1u);
357350
ASSERT_EQ(DCDM[Bindings.front()], ResourceCounterDirection::Increment);
358351
}
@@ -366,11 +359,8 @@ TEST_F(UniqueResourceFromUseTest, TestResourceCounterUnknown) {
366359
define void @main() {
367360
entry:
368361
%handle = call target("dx.RawBuffer", float, 1, 0) @llvm.dx.resource.handlefrombinding(i32 1, i32 2, i32 3, i32 4, i1 false)
369-
call void @a.func(target("dx.RawBuffer", float, 1, 0) %handle)
370362
ret void
371363
}
372-
373-
declare void @a.func(target("dx.RawBuffer", float, 1, 0) %handle)
374364
)";
375365

376366
LLVMContext Context;
@@ -383,14 +373,13 @@ declare void @a.func(target("dx.RawBuffer", float, 1, 0) %handle)
383373
MAM->getResult<DXILResourceCounterDirectionAnalysis>(*M);
384374

385375
for (const Function &F : M->functions()) {
386-
if (F.getName() != "a.func") {
376+
if (F.getIntrinsicID() != Intrinsic::dx_resource_handlefrombinding) {
387377
continue;
388378
}
389379

390380
for (const User *U : F.users()) {
391381
const CallInst *CI = cast<CallInst>(U);
392-
const Value *Handle = CI->getArgOperand(0);
393-
const auto Bindings = DBM.findByUse(Handle);
382+
const auto Bindings = DBM.findByUse(CI);
394383
ASSERT_EQ(Bindings.size(), 1u);
395384
ASSERT_EQ(DCDM[Bindings.front()], ResourceCounterDirection::Unknown);
396385
}
@@ -407,13 +396,8 @@ define void @main() {
407396
%handle2 = call target("dx.RawBuffer", float, 1, 0) @llvm.dx.resource.handlefrombinding(i32 4, i32 3, i32 2, i32 1, i1 false)
408397
call i32 @llvm.dx.resource.updatecounter(target("dx.RawBuffer", float, 1, 0) %handle1, i8 -1)
409398
call i32 @llvm.dx.resource.updatecounter(target("dx.RawBuffer", float, 1, 0) %handle2, i8 1)
410-
call void @a.func(target("dx.RawBuffer", float, 1, 0) %handle1)
411-
call void @b.func(target("dx.RawBuffer", float, 1, 0) %handle2)
412399
ret void
413400
}
414-
415-
declare void @a.func(target("dx.RawBuffer", float, 1, 0) %handle)
416-
declare void @b.func(target("dx.RawBuffer", float, 1, 0) %handle)
417401
)";
418402

419403
LLVMContext Context;
@@ -425,21 +409,21 @@ declare void @b.func(target("dx.RawBuffer", float, 1, 0) %handle)
425409
const DXILResourceCounterDirectionMap &DCDM =
426410
MAM->getResult<DXILResourceCounterDirectionAnalysis>(*M);
427411

412+
ResourceCounterDirection Dirs[2] = {ResourceCounterDirection::Decrement,
413+
ResourceCounterDirection::Increment};
414+
ResourceCounterDirection *Dir = Dirs;
415+
428416
for (const Function &F : M->functions()) {
429-
StringRef FName = F.getName();
430-
if (FName != "a.func" && FName != "b.func") {
417+
if (F.getIntrinsicID() != Intrinsic::dx_resource_handlefrombinding) {
431418
continue;
432419
}
433420

434-
auto Dir = FName == "a.func" ? ResourceCounterDirection::Decrement
435-
: ResourceCounterDirection::Increment;
436-
437421
for (const User *U : F.users()) {
438422
const CallInst *CI = cast<CallInst>(U);
439-
const Value *Handle = CI->getArgOperand(0);
440-
const auto Bindings = DBM.findByUse(Handle);
423+
const auto Bindings = DBM.findByUse(CI);
441424
ASSERT_EQ(Bindings.size(), 1u);
442-
ASSERT_EQ(DCDM[Bindings.front()], Dir);
425+
ASSERT_EQ(DCDM[Bindings.front()], *Dir);
426+
Dir++;
443427
}
444428
}
445429
}

0 commit comments

Comments
 (0)