[llvm-branch-commits] [DirectX] Add resource handling to the DXIL pretty printer (PR #104448)

Farzon Lotfi via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Aug 21 20:05:00 PDT 2024


================
@@ -10,23 +10,235 @@
 #include "DXILResourceAnalysis.h"
 #include "DirectX.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Analysis/DXILResource.h"
 #include "llvm/IR/PassManager.h"
+#include "llvm/InitializePasses.h"
 #include "llvm/Pass.h"
+#include "llvm/Support/FormatAdapters.h"
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/raw_ostream.h"
 
 using namespace llvm;
 
-static void prettyPrintResources(raw_ostream &OS,
+static constexpr StringRef getRCName(dxil::ResourceClass RC) {
----------------
farzonl wrote:

Feel free to ignore, I was thinking of a different  way to do this that would have a tighter coupling of  Names and prefixes:

```cpp
struct ResourceClassInfo {
  const StringRef name;
  const StringRef prefix;
};

llvm::DenseMap<dxil::ResourceClass, ResourceClassInfo> createResourceClassMap() {
  return {
    {dxil::ResourceClass::SRV, {"SRV", "t"}},
    {dxil::ResourceClass::UAV, {"UAV", "u"}},
    {dxil::ResourceClass::CBuffer, {"cbuffer", "cb"}},
    {dxil::ResourceClass::Sampler, {"sampler", "s"}}
  };
}

static const llvm::DenseMap<dxil::ResourceClass, ResourceClassInfo> ResourceClassMap = createResourceClassMap();

StringRef getRCName(dxil::ResourceClass RC) {
  return ResourceClassMap.lookup(RC).name;
}

StringRef getRCPrefix(dxil::ResourceClass RC) {
  return ResourceClassMap.lookup(RC).prefix;
}
```

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


More information about the llvm-branch-commits mailing list