Adding IR optimization support

LLVM provides a wide variety of optimization passes. LLVM allows a compiler implementation to decide which optimizations to use, their order, and so on. In this recipe, you will learn how to add IR optimization support.

How to do it…

Do the following steps:

  1. To start with the addition of IR optimization support, first of all a static variable for function manager has to be defined as follows:
    static FunctionPassManager *Global_FP;
  2. Then, a function pass manager needs to be defined for the Module object used previously. This can be done in the main() function as follows:
    FunctionPassManager My_FP(TheModule);
  3. Now a pipeline of various optimizer passes can be added in the main() function as follows:
    My_FP.add(createBasicAliasAnalysisPass()); ...

Get LLVM Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.