Posts IPA
Post
Cancel

IPA

过程间分析(Inter-Procedural Analysis)是一个多步骤的过程,是LTO分析过程中的重要部分,也是一个跨模块的分析过程。过程间分析包含local分析和global分析。局部分析会为每一个过程和调用点生成Local Summary;全局分析时会根据具体要解决的数据流问题在Local Summary中去查找。

IPA 选项

-fipa-pure-const

Discover which functions are pure or constant. Enabled by default at ‘-O1’ and higher.

检测空函数或者常量函数。

-fipa-cp

Perform interprocedural constant propagation. This optimization analyzes the program to determine when values passed to functions are constants and then optimizes accordingly. This optimization can substantially increase performance if the application has constants passed to functions. This flag is enabled by default at ‘-O2’, ‘-Os’ and ‘-O3’. It is also enabled by ‘-fprofile-use’ and ‘-fauto-profile’.

函数间常量传播。

-fipa-bit-cp

When enabled, perform interprocedural bitwise constant propagation. This flag is enabled by default at ‘-O2’ and by ‘-fprofile-use’ and ‘-fauto-profile’. It requires that ‘-fipa-cp’ is enabled.

-fipa-cp

Perform interprocedural constant propagation. This optimization analyzes the program to determine when values passed to functions are constants and then optimizes accordingly. This optimization can substantially increase performance if the application has constants passed to functions. This flag is enabled by default at ‘-O2’, ‘-Os’ and ‘-O3’. It is also enabled by ‘-fprofile-use’ and ‘-fauto-profile’.

-fipa-cp-clone

Perform function cloning to make interprocedural constant propagation stronger. When enabled, interprocedural constant propagation performs function cloning when externally visible function can be called with constant arguments. Because this optimization can create multiple copies of functions, it may significantly increase code size (see ‘–param ipa-cp-unit-growth=value’). This flag is enabled by default at ‘-O3’. It is also enabled by ‘-fprofile-use’ and ‘-fauto-profile’.

-fipa-vrp

When enabled, perform interprocedural propagation of value ranges. This flag is enabled by default at ‘-O2’. It requires that ‘-fipa-cp’ is enabled.

增强VRP分析

-fipa-sra

Perform interprocedural scalar replacement of aggregates, removal of unused parameters and replacement of parameters passed by reference by parameters passed by value. Enabled at levels ‘-O2’, ‘-O3’ and ‘-Os’.

函数间传参优化

-fipa-ra

Use caller save registers for allocation if those registers are not used by any called function. In that case it is not necessary to save and restore them around calls. This is only possible if called functions are part of same compilation unit as current function and they are compiled before it. Enabled at levels ‘-O2’, ‘-O3’, ‘-Os’, however the option is disabled if generated code will be instrumented for profiling (‘-p’, or ‘-pg’) or if callee’s register usage cannot be known exactly (this happens on targets that do not expose prologues and epilogues in RTL).

减少caller-save

-fipa-icf, -fipa-icf-functions, -fipa-icf-variables

Perform Identical Code Folding for functions and read-only variables. The optimization reduces code size and may disturb unwind stacks by replacing a function by equivalent one with a different name. The optimization works more effectively with link-time optimization enabled. Although the behavior is similar to the Gold Linker’s ICF optimization, GCC ICF works on different levels and thus the optimizations are not same - there are equivalences that are found only by GCC and equivalences found only by Gold. This flag is enabled by default at ‘-O2’ and ‘-Os’.

-fipa-reference

Discover which static variables do not escape the compilation unit. Enabled by default at ‘-O1’ and higher.

-fipa-profile

Perform interprocedural profile propagation. The functions called only from cold functions are marked as cold. Also functions executed once (such as cold, noreturn, static constructors or destructors) are identified. Cold functions and loop less parts of functions executed once are then optimized for size. Enabled by default at ‘-O1’ and higher.

__attribute__((section("section_name"))),可以将其修饰的函数或数据放入自定义的段section_name中。gcc下会在section_name前分别加__start___stop_表示该段的起始和结束地址。

参考文献

Using the GNU Compiler Collection

编译优化之 - 过程间优化(IPA/IPO)入门

This post is licensed under CC BY 4.0 by the author.