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

Justin Bogner via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Dec 16 13:03:23 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;
----------------
bogner wrote:

There are a couple of reasons I structured it this way.
1. The map as is only has the pieces of information that aren't derived from the target type itself, making it easier to see that the `ResourceTypeInfo` is a simple convenience API wrapper
2. Storing the pointer as both the key and as a value in the map is redundant, both wasting size and making it less clear what the invariants are.

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


More information about the llvm-branch-commits mailing list