c语言中内联嵌套的限制:对此有一个硬性限制吗?

时间:2013-07-03 02:00:21

标签: c linux gcc inline compiler-optimization

我正在研究C中的项目。当我编译时,我收到此错误:

warning: inlining failed in call to 'xyz()'  --param max-inline-insns-single limit reached

我的编译器将警告报告为错误,我不想绕过它。

那么,这是因为内联函数的嵌套太多了吗?我能做些什么来使其工作(除了不声明内联函数)?

谢谢!

2 个答案:

答案 0 :(得分:2)

正如gcc docs指出:

  

<强> MAX-直列的insn单

     

几个参数控制gcc中使用的树内联器。此数字设置树内联器将考虑用于内联的单个函数中的最大指令数(以GCC的内部表示计算)。这只影响在内联声明的函数和在类声明(C ++)中实现的方法。默认值为500.

如果您仍然希望警告被视为错误(不是无理的愿望),请使用:

--param max-inline-insns-single=1000

(或更高的值)将其从默认值中提升。

答案 1 :(得分:0)

gcc / g ++提供了调整inliner

的选项
-finline-limit=n
By default, GCC limits the size of functions that can be inlined. This flag allows the control of this limit for functions that are explicitly marked as inline (i.e., marked with the inline keyword or defined within the class definition in c++). n is the size of functions that can be inlined in number of pseudo instructions (not counting parameter handling). The default value of n is 600. Increasing this value can result in more inlined code at the cost of compilation time and memory consumption. Decreasing usually makes the compilation faster and less code will be inlined (which presumably means slower programs). This option is particularly useful for programs that use inlining heavily such as those based on recursive templates with C++.
Inlining is actually controlled by a number of parameters, which may be specified individually by using --param name=value. The -finline-limit=n option sets some of these parameters as follows:

max-inline-insns-single
is set to n/2. 
max-inline-insns-auto
is set to n/2. 
min-inline-insns
is set to 130 or n/4, whichever is smaller. 
max-inline-insns-rtl
is set to n.

所以你可以做的就是增加n的价值。虽然手动进行内嵌并不是一个好主意(编译器对此非常擅长)。

了解详情hereman gcc