跨翻译单元和gcc 4.6自动内联函数 [英] automatically inlined functions across translation units and gcc 4.6

查看:156
本文介绍了跨翻译单元和gcc 4.6自动内联函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我不声明一个函数f内联。正如如下:

If I don't declare a function f as inlined. Just as follows:

A.H:

X f(Y y);

A.cpp:

X f(Y y)
{
    ...
}

然后在不同的翻译单元:

Then in a different translation unit:

B.cpp:

#include "A.h"

Z g(W w)
{
    ...
    ... f(...) ...
    ...
}

然后我编译两个翻译单元A.o和B.O用gcc 4.6,然后还要将它们链接通过GCC。 (也许与-O3到两个步骤)

Then I compile the two translation units A.o and B.o with gcc 4.6, and then link them also through gcc. (Maybe with -O3 to both steps)

请问gcc的考虑在链接时内联函数的性能?或者是太晚了?

Will gcc consider inlining the function for performance at link time? Or is it too late?

在一个code回顾有人建议,由于编译器知道比我做的时候内联,我应该不会宣布我作为内联。我总是即时pression下,除非该功能在头比编译器定义不具有内联它的选项。

In a code review someone suggested that I shouldn't declare my functions as inline as the compiler knows better than I do when to inline. I was always under the impression unless the function is defined in the header than the compiler doesn't have the option to inline it.

(如果答案为不同C模式,C ++模式,或GNU ++ 0x中模式还请指出这一点)

(If the answer differs for C mode, C++ mode, or gnu++0x mode please point this out also)

推荐答案

该功能被称为链接时优化(LTO)而不是默认的GCC 4.6启用

The feature is called Link Time Optimization(LTO) and is not enabled by default in GCC 4.6


启用LTO,GCC将节省一个GIMPLE重$ P $ X F(Y Y)的psentation在 A.OBJ 。这将重新presentation略多于通常的C ++ pre-加工处理,但不是很多。尤其是,它没有被翻译成汇编爱好。其结果是,连接体仍然可以内联它

[edit] With LTO enabled, GCC will save a "GIMPLE" representation of X f(Y y) in A.obj. This representation is slightly more processed than the usual C++ pre-processing, but not a lot. In particular, it's not translated into assembly yet. As a result, the linker can still inline it.

这篇关于跨翻译单元和gcc 4.6自动内联函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆