authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-10-15 21:28:42+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-10-20 09:21:17+02:00
logef72b91ac2b96ba64a53b08a661e9ad83a828ee4
tree03d0c78049441a867629d0534a98face6703e578
parentd2f04e919c833288d5cf1efa97c25bbaae101168
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

compiler: Remove uses of defaultFunctionAlignment() in the frontend.

minFunctionAlignment() is something we can know ahead of time for any given target because it's a matter of ABI. However, defaultFunctionAlignment() is a matter of optimization and every backend can do it differently depending on any number of factors. For example, LLVM will base the choice on the CPU model in its aarch64 backend. So just don't use this value in the frontend.

3 files changed, 5 insertions(+), 8 deletions(-)

src/Sema.zig+2-6
...@@ -26572,9 +26572,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -26572,9 +26572,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
26572 if (val.isGenericPoison()) {26572 if (val.isGenericPoison()) {
26573 break :blk null;26573 break :blk null;
26574 }26574 }
26575 const alignment = try sema.validateAlignAllowZero(block, align_src, try val.toUnsignedIntSema(pt));26575 break :blk try sema.validateAlignAllowZero(block, align_src, try val.toUnsignedIntSema(pt));
26576 const default = target_util.defaultFunctionAlignment(target);
26577 break :blk if (alignment == default) .none else alignment;
26578 } else if (extra.data.bits.has_align_ref) blk: {26576 } else if (extra.data.bits.has_align_ref) blk: {
26579 const align_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);26577 const align_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
26580 extra_index += 1;26578 extra_index += 1;
...@@ -26592,9 +26590,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -26592,9 +26590,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
26592 error.GenericPoison => break :blk null,26590 error.GenericPoison => break :blk null,
26593 else => |e| return e,26591 else => |e| return e,
26594 };26592 };
26595 const alignment = try sema.validateAlignAllowZero(block, align_src, try align_val.toUnsignedIntSema(pt));26593 break :blk try sema.validateAlignAllowZero(block, align_src, try align_val.toUnsignedIntSema(pt));
26596 const default = target_util.defaultFunctionAlignment(target);
26597 break :blk if (alignment == default) .none else alignment;
26598 } else .none;26594 } else .none;
2659926595
26600 const @"addrspace": ?std.builtin.AddressSpace = if (extra.data.bits.has_addrspace_body) blk: {26596 const @"addrspace": ?std.builtin.AddressSpace = if (extra.data.bits.has_addrspace_body) blk: {
src/Type.zig+1-1
...@@ -1020,7 +1020,7 @@ pub fn abiAlignmentInner(...@@ -1020,7 +1020,7 @@ pub fn abiAlignmentInner(
1020 },1020 },
10211021
1022 // represents machine code; not a pointer1022 // represents machine code; not a pointer
1023 .func_type => return .{ .scalar = target_util.defaultFunctionAlignment(target) },1023 .func_type => return .{ .scalar = target_util.minFunctionAlignment(target) },
10241024
1025 .simple_type => |t| switch (t) {1025 .simple_type => |t| switch (t) {
1026 .bool,1026 .bool,
src/target.zig+2-1
...@@ -459,7 +459,8 @@ pub fn llvmMachineAbi(target: std.Target) ?[:0]const u8 {...@@ -459,7 +459,8 @@ pub fn llvmMachineAbi(target: std.Target) ?[:0]const u8 {
459 }459 }
460}460}
461461
462/// This function returns 1 if function alignment is not observable or settable.462/// This function returns 1 if function alignment is not observable or settable. Note that this
463/// value will not necessarily match the backend's default function alignment (e.g. for LLVM).
463pub fn defaultFunctionAlignment(target: std.Target) Alignment {464pub fn defaultFunctionAlignment(target: std.Target) Alignment {
464 // Overrides of the minimum for performance.465 // Overrides of the minimum for performance.
465 return switch (target.cpu.arch) {466 return switch (target.cpu.arch) {