Compilers

Which optimization does link-time optimization (LTO) make possible?

  1. AInlining and similar optimizations across separate source files
  2. BUnrolling loops, but only within a single function
  3. CLinking becomes unnecessary, and object files can be run directly as they are
Show answer and explanation

Answer: A. Inlining and similar optimizations across separate source files

Normal compilation translates each source file to machine code separately, so the contents of functions in other files are invisible and cross-file inlining or constant propagation is impossible. With LTO, each file is kept as an intermediate representation and the whole program is optimized together at link time. This enables cross-file inlining and removing functions that are never called. Unrolling loops within a function is possible with normal compilation.

  • A. Correct. Optimization across files becomes possible.
  • B. Unrolling loops within a function works in normal compilation too.
  • C. Linking is still required.
Practice this topic Back to topic

More Compilers questions

  1. In C, signed integer overflow is undefined behavior. Under this rule, which code might an optimizing compiler generate for the function above?
  2. Which program error can be detected at compile time?
  3. What is the main benefit of compile-time type checking in a statically typed language?
  4. What is commonly used to express the rules for recognizing tokens in lexical analysis?
  5. Which kind of grammar is used to describe most programming languages and underlies parsing?