[llvm] [SPIR-V] Add support for inline SPIR-V types (PR #125316)

Vyacheslav Levytskyy via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 14 06:16:21 PST 2025


================
@@ -968,6 +968,26 @@ static TargetTypeInfo getTargetTypeInfo(const TargetExtType *Ty) {
   if (Name == "spirv.Image")
     return TargetTypeInfo(PointerType::get(C, 0), TargetExtType::CanBeGlobal,
                           TargetExtType::CanBeLocal);
+  if (Name == "spirv.Type") {
+    assert(Ty->getNumIntParameters() == 3 &&
+           "Wrong number of parameters for spirv.Type");
+
+    auto Size = Ty->getIntParameter(1);
+    auto Alignment = Ty->getIntParameter(2);
+
+    // LLVM expects variables that can be allocated to have an alignment and
+    // size. Default to using a 32-bit int as the layout type if none are
+    // present.
+    llvm::Type *LayoutType = Type::getInt32Ty(C);
+    if (Size > 0 && Alignment > 0)
+      LayoutType =
----------------
VyacheslavLevytskyy wrote:

This would just rewrite LayoutType, so probably we'd better have it as if-then-else instead of assign and re-assign in if-then?

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


More information about the llvm-commits mailing list