Compilers

Which describes profile-guided optimization (PGO)?

  1. AA feature that reformats source code to make it more readable
  2. BA feature where the compiler picks optimizations at random and compares the results
  3. CRecompiling with data recorded from runs on representative input
Show answer and explanation

Answer: C. Recompiling with data recorded from runs on representative input

In PGO, a program compiled with instrumentation is first run on representative input, recording which branches are usually taken and which functions are called often. It is then recompiled using this information, laying out hot paths straight-line and inlining frequently called functions to match actual usage. The benefit fades if the training input differs greatly from real usage. It is neither source reformatting nor random selection.

  • A. Reformatting source is the job of other tools.
  • B. It uses execution records, not random choices.
  • C. Correct. It recompiles using recorded execution data.
Practice this topic Back to topic

More Compilers questions

  1. Which optimization does link-time optimization (LTO) make possible?
  2. In C, signed integer overflow is undefined behavior. Under this rule, which code might an optimizing compiler generate for the function above?
  3. Which program error can be detected at compile time?
  4. What is the main benefit of compile-time type checking in a statically typed language?
  5. What is commonly used to express the rules for recognizing tokens in lexical analysis?