[Mlir-commits] [mlir] [mlir][SPIR-V] Add CopyMemorySized support (PR #232190)

Igor Wodiany llvmlistbot at llvm.org
Tue Oct 20 02:11:14 PDT 2026


================
@@ -679,89 +679,96 @@ Deserializer::processOp<spirv::FunctionCallOp>(ArrayRef<uint32_t> operands) {
   return success();
 }
 
-template <>
-LogicalResult
-Deserializer::processOp<spirv::CopyMemoryOp>(ArrayRef<uint32_t> words) {
-  SmallVector<Type, 1> resultTypes;
-  size_t wordIndex = 0;
-  SmallVector<Value, 4> operands;
-  SmallVector<NamedAttribute, 4> attributes;
-
-  if (wordIndex < words.size()) {
-    auto arg = getValue(words[wordIndex]);
-
-    if (!arg) {
-      return emitError(unknownLoc, "unknown result <id> : ")
-             << words[wordIndex];
-    }
-
-    operands.push_back(arg);
-    wordIndex++;
+template <typename OpTy>
+LogicalResult Deserializer::processCopyMemoryOp(ArrayRef<uint32_t> words,
+                                                unsigned numValueOperands) {
+  if (words.size() < numValueOperands) {
+    return emitError(unknownLoc, "expected at least ")
+           << numValueOperands << " operands for " << OpTy::getOperationName()
+           << ", but got " << words.size();
   }
 
-  if (wordIndex < words.size()) {
-    auto arg = getValue(words[wordIndex]);
-
-    if (!arg) {
-      return emitError(unknownLoc, "unknown result <id> : ")
-             << words[wordIndex];
-    }
-
-    operands.push_back(arg);
-    wordIndex++;
+  SmallVector<Value, 3> operands;
+  for (uint32_t operandID : words.take_front(numValueOperands)) {
+    Value operand = getValue(operandID);
+    if (!operand)
+      return emitError(unknownLoc, "unknown result <id> : ") << operandID;
+    operands.push_back(operand);
   }
 
-  bool isAlignedAttr = false;
-
-  if (wordIndex < words.size()) {
-    auto attrValue = words[wordIndex++];
-    auto attr = opBuilder.getAttr<spirv::MemoryAccessAttr>(
-        static_cast<spirv::MemoryAccess>(attrValue));
-    attributes.push_back(
-        opBuilder.getNamedAttr(attributeName<MemoryAccess>(), attr));
-    isAlignedAttr = (attrValue == 2);
-  }
-
-  if (isAlignedAttr && wordIndex < words.size()) {
-    attributes.push_back(opBuilder.getNamedAttr(
-        "alignment", opBuilder.getI32IntegerAttr(words[wordIndex++])));
-  }
-
-  if (wordIndex < words.size()) {
-    auto attrValue = words[wordIndex++];
-    auto attr = opBuilder.getAttr<spirv::MemoryAccessAttr>(
-        static_cast<spirv::MemoryAccess>(attrValue));
-    attributes.push_back(opBuilder.getNamedAttr("source_memory_access", attr));
-  }
-
-  if (wordIndex < words.size()) {
+  SmallVector<NamedAttribute, 4> attributes;
+  size_t wordIndex = numValueOperands;
+  auto parseMemoryAccess = [&](StringRef memoryAccessName,
+                               StringRef alignmentName) -> LogicalResult {
+    if (wordIndex == words.size())
+      return success();
+    auto memoryAccess = static_cast<spirv::MemoryAccess>(words[wordIndex++]);
+    // Other masks require scope or alias-list operands that these ops cannot
+    // represent. Do not mistake those operands for a second memory access mask.
+    constexpr auto supported = spirv::MemoryAccess::Volatile |
+                               spirv::MemoryAccess::Aligned |
+                               spirv::MemoryAccess::Nontemporal |
+                               spirv::MemoryAccess::NonPrivatePointer;
+    if (static_cast<uint32_t>(memoryAccess) &
+        ~static_cast<uint32_t>(supported)) {
+      auto mask =
----------------
IgWod wrote:

nit: Please spell out the type.

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


More information about the Mlir-commits mailing list