From ef72b91ac2b96ba64a53b08a661e9ad83a828ee4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Tue, 15 Oct 2024 21:28:42 +0200 Subject: [PATCH] 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. --- src/Sema.zig | 8 ++------ src/Type.zig | 2 +- src/target.zig | 3 ++- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Sema.zig b/src/Sema.zig index 1250a06a9c..a2a13184e4 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -26572,9 +26572,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A if (val.isGenericPoison()) { break :blk null; } - const alignment = try sema.validateAlignAllowZero(block, align_src, try val.toUnsignedIntSema(pt)); - const default = target_util.defaultFunctionAlignment(target); - break :blk if (alignment == default) .none else alignment; + break :blk try sema.validateAlignAllowZero(block, align_src, try val.toUnsignedIntSema(pt)); } else if (extra.data.bits.has_align_ref) blk: { const align_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); extra_index += 1; @@ -26592,9 +26590,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A error.GenericPoison => break :blk null, else => |e| return e, }; - const alignment = try sema.validateAlignAllowZero(block, align_src, try align_val.toUnsignedIntSema(pt)); - const default = target_util.defaultFunctionAlignment(target); - break :blk if (alignment == default) .none else alignment; + break :blk try sema.validateAlignAllowZero(block, align_src, try align_val.toUnsignedIntSema(pt)); } else .none; const @"addrspace": ?std.builtin.AddressSpace = if (extra.data.bits.has_addrspace_body) blk: { diff --git a/src/Type.zig b/src/Type.zig index c6feb9ddd4..582e997ac7 100644 --- a/src/Type.zig +++ b/src/Type.zig @@ -1020,7 +1020,7 @@ pub fn abiAlignmentInner( }, // represents machine code; not a pointer - .func_type => return .{ .scalar = target_util.defaultFunctionAlignment(target) }, + .func_type => return .{ .scalar = target_util.minFunctionAlignment(target) }, .simple_type => |t| switch (t) { .bool, diff --git a/src/target.zig b/src/target.zig index cce1787f33..87674cda89 100644 --- a/src/target.zig +++ b/src/target.zig @@ -459,7 +459,8 @@ pub fn llvmMachineAbi(target: std.Target) ?[:0]const u8 { } } -/// This function returns 1 if function alignment is not observable or settable. +/// This function returns 1 if function alignment is not observable or settable. Note that this +/// value will not necessarily match the backend's default function alignment (e.g. for LLVM). pub fn defaultFunctionAlignment(target: std.Target) Alignment { // Overrides of the minimum for performance. return switch (target.cpu.arch) {