[llvm] [SPIR-V] Parse parameterized Memory Access operands with a shared helper (PR #209262)

Dmitry Sidorov via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 14 04:59:37 PDT 2026


================
@@ -113,6 +113,42 @@ void SPIRVInstPrinter::printOpConstantVarOps(const MCInst *MI,
   O << Imm;
 }
 
+unsigned SPIRVInstPrinter::printMemoryOperand(const MCInst *MI, unsigned OpNo,
+                                              raw_ostream &O) {
+  O << ' ';
+  if (OpNo >= MI->getNumOperands())
+    return OpNo;
+  const uint64_t Mask = MI->getOperand(OpNo).getImm();
+  printSymbolicOperand<OperandCategory::MemoryOperandOperand>(MI, OpNo, O);
+  unsigned NextOp = OpNo + 1;
+  if (Mask & SPIRV::MemoryOperand::Aligned) {
+    O << ' ';
+    printOperand(MI, NextOp, O);
+    ++NextOp;
+  }
+  if (Mask & SPIRV::MemoryOperand::MakePointerAvailableKHR) {
+    O << ' ';
+    printOperand(MI, NextOp, O);
+    ++NextOp;
+  }
+  if (Mask & SPIRV::MemoryOperand::MakePointerVisibleKHR) {
+    O << ' ';
+    printOperand(MI, NextOp, O);
+    ++NextOp;
+  }
+  if (Mask & SPIRV::MemoryOperand::AliasScopeINTELMask) {
+    O << ' ';
+    printOperand(MI, NextOp, O);
+    ++NextOp;
+  }
+  if (Mask & SPIRV::MemoryOperand::NoAliasINTELMask) {
+    O << ' ';
+    printOperand(MI, NextOp, O);
+    ++NextOp;
+  }
+  return NextOp;
+}
----------------
MrSidims wrote:

Iterating in one place and incrementing iterator in another is looking very fragile.

Lets imagine in the future in SPIR-V spec will be added another memory operand mask which makes an instruction accepting yet another literal operand. This memory operand was implemented with a bug and somehow we made it this far. In such case the loop block on L289 will be executed once more time re-processing all of the already processed masks, duplicating printed operands and making the iterator be out of bound.

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


More information about the llvm-commits mailing list