Can LTO for clang optimize across C and C++ method

2019-02-25 15:39发布

问题:

This question already has an answer here:

  • Can LTO for gcc or clang optimize across C and C++ methods 1 answer

If link-time optimization (LTO) is being used with clang, is it possible that code can be optimized across the C and C++ language boundary?

For example, can a C function be inlined into a C++ caller, or vice-versa?

回答1:

AFAIK, yes since Clang produces LLVM intermediate representation, and LTO happens on that LLVM bytecode.

BTW any kind of link-time-optimization happens on some intermediate representation (of the compiled code), not just on machine code with relocation, as kept in every object file. LTO, whatever representation is used (GIMPLE in GCC, LLVM in Clang) is adding and using such extra information (and that is why the object files become fatter).