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.
Do the following steps:
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;
Then, a function pass manager needs to be defined for the
Module
object used previously. This can be done in themain()
function as follows:FunctionPassManager My_FP(TheModule);
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();
Now the static global function Pass Manager is assigned to this pipeline as follows:
Global_FP = &...