[llvm-branch-commits] [llvm] [NFC] Refactoring DXContainerYaml Root Parameter representation (PR #138318)

Damyan Pepper via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri May 2 11:18:51 PDT 2025


================
@@ -278,33 +280,35 @@ void DXContainerWriter::writeParts(raw_ostream &OS) {
         auto Header = dxbc::RootParameterHeader{Param.Type, Param.Visibility,
                                                 Param.Offset};
 
-        switch (Param.Type) {
-        case llvm::to_underlying(dxbc::RootParameterType::Constants32Bit):
+        if(std::holds_alternative<DXContainerYAML::RootConstantsYaml>(Param.Data)){
+          auto ConstantYaml = std::get<DXContainerYAML::RootConstantsYaml>(Param.Data);
----------------
damyanp wrote:

```suggestion
        if (auto* ConstantYaml = std::get_if<DXContainerYAML::RootConstantsYaml>(&Param.Data)) {
```

(If I remember how variant works correctly)

Saves some repetitive code, and also allows you to pull the data directly out of `Param.Data` without making a copy of it.

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


More information about the llvm-branch-commits mailing list