Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know what optimizations are enabled by clang and gcc for each mcpu and march option?

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.

like image 887
Rufo El Magufo Avatar asked Jan 12 '14 04:01

Rufo El Magufo


People also ask

Does Clang optimize better than GCC?

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.

What is the difference between Clang and LLVM?

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.

What flag did we provide Clang ++ to stop compilation after the preprocess and compilation steps of the C++ compilation pipeline?

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).

Does Clang use GCC?

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.


1 Answers

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.

like image 134
Ali Avatar answered Oct 03 '22 15:10

Ali