Book Image

LLVM Cookbook

Book Image

LLVM Cookbook

Overview of this book

Table of Contents (16 chapters)
LLVM Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

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());
    My_FP.add(createInstructionCombiningPass());
    My_FP.add(createReassociatePass());
    My_FP.add(createGVNPass());
    My_FP.doInitialization();
  4. Now the static global function Pass Manager is assigned to this pipeline as follows:

    Global_FP = &amp...