1

I am trying to find a command line option to specify "generate code for this host your are compiling on, it should take advantage of all the CPU features available, and needs not run on any other system" for llvm.

I have fairly recent llvm versions across all the platforms I use, they are all arm, arm64, x86 or x86-64. All code is either C or C++.

Is there a generic option for this for llvm?

jlainema
  • 31
  • 4
  • See `llc`'s `-mcpu` option https://llvm.org/docs/CommandGuide/llc.html#cmdoption-llc-march – droptop Dec 09 '20 at 09:19
  • Yes, I've read that and tried to find an option that would set it at "target current host cpu" - the question is, what the value should be for that? I want to target the host, not a named cpu. The documentation says "or autodetected to the current architecture." but it certainly is not on any of my architectures/platforms. – jlainema Dec 09 '20 at 12:03
  • 1
    Does `-march=native` do the trick? – ingomueller.net Nov 11 '22 at 11:05
  • Works on x86/x64 for me, but not on arm/arm64 on llvm 10, perhaps I need to upgrade the version. – jlainema Nov 12 '22 at 12:22

1 Answers1

1

The correct command line parameters are: -mtune=native and -mcpu=native

quepas
  • 956
  • 1
  • 13
  • 30
jlainema
  • 31
  • 4
  • Does that work on x86-64, or only on ARM/ARM64? For GCC, you'd need to use `-march=native` on x86-64. (That implies `-mtune=native`.) – Peter Cordes Nov 12 '22 at 12:42
  • It did compile without warnings on x85-64, but I did not actually look if the codegen actually used features beyond what the baseline was. – jlainema Nov 13 '22 at 13:36
  • When I tried it with x86-64 clang15, I got `warning: argument unused during compilation: '-mcpu=native'`. (Clang expects that people will pass it GCC args, so by default it warns instead of erroring out on stuff it doesn't understand. Same with some `__attribute__(())` declarations. – Peter Cordes Nov 13 '22 at 13:56