spirv: make decl deps a hash map instead of an arraylist

The same declaration can be added to the dependency set multiple
times, and in this case we still need to emit it once. By making
this list a hash map instead, we can do that quite easily.

This commit also introduces some additional debug logging regarding
decls.
This commit is contained in:
Robin Voetter
2023-04-22 11:18:58 +02:00
parent d961b11cde
commit e26d8d0604
2 changed files with 15 additions and 12 deletions

View File

@@ -40,14 +40,14 @@ pub const Fn = struct {
/// the end of this function definition.
body: Section = .{},
/// The decl dependencies that this function depends on.
decl_deps: std.ArrayListUnmanaged(Decl.Index) = .{},
decl_deps: std.AutoArrayHashMapUnmanaged(Decl.Index, void) = .{},
/// Reset this function without deallocating resources, so that
/// it may be used to emit code for another function.
pub fn reset(self: *Fn) void {
self.prologue.reset();
self.body.reset();
self.decl_deps.items.len = 0;
self.decl_deps.clearRetainingCapacity();
}
/// Free the resources owned by this function.
@@ -358,7 +358,7 @@ pub fn flush(self: *Module, file: std.fs.File) !void {
pub fn addFunction(self: *Module, decl_index: Decl.Index, func: Fn) !void {
try self.sections.functions.append(self.gpa, func.prologue);
try self.sections.functions.append(self.gpa, func.body);
try self.declareDeclDeps(decl_index, func.decl_deps.items);
try self.declareDeclDeps(decl_index, func.decl_deps.keys());
}
/// Fetch the result-id of an OpString instruction that encodes the path of the source