Clang and GCC have two switches, -mcpu
and -march
, to enable some optimizations especific for the CPU selected. i.e. -march=i686
enables internally -mmmx
, -msse
and so forth.
I would like know if there is some command to show what switches are enabled by march
and mcpu
for each CPU. I prefer just a command but I also accept answers with the location of the code with the info.
GCC consistently outperformance Clang on all optimization levels. 32 Bit Performance is on a bit lower side with respect to corresponding 64-bit compilers & optimization levels. This can be attributed to being able to utilize the RAM properly. The contrast between O0 & Other optimization levels is very visible.
LLVM is a backend compiler meant to build compilers on top of it. It deals with optimizations and production of code adapted to the target architecture. CLang is a front end which parses C, C++ and Objective C code and translates it into a representation suitable for LLVM.
The -S flag instructs Clang to stop after this step. Assembler: This converts target-specific assembly code into target-specific machine code object files. The -c flag instructs Clang to stop after this step. Linker: This combines multiple object files into a single image (either a shared object or an executable).
Clang is compatible with GCC. Its command-line interface shares many of GCC's flags and options. Clang implements many GNU language extensions and compiler intrinsics, some of which are purely for compatibility.
For gcc, try
gcc -mcpu=native -Q --help=target
The first line it prints:
gcc: warning: ‘-mcpu=’ is deprecated; use ‘-mtune=’ or ‘-march=’ instead
followed by
The following options are target specific:
-m128bit-long-double [disabled]
-m32 [disabled]
-m3dnow [disabled]
-m3dnowa [disabled]
-m64 [enabled]
-m80387 [enabled]
-m8bit-idiv [disabled]
[...]
That answers the part for gcc.
Unfortunately, I am not familiar with clang. The best I could figure out so far is:
clang --target=i386 -### myfile.c
.
where the -###
makes the options to be shown. Different things are shown for arm. I am not sure if it is sufficient for you.
The file that sets the options seems to be Targets.cpp, although it is not much help as it a 5.8k line long file.
After looking at the llvm code generation, I have the impression that clang/LLVM doesn't have so many target specific options as gcc. See for example the target-specific feature matrix or the exposed (documented) options of llc.
And one more thing: clang exposes far less options of the compiler optimizations on purpose. For example there is no -finline-limit
analogue exposed in clang.
Maybe -###
prints everything exposed after all.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With