Unified source code against multiple files + libraries

How many effects does having multiple files or compiled libraries have against throwing everything (> 10,000 LOCs) into one source code for the final binary? For example, instead of linking the Boost library separately, I embed my code along with my source in one giant file for compilation. And on the same line, instead of uploading multiple files to gcc , pasting them all together and providing only one file.

I'm interested in the differences in optimization, not the problems (horrors) that come with saving one source file with gigantic proportions.

Of course, there can only be optimization of the connection time (maybe I'm wrong), but is there a difference between the optimization capabilities?

+4
source share
2 answers

If the compiler can see all the source code, it can be optimized better if your compiler has Interprocedural Optimization (IPO) enabled. IPO differs from other compiler optimizations because it analyzes the entire program ; other optimizations look at only one function or even one block of code

Below is some interprocedural optimization, for more details see here :

  • Embedding
  • Constant distribution
  • mod / ref analysis
  • Nickname Analysis
  • Direct replacement
  • Distributing routine key attributes
  • Partial Deletion of Dead Calls
  • Promotion of character table data
  • Elimination of Dead Function
  • Analysis of the entire program

GCC supports this optimization.

This interprocedural optimization can be used to analyze and optimize the called function.

If the compiler cannot see the source code of the library function, it cannot do such an optimization.

+3
source

Note that some modern compilers (clang / LLVM, icc, and more recently even gcc) now support connection time optimization (LTO) to minimize the effect of separate compilation. Thus, you get the benefits of a separate compilation (maintenance, faster compilation, etc.), as well as all analyzes of the entire program.

By the way, gcc seems to support -fwhole-program and -combine since version 4.1. However, you must transfer all source files.

Finally, since BOOSTs are basically header files (templates) included by #, you cannot get anything from adding them to the source code.

+2
source

All Articles