diff options
| author | Alex Rønne Petersen <alex@alexrp.com> | 2024-10-25 11:10:28 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-25 11:10:28 +0200 |
| commit | 03d0e296cb8a8afb2bd81c030b31e96e6e2940c7 (patch) | |
| tree | f340a6c090dd562ec0d710573d66e1651ced5bd5 /src/target.zig | |
| parent | 5769592cdda3c14a37b8c381219343052609cbbc (diff) | |
| parent | 6c1e306484530bfeaf26450fb83a70ff1c323bcd (diff) | |
| download | zig-03d0e296cb8a8afb2bd81c030b31e96e6e2940c7.tar.gz zig-03d0e296cb8a8afb2bd81c030b31e96e6e2940c7.zip | |
Merge pull request #21710 from alexrp/function-alignment
Some improvements to the compiler's handling of function alignment
Diffstat (limited to 'src/target.zig')
| -rw-r--r-- | src/target.zig | 73 |
1 files changed, 63 insertions, 10 deletions
diff --git a/src/target.zig b/src/target.zig index ec34a23f0d..1f8a567f03 100644 --- a/src/target.zig +++ b/src/target.zig @@ -436,35 +436,88 @@ 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) { - .arm, .armeb => .@"4", - .aarch64, .aarch64_be => .@"4", - .sparc, .sparc64 => .@"4", - .riscv64 => .@"2", - else => .@"1", + .csky, + .thumb, + .thumbeb, + .xcore, + => .@"4", + .aarch64, + .aarch64_be, + .hexagon, + .powerpc, + .powerpcle, + .powerpc64, + .powerpc64le, + .s390x, + .x86, + .x86_64, + => .@"16", + .loongarch32, + .loongarch64, + => .@"32", + else => minFunctionAlignment(target), }; } +/// This function returns 1 if function alignment is not observable or settable. pub fn minFunctionAlignment(target: std.Target) Alignment { return switch (target.cpu.arch) { + .riscv32, + .riscv64, + => if (std.Target.riscv.featureSetHasAny(target.cpu.features, .{ .c, .zca })) .@"2" else .@"4", + .thumb, + .thumbeb, + .csky, + .m68k, + .msp430, + .s390x, + .xcore, + => .@"2", + .arc, .arm, .armeb, .aarch64, .aarch64_be, - .riscv32, - .riscv64, + .hexagon, + .lanai, + .loongarch32, + .loongarch64, + .mips, + .mipsel, + .powerpc, + .powerpcle, + .powerpc64, + .powerpc64le, .sparc, .sparc64, - => .@"2", + .xtensa, + => .@"4", + .bpfel, + .bpfeb, + .mips64, + .mips64el, + => .@"8", + .ve, + => .@"16", else => .@"1", }; } pub fn supportsFunctionAlignment(target: std.Target) bool { return switch (target.cpu.arch) { - .wasm32, .wasm64 => false, + .nvptx, + .nvptx64, + .spirv, + .spirv32, + .spirv64, + .wasm32, + .wasm64, + => false, else => true, }; } |
