authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-03-23 16:10:16+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-03-28 16:47:55+00:00
log9c0c65c313776fdc394d8e481ee4eb548a5333ed
tree4edb7f6bb616ec8ba268ca7bba50d38499dac4ec
parentfb224178aaeeb5d8e37392f5c168afca771147ca
signaturelock-open Commit is signed but in an unrecognized format.

llvm: minor refactors, and incremental `@tagName` updates


2 files changed, 201 insertions(+), 176 deletions(-)

src/codegen/llvm.zig+49-37
...@@ -562,7 +562,7 @@ pub const Object = struct {...@@ -562,7 +562,7 @@ pub const Object = struct {
562 /// Same deal as `decl_map` but for anonymous declarations, which are always global constants.562 /// Same deal as `decl_map` but for anonymous declarations, which are always global constants.
563 uav_map: std.AutoHashMapUnmanaged(InternPool.Index, Builder.Global.Index),563 uav_map: std.AutoHashMapUnmanaged(InternPool.Index, Builder.Global.Index),
564 /// Maps enum types to their corresponding LLVM functions for implementing the `tag_name` instruction.564 /// Maps enum types to their corresponding LLVM functions for implementing the `tag_name` instruction.
565 enum_tag_name_map: std.AutoHashMapUnmanaged(InternPool.Index, Builder.Global.Index),565 enum_tag_name_map: std.AutoHashMapUnmanaged(InternPool.Index, Builder.Function.Index),
566 /// Serves the same purpose as `enum_tag_name_map` but for the `is_named_enum_value` instruction.566 /// Serves the same purpose as `enum_tag_name_map` but for the `is_named_enum_value` instruction.
567 named_enum_map: std.AutoHashMapUnmanaged(InternPool.Index, Builder.Function.Index),567 named_enum_map: std.AutoHashMapUnmanaged(InternPool.Index, Builder.Function.Index),
568 /// Maps Zig types to LLVM types. The table memory is backed by the GPA of568 /// Maps Zig types to LLVM types. The table memory is backed by the GPA of
...@@ -1138,7 +1138,7 @@ pub const Object = struct {...@@ -1138,7 +1138,7 @@ pub const Object = struct {
1138 func_index: InternPool.Index,1138 func_index: InternPool.Index,
1139 air: *const Air,1139 air: *const Air,
1140 liveness: *const ?Air.Liveness,1140 liveness: *const ?Air.Liveness,
1141 ) !void {1141 ) Zcu.CodegenFailError!void {
1142 const zcu = o.zcu;1142 const zcu = o.zcu;
1143 const comp = zcu.comp;1143 const comp = zcu.comp;
1144 const ip = &zcu.intern_pool;1144 const ip = &zcu.intern_pool;
...@@ -1514,10 +1514,7 @@ pub const Object = struct {...@@ -1514,10 +1514,7 @@ pub const Object = struct {
1514 defer fg.deinit();1514 defer fg.deinit();
1515 deinit_wip = false;1515 deinit_wip = false;
15161516
1517 fg.genBody(air.getMainBody(), .poi) catch |err| switch (err) {1517 try fg.genBody(air.getMainBody(), .poi);
1518 error.CodegenFail => return, // MLUGG TODO
1519 else => |e| return e,
1520 };
15211518
1522 // If we saw any loads or stores involving `allowzero` pointers, we need to mark the whole1519 // If we saw any loads or stores involving `allowzero` pointers, we need to mark the whole
1523 // function as considering null pointers valid so that LLVM's optimizers don't remove these1520 // function as considering null pointers valid so that LLVM's optimizers don't remove these
...@@ -1894,6 +1891,9 @@ pub const Object = struct {...@@ -1894,6 +1891,9 @@ pub const Object = struct {
1894 if (o.named_enum_map.get(ty)) |function_index| {1891 if (o.named_enum_map.get(ty)) |function_index| {
1895 try o.updateIsNamedEnumValueFunction(.fromInterned(ty), function_index);1892 try o.updateIsNamedEnumValueFunction(.fromInterned(ty), function_index);
1896 }1893 }
1894 if (o.enum_tag_name_map.get(ty)) |function_index| {
1895 try o.updateEnumTagNameFunction(.fromInterned(ty), function_index);
1896 }
1897 }1897 }
18981898
1899 /// Should only be called by the `link.ConstPool` implementation.1899 /// Should only be called by the `link.ConstPool` implementation.
...@@ -4271,25 +4271,39 @@ pub const Object = struct {...@@ -4271,25 +4271,39 @@ pub const Object = struct {
4271 return o.errors_len_variable;4271 return o.errors_len_variable;
4272 }4272 }
42734273
4274 /// MLUGG TODO: this also needs incremental updates dumbass4274 pub fn getEnumTagNameFunction(o: *Object, enum_ty: Type) Allocator.Error!Builder.Function.Index {
4275 pub fn getEnumTagNameFunction(o: *Object, enum_ty: Type) !Builder.Function.Index {
4276 const zcu = o.zcu;4275 const zcu = o.zcu;
4277 const ip = &zcu.intern_pool;4276 const ip = &zcu.intern_pool;
4278 const enum_type = ip.loadEnumType(enum_ty.toIntern());
42794277
4280 const gop = try o.enum_tag_name_map.getOrPut(o.gpa, enum_ty.toIntern());4278 const gop = try o.enum_tag_name_map.getOrPut(o.gpa, enum_ty.toIntern());
4281 if (gop.found_existing) return gop.value_ptr.ptrConst(&o.builder).kind.function;4279 if (gop.found_existing) return gop.value_ptr.*;
4282 errdefer assert(o.enum_tag_name_map.remove(enum_ty.toIntern()));4280 errdefer assert(o.enum_tag_name_map.remove(enum_ty.toIntern()));
4283
4284 const usize_ty = try o.lowerType(.usize);
4285 const ret_ty = try o.lowerType(.slice_const_u8_sentinel_0);
4286 const llvm_int_ty = try o.lowerType(.fromInterned(enum_type.int_tag_type));
4287 const target = &zcu.root_mod.resolved_target.result;
4288 const function_index = try o.builder.addFunction(4281 const function_index = try o.builder.addFunction(
4289 try o.builder.fnType(ret_ty, &.{llvm_int_ty}, .normal),4282 // Dummy function type; `updateEnumTagNameFunction` will replace it with the correct type.
4290 try o.builder.strtabStringFmt("__zig_tag_name_{f}", .{enum_type.name.fmt(ip)}),4283 // TODO: change the builder API so we don't need to do this.
4291 toLlvmAddressSpace(.generic, target),4284 try o.builder.fnType(.void, &.{}, .normal),
4285 try o.builder.strtabStringFmt("__zig_tag_name_{f}", .{enum_ty.containerTypeName(ip).fmt(ip)}),
4286 toLlvmAddressSpace(.generic, zcu.getTarget()),
4292 );4287 );
4288 gop.value_ptr.* = function_index;
4289 try o.updateEnumTagNameFunction(enum_ty, function_index);
4290 return function_index;
4291 }
4292 fn updateEnumTagNameFunction(
4293 o: *Object,
4294 enum_ty: Type,
4295 function_index: Builder.Function.Index,
4296 ) Allocator.Error!void {
4297 const zcu = o.zcu;
4298 const ip = &zcu.intern_pool;
4299 const loaded_enum = ip.loadEnumType(enum_ty.toIntern());
4300
4301 const llvm_usize_ty = try o.lowerType(.usize);
4302 const llvm_ret_ty = try o.lowerType(.slice_const_u8_sentinel_0);
4303 const llvm_int_ty = try o.lowerType(.fromInterned(loaded_enum.int_tag_type));
4304
4305 function_index.ptrConst(&o.builder).global.ptr(&o.builder).type =
4306 try o.builder.fnType(llvm_ret_ty, &.{llvm_int_ty}, .normal);
42934307
4294 var attributes: Builder.FunctionAttributes.Wip = .{};4308 var attributes: Builder.FunctionAttributes.Wip = .{};
4295 defer attributes.deinit(&o.builder);4309 defer attributes.deinit(&o.builder);
...@@ -4298,7 +4312,6 @@ pub const Object = struct {...@@ -4298,7 +4312,6 @@ pub const Object = struct {
4298 function_index.setLinkage(if (o.builder.strip) .private else .internal, &o.builder);4312 function_index.setLinkage(if (o.builder.strip) .private else .internal, &o.builder);
4299 function_index.setCallConv(.fastcc, &o.builder);4313 function_index.setCallConv(.fastcc, &o.builder);
4300 function_index.setAttributes(try attributes.finish(&o.builder), &o.builder);4314 function_index.setAttributes(try attributes.finish(&o.builder), &o.builder);
4301 gop.value_ptr.* = function_index.ptrConst(&o.builder).global;
43024315
4303 var wip = try Builder.WipFunction.init(&o.builder, .{4316 var wip = try Builder.WipFunction.init(&o.builder, .{
4304 .function = function_index,4317 .function = function_index,
...@@ -4312,13 +4325,13 @@ pub const Object = struct {...@@ -4312,13 +4325,13 @@ pub const Object = struct {
4312 var wip_switch = try wip.@"switch"(4325 var wip_switch = try wip.@"switch"(
4313 tag_int_value,4326 tag_int_value,
4314 bad_value_block,4327 bad_value_block,
4315 @intCast(enum_type.field_names.len),4328 @intCast(loaded_enum.field_names.len),
4316 .none,4329 .none,
4317 );4330 );
4318 defer wip_switch.finish(&wip);4331 defer wip_switch.finish(&wip);
43194332
4320 for (0..enum_type.field_names.len) |field_index| {4333 for (0..loaded_enum.field_names.len) |field_index| {
4321 const name = try o.builder.stringNull(enum_type.field_names.get(ip)[field_index].toSlice(ip));4334 const name = try o.builder.stringNull(loaded_enum.field_names.get(ip)[field_index].toSlice(ip));
4322 const name_init = try o.builder.stringConst(name);4335 const name_init = try o.builder.stringConst(name);
4323 const name_variable_index =4336 const name_variable_index =
4324 try o.builder.addVariable(.empty, name_init.typeOf(&o.builder), .default);4337 try o.builder.addVariable(.empty, name_init.typeOf(&o.builder), .default);
...@@ -4328,13 +4341,13 @@ pub const Object = struct {...@@ -4328,13 +4341,13 @@ pub const Object = struct {
4328 name_variable_index.setUnnamedAddr(.unnamed_addr, &o.builder);4341 name_variable_index.setUnnamedAddr(.unnamed_addr, &o.builder);
4329 name_variable_index.setAlignment(comptime Builder.Alignment.fromByteUnits(1), &o.builder);4342 name_variable_index.setAlignment(comptime Builder.Alignment.fromByteUnits(1), &o.builder);
43304343
4331 const name_val = try o.builder.structValue(ret_ty, &.{4344 const name_val = try o.builder.structValue(llvm_ret_ty, &.{
4332 name_variable_index.toConst(&o.builder),4345 name_variable_index.toConst(&o.builder),
4333 try o.builder.intConst(usize_ty, name.slice(&o.builder).?.len - 1),4346 try o.builder.intConst(llvm_usize_ty, name.slice(&o.builder).?.len - 1),
4334 });4347 });
43354348
4336 const return_block = try wip.block(1, "Name");4349 const return_block = try wip.block(1, "Name");
4337 const llvm_tag_val = switch (enum_type.field_values.getOrNone(ip, field_index)) {4350 const llvm_tag_val = switch (loaded_enum.field_values.getOrNone(ip, field_index)) {
4338 .none => try o.builder.intConst(llvm_int_ty, field_index), // auto-numbered4351 .none => try o.builder.intConst(llvm_int_ty, field_index), // auto-numbered
4339 else => |tag_val_ip| try o.lowerValue(tag_val_ip),4352 else => |tag_val_ip| try o.lowerValue(tag_val_ip),
4340 };4353 };
...@@ -4348,7 +4361,6 @@ pub const Object = struct {...@@ -4348,7 +4361,6 @@ pub const Object = struct {
4348 _ = try wip.@"unreachable"();4361 _ = try wip.@"unreachable"();
43494362
4350 try wip.finish();4363 try wip.finish();
4351 return function_index;
4352 }4364 }
43534365
4354 pub fn lazyAbiAlignment(o: *Object, pt: Zcu.PerThread, ty: Type) Allocator.Error!Builder.Alignment.Lazy {4366 pub fn lazyAbiAlignment(o: *Object, pt: Zcu.PerThread, ty: Type) Allocator.Error!Builder.Alignment.Lazy {
...@@ -4356,7 +4368,7 @@ pub const Object = struct {...@@ -4356,7 +4368,7 @@ pub const Object = struct {
4356 return o.lazy_abi_aligns.items[@intFromEnum(index)];4368 return o.lazy_abi_aligns.items[@intFromEnum(index)];
4357 }4369 }
43584370
4359 pub fn getIsNamedEnumValueFunction(o: *Object, enum_ty: Type) !Builder.Function.Index {4371 pub fn getIsNamedEnumValueFunction(o: *Object, enum_ty: Type) Allocator.Error!Builder.Function.Index {
4360 const zcu = o.zcu;4372 const zcu = o.zcu;
4361 const ip = &zcu.intern_pool;4373 const ip = &zcu.intern_pool;
43624374
...@@ -4380,22 +4392,22 @@ pub const Object = struct {...@@ -4380,22 +4392,22 @@ pub const Object = struct {
4380 function_index: Builder.Function.Index,4392 function_index: Builder.Function.Index,
4381 ) Allocator.Error!void {4393 ) Allocator.Error!void {
4382 const zcu = o.zcu;4394 const zcu = o.zcu;
4383 const builder = &o.builder;4395 const ip = &zcu.intern_pool;
4384 const loaded_enum = zcu.intern_pool.loadEnumType(enum_ty.toIntern());4396 const loaded_enum = ip.loadEnumType(enum_ty.toIntern());
43854397
4386 const llvm_int_ty = try o.lowerType(.fromInterned(loaded_enum.int_tag_type));4398 const llvm_int_ty = try o.lowerType(.fromInterned(loaded_enum.int_tag_type));
4387 function_index.ptrConst(builder).global.ptr(builder).type =4399 function_index.ptrConst(&o.builder).global.ptr(&o.builder).type =
4388 try builder.fnType(.i1, &.{llvm_int_ty}, .normal);4400 try o.builder.fnType(.i1, &.{llvm_int_ty}, .normal);
43894401
4390 var attributes: Builder.FunctionAttributes.Wip = .{};4402 var attributes: Builder.FunctionAttributes.Wip = .{};
4391 defer attributes.deinit(builder);4403 defer attributes.deinit(&o.builder);
4392 try o.addCommonFnAttributes(&attributes, zcu.root_mod, zcu.root_mod.omit_frame_pointer);4404 try o.addCommonFnAttributes(&attributes, zcu.root_mod, zcu.root_mod.omit_frame_pointer);
43934405
4394 function_index.setLinkage(if (o.builder.strip) .private else .internal, builder);4406 function_index.setLinkage(if (o.builder.strip) .private else .internal, &o.builder);
4395 function_index.setCallConv(.fastcc, builder);4407 function_index.setCallConv(.fastcc, &o.builder);
4396 function_index.setAttributes(try attributes.finish(builder), builder);4408 function_index.setAttributes(try attributes.finish(&o.builder), &o.builder);
43974409
4398 var wip: Builder.WipFunction = try .init(builder, .{4410 var wip: Builder.WipFunction = try .init(&o.builder, .{
4399 .function = function_index,4411 .function = function_index,
4400 .strip = true,4412 .strip = true,
4401 });4413 });
...@@ -4409,7 +4421,7 @@ pub const Object = struct {...@@ -4409,7 +4421,7 @@ pub const Object = struct {
4409 defer wip_switch.finish(&wip);4421 defer wip_switch.finish(&wip);
44104422
4411 if (loaded_enum.field_values.len > 0) {4423 if (loaded_enum.field_values.len > 0) {
4412 for (loaded_enum.field_values.get(&zcu.intern_pool)) |tag_val_ip| {4424 for (loaded_enum.field_values.get(ip)) |tag_val_ip| {
4413 const llvm_tag_val = try o.lowerValue(tag_val_ip);4425 const llvm_tag_val = try o.lowerValue(tag_val_ip);
4414 try wip_switch.addCase(llvm_tag_val, named_block, &wip);4426 try wip_switch.addCase(llvm_tag_val, named_block, &wip);
4415 }4427 }
src/codegen/llvm/FuncGen.zig+152-139
...@@ -175,11 +175,6 @@ fn resolveValue(self: *FuncGen, val: Value) Allocator.Error!Builder.Constant {...@@ -175,11 +175,6 @@ fn resolveValue(self: *FuncGen, val: Value) Allocator.Error!Builder.Constant {
175 }175 }
176}176}
177177
178/// MLUGG TODO okay yeah prolly delete this again
179fn lowerType(fg: *const FuncGen, ty: Type) Allocator.Error!Builder.Type {
180 return fg.object.lowerType(ty);
181}
182
183pub fn genBody(self: *FuncGen, body: []const Air.Inst.Index, coverage_point: Air.CoveragePoint) TodoError!void {178pub fn genBody(self: *FuncGen, body: []const Air.Inst.Index, coverage_point: Air.CoveragePoint) TodoError!void {
184 const o = self.object;179 const o = self.object;
185 const zcu = self.object.zcu;180 const zcu = self.object.zcu;
...@@ -608,7 +603,7 @@ fn airCall(self: *FuncGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif...@@ -608,7 +603,7 @@ fn airCall(self: *FuncGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif
608 }603 }
609604
610 const ret_ptr = if (!sret) null else blk: {605 const ret_ptr = if (!sret) null else blk: {
611 const llvm_ret_ty = try self.lowerType(return_type);606 const llvm_ret_ty = try o.lowerType(return_type);
612 try attributes.addParamAttr(0, .{ .sret = llvm_ret_ty }, &o.builder);607 try attributes.addParamAttr(0, .{ .sret = llvm_ret_ty }, &o.builder);
613608
614 const alignment = return_type.abiAlignment(zcu).toLlvm();609 const alignment = return_type.abiAlignment(zcu).toLlvm();
...@@ -630,7 +625,7 @@ fn airCall(self: *FuncGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif...@@ -630,7 +625,7 @@ fn airCall(self: *FuncGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif
630 const arg = args[it.zig_index - 1];625 const arg = args[it.zig_index - 1];
631 const param_ty = self.typeOf(arg);626 const param_ty = self.typeOf(arg);
632 const llvm_arg = try self.resolveInst(arg);627 const llvm_arg = try self.resolveInst(arg);
633 const llvm_param_ty = try self.lowerType(param_ty);628 const llvm_param_ty = try o.lowerType(param_ty);
634 if (isByRef(param_ty, zcu)) {629 if (isByRef(param_ty, zcu)) {
635 const alignment = param_ty.abiAlignment(zcu).toLlvm();630 const alignment = param_ty.abiAlignment(zcu).toLlvm();
636 const loaded = try self.wip.load(.normal, llvm_param_ty, llvm_arg, alignment, "");631 const loaded = try self.wip.load(.normal, llvm_param_ty, llvm_arg, alignment, "");
...@@ -659,7 +654,7 @@ fn airCall(self: *FuncGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif...@@ -659,7 +654,7 @@ fn airCall(self: *FuncGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif
659 const llvm_arg = try self.resolveInst(arg);654 const llvm_arg = try self.resolveInst(arg);
660655
661 const alignment = param_ty.abiAlignment(zcu).toLlvm();656 const alignment = param_ty.abiAlignment(zcu).toLlvm();
662 const param_llvm_ty = try self.lowerType(param_ty);657 const param_llvm_ty = try o.lowerType(param_ty);
663 const arg_ptr = try self.buildAlloca(param_llvm_ty, alignment);658 const arg_ptr = try self.buildAlloca(param_llvm_ty, alignment);
664 if (isByRef(param_ty, zcu)) {659 if (isByRef(param_ty, zcu)) {
665 const loaded = try self.wip.load(.normal, param_llvm_ty, llvm_arg, alignment, "");660 const loaded = try self.wip.load(.normal, param_llvm_ty, llvm_arg, alignment, "");
...@@ -729,7 +724,7 @@ fn airCall(self: *FuncGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif...@@ -729,7 +724,7 @@ fn airCall(self: *FuncGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif
729 llvm_arg = ptr;724 llvm_arg = ptr;
730 }725 }
731726
732 const float_ty = try self.lowerType(aarch64_c_abi.getFloatArrayType(arg_ty, zcu).?);727 const float_ty = try o.lowerType(aarch64_c_abi.getFloatArrayType(arg_ty, zcu).?);
733 const array_ty = try o.builder.arrayType(count, float_ty);728 const array_ty = try o.builder.arrayType(count, float_ty);
734729
735 const loaded = try self.wip.load(.normal, array_ty, llvm_arg, alignment, "");730 const loaded = try self.wip.load(.normal, array_ty, llvm_arg, alignment, "");
...@@ -770,7 +765,7 @@ fn airCall(self: *FuncGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif...@@ -770,7 +765,7 @@ fn airCall(self: *FuncGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif
770 .byref => {765 .byref => {
771 const param_index = it.zig_index - 1;766 const param_index = it.zig_index - 1;
772 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[param_index]);767 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[param_index]);
773 const param_llvm_ty = try self.lowerType(param_ty);768 const param_llvm_ty = try o.lowerType(param_ty);
774 const alignment = param_ty.abiAlignment(zcu).toLlvm();769 const alignment = param_ty.abiAlignment(zcu).toLlvm();
775 try o.addByRefParamAttrs(&attributes, it.llvm_index - 1, alignment, it.byval_attr, param_llvm_ty);770 try o.addByRefParamAttrs(&attributes, it.llvm_index - 1, alignment, it.byval_attr, param_llvm_ty);
776 },771 },
...@@ -822,7 +817,7 @@ fn airCall(self: *FuncGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif...@@ -822,7 +817,7 @@ fn airCall(self: *FuncGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif
822 },817 },
823 toLlvmCallConvTag(fn_info.cc, target).?,818 toLlvmCallConvTag(fn_info.cc, target).?,
824 try attributes.finish(&o.builder),819 try attributes.finish(&o.builder),
825 try self.lowerType(zig_fn_ty),820 try o.lowerType(zig_fn_ty),
826 llvm_fn,821 llvm_fn,
827 llvm_args.items,822 llvm_args.items,
828 "",823 "",
...@@ -836,7 +831,7 @@ fn airCall(self: *FuncGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif...@@ -836,7 +831,7 @@ fn airCall(self: *FuncGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif
836 return .none;831 return .none;
837 }832 }
838833
839 const llvm_ret_ty = try self.lowerType(return_type);834 const llvm_ret_ty = try o.lowerType(return_type);
840 if (ret_ptr) |rp| {835 if (ret_ptr) |rp| {
841 if (isByRef(return_type, zcu)) {836 if (isByRef(return_type, zcu)) {
842 return rp;837 return rp;
...@@ -908,7 +903,7 @@ fn airRet(self: *FuncGen, inst: Air.Inst.Index, safety: bool) Allocator.Error!vo...@@ -908,7 +903,7 @@ fn airRet(self: *FuncGen, inst: Air.Inst.Index, safety: bool) Allocator.Error!vo
908 const operand = try self.resolveInst(un_op);903 const operand = try self.resolveInst(un_op);
909 const val_is_undef = if (un_op.toInterned()) |i| Value.fromInterned(i).isUndef(zcu) else false;904 const val_is_undef = if (un_op.toInterned()) |i| Value.fromInterned(i).isUndef(zcu) else false;
910 if (val_is_undef and safety) {905 if (val_is_undef and safety) {
911 const len = try o.builder.intValue(try self.lowerType(.usize), ret_ty.abiSize(zcu));906 const len = try o.builder.intValue(try o.lowerType(.usize), ret_ty.abiSize(zcu));
912 _ = try self.wip.callMemSet(907 _ = try self.wip.callMemSet(
913 self.ret_ptr,908 self.ret_ptr,
914 ret_ty.abiAlignment(zcu).toLlvm(),909 ret_ty.abiAlignment(zcu).toLlvm(),
...@@ -964,7 +959,7 @@ fn airRet(self: *FuncGen, inst: Air.Inst.Index, safety: bool) Allocator.Error!vo...@@ -964,7 +959,7 @@ fn airRet(self: *FuncGen, inst: Air.Inst.Index, safety: bool) Allocator.Error!vo
964 if (val_is_undef and safety) {959 if (val_is_undef and safety) {
965 const llvm_ret_ty = operand.typeOfWip(&self.wip);960 const llvm_ret_ty = operand.typeOfWip(&self.wip);
966 const rp = try self.buildAlloca(llvm_ret_ty, alignment);961 const rp = try self.buildAlloca(llvm_ret_ty, alignment);
967 const len = try o.builder.intValue(try self.lowerType(.usize), ret_ty.abiSize(zcu));962 const len = try o.builder.intValue(try o.lowerType(.usize), ret_ty.abiSize(zcu));
968 _ = try self.wip.callMemSet(963 _ = try self.wip.callMemSet(
969 rp,964 rp,
970 alignment,965 alignment,
...@@ -1034,17 +1029,18 @@ fn airCVaArg(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value...@@ -1034,17 +1029,18 @@ fn airCVaArg(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value
1034 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;1029 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1035 const list = try self.resolveInst(ty_op.operand);1030 const list = try self.resolveInst(ty_op.operand);
1036 const arg_ty = ty_op.ty.toType();1031 const arg_ty = ty_op.ty.toType();
1037 const llvm_arg_ty = try self.lowerType(arg_ty);1032 const llvm_arg_ty = try self.object.lowerType(arg_ty);
10381033
1039 return self.wip.vaArg(list, llvm_arg_ty, "");1034 return self.wip.vaArg(list, llvm_arg_ty, "");
1040}1035}
10411036
1042fn airCVaCopy(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {1037fn airCVaCopy(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {
1043 const zcu = self.object.zcu;1038 const o = self.object;
1039 const zcu = o.zcu;
1044 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;1040 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1045 const src_list = try self.resolveInst(ty_op.operand);1041 const src_list = try self.resolveInst(ty_op.operand);
1046 const va_list_ty = ty_op.ty.toType();1042 const va_list_ty = ty_op.ty.toType();
1047 const llvm_va_list_ty = try self.lowerType(va_list_ty);1043 const llvm_va_list_ty = try o.lowerType(va_list_ty);
10481044
1049 const result_alignment = va_list_ty.abiAlignment(zcu).toLlvm();1045 const result_alignment = va_list_ty.abiAlignment(zcu).toLlvm();
1050 const dest_list = try self.buildAlloca(llvm_va_list_ty, result_alignment);1046 const dest_list = try self.buildAlloca(llvm_va_list_ty, result_alignment);
...@@ -1065,9 +1061,10 @@ fn airCVaEnd(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value...@@ -1065,9 +1061,10 @@ fn airCVaEnd(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value
1065}1061}
10661062
1067fn airCVaStart(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {1063fn airCVaStart(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {
1068 const zcu = self.object.zcu;1064 const o = self.object;
1065 const zcu = o.zcu;
1069 const va_list_ty = self.typeOfIndex(inst);1066 const va_list_ty = self.typeOfIndex(inst);
1070 const llvm_va_list_ty = try self.lowerType(va_list_ty);1067 const llvm_va_list_ty = try o.lowerType(va_list_ty);
10711068
1072 const result_alignment = va_list_ty.abiAlignment(zcu).toLlvm();1069 const result_alignment = va_list_ty.abiAlignment(zcu).toLlvm();
1073 const dest_list = try self.buildAlloca(llvm_va_list_ty, result_alignment);1070 const dest_list = try self.buildAlloca(llvm_va_list_ty, result_alignment);
...@@ -1227,7 +1224,8 @@ fn lowerBlock(...@@ -1227,7 +1224,8 @@ fn lowerBlock(
1227 maybe_inline_func: ?InternPool.Index,1224 maybe_inline_func: ?InternPool.Index,
1228 body: []const Air.Inst.Index,1225 body: []const Air.Inst.Index,
1229) TodoError!Builder.Value {1226) TodoError!Builder.Value {
1230 const zcu = self.object.zcu;1227 const o = self.object;
1228 const zcu = o.zcu;
1231 const inst_ty = self.typeOfIndex(inst);1229 const inst_ty = self.typeOfIndex(inst);
12321230
1233 if (inst_ty.isNoReturn(zcu)) {1231 if (inst_ty.isNoReturn(zcu)) {
...@@ -1253,7 +1251,7 @@ fn lowerBlock(...@@ -1253,7 +1251,7 @@ fn lowerBlock(
12531251
1254 // Create a phi node only if the block returns a value.1252 // Create a phi node only if the block returns a value.
1255 if (have_block_result) {1253 if (have_block_result) {
1256 const raw_llvm_ty = try self.lowerType(inst_ty);1254 const raw_llvm_ty = try o.lowerType(inst_ty);
1257 const llvm_ty: Builder.Type = ty: {1255 const llvm_ty: Builder.Type = ty: {
1258 // If the zig tag type is a function, this represents an actual function body; not1256 // If the zig tag type is a function, this represents an actual function body; not
1259 // a pointer to it. LLVM IR allows the call instruction to use function bodies instead1257 // a pointer to it. LLVM IR allows the call instruction to use function bodies instead
...@@ -1370,7 +1368,7 @@ fn lowerSwitchDispatch(...@@ -1370,7 +1368,7 @@ fn lowerSwitchDispatch(
1370 const table_index = try self.wip.conv(1368 const table_index = try self.wip.conv(
1371 .unsigned,1369 .unsigned,
1372 try self.wip.bin(.@"sub nuw", cond, jmp_table.min.toValue(), ""),1370 try self.wip.bin(.@"sub nuw", cond, jmp_table.min.toValue(), ""),
1373 try self.lowerType(.usize),1371 try o.lowerType(.usize),
1374 "",1372 "",
1375 );1373 );
1376 const target_ptr_ptr = try self.ptraddScaled(1374 const target_ptr_ptr = try self.ptraddScaled(
...@@ -1395,7 +1393,7 @@ fn lowerSwitchDispatch(...@@ -1395,7 +1393,7 @@ fn lowerSwitchDispatch(
1395 // The switch prongs will correspond to our scalar cases. Ranges will1393 // The switch prongs will correspond to our scalar cases. Ranges will
1396 // be handled by conditional branches in the `else` prong.1394 // be handled by conditional branches in the `else` prong.
13971395
1398 const llvm_usize = try self.lowerType(.usize);1396 const llvm_usize = try o.lowerType(.usize);
1399 const cond_int = if (cond.typeOfWip(&self.wip).isPointer(&o.builder))1397 const cond_int = if (cond.typeOfWip(&self.wip).isPointer(&o.builder))
1400 try self.wip.cast(.ptrtoint, cond, llvm_usize, "")1398 try self.wip.cast(.ptrtoint, cond, llvm_usize, "")
1401 else1399 else
...@@ -1642,7 +1640,7 @@ fn lowerTry(...@@ -1642,7 +1640,7 @@ fn lowerTry(
1642 } else if (isByRef(payload_ty, zcu)) {1640 } else if (isByRef(payload_ty, zcu)) {
1643 return fg.loadByRef(payload_ptr, payload_ty, payload_align.toLlvm(), .normal);1641 return fg.loadByRef(payload_ptr, payload_ty, payload_align.toLlvm(), .normal);
1644 } else {1642 } else {
1645 return fg.wip.load(.normal, try fg.lowerType(payload_ty), payload_ptr, payload_align.toLlvm(), "");1643 return fg.wip.load(.normal, try o.lowerType(payload_ty), payload_ptr, payload_align.toLlvm(), "");
1646 }1644 }
1647}1645}
16481646
...@@ -1912,9 +1910,9 @@ fn airArrayToSlice(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder...@@ -1912,9 +1910,9 @@ fn airArrayToSlice(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder
1912 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;1910 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1913 const operand_ty = self.typeOf(ty_op.operand);1911 const operand_ty = self.typeOf(ty_op.operand);
1914 const array_ty = operand_ty.childType(zcu);1912 const array_ty = operand_ty.childType(zcu);
1915 const llvm_usize = try self.lowerType(.usize);1913 const llvm_usize = try o.lowerType(.usize);
1916 const len = try o.builder.intValue(llvm_usize, array_ty.arrayLen(zcu));1914 const len = try o.builder.intValue(llvm_usize, array_ty.arrayLen(zcu));
1917 const slice_llvm_ty = try self.lowerType(self.typeOfIndex(inst));1915 const slice_llvm_ty = try o.lowerType(self.typeOfIndex(inst));
1918 const operand = try self.resolveInst(ty_op.operand);1916 const operand = try self.resolveInst(ty_op.operand);
1919 return self.wip.buildAggregate(slice_llvm_ty, &.{ operand, len }, "");1917 return self.wip.buildAggregate(slice_llvm_ty, &.{ operand, len }, "");
1920}1918}
...@@ -1931,7 +1929,7 @@ fn airFloatFromInt(self: *FuncGen, inst: Air.Inst.Index) TodoError!Builder.Value...@@ -1931,7 +1929,7 @@ fn airFloatFromInt(self: *FuncGen, inst: Air.Inst.Index) TodoError!Builder.Value
19311929
1932 const dest_ty = self.typeOfIndex(inst);1930 const dest_ty = self.typeOfIndex(inst);
1933 const dest_scalar_ty = dest_ty.scalarType(zcu);1931 const dest_scalar_ty = dest_ty.scalarType(zcu);
1934 const dest_llvm_ty = try self.lowerType(dest_ty);1932 const dest_llvm_ty = try o.lowerType(dest_ty);
1935 const target = zcu.getTarget();1933 const target = zcu.getTarget();
19361934
1937 if (intrinsicsAllowed(dest_scalar_ty, target)) return self.wip.conv(1935 if (intrinsicsAllowed(dest_scalar_ty, target)) return self.wip.conv(
...@@ -1999,7 +1997,7 @@ fn airIntFromFloat(...@@ -1999,7 +1997,7 @@ fn airIntFromFloat(
19991997
2000 const dest_ty = self.typeOfIndex(inst);1998 const dest_ty = self.typeOfIndex(inst);
2001 const dest_scalar_ty = dest_ty.scalarType(zcu);1999 const dest_scalar_ty = dest_ty.scalarType(zcu);
2002 const dest_llvm_ty = try self.lowerType(dest_ty);2000 const dest_llvm_ty = try o.lowerType(dest_ty);
20032001
2004 if (intrinsicsAllowed(operand_scalar_ty, target)) {2002 if (intrinsicsAllowed(operand_scalar_ty, target)) {
2005 // TODO set fast math flag2003 // TODO set fast math flag
...@@ -2033,7 +2031,7 @@ fn airIntFromFloat(...@@ -2033,7 +2031,7 @@ fn airIntFromFloat(
2033 compiler_rt_dest_abbrev,2031 compiler_rt_dest_abbrev,
2034 });2032 });
20352033
2036 const operand_llvm_ty = try self.lowerType(operand_ty);2034 const operand_llvm_ty = try o.lowerType(operand_ty);
2037 const libc_fn = try o.getLibcFunction(fn_name, &.{operand_llvm_ty}, libc_ret_ty);2035 const libc_fn = try o.getLibcFunction(fn_name, &.{operand_llvm_ty}, libc_ret_ty);
2038 var result = try self.wip.call(2036 var result = try self.wip.call(
2039 .normal,2037 .normal,
...@@ -2058,7 +2056,7 @@ fn sliceOrArrayPtr(fg: *FuncGen, ptr: Builder.Value, ty: Type) Allocator.Error!B...@@ -2058,7 +2056,7 @@ fn sliceOrArrayPtr(fg: *FuncGen, ptr: Builder.Value, ty: Type) Allocator.Error!B
2058fn sliceOrArrayLenInBytes(fg: *FuncGen, ptr: Builder.Value, ty: Type) Allocator.Error!Builder.Value {2056fn sliceOrArrayLenInBytes(fg: *FuncGen, ptr: Builder.Value, ty: Type) Allocator.Error!Builder.Value {
2059 const o = fg.object;2057 const o = fg.object;
2060 const zcu = o.zcu;2058 const zcu = o.zcu;
2061 const llvm_usize = try fg.lowerType(.usize);2059 const llvm_usize = try o.lowerType(.usize);
2062 switch (ty.ptrSize(zcu)) {2060 switch (ty.ptrSize(zcu)) {
2063 .slice => {2061 .slice => {
2064 const len = try fg.wip.extractValue(ptr, &.{1}, "");2062 const len = try fg.wip.extractValue(ptr, &.{1}, "");
...@@ -2240,7 +2238,7 @@ fn airStructFieldVal(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Build...@@ -2240,7 +2238,7 @@ fn airStructFieldVal(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Build
2240 },2238 },
2241 .float => {2239 .float => {
2242 // bitcast int->float2240 // bitcast int->float
2243 return self.wip.cast(.bitcast, field_int_val, try self.lowerType(field_ty), "");2241 return self.wip.cast(.bitcast, field_int_val, try o.lowerType(field_ty), "");
2244 },2242 },
2245 }2243 }
2246 }2244 }
...@@ -2277,8 +2275,8 @@ fn airFieldParentPtr(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Build...@@ -2277,8 +2275,8 @@ fn airFieldParentPtr(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Build
2277 const field_offset = parent_ty.structFieldOffset(extra.field_index, zcu);2275 const field_offset = parent_ty.structFieldOffset(extra.field_index, zcu);
2278 if (field_offset == 0) return field_ptr;2276 if (field_offset == 0) return field_ptr;
22792277
2280 const res_ty = try self.lowerType(ty_pl.ty.toType());2278 const res_ty = try o.lowerType(ty_pl.ty.toType());
2281 const llvm_usize = try self.lowerType(.usize);2279 const llvm_usize = try o.lowerType(.usize);
22822280
2283 const field_ptr_int = try self.wip.cast(.ptrtoint, field_ptr, llvm_usize, "");2281 const field_ptr_int = try self.wip.cast(.ptrtoint, field_ptr, llvm_usize, "");
2284 const base_ptr_int = try self.wip.bin(2282 const base_ptr_int = try self.wip.bin(
...@@ -2495,7 +2493,7 @@ fn airAssembly(self: *FuncGen, inst: Air.Inst.Index) TodoError!Builder.Value {...@@ -2495,7 +2493,7 @@ fn airAssembly(self: *FuncGen, inst: Air.Inst.Index) TodoError!Builder.Value {
2495 const output_inst = try self.resolveInst(output.operand);2493 const output_inst = try self.resolveInst(output.operand);
2496 const output_ty = self.typeOf(output.operand);2494 const output_ty = self.typeOf(output.operand);
2497 assert(output_ty.zigTypeTag(zcu) == .pointer);2495 assert(output_ty.zigTypeTag(zcu) == .pointer);
2498 const elem_llvm_ty = try self.lowerType(output_ty.childType(zcu));2496 const elem_llvm_ty = try o.lowerType(output_ty.childType(zcu));
24992497
2500 switch (constraint[0]) {2498 switch (constraint[0]) {
2501 '=' => {},2499 '=' => {},
...@@ -2533,7 +2531,7 @@ fn airAssembly(self: *FuncGen, inst: Air.Inst.Index) TodoError!Builder.Value {...@@ -2533,7 +2531,7 @@ fn airAssembly(self: *FuncGen, inst: Air.Inst.Index) TodoError!Builder.Value {
2533 llvm_ret_indirect[output.index] = false;2531 llvm_ret_indirect[output.index] = false;
25342532
2535 const ret_ty = self.typeOfIndex(inst);2533 const ret_ty = self.typeOfIndex(inst);
2536 llvm_ret_types[llvm_ret_i] = try self.lowerType(ret_ty);2534 llvm_ret_types[llvm_ret_i] = try o.lowerType(ret_ty);
2537 llvm_ret_i += 1;2535 llvm_ret_i += 1;
2538 }2536 }
25392537
...@@ -2572,7 +2570,7 @@ fn airAssembly(self: *FuncGen, inst: Air.Inst.Index) TodoError!Builder.Value {...@@ -2572,7 +2570,7 @@ fn airAssembly(self: *FuncGen, inst: Air.Inst.Index) TodoError!Builder.Value {
2572 llvm_param_types[llvm_param_i] = arg_llvm_value.typeOfWip(&self.wip);2570 llvm_param_types[llvm_param_i] = arg_llvm_value.typeOfWip(&self.wip);
2573 } else {2571 } else {
2574 const alignment = arg_ty.abiAlignment(zcu).toLlvm();2572 const alignment = arg_ty.abiAlignment(zcu).toLlvm();
2575 const arg_llvm_ty = try self.lowerType(arg_ty);2573 const arg_llvm_ty = try o.lowerType(arg_ty);
2576 const load_inst =2574 const load_inst =
2577 try self.wip.load(.normal, arg_llvm_ty, arg_llvm_value, alignment, "");2575 try self.wip.load(.normal, arg_llvm_ty, arg_llvm_value, alignment, "");
2578 llvm_param_values[llvm_param_i] = load_inst;2576 llvm_param_values[llvm_param_i] = load_inst;
...@@ -2613,7 +2611,7 @@ fn airAssembly(self: *FuncGen, inst: Air.Inst.Index) TodoError!Builder.Value {...@@ -2613,7 +2611,7 @@ fn airAssembly(self: *FuncGen, inst: Air.Inst.Index) TodoError!Builder.Value {
2613 llvm_param_attrs[llvm_param_i] = if (constraint[0] == '*') blk: {2611 llvm_param_attrs[llvm_param_i] = if (constraint[0] == '*') blk: {
2614 if (!is_by_ref) self.maybeMarkAllowZeroAccess(arg_ty.ptrInfo(zcu));2612 if (!is_by_ref) self.maybeMarkAllowZeroAccess(arg_ty.ptrInfo(zcu));
26152613
2616 break :blk try self.lowerType(if (is_by_ref) arg_ty else arg_ty.childType(zcu));2614 break :blk try o.lowerType(if (is_by_ref) arg_ty else arg_ty.childType(zcu));
2617 } else .none;2615 } else .none;
26182616
2619 llvm_param_i += 1;2617 llvm_param_i += 1;
...@@ -2627,7 +2625,7 @@ fn airAssembly(self: *FuncGen, inst: Air.Inst.Index) TodoError!Builder.Value {...@@ -2627,7 +2625,7 @@ fn airAssembly(self: *FuncGen, inst: Air.Inst.Index) TodoError!Builder.Value {
2627 if (constraint[0] != '+') continue;2625 if (constraint[0] != '+') continue;
26282626
2629 const rw_ty = self.typeOf(output.operand);2627 const rw_ty = self.typeOf(output.operand);
2630 const llvm_elem_ty = try self.lowerType(rw_ty.childType(zcu));2628 const llvm_elem_ty = try o.lowerType(rw_ty.childType(zcu));
2631 if (llvm_ret_indirect[output.index]) {2629 if (llvm_ret_indirect[output.index]) {
2632 llvm_param_values[llvm_param_i] = llvm_rw_vals[output.index];2630 llvm_param_values[llvm_param_i] = llvm_rw_vals[output.index];
2633 llvm_param_types[llvm_param_i] = llvm_rw_vals[output.index].typeOfWip(&self.wip);2631 llvm_param_types[llvm_param_i] = llvm_rw_vals[output.index].typeOfWip(&self.wip);
...@@ -2827,7 +2825,7 @@ fn airIsNonNull(...@@ -2827,7 +2825,7 @@ fn airIsNonNull(
2827 const operand = try self.resolveInst(un_op);2825 const operand = try self.resolveInst(un_op);
2828 const operand_ty = self.typeOf(un_op);2826 const operand_ty = self.typeOf(un_op);
2829 const optional_ty = if (operand_is_ptr) operand_ty.childType(zcu) else operand_ty;2827 const optional_ty = if (operand_is_ptr) operand_ty.childType(zcu) else operand_ty;
2830 const optional_llvm_ty = try self.lowerType(optional_ty);2828 const optional_llvm_ty = try o.lowerType(optional_ty);
2831 const payload_ty = optional_ty.optionalChild(zcu);2829 const payload_ty = optional_ty.optionalChild(zcu);
28322830
2833 const access_kind: Builder.MemoryAccessKind =2831 const access_kind: Builder.MemoryAccessKind =
...@@ -2896,7 +2894,7 @@ fn airIsErr(...@@ -2896,7 +2894,7 @@ fn airIsErr(
28962894
2897 if (!payload_ty.hasRuntimeBits(zcu)) {2895 if (!payload_ty.hasRuntimeBits(zcu)) {
2898 const loaded = if (operand_is_ptr)2896 const loaded = if (operand_is_ptr)
2899 try self.wip.load(access_kind, try self.lowerType(err_union_ty), operand, operand_ty.ptrAlignment(zcu).toLlvm(), "")2897 try self.wip.load(access_kind, try o.lowerType(err_union_ty), operand, operand_ty.ptrAlignment(zcu).toLlvm(), "")
2900 else2898 else
2901 operand;2899 operand;
2902 return self.wip.icmp(cond, loaded, zero, "");2900 return self.wip.icmp(cond, loaded, zero, "");
...@@ -2981,7 +2979,8 @@ fn airOptionalPayload(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Buil...@@ -2981,7 +2979,8 @@ fn airOptionalPayload(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Buil
2981}2979}
29822980
2983fn airErrUnionPayload(self: *FuncGen, inst: Air.Inst.Index, operand_is_ptr: bool) Allocator.Error!Builder.Value {2981fn airErrUnionPayload(self: *FuncGen, inst: Air.Inst.Index, operand_is_ptr: bool) Allocator.Error!Builder.Value {
2984 const zcu = self.object.zcu;2982 const o = self.object;
2983 const zcu = o.zcu;
2985 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;2984 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2986 const operand = try self.resolveInst(ty_op.operand);2985 const operand = try self.resolveInst(ty_op.operand);
2987 const operand_ty = self.typeOf(ty_op.operand);2986 const operand_ty = self.typeOf(ty_op.operand);
...@@ -3001,7 +3000,7 @@ fn airErrUnionPayload(self: *FuncGen, inst: Air.Inst.Index, operand_is_ptr: bool...@@ -3001,7 +3000,7 @@ fn airErrUnionPayload(self: *FuncGen, inst: Air.Inst.Index, operand_is_ptr: bool
3001 if (isByRef(payload_ty, zcu)) {3000 if (isByRef(payload_ty, zcu)) {
3002 return self.loadByRef(payload_ptr, payload_ty, payload_alignment, .normal);3001 return self.loadByRef(payload_ptr, payload_ty, payload_alignment, .normal);
3003 } else {3002 } else {
3004 const payload_llvm_ty = try self.lowerType(payload_ty);3003 const payload_llvm_ty = try o.lowerType(payload_ty);
3005 return self.wip.load(.normal, payload_llvm_ty, payload_ptr, payload_alignment, "");3004 return self.wip.load(.normal, payload_llvm_ty, payload_ptr, payload_alignment, "");
3006 }3005 }
3007}3006}
...@@ -3148,7 +3147,7 @@ fn airWrapOptional(self: *FuncGen, body_tail: []const Air.Inst.Index) Allocator....@@ -3148,7 +3147,7 @@ fn airWrapOptional(self: *FuncGen, body_tail: []const Air.Inst.Index) Allocator.
3148 const optional_ty = self.typeOfIndex(inst);3147 const optional_ty = self.typeOfIndex(inst);
3149 if (optional_ty.optionalReprIsPayload(zcu)) return operand;3148 if (optional_ty.optionalReprIsPayload(zcu)) return operand;
3150 assert(isByRef(optional_ty, zcu)); // optionals with runtime bits are by-ref unless `optionalReprIsPayload`3149 assert(isByRef(optional_ty, zcu)); // optionals with runtime bits are by-ref unless `optionalReprIsPayload`
3151 const llvm_optional_ty = try self.lowerType(optional_ty);3150 const llvm_optional_ty = try o.lowerType(optional_ty);
3152 const optional_ptr = if (self.isNextRet(body_tail))3151 const optional_ptr = if (self.isNextRet(body_tail))
3153 self.ret_ptr3152 self.ret_ptr
3154 else brk: {3153 else brk: {
...@@ -3181,7 +3180,7 @@ fn airWrapErrUnionPayload(self: *FuncGen, body_tail: []const Air.Inst.Index) All...@@ -3181,7 +3180,7 @@ fn airWrapErrUnionPayload(self: *FuncGen, body_tail: []const Air.Inst.Index) All
3181 assert(payload_ty.hasRuntimeBits(zcu));3180 assert(payload_ty.hasRuntimeBits(zcu));
3182 assert(isByRef(err_un_ty, zcu)); // error unions with runtime bits are always by-ref3181 assert(isByRef(err_un_ty, zcu)); // error unions with runtime bits are always by-ref
3183 const ok_err_code = try o.builder.intValue(try o.errorIntType(), 0);3182 const ok_err_code = try o.builder.intValue(try o.errorIntType(), 0);
3184 const err_un_llvm_ty = try self.lowerType(err_un_ty);3183 const err_un_llvm_ty = try o.lowerType(err_un_ty);
31853184
3186 const result_ptr = if (self.isNextRet(body_tail))3185 const result_ptr = if (self.isNextRet(body_tail))
3187 self.ret_ptr3186 self.ret_ptr
...@@ -3205,7 +3204,8 @@ fn airWrapErrUnionPayload(self: *FuncGen, body_tail: []const Air.Inst.Index) All...@@ -3205,7 +3204,8 @@ fn airWrapErrUnionPayload(self: *FuncGen, body_tail: []const Air.Inst.Index) All
3205}3204}
32063205
3207fn airWrapErrUnionErr(self: *FuncGen, body_tail: []const Air.Inst.Index) Allocator.Error!Builder.Value {3206fn airWrapErrUnionErr(self: *FuncGen, body_tail: []const Air.Inst.Index) Allocator.Error!Builder.Value {
3208 const zcu = self.object.zcu;3207 const o = self.object;
3208 const zcu = o.zcu;
3209 const inst = body_tail[0];3209 const inst = body_tail[0];
3210 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;3210 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3211 const err_un_ty = self.typeOfIndex(inst);3211 const err_un_ty = self.typeOfIndex(inst);
...@@ -3213,7 +3213,7 @@ fn airWrapErrUnionErr(self: *FuncGen, body_tail: []const Air.Inst.Index) Allocat...@@ -3213,7 +3213,7 @@ fn airWrapErrUnionErr(self: *FuncGen, body_tail: []const Air.Inst.Index) Allocat
3213 const operand = try self.resolveInst(ty_op.operand);3213 const operand = try self.resolveInst(ty_op.operand);
3214 if (!payload_ty.hasRuntimeBits(zcu)) return operand;3214 if (!payload_ty.hasRuntimeBits(zcu)) return operand;
3215 assert(isByRef(err_un_ty, zcu)); // error unions with runtime bits are always by-ref3215 assert(isByRef(err_un_ty, zcu)); // error unions with runtime bits are always by-ref
3216 const err_un_llvm_ty = try self.lowerType(err_un_ty);3216 const err_un_llvm_ty = try o.lowerType(err_un_ty);
32173217
3218 const result_ptr = if (self.isNextRet(body_tail))3218 const result_ptr = if (self.isNextRet(body_tail))
3219 self.ret_ptr3219 self.ret_ptr
...@@ -3236,7 +3236,7 @@ fn airWasmMemorySize(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Build...@@ -3236,7 +3236,7 @@ fn airWasmMemorySize(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Build
3236 const o = self.object;3236 const o = self.object;
3237 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;3237 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
3238 const index = pl_op.payload;3238 const index = pl_op.payload;
3239 const llvm_usize = try self.lowerType(.usize);3239 const llvm_usize = try o.lowerType(.usize);
3240 return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.size", &.{llvm_usize}, &.{3240 return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.size", &.{llvm_usize}, &.{
3241 try o.builder.intValue(.i32, index),3241 try o.builder.intValue(.i32, index),
3242 }, "");3242 }, "");
...@@ -3246,7 +3246,7 @@ fn airWasmMemoryGrow(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Build...@@ -3246,7 +3246,7 @@ fn airWasmMemoryGrow(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Build
3246 const o = self.object;3246 const o = self.object;
3247 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;3247 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
3248 const index = pl_op.payload;3248 const index = pl_op.payload;
3249 const llvm_isize = try self.lowerType(.isize);3249 const llvm_isize = try o.lowerType(.isize);
3250 return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.grow", &.{llvm_isize}, &.{3250 return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.grow", &.{llvm_isize}, &.{
3251 try o.builder.intValue(.i32, index), try self.resolveInst(pl_op.operand),3251 try o.builder.intValue(.i32, index), try self.resolveInst(pl_op.operand),
3252 }, "");3252 }, "");
...@@ -3260,7 +3260,8 @@ fn airRuntimeNavPtr(fg: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder....@@ -3260,7 +3260,8 @@ fn airRuntimeNavPtr(fg: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.
3260}3260}
32613261
3262fn airMin(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {3262fn airMin(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {
3263 const zcu = self.object.zcu;3263 const o = self.object;
3264 const zcu = o.zcu;
3264 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;3265 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
3265 const lhs = try self.resolveInst(bin_op.lhs);3266 const lhs = try self.resolveInst(bin_op.lhs);
3266 const rhs = try self.resolveInst(bin_op.rhs);3267 const rhs = try self.resolveInst(bin_op.rhs);
...@@ -3272,14 +3273,15 @@ fn airMin(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {...@@ -3272,14 +3273,15 @@ fn airMin(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {
3272 .normal,3273 .normal,
3273 .none,3274 .none,
3274 if (scalar_ty.isSignedInt(zcu)) .smin else .umin,3275 if (scalar_ty.isSignedInt(zcu)) .smin else .umin,
3275 &.{try self.lowerType(inst_ty)},3276 &.{try o.lowerType(inst_ty)},
3276 &.{ lhs, rhs },3277 &.{ lhs, rhs },
3277 "",3278 "",
3278 );3279 );
3279}3280}
32803281
3281fn airMax(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {3282fn airMax(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {
3282 const zcu = self.object.zcu;3283 const o = self.object;
3284 const zcu = o.zcu;
3283 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;3285 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
3284 const lhs = try self.resolveInst(bin_op.lhs);3286 const lhs = try self.resolveInst(bin_op.lhs);
3285 const rhs = try self.resolveInst(bin_op.rhs);3287 const rhs = try self.resolveInst(bin_op.rhs);
...@@ -3291,7 +3293,7 @@ fn airMax(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {...@@ -3291,7 +3293,7 @@ fn airMax(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {
3291 .normal,3293 .normal,
3292 .none,3294 .none,
3293 if (scalar_ty.isSignedInt(zcu)) .smax else .umax,3295 if (scalar_ty.isSignedInt(zcu)) .smax else .umax,
3294 &.{try self.lowerType(inst_ty)},3296 &.{try o.lowerType(inst_ty)},
3295 &.{ lhs, rhs },3297 &.{ lhs, rhs },
3296 "",3298 "",
3297 );3299 );
...@@ -3303,7 +3305,7 @@ fn airSlice(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value...@@ -3303,7 +3305,7 @@ fn airSlice(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value
3303 const ptr = try self.resolveInst(bin_op.lhs);3305 const ptr = try self.resolveInst(bin_op.lhs);
3304 const len = try self.resolveInst(bin_op.rhs);3306 const len = try self.resolveInst(bin_op.rhs);
3305 const inst_ty = self.typeOfIndex(inst);3307 const inst_ty = self.typeOfIndex(inst);
3306 return self.wip.buildAggregate(try self.lowerType(inst_ty), &.{ ptr, len }, "");3308 return self.wip.buildAggregate(try self.object.lowerType(inst_ty), &.{ ptr, len }, "");
3307}3309}
33083310
3309fn airAdd(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) Allocator.Error!Builder.Value {3311fn airAdd(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) Allocator.Error!Builder.Value {
...@@ -3334,7 +3336,7 @@ fn airSafeArithmetic(...@@ -3334,7 +3336,7 @@ fn airSafeArithmetic(
3334 const scalar_ty = inst_ty.scalarType(zcu);3336 const scalar_ty = inst_ty.scalarType(zcu);
33353337
3336 const intrinsic = if (scalar_ty.isSignedInt(zcu)) signed_intrinsic else unsigned_intrinsic;3338 const intrinsic = if (scalar_ty.isSignedInt(zcu)) signed_intrinsic else unsigned_intrinsic;
3337 const llvm_inst_ty = try fg.lowerType(inst_ty);3339 const llvm_inst_ty = try o.lowerType(inst_ty);
3338 const results =3340 const results =
3339 try fg.wip.callIntrinsic(.normal, .none, intrinsic, &.{llvm_inst_ty}, &.{ lhs, rhs }, "");3341 try fg.wip.callIntrinsic(.normal, .none, intrinsic, &.{llvm_inst_ty}, &.{ lhs, rhs }, "");
33403342
...@@ -3372,7 +3374,8 @@ fn airAddWrap(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Valu...@@ -3372,7 +3374,8 @@ fn airAddWrap(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Valu
3372}3374}
33733375
3374fn airAddSat(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {3376fn airAddSat(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {
3375 const zcu = self.object.zcu;3377 const o = self.object;
3378 const zcu = o.zcu;
3376 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;3379 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
3377 const lhs = try self.resolveInst(bin_op.lhs);3380 const lhs = try self.resolveInst(bin_op.lhs);
3378 const rhs = try self.resolveInst(bin_op.rhs);3381 const rhs = try self.resolveInst(bin_op.rhs);
...@@ -3383,7 +3386,7 @@ fn airAddSat(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value...@@ -3383,7 +3386,7 @@ fn airAddSat(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value
3383 .normal,3386 .normal,
3384 .none,3387 .none,
3385 if (scalar_ty.isSignedInt(zcu)) .@"sadd.sat" else .@"uadd.sat",3388 if (scalar_ty.isSignedInt(zcu)) .@"sadd.sat" else .@"uadd.sat",
3386 &.{try self.lowerType(inst_ty)},3389 &.{try o.lowerType(inst_ty)},
3387 &.{ lhs, rhs },3390 &.{ lhs, rhs },
3388 "",3391 "",
3389 );3392 );
...@@ -3410,7 +3413,8 @@ fn airSubWrap(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Valu...@@ -3410,7 +3413,8 @@ fn airSubWrap(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Valu
3410}3413}
34113414
3412fn airSubSat(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {3415fn airSubSat(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {
3413 const zcu = self.object.zcu;3416 const o = self.object;
3417 const zcu = o.zcu;
3414 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;3418 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
3415 const lhs = try self.resolveInst(bin_op.lhs);3419 const lhs = try self.resolveInst(bin_op.lhs);
3416 const rhs = try self.resolveInst(bin_op.rhs);3420 const rhs = try self.resolveInst(bin_op.rhs);
...@@ -3421,7 +3425,7 @@ fn airSubSat(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value...@@ -3421,7 +3425,7 @@ fn airSubSat(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value
3421 .normal,3425 .normal,
3422 .none,3426 .none,
3423 if (scalar_ty.isSignedInt(zcu)) .@"ssub.sat" else .@"usub.sat",3427 if (scalar_ty.isSignedInt(zcu)) .@"ssub.sat" else .@"usub.sat",
3424 &.{try self.lowerType(inst_ty)},3428 &.{try o.lowerType(inst_ty)},
3425 &.{ lhs, rhs },3429 &.{ lhs, rhs },
3426 "",3430 "",
3427 );3431 );
...@@ -3448,7 +3452,8 @@ fn airMulWrap(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Valu...@@ -3448,7 +3452,8 @@ fn airMulWrap(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Valu
3448}3452}
34493453
3450fn airMulSat(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {3454fn airMulSat(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {
3451 const zcu = self.object.zcu;3455 const o = self.object;
3456 const zcu = o.zcu;
3452 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;3457 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
3453 const lhs = try self.resolveInst(bin_op.lhs);3458 const lhs = try self.resolveInst(bin_op.lhs);
3454 const rhs = try self.resolveInst(bin_op.rhs);3459 const rhs = try self.resolveInst(bin_op.rhs);
...@@ -3459,7 +3464,7 @@ fn airMulSat(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value...@@ -3459,7 +3464,7 @@ fn airMulSat(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value
3459 .normal,3464 .normal,
3460 .none,3465 .none,
3461 if (scalar_ty.isSignedInt(zcu)) .@"smul.fix.sat" else .@"umul.fix.sat",3466 if (scalar_ty.isSignedInt(zcu)) .@"smul.fix.sat" else .@"umul.fix.sat",
3462 &.{try self.lowerType(inst_ty)},3467 &.{try o.lowerType(inst_ty)},
3463 &.{ lhs, rhs, .@"0" },3468 &.{ lhs, rhs, .@"0" },
3464 "",3469 "",
3465 );3470 );
...@@ -3503,7 +3508,7 @@ fn airDivFloor(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind)...@@ -3503,7 +3508,7 @@ fn airDivFloor(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind)
3503 return self.buildFloatOp(.floor, fast, inst_ty, 1, .{result});3508 return self.buildFloatOp(.floor, fast, inst_ty, 1, .{result});
3504 }3509 }
3505 if (scalar_ty.isSignedInt(zcu)) {3510 if (scalar_ty.isSignedInt(zcu)) {
3506 const inst_llvm_ty = try self.lowerType(inst_ty);3511 const inst_llvm_ty = try o.lowerType(inst_ty);
35073512
3508 const ExpectedContents = [std.math.big.int.calcTwosCompLimbCount(256)]std.math.big.Limb;3513 const ExpectedContents = [std.math.big.int.calcTwosCompLimbCount(256)]std.math.big.Limb;
3509 var stack align(@max(3514 var stack align(@max(
...@@ -3579,7 +3584,7 @@ fn airMod(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) Allo...@@ -3579,7 +3584,7 @@ fn airMod(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) Allo
3579 const lhs = try self.resolveInst(bin_op.lhs);3584 const lhs = try self.resolveInst(bin_op.lhs);
3580 const rhs = try self.resolveInst(bin_op.rhs);3585 const rhs = try self.resolveInst(bin_op.rhs);
3581 const inst_ty = self.typeOfIndex(inst);3586 const inst_ty = self.typeOfIndex(inst);
3582 const inst_llvm_ty = try self.lowerType(inst_ty);3587 const inst_llvm_ty = try o.lowerType(inst_ty);
3583 const scalar_ty = inst_ty.scalarType(zcu);3588 const scalar_ty = inst_ty.scalarType(zcu);
35843589
3585 if (scalar_ty.isRuntimeFloat()) {3590 if (scalar_ty.isRuntimeFloat()) {
...@@ -3646,7 +3651,7 @@ fn airPtrSub(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value...@@ -3646,7 +3651,7 @@ fn airPtrSub(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value
3646 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;3651 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
3647 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;3652 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
3648 const ptr_or_slice = try self.resolveInst(bin_op.lhs);3653 const ptr_or_slice = try self.resolveInst(bin_op.lhs);
3649 const llvm_usize_ty = try self.lowerType(.usize);3654 const llvm_usize_ty = try o.lowerType(.usize);
3650 const ptr_ty = self.typeOf(bin_op.lhs);3655 const ptr_ty = self.typeOf(bin_op.lhs);
3651 const elem_ty = ptr_ty.indexableElem(zcu);3656 const elem_ty = ptr_ty.indexableElem(zcu);
3652 const ptr = switch (ptr_ty.ptrSize(zcu)) {3657 const ptr = switch (ptr_ty.ptrSize(zcu)) {
...@@ -3665,7 +3670,8 @@ fn airOverflow(...@@ -3665,7 +3670,8 @@ fn airOverflow(
3665 signed_intrinsic: Builder.Intrinsic,3670 signed_intrinsic: Builder.Intrinsic,
3666 unsigned_intrinsic: Builder.Intrinsic,3671 unsigned_intrinsic: Builder.Intrinsic,
3667) Allocator.Error!Builder.Value {3672) Allocator.Error!Builder.Value {
3668 const zcu = self.object.zcu;3673 const o = self.object;
3674 const zcu = o.zcu;
3669 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;3675 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
3670 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;3676 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
36713677
...@@ -3678,8 +3684,8 @@ fn airOverflow(...@@ -3678,8 +3684,8 @@ fn airOverflow(
3678 assert(isByRef(inst_ty, zcu)); // auto structs are by-ref3684 assert(isByRef(inst_ty, zcu)); // auto structs are by-ref
36793685
3680 const intrinsic = if (scalar_ty.isSignedInt(zcu)) signed_intrinsic else unsigned_intrinsic;3686 const intrinsic = if (scalar_ty.isSignedInt(zcu)) signed_intrinsic else unsigned_intrinsic;
3681 const llvm_inst_ty = try self.lowerType(inst_ty);3687 const llvm_inst_ty = try o.lowerType(inst_ty);
3682 const llvm_lhs_ty = try self.lowerType(lhs_ty);3688 const llvm_lhs_ty = try o.lowerType(lhs_ty);
3683 const results =3689 const results =
3684 try self.wip.callIntrinsic(.normal, .none, intrinsic, &.{llvm_lhs_ty}, &.{ lhs, rhs }, "");3690 try self.wip.callIntrinsic(.normal, .none, intrinsic, &.{llvm_lhs_ty}, &.{ lhs, rhs }, "");
36853691
...@@ -3750,7 +3756,7 @@ fn buildFloatCmp(...@@ -3750,7 +3756,7 @@ fn buildFloatCmp(
3750 const zcu = o.zcu;3756 const zcu = o.zcu;
3751 const target = zcu.getTarget();3757 const target = zcu.getTarget();
3752 const scalar_ty = ty.scalarType(zcu);3758 const scalar_ty = ty.scalarType(zcu);
3753 const scalar_llvm_ty = try self.lowerType(scalar_ty);3759 const scalar_llvm_ty = try o.lowerType(scalar_ty);
37543760
3755 if (intrinsicsAllowed(scalar_ty, target)) {3761 if (intrinsicsAllowed(scalar_ty, target)) {
3756 const cond: Builder.FloatCondition = switch (pred) {3762 const cond: Builder.FloatCondition = switch (pred) {
...@@ -3856,7 +3862,7 @@ fn buildFloatOp(...@@ -3856,7 +3862,7 @@ fn buildFloatOp(
3856 const zcu = o.zcu;3862 const zcu = o.zcu;
3857 const target = zcu.getTarget();3863 const target = zcu.getTarget();
3858 const scalar_ty = ty.scalarType(zcu);3864 const scalar_ty = ty.scalarType(zcu);
3859 const llvm_ty = try self.lowerType(ty);3865 const llvm_ty = try o.lowerType(ty);
38603866
3861 if (op != .tan and intrinsicsAllowed(scalar_ty, target)) switch (op) {3867 if (op != .tan and intrinsicsAllowed(scalar_ty, target)) switch (op) {
3862 // Some operations are dedicated LLVM instructions, not available as intrinsics3868 // Some operations are dedicated LLVM instructions, not available as intrinsics
...@@ -3993,7 +3999,8 @@ fn airMulAdd(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value...@@ -3993,7 +3999,8 @@ fn airMulAdd(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value
3993}3999}
39944000
3995fn airShlWithOverflow(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {4001fn airShlWithOverflow(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {
3996 const zcu = self.object.zcu;4002 const o = self.object;
4003 const zcu = o.zcu;
3997 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;4004 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
3998 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;4005 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
39994006
...@@ -4011,9 +4018,9 @@ fn airShlWithOverflow(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Buil...@@ -4011,9 +4018,9 @@ fn airShlWithOverflow(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Buil
40114018
4012 const dest_ty = self.typeOfIndex(inst);4019 const dest_ty = self.typeOfIndex(inst);
4013 assert(isByRef(dest_ty, zcu)); // auto structs are by-ref4020 assert(isByRef(dest_ty, zcu)); // auto structs are by-ref
4014 const llvm_dest_ty = try self.lowerType(dest_ty);4021 const llvm_dest_ty = try o.lowerType(dest_ty);
40154022
4016 const casted_rhs = try self.wip.conv(.unsigned, rhs, try self.lowerType(lhs_ty), "");4023 const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(lhs_ty), "");
40174024
4018 const result = try self.wip.bin(.shl, lhs, casted_rhs, "");4025 const result = try self.wip.bin(.shl, lhs, casted_rhs, "");
4019 const reconstructed = try self.wip.bin(if (lhs_scalar_ty.isSignedInt(zcu))4026 const reconstructed = try self.wip.bin(if (lhs_scalar_ty.isSignedInt(zcu))
...@@ -4063,7 +4070,8 @@ fn airXor(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {...@@ -4063,7 +4070,8 @@ fn airXor(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {
4063}4070}
40644071
4065fn airShlExact(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {4072fn airShlExact(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {
4066 const zcu = self.object.zcu;4073 const o = self.object;
4074 const zcu = o.zcu;
4067 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;4075 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
40684076
4069 const lhs = try self.resolveInst(bin_op.lhs);4077 const lhs = try self.resolveInst(bin_op.lhs);
...@@ -4077,7 +4085,7 @@ fn airShlExact(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Val...@@ -4077,7 +4085,7 @@ fn airShlExact(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Val
4077 }4085 }
4078 const lhs_scalar_ty = lhs_ty.scalarType(zcu);4086 const lhs_scalar_ty = lhs_ty.scalarType(zcu);
40794087
4080 const casted_rhs = try self.wip.conv(.unsigned, rhs, try self.lowerType(lhs_ty), "");4088 const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(lhs_ty), "");
4081 return self.wip.bin(if (lhs_scalar_ty.isSignedInt(zcu))4089 return self.wip.bin(if (lhs_scalar_ty.isSignedInt(zcu))
4082 .@"shl nsw"4090 .@"shl nsw"
4083 else4091 else
...@@ -4085,7 +4093,8 @@ fn airShlExact(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Val...@@ -4085,7 +4093,8 @@ fn airShlExact(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Val
4085}4093}
40864094
4087fn airShl(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {4095fn airShl(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {
4088 const zcu = self.object.zcu;4096 const o = self.object;
4097 const zcu = o.zcu;
4089 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;4098 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
40904099
4091 const lhs = try self.resolveInst(bin_op.lhs);4100 const lhs = try self.resolveInst(bin_op.lhs);
...@@ -4097,7 +4106,7 @@ fn airShl(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {...@@ -4097,7 +4106,7 @@ fn airShl(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {
4097 // features which we do not use. Therefore this branch is currently impossible.4106 // features which we do not use. Therefore this branch is currently impossible.
4098 unreachable;4107 unreachable;
4099 }4108 }
4100 const casted_rhs = try self.wip.conv(.unsigned, rhs, try self.lowerType(lhs_ty), "");4109 const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(lhs_ty), "");
4101 return self.wip.bin(.shl, lhs, casted_rhs, "");4110 return self.wip.bin(.shl, lhs, casted_rhs, "");
4102}4111}
41034112
...@@ -4111,7 +4120,7 @@ fn airShlSat(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value...@@ -4111,7 +4120,7 @@ fn airShlSat(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value
41114120
4112 const lhs_ty = self.typeOf(bin_op.lhs);4121 const lhs_ty = self.typeOf(bin_op.lhs);
4113 const lhs_info = lhs_ty.intInfo(zcu);4122 const lhs_info = lhs_ty.intInfo(zcu);
4114 const llvm_lhs_ty = try self.lowerType(lhs_ty);4123 const llvm_lhs_ty = try o.lowerType(lhs_ty);
4115 const llvm_lhs_scalar_ty = llvm_lhs_ty.scalarType(&o.builder);4124 const llvm_lhs_scalar_ty = llvm_lhs_ty.scalarType(&o.builder);
41164125
4117 const rhs_ty = self.typeOf(bin_op.rhs);4126 const rhs_ty = self.typeOf(bin_op.rhs);
...@@ -4122,7 +4131,7 @@ fn airShlSat(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value...@@ -4122,7 +4131,7 @@ fn airShlSat(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value
4122 }4131 }
4123 const rhs_info = rhs_ty.intInfo(zcu);4132 const rhs_info = rhs_ty.intInfo(zcu);
4124 assert(rhs_info.signedness == .unsigned);4133 assert(rhs_info.signedness == .unsigned);
4125 const llvm_rhs_ty = try self.lowerType(rhs_ty);4134 const llvm_rhs_ty = try o.lowerType(rhs_ty);
4126 const llvm_rhs_scalar_ty = llvm_rhs_ty.scalarType(&o.builder);4135 const llvm_rhs_scalar_ty = llvm_rhs_ty.scalarType(&o.builder);
41274136
4128 const result = try self.wip.callIntrinsic(4137 const result = try self.wip.callIntrinsic(
...@@ -4184,7 +4193,8 @@ fn airShlSat(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value...@@ -4184,7 +4193,8 @@ fn airShlSat(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value
4184}4193}
41854194
4186fn airShr(self: *FuncGen, inst: Air.Inst.Index, is_exact: bool) Allocator.Error!Builder.Value {4195fn airShr(self: *FuncGen, inst: Air.Inst.Index, is_exact: bool) Allocator.Error!Builder.Value {
4187 const zcu = self.object.zcu;4196 const o = self.object;
4197 const zcu = o.zcu;
4188 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;4198 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
41894199
4190 const lhs = try self.resolveInst(bin_op.lhs);4200 const lhs = try self.resolveInst(bin_op.lhs);
...@@ -4198,7 +4208,7 @@ fn airShr(self: *FuncGen, inst: Air.Inst.Index, is_exact: bool) Allocator.Error!...@@ -4198,7 +4208,7 @@ fn airShr(self: *FuncGen, inst: Air.Inst.Index, is_exact: bool) Allocator.Error!
4198 }4208 }
4199 const lhs_scalar_ty = lhs_ty.scalarType(zcu);4209 const lhs_scalar_ty = lhs_ty.scalarType(zcu);
42004210
4201 const casted_rhs = try self.wip.conv(.unsigned, rhs, try self.lowerType(lhs_ty), "");4211 const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(lhs_ty), "");
4202 const is_signed_int = lhs_scalar_ty.isSignedInt(zcu);4212 const is_signed_int = lhs_scalar_ty.isSignedInt(zcu);
42034213
4204 return self.wip.bin(if (is_exact)4214 return self.wip.bin(if (is_exact)
...@@ -4219,7 +4229,7 @@ fn airAbs(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {...@@ -4219,7 +4229,7 @@ fn airAbs(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {
4219 .normal,4229 .normal,
4220 .none,4230 .none,
4221 .abs,4231 .abs,
4222 &.{try self.lowerType(operand_ty)},4232 &.{try o.lowerType(operand_ty)},
4223 &.{ operand, try o.builder.intValue(.i1, 0) },4233 &.{ operand, try o.builder.intValue(.i1, 0) },
4224 "",4234 "",
4225 ),4235 ),
...@@ -4233,7 +4243,7 @@ fn airIntCast(fg: *FuncGen, inst: Air.Inst.Index, safety: bool) Allocator.Error!...@@ -4233,7 +4243,7 @@ fn airIntCast(fg: *FuncGen, inst: Air.Inst.Index, safety: bool) Allocator.Error!
4233 const zcu = o.zcu;4243 const zcu = o.zcu;
4234 const ty_op = fg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;4244 const ty_op = fg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
4235 const dest_ty = fg.typeOfIndex(inst);4245 const dest_ty = fg.typeOfIndex(inst);
4236 const dest_llvm_ty = try fg.lowerType(dest_ty);4246 const dest_llvm_ty = try o.lowerType(dest_ty);
4237 const operand = try fg.resolveInst(ty_op.operand);4247 const operand = try fg.resolveInst(ty_op.operand);
4238 const operand_ty = fg.typeOf(ty_op.operand);4248 const operand_ty = fg.typeOf(ty_op.operand);
4239 const operand_info = operand_ty.intInfo(zcu);4249 const operand_info = operand_ty.intInfo(zcu);
...@@ -4261,8 +4271,8 @@ fn airIntCast(fg: *FuncGen, inst: Air.Inst.Index, safety: bool) Allocator.Error!...@@ -4261,8 +4271,8 @@ fn airIntCast(fg: *FuncGen, inst: Air.Inst.Index, safety: bool) Allocator.Error!
42614271
4262 if (!have_min_check and !have_max_check) break :bounds_check;4272 if (!have_min_check and !have_max_check) break :bounds_check;
42634273
4264 const operand_llvm_ty = try fg.lowerType(operand_ty);4274 const operand_llvm_ty = try o.lowerType(operand_ty);
4265 const operand_scalar_llvm_ty = try fg.lowerType(operand_scalar);4275 const operand_scalar_llvm_ty = try o.lowerType(operand_scalar);
42664276
4267 const is_vector = operand_ty.zigTypeTag(zcu) == .vector;4277 const is_vector = operand_ty.zigTypeTag(zcu) == .vector;
4268 assert(is_vector == (dest_ty.zigTypeTag(zcu) == .vector));4278 assert(is_vector == (dest_ty.zigTypeTag(zcu) == .vector));
...@@ -4340,7 +4350,7 @@ fn airIntCast(fg: *FuncGen, inst: Air.Inst.Index, safety: bool) Allocator.Error!...@@ -4340,7 +4350,7 @@ fn airIntCast(fg: *FuncGen, inst: Air.Inst.Index, safety: bool) Allocator.Error!
4340fn airTrunc(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {4350fn airTrunc(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {
4341 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;4351 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
4342 const operand = try self.resolveInst(ty_op.operand);4352 const operand = try self.resolveInst(ty_op.operand);
4343 const dest_llvm_ty = try self.lowerType(self.typeOfIndex(inst));4353 const dest_llvm_ty = try self.object.lowerType(self.typeOfIndex(inst));
4344 return self.wip.cast(.trunc, operand, dest_llvm_ty, "");4354 return self.wip.cast(.trunc, operand, dest_llvm_ty, "");
4345}4355}
43464356
...@@ -4354,10 +4364,10 @@ fn airFptrunc(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Valu...@@ -4354,10 +4364,10 @@ fn airFptrunc(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Valu
4354 const target = zcu.getTarget();4364 const target = zcu.getTarget();
43554365
4356 if (intrinsicsAllowed(dest_ty, target) and intrinsicsAllowed(operand_ty, target)) {4366 if (intrinsicsAllowed(dest_ty, target) and intrinsicsAllowed(operand_ty, target)) {
4357 return self.wip.cast(.fptrunc, operand, try self.lowerType(dest_ty), "");4367 return self.wip.cast(.fptrunc, operand, try o.lowerType(dest_ty), "");
4358 } else {4368 } else {
4359 const operand_llvm_ty = try self.lowerType(operand_ty);4369 const operand_llvm_ty = try o.lowerType(operand_ty);
4360 const dest_llvm_ty = try self.lowerType(dest_ty);4370 const dest_llvm_ty = try o.lowerType(dest_ty);
43614371
4362 const dest_bits = dest_ty.floatBits(target);4372 const dest_bits = dest_ty.floatBits(target);
4363 const src_bits = operand_ty.floatBits(target);4373 const src_bits = operand_ty.floatBits(target);
...@@ -4388,10 +4398,10 @@ fn airFpext(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value...@@ -4388,10 +4398,10 @@ fn airFpext(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value
4388 const target = zcu.getTarget();4398 const target = zcu.getTarget();
43894399
4390 if (intrinsicsAllowed(dest_ty, target) and intrinsicsAllowed(operand_ty, target)) {4400 if (intrinsicsAllowed(dest_ty, target) and intrinsicsAllowed(operand_ty, target)) {
4391 return self.wip.cast(.fpext, operand, try self.lowerType(dest_ty), "");4401 return self.wip.cast(.fpext, operand, try o.lowerType(dest_ty), "");
4392 } else {4402 } else {
4393 const operand_llvm_ty = try self.lowerType(operand_ty);4403 const operand_llvm_ty = try o.lowerType(operand_ty);
4394 const dest_llvm_ty = try self.lowerType(dest_ty);4404 const dest_llvm_ty = try o.lowerType(dest_ty);
43954405
4396 const dest_bits = dest_ty.scalarType(zcu).floatBits(target);4406 const dest_bits = dest_ty.scalarType(zcu).floatBits(target);
4397 const src_bits = operand_ty.scalarType(zcu).floatBits(target);4407 const src_bits = operand_ty.scalarType(zcu).floatBits(target);
...@@ -4431,7 +4441,7 @@ fn bitCast(self: *FuncGen, operand: Builder.Value, operand_ty: Type, inst_ty: Ty...@@ -4431,7 +4441,7 @@ fn bitCast(self: *FuncGen, operand: Builder.Value, operand_ty: Type, inst_ty: Ty
4431 const zcu = o.zcu;4441 const zcu = o.zcu;
4432 const operand_is_ref = isByRef(operand_ty, zcu);4442 const operand_is_ref = isByRef(operand_ty, zcu);
4433 const result_is_ref = isByRef(inst_ty, zcu);4443 const result_is_ref = isByRef(inst_ty, zcu);
4434 const llvm_dest_ty = try self.lowerType(inst_ty);4444 const llvm_dest_ty = try o.lowerType(inst_ty);
44354445
4436 if (operand_is_ref and result_is_ref) {4446 if (operand_is_ref and result_is_ref) {
4437 // They are both pointers, so just return the same opaque pointer :)4447 // They are both pointers, so just return the same opaque pointer :)
...@@ -4477,7 +4487,7 @@ fn bitCast(self: *FuncGen, operand: Builder.Value, operand_ty: Type, inst_ty: Ty...@@ -4477,7 +4487,7 @@ fn bitCast(self: *FuncGen, operand: Builder.Value, operand_ty: Type, inst_ty: Ty
4477 } else if (operand_ty.zigTypeTag(zcu) == .array and inst_ty.zigTypeTag(zcu) == .vector) {4487 } else if (operand_ty.zigTypeTag(zcu) == .array and inst_ty.zigTypeTag(zcu) == .vector) {
4478 const elem_ty = operand_ty.childType(zcu);4488 const elem_ty = operand_ty.childType(zcu);
4479 assert(operand_is_ref); // arrays are always by-ref provided they have runtime bits4489 assert(operand_is_ref); // arrays are always by-ref provided they have runtime bits
4480 const llvm_vector_ty = try self.lowerType(inst_ty);4490 const llvm_vector_ty = try o.lowerType(inst_ty);
44814491
4482 const bitcast_ok = elem_ty.bitSize(zcu) == elem_ty.abiSize(zcu) * 8;4492 const bitcast_ok = elem_ty.bitSize(zcu) == elem_ty.abiSize(zcu) * 8;
4483 if (bitcast_ok) {4493 if (bitcast_ok) {
...@@ -4488,7 +4498,7 @@ fn bitCast(self: *FuncGen, operand: Builder.Value, operand_ty: Type, inst_ty: Ty...@@ -4488,7 +4498,7 @@ fn bitCast(self: *FuncGen, operand: Builder.Value, operand_ty: Type, inst_ty: Ty
4488 } else {4498 } else {
4489 // If the ABI size of the element type is not evenly divisible by size in bits;4499 // If the ABI size of the element type is not evenly divisible by size in bits;
4490 // a simple bitcast will not work, and we fall back to extractelement.4500 // a simple bitcast will not work, and we fall back to extractelement.
4491 const elem_llvm_ty = try self.lowerType(elem_ty);4501 const elem_llvm_ty = try o.lowerType(elem_ty);
4492 const elem_size = elem_ty.abiSize(zcu);4502 const elem_size = elem_ty.abiSize(zcu);
4493 const vector_len = operand_ty.arrayLen(zcu);4503 const vector_len = operand_ty.arrayLen(zcu);
4494 var vector = try o.builder.poisonValue(llvm_vector_ty);4504 var vector = try o.builder.poisonValue(llvm_vector_ty);
...@@ -4629,7 +4639,7 @@ fn airAlloc(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value...@@ -4629,7 +4639,7 @@ fn airAlloc(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value
4629 const ptr_info = ptr_ty.ptrInfo(zcu);4639 const ptr_info = ptr_ty.ptrInfo(zcu);
4630 return (try o.lowerPtrToVoid(ptr_info.flags.alignment, ptr_info.flags.address_space)).toValue();4640 return (try o.lowerPtrToVoid(ptr_info.flags.alignment, ptr_info.flags.address_space)).toValue();
4631 }4641 }
4632 const pointee_llvm_ty = try self.lowerType(pointee_type);4642 const pointee_llvm_ty = try o.lowerType(pointee_type);
4633 const alignment = ptr_ty.ptrAlignment(zcu).toLlvm();4643 const alignment = ptr_ty.ptrAlignment(zcu).toLlvm();
4634 return self.buildAlloca(pointee_llvm_ty, alignment);4644 return self.buildAlloca(pointee_llvm_ty, alignment);
4635}4645}
...@@ -4644,7 +4654,7 @@ fn airRetPtr(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value...@@ -4644,7 +4654,7 @@ fn airRetPtr(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value
4644 return (try o.lowerPtrToVoid(ptr_info.flags.alignment, ptr_info.flags.address_space)).toValue();4654 return (try o.lowerPtrToVoid(ptr_info.flags.alignment, ptr_info.flags.address_space)).toValue();
4645 }4655 }
4646 if (self.ret_ptr != .none) return self.ret_ptr;4656 if (self.ret_ptr != .none) return self.ret_ptr;
4647 const ret_llvm_ty = try self.lowerType(ret_ty);4657 const ret_llvm_ty = try o.lowerType(ret_ty);
4648 const alignment = ptr_ty.ptrAlignment(zcu).toLlvm();4658 const alignment = ptr_ty.ptrAlignment(zcu).toLlvm();
4649 return self.buildAlloca(ret_llvm_ty, alignment);4659 return self.buildAlloca(ret_llvm_ty, alignment);
4650}4660}
...@@ -4696,7 +4706,7 @@ fn airStore(self: *FuncGen, inst: Air.Inst.Index, safety: bool) Allocator.Error!...@@ -4696,7 +4706,7 @@ fn airStore(self: *FuncGen, inst: Air.Inst.Index, safety: bool) Allocator.Error!
46964706
4697 self.maybeMarkAllowZeroAccess(ptr_info);4707 self.maybeMarkAllowZeroAccess(ptr_info);
46984708
4699 const len = try o.builder.intValue(try self.lowerType(.usize), operand_ty.abiSize(zcu));4709 const len = try o.builder.intValue(try o.lowerType(.usize), operand_ty.abiSize(zcu));
4700 _ = try self.wip.callMemSet(4710 _ = try self.wip.callMemSet(
4701 dest_ptr,4711 dest_ptr,
4702 ptr_ty.ptrAlignment(zcu).toLlvm(),4712 ptr_ty.ptrAlignment(zcu).toLlvm(),
...@@ -4735,7 +4745,7 @@ fn airLoad(fg: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {...@@ -4735,7 +4745,7 @@ fn airLoad(fg: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {
47354745
4736 if (ptr_info.flags.vector_index != .none) {4746 if (ptr_info.flags.vector_index != .none) {
4737 const index_u32 = try o.builder.intValue(.i32, ptr_info.flags.vector_index);4747 const index_u32 = try o.builder.intValue(.i32, ptr_info.flags.vector_index);
4738 const vec_elem_ty = try fg.lowerType(elem_ty);4748 const vec_elem_ty = try o.lowerType(elem_ty);
4739 const vec_ty = try o.builder.vectorType(.normal, ptr_info.packed_offset.host_size, vec_elem_ty);4749 const vec_ty = try o.builder.vectorType(.normal, ptr_info.packed_offset.host_size, vec_elem_ty);
47404750
4741 const loaded_vector = try fg.wip.load(access_kind, vec_ty, ptr, llvm_ptr_align, "");4751 const loaded_vector = try fg.wip.load(access_kind, vec_ty, ptr, llvm_ptr_align, "");
...@@ -4753,7 +4763,7 @@ fn airLoad(fg: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {...@@ -4753,7 +4763,7 @@ fn airLoad(fg: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {
4753 const elem_bits = ptr_ty.childType(zcu).bitSize(zcu);4763 const elem_bits = ptr_ty.childType(zcu).bitSize(zcu);
4754 const shift_amt = try o.builder.intValue(containing_int_ty, ptr_info.packed_offset.bit_offset);4764 const shift_amt = try o.builder.intValue(containing_int_ty, ptr_info.packed_offset.bit_offset);
4755 const shifted_value = try fg.wip.bin(.lshr, containing_int, shift_amt, "");4765 const shifted_value = try fg.wip.bin(.lshr, containing_int, shift_amt, "");
4756 const elem_llvm_ty = try fg.lowerType(elem_ty);4766 const elem_llvm_ty = try o.lowerType(elem_ty);
47574767
4758 if (isByRef(elem_ty, zcu)) {4768 if (isByRef(elem_ty, zcu)) {
4759 const result_align = elem_ty.abiAlignment(zcu).toLlvm();4769 const result_align = elem_ty.abiAlignment(zcu).toLlvm();
...@@ -4813,7 +4823,7 @@ fn airBreakpoint(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.V...@@ -4813,7 +4823,7 @@ fn airBreakpoint(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.V
4813fn airRetAddr(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {4823fn airRetAddr(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {
4814 _ = inst;4824 _ = inst;
4815 const o = self.object;4825 const o = self.object;
4816 const llvm_usize = try self.lowerType(.usize);4826 const llvm_usize = try o.lowerType(.usize);
4817 if (!target_util.supportsReturnAddress(self.object.zcu.getTarget(), self.ownerModule().optimize_mode)) {4827 if (!target_util.supportsReturnAddress(self.object.zcu.getTarget(), self.ownerModule().optimize_mode)) {
4818 // https://github.com/ziglang/zig/issues/119464828 // https://github.com/ziglang/zig/issues/11946
4819 return o.builder.intValue(llvm_usize, 0);4829 return o.builder.intValue(llvm_usize, 0);
...@@ -4825,7 +4835,7 @@ fn airRetAddr(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Valu...@@ -4825,7 +4835,7 @@ fn airRetAddr(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Valu
4825fn airFrameAddress(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {4835fn airFrameAddress(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {
4826 _ = inst;4836 _ = inst;
4827 const result = try self.wip.callIntrinsic(.normal, .none, .frameaddress, &.{.ptr}, &.{.@"0"}, "");4837 const result = try self.wip.callIntrinsic(.normal, .none, .frameaddress, &.{.ptr}, &.{.@"0"}, "");
4828 return self.wip.cast(.ptrtoint, result, try self.lowerType(.usize), "");4838 return self.wip.cast(.ptrtoint, result, try self.object.lowerType(.usize), "");
4829}4839}
48304840
4831fn airCmpxchg(4841fn airCmpxchg(
...@@ -4842,7 +4852,7 @@ fn airCmpxchg(...@@ -4842,7 +4852,7 @@ fn airCmpxchg(
4842 var expected_value = try self.resolveInst(extra.expected_value);4852 var expected_value = try self.resolveInst(extra.expected_value);
4843 var new_value = try self.resolveInst(extra.new_value);4853 var new_value = try self.resolveInst(extra.new_value);
4844 const operand_ty = ptr_ty.childType(zcu);4854 const operand_ty = ptr_ty.childType(zcu);
4845 const llvm_operand_ty = try self.lowerType(operand_ty);4855 const llvm_operand_ty = try o.lowerType(operand_ty);
4846 const llvm_abi_ty = try self.getAtomicAbiType(operand_ty, false);4856 const llvm_abi_ty = try self.getAtomicAbiType(operand_ty, false);
4847 if (llvm_abi_ty != .none) {4857 if (llvm_abi_ty != .none) {
4848 // operand needs widening and truncating4858 // operand needs widening and truncating
...@@ -4885,7 +4895,7 @@ fn airCmpxchg(...@@ -4885,7 +4895,7 @@ fn airCmpxchg(
4885 const non_null_bit = try self.wip.not(success_bit, "");4895 const non_null_bit = try self.wip.not(success_bit, "");
48864896
4887 const payload_align = operand_ty.abiAlignment(zcu).toLlvm();4897 const payload_align = operand_ty.abiAlignment(zcu).toLlvm();
4888 const alloca_inst = try self.buildAlloca(try self.lowerType(optional_ty), payload_align);4898 const alloca_inst = try self.buildAlloca(try o.lowerType(optional_ty), payload_align);
48894899
4890 // Payload is always the first field at offset 0, so address is `alloca_inst`4900 // Payload is always the first field at offset 0, so address is `alloca_inst`
4891 _ = try self.wip.store(.normal, payload, alloca_inst, payload_align);4901 _ = try self.wip.store(.normal, payload, alloca_inst, payload_align);
...@@ -4911,7 +4921,7 @@ fn airAtomicRmw(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Va...@@ -4911,7 +4921,7 @@ fn airAtomicRmw(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Va
4911 const op = toLlvmAtomicRmwBinOp(extra.op(), is_signed_int, is_float);4921 const op = toLlvmAtomicRmwBinOp(extra.op(), is_signed_int, is_float);
4912 const ordering = toLlvmAtomicOrdering(extra.ordering());4922 const ordering = toLlvmAtomicOrdering(extra.ordering());
4913 const llvm_abi_ty = try self.getAtomicAbiType(operand_ty, op == .xchg);4923 const llvm_abi_ty = try self.getAtomicAbiType(operand_ty, op == .xchg);
4914 const llvm_operand_ty = try self.lowerType(operand_ty);4924 const llvm_operand_ty = try o.lowerType(operand_ty);
49154925
4916 const access_kind: Builder.MemoryAccessKind =4926 const access_kind: Builder.MemoryAccessKind =
4917 if (ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal;4927 if (ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal;
...@@ -4954,7 +4964,7 @@ fn airAtomicRmw(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Va...@@ -4954,7 +4964,7 @@ fn airAtomicRmw(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Va
4954 access_kind,4964 access_kind,
4955 op,4965 op,
4956 ptr,4966 ptr,
4957 try self.wip.cast(.ptrtoint, operand, try self.lowerType(.usize), ""),4967 try self.wip.cast(.ptrtoint, operand, try o.lowerType(.usize), ""),
4958 self.sync_scope,4968 self.sync_scope,
4959 ordering,4969 ordering,
4960 ptr_alignment,4970 ptr_alignment,
...@@ -4963,7 +4973,8 @@ fn airAtomicRmw(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Va...@@ -4963,7 +4973,8 @@ fn airAtomicRmw(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Va
4963}4973}
49644974
4965fn airAtomicLoad(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {4975fn airAtomicLoad(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {
4966 const zcu = self.object.zcu;4976 const o = self.object;
4977 const zcu = o.zcu;
4967 const atomic_load = self.air.instructions.items(.data)[@intFromEnum(inst)].atomic_load;4978 const atomic_load = self.air.instructions.items(.data)[@intFromEnum(inst)].atomic_load;
4968 const ptr = try self.resolveInst(atomic_load.ptr);4979 const ptr = try self.resolveInst(atomic_load.ptr);
4969 const ptr_ty = self.typeOf(atomic_load.ptr);4980 const ptr_ty = self.typeOf(atomic_load.ptr);
...@@ -4978,7 +4989,7 @@ fn airAtomicLoad(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.V...@@ -4978,7 +4989,7 @@ fn airAtomicLoad(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.V
4978 Type.fromInterned(info.child).abiAlignment(zcu)).toLlvm();4989 Type.fromInterned(info.child).abiAlignment(zcu)).toLlvm();
4979 const access_kind: Builder.MemoryAccessKind =4990 const access_kind: Builder.MemoryAccessKind =
4980 if (info.flags.is_volatile) .@"volatile" else .normal;4991 if (info.flags.is_volatile) .@"volatile" else .normal;
4981 const elem_llvm_ty = try self.lowerType(elem_ty);4992 const elem_llvm_ty = try o.lowerType(elem_ty);
49824993
4983 self.maybeMarkAllowZeroAccess(info);4994 self.maybeMarkAllowZeroAccess(info);
49844995
...@@ -5135,7 +5146,7 @@ fn airMemset(self: *FuncGen, inst: Air.Inst.Index, safety: bool) Allocator.Error...@@ -5135,7 +5146,7 @@ fn airMemset(self: *FuncGen, inst: Air.Inst.Index, safety: bool) Allocator.Error
5135 const body_block = try self.wip.block(1, "InlineMemsetBody");5146 const body_block = try self.wip.block(1, "InlineMemsetBody");
5136 const end_block = try self.wip.block(1, "InlineMemsetEnd");5147 const end_block = try self.wip.block(1, "InlineMemsetEnd");
51375148
5138 const llvm_usize_ty = try self.lowerType(.usize);5149 const llvm_usize_ty = try o.lowerType(.usize);
5139 const end_ptr = switch (ptr_ty.ptrSize(zcu)) {5150 const end_ptr = switch (ptr_ty.ptrSize(zcu)) {
5140 .slice => try self.ptraddScaled(5151 .slice => try self.ptraddScaled(
5141 dest_ptr,5152 dest_ptr,
...@@ -5265,7 +5276,7 @@ fn airGetUnionTag(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder....@@ -5265,7 +5276,7 @@ fn airGetUnionTag(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.
5265 assert(layout.tag_size != 0);5276 assert(layout.tag_size != 0);
5266 const union_ptr = try self.resolveInst(ty_op.operand);5277 const union_ptr = try self.resolveInst(ty_op.operand);
5267 if (isByRef(un_ty, zcu)) {5278 if (isByRef(un_ty, zcu)) {
5268 const llvm_un_ty = try self.lowerType(un_ty);5279 const llvm_un_ty = try o.lowerType(un_ty);
5269 if (layout.payload_size == 0)5280 if (layout.payload_size == 0)
5270 return self.wip.load(.normal, llvm_un_ty, union_ptr, .default, "");5281 return self.wip.load(.normal, llvm_un_ty, union_ptr, .default, "");
5271 const tag_index = @intFromBool(layout.tag_align.compare(.lt, layout.payload_align));5282 const tag_index = @intFromBool(layout.tag_align.compare(.lt, layout.payload_align));
...@@ -5296,6 +5307,7 @@ fn airNeg(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) Allo...@@ -5296,6 +5307,7 @@ fn airNeg(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) Allo
5296}5307}
52975308
5298fn airClzCtz(self: *FuncGen, inst: Air.Inst.Index, intrinsic: Builder.Intrinsic) Allocator.Error!Builder.Value {5309fn airClzCtz(self: *FuncGen, inst: Air.Inst.Index, intrinsic: Builder.Intrinsic) Allocator.Error!Builder.Value {
5310 const o = self.object;
5299 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;5311 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
5300 const inst_ty = self.typeOfIndex(inst);5312 const inst_ty = self.typeOfIndex(inst);
5301 const operand_ty = self.typeOf(ty_op.operand);5313 const operand_ty = self.typeOf(ty_op.operand);
...@@ -5305,14 +5317,15 @@ fn airClzCtz(self: *FuncGen, inst: Air.Inst.Index, intrinsic: Builder.Intrinsic)...@@ -5305,14 +5317,15 @@ fn airClzCtz(self: *FuncGen, inst: Air.Inst.Index, intrinsic: Builder.Intrinsic)
5305 .normal,5317 .normal,
5306 .none,5318 .none,
5307 intrinsic,5319 intrinsic,
5308 &.{try self.lowerType(operand_ty)},5320 &.{try o.lowerType(operand_ty)},
5309 &.{ operand, .false },5321 &.{ operand, .false },
5310 "",5322 "",
5311 );5323 );
5312 return self.wip.conv(.unsigned, result, try self.lowerType(inst_ty), "");5324 return self.wip.conv(.unsigned, result, try o.lowerType(inst_ty), "");
5313}5325}
53145326
5315fn airBitOp(self: *FuncGen, inst: Air.Inst.Index, intrinsic: Builder.Intrinsic) Allocator.Error!Builder.Value {5327fn airBitOp(self: *FuncGen, inst: Air.Inst.Index, intrinsic: Builder.Intrinsic) Allocator.Error!Builder.Value {
5328 const o = self.object;
5316 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;5329 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
5317 const inst_ty = self.typeOfIndex(inst);5330 const inst_ty = self.typeOfIndex(inst);
5318 const operand_ty = self.typeOf(ty_op.operand);5331 const operand_ty = self.typeOf(ty_op.operand);
...@@ -5322,11 +5335,11 @@ fn airBitOp(self: *FuncGen, inst: Air.Inst.Index, intrinsic: Builder.Intrinsic)...@@ -5322,11 +5335,11 @@ fn airBitOp(self: *FuncGen, inst: Air.Inst.Index, intrinsic: Builder.Intrinsic)
5322 .normal,5335 .normal,
5323 .none,5336 .none,
5324 intrinsic,5337 intrinsic,
5325 &.{try self.lowerType(operand_ty)},5338 &.{try o.lowerType(operand_ty)},
5326 &.{operand},5339 &.{operand},
5327 "",5340 "",
5328 );5341 );
5329 return self.wip.conv(.unsigned, result, try self.lowerType(inst_ty), "");5342 return self.wip.conv(.unsigned, result, try o.lowerType(inst_ty), "");
5330}5343}
53315344
5332fn airByteSwap(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {5345fn airByteSwap(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {
...@@ -5339,7 +5352,7 @@ fn airByteSwap(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Val...@@ -5339,7 +5352,7 @@ fn airByteSwap(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Val
53395352
5340 const inst_ty = self.typeOfIndex(inst);5353 const inst_ty = self.typeOfIndex(inst);
5341 var operand = try self.resolveInst(ty_op.operand);5354 var operand = try self.resolveInst(ty_op.operand);
5342 var llvm_operand_ty = try self.lowerType(operand_ty);5355 var llvm_operand_ty = try o.lowerType(operand_ty);
53435356
5344 if (bits % 16 == 8) {5357 if (bits % 16 == 8) {
5345 // If not an even byte-multiple, we need zero-extend + shift-left 1 byte5358 // If not an even byte-multiple, we need zero-extend + shift-left 1 byte
...@@ -5360,7 +5373,7 @@ fn airByteSwap(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Val...@@ -5360,7 +5373,7 @@ fn airByteSwap(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Val
53605373
5361 const result =5374 const result =
5362 try self.wip.callIntrinsic(.normal, .none, .bswap, &.{llvm_operand_ty}, &.{operand}, "");5375 try self.wip.callIntrinsic(.normal, .none, .bswap, &.{llvm_operand_ty}, &.{operand}, "");
5363 return self.wip.conv(.unsigned, result, try self.lowerType(inst_ty), "");5376 return self.wip.conv(.unsigned, result, try o.lowerType(inst_ty), "");
5364}5377}
53655378
5366fn airErrorSetHasValue(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {5379fn airErrorSetHasValue(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {
...@@ -5437,10 +5450,10 @@ fn airErrorName(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Va...@@ -5437,10 +5450,10 @@ fn airErrorName(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Va
5437 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;5450 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
5438 const operand = try self.resolveInst(un_op);5451 const operand = try self.resolveInst(un_op);
5439 const slice_ty = self.typeOfIndex(inst);5452 const slice_ty = self.typeOfIndex(inst);
5440 const slice_llvm_ty = try self.lowerType(slice_ty);5453 const slice_llvm_ty = try o.lowerType(slice_ty);
54415454
5442 // If operand is small (e.g. `u8`), then signedness becomes a problem -- GEP always treats the index as signed.5455 // If operand is small (e.g. `u8`), then signedness becomes a problem -- GEP always treats the index as signed.
5443 const operand_usize = try self.wip.conv(.unsigned, operand, try self.lowerType(.usize), "");5456 const operand_usize = try self.wip.conv(.unsigned, operand, try o.lowerType(.usize), "");
54445457
5445 const error_name_table_ptr = try o.getErrorNameTable();5458 const error_name_table_ptr = try o.getErrorNameTable();
5446 const error_name_ptr = try self.ptraddScaled(error_name_table_ptr.toValue(&o.builder), operand_usize, slice_ty.abiSize(zcu));5459 const error_name_ptr = try self.ptraddScaled(error_name_table_ptr.toValue(&o.builder), operand_usize, slice_ty.abiSize(zcu));
...@@ -5451,7 +5464,7 @@ fn airSplat(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value...@@ -5451,7 +5464,7 @@ fn airSplat(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value
5451 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;5464 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
5452 const scalar = try self.resolveInst(ty_op.operand);5465 const scalar = try self.resolveInst(ty_op.operand);
5453 const vector_ty = self.typeOfIndex(inst);5466 const vector_ty = self.typeOfIndex(inst);
5454 return self.wip.splatVector(try self.lowerType(vector_ty), scalar, "");5467 return self.wip.splatVector(try self.object.lowerType(vector_ty), scalar, "");
5455}5468}
54565469
5457fn airSelect(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {5470fn airSelect(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Value {
...@@ -5474,9 +5487,9 @@ fn airShuffleOne(fg: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Val...@@ -5474,9 +5487,9 @@ fn airShuffleOne(fg: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Val
5474 const operand = try fg.resolveInst(unwrapped.operand);5487 const operand = try fg.resolveInst(unwrapped.operand);
5475 const mask = unwrapped.mask;5488 const mask = unwrapped.mask;
5476 const operand_ty = fg.typeOf(unwrapped.operand);5489 const operand_ty = fg.typeOf(unwrapped.operand);
5477 const llvm_operand_ty = try fg.lowerType(operand_ty);5490 const llvm_operand_ty = try o.lowerType(operand_ty);
5478 const llvm_result_ty = try fg.lowerType(unwrapped.result_ty);5491 const llvm_result_ty = try o.lowerType(unwrapped.result_ty);
5479 const llvm_elem_ty = try fg.lowerType(unwrapped.result_ty.childType(zcu));5492 const llvm_elem_ty = try o.lowerType(unwrapped.result_ty.childType(zcu));
5480 const llvm_poison_elem = try o.builder.poisonConst(llvm_elem_ty);5493 const llvm_poison_elem = try o.builder.poisonConst(llvm_elem_ty);
5481 const llvm_poison_mask_elem = try o.builder.poisonConst(.i32);5494 const llvm_poison_mask_elem = try o.builder.poisonConst(.i32);
5482 const llvm_mask_ty = try o.builder.vectorType(.normal, @intCast(mask.len), .i32);5495 const llvm_mask_ty = try o.builder.vectorType(.normal, @intCast(mask.len), .i32);
...@@ -5578,7 +5591,7 @@ fn airShuffleTwo(fg: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Val...@@ -5578,7 +5591,7 @@ fn airShuffleTwo(fg: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Val
5578 const unwrapped = fg.air.unwrapShuffleTwo(zcu, inst);5591 const unwrapped = fg.air.unwrapShuffleTwo(zcu, inst);
55795592
5580 const mask = unwrapped.mask;5593 const mask = unwrapped.mask;
5581 const llvm_elem_ty = try fg.lowerType(unwrapped.result_ty.childType(zcu));5594 const llvm_elem_ty = try o.lowerType(unwrapped.result_ty.childType(zcu));
5582 const llvm_mask_ty = try o.builder.vectorType(.normal, @intCast(mask.len), .i32);5595 const llvm_mask_ty = try o.builder.vectorType(.normal, @intCast(mask.len), .i32);
5583 const llvm_poison_mask_elem = try o.builder.poisonConst(.i32);5596 const llvm_poison_mask_elem = try o.builder.poisonConst(.i32);
55845597
...@@ -5670,7 +5683,7 @@ fn buildReducedCall(...@@ -5670,7 +5683,7 @@ fn buildReducedCall(
5670 accum_init: Builder.Value,5683 accum_init: Builder.Value,
5671) Allocator.Error!Builder.Value {5684) Allocator.Error!Builder.Value {
5672 const o = self.object;5685 const o = self.object;
5673 const usize_ty = try self.lowerType(.usize);5686 const usize_ty = try o.lowerType(.usize);
5674 const llvm_vector_len = try o.builder.intValue(usize_ty, vector_len);5687 const llvm_vector_len = try o.builder.intValue(usize_ty, vector_len);
5675 const llvm_result_ty = accum_init.typeOfWip(&self.wip);5688 const llvm_result_ty = accum_init.typeOfWip(&self.wip);
56765689
...@@ -5730,9 +5743,9 @@ fn airReduce(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) A...@@ -5730,9 +5743,9 @@ fn airReduce(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) A
5730 const reduce = self.air.instructions.items(.data)[@intFromEnum(inst)].reduce;5743 const reduce = self.air.instructions.items(.data)[@intFromEnum(inst)].reduce;
5731 const operand = try self.resolveInst(reduce.operand);5744 const operand = try self.resolveInst(reduce.operand);
5732 const operand_ty = self.typeOf(reduce.operand);5745 const operand_ty = self.typeOf(reduce.operand);
5733 const llvm_operand_ty = try self.lowerType(operand_ty);5746 const llvm_operand_ty = try o.lowerType(operand_ty);
5734 const scalar_ty = self.typeOfIndex(inst);5747 const scalar_ty = self.typeOfIndex(inst);
5735 const llvm_scalar_ty = try self.lowerType(scalar_ty);5748 const llvm_scalar_ty = try o.lowerType(scalar_ty);
57365749
5737 switch (reduce.operation) {5750 switch (reduce.operation) {
5738 .And, .Or, .Xor => return self.wip.callIntrinsic(.normal, .none, switch (reduce.operation) {5751 .And, .Or, .Xor => return self.wip.callIntrinsic(.normal, .none, switch (reduce.operation) {
...@@ -5839,7 +5852,7 @@ fn airAggregateInit(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builde...@@ -5839,7 +5852,7 @@ fn airAggregateInit(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builde
5839 const result_ty = self.typeOfIndex(inst);5852 const result_ty = self.typeOfIndex(inst);
5840 const len: usize = @intCast(result_ty.arrayLen(zcu));5853 const len: usize = @intCast(result_ty.arrayLen(zcu));
5841 const elements: []const Air.Inst.Ref = @ptrCast(self.air.extra.items[ty_pl.payload..][0..len]);5854 const elements: []const Air.Inst.Ref = @ptrCast(self.air.extra.items[ty_pl.payload..][0..len]);
5842 const llvm_result_ty = try self.lowerType(result_ty);5855 const llvm_result_ty = try o.lowerType(result_ty);
58435856
5844 switch (result_ty.zigTypeTag(zcu)) {5857 switch (result_ty.zigTypeTag(zcu)) {
5845 .vector => {5858 .vector => {
...@@ -5905,7 +5918,7 @@ fn airAggregateInit(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builde...@@ -5905,7 +5918,7 @@ fn airAggregateInit(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builde
5905 field_ptr_align.toLlvm(),5918 field_ptr_align.toLlvm(),
5906 llvm_field_val,5919 llvm_field_val,
5907 field_ty.abiAlignment(zcu).toLlvm(),5920 field_ty.abiAlignment(zcu).toLlvm(),
5908 try o.builder.intValue(try self.lowerType(.usize), field_ty.abiSize(zcu)),5921 try o.builder.intValue(try o.lowerType(.usize), field_ty.abiSize(zcu)),
5909 .normal,5922 .normal,
5910 self.disable_intrinsics,5923 self.disable_intrinsics,
5911 );5924 );
...@@ -5956,7 +5969,7 @@ fn airUnionInit(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Va...@@ -5956,7 +5969,7 @@ fn airUnionInit(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builder.Va
5956 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;5969 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
5957 const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data;5970 const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data;
5958 const union_ty = self.typeOfIndex(inst);5971 const union_ty = self.typeOfIndex(inst);
5959 const union_llvm_ty = try self.lowerType(union_ty);5972 const union_llvm_ty = try o.lowerType(union_ty);
5960 const union_obj = zcu.typeToUnion(union_ty).?;5973 const union_obj = zcu.typeToUnion(union_ty).?;
59615974
5962 assert(union_obj.layout != .@"packed");5975 assert(union_obj.layout != .@"packed");
...@@ -6046,8 +6059,7 @@ fn airAddrSpaceCast(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builde...@@ -6046,8 +6059,7 @@ fn airAddrSpaceCast(self: *FuncGen, inst: Air.Inst.Index) Allocator.Error!Builde
6046 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;6059 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
6047 const inst_ty = self.typeOfIndex(inst);6060 const inst_ty = self.typeOfIndex(inst);
6048 const operand = try self.resolveInst(ty_op.operand);6061 const operand = try self.resolveInst(ty_op.operand);
60496062 return self.wip.cast(.addrspacecast, operand, try self.object.lowerType(inst_ty), "");
6050 return self.wip.cast(.addrspacecast, operand, try self.lowerType(inst_ty), "");
6051}6063}
60526064
6053fn workIntrinsic(6065fn workIntrinsic(
...@@ -6192,7 +6204,7 @@ fn loadTruncate(...@@ -6192,7 +6204,7 @@ fn loadTruncate(
61926204
6193 const o = fg.object;6205 const o = fg.object;
6194 const zcu = o.zcu;6206 const zcu = o.zcu;
6195 const payload_llvm_ty = try fg.lowerType(payload_ty);6207 const payload_llvm_ty = try o.lowerType(payload_ty);
6196 const abi_size = payload_ty.abiSize(zcu);6208 const abi_size = payload_ty.abiSize(zcu);
61976209
6198 const load_llvm_ty = if (payload_ty.isAbiInt(zcu))6210 const load_llvm_ty = if (payload_ty.isAbiInt(zcu))
...@@ -6220,7 +6232,7 @@ fn loadByRef(...@@ -6220,7 +6232,7 @@ fn loadByRef(
6220 access_kind: Builder.MemoryAccessKind,6232 access_kind: Builder.MemoryAccessKind,
6221) Allocator.Error!Builder.Value {6233) Allocator.Error!Builder.Value {
6222 const o = fg.object;6234 const o = fg.object;
6223 const pointee_llvm_ty = try fg.lowerType(pointee_type);6235 const pointee_llvm_ty = try o.lowerType(pointee_type);
6224 const result_align = InternPool.Alignment.fromLlvm(ptr_alignment)6236 const result_align = InternPool.Alignment.fromLlvm(ptr_alignment)
6225 .max(pointee_type.abiAlignment(o.zcu)).toLlvm();6237 .max(pointee_type.abiAlignment(o.zcu)).toLlvm();
6226 const result_ptr = try fg.buildAlloca(pointee_llvm_ty, result_align);6238 const result_ptr = try fg.buildAlloca(pointee_llvm_ty, result_align);
...@@ -6230,7 +6242,7 @@ fn loadByRef(...@@ -6230,7 +6242,7 @@ fn loadByRef(
6230 result_align,6242 result_align,
6231 ptr,6243 ptr,
6232 ptr_alignment,6244 ptr_alignment,
6233 try o.builder.intValue(try fg.lowerType(.usize), size_bytes),6245 try o.builder.intValue(try o.lowerType(.usize), size_bytes),
6234 access_kind,6246 access_kind,
6235 fg.disable_intrinsics,6247 fg.disable_intrinsics,
6236 );6248 );
...@@ -6274,7 +6286,7 @@ fn storeFull(...@@ -6274,7 +6286,7 @@ fn storeFull(
62746286
6275 if (info.flags.vector_index != .none) {6287 if (info.flags.vector_index != .none) {
6276 const index_u32 = try o.builder.intValue(.i32, info.flags.vector_index);6288 const index_u32 = try o.builder.intValue(.i32, info.flags.vector_index);
6277 const vec_elem_ty = try self.lowerType(elem_ty);6289 const vec_elem_ty = try o.lowerType(elem_ty);
6278 const vec_ty = try o.builder.vectorType(.normal, info.packed_offset.host_size, vec_elem_ty);6290 const vec_ty = try o.builder.vectorType(.normal, info.packed_offset.host_size, vec_elem_ty);
62796291
6280 const loaded_vector = try self.wip.load(.normal, vec_ty, ptr, ptr_alignment, "");6292 const loaded_vector = try self.wip.load(.normal, vec_ty, ptr, ptr_alignment, "");
...@@ -6343,7 +6355,7 @@ fn storeFull(...@@ -6343,7 +6355,7 @@ fn storeFull(
6343 ptr_alignment,6355 ptr_alignment,
6344 elem,6356 elem,
6345 elem_ty.abiAlignment(zcu).toLlvm(),6357 elem_ty.abiAlignment(zcu).toLlvm(),
6346 try o.builder.intValue(try self.lowerType(.usize), elem_ty.abiSize(zcu)),6358 try o.builder.intValue(try o.lowerType(.usize), elem_ty.abiSize(zcu)),
6347 access_kind,6359 access_kind,
6348 self.disable_intrinsics,6360 self.disable_intrinsics,
6349 );6361 );
...@@ -6370,7 +6382,7 @@ fn store(...@@ -6370,7 +6382,7 @@ fn store(
6370 elem,6382 elem,
6371 elem_ty.abiAlignment(zcu).toLlvm(),6383 elem_ty.abiAlignment(zcu).toLlvm(),
6372 try o.builder.intValue(6384 try o.builder.intValue(
6373 try fg.lowerType(.usize),6385 try o.lowerType(.usize),
6374 elem_ty.abiSize(zcu),6386 elem_ty.abiSize(zcu),
6375 ),6387 ),
6376 .normal,6388 .normal,
...@@ -6391,7 +6403,7 @@ fn store(...@@ -6391,7 +6403,7 @@ fn store(
6391fn valgrindMarkUndef(fg: *FuncGen, ptr: Builder.Value, len: Builder.Value) Allocator.Error!void {6403fn valgrindMarkUndef(fg: *FuncGen, ptr: Builder.Value, len: Builder.Value) Allocator.Error!void {
6392 const VG_USERREQ__MAKE_MEM_UNDEFINED = 1296236545;6404 const VG_USERREQ__MAKE_MEM_UNDEFINED = 1296236545;
6393 const o = fg.object;6405 const o = fg.object;
6394 const usize_ty = try fg.lowerType(.usize);6406 const usize_ty = try o.lowerType(.usize);
6395 const zero = try o.builder.intValue(usize_ty, 0);6407 const zero = try o.builder.intValue(usize_ty, 0);
6396 const req = try o.builder.intValue(usize_ty, VG_USERREQ__MAKE_MEM_UNDEFINED);6408 const req = try o.builder.intValue(usize_ty, VG_USERREQ__MAKE_MEM_UNDEFINED);
6397 const ptr_as_usize = try fg.wip.cast(.ptrtoint, ptr, usize_ty, "");6409 const ptr_as_usize = try fg.wip.cast(.ptrtoint, ptr, usize_ty, "");
...@@ -6413,7 +6425,7 @@ fn valgrindClientRequest(...@@ -6413,7 +6425,7 @@ fn valgrindClientRequest(
6413 const target = zcu.getTarget();6425 const target = zcu.getTarget();
6414 if (!target_util.hasValgrindSupport(target, .stage2_llvm)) return default_value;6426 if (!target_util.hasValgrindSupport(target, .stage2_llvm)) return default_value;
64156427
6416 const llvm_usize = try fg.lowerType(.usize);6428 const llvm_usize = try o.lowerType(.usize);
6417 const usize_alignment = Type.usize.abiAlignment(zcu).toLlvm();6429 const usize_alignment = Type.usize.abiAlignment(zcu).toLlvm();
64186430
6419 const array_llvm_ty = try o.builder.arrayType(6, llvm_usize);6431 const array_llvm_ty = try o.builder.arrayType(6, llvm_usize);
...@@ -7261,8 +7273,9 @@ fn getAtomicAbiType(fg: *const FuncGen, ty: Type, is_rmw_xchg: bool) Allocator.E...@@ -7261,8 +7273,9 @@ fn getAtomicAbiType(fg: *const FuncGen, ty: Type, is_rmw_xchg: bool) Allocator.E
72617273
7262fn ptraddConst(fg: *FuncGen, ptr: Builder.Value, offset: u64) Allocator.Error!Builder.Value {7274fn ptraddConst(fg: *FuncGen, ptr: Builder.Value, offset: u64) Allocator.Error!Builder.Value {
7263 if (offset == 0) return ptr;7275 if (offset == 0) return ptr;
7264 const llvm_usize_ty = try fg.lowerType(.usize);7276 const o = fg.object;
7265 const offset_val = try fg.object.builder.intValue(llvm_usize_ty, offset);7277 const llvm_usize_ty = try o.lowerType(.usize);
7278 const offset_val = try o.builder.intValue(llvm_usize_ty, offset);
7266 return fg.wip.gep(.inbounds, .i8, ptr, &.{offset_val}, "");7279 return fg.wip.gep(.inbounds, .i8, ptr, &.{offset_val}, "");
7267}7280}
7268fn ptraddScaled(fg: *FuncGen, ptr: Builder.Value, index: Builder.Value, scale: u64) Allocator.Error!Builder.Value {7281fn ptraddScaled(fg: *FuncGen, ptr: Builder.Value, index: Builder.Value, scale: u64) Allocator.Error!Builder.Value {