Technical requirements – Optimizing IR
LLVM uses a series of passes to optimize the IR. A pass operates on a unit of IR, such as a function or a module. The operation can be a transformation, which changes the IR in a defined way, or an analysis, which collects information such as dependencies. This series of passes is called the pass pipeline. The pass manager executes the pass pipeline on the IR, which our compiler produces. Therefore, you need to know what the pass manager does and how to construct a pass pipeline. The semantics of a programming language may require the development of new passes, and we must add these passes to the pipeline.
In this chapter, you will learn about the following:
- How to leverage the LLVM pass manager to implement passes within LLVM
- How to implement an instrumentation pass, as an example, within the LLVM project, as well as a separate plugin
- In using the ppprofiler pass with LLVM tools, you will learn how to use a pass plugin with opt and clang
- In adding an optimization pipeline to your compiler, you will extend the tinylang compiler with an optimization pipeline based on the new pass manager
By the end of this chapter, you will know how to develop a new pass and how you can add it to a pass pipeline. You will also be able to set up the pass pipeline in your compiler.
Technical requirements
The source code for this chapter is available at https://github.com/PacktPublishing/Learn-LLVM-17/tree/main/Chapter07.