authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2024-10-13 01:56:33+02:00
committergravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2024-10-13 01:56:33+02:00
log3cd19b8884a48097bccc25d7b6cc8835bbc7cdd5
treec49010af16c0cb583749355b02ec971752e72c6c
parent7e530c13b3ef9b61417a610c00fc1d37c11ff7ed
signaturebadge-check Signed by SSH key SHA256:ZS52FNyUv2WUXvO4njmVaFVO46RHojFuOrxRc4LuKzg

spirv: don't try to lower types which have no runtime bits


2 files changed, 14 insertions(+), 7 deletions(-)

src/codegen/spirv.zig+13-6
......@@ -190,6 +190,7 @@ pub const Object = struct {
190190 nav_index: InternPool.Nav.Index,
191191 air: Air,
192192 liveness: Liveness,
193 do_codegen: bool,
193194 ) !void {
194195 const zcu = pt.zcu;
195196 const gpa = zcu.gpa;
......@@ -214,7 +215,7 @@ pub const Object = struct {
214215 };
215216 defer nav_gen.deinit();
216217
217 nav_gen.genNav() catch |err| switch (err) {
218 nav_gen.genNav(do_codegen) catch |err| switch (err) {
218219 error.CodegenFail => {
219220 try zcu.failed_codegen.put(gpa, nav_index, nav_gen.error_msg.?);
220221 },
......@@ -239,7 +240,7 @@ pub const Object = struct {
239240 ) !void {
240241 const nav = pt.zcu.funcInfo(func_index).owner_nav;
241242 // TODO: Separate types for generating decls and functions?
242 try self.genNav(pt, nav, air, liveness);
243 try self.genNav(pt, nav, air, liveness, true);
243244 }
244245
245246 pub fn updateNav(
......@@ -247,7 +248,7 @@ pub const Object = struct {
247248 pt: Zcu.PerThread,
248249 nav: InternPool.Nav.Index,
249250 ) !void {
250 try self.genNav(pt, nav, undefined, undefined);
251 try self.genNav(pt, nav, undefined, undefined, false);
251252 }
252253
253254 /// Fetch or allocate a result id for nav index. This function also marks the nav as alive.
......@@ -2943,16 +2944,22 @@ const NavGen = struct {
29432944 try self.spv.declareEntryPoint(spv_decl_index, test_name, .Kernel);
29442945 }
29452946
2946 fn genNav(self: *NavGen) !void {
2947 fn genNav(self: *NavGen, do_codegen: bool) !void {
29472948 const pt = self.pt;
29482949 const zcu = pt.zcu;
29492950 const ip = &zcu.intern_pool;
2950 const spv_decl_index = try self.object.resolveNav(zcu, self.owner_nav);
2951 const result_id = self.spv.declPtr(spv_decl_index).result_id;
29522951
29532952 const nav = ip.getNav(self.owner_nav);
29542953 const val = zcu.navValue(self.owner_nav);
29552954 const ty = val.typeOf(zcu);
2955
2956 if (!do_codegen and !ty.hasRuntimeBits(zcu)) {
2957 return;
2958 }
2959
2960 const spv_decl_index = try self.object.resolveNav(zcu, self.owner_nav);
2961 const result_id = self.spv.declPtr(spv_decl_index).result_id;
2962
29562963 switch (self.spv.declPtr(spv_decl_index).kind) {
29572964 .func => {
29582965 const fn_info = zcu.typeToFunc(ty).?;
src/link/SpirV.zig+1-1
......@@ -140,7 +140,7 @@ pub fn updateNav(self: *SpirV, pt: Zcu.PerThread, nav: InternPool.Nav.Index) !vo
140140 }
141141
142142 const ip = &pt.zcu.intern_pool;
143 log.debug("lowering declaration {}", .{ip.getNav(nav).name.fmt(ip)});
143 log.debug("lowering nav {}({d})", .{ ip.getNav(nav).fqn.fmt(ip), nav });
144144
145145 try self.object.updateNav(pt, nav);
146146}