[llvm] [NFC] Refactoring MCDXBC to support out of order storage of root parameters (PR #137284)

Justin Bogner via llvm-commits llvm-commits at lists.llvm.org
Wed May 14 21:04:55 PDT 2025


================
@@ -15,12 +15,64 @@ namespace llvm {
 class raw_ostream;
 namespace mcdxbc {
 
-struct RootParameter {
+struct RootParameterInfo {
   dxbc::RootParameterHeader Header;
-  union {
-    dxbc::RootConstants Constants;
-    dxbc::RTS0::v2::RootDescriptor Descriptor;
-  };
+  size_t Location;
+
+  RootParameterInfo() = default;
+
+  RootParameterInfo(dxbc::RootParameterHeader H, size_t L)
+      : Header(H), Location(L) {}
+};
+
+struct RootParametersContainer {
+  SmallVector<RootParameterInfo> ParametersInfo;
+
+  SmallVector<dxbc::RootConstants> Constants;
+  SmallVector<dxbc::RTS0::v2::RootDescriptor> Descriptors;
+
+  void addInfo(dxbc::RootParameterHeader H, size_t L) {
+    ParametersInfo.push_back(RootParameterInfo(H, L));
+  }
+
+  void addParameter(dxbc::RootParameterHeader H, dxbc::RootConstants C) {
+    addInfo(H, Constants.size());
+    Constants.push_back(C);
+  }
+
+  void addParameter(dxbc::RootParameterHeader H,
+                    dxbc::RTS0::v2::RootDescriptor D) {
+    addInfo(H, Descriptors.size());
+    Descriptors.push_back(D);
+  }
+
+  const std::pair<uint32_t, uint32_t>
+  getTypeAndLocForParameter(uint32_t Index) const {
+    const RootParameterInfo &Info = ParametersInfo[Index];
+    return {Info.Header.ParameterType, Info.Location};
+  }
+
+  const dxbc::RootParameterHeader &getHeader(size_t Index) const {
+    const RootParameterInfo &Info = ParametersInfo[Index];
+    return Info.Header;
+  }
+
+  const dxbc::RootConstants &getConstant(size_t Index) const {
+    return Constants[Index];
+  }
+
+  const dxbc::RTS0::v2::RootDescriptor &getRootDescriptor(size_t Index) const {
+    return Descriptors[Index];
+  }
----------------
bogner wrote:

(I thought I commented on this already, but I think github ate it...)

Seeing these next to `getTypeAndLocForParameter` and `getHeader`, "Index" is maybe ambiguous as a variable name. Let's call these ones "Location" instead to differentiate that these are indices into the particular type of object not the index into headers used elsewhere

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


More information about the llvm-commits mailing list