Collecting statistics
As mentioned in the previous section, a compiler is a complex piece of software. Collecting statistical numbers—for example, the number of basic blocks processed by a specific optimization—is one of the easiest and most efficient ways to get a quick portrait on the runtime behaviors of a compiler.
There are several ways to collect statistics in LLVM. In this section, we are going to learn three of the most common and useful options for doing this, and these methods are outlined here:
- Using the
Statistic
class - Using an optimization remark
- Adding time measurements
The first option is a general utility that collects statistics via simple counters; the second option is specifically designed to profile compiler optimizations; and the last option is used for collecting timing information in the compiler.
Let's start with the first one.
Using the Statistic class
In this section, we are going to demonstrate new features...