Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what optimization passes are done for -O4 in clang?

We are trying to implement a jit compiler whose performance is supposed to be same as doing it with clang -o4. Is there a place where I could easily get the list of optimization passes invoked by clang with -o4 is specified?

like image 603
Amit Prakash Avatar asked Dec 17 '12 23:12

Amit Prakash


People also ask

What are passes in LLVM?

All LLVM passes are subclasses of the Pass class, which implement functionality by overriding virtual methods inherited from Pass .

What is LLVM optimization?

DESCRIPTION. The opt command is the modular LLVM optimizer and analyzer. It takes LLVM source files as input, runs the specified optimizations or analyses on it, and then outputs the optimized file.

What is mem2reg?

-mem2reg : Promote Memory to Register This file promotes memory references to be register references. It promotes alloca instructions which only have loads and stores as uses.

What is option in clang?

clang supports the -std option, which changes what language mode clang uses. The supported modes for C are c89, gnu89, c94, c99, gnu99 and various aliases for those modes. If no -std option is specified, clang defaults to gnu99 mode.


2 Answers

As far as I know -O4 means same thing as -O3 + enabled LTO (Link Time Optimization). See the folloing code fragments:

  • Tools.cpp // Manually translate -O to -O2 and -O4 to -O3;
  • Driver.cpp // Check for -O4.

Also see here:

You can produce bitcode files from clang using -emit-llvm or -flto, or the -O4 flag which is synonymous with -O3 -flto.

For optimizations used with -O3 flag see this PassManagerBuilder.cpp file (look for OptLevel variable - it will have value 3).

like image 133
Mārtiņš Možeiko Avatar answered Nov 03 '22 21:11

Mārtiņš Možeiko


Note that as of LLVM version 5.1 -O4 no longer implies link time optimization. If you want that you need to pass -flto. See Xcode 5 Release Notes.

like image 26
moobag Avatar answered Nov 03 '22 21:11

moobag