authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-08-07 23:50:40-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-08-08 21:32:50-04:00
log2499d8fb73b943640cbc7d0484377fffbee403c6
tree6cc4ea7466da93418239047de40de236490a7562
parenta66cd54f94cf675a67f6de594e3d59e7ca14b92f

Builder: fix enough bugs to pass the behavior tests

without using any information from the LLVM API

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

src/codegen/llvm.zig+2-2
......@@ -6243,7 +6243,7 @@ pub const FuncGen = struct {
62436243 if (elem_ptr.ptrInfo(mod).flags.vector_index != .none) return base_ptr;
62446244
62456245 const llvm_elem_ty = try o.lowerPtrElemTy(elem_ty);
6246 return try self.wip.gep(.inbounds, llvm_elem_ty, base_ptr, if (ptr_ty.isSinglePointer(mod))
6246 return self.wip.gep(.inbounds, llvm_elem_ty, base_ptr, if (ptr_ty.isSinglePointer(mod))
62476247 // If this is a single-item pointer to an array, we need another index in the GEP.
62486248 &.{ try o.builder.intValue(try o.lowerType(Type.usize), 0), rhs }
62496249 else
......@@ -10532,7 +10532,7 @@ pub const FuncGen = struct {
1053210532 else => unreachable,
1053310533 };
1053410534
10535 return try fg.wip.callAsm(
10535 return fg.wip.callAsm(
1053610536 .none,
1053710537 try o.builder.fnType(llvm_usize, &.{ llvm_usize, llvm_usize }, .normal),
1053810538 .{ .sideeffect = true },
src/codegen/llvm/Builder.zig+40-5
......@@ -5723,7 +5723,16 @@ pub const WipFunction = struct {
57235723 .void => null,
57245724 else => name,
57255725 }, .{
5726 .tag = .call,
5726 .tag = switch (kind) {
5727 .normal => .call,
5728 .fast => .@"call fast",
5729 .musttail => .@"musttail call",
5730 .musttail_fast => .@"musttail call fast",
5731 .notail => .@"notail call",
5732 .notail_fast => .@"notail call fast",
5733 .tail => .@"tail call",
5734 .tail_fast => .@"tail call fast",
5735 },
57275736 .data = self.addExtraAssumeCapacity(Instruction.Call{
57285737 .info = .{ .call_conv = call_conv },
57295738 .attributes = function_attributes,
......@@ -7312,9 +7321,34 @@ pub const Constant = enum(u32) {
73127321 .bfloat => 16,
73137322 else => unreachable,
73147323 } }),
7315 .float => try writer.print("0x{X:0>16}", .{
7316 @as(u64, @bitCast(@as(f64, @as(f32, @bitCast(item.data))))),
7317 }),
7324 .float => {
7325 const Float = struct {
7326 fn Repr(comptime T: type) type {
7327 return packed struct(std.meta.Int(.unsigned, @bitSizeOf(T))) {
7328 mantissa: std.meta.Int(.unsigned, std.math.floatMantissaBits(T)),
7329 exponent: std.meta.Int(.unsigned, std.math.floatExponentBits(T)),
7330 sign: u1,
7331 };
7332 }
7333 };
7334 const Exponent32 = std.meta.FieldType(Float.Repr(f32), .exponent);
7335 const Exponent64 = std.meta.FieldType(Float.Repr(f64), .exponent);
7336 const repr: Float.Repr(f32) = @bitCast(item.data);
7337 try writer.print("0x{X:0>16}", .{@as(u64, @bitCast(Float.Repr(f64){
7338 .mantissa = std.math.shl(
7339 std.meta.FieldType(Float.Repr(f64), .mantissa),
7340 repr.mantissa,
7341 std.math.floatMantissaBits(f64) - std.math.floatMantissaBits(f32),
7342 ),
7343 .exponent = switch (repr.exponent) {
7344 std.math.minInt(Exponent32) => std.math.minInt(Exponent64),
7345 else => @as(Exponent64, repr.exponent) +
7346 (std.math.floatExponentMax(f64) - std.math.floatExponentMax(f32)),
7347 std.math.maxInt(Exponent32) => std.math.maxInt(Exponent64),
7348 },
7349 .sign = repr.sign,
7350 }))});
7351 },
73187352 .double => {
73197353 const extra = data.builder.constantExtraData(Double, item.data);
73207354 try writer.print("0x{X:0>8}{X:0>8}", .{ extra.hi, extra.lo });
......@@ -8361,6 +8395,7 @@ pub fn getIntrinsic(
83618395
83628396 var overload_index: usize = 0;
83638397 function_attributes[FunctionAttributes.function_index] = try attributes.get(signature.attrs);
8398 function_attributes[FunctionAttributes.return_index] = .none; // needed for void return
83648399 for (0.., param_types, signature.params) |param_index, *param_type, signature_param| {
83658400 switch (signature_param.kind) {
83668401 .type => |ty| param_type.* = ty,
......@@ -9573,7 +9608,7 @@ fn fnTypeAssumeCapacity(
95739608 gop.key_ptr.* = {};
95749609 gop.value_ptr.* = {};
95759610 self.type_items.appendAssumeCapacity(.{
9576 .tag = .function,
9611 .tag = tag,
95779612 .data = self.addTypeExtraAssumeCapacity(Type.Function{
95789613 .ret = ret,
95799614 .params_len = @intCast(params.len),