dxil: finish renumbers instructions in place
finish passed each instruction to remapInst by value, got it back by value and appended that: three copies of 48 bytes per instruction lowered. It now copies each once, into its place, and renumbers there. The hill-climbing set: -3.8% (A/B); output unchanged on the verify corpus.
This commit is contained in:
parent
69b33c2af2
commit
0634987f5e
|
|
@ -1497,8 +1497,17 @@ const Emitter = struct {
|
||||||
};
|
};
|
||||||
stats.add(.dxil_lowered, n);
|
stats.add(.dxil_lowered, n);
|
||||||
try f.insts.ensureUnusedCapacity(e.dm.allocator(), n);
|
try f.insts.ensureUnusedCapacity(e.dm.allocator(), n);
|
||||||
for (e.prologue.items) |id| f.insts.appendAssumeCapacity(try remapInst(e.arena, map, e.insts.at(id).*, remap));
|
// (Copied into place, then renumbered there.)
|
||||||
for (e.blocks.items) |blk| for (blk.items) |id| f.insts.appendAssumeCapacity(try remapInst(e.arena, map, e.insts.at(id).*, remap));
|
for (e.prologue.items) |id| {
|
||||||
|
const dst = f.insts.addOneAssumeCapacity();
|
||||||
|
dst.* = e.insts.at(id).*;
|
||||||
|
try remapInst(e.arena, map, dst, remap);
|
||||||
|
}
|
||||||
|
for (e.blocks.items) |blk| for (blk.items) |id| {
|
||||||
|
const dst = f.insts.addOneAssumeCapacity();
|
||||||
|
dst.* = e.insts.at(id).*;
|
||||||
|
try remapInst(e.arena, map, dst, remap);
|
||||||
|
};
|
||||||
var ranges: std.AutoHashMapUnmanaged(u32, [2]u32) = .empty;
|
var ranges: std.AutoHashMapUnmanaged(u32, [2]u32) = .empty;
|
||||||
var it = e.dyn_ranges.iterator();
|
var it = e.dyn_ranges.iterator();
|
||||||
while (it.next()) |kv| try ranges.put(e.arena, map[kv.key_ptr.*], kv.value_ptr.*);
|
while (it.next()) |kv| try ranges.put(e.arena, map[kv.key_ptr.*], kv.value_ptr.*);
|
||||||
|
|
@ -1564,11 +1573,11 @@ const Emitter = struct {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
M.u = used;
|
M.u = used;
|
||||||
_ = remapInst(a, &.{}, inst, M) catch {};
|
var copy = inst;
|
||||||
|
remapInst(a, &.{}, ©, M) catch {};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remapInst(a: Allocator, map: []const u32, inst: module.Inst, comptime R: type) Allocator.Error!module.Inst {
|
fn remapInst(a: Allocator, map: []const u32, out: *module.Inst, comptime R: type) Allocator.Error!void {
|
||||||
var out = inst;
|
|
||||||
switch (out.op) {
|
switch (out.op) {
|
||||||
.ret => |*v| if (v.*) |x| {
|
.ret => |*v| if (v.*) |x| {
|
||||||
v.* = R.v(map, x);
|
v.* = R.v(map, x);
|
||||||
|
|
@ -1628,7 +1637,6 @@ const Emitter = struct {
|
||||||
x.index = R.v(map, x.index);
|
x.index = R.v(map, x.index);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue