authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-03-14 22:13:52-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-03-15 01:04:21-04:00
logd14a9e82feca6467176d188d2eccf6ff51606952
tree4212b10b6907a21f04255dc38f61f40fabb0f4de
parentbb6b9c19e06320d8617f8858dde1ae6a7cf7fc5e

x86_64: use new for loop syntax


1 files changed, 14 insertions(+), 22 deletions(-)

src/arch/x86_64/CodeGen.zig+14-22
......@@ -184,8 +184,7 @@ const Branch = struct {
184184 _ = options;
185185 comptime assert(unused_format_string.len == 0);
186186 try writer.writeAll("Branch {\n");
187 for (ctx.insts, 0..) |inst, i| {
188 const mcv = ctx.mcvs[i];
187 for (ctx.insts, ctx.mcvs) |inst, mcv| {
189188 try writer.print(" %{d} => {}\n", .{ inst, mcv });
190189 }
191190 try writer.writeAll("}");
......@@ -3982,10 +3981,10 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
39823981 };
39833982 defer if (ret_reg_lock) |lock| self.register_manager.unlockReg(lock);
39843983
3985 for (args, 0..) |arg, arg_i| {
3986 const mc_arg = info.args[arg_i];
3984 for (args, info.args) |arg, info_arg| {
3985 const mc_arg = info_arg;
39873986 const arg_ty = self.air.typeOf(arg);
3988 const arg_mcv = try self.resolveInst(args[arg_i]);
3987 const arg_mcv = try self.resolveInst(arg);
39893988 // Here we do not use setRegOrMem even though the logic is similar, because
39903989 // the function call will move the stack pointer, so the offsets are different.
39913990 switch (mc_arg) {
......@@ -4851,9 +4850,9 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {
48514850 var relocs = try self.gpa.alloc(u32, items.len);
48524851 defer self.gpa.free(relocs);
48534852
4854 for (items, 0..) |item, item_i| {
4853 for (items, relocs) |item, *reloc| {
48554854 const item_mcv = try self.resolveInst(item);
4856 relocs[item_i] = try self.genCondSwitchMir(condition_ty, condition, item_mcv);
4855 reloc.* = try self.genCondSwitchMir(condition_ty, condition, item_mcv);
48574856 }
48584857
48594858 // Capture the state of register and stack allocation state so that we can revert to it.
......@@ -4935,11 +4934,7 @@ fn canonicaliseBranches(self: *Self, parent_branch: *Branch, canon_branch: *Bran
49354934 try parent_branch.inst_table.ensureUnusedCapacity(self.gpa, target_branch.inst_table.count());
49364935
49374936 const target_slice = target_branch.inst_table.entries.slice();
4938 const target_keys = target_slice.items(.key);
4939 const target_values = target_slice.items(.value);
4940
4941 for (target_keys, 0..) |target_key, target_idx| {
4942 const target_value = target_values[target_idx];
4937 for (target_slice.items(.key), target_slice.items(.value)) |target_key, target_value| {
49434938 const canon_mcv = if (canon_branch.inst_table.fetchSwapRemove(target_key)) |canon_entry| blk: {
49444939 // The instruction's MCValue is overridden in both branches.
49454940 parent_branch.inst_table.putAssumeCapacity(target_key, canon_entry.value);
......@@ -4969,10 +4964,7 @@ fn canonicaliseBranches(self: *Self, parent_branch: *Branch, canon_branch: *Bran
49694964 }
49704965 try parent_branch.inst_table.ensureUnusedCapacity(self.gpa, canon_branch.inst_table.count());
49714966 const canon_slice = canon_branch.inst_table.entries.slice();
4972 const canon_keys = canon_slice.items(.key);
4973 const canon_values = canon_slice.items(.value);
4974 for (canon_keys, 0..) |canon_key, canon_idx| {
4975 const canon_value = canon_values[canon_idx];
4967 for (canon_slice.items(.key), canon_slice.items(.value)) |canon_key, canon_value| {
49764968 // We already deleted the items from this table that matched the target_branch.
49774969 // So these are all instructions that are only overridden in the canon branch.
49784970 parent_branch.inst_table.putAssumeCapacity(canon_key, canon_value);
......@@ -6446,7 +6438,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
64466438 else => 0,
64476439 };
64486440
6449 for (param_types, 0..) |ty, i| {
6441 for (param_types, result.args, 0..) |ty, *arg, i| {
64506442 assert(ty.hasRuntimeBits());
64516443
64526444 const classes: []const abi.Class = switch (self.target.os.tag) {
......@@ -6459,7 +6451,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
64596451 switch (classes[0]) {
64606452 .integer => blk: {
64616453 if (i >= abi.getCAbiIntParamRegs(self.target.*).len) break :blk; // fallthrough
6462 result.args[i] = .{ .register = abi.getCAbiIntParamRegs(self.target.*)[i] };
6454 arg.* = .{ .register = abi.getCAbiIntParamRegs(self.target.*)[i] };
64636455 continue;
64646456 },
64656457 .memory => {}, // fallthrough
......@@ -6471,7 +6463,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
64716463 const param_size = @intCast(u32, ty.abiSize(self.target.*));
64726464 const param_align = @intCast(u32, ty.abiAlignment(self.target.*));
64736465 const offset = mem.alignForwardGeneric(u32, next_stack_offset + param_size, param_align);
6474 result.args[i] = .{ .stack_offset = @intCast(i32, offset) };
6466 arg.* = .{ .stack_offset = @intCast(i32, offset) };
64756467 next_stack_offset = offset;
64766468 }
64776469
......@@ -6522,15 +6514,15 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
65226514 else => 0,
65236515 };
65246516
6525 for (param_types, 0..) |ty, i| {
6517 for (param_types, result.args) |ty, *arg| {
65266518 if (!ty.hasRuntimeBits()) {
6527 result.args[i] = .{ .none = {} };
6519 arg.* = .{ .none = {} };
65286520 continue;
65296521 }
65306522 const param_size = @intCast(u32, ty.abiSize(self.target.*));
65316523 const param_align = @intCast(u32, ty.abiAlignment(self.target.*));
65326524 const offset = mem.alignForwardGeneric(u32, next_stack_offset + param_size, param_align);
6533 result.args[i] = .{ .stack_offset = @intCast(i32, offset) };
6525 arg.* = .{ .stack_offset = @intCast(i32, offset) };
65346526 next_stack_offset = offset;
65356527 }
65366528