[llvm] [SPIRV] Emit NonSemantic DebugDeclare, DebugExpression and DebugOperation (PR #222011)

Manuel Carrasco via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 11 06:12:49 PDT 2026


================
@@ -842,10 +846,82 @@ std::optional<MCRegister> SPIRVNonSemanticDebugHandler::mapDISignatureTypeToReg(
   return lookupOptReg(DebugScopeRegs, Ty);
 }
 
-// Unimplemented no-op; see emitDebugExpression declaration.
+// NonSemantic.Shader.DebugInfo.100 debug operation encodings
+// (section 4.5, "Debug Operations").
+namespace NonSemanticDebugOp {
+enum : uint32_t {
+  Deref = 0,
+  Plus = 1,
+  Minus = 2,
+  PlusUconst = 3,
+  BitPiece = 4,
+  Swap = 5,
+  Xderef = 6,
+  StackValue = 7,
+  Constu = 8,
+  Fragment = 9
+};
+} // namespace NonSemanticDebugOp
+
+static std::optional<uint32_t> mapDwarfOpToNonSemanticOp(uint64_t DwarfOp) {
+  switch (DwarfOp) {
+  case dwarf::DW_OP_deref:
+    return NonSemanticDebugOp::Deref;
+  case dwarf::DW_OP_plus:
+    return NonSemanticDebugOp::Plus;
+  case dwarf::DW_OP_minus:
+    return NonSemanticDebugOp::Minus;
+  case dwarf::DW_OP_plus_uconst:
+    return NonSemanticDebugOp::PlusUconst;
+  case dwarf::DW_OP_bit_piece:
+    return NonSemanticDebugOp::BitPiece;
+  case dwarf::DW_OP_swap:
+    return NonSemanticDebugOp::Swap;
+  case dwarf::DW_OP_xderef:
+    return NonSemanticDebugOp::Xderef;
+  case dwarf::DW_OP_stack_value:
+    return NonSemanticDebugOp::StackValue;
+  case dwarf::DW_OP_constu:
+    return NonSemanticDebugOp::Constu;
+  case dwarf::DW_OP_LLVM_fragment:
+    return NonSemanticDebugOp::Fragment;
+  default:
+    return std::nullopt;
+  }
+}
+
 std::optional<MCRegister> SPIRVNonSemanticDebugHandler::emitDebugExpression(
-    const DIExpression *, MCRegister, MCRegister, SPIRV::ModuleAnalysisInfo &) {
-  return std::nullopt;
+    const DIExpression *Expr, MCRegister VoidTypeReg, MCRegister I32TypeReg,
+    MCRegister ExtInstSetReg, SPIRV::ModuleAnalysisInfo &MAI) {
+  assert(Expr && "Expr must not be null in emitDebugExpression");
+
+  // Check the whole expression before emitting anything, and bail out if
+  // unsupported. Verify that the operation is supported, and that each argument
+  // is a 32-bit constant (as per spec).
+  for (const DIExpression::ExprOperand &Op : Expr->expr_ops()) {
+    if (!mapDwarfOpToNonSemanticOp(Op.getOp()))
+      return std::nullopt;
----------------
mgcarrasco wrote:

I've simplified the code after implementing caching for DebugOperation and DebugExpression.  The original code was over-engineering the unhappy case, now there is no such handling. This case is no longer in the new version. Let me know if you prefer otherwise!

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


More information about the llvm-commits mailing list