2011-08-02 21:50:24 +00:00
|
|
|
// llvm/Transforms/IPO/PassManagerBuilder.h - Build Standard Pass -*- C++ -*-=//
|
2011-05-21 20:39:42 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the PassManagerBuilder class, which is used to set up a
|
|
|
|
// "standard" optimization sequence suitable for languages like C and C++.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_SUPPORT_PASSMANAGERBUILDER_H
|
|
|
|
#define LLVM_SUPPORT_PASSMANAGERBUILDER_H
|
|
|
|
|
2011-08-02 21:50:27 +00:00
|
|
|
#include <vector>
|
2011-05-21 20:39:42 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
2011-08-02 21:50:27 +00:00
|
|
|
class TargetLibraryInfo;
|
|
|
|
class PassManagerBase;
|
|
|
|
class Pass;
|
|
|
|
class FunctionPassManager;
|
|
|
|
|
2011-05-21 20:39:42 +00:00
|
|
|
/// PassManagerBuilder - This class is used to set up a standard optimization
|
|
|
|
/// sequence for languages like C and C++, allowing some APIs to customize the
|
|
|
|
/// pass sequence in various ways. A simple example of using it would be:
|
|
|
|
///
|
2011-06-10 12:28:24 +00:00
|
|
|
/// PassManagerBuilder Builder;
|
|
|
|
/// Builder.OptLevel = 2;
|
2011-05-21 20:39:42 +00:00
|
|
|
/// Builder.populateFunctionPassManager(FPM);
|
|
|
|
/// Builder.populateModulePassManager(MPM);
|
|
|
|
///
|
2011-05-21 23:50:37 +00:00
|
|
|
/// In addition to setting up the basic passes, PassManagerBuilder allows
|
|
|
|
/// frontends to vend a plugin API, where plugins are allowed to add extensions
|
|
|
|
/// to the default pass manager. They do this by specifying where in the pass
|
|
|
|
/// pipeline they want to be added, along with a callback function that adds
|
|
|
|
/// the pass(es). For example, a plugin that wanted to add a loop optimization
|
|
|
|
/// could do something like this:
|
|
|
|
///
|
|
|
|
/// static void addMyLoopPass(const PMBuilder &Builder, PassManagerBase &PM) {
|
|
|
|
/// if (Builder.getOptLevel() > 2 && Builder.getOptSizeLevel() == 0)
|
|
|
|
/// PM.add(createMyAwesomePass());
|
|
|
|
/// }
|
|
|
|
/// ...
|
|
|
|
/// Builder.addExtension(PassManagerBuilder::EP_LoopOptimizerEnd,
|
|
|
|
/// addMyLoopPass);
|
|
|
|
/// ...
|
2011-05-21 20:39:42 +00:00
|
|
|
class PassManagerBuilder {
|
2011-05-21 23:50:37 +00:00
|
|
|
public:
|
2011-08-02 21:50:27 +00:00
|
|
|
|
2011-05-21 23:50:37 +00:00
|
|
|
/// Extensions are passed the builder itself (so they can see how it is
|
|
|
|
/// configured) as well as the pass manager to add stuff to.
|
|
|
|
typedef void (*ExtensionFn)(const PassManagerBuilder &Builder,
|
|
|
|
PassManagerBase &PM);
|
|
|
|
enum ExtensionPointTy {
|
|
|
|
/// EP_EarlyAsPossible - This extension point allows adding passes before
|
|
|
|
/// any other transformations, allowing them to see the code as it is coming
|
|
|
|
/// out of the frontend.
|
|
|
|
EP_EarlyAsPossible,
|
2011-08-02 21:50:27 +00:00
|
|
|
|
2012-01-17 20:51:32 +00:00
|
|
|
/// EP_ModuleOptimizerEarly - This extension point allows adding passes
|
|
|
|
/// just before the main module-level optimization passes.
|
|
|
|
EP_ModuleOptimizerEarly,
|
|
|
|
|
2011-05-21 23:50:37 +00:00
|
|
|
/// EP_LoopOptimizerEnd - This extension point allows adding loop passes to
|
|
|
|
/// the end of the loop optimizer.
|
2011-07-05 22:01:44 +00:00
|
|
|
EP_LoopOptimizerEnd,
|
|
|
|
|
|
|
|
/// EP_ScalarOptimizerLate - This extension point allows adding optimization
|
|
|
|
/// passes after most of the main optimizations, but before the last
|
|
|
|
/// cleanup-ish optimizations.
|
2011-11-30 22:19:26 +00:00
|
|
|
EP_ScalarOptimizerLate,
|
|
|
|
|
2012-03-23 23:22:59 +00:00
|
|
|
/// EP_OptimizerLast -- This extension point allows adding passes that
|
|
|
|
/// run after everything else.
|
|
|
|
EP_OptimizerLast,
|
|
|
|
|
2011-11-30 22:19:26 +00:00
|
|
|
/// EP_EnabledOnOptLevel0 - This extension point allows adding passes that
|
|
|
|
/// should not be disabled by O0 optimization level. The passes will be
|
|
|
|
/// inserted after the inlining pass.
|
|
|
|
EP_EnabledOnOptLevel0
|
2011-05-21 23:50:37 +00:00
|
|
|
};
|
2011-08-02 21:50:27 +00:00
|
|
|
|
2011-05-21 23:50:37 +00:00
|
|
|
/// The Optimization Level - Specify the basic optimization level.
|
|
|
|
/// 0 = -O0, 1 = -O1, 2 = -O2, 3 = -O3
|
|
|
|
unsigned OptLevel;
|
2011-08-02 21:50:27 +00:00
|
|
|
|
2011-05-21 23:50:37 +00:00
|
|
|
/// SizeLevel - How much we're optimizing for size.
|
|
|
|
/// 0 = none, 1 = -Os, 2 = -Oz
|
|
|
|
unsigned SizeLevel;
|
2011-08-02 21:50:27 +00:00
|
|
|
|
2011-05-21 23:50:37 +00:00
|
|
|
/// LibraryInfo - Specifies information about the runtime library for the
|
|
|
|
/// optimizer. If this is non-null, it is added to both the function and
|
|
|
|
/// per-module pass pipeline.
|
|
|
|
TargetLibraryInfo *LibraryInfo;
|
2011-08-02 21:50:27 +00:00
|
|
|
|
2011-05-21 23:50:37 +00:00
|
|
|
/// Inliner - Specifies the inliner to use. If this is non-null, it is
|
|
|
|
/// added to the per-module passes.
|
|
|
|
Pass *Inliner;
|
2011-08-02 21:50:27 +00:00
|
|
|
|
2011-05-21 20:39:42 +00:00
|
|
|
bool DisableSimplifyLibCalls;
|
|
|
|
bool DisableUnitAtATime;
|
|
|
|
bool DisableUnrollLoops;
|
2012-02-01 03:51:43 +00:00
|
|
|
bool Vectorize;
|
2011-08-02 21:50:27 +00:00
|
|
|
|
2011-05-21 23:50:37 +00:00
|
|
|
private:
|
|
|
|
/// ExtensionList - This is list of all of the extensions that are registered.
|
|
|
|
std::vector<std::pair<ExtensionPointTy, ExtensionFn> > Extensions;
|
2011-08-02 21:50:27 +00:00
|
|
|
|
2011-05-21 20:39:42 +00:00
|
|
|
public:
|
2011-08-02 21:50:27 +00:00
|
|
|
PassManagerBuilder();
|
|
|
|
~PassManagerBuilder();
|
2011-08-16 13:58:41 +00:00
|
|
|
/// Adds an extension that will be used by all PassManagerBuilder instances.
|
|
|
|
/// This is intended to be used by plugins, to register a set of
|
|
|
|
/// optimisations to run automatically.
|
|
|
|
static void addGlobalExtension(ExtensionPointTy Ty, ExtensionFn Fn);
|
2011-08-02 21:50:27 +00:00
|
|
|
void addExtension(ExtensionPointTy Ty, ExtensionFn Fn);
|
|
|
|
|
2011-05-21 20:39:42 +00:00
|
|
|
private:
|
2011-08-02 21:50:27 +00:00
|
|
|
void addExtensionsToPM(ExtensionPointTy ETy, PassManagerBase &PM) const;
|
|
|
|
void addInitialAliasAnalysisPasses(PassManagerBase &PM) const;
|
2011-05-21 20:39:42 +00:00
|
|
|
public:
|
2011-08-02 21:50:27 +00:00
|
|
|
|
2011-05-21 20:39:42 +00:00
|
|
|
/// populateFunctionPassManager - This fills in the function pass manager,
|
|
|
|
/// which is expected to be run on each function immediately as it is
|
|
|
|
/// generated. The idea is to reduce the size of the IR in memory.
|
2011-08-02 21:50:27 +00:00
|
|
|
void populateFunctionPassManager(FunctionPassManager &FPM);
|
2011-05-21 23:50:37 +00:00
|
|
|
|
2011-05-21 20:39:42 +00:00
|
|
|
/// populateModulePassManager - This sets up the primary pass manager.
|
2011-08-02 21:50:27 +00:00
|
|
|
void populateModulePassManager(PassManagerBase &MPM);
|
2011-05-22 00:14:20 +00:00
|
|
|
void populateLTOPassManager(PassManagerBase &PM, bool Internalize,
|
2012-04-02 22:16:50 +00:00
|
|
|
bool RunInliner, bool DisableGVNLoadPRE = false);
|
2011-05-21 20:39:42 +00:00
|
|
|
};
|
2012-04-02 22:16:50 +00:00
|
|
|
|
2011-08-16 13:58:41 +00:00
|
|
|
/// Registers a function for adding a standard set of passes. This should be
|
|
|
|
/// used by optimizer plugins to allow all front ends to transparently use
|
|
|
|
/// them. Create a static instance of this class in your plugin, providing a
|
|
|
|
/// private function that the PassManagerBuilder can use to add your passes.
|
|
|
|
struct RegisterStandardPasses {
|
|
|
|
RegisterStandardPasses(PassManagerBuilder::ExtensionPointTy Ty,
|
|
|
|
PassManagerBuilder::ExtensionFn Fn) {
|
|
|
|
PassManagerBuilder::addGlobalExtension(Ty, Fn);
|
|
|
|
}
|
|
|
|
};
|
2012-04-02 22:16:50 +00:00
|
|
|
|
2011-05-21 20:39:42 +00:00
|
|
|
} // end namespace llvm
|
|
|
|
#endif
|