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

Cassandra Beckley via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 3 10:56:09 PST 2025


================
@@ -2868,6 +2868,61 @@ static SPIRVType *getSampledImageType(const TargetExtType *OpaqueType,
   return GR->getOrCreateOpTypeSampledImage(OpaqueImageType, MIRBuilder);
 }
 
+static SPIRVType *getInlineSpirvType(const TargetExtType *ExtensionType,
+                                     MachineIRBuilder &MIRBuilder,
+                                     SPIRVGlobalRegistry *GR) {
+  assert(ExtensionType->getNumIntParameters() == 3 &&
+         "Inline SPIR-V type builtin takes an opcode, size, and alignment "
+         "parameter");
+  auto Opcode = ExtensionType->getIntParameter(0);
+
+  return GR->getOrCreateUnknownType(
+      ExtensionType, MIRBuilder, Opcode,
+      [&ExtensionType, &GR, &MIRBuilder](llvm::MachineInstrBuilder Instr) {
+        for (llvm::Type *Param : ExtensionType->type_params()) {
+          if (const TargetExtType *ParamEType =
+                  dyn_cast<TargetExtType>(Param)) {
+            if (ParamEType->getName() == "spirv.IntegralConstant") {
+              assert(ParamEType->getNumTypeParameters() == 1 &&
+                     "Inline SPIR-V integral constant builtin must have a type "
+                     "parameter");
+              assert(ParamEType->getNumIntParameters() == 1 &&
+                     "Inline SPIR-V integral constant builtin must have a "
+                     "value parameter");
+
+              auto OperandValue = ParamEType->getIntParameter(0);
+              auto *OperandType = ParamEType->getTypeParameter(0);
+
+              const SPIRVType *OperandSPIRVType =
+                  GR->getOrCreateSPIRVType(OperandType, MIRBuilder);
+
+              Instr = Instr.addUse(GR->buildConstantInt(
+                  OperandValue, MIRBuilder, OperandSPIRVType, true));
+              continue;
+            } else if (ParamEType->getName() == "spirv.Literal") {
+              assert(ParamEType->getNumTypeParameters() == 0 &&
+                     "Inline SPIR-V literal builtin does not take type "
+                     "parameters");
+              assert(ParamEType->getNumIntParameters() == 1 &&
+                     "Inline SPIR-V literal builtin must have an integer "
+                     "parameter");
+
+              auto OperandValue = ParamEType->getIntParameter(0);
+
+              Instr = Instr.addImm(OperandValue);
+              continue;
+            }
+          }
+          const SPIRVType *TypeOperand =
+              GR->getOrCreateSPIRVType(Param, MIRBuilder);
+          Instr = Instr.addUse(GR->getSPIRVTypeID(TypeOperand));
+        }
+        return Instr;
+      });
+
+  // GR->getOrCreateSPIRVArrayType();
----------------
cassiebeckley wrote:

Yes, thanks.

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


More information about the llvm-commits mailing list