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 {...@@ -190,6 +190,7 @@ pub const Object = struct {
190 nav_index: InternPool.Nav.Index,190 nav_index: InternPool.Nav.Index,
191 air: Air,191 air: Air,
192 liveness: Liveness,192 liveness: Liveness,
193 do_codegen: bool,
193 ) !void {194 ) !void {
194 const zcu = pt.zcu;195 const zcu = pt.zcu;
195 const gpa = zcu.gpa;196 const gpa = zcu.gpa;
...@@ -214,7 +215,7 @@ pub const Object = struct {...@@ -214,7 +215,7 @@ pub const Object = struct {
214 };215 };
215 defer nav_gen.deinit();216 defer nav_gen.deinit();
216217
217 nav_gen.genNav() catch |err| switch (err) {218 nav_gen.genNav(do_codegen) catch |err| switch (err) {
218 error.CodegenFail => {219 error.CodegenFail => {
219 try zcu.failed_codegen.put(gpa, nav_index, nav_gen.error_msg.?);220 try zcu.failed_codegen.put(gpa, nav_index, nav_gen.error_msg.?);
220 },221 },
...@@ -239,7 +240,7 @@ pub const Object = struct {...@@ -239,7 +240,7 @@ pub const Object = struct {
239 ) !void {240 ) !void {
240 const nav = pt.zcu.funcInfo(func_index).owner_nav;241 const nav = pt.zcu.funcInfo(func_index).owner_nav;
241 // TODO: Separate types for generating decls and functions?242 // 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);
243 }244 }
244245
245 pub fn updateNav(246 pub fn updateNav(
...@@ -247,7 +248,7 @@ pub const Object = struct {...@@ -247,7 +248,7 @@ pub const Object = struct {
247 pt: Zcu.PerThread,248 pt: Zcu.PerThread,
248 nav: InternPool.Nav.Index,249 nav: InternPool.Nav.Index,
249 ) !void {250 ) !void {
250 try self.genNav(pt, nav, undefined, undefined);251 try self.genNav(pt, nav, undefined, undefined, false);
251 }252 }
252253
253 /// Fetch or allocate a result id for nav index. This function also marks the nav as alive.254 /// Fetch or allocate a result id for nav index. This function also marks the nav as alive.
...@@ -2943,16 +2944,22 @@ const NavGen = struct {...@@ -2943,16 +2944,22 @@ const NavGen = struct {
2943 try self.spv.declareEntryPoint(spv_decl_index, test_name, .Kernel);2944 try self.spv.declareEntryPoint(spv_decl_index, test_name, .Kernel);
2944 }2945 }
29452946
2946 fn genNav(self: *NavGen) !void {2947 fn genNav(self: *NavGen, do_codegen: bool) !void {
2947 const pt = self.pt;2948 const pt = self.pt;
2948 const zcu = pt.zcu;2949 const zcu = pt.zcu;
2949 const ip = &zcu.intern_pool;2950 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
2953 const nav = ip.getNav(self.owner_nav);2952 const nav = ip.getNav(self.owner_nav);
2954 const val = zcu.navValue(self.owner_nav);2953 const val = zcu.navValue(self.owner_nav);
2955 const ty = val.typeOf(zcu);2954 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
2956 switch (self.spv.declPtr(spv_decl_index).kind) {2963 switch (self.spv.declPtr(spv_decl_index).kind) {
2957 .func => {2964 .func => {
2958 const fn_info = zcu.typeToFunc(ty).?;2965 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...@@ -140,7 +140,7 @@ pub fn updateNav(self: *SpirV, pt: Zcu.PerThread, nav: InternPool.Nav.Index) !vo
140 }140 }
141141
142 const ip = &pt.zcu.intern_pool;142 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
145 try self.object.updateNav(pt, nav);145 try self.object.updateNav(pt, nav);
146}146}