Skip to content

Commit 6bb6013

Browse files
authored
Merge pull request ziglang#24768 from alichraghi/spv5
spirv: remove prune_unused ISel
2 parents 2983285 + 64563e2 commit 6bb6013

File tree

15 files changed

+154
-484
lines changed

15 files changed

+154
-484
lines changed

src/codegen/spirv/CodeGen.zig

Lines changed: 96 additions & 105 deletions
Large diffs are not rendered by default.

src/codegen/spirv/Module.zig

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -676,8 +676,9 @@ pub fn structType(
676676
ip_index: InternPool.Index,
677677
) !Id {
678678
const target = module.zcu.getTarget();
679+
const actual_ip_index = if (module.zcu.comp.config.root_strip) .none else ip_index;
679680

680-
if (module.cache.struct_types.get(.{ .fields = types, .ip_index = ip_index })) |id| return id;
681+
if (module.cache.struct_types.get(.{ .fields = types, .ip_index = actual_ip_index })) |id| return id;
681682
const result_id = module.allocId();
682683
const types_dup = try module.arena.dupe(Id, types);
683684
try module.sections.globals.emit(module.gpa, .OpTypeStruct, .{
@@ -710,10 +711,7 @@ pub fn structType(
710711

711712
try module.cache.struct_types.put(
712713
module.gpa,
713-
.{
714-
.fields = types_dup,
715-
.ip_index = if (module.zcu.comp.config.root_strip) .none else ip_index,
716-
},
714+
.{ .fields = types_dup, .ip_index = actual_ip_index },
717715
result_id,
718716
);
719717
return result_id;
@@ -874,19 +872,22 @@ pub fn declareEntryPoint(
874872
}
875873

876874
pub fn debugName(module: *Module, target: Id, name: []const u8) !void {
875+
if (module.zcu.comp.config.root_strip) return;
877876
try module.sections.debug_names.emit(module.gpa, .OpName, .{
878877
.target = target,
879878
.name = name,
880879
});
881880
}
882881

883882
pub fn debugNameFmt(module: *Module, target: Id, comptime fmt: []const u8, args: anytype) !void {
883+
if (module.zcu.comp.config.root_strip) return;
884884
const name = try std.fmt.allocPrint(module.gpa, fmt, args);
885885
defer module.gpa.free(name);
886886
try module.debugName(target, name);
887887
}
888888

889889
pub fn memberDebugName(module: *Module, target: Id, member: u32, name: []const u8) !void {
890+
if (module.zcu.comp.config.root_strip) return;
890891
try module.sections.debug_names.emit(module.gpa, .OpMemberName, .{
891892
.type = target,
892893
.member = member,

src/link/SpirV.zig

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ const Compilation = @import("../Compilation.zig");
1010
const link = @import("../link.zig");
1111
const Air = @import("../Air.zig");
1212
const Type = @import("../Type.zig");
13-
const BinaryModule = @import("SpirV/BinaryModule.zig");
1413
const CodeGen = @import("../codegen/spirv/CodeGen.zig");
1514
const Module = @import("../codegen/spirv/Module.zig");
1615
const trace = @import("../tracy.zig").trace;
16+
const BinaryModule = @import("SpirV/BinaryModule.zig");
17+
const lower_invocation_globals = @import("SpirV/lower_invocation_globals.zig");
1718

1819
const spec = @import("../codegen/spirv/spec.zig");
1920
const Id = spec.Id;
@@ -279,7 +280,7 @@ pub fn flush(
279280
const module = try linker.module.finalize(arena);
280281
errdefer arena.free(module);
281282

282-
const linked_module = linker.linkModule(arena, module, sub_prog_node) catch |err| switch (err) {
283+
const linked_module = linkModule(arena, module, sub_prog_node) catch |err| switch (err) {
283284
error.OutOfMemory => return error.OutOfMemory,
284285
else => |other| return diags.fail("error while linking: {s}", .{@errorName(other)}),
285286
};
@@ -288,18 +289,10 @@ pub fn flush(
288289
return diags.fail("failed to write: {s}", .{@errorName(err)});
289290
}
290291

291-
fn linkModule(linker: *Linker, arena: Allocator, module: []Word, progress: std.Progress.Node) ![]Word {
292-
_ = linker;
293-
294-
const lower_invocation_globals = @import("SpirV/lower_invocation_globals.zig");
295-
const prune_unused = @import("SpirV/prune_unused.zig");
296-
292+
fn linkModule(arena: Allocator, module: []Word, progress: std.Progress.Node) ![]Word {
297293
var parser = try BinaryModule.Parser.init(arena);
298294
defer parser.deinit();
299295
var binary = try parser.parse(module);
300-
301296
try lower_invocation_globals.run(&parser, &binary, progress);
302-
try prune_unused.run(&parser, &binary, progress);
303-
304297
return binary.finalize(arena);
305298
}

src/link/SpirV/lower_invocation_globals.zig

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,15 @@ const ModuleBuilder = struct {
382382
var it = binary.iterateInstructions();
383383
while (it.next()) |inst| {
384384
switch (inst.opcode) {
385+
.OpName => {
386+
const id: ResultId = @enumFromInt(inst.operands[0]);
387+
if (info.invocation_globals.contains(id)) continue;
388+
},
389+
.OpExtInstImport => {
390+
const set_id: ResultId = @enumFromInt(inst.operands[0]);
391+
const set = binary.ext_inst_map.get(set_id).?;
392+
if (set == .zig) continue;
393+
},
385394
.OpExtInst => {
386395
const set_id: ResultId = @enumFromInt(inst.operands[2]);
387396
const set_inst = inst.operands[3];
@@ -482,7 +491,7 @@ const ModuleBuilder = struct {
482491
return entry.value_ptr.*;
483492
}
484493

485-
/// Rewrite the modules' functions and emit them with the new parameter types.
494+
/// Rewrite the modules functions and emit them with the new parameter types.
486495
fn rewriteFunctions(
487496
self: *ModuleBuilder,
488497
parser: *BinaryModule.Parser,

0 commit comments

Comments
 (0)