Files
compiler-explorer/lib
Peter Waller 38b2d9a16e Improve passthrough of -march and -mcpu from compiler to llvm-mca (#6710)
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
2024-07-31 20:16:50 -05:00
..
2024-04-22 20:01:30 +02:00
2023-07-10 21:31:04 -05:00
2023-06-06 21:17:25 -05:00
2022-12-14 20:44:26 -06:00
2024-04-16 21:26:53 +02:00
2024-06-10 21:29:03 -05:00