diff options
| author | Jacob Young <jacobly0@users.noreply.github.com> | 2023-05-26 21:22:34 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-06-10 20:47:56 -0700 |
| commit | 2d5bc0146941f4cc207c4fd23058e25a16fd40a7 (patch) | |
| tree | 64087a3ecf4d63d9e53a5f04156dff508d58bd26 /src/codegen | |
| parent | c8b0d4d149c891ed83db57fe6986d10c5dd654af (diff) | |
| download | zig-2d5bc0146941f4cc207c4fd23058e25a16fd40a7.tar.gz zig-2d5bc0146941f4cc207c4fd23058e25a16fd40a7.zip | |
behavior: get more test cases passing with llvm
Diffstat (limited to 'src/codegen')
| -rw-r--r-- | src/codegen/llvm.zig | 34 | ||||
| -rw-r--r-- | src/codegen/spirv.zig | 50 |
2 files changed, 22 insertions, 62 deletions
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 1d3749f6a3..41db3e7a04 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -2003,7 +2003,7 @@ pub const Object = struct { mod.intern_pool.stringToSlice(tuple.names[i]) else try std.fmt.allocPrintZ(gpa, "{d}", .{i}); - defer gpa.free(field_name); + defer if (tuple.names.len == 0) gpa.free(field_name); try di_fields.append(gpa, dib.createMemberType( fwd_decl.toScope(), @@ -2461,13 +2461,13 @@ pub const DeclGen = struct { if (decl.@"linksection") |section| global.setSection(section); assert(decl.has_tv); const init_val = if (decl.val.getVariable(mod)) |variable| init_val: { - break :init_val variable.init.toValue(); + break :init_val variable.init; } else init_val: { global.setGlobalConstant(.True); - break :init_val decl.val; + break :init_val decl.val.toIntern(); }; - if (init_val.toIntern() != .unreachable_value) { - const llvm_init = try dg.lowerValue(.{ .ty = decl.ty, .val = init_val }); + if (init_val != .none) { + const llvm_init = try dg.lowerValue(.{ .ty = decl.ty, .val = init_val.toValue() }); if (global.globalGetValueType() == llvm_init.typeOf()) { global.setInitializer(llvm_init); } else { @@ -2748,7 +2748,7 @@ pub const DeclGen = struct { if (std.debug.runtime_safety and false) check: { if (t.zigTypeTag(mod) == .Opaque) break :check; if (!t.hasRuntimeBits(mod)) break :check; - if (!llvm_ty.isSized().toBool(mod)) break :check; + if (!llvm_ty.isSized().toBool()) break :check; const zig_size = t.abiSize(mod); const llvm_size = dg.object.target_data.abiSizeOfType(llvm_ty); @@ -3239,7 +3239,7 @@ pub const DeclGen = struct { => unreachable, // non-runtime values .false, .true => { const llvm_type = try dg.lowerType(tv.ty); - return if (tv.val.toBool(mod)) llvm_type.constAllOnes() else llvm_type.constNull(); + return if (tv.val.toBool()) llvm_type.constAllOnes() else llvm_type.constNull(); }, }, .variable, @@ -3522,15 +3522,19 @@ pub const DeclGen = struct { const elem_ty = vector_type.child.toType(); const llvm_elems = try dg.gpa.alloc(*llvm.Value, vector_type.len); defer dg.gpa.free(llvm_elems); + const llvm_i8 = dg.context.intType(8); for (llvm_elems, 0..) |*llvm_elem, i| { - llvm_elem.* = try dg.lowerValue(.{ - .ty = elem_ty, - .val = switch (aggregate.storage) { - .bytes => unreachable, - .elems => |elems| elems[i], - .repeated_elem => |elem| elem, - }.toValue(), - }); + llvm_elem.* = switch (aggregate.storage) { + .bytes => |bytes| llvm_i8.constInt(bytes[i], .False), + .elems => |elems| try dg.lowerValue(.{ + .ty = elem_ty, + .val = elems[i].toValue(), + }), + .repeated_elem => |elem| try dg.lowerValue(.{ + .ty = elem_ty, + .val = elem.toValue(), + }), + }; } return llvm.constVector( llvm_elems.ptr, diff --git a/src/codegen/spirv.zig b/src/codegen/spirv.zig index 64a0a7ec57..94ea8b7f89 100644 --- a/src/codegen/spirv.zig +++ b/src/codegen/spirv.zig @@ -654,7 +654,7 @@ pub const DeclGen = struct { .@"unreachable", .generic_poison, => unreachable, // non-runtime values - .false, .true => try self.addConstBool(val.toBool(mod)), + .false, .true => try self.addConstBool(val.toBool()), }, .variable, .extern_func, @@ -974,7 +974,6 @@ pub const DeclGen = struct { /// This function should only be called during function code generation. fn constant(self: *DeclGen, ty: Type, val: Value, repr: Repr) !IdRef { const mod = self.module; - const target = self.getTarget(); const result_ty_ref = try self.resolveType(ty, repr); log.debug("constant: ty = {}, val = {}", .{ ty.fmt(self.module), val.fmtValue(ty, self.module) }); @@ -991,51 +990,8 @@ pub const DeclGen = struct { return try self.spv.constInt(result_ty_ref, val.toUnsignedInt(mod)); } }, - .Bool => switch (repr) { - .direct => return try self.spv.constBool(result_ty_ref, val.toBool(mod)), - .indirect => return try self.spv.constInt(result_ty_ref, @boolToInt(val.toBool(mod))), - }, - .Float => return switch (ty.floatBits(target)) { - 16 => try self.spv.resolveId(.{ .float = .{ .ty = result_ty_ref, .value = .{ .float16 = val.toFloat(f16, mod) } } }), - 32 => try self.spv.resolveId(.{ .float = .{ .ty = result_ty_ref, .value = .{ .float32 = val.toFloat(f32, mod) } } }), - 64 => try self.spv.resolveId(.{ .float = .{ .ty = result_ty_ref, .value = .{ .float64 = val.toFloat(f64, mod) } } }), - 80, 128 => unreachable, // TODO - else => unreachable, - }, - .ErrorSet => { - const value = switch (val.tag()) { - .@"error" => blk: { - const err_name = val.castTag(.@"error").?.data.name; - const kv = try self.module.getErrorValue(err_name); - break :blk @intCast(u16, kv.value); - }, - .zero => 0, - else => unreachable, - }; - - return try self.spv.constInt(result_ty_ref, value); - }, - .ErrorUnion => { - const payload_ty = ty.errorUnionPayload(); - const is_pl = val.errorUnionIsPayload(); - const error_val = if (!is_pl) val else Value.initTag(.zero); - - const eu_layout = self.errorUnionLayout(payload_ty); - if (!eu_layout.payload_has_bits) { - return try self.constant(Type.anyerror, error_val, repr); - } - - const payload_val = if (val.castTag(.eu_payload)) |pl| pl.data else Value.undef; - - var members: [2]IdRef = undefined; - if (eu_layout.error_first) { - members[0] = try self.constant(Type.anyerror, error_val, .indirect); - members[1] = try self.constant(payload_ty, payload_val, .indirect); - } else { - members[0] = try self.constant(payload_ty, payload_val, .indirect); - members[1] = try self.constant(Type.anyerror, error_val, .indirect); - } - return try self.spv.constComposite(result_ty_ref, &members); + .Bool => { + @compileError("TODO merge conflict failure"); }, // TODO: We can handle most pointers here (decl refs etc), because now they emit an extra // OpVariable that is not really required. |
