Chapter 4. Preparing Optimizations

In this chapter, we will cover the following recipes:

  • Various levels of optimization
  • Writing your own LLVM pass
  • Running your own pass with the opt tool
  • Using another pass in a new pass
  • Registering a pass with pass manager
  • Writing an analysis pass
  • Writing an alias analysis pass
  • Using other analysis passes

Introduction

Once the source code transformation completes, the output is in the LLVM IR form. This IR serves as a common platform for converting into assembly code, depending on the backend. However, before converting into an assembly code, the IR can be optimized to produce more effective code. The IR is in the SSA form, where every new assignment to a variable is a new variable itself—a classic case of an SSA representation.

In the LLVM infrastructure, a pass serves the purpose of optimizing LLVM IR. A pass runs over the LLVM IR, processes the IR, analyzes it, identifies the optimization opportunities, and modifies the IR to produce optimized code. The command-line interface opt is used to run optimization passes on LLVM IR.

In the upcoming chapters, various optimization techniques will be discussed. Also, how to write and register a new optimization pass will be explored.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.9.169