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