11
11
#include " llvm/AsmParser/Parser.h"
12
12
#include " llvm/CodeGen/CommandFlags.h"
13
13
#include " llvm/IR/Instructions.h"
14
+ #include " llvm/IR/IntrinsicsDirectX.h"
14
15
#include " llvm/IR/LLVMContext.h"
15
16
#include " llvm/IR/Module.h"
16
17
#include " llvm/IR/Type.h"
@@ -287,11 +288,8 @@ define void @main() {
287
288
call i32 @llvm.dx.resource.updatecounter(target("dx.RawBuffer", float, 1, 0) %handle, i8 -1)
288
289
call i32 @llvm.dx.resource.updatecounter(target("dx.RawBuffer", float, 1, 0) %handle, i8 -1)
289
290
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)
291
291
ret void
292
292
}
293
-
294
- declare void @a.func(target("dx.RawBuffer", float, 1, 0) %handle)
295
293
)" ;
296
294
297
295
LLVMContext Context;
@@ -304,14 +302,13 @@ declare void @a.func(target("dx.RawBuffer", float, 1, 0) %handle)
304
302
MAM->getResult <DXILResourceCounterDirectionAnalysis>(*M);
305
303
306
304
for (const Function &F : M->functions ()) {
307
- if (F.getName () != " a.func " ) {
305
+ if (F.getIntrinsicID () != Intrinsic::dx_resource_handlefrombinding ) {
308
306
continue ;
309
307
}
310
308
311
309
for (const User *U : F.users ()) {
312
310
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);
315
312
ASSERT_EQ (Bindings.size (), 1u );
316
313
ASSERT_EQ (DCDM[Bindings.front ()], ResourceCounterDirection::Decrement);
317
314
}
@@ -328,11 +325,8 @@ define void @main() {
328
325
call i32 @llvm.dx.resource.updatecounter(target("dx.RawBuffer", float, 1, 0) %handle, i8 1)
329
326
call i32 @llvm.dx.resource.updatecounter(target("dx.RawBuffer", float, 1, 0) %handle, i8 1)
330
327
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)
332
328
ret void
333
329
}
334
-
335
- declare void @a.func(target("dx.RawBuffer", float, 1, 0) %handle)
336
330
)" ;
337
331
338
332
LLVMContext Context;
@@ -345,14 +339,13 @@ declare void @a.func(target("dx.RawBuffer", float, 1, 0) %handle)
345
339
MAM->getResult <DXILResourceCounterDirectionAnalysis>(*M);
346
340
347
341
for (const Function &F : M->functions ()) {
348
- if (F.getName () != " a.func " ) {
342
+ if (F.getIntrinsicID () != Intrinsic::dx_resource_handlefrombinding ) {
349
343
continue ;
350
344
}
351
345
352
346
for (const User *U : F.users ()) {
353
347
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);
356
349
ASSERT_EQ (Bindings.size (), 1u );
357
350
ASSERT_EQ (DCDM[Bindings.front ()], ResourceCounterDirection::Increment);
358
351
}
@@ -366,11 +359,8 @@ TEST_F(UniqueResourceFromUseTest, TestResourceCounterUnknown) {
366
359
define void @main() {
367
360
entry:
368
361
%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)
370
362
ret void
371
363
}
372
-
373
- declare void @a.func(target("dx.RawBuffer", float, 1, 0) %handle)
374
364
)" ;
375
365
376
366
LLVMContext Context;
@@ -383,14 +373,13 @@ declare void @a.func(target("dx.RawBuffer", float, 1, 0) %handle)
383
373
MAM->getResult <DXILResourceCounterDirectionAnalysis>(*M);
384
374
385
375
for (const Function &F : M->functions ()) {
386
- if (F.getName () != " a.func " ) {
376
+ if (F.getIntrinsicID () != Intrinsic::dx_resource_handlefrombinding ) {
387
377
continue ;
388
378
}
389
379
390
380
for (const User *U : F.users ()) {
391
381
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);
394
383
ASSERT_EQ (Bindings.size (), 1u );
395
384
ASSERT_EQ (DCDM[Bindings.front ()], ResourceCounterDirection::Unknown);
396
385
}
@@ -407,13 +396,8 @@ define void @main() {
407
396
%handle2 = call target("dx.RawBuffer", float, 1, 0) @llvm.dx.resource.handlefrombinding(i32 4, i32 3, i32 2, i32 1, i1 false)
408
397
call i32 @llvm.dx.resource.updatecounter(target("dx.RawBuffer", float, 1, 0) %handle1, i8 -1)
409
398
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)
412
399
ret void
413
400
}
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)
417
401
)" ;
418
402
419
403
LLVMContext Context;
@@ -425,21 +409,21 @@ declare void @b.func(target("dx.RawBuffer", float, 1, 0) %handle)
425
409
const DXILResourceCounterDirectionMap &DCDM =
426
410
MAM->getResult <DXILResourceCounterDirectionAnalysis>(*M);
427
411
412
+ ResourceCounterDirection Dirs[2 ] = {ResourceCounterDirection::Decrement,
413
+ ResourceCounterDirection::Increment};
414
+ ResourceCounterDirection *Dir = Dirs;
415
+
428
416
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) {
431
418
continue ;
432
419
}
433
420
434
- auto Dir = FName == " a.func" ? ResourceCounterDirection::Decrement
435
- : ResourceCounterDirection::Increment;
436
-
437
421
for (const User *U : F.users ()) {
438
422
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);
441
424
ASSERT_EQ (Bindings.size (), 1u );
442
- ASSERT_EQ (DCDM[Bindings.front ()], Dir);
425
+ ASSERT_EQ (DCDM[Bindings.front ()], *Dir);
426
+ Dir++;
443
427
}
444
428
}
445
429
}
0 commit comments