[llvm] [DXIL][Analysis] Implement enough of DXILResourceAnalysis for buffers (PR #100699)

Mehdi Amini via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 15 13:47:47 PDT 2024


================
@@ -8,16 +8,146 @@
 
 #include "llvm/Analysis/DXILResource.h"
 #include "llvm/ADT/APInt.h"
+#include "llvm/IR/Constants.h"
 #include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/DiagnosticInfo.h"
 #include "llvm/IR/Instructions.h"
+#include "llvm/IR/Intrinsics.h"
+#include "llvm/IR/IntrinsicsDirectX.h"
 #include "llvm/IR/Metadata.h"
+#include "llvm/IR/Module.h"
 #include "llvm/InitializePasses.h"
 
 #define DEBUG_TYPE "dxil-resource"
 
 using namespace llvm;
 using namespace dxil;
 
+static constexpr StringRef getResourceClassName(ResourceClass RC) {
+  switch (RC) {
+  case ResourceClass::SRV:
+    return "SRV";
+  case ResourceClass::UAV:
+    return "UAV";
+  case ResourceClass::CBuffer:
+    return "CBuffer";
+  case ResourceClass::Sampler:
+    return "Sampler";
+  }
+  llvm_unreachable("Unhandled ResourceClass");
+}
+
+static constexpr StringRef getResourceKindName(ResourceKind RK) {
+  switch (RK) {
+  case ResourceKind::Texture1D:
+    return "Texture1D";
+  case ResourceKind::Texture2D:
+    return "Texture2D";
+  case ResourceKind::Texture2DMS:
+    return "Texture2DMS";
+  case ResourceKind::Texture3D:
+    return "Texture3D";
+  case ResourceKind::TextureCube:
+    return "TextureCube";
+  case ResourceKind::Texture1DArray:
+    return "Texture1DArray";
+  case ResourceKind::Texture2DArray:
+    return "Texture2DArray";
+  case ResourceKind::Texture2DMSArray:
+    return "Texture2DMSArray";
+  case ResourceKind::TextureCubeArray:
+    return "TextureCubeArray";
+  case ResourceKind::TypedBuffer:
+    return "TypedBuffer";
+  case ResourceKind::RawBuffer:
+    return "RawBuffer";
+  case ResourceKind::StructuredBuffer:
+    return "StructuredBuffer";
+  case ResourceKind::CBuffer:
+    return "CBuffer";
+  case ResourceKind::Sampler:
+    return "Sampler";
+  case ResourceKind::TBuffer:
+    return "TBuffer";
+  case ResourceKind::RTAccelerationStructure:
+    return "RTAccelerationStructure";
+  case ResourceKind::FeedbackTexture2D:
+    return "FeedbackTexture2D";
+  case ResourceKind::FeedbackTexture2DArray:
+    return "FeedbackTexture2DArray";
+  case ResourceKind::NumEntries:
+  case ResourceKind::Invalid:
+    return "<invalid>";
+  }
+  llvm_unreachable("Unhandled ResourceKind");
+}
+
+static constexpr StringRef getElementTypeName(ElementType ET) {
+  switch (ET) {
+  case ElementType::I1:
+    return "i1";
+  case ElementType::I16:
+    return "i16";
+  case ElementType::U16:
+    return "u16";
+  case ElementType::I32:
+    return "i32";
+  case ElementType::U32:
+    return "u32";
+  case ElementType::I64:
+    return "i64";
+  case ElementType::U64:
+    return "u64";
+  case ElementType::F16:
+    return "f16";
+  case ElementType::F32:
+    return "f32";
+  case ElementType::F64:
+    return "f64";
+  case ElementType::SNormF16:
+    return "snorm_f16";
+  case ElementType::UNormF16:
+    return "unorm_f16";
+  case ElementType::SNormF32:
+    return "snorm_f32";
+  case ElementType::UNormF32:
+    return "unorm_f32";
+  case ElementType::SNormF64:
+    return "snorm_f64";
+  case ElementType::UNormF64:
+    return "unorm_f64";
+  case ElementType::PackedS8x32:
+    return "p32i8";
+  case ElementType::PackedU8x32:
+    return "p32u8";
+  case ElementType::Invalid:
+    return "<invalid>";
+  }
+  llvm_unreachable("Unhandled ElementType");
----------------
joker-eph wrote:

This fails with GCC 7:

```
/vol/worker/mlir-nvidia/mlir-nvidia-gcc7/llvm.src/llvm/lib/Analysis/DXILResource.cpp: In function ‘constexpr llvm::StringRef getElementTypeName(llvm::dxil::ElementType)’:
/vol/worker/mlir-nvidia/mlir-nvidia-gcc7/llvm.src/llvm/include/llvm/Support/ErrorHandling.h:144:36: error: call to non-constexpr function ‘void llvm::llvm_unreachable_internal(const char*, const char*, unsigned int)’
   ::llvm::llvm_unreachable_internal(msg, __FILE__, __LINE__)
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/vol/worker/mlir-nvidia/mlir-nvidia-gcc7/llvm.src/llvm/lib/Analysis/DXILResource.cpp:126:3: note: in expansion of macro ‘llvm_unreachable’
   llvm_unreachable("Unhandled ElementType");
   ^~~~~~~~~~~~~~~~
```

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


More information about the llvm-commits mailing list