@@ -25,6 +25,8 @@ class MDTuple;
25
25
class TargetExtType ;
26
26
class Value ;
27
27
28
+ class DXILResourceTypeMap ;
29
+
28
30
namespace dxil {
29
31
30
32
// / The dx.RawBuffer target extension type
@@ -196,27 +198,8 @@ class SamplerExtType : public TargetExtType {
196
198
197
199
// ===----------------------------------------------------------------------===//
198
200
199
- class ResourceInfo {
201
+ class ResourceTypeInfo {
200
202
public:
201
- struct ResourceBinding {
202
- uint32_t RecordID;
203
- uint32_t Space;
204
- uint32_t LowerBound;
205
- uint32_t Size;
206
-
207
- bool operator ==(const ResourceBinding &RHS) const {
208
- return std::tie (RecordID, Space, LowerBound, Size) ==
209
- std::tie (RHS.RecordID , RHS.Space , RHS.LowerBound , RHS.Size );
210
- }
211
- bool operator !=(const ResourceBinding &RHS) const {
212
- return !(*this == RHS);
213
- }
214
- bool operator <(const ResourceBinding &RHS) const {
215
- return std::tie (RecordID, Space, LowerBound, Size) <
216
- std::tie (RHS.RecordID , RHS.Space , RHS.LowerBound , RHS.Size );
217
- }
218
- };
219
-
220
203
struct UAVInfo {
221
204
bool GloballyCoherent;
222
205
bool HasCounter;
@@ -266,22 +249,25 @@ class ResourceInfo {
266
249
};
267
250
268
251
private:
269
- ResourceBinding Binding;
270
252
TargetExtType *HandleTy;
271
253
272
254
// GloballyCoherent and HasCounter aren't really part of the type and need to
273
- // be determined by analysis, so they're just provided directly when we
274
- // construct these.
255
+ // be determined by analysis, so they're just provided directly by the
256
+ // DXILResourceTypeMap when we construct these.
275
257
bool GloballyCoherent;
276
258
bool HasCounter;
277
259
278
260
dxil::ResourceClass RC;
279
261
dxil::ResourceKind Kind;
280
262
281
263
public:
282
- ResourceInfo (uint32_t RecordID, uint32_t Space, uint32_t LowerBound,
283
- uint32_t Size, TargetExtType *HandleTy,
284
- bool GloballyCoherent = false , bool HasCounter = false );
264
+ ResourceTypeInfo (TargetExtType *HandleTy, const dxil::ResourceClass RC,
265
+ const dxil::ResourceKind Kind, bool GloballyCoherent = false ,
266
+ bool HasCounter = false );
267
+ ResourceTypeInfo (TargetExtType *HandleTy, bool GloballyCoherent = false ,
268
+ bool HasCounter = false )
269
+ : ResourceTypeInfo(HandleTy, {}, dxil::ResourceKind::Invalid,
270
+ GloballyCoherent, HasCounter) {}
285
271
286
272
TargetExtType *getHandleTy () const { return HandleTy; }
287
273
@@ -303,44 +289,157 @@ class ResourceInfo {
303
289
dxil::SamplerFeedbackType getFeedbackType () const ;
304
290
uint32_t getMultiSampleCount () const ;
305
291
306
- StringRef getName () const {
307
- // TODO: Get the name from the symbol once we include one here.
308
- return " " ;
309
- }
310
292
dxil::ResourceClass getResourceClass () const { return RC; }
311
293
dxil::ResourceKind getResourceKind () const { return Kind; }
312
294
295
+ bool operator ==(const ResourceTypeInfo &RHS) const ;
296
+ bool operator !=(const ResourceTypeInfo &RHS) const { return !(*this == RHS); }
297
+ bool operator <(const ResourceTypeInfo &RHS) const ;
298
+
299
+ void print (raw_ostream &OS, const DataLayout &DL) const ;
300
+ };
301
+
302
+ // ===----------------------------------------------------------------------===//
303
+
304
+ class ResourceBindingInfo {
305
+ public:
306
+ struct ResourceBinding {
307
+ uint32_t RecordID;
308
+ uint32_t Space;
309
+ uint32_t LowerBound;
310
+ uint32_t Size;
311
+
312
+ bool operator ==(const ResourceBinding &RHS) const {
313
+ return std::tie (RecordID, Space, LowerBound, Size) ==
314
+ std::tie (RHS.RecordID , RHS.Space , RHS.LowerBound , RHS.Size );
315
+ }
316
+ bool operator !=(const ResourceBinding &RHS) const {
317
+ return !(*this == RHS);
318
+ }
319
+ bool operator <(const ResourceBinding &RHS) const {
320
+ return std::tie (RecordID, Space, LowerBound, Size) <
321
+ std::tie (RHS.RecordID , RHS.Space , RHS.LowerBound , RHS.Size );
322
+ }
323
+ };
324
+
325
+ private:
326
+ ResourceBinding Binding;
327
+ TargetExtType *HandleTy;
328
+
329
+ public:
330
+ ResourceBindingInfo (uint32_t RecordID, uint32_t Space, uint32_t LowerBound,
331
+ uint32_t Size, TargetExtType *HandleTy)
332
+ : Binding{RecordID, Space, LowerBound, Size}, HandleTy(HandleTy) {}
333
+
313
334
void setBindingID (unsigned ID) { Binding.RecordID = ID; }
314
335
315
336
const ResourceBinding &getBinding () const { return Binding; }
337
+ TargetExtType *getHandleTy () const { return HandleTy; }
338
+ const StringRef getName () const {
339
+ // TODO: Get the name from the symbol once we include one here.
340
+ return " " ;
341
+ }
316
342
317
- MDTuple *getAsMetadata (Module &M) const ;
318
- std::pair< uint32_t , uint32_t > getAnnotateProps (Module &M) const ;
343
+ MDTuple *getAsMetadata (Module &M, DXILResourceTypeMap &DRTM ) const ;
344
+ MDTuple * getAsMetadata (Module &M, dxil::ResourceTypeInfo RTI ) const ;
319
345
320
- bool operator ==(const ResourceInfo &RHS) const ;
321
- bool operator !=(const ResourceInfo &RHS) const { return !(*this == RHS); }
322
- bool operator <(const ResourceInfo &RHS) const ;
346
+ std::pair<uint32_t , uint32_t >
347
+ getAnnotateProps (Module &M, DXILResourceTypeMap &DRTM) const ;
348
+ std::pair<uint32_t , uint32_t >
349
+ getAnnotateProps (Module &M, dxil::ResourceTypeInfo RTI) const ;
323
350
324
- void print (raw_ostream &OS, const DataLayout &DL) const ;
351
+ bool operator ==(const ResourceBindingInfo &RHS) const {
352
+ return std::tie (Binding, HandleTy) == std::tie (RHS.Binding , RHS.HandleTy );
353
+ }
354
+ bool operator !=(const ResourceBindingInfo &RHS) const {
355
+ return !(*this == RHS);
356
+ }
357
+ bool operator <(const ResourceBindingInfo &RHS) const {
358
+ return Binding < RHS.Binding ;
359
+ }
360
+
361
+ void print (raw_ostream &OS, DXILResourceTypeMap &DRTM,
362
+ const DataLayout &DL) const ;
363
+ void print (raw_ostream &OS, dxil::ResourceTypeInfo RTI,
364
+ const DataLayout &DL) const ;
325
365
};
326
366
327
367
} // namespace dxil
328
368
329
369
// ===----------------------------------------------------------------------===//
330
370
331
- class DXILResourceMap {
332
- SmallVector<dxil::ResourceInfo> Infos;
371
+ class DXILResourceTypeMap {
372
+ struct Info {
373
+ dxil::ResourceClass RC;
374
+ dxil::ResourceKind Kind;
375
+ bool GloballyCoherent;
376
+ bool HasCounter;
377
+ };
378
+ DenseMap<TargetExtType *, Info> Infos;
379
+
380
+ public:
381
+ bool invalidate (Module &M, const PreservedAnalyses &PA,
382
+ ModuleAnalysisManager::Invalidator &Inv);
383
+
384
+ dxil::ResourceTypeInfo operator [](TargetExtType *Ty) {
385
+ Info I = Infos[Ty];
386
+ return dxil::ResourceTypeInfo (Ty, I.RC , I.Kind , I.GloballyCoherent ,
387
+ I.HasCounter );
388
+ }
389
+
390
+ void setGloballyCoherent (TargetExtType *Ty, bool GloballyCoherent) {
391
+ Infos[Ty].GloballyCoherent = GloballyCoherent;
392
+ }
393
+
394
+ void setHasCounter (TargetExtType *Ty, bool HasCounter) {
395
+ Infos[Ty].HasCounter = HasCounter;
396
+ }
397
+ };
398
+
399
+ class DXILResourceTypeAnalysis
400
+ : public AnalysisInfoMixin<DXILResourceTypeAnalysis> {
401
+ friend AnalysisInfoMixin<DXILResourceTypeAnalysis>;
402
+
403
+ static AnalysisKey Key;
404
+
405
+ public:
406
+ using Result = DXILResourceTypeMap;
407
+
408
+ DXILResourceTypeMap run (Module &M, ModuleAnalysisManager &AM) {
409
+ return Result ();
410
+ }
411
+ };
412
+
413
+ class DXILResourceTypeWrapperPass : public ImmutablePass {
414
+ DXILResourceTypeMap DRTM;
415
+
416
+ virtual void anchor ();
417
+
418
+ public:
419
+ static char ID;
420
+ DXILResourceTypeWrapperPass ();
421
+
422
+ DXILResourceTypeMap &getResourceTypeMap () { return DRTM; }
423
+ const DXILResourceTypeMap &getResourceTypeMap () const { return DRTM; }
424
+ };
425
+
426
+ ModulePass *createDXILResourceTypeWrapperPassPass ();
427
+
428
+ // ===----------------------------------------------------------------------===//
429
+
430
+ class DXILBindingMap {
431
+ SmallVector<dxil::ResourceBindingInfo> Infos;
333
432
DenseMap<CallInst *, unsigned > CallMap;
334
433
unsigned FirstUAV = 0 ;
335
434
unsigned FirstCBuffer = 0 ;
336
435
unsigned FirstSampler = 0 ;
337
436
338
437
// / Populate the map given the resource binding calls in the given module.
339
- void populate (Module &M);
438
+ void populate (Module &M, DXILResourceTypeMap &DRTM );
340
439
341
440
public:
342
- using iterator = SmallVector<dxil::ResourceInfo >::iterator;
343
- using const_iterator = SmallVector<dxil::ResourceInfo >::const_iterator;
441
+ using iterator = SmallVector<dxil::ResourceBindingInfo >::iterator;
442
+ using const_iterator = SmallVector<dxil::ResourceBindingInfo >::const_iterator;
344
443
345
444
iterator begin () { return Infos.begin (); }
346
445
const_iterator begin () const { return Infos.begin (); }
@@ -399,47 +498,51 @@ class DXILResourceMap {
399
498
return make_range (sampler_begin (), sampler_end ());
400
499
}
401
500
402
- void print (raw_ostream &OS, const DataLayout &DL) const ;
501
+ void print (raw_ostream &OS, DXILResourceTypeMap &DRTM,
502
+ const DataLayout &DL) const ;
403
503
404
- friend class DXILResourceAnalysis ;
405
- friend class DXILResourceWrapperPass ;
504
+ friend class DXILResourceBindingAnalysis ;
505
+ friend class DXILResourceBindingWrapperPass ;
406
506
};
407
507
408
- class DXILResourceAnalysis : public AnalysisInfoMixin <DXILResourceAnalysis> {
409
- friend AnalysisInfoMixin<DXILResourceAnalysis>;
508
+ class DXILResourceBindingAnalysis
509
+ : public AnalysisInfoMixin<DXILResourceBindingAnalysis> {
510
+ friend AnalysisInfoMixin<DXILResourceBindingAnalysis>;
410
511
411
512
static AnalysisKey Key;
412
513
413
514
public:
414
- using Result = DXILResourceMap ;
515
+ using Result = DXILBindingMap ;
415
516
416
517
// / Gather resource info for the module \c M.
417
- DXILResourceMap run (Module &M, ModuleAnalysisManager &AM);
518
+ DXILBindingMap run (Module &M, ModuleAnalysisManager &AM);
418
519
};
419
520
420
- // / Printer pass for the \c DXILResourceAnalysis results.
421
- class DXILResourcePrinterPass : public PassInfoMixin <DXILResourcePrinterPass> {
521
+ // / Printer pass for the \c DXILResourceBindingAnalysis results.
522
+ class DXILResourceBindingPrinterPass
523
+ : public PassInfoMixin<DXILResourceBindingPrinterPass> {
422
524
raw_ostream &OS;
423
525
424
526
public:
425
- explicit DXILResourcePrinterPass (raw_ostream &OS) : OS(OS) {}
527
+ explicit DXILResourceBindingPrinterPass (raw_ostream &OS) : OS(OS) {}
426
528
427
529
PreservedAnalyses run (Module &M, ModuleAnalysisManager &AM);
428
530
429
531
static bool isRequired () { return true ; }
430
532
};
431
533
432
- class DXILResourceWrapperPass : public ModulePass {
433
- std::unique_ptr<DXILResourceMap> Map;
534
+ class DXILResourceBindingWrapperPass : public ModulePass {
535
+ std::unique_ptr<DXILBindingMap> Map;
536
+ DXILResourceTypeMap *DRTM;
434
537
435
538
public:
436
539
static char ID; // Class identification, replacement for typeinfo
437
540
438
- DXILResourceWrapperPass ();
439
- ~DXILResourceWrapperPass () override ;
541
+ DXILResourceBindingWrapperPass ();
542
+ ~DXILResourceBindingWrapperPass () override ;
440
543
441
- const DXILResourceMap & getResourceMap () const { return *Map; }
442
- DXILResourceMap & getResourceMap () { return *Map; }
544
+ const DXILBindingMap & getBindingMap () const { return *Map; }
545
+ DXILBindingMap & getBindingMap () { return *Map; }
443
546
444
547
void getAnalysisUsage (AnalysisUsage &AU) const override ;
445
548
bool runOnModule (Module &M) override ;
@@ -449,7 +552,7 @@ class DXILResourceWrapperPass : public ModulePass {
449
552
void dump () const ;
450
553
};
451
554
452
- ModulePass *createDXILResourceWrapperPassPass ();
555
+ ModulePass *createDXILResourceBindingWrapperPassPass ();
453
556
454
557
} // namespace llvm
455
558
0 commit comments