authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2023-09-21 23:02:53+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-09-23 12:36:56-07:00
log572517376a7695693c59a0ec4ec6cc5442003e3a
tree6b93537b4f022f84e3646598b9af6721258969bc
parent68c7fc5c595b4a48f95b3f2f8c4d0a6c3a388667

spirv: air dbg_var_val and dbg_var_ptr


3 files changed, 26 insertions(+), 30 deletions(-)

src/codegen/spirv.zig+14-20
......@@ -1474,10 +1474,7 @@ pub const DeclGen = struct {
14741474 try self.spv.addFunction(spv_decl_index, self.func);
14751475
14761476 const fqn = ip.stringToSlice(try decl.getFullyQualifiedName(self.module));
1477 try self.spv.sections.debug_names.emit(self.gpa, .OpName, .{
1478 .target = decl_id,
1479 .name = fqn,
1480 });
1477 try self.spv.debugName(decl_id, fqn);
14811478
14821479 // Temporarily generate a test kernel declaration if this is a test function.
14831480 if (self.module.test_functions.contains(self.decl_index)) {
......@@ -1548,17 +1545,8 @@ pub const DeclGen = struct {
15481545 try self.spv.addFunction(spv_decl_index, self.func);
15491546
15501547 const fqn = ip.stringToSlice(try decl.getFullyQualifiedName(self.module));
1551 try self.spv.sections.debug_names.emit(self.gpa, .OpName, .{
1552 .target = decl_id,
1553 .name = fqn,
1554 });
1555
1556 const init_name = try std.fmt.allocPrint(self.gpa, "initializer of {s}", .{fqn});
1557 defer self.gpa.free(init_name);
1558 try self.spv.sections.debug_names.emit(self.gpa, .OpName, .{
1559 .target = initializer_id,
1560 .name = init_name,
1561 });
1548 try self.spv.debugName(decl_id, fqn);
1549 try self.spv.debugNameFmt(initializer_id, "initializer of {s}", .{fqn});
15621550 }
15631551 }
15641552
......@@ -1756,11 +1744,10 @@ pub const DeclGen = struct {
17561744 .switch_br => return self.airSwitchBr(inst),
17571745 .unreach, .trap => return self.airUnreach(),
17581746
1759 .dbg_stmt => return self.airDbgStmt(inst),
1760 .dbg_inline_begin => return self.airDbgInlineBegin(inst),
1761 .dbg_inline_end => return self.airDbgInlineEnd(inst),
1762 .dbg_var_ptr => return,
1763 .dbg_var_val => return,
1747 .dbg_stmt => return self.airDbgStmt(inst),
1748 .dbg_inline_begin => return self.airDbgInlineBegin(inst),
1749 .dbg_inline_end => return self.airDbgInlineEnd(inst),
1750 .dbg_var_ptr, .dbg_var_val => return self.airDbgVar(inst),
17641751 .dbg_block_begin => return,
17651752 .dbg_block_end => return,
17661753
......@@ -3566,6 +3553,13 @@ pub const DeclGen = struct {
35663553 _ = self.base_line_stack.pop();
35673554 }
35683555
3556 fn airDbgVar(self: *DeclGen, inst: Air.Inst.Index) !void {
3557 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
3558 const target_id = try self.resolve(pl_op.operand);
3559 const name = self.air.nullTerminatedString(pl_op.payload);
3560 try self.spv.debugName(target_id, name);
3561 }
3562
35693563 fn airAssembly(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
35703564 const mod = self.module;
35713565 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
src/codegen/spirv/Cache.zig+6-6
......@@ -462,11 +462,11 @@ fn emit(
462462 switch (key) {
463463 .void_type => {
464464 try section.emit(spv.gpa, .OpTypeVoid, .{ .id_result = result_id });
465 try spv.debugName(result_id, "void", .{});
465 try spv.debugName(result_id, "void");
466466 },
467467 .bool_type => {
468468 try section.emit(spv.gpa, .OpTypeBool, .{ .id_result = result_id });
469 try spv.debugName(result_id, "bool", .{});
469 try spv.debugName(result_id, "bool");
470470 },
471471 .int_type => |int| {
472472 try section.emit(spv.gpa, .OpTypeInt, .{
......@@ -481,14 +481,14 @@ fn emit(
481481 .unsigned => "u",
482482 .signed => "i",
483483 };
484 try spv.debugName(result_id, "{s}{}", .{ ui, int.bits });
484 try spv.debugNameFmt(result_id, "{s}{}", .{ ui, int.bits });
485485 },
486486 .float_type => |float| {
487487 try section.emit(spv.gpa, .OpTypeFloat, .{
488488 .id_result = result_id,
489489 .width = float.bits,
490490 });
491 try spv.debugName(result_id, "f{}", .{float.bits});
491 try spv.debugNameFmt(result_id, "f{}", .{float.bits});
492492 },
493493 .vector_type => |vector| {
494494 try section.emit(spv.gpa, .OpTypeVector, .{
......@@ -530,11 +530,11 @@ fn emit(
530530 section.writeOperand(IdResult, self.resultId(member_type));
531531 }
532532 if (self.getString(struct_type.name)) |name| {
533 try spv.debugName(result_id, "{s}", .{name});
533 try spv.debugName(result_id, name);
534534 }
535535 for (struct_type.memberNames(), 0..) |member_name, i| {
536536 if (self.getString(member_name)) |name| {
537 try spv.memberDebugName(result_id, @as(u32, @intCast(i)), "{s}", .{name});
537 try spv.memberDebugName(result_id, @as(u32, @intCast(i)), name);
538538 }
539539 }
540540 // TODO: Decorations?
src/codegen/spirv/Module.zig+6-4
......@@ -645,18 +645,20 @@ pub fn declareEntryPoint(self: *Module, decl_index: Decl.Index, name: []const u8
645645 });
646646}
647647
648pub fn debugName(self: *Module, target: IdResult, comptime fmt: []const u8, args: anytype) !void {
649 const name = try std.fmt.allocPrint(self.gpa, fmt, args);
650 defer self.gpa.free(name);
648pub fn debugName(self: *Module, target: IdResult, name: []const u8) !void {
651649 try self.sections.debug_names.emit(self.gpa, .OpName, .{
652650 .target = target,
653651 .name = name,
654652 });
655653}
656654
657pub fn memberDebugName(self: *Module, target: IdResult, member: u32, comptime fmt: []const u8, args: anytype) !void {
655pub fn debugNameFmt(self: *Module, target: IdResult, comptime fmt: []const u8, args: anytype) !void {
658656 const name = try std.fmt.allocPrint(self.gpa, fmt, args);
659657 defer self.gpa.free(name);
658 try self.debugName(target, name);
659}
660
661pub fn memberDebugName(self: *Module, target: IdResult, member: u32, name: []const u8) !void {
660662 try self.sections.debug_names.emit(self.gpa, .OpMemberName, .{
661663 .type = target,
662664 .member = member,