| author | |
| committer | |
| log | 125d3324d982d13df02af5bbb3dfba3d07d65fff |
| tree | b65e5162cfc88cef2cd0ed07fc4ea9c4dca250d6 |
| parent | 3e388faecdb7100403d466df20086eb6781409e2 |
| signature |
4 files changed, 35 insertions(+), 8 deletions(-)
src/link/SpirV.zig+5-5| ... | ... | @@ -245,7 +245,7 @@ pub fn flushModule(self: *SpirV, arena: Allocator, prog_node: *std.Progress.Node |
| 245 | 245 | const module = try spv.finalize(arena, target); |
| 246 | 246 | errdefer arena.free(module); |
| 247 | 247 | |
| 248 | const linked_module = self.linkModule(arena, module) catch |err| switch (err) { | |
| 248 | const linked_module = self.linkModule(arena, module, &sub_prog_node) catch |err| switch (err) { | |
| 249 | 249 | error.OutOfMemory => return error.OutOfMemory, |
| 250 | 250 | else => |other| { |
| 251 | 251 | log.err("error while linking: {s}\n", .{@errorName(other)}); |
| ... | ... | @@ -256,7 +256,7 @@ pub fn flushModule(self: *SpirV, arena: Allocator, prog_node: *std.Progress.Node |
| 256 | 256 | try self.base.file.?.writeAll(std.mem.sliceAsBytes(linked_module)); |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | fn linkModule(self: *SpirV, a: Allocator, module: []Word) ![]Word { | |
| 259 | fn linkModule(self: *SpirV, a: Allocator, module: []Word, progress: *std.Progress.Node) ![]Word { | |
| 260 | 260 | _ = self; |
| 261 | 261 | |
| 262 | 262 | const lower_invocation_globals = @import("SpirV/lower_invocation_globals.zig"); |
| ... | ... | @@ -267,9 +267,9 @@ fn linkModule(self: *SpirV, a: Allocator, module: []Word) ![]Word { |
| 267 | 267 | defer parser.deinit(); |
| 268 | 268 | var binary = try parser.parse(module); |
| 269 | 269 | |
| 270 | try lower_invocation_globals.run(&parser, &binary); | |
| 271 | try prune_unused.run(&parser, &binary); | |
| 272 | try dedup.run(&parser, &binary); | |
| 270 | try lower_invocation_globals.run(&parser, &binary, progress); | |
| 271 | try prune_unused.run(&parser, &binary, progress); | |
| 272 | try dedup.run(&parser, &binary, progress); | |
| 273 | 273 | |
| 274 | 274 | return binary.finalize(a); |
| 275 | 275 | } |
src/link/SpirV/deduplicate.zig+10-1| ... | ... | @@ -363,7 +363,11 @@ const EntityHashContext = struct { |
| 363 | 363 | } |
| 364 | 364 | }; |
| 365 | 365 | |
| 366 | pub fn run(parser: *BinaryModule.Parser, binary: *BinaryModule) !void { | |
| 366 | pub fn run(parser: *BinaryModule.Parser, binary: *BinaryModule, progress: *std.Progress.Node) !void { | |
| 367 | var sub_node = progress.start("deduplicate", 0); | |
| 368 | sub_node.activate(); | |
| 369 | defer sub_node.end(); | |
| 370 | ||
| 367 | 371 | var arena = std.heap.ArenaAllocator.init(parser.a); |
| 368 | 372 | defer arena.deinit(); |
| 369 | 373 | const a = arena.allocator(); |
| ... | ... | @@ -376,6 +380,7 @@ pub fn run(parser: *BinaryModule.Parser, binary: *BinaryModule) !void { |
| 376 | 380 | .info = &info, |
| 377 | 381 | .binary = binary, |
| 378 | 382 | }; |
| 383 | ||
| 379 | 384 | for (info.entities.keys()) |id| { |
| 380 | 385 | _ = try ctx.hash(id); |
| 381 | 386 | } |
| ... | ... | @@ -395,6 +400,8 @@ pub fn run(parser: *BinaryModule.Parser, binary: *BinaryModule) !void { |
| 395 | 400 | } |
| 396 | 401 | } |
| 397 | 402 | |
| 403 | sub_node.setEstimatedTotalItems(binary.instructions.len); | |
| 404 | ||
| 398 | 405 | // Now process the module, and replace instructions where needed. |
| 399 | 406 | var section = Section{}; |
| 400 | 407 | var it = binary.iterateInstructions(); |
| ... | ... | @@ -402,6 +409,8 @@ pub fn run(parser: *BinaryModule.Parser, binary: *BinaryModule) !void { |
| 402 | 409 | var new_operands = std.ArrayList(u32).init(a); |
| 403 | 410 | var emitted_ptrs = std.AutoHashMap(ResultId, void).init(a); |
| 404 | 411 | while (it.next()) |inst| { |
| 412 | defer sub_node.setCompletedItems(inst.offset); | |
| 413 | ||
| 405 | 414 | // Result-id can only be the first or second operand |
| 406 | 415 | const inst_spec = parser.getInstSpec(inst.opcode).?; |
| 407 | 416 |
src/link/SpirV/lower_invocation_globals.zig+11-1| ... | ... | @@ -682,7 +682,11 @@ const ModuleBuilder = struct { |
| 682 | 682 | } |
| 683 | 683 | }; |
| 684 | 684 | |
| 685 | pub fn run(parser: *BinaryModule.Parser, binary: *BinaryModule) !void { | |
| 685 | pub fn run(parser: *BinaryModule.Parser, binary: *BinaryModule, progress: *std.Progress.Node) !void { | |
| 686 | var sub_node = progress.start("Lower invocation globals", 6); | |
| 687 | sub_node.activate(); | |
| 688 | defer sub_node.end(); | |
| 689 | ||
| 686 | 690 | var arena = std.heap.ArenaAllocator.init(parser.a); |
| 687 | 691 | defer arena.deinit(); |
| 688 | 692 | const a = arena.allocator(); |
| ... | ... | @@ -691,10 +695,16 @@ pub fn run(parser: *BinaryModule.Parser, binary: *BinaryModule) !void { |
| 691 | 695 | try info.resolve(a); |
| 692 | 696 | |
| 693 | 697 | var builder = try ModuleBuilder.init(a, binary.*, info); |
| 698 | sub_node.completeOne(); | |
| 694 | 699 | try builder.deriveNewFnInfo(info); |
| 700 | sub_node.completeOne(); | |
| 695 | 701 | try builder.processPreamble(binary.*, info); |
| 702 | sub_node.completeOne(); | |
| 696 | 703 | try builder.emitFunctionTypes(info); |
| 704 | sub_node.completeOne(); | |
| 697 | 705 | try builder.rewriteFunctions(parser, binary.*, info); |
| 706 | sub_node.completeOne(); | |
| 698 | 707 | try builder.emitNewEntryPoints(info); |
| 708 | sub_node.completeOne(); | |
| 699 | 709 | try builder.finalize(parser.a, binary); |
| 700 | 710 | } |
src/link/SpirV/prune_unused.zig+9-1| ... | ... | @@ -255,7 +255,11 @@ fn removeIdsFromMap(a: Allocator, map: anytype, info: ModuleInfo, alive_marker: |
| 255 | 255 | } |
| 256 | 256 | } |
| 257 | 257 | |
| 258 | pub fn run(parser: *BinaryModule.Parser, binary: *BinaryModule) !void { | |
| 258 | pub fn run(parser: *BinaryModule.Parser, binary: *BinaryModule, progress: *std.Progress.Node) !void { | |
| 259 | var sub_node = progress.start("Prune unused IDs", 0); | |
| 260 | sub_node.activate(); | |
| 261 | defer sub_node.end(); | |
| 262 | ||
| 259 | 263 | var arena = std.heap.ArenaAllocator.init(parser.a); |
| 260 | 264 | defer arena.deinit(); |
| 261 | 265 | const a = arena.allocator(); |
| ... | ... | @@ -285,9 +289,13 @@ pub fn run(parser: *BinaryModule.Parser, binary: *BinaryModule) !void { |
| 285 | 289 | |
| 286 | 290 | var section = Section{}; |
| 287 | 291 | |
| 292 | sub_node.setEstimatedTotalItems(binary.instructions.len); | |
| 293 | ||
| 288 | 294 | var new_functions_section: ?usize = null; |
| 289 | 295 | var it = binary.iterateInstructions(); |
| 290 | 296 | skip: while (it.next()) |inst| { |
| 297 | defer sub_node.setCompletedItems(inst.offset); | |
| 298 | ||
| 291 | 299 | const inst_spec = parser.getInstSpec(inst.opcode).?; |
| 292 | 300 | |
| 293 | 301 | reemit: { |