PassManagerBuilder.h revision 263509
144348Simp// llvm/Transforms/IPO/PassManagerBuilder.h - Build Standard Pass -*- C++ -*-=// 260484Sobrien// 344348Simp// The LLVM Compiler Infrastructure 444348Simp// 544348Simp// This file is distributed under the University of Illinois Open Source 644348Simp// License. See LICENSE.TXT for details. 744348Simp// 844348Simp//===----------------------------------------------------------------------===// 944348Simp// 1044348Simp// This file defines the PassManagerBuilder class, which is used to set up a 1144348Simp// "standard" optimization sequence suitable for languages like C and C++. 1244348Simp// 1344348Simp//===----------------------------------------------------------------------===// 1444348Simp 1544348Simp#ifndef LLVM_TRANSFORMS_IPO_PASSMANAGERBUILDER_H 1644348Simp#define LLVM_TRANSFORMS_IPO_PASSMANAGERBUILDER_H 1744348Simp 1844348Simp#include <vector> 1944348Simp 2044348Simpnamespace llvm { 2144348Simpclass TargetLibraryInfo; 2244348Simpclass Pass; 2344348Simp 2444348Simp// The old pass manager infrastructure is hidden in a legacy namespace now. 2544348Simpnamespace legacy { 2644348Simpclass PassManagerBase; 2744348Simpclass FunctionPassManager; 2844348Simp} 2944348Simpusing legacy::PassManagerBase; 3060484Sobrienusing legacy::FunctionPassManager; 3160484Sobrien 3260484Sobrien/// PassManagerBuilder - This class is used to set up a standard optimization 3360484Sobrien/// sequence for languages like C and C++, allowing some APIs to customize the 3460484Sobrien/// pass sequence in various ways. A simple example of using it would be: 3560484Sobrien/// 3660484Sobrien/// PassManagerBuilder Builder; 3760484Sobrien/// Builder.OptLevel = 2; 3860484Sobrien/// Builder.populateFunctionPassManager(FPM); 3960484Sobrien/// Builder.populateModulePassManager(MPM); 4060484Sobrien/// 4160484Sobrien/// In addition to setting up the basic passes, PassManagerBuilder allows 4260484Sobrien/// frontends to vend a plugin API, where plugins are allowed to add extensions 4360484Sobrien/// to the default pass manager. They do this by specifying where in the pass 4460484Sobrien/// pipeline they want to be added, along with a callback function that adds 4560484Sobrien/// the pass(es). For example, a plugin that wanted to add a loop optimization 4660484Sobrien/// could do something like this: 4760484Sobrien/// 4860484Sobrien/// static void addMyLoopPass(const PMBuilder &Builder, PassManagerBase &PM) { 4960484Sobrien/// if (Builder.getOptLevel() > 2 && Builder.getOptSizeLevel() == 0) 5060484Sobrien/// PM.add(createMyAwesomePass()); 5160484Sobrien/// } 5260484Sobrien/// ... 5360484Sobrien/// Builder.addExtension(PassManagerBuilder::EP_LoopOptimizerEnd, 5460484Sobrien/// addMyLoopPass); 5560484Sobrien/// ... 5660484Sobrienclass PassManagerBuilder { 5760484Sobrienpublic: 5860484Sobrien 5960484Sobrien /// Extensions are passed the builder itself (so they can see how it is 6060484Sobrien /// configured) as well as the pass manager to add stuff to. 6160484Sobrien typedef void (*ExtensionFn)(const PassManagerBuilder &Builder, 6260484Sobrien PassManagerBase &PM); 6360484Sobrien enum ExtensionPointTy { 6460484Sobrien /// EP_EarlyAsPossible - This extension point allows adding passes before 6560484Sobrien /// any other transformations, allowing them to see the code as it is coming 6660484Sobrien /// out of the frontend. 6760484Sobrien EP_EarlyAsPossible, 6860484Sobrien 6960484Sobrien /// EP_ModuleOptimizerEarly - This extension point allows adding passes 7060484Sobrien /// just before the main module-level optimization passes. 7160484Sobrien EP_ModuleOptimizerEarly, 7260484Sobrien 7360484Sobrien /// EP_LoopOptimizerEnd - This extension point allows adding loop passes to 7460484Sobrien /// the end of the loop optimizer. 7560484Sobrien EP_LoopOptimizerEnd, 7660484Sobrien 7760484Sobrien /// EP_ScalarOptimizerLate - This extension point allows adding optimization 7860484Sobrien /// passes after most of the main optimizations, but before the last 7960484Sobrien /// cleanup-ish optimizations. 8060484Sobrien EP_ScalarOptimizerLate, 8160484Sobrien 8260484Sobrien /// EP_OptimizerLast -- This extension point allows adding passes that 8360484Sobrien /// run after everything else. 8460484Sobrien EP_OptimizerLast, 8560484Sobrien 8660484Sobrien /// EP_EnabledOnOptLevel0 - This extension point allows adding passes that 8760484Sobrien /// should not be disabled by O0 optimization level. The passes will be 8860484Sobrien /// inserted after the inlining pass. 8944348Simp EP_EnabledOnOptLevel0 9044348Simp }; 9144348Simp 9244348Simp /// The Optimization Level - Specify the basic optimization level. 9344348Simp /// 0 = -O0, 1 = -O1, 2 = -O2, 3 = -O3 9444348Simp unsigned OptLevel; 9544348Simp 9644348Simp /// SizeLevel - How much we're optimizing for size. 9744348Simp /// 0 = none, 1 = -Os, 2 = -Oz 9844348Simp unsigned SizeLevel; 9944348Simp 10044348Simp /// LibraryInfo - Specifies information about the runtime library for the 10144348Simp /// optimizer. If this is non-null, it is added to both the function and 10244348Simp /// per-module pass pipeline. 10344348Simp TargetLibraryInfo *LibraryInfo; 10460484Sobrien 10560484Sobrien /// Inliner - Specifies the inliner to use. If this is non-null, it is 10660484Sobrien /// added to the per-module passes. 10760484Sobrien Pass *Inliner; 10844348Simp 10944348Simp bool DisableUnitAtATime; 11044348Simp bool DisableUnrollLoops; 11144348Simp bool BBVectorize; 11244348Simp bool SLPVectorize; 11344348Simp bool LoopVectorize; 11444348Simp bool LateVectorize; 11544348Simp bool RerollLoops; 11644348Simp 11744348Simpprivate: 11844348Simp /// ExtensionList - This is list of all of the extensions that are registered. 11944348Simp std::vector<std::pair<ExtensionPointTy, ExtensionFn> > Extensions; 12044348Simp 12144348Simppublic: 12260484Sobrien PassManagerBuilder(); 12360484Sobrien ~PassManagerBuilder(); 12460484Sobrien /// Adds an extension that will be used by all PassManagerBuilder instances. 12560484Sobrien /// This is intended to be used by plugins, to register a set of 12660484Sobrien /// optimisations to run automatically. 12760484Sobrien static void addGlobalExtension(ExtensionPointTy Ty, ExtensionFn Fn); 12860484Sobrien void addExtension(ExtensionPointTy Ty, ExtensionFn Fn); 12960484Sobrien 13060484Sobrienprivate: 13160484Sobrien void addExtensionsToPM(ExtensionPointTy ETy, PassManagerBase &PM) const; 13260484Sobrien void addInitialAliasAnalysisPasses(PassManagerBase &PM) const; 13360484Sobrienpublic: 13460484Sobrien 13560484Sobrien /// populateFunctionPassManager - This fills in the function pass manager, 13660484Sobrien /// which is expected to be run on each function immediately as it is 13760484Sobrien /// generated. The idea is to reduce the size of the IR in memory. 13860484Sobrien void populateFunctionPassManager(FunctionPassManager &FPM); 13960484Sobrien 14060484Sobrien /// populateModulePassManager - This sets up the primary pass manager. 14160484Sobrien void populateModulePassManager(PassManagerBase &MPM); 14260484Sobrien void populateLTOPassManager(PassManagerBase &PM, bool Internalize, 14360484Sobrien bool RunInliner, bool DisableGVNLoadPRE = false); 14460484Sobrien}; 14560484Sobrien 14660484Sobrien/// Registers a function for adding a standard set of passes. This should be 14760484Sobrien/// used by optimizer plugins to allow all front ends to transparently use 14860484Sobrien/// them. Create a static instance of this class in your plugin, providing a 14960484Sobrien/// private function that the PassManagerBuilder can use to add your passes. 15060484Sobrienstruct RegisterStandardPasses { 15160484Sobrien RegisterStandardPasses(PassManagerBuilder::ExtensionPointTy Ty, 15260484Sobrien PassManagerBuilder::ExtensionFn Fn) { 15360484Sobrien PassManagerBuilder::addGlobalExtension(Ty, Fn); 15460484Sobrien } 15560484Sobrien}; 15644348Simp 15744348Simp} // end namespace llvm 15844348Simp#endif 15944348Simp