mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2026-12-01 23:59:22 -06:00
This patch fixes a few issues with argument passthrough that have been discovered since #6682 was landed. * X86 didn't work if -march=CPU was supplied. * It wasn't possible to override flags on MCA, because the auto-detected flags came before user flags. * Since compiler-explorer runs on x86 native hardware, if targetting aarch64, it would result in an error about the default requested native CPU not being available for the architecture. X86 clang uses -march to specify the CPU, and it's invalid to supply -march=<cpu> to LLVM-MCA. Meanwhile, LLVM-MCA requires an -mcpu argument. Therefore, to handle x86 it's necessary to rewrite -march to -mcpu so long as the march flag is used to supply a CPU value (i.e. not an architecture level beginning with `x86-64`). Per https://maskray.me/blog/2022-08-28-march-mcpu-mtune, I understand x86 is currently the only target to have this behaviour so it needs special casing. Additionally, llvm-mca assumes -mcpu=native if it is not otherwise specified. Since compiler-explorer runs on x86 hardware, it is easy to end up in a situation for example targetting aarch64 but with -mcpu=<an x86 CPU>. To handle this case some logic is added to detect if a CPU is not specified and the target is not x86, in which case -mcpu=generic is supplied instead as a reasonable default for the target. Further, handle the case where --target is being passed to the compiler, and pass this through as -mtriple. Testing: * I have been testing on an aarch64-native machine. * I have tested targeting x86 by specifying --target and using the override functionality in compiler explorrer to specify x86. * I have been inspecting the `--debug` output to see what flags are passed to LLVM-MCA. * I've checked that I can override the -mcpu in MCA regardless of what is passed to the compiler. * I have checked that I can supply either -march=x86-64* or -march=<cpu> on the x86 target and things behave as expected. Fixes: #6709