dxil: instruction metadata out of line (instructions 56 -> 48 bytes)
Few instructions carry metadata (!dx.nonuniform), but each had room for an optional (kind, node) pair. It is now an index into Module.inst_mds, and every pass moves 14% less memory. The hill-climbing set: -2.1%; output unchanged on the verify corpus.
This commit is contained in:
parent
dfb629ace0
commit
5019d2b838
|
|
@ -4033,7 +4033,8 @@ const Emitter = struct {
|
||||||
const ptr = try e.add(try e.dm.ptrType(class_ty), .{ .gep = .{ .elem = arr_ty, .ptr = .{ .global = lg }, .indices = try e.arena.dupe(Value, &.{ try e.i32Const(0), index }) } });
|
const ptr = try e.add(try e.dm.ptrType(class_ty), .{ .gep = .{ .elem = arr_ty, .ptr = .{ .global = lg }, .indices = try e.arena.dupe(Value, &.{ try e.i32Const(0), index }) } });
|
||||||
if (nonuniform) {
|
if (nonuniform) {
|
||||||
const blk = e.blocks.items[e.cur].items;
|
const blk = e.blocks.items[e.cur].items;
|
||||||
e.insts.at(blk[blk.len - 1]).md = .{ .kind = try e.dm.mdKind("dx.nonuniform"), .node = try e.dm.mdNode(&.{try e.dm.mdI32(1)}) };
|
const kind = try e.dm.mdKind("dx.nonuniform");
|
||||||
|
e.insts.at(blk[blk.len - 1]).md = try e.dm.instMd(kind, try e.dm.mdNode(&.{try e.dm.mdI32(1)}));
|
||||||
}
|
}
|
||||||
const loaded = try e.add(class_ty, .{ .load = .{ .ptr = ptr, .@"align" = 4 } });
|
const loaded = try e.add(class_ty, .{ .load = .{ .ptr = ptr, .@"align" = 4 } });
|
||||||
const struct_name = e.dm.types.items[class_ty].@"struct".name;
|
const struct_name = e.dm.types.items[class_ty].@"struct".name;
|
||||||
|
|
|
||||||
|
|
@ -159,11 +159,15 @@ pub const Inst = struct {
|
||||||
extractelement: struct { vec: Value, index: Value },
|
extractelement: struct { vec: Value, index: Value },
|
||||||
insertelement: struct { vec: Value, val: Value, index: Value },
|
insertelement: struct { vec: Value, val: Value, index: Value },
|
||||||
},
|
},
|
||||||
/// An attached metadata node (`kind` from Module.mdKind), as
|
/// An attached metadata node, as `!dx.nonuniform` on a resource
|
||||||
/// `!dx.nonuniform` on a resource array's getelementptr.
|
/// array's getelementptr (see Module.instMd).
|
||||||
md: ?struct { kind: u32, node: MdId } = null,
|
md: InstMd = .none,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// An instruction's metadata attachment: an index into Module.inst_mds,
|
||||||
|
/// kept out of line (few instructions have one).
|
||||||
|
pub const InstMd = enum(u32) { none = 0, _ };
|
||||||
|
|
||||||
pub const Function = struct {
|
pub const Function = struct {
|
||||||
name: []const u8,
|
name: []const u8,
|
||||||
ty: TypeId,
|
ty: TypeId,
|
||||||
|
|
@ -199,6 +203,8 @@ pub const Module = struct {
|
||||||
globals: std.ArrayList(GlobalVar) = .empty,
|
globals: std.ArrayList(GlobalVar) = .empty,
|
||||||
metadata: std.ArrayList(Metadata) = .empty,
|
metadata: std.ArrayList(Metadata) = .empty,
|
||||||
named_metadata: std.ArrayList(struct { name: []const u8, nodes: []const MdId }) = .empty,
|
named_metadata: std.ArrayList(struct { name: []const u8, nodes: []const MdId }) = .empty,
|
||||||
|
/// Instruction metadata attachments (InstMd), from 1.
|
||||||
|
inst_mds: std.ArrayList(struct { kind: u32, node: MdId }) = .empty,
|
||||||
/// Instruction metadata kinds, by id.
|
/// Instruction metadata kinds, by id.
|
||||||
md_kinds: std.ArrayList([]const u8) = .empty,
|
md_kinds: std.ArrayList([]const u8) = .empty,
|
||||||
|
|
||||||
|
|
@ -285,6 +291,12 @@ pub const Module = struct {
|
||||||
return m.constant(.{ .ty = try m.intType(bits), .kind = .{ .int = v } });
|
return m.constant(.{ .ty = try m.intType(bits), .kind = .{ .int = v } });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// An attachment of node `node` as metadata kind `kind` (from mdKind).
|
||||||
|
pub fn instMd(m: *Module, kind: u32, node: MdId) !InstMd {
|
||||||
|
try m.inst_mds.append(m.allocator(), .{ .kind = kind, .node = node });
|
||||||
|
return @fromBackingInt(@intCast(m.inst_mds.items.len));
|
||||||
|
}
|
||||||
|
|
||||||
pub fn addFunction(m: *Module, f: Function) !u32 {
|
pub fn addFunction(m: *Module, f: Function) !u32 {
|
||||||
var owned = f;
|
var owned = f;
|
||||||
owned.name = try m.allocator().dupe(u8, f.name);
|
owned.name = try m.allocator().dupe(u8, f.name);
|
||||||
|
|
@ -776,10 +788,11 @@ const Encoder = struct {
|
||||||
}
|
}
|
||||||
// METADATA_ATTACHMENT: [instruction index, (kind, node)...]
|
// METADATA_ATTACHMENT: [instruction index, (kind, node)...]
|
||||||
var any_md = false;
|
var any_md = false;
|
||||||
for (f.insts.items) |inst| any_md = any_md or inst.md != null;
|
for (f.insts.items) |inst| any_md = any_md or inst.md != .none;
|
||||||
if (any_md) {
|
if (any_md) {
|
||||||
try w.enterBlock(block_metadata_attachment, 3);
|
try w.enterBlock(block_metadata_attachment, 3);
|
||||||
for (f.insts.items, 0..) |inst, k| if (inst.md) |md| {
|
for (f.insts.items, 0..) |inst, k| if (inst.md != .none) {
|
||||||
|
const md = e.m.inst_mds.items[@backingInt(inst.md) - 1];
|
||||||
try e.ops.appendSlice(e.gpa(), &.{ k, md.kind, md.node });
|
try e.ops.appendSlice(e.gpa(), &.{ k, md.kind, md.node });
|
||||||
try e.rec(11);
|
try e.rec(11);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue