[llvm-branch-commits] [llvm] [DirectX] Split resource info into type and binding info. NFC (PR #119773)

Helena Kotas via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sat Dec 14 10:30:28 PST 2024


================
@@ -303,44 +289,157 @@ class ResourceInfo {
   dxil::SamplerFeedbackType getFeedbackType() const;
   uint32_t getMultiSampleCount() const;
 
-  StringRef getName() const {
-    // TODO: Get the name from the symbol once we include one here.
-    return "";
-  }
   dxil::ResourceClass getResourceClass() const { return RC; }
   dxil::ResourceKind getResourceKind() const { return Kind; }
 
+  bool operator==(const ResourceTypeInfo &RHS) const;
+  bool operator!=(const ResourceTypeInfo &RHS) const { return !(*this == RHS); }
+  bool operator<(const ResourceTypeInfo &RHS) const;
+
+  void print(raw_ostream &OS, const DataLayout &DL) const;
+};
+
+//===----------------------------------------------------------------------===//
+
+class ResourceBindingInfo {
+public:
+  struct ResourceBinding {
+    uint32_t RecordID;
+    uint32_t Space;
+    uint32_t LowerBound;
+    uint32_t Size;
+
+    bool operator==(const ResourceBinding &RHS) const {
+      return std::tie(RecordID, Space, LowerBound, Size) ==
+             std::tie(RHS.RecordID, RHS.Space, RHS.LowerBound, RHS.Size);
+    }
+    bool operator!=(const ResourceBinding &RHS) const {
+      return !(*this == RHS);
+    }
+    bool operator<(const ResourceBinding &RHS) const {
+      return std::tie(RecordID, Space, LowerBound, Size) <
+             std::tie(RHS.RecordID, RHS.Space, RHS.LowerBound, RHS.Size);
+    }
+  };
+
+private:
+  ResourceBinding Binding;
+  TargetExtType *HandleTy;
+
+public:
+  ResourceBindingInfo(uint32_t RecordID, uint32_t Space, uint32_t LowerBound,
+                      uint32_t Size, TargetExtType *HandleTy)
+      : Binding{RecordID, Space, LowerBound, Size}, HandleTy(HandleTy) {}
+
   void setBindingID(unsigned ID) { Binding.RecordID = ID; }
 
   const ResourceBinding &getBinding() const { return Binding; }
+  TargetExtType *getHandleTy() const { return HandleTy; }
+  const StringRef getName() const {
+    // TODO: Get the name from the symbol once we include one here.
+    return "";
+  }
 
-  MDTuple *getAsMetadata(Module &M) const;
-  std::pair<uint32_t, uint32_t> getAnnotateProps(Module &M) const;
+  MDTuple *getAsMetadata(Module &M, DXILResourceTypeMap &DRTM) const;
+  MDTuple *getAsMetadata(Module &M, dxil::ResourceTypeInfo RTI) const;
 
-  bool operator==(const ResourceInfo &RHS) const;
-  bool operator!=(const ResourceInfo &RHS) const { return !(*this == RHS); }
-  bool operator<(const ResourceInfo &RHS) const;
+  std::pair<uint32_t, uint32_t>
+  getAnnotateProps(Module &M, DXILResourceTypeMap &DRTM) const;
+  std::pair<uint32_t, uint32_t>
+  getAnnotateProps(Module &M, dxil::ResourceTypeInfo RTI) const;
 
-  void print(raw_ostream &OS, const DataLayout &DL) const;
+  bool operator==(const ResourceBindingInfo &RHS) const {
+    return std::tie(Binding, HandleTy) == std::tie(RHS.Binding, RHS.HandleTy);
+  }
+  bool operator!=(const ResourceBindingInfo &RHS) const {
+    return !(*this == RHS);
+  }
+  bool operator<(const ResourceBindingInfo &RHS) const {
+    return Binding < RHS.Binding;
+  }
+
+  void print(raw_ostream &OS, DXILResourceTypeMap &DRTM,
+             const DataLayout &DL) const;
+  void print(raw_ostream &OS, dxil::ResourceTypeInfo RTI,
+             const DataLayout &DL) const;
 };
 
 } // namespace dxil
 
 //===----------------------------------------------------------------------===//
 
-class DXILResourceMap {
-  SmallVector<dxil::ResourceInfo> Infos;
+class DXILResourceTypeMap {
+  struct Info {
+    dxil::ResourceClass RC;
+    dxil::ResourceKind Kind;
+    bool GloballyCoherent;
+    bool HasCounter;
+  };
+  DenseMap<TargetExtType *, Info> Infos;
+
+public:
+  bool invalidate(Module &M, const PreservedAnalyses &PA,
+                  ModuleAnalysisManager::Invalidator &Inv);
+
+  dxil::ResourceTypeInfo operator[](TargetExtType *Ty) {
+    Info I = Infos[Ty];
+    return dxil::ResourceTypeInfo(Ty, I.RC, I.Kind, I.GloballyCoherent,
+                                  I.HasCounter);
+  }
+
+  void setGloballyCoherent(TargetExtType *Ty, bool GloballyCoherent) {
+    Infos[Ty].GloballyCoherent = GloballyCoherent;
+  }
+
+  void setHasCounter(TargetExtType *Ty, bool HasCounter) {
+    Infos[Ty].HasCounter = HasCounter;
+  }
+};
+
+class DXILResourceTypeAnalysis
+    : public AnalysisInfoMixin<DXILResourceTypeAnalysis> {
+  friend AnalysisInfoMixin<DXILResourceTypeAnalysis>;
+
+  static AnalysisKey Key;
+
+public:
+  using Result = DXILResourceTypeMap;
+
+  DXILResourceTypeMap run(Module &M, ModuleAnalysisManager &AM) {
+    return Result();
+  }
----------------
hekota wrote:

It would be nice to add a comment on this class explaining how will the DXILResourceTypeMap get populated (that it happens in the DXILResourceBindingAnalysis, if I understand it correctly).

https://github.com/llvm/llvm-project/pull/119773


More information about the llvm-branch-commits mailing list