Automatically built-in functions between translation units and gcc 4.6

If I do not declare the function f as inline. Similar:

hijras:

X f(Y y); 

a.cpp:

 X f(Y y) { ... } 

Then in another translation unit:

B.cpp:

 #include "Ah" Z g(W w) { ... ... f(...) ... ... } 

Then I will compile the two translation units Ao and Bo with gcc 4.6, and then link them through gcc as well. (Perhaps with -O3 in both steps)

Will gcc consider a built-in function for performance during a connection? Or is it too late?

In a code review, someone suggested that I should not declare my functions as built-in, since the compiler knows better than I do when I connect. I was always impressed if the function is not defined in the header, than the compiler is not able to embed it.

(If the answer is different for C mode, C ++ or gnu ++ 0x mode, please indicate this as well)

+6
source share
3 answers

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

[edit] When LTO is enabled, GCC will save the "GIMPLE" X f(Y y) A.obj in A.obj . This view is slightly more processed than normal C ++ preprocessing, but not so much. In particular, it has not yet been transferred to the assembly. As a result, the linker can still embed it.

+12
source

I do not think gcc can create make functions in different source files as inline ones. It only works if you declare them in the same source file.

-1
source

The compiler can choose built-in or not to improve performance. But in this case, the compiler is helpless, I think. he cannot in any way build in the function f.

NB: Even if you use a keyword, this is only a suggestion. the final decision on whether to enable or not depends on the compiler. Therefore, there is no problem in suggesting to the compiler.

-1
source

Source: https://habr.com/ru/post/911075/


All Articles