[llvm-branch-commits] [DirectX] Add resource handling to the DXIL pretty printer (PR #104448)
Justin Bogner via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Aug 26 16:14:03 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) {
----------------
bogner wrote:
This generates noticeably worse code because of the hash table lookup and also introduces a static initializer, which should really be avoided. It is possible to do something similar with a static table, but you need to break the abstraction of the enum a bit to do that and adding static asserts to make sure it's correct undoes most of the potential clarity it adds.
I suppose we could do something like this to couple the names, but I'm not entirely sold that the usability hit is worth it:
```c++
struct ResourceClassNameInfo {
const StringRef Name;
const StringRef Prefix;
};
static constexpr ResourceClassNameInfo getRCNameInfo(dxil::ResourceClass RC) {
switch (RC) {
case dxil::ResourceClass::SRV:
return {"SRV", "t"};
case dxil::ResourceClass::UAV:
return {"UAV", "u"};
case dxil::ResourceClass::CBuffer:
return {"cbuffer", "cb"};
case dxil::ResourceClass::Sampler:
return {"sampler", "s"};
}
llvm_unreachable("covered switch");
}
```
https://github.com/llvm/llvm-project/pull/104448
More information about the llvm-branch-commits
mailing list