Adding an optimization pipeline to your compiler
Our tinylang
compiler, which was developed in the previous chapters, performs no optimizations on the created IR code. In the following sections, we will add an optimization pipeline to the compiler to perform this exactly.
Creating an optimization pipeline with the new Pass manager
Central to the setup of the optimization pipeline is the PassBuilder
class. This class knows about all of the registered Passes and can construct a Pass pipeline from a textual description. We use this class to either create the Pass pipeline from a description given on the command line or use a default pipeline based on the requested optimization level. We also support the use of Pass plugins, such as the countir
Pass plugin, which we discussed in the previous section. With this, we mimic part of the functionality of the opt
tool and also use similar names for the command-line options.
The PassBuilder
class populates an instance of a ModulePassManager...