mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-02 19:24:25 +00:00
Move methods in PassManagerBuilder offline.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@136727 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -10,23 +10,18 @@
|
|||||||
// This file defines the PassManagerBuilder class, which is used to set up a
|
// This file defines the PassManagerBuilder class, which is used to set up a
|
||||||
// "standard" optimization sequence suitable for languages like C and C++.
|
// "standard" optimization sequence suitable for languages like C and C++.
|
||||||
//
|
//
|
||||||
// These are implemented as inline functions so that we do not have to worry
|
|
||||||
// about link issues.
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#ifndef LLVM_SUPPORT_PASSMANAGERBUILDER_H
|
#ifndef LLVM_SUPPORT_PASSMANAGERBUILDER_H
|
||||||
#define LLVM_SUPPORT_PASSMANAGERBUILDER_H
|
#define LLVM_SUPPORT_PASSMANAGERBUILDER_H
|
||||||
|
|
||||||
#include "llvm/PassManager.h"
|
#include <vector>
|
||||||
#include "llvm/DefaultPasses.h"
|
|
||||||
#include "llvm/Analysis/Passes.h"
|
|
||||||
#include "llvm/Analysis/Verifier.h"
|
|
||||||
#include "llvm/Target/TargetLibraryInfo.h"
|
|
||||||
#include "llvm/Transforms/Scalar.h"
|
|
||||||
#include "llvm/Transforms/IPO.h"
|
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
class TargetLibraryInfo;
|
||||||
|
class PassManagerBase;
|
||||||
|
class Pass;
|
||||||
|
class FunctionPassManager;
|
||||||
|
|
||||||
/// PassManagerBuilder - This class is used to set up a standard optimization
|
/// PassManagerBuilder - This class is used to set up a standard optimization
|
||||||
/// sequence for languages like C and C++, allowing some APIs to customize the
|
/// sequence for languages like C and C++, allowing some APIs to customize the
|
||||||
@ -101,231 +96,25 @@ private:
|
|||||||
std::vector<std::pair<ExtensionPointTy, ExtensionFn> > Extensions;
|
std::vector<std::pair<ExtensionPointTy, ExtensionFn> > Extensions;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PassManagerBuilder() {
|
PassManagerBuilder();
|
||||||
OptLevel = 2;
|
~PassManagerBuilder();
|
||||||
SizeLevel = 0;
|
void addExtension(ExtensionPointTy Ty, ExtensionFn Fn);
|
||||||
LibraryInfo = 0;
|
|
||||||
Inliner = 0;
|
|
||||||
DisableSimplifyLibCalls = false;
|
|
||||||
DisableUnitAtATime = false;
|
|
||||||
DisableUnrollLoops = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
~PassManagerBuilder() {
|
|
||||||
delete LibraryInfo;
|
|
||||||
delete Inliner;
|
|
||||||
}
|
|
||||||
|
|
||||||
void addExtension(ExtensionPointTy Ty, ExtensionFn Fn) {
|
|
||||||
Extensions.push_back(std::make_pair(Ty, Fn));
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void addExtensionsToPM(ExtensionPointTy ETy, PassManagerBase &PM) const {
|
void addExtensionsToPM(ExtensionPointTy ETy, PassManagerBase &PM) const;
|
||||||
for (unsigned i = 0, e = Extensions.size(); i != e; ++i)
|
void addInitialAliasAnalysisPasses(PassManagerBase &PM) const;
|
||||||
if (Extensions[i].first == ETy)
|
|
||||||
Extensions[i].second(*this, PM);
|
|
||||||
}
|
|
||||||
|
|
||||||
void addInitialAliasAnalysisPasses(PassManagerBase &PM) const {
|
|
||||||
// Add TypeBasedAliasAnalysis before BasicAliasAnalysis so that
|
|
||||||
// BasicAliasAnalysis wins if they disagree. This is intended to help
|
|
||||||
// support "obvious" type-punning idioms.
|
|
||||||
PM.add(createTypeBasedAliasAnalysisPass());
|
|
||||||
PM.add(createBasicAliasAnalysisPass());
|
|
||||||
}
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/// populateFunctionPassManager - This fills in the function pass manager,
|
/// populateFunctionPassManager - This fills in the function pass manager,
|
||||||
/// which is expected to be run on each function immediately as it is
|
/// 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.
|
/// generated. The idea is to reduce the size of the IR in memory.
|
||||||
void populateFunctionPassManager(FunctionPassManager &FPM) {
|
void populateFunctionPassManager(FunctionPassManager &FPM);
|
||||||
addExtensionsToPM(EP_EarlyAsPossible, FPM);
|
|
||||||
|
|
||||||
// Add LibraryInfo if we have some.
|
|
||||||
if (LibraryInfo) FPM.add(new TargetLibraryInfo(*LibraryInfo));
|
|
||||||
|
|
||||||
if (OptLevel == 0) return;
|
|
||||||
|
|
||||||
addInitialAliasAnalysisPasses(FPM);
|
|
||||||
|
|
||||||
FPM.add(createCFGSimplificationPass());
|
|
||||||
FPM.add(createScalarReplAggregatesPass());
|
|
||||||
FPM.add(createEarlyCSEPass());
|
|
||||||
FPM.add(createLowerExpectIntrinsicPass());
|
|
||||||
}
|
|
||||||
|
|
||||||
/// populateModulePassManager - This sets up the primary pass manager.
|
/// populateModulePassManager - This sets up the primary pass manager.
|
||||||
void populateModulePassManager(PassManagerBase &MPM) {
|
void populateModulePassManager(PassManagerBase &MPM);
|
||||||
// If all optimizations are disabled, just run the always-inline pass.
|
|
||||||
if (OptLevel == 0) {
|
|
||||||
if (Inliner) {
|
|
||||||
MPM.add(Inliner);
|
|
||||||
Inliner = 0;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add LibraryInfo if we have some.
|
|
||||||
if (LibraryInfo) MPM.add(new TargetLibraryInfo(*LibraryInfo));
|
|
||||||
|
|
||||||
addInitialAliasAnalysisPasses(MPM);
|
|
||||||
|
|
||||||
if (!DisableUnitAtATime) {
|
|
||||||
MPM.add(createGlobalOptimizerPass()); // Optimize out global vars
|
|
||||||
|
|
||||||
MPM.add(createIPSCCPPass()); // IP SCCP
|
|
||||||
MPM.add(createDeadArgEliminationPass()); // Dead argument elimination
|
|
||||||
|
|
||||||
MPM.add(createInstructionCombiningPass());// Clean up after IPCP & DAE
|
|
||||||
MPM.add(createCFGSimplificationPass()); // Clean up after IPCP & DAE
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start of CallGraph SCC passes.
|
|
||||||
if (!DisableUnitAtATime)
|
|
||||||
MPM.add(createPruneEHPass()); // Remove dead EH info
|
|
||||||
if (Inliner) {
|
|
||||||
MPM.add(Inliner);
|
|
||||||
Inliner = 0;
|
|
||||||
}
|
|
||||||
if (!DisableUnitAtATime)
|
|
||||||
MPM.add(createFunctionAttrsPass()); // Set readonly/readnone attrs
|
|
||||||
if (OptLevel > 2)
|
|
||||||
MPM.add(createArgumentPromotionPass()); // Scalarize uninlined fn args
|
|
||||||
|
|
||||||
// Start of function pass.
|
|
||||||
// Break up aggregate allocas, using SSAUpdater.
|
|
||||||
MPM.add(createScalarReplAggregatesPass(-1, false));
|
|
||||||
MPM.add(createEarlyCSEPass()); // Catch trivial redundancies
|
|
||||||
if (!DisableSimplifyLibCalls)
|
|
||||||
MPM.add(createSimplifyLibCallsPass()); // Library Call Optimizations
|
|
||||||
MPM.add(createJumpThreadingPass()); // Thread jumps.
|
|
||||||
MPM.add(createCorrelatedValuePropagationPass()); // Propagate conditionals
|
|
||||||
MPM.add(createCFGSimplificationPass()); // Merge & remove BBs
|
|
||||||
MPM.add(createInstructionCombiningPass()); // Combine silly seq's
|
|
||||||
|
|
||||||
MPM.add(createTailCallEliminationPass()); // Eliminate tail calls
|
|
||||||
MPM.add(createCFGSimplificationPass()); // Merge & remove BBs
|
|
||||||
MPM.add(createReassociatePass()); // Reassociate expressions
|
|
||||||
MPM.add(createLoopRotatePass()); // Rotate Loop
|
|
||||||
MPM.add(createLICMPass()); // Hoist loop invariants
|
|
||||||
MPM.add(createLoopUnswitchPass(SizeLevel || OptLevel < 3));
|
|
||||||
MPM.add(createInstructionCombiningPass());
|
|
||||||
MPM.add(createIndVarSimplifyPass()); // Canonicalize indvars
|
|
||||||
MPM.add(createLoopIdiomPass()); // Recognize idioms like memset.
|
|
||||||
MPM.add(createLoopDeletionPass()); // Delete dead loops
|
|
||||||
if (!DisableUnrollLoops)
|
|
||||||
MPM.add(createLoopUnrollPass()); // Unroll small loops
|
|
||||||
addExtensionsToPM(EP_LoopOptimizerEnd, MPM);
|
|
||||||
|
|
||||||
if (OptLevel > 1)
|
|
||||||
MPM.add(createGVNPass()); // Remove redundancies
|
|
||||||
MPM.add(createMemCpyOptPass()); // Remove memcpy / form memset
|
|
||||||
MPM.add(createSCCPPass()); // Constant prop with SCCP
|
|
||||||
|
|
||||||
// Run instcombine after redundancy elimination to exploit opportunities
|
|
||||||
// opened up by them.
|
|
||||||
MPM.add(createInstructionCombiningPass());
|
|
||||||
MPM.add(createJumpThreadingPass()); // Thread jumps
|
|
||||||
MPM.add(createCorrelatedValuePropagationPass());
|
|
||||||
MPM.add(createDeadStoreEliminationPass()); // Delete dead stores
|
|
||||||
|
|
||||||
addExtensionsToPM(EP_ScalarOptimizerLate, MPM);
|
|
||||||
|
|
||||||
MPM.add(createAggressiveDCEPass()); // Delete dead instructions
|
|
||||||
MPM.add(createCFGSimplificationPass()); // Merge & remove BBs
|
|
||||||
MPM.add(createInstructionCombiningPass()); // Clean up after everything.
|
|
||||||
|
|
||||||
if (!DisableUnitAtATime) {
|
|
||||||
// FIXME: We shouldn't bother with this anymore.
|
|
||||||
MPM.add(createStripDeadPrototypesPass()); // Get rid of dead prototypes
|
|
||||||
|
|
||||||
// GlobalOpt already deletes dead functions and globals, at -O3 try a
|
|
||||||
// late pass of GlobalDCE. It is capable of deleting dead cycles.
|
|
||||||
if (OptLevel > 2)
|
|
||||||
MPM.add(createGlobalDCEPass()); // Remove dead fns and globals.
|
|
||||||
|
|
||||||
if (OptLevel > 1)
|
|
||||||
MPM.add(createConstantMergePass()); // Merge dup global constants
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void populateLTOPassManager(PassManagerBase &PM, bool Internalize,
|
void populateLTOPassManager(PassManagerBase &PM, bool Internalize,
|
||||||
bool RunInliner) {
|
bool RunInliner);
|
||||||
// Provide AliasAnalysis services for optimizations.
|
|
||||||
addInitialAliasAnalysisPasses(PM);
|
|
||||||
|
|
||||||
// Now that composite has been compiled, scan through the module, looking
|
|
||||||
// for a main function. If main is defined, mark all other functions
|
|
||||||
// internal.
|
|
||||||
if (Internalize)
|
|
||||||
PM.add(createInternalizePass(true));
|
|
||||||
|
|
||||||
// Propagate constants at call sites into the functions they call. This
|
|
||||||
// opens opportunities for globalopt (and inlining) by substituting function
|
|
||||||
// pointers passed as arguments to direct uses of functions.
|
|
||||||
PM.add(createIPSCCPPass());
|
|
||||||
|
|
||||||
// Now that we internalized some globals, see if we can hack on them!
|
|
||||||
PM.add(createGlobalOptimizerPass());
|
|
||||||
|
|
||||||
// Linking modules together can lead to duplicated global constants, only
|
|
||||||
// keep one copy of each constant.
|
|
||||||
PM.add(createConstantMergePass());
|
|
||||||
|
|
||||||
// Remove unused arguments from functions.
|
|
||||||
PM.add(createDeadArgEliminationPass());
|
|
||||||
|
|
||||||
// Reduce the code after globalopt and ipsccp. Both can open up significant
|
|
||||||
// simplification opportunities, and both can propagate functions through
|
|
||||||
// function pointers. When this happens, we often have to resolve varargs
|
|
||||||
// calls, etc, so let instcombine do this.
|
|
||||||
PM.add(createInstructionCombiningPass());
|
|
||||||
|
|
||||||
// Inline small functions
|
|
||||||
if (RunInliner)
|
|
||||||
PM.add(createFunctionInliningPass());
|
|
||||||
|
|
||||||
PM.add(createPruneEHPass()); // Remove dead EH info.
|
|
||||||
|
|
||||||
// Optimize globals again if we ran the inliner.
|
|
||||||
if (RunInliner)
|
|
||||||
PM.add(createGlobalOptimizerPass());
|
|
||||||
PM.add(createGlobalDCEPass()); // Remove dead functions.
|
|
||||||
|
|
||||||
// If we didn't decide to inline a function, check to see if we can
|
|
||||||
// transform it to pass arguments by value instead of by reference.
|
|
||||||
PM.add(createArgumentPromotionPass());
|
|
||||||
|
|
||||||
// The IPO passes may leave cruft around. Clean up after them.
|
|
||||||
PM.add(createInstructionCombiningPass());
|
|
||||||
PM.add(createJumpThreadingPass());
|
|
||||||
// Break up allocas
|
|
||||||
PM.add(createScalarReplAggregatesPass());
|
|
||||||
|
|
||||||
// Run a few AA driven optimizations here and now, to cleanup the code.
|
|
||||||
PM.add(createFunctionAttrsPass()); // Add nocapture.
|
|
||||||
PM.add(createGlobalsModRefPass()); // IP alias analysis.
|
|
||||||
|
|
||||||
PM.add(createLICMPass()); // Hoist loop invariants.
|
|
||||||
PM.add(createGVNPass()); // Remove redundancies.
|
|
||||||
PM.add(createMemCpyOptPass()); // Remove dead memcpys.
|
|
||||||
// Nuke dead stores.
|
|
||||||
PM.add(createDeadStoreEliminationPass());
|
|
||||||
|
|
||||||
// Cleanup and simplify the code after the scalar optimizations.
|
|
||||||
PM.add(createInstructionCombiningPass());
|
|
||||||
|
|
||||||
PM.add(createJumpThreadingPass());
|
|
||||||
|
|
||||||
// Delete basic blocks, which optimization passes may have killed.
|
|
||||||
PM.add(createCFGSimplificationPass());
|
|
||||||
|
|
||||||
// Now that we have optimized the program, discard unreachable functions.
|
|
||||||
PM.add(createGlobalDCEPass());
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // end namespace llvm
|
} // end namespace llvm
|
||||||
#endif
|
#endif
|
||||||
|
@ -16,6 +16,7 @@ add_llvm_library(LLVMipo
|
|||||||
LowerSetJmp.cpp
|
LowerSetJmp.cpp
|
||||||
MergeFunctions.cpp
|
MergeFunctions.cpp
|
||||||
PartialInlining.cpp
|
PartialInlining.cpp
|
||||||
|
PassManagerBuilder.cpp
|
||||||
PruneEH.cpp
|
PruneEH.cpp
|
||||||
StripDeadPrototypes.cpp
|
StripDeadPrototypes.cpp
|
||||||
StripSymbols.cpp
|
StripSymbols.cpp
|
||||||
|
248
lib/Transforms/IPO/PassManagerBuilder.cpp
Normal file
248
lib/Transforms/IPO/PassManagerBuilder.cpp
Normal file
@ -0,0 +1,248 @@
|
|||||||
|
//===- PassManagerBuilder.cpp - Build Standard Pass -----------------------===//
|
||||||
|
//
|
||||||
|
// 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++.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
|
||||||
|
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
|
||||||
|
|
||||||
|
#include "llvm/PassManager.h"
|
||||||
|
#include "llvm/DefaultPasses.h"
|
||||||
|
#include "llvm/PassManager.h"
|
||||||
|
#include "llvm/Analysis/Passes.h"
|
||||||
|
#include "llvm/Analysis/Verifier.h"
|
||||||
|
#include "llvm/Target/TargetLibraryInfo.h"
|
||||||
|
#include "llvm/Transforms/Scalar.h"
|
||||||
|
#include "llvm/Transforms/IPO.h"
|
||||||
|
|
||||||
|
using namespace llvm;
|
||||||
|
|
||||||
|
PassManagerBuilder::PassManagerBuilder() {
|
||||||
|
OptLevel = 2;
|
||||||
|
SizeLevel = 0;
|
||||||
|
LibraryInfo = 0;
|
||||||
|
Inliner = 0;
|
||||||
|
DisableSimplifyLibCalls = false;
|
||||||
|
DisableUnitAtATime = false;
|
||||||
|
DisableUnrollLoops = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
PassManagerBuilder::~PassManagerBuilder() {
|
||||||
|
delete LibraryInfo;
|
||||||
|
delete Inliner;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PassManagerBuilder::addExtension(ExtensionPointTy Ty, ExtensionFn Fn) {
|
||||||
|
Extensions.push_back(std::make_pair(Ty, Fn));
|
||||||
|
}
|
||||||
|
|
||||||
|
void PassManagerBuilder::addExtensionsToPM(ExtensionPointTy ETy,
|
||||||
|
PassManagerBase &PM) const {
|
||||||
|
for (unsigned i = 0, e = Extensions.size(); i != e; ++i)
|
||||||
|
if (Extensions[i].first == ETy)
|
||||||
|
Extensions[i].second(*this, PM);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PassManagerBuilder::addInitialAliasAnalysisPasses(PassManagerBase &PM) const {
|
||||||
|
// Add TypeBasedAliasAnalysis before BasicAliasAnalysis so that
|
||||||
|
// BasicAliasAnalysis wins if they disagree. This is intended to help
|
||||||
|
// support "obvious" type-punning idioms.
|
||||||
|
PM.add(createTypeBasedAliasAnalysisPass());
|
||||||
|
PM.add(createBasicAliasAnalysisPass());
|
||||||
|
}
|
||||||
|
|
||||||
|
void PassManagerBuilder::populateFunctionPassManager(FunctionPassManager &FPM) {
|
||||||
|
addExtensionsToPM(EP_EarlyAsPossible, FPM);
|
||||||
|
|
||||||
|
// Add LibraryInfo if we have some.
|
||||||
|
if (LibraryInfo) FPM.add(new TargetLibraryInfo(*LibraryInfo));
|
||||||
|
|
||||||
|
if (OptLevel == 0) return;
|
||||||
|
|
||||||
|
addInitialAliasAnalysisPasses(FPM);
|
||||||
|
|
||||||
|
FPM.add(createCFGSimplificationPass());
|
||||||
|
FPM.add(createScalarReplAggregatesPass());
|
||||||
|
FPM.add(createEarlyCSEPass());
|
||||||
|
FPM.add(createLowerExpectIntrinsicPass());
|
||||||
|
}
|
||||||
|
|
||||||
|
void PassManagerBuilder::populateModulePassManager(PassManagerBase &MPM) {
|
||||||
|
// If all optimizations are disabled, just run the always-inline pass.
|
||||||
|
if (OptLevel == 0) {
|
||||||
|
if (Inliner) {
|
||||||
|
MPM.add(Inliner);
|
||||||
|
Inliner = 0;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add LibraryInfo if we have some.
|
||||||
|
if (LibraryInfo) MPM.add(new TargetLibraryInfo(*LibraryInfo));
|
||||||
|
|
||||||
|
addInitialAliasAnalysisPasses(MPM);
|
||||||
|
|
||||||
|
if (!DisableUnitAtATime) {
|
||||||
|
MPM.add(createGlobalOptimizerPass()); // Optimize out global vars
|
||||||
|
|
||||||
|
MPM.add(createIPSCCPPass()); // IP SCCP
|
||||||
|
MPM.add(createDeadArgEliminationPass()); // Dead argument elimination
|
||||||
|
|
||||||
|
MPM.add(createInstructionCombiningPass());// Clean up after IPCP & DAE
|
||||||
|
MPM.add(createCFGSimplificationPass()); // Clean up after IPCP & DAE
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start of CallGraph SCC passes.
|
||||||
|
if (!DisableUnitAtATime)
|
||||||
|
MPM.add(createPruneEHPass()); // Remove dead EH info
|
||||||
|
if (Inliner) {
|
||||||
|
MPM.add(Inliner);
|
||||||
|
Inliner = 0;
|
||||||
|
}
|
||||||
|
if (!DisableUnitAtATime)
|
||||||
|
MPM.add(createFunctionAttrsPass()); // Set readonly/readnone attrs
|
||||||
|
if (OptLevel > 2)
|
||||||
|
MPM.add(createArgumentPromotionPass()); // Scalarize uninlined fn args
|
||||||
|
|
||||||
|
// Start of function pass.
|
||||||
|
// Break up aggregate allocas, using SSAUpdater.
|
||||||
|
MPM.add(createScalarReplAggregatesPass(-1, false));
|
||||||
|
MPM.add(createEarlyCSEPass()); // Catch trivial redundancies
|
||||||
|
if (!DisableSimplifyLibCalls)
|
||||||
|
MPM.add(createSimplifyLibCallsPass()); // Library Call Optimizations
|
||||||
|
MPM.add(createJumpThreadingPass()); // Thread jumps.
|
||||||
|
MPM.add(createCorrelatedValuePropagationPass()); // Propagate conditionals
|
||||||
|
MPM.add(createCFGSimplificationPass()); // Merge & remove BBs
|
||||||
|
MPM.add(createInstructionCombiningPass()); // Combine silly seq's
|
||||||
|
|
||||||
|
MPM.add(createTailCallEliminationPass()); // Eliminate tail calls
|
||||||
|
MPM.add(createCFGSimplificationPass()); // Merge & remove BBs
|
||||||
|
MPM.add(createReassociatePass()); // Reassociate expressions
|
||||||
|
MPM.add(createLoopRotatePass()); // Rotate Loop
|
||||||
|
MPM.add(createLICMPass()); // Hoist loop invariants
|
||||||
|
MPM.add(createLoopUnswitchPass(SizeLevel || OptLevel < 3));
|
||||||
|
MPM.add(createInstructionCombiningPass());
|
||||||
|
MPM.add(createIndVarSimplifyPass()); // Canonicalize indvars
|
||||||
|
MPM.add(createLoopIdiomPass()); // Recognize idioms like memset.
|
||||||
|
MPM.add(createLoopDeletionPass()); // Delete dead loops
|
||||||
|
if (!DisableUnrollLoops)
|
||||||
|
MPM.add(createLoopUnrollPass()); // Unroll small loops
|
||||||
|
addExtensionsToPM(EP_LoopOptimizerEnd, MPM);
|
||||||
|
|
||||||
|
if (OptLevel > 1)
|
||||||
|
MPM.add(createGVNPass()); // Remove redundancies
|
||||||
|
MPM.add(createMemCpyOptPass()); // Remove memcpy / form memset
|
||||||
|
MPM.add(createSCCPPass()); // Constant prop with SCCP
|
||||||
|
|
||||||
|
// Run instcombine after redundancy elimination to exploit opportunities
|
||||||
|
// opened up by them.
|
||||||
|
MPM.add(createInstructionCombiningPass());
|
||||||
|
MPM.add(createJumpThreadingPass()); // Thread jumps
|
||||||
|
MPM.add(createCorrelatedValuePropagationPass());
|
||||||
|
MPM.add(createDeadStoreEliminationPass()); // Delete dead stores
|
||||||
|
|
||||||
|
addExtensionsToPM(EP_ScalarOptimizerLate, MPM);
|
||||||
|
|
||||||
|
MPM.add(createAggressiveDCEPass()); // Delete dead instructions
|
||||||
|
MPM.add(createCFGSimplificationPass()); // Merge & remove BBs
|
||||||
|
MPM.add(createInstructionCombiningPass()); // Clean up after everything.
|
||||||
|
|
||||||
|
if (!DisableUnitAtATime) {
|
||||||
|
// FIXME: We shouldn't bother with this anymore.
|
||||||
|
MPM.add(createStripDeadPrototypesPass()); // Get rid of dead prototypes
|
||||||
|
|
||||||
|
// GlobalOpt already deletes dead functions and globals, at -O3 try a
|
||||||
|
// late pass of GlobalDCE. It is capable of deleting dead cycles.
|
||||||
|
if (OptLevel > 2)
|
||||||
|
MPM.add(createGlobalDCEPass()); // Remove dead fns and globals.
|
||||||
|
|
||||||
|
if (OptLevel > 1)
|
||||||
|
MPM.add(createConstantMergePass()); // Merge dup global constants
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PassManagerBuilder::populateLTOPassManager(PassManagerBase &PM,
|
||||||
|
bool Internalize,
|
||||||
|
bool RunInliner) {
|
||||||
|
// Provide AliasAnalysis services for optimizations.
|
||||||
|
addInitialAliasAnalysisPasses(PM);
|
||||||
|
|
||||||
|
// Now that composite has been compiled, scan through the module, looking
|
||||||
|
// for a main function. If main is defined, mark all other functions
|
||||||
|
// internal.
|
||||||
|
if (Internalize)
|
||||||
|
PM.add(createInternalizePass(true));
|
||||||
|
|
||||||
|
// Propagate constants at call sites into the functions they call. This
|
||||||
|
// opens opportunities for globalopt (and inlining) by substituting function
|
||||||
|
// pointers passed as arguments to direct uses of functions.
|
||||||
|
PM.add(createIPSCCPPass());
|
||||||
|
|
||||||
|
// Now that we internalized some globals, see if we can hack on them!
|
||||||
|
PM.add(createGlobalOptimizerPass());
|
||||||
|
|
||||||
|
// Linking modules together can lead to duplicated global constants, only
|
||||||
|
// keep one copy of each constant.
|
||||||
|
PM.add(createConstantMergePass());
|
||||||
|
|
||||||
|
// Remove unused arguments from functions.
|
||||||
|
PM.add(createDeadArgEliminationPass());
|
||||||
|
|
||||||
|
// Reduce the code after globalopt and ipsccp. Both can open up significant
|
||||||
|
// simplification opportunities, and both can propagate functions through
|
||||||
|
// function pointers. When this happens, we often have to resolve varargs
|
||||||
|
// calls, etc, so let instcombine do this.
|
||||||
|
PM.add(createInstructionCombiningPass());
|
||||||
|
|
||||||
|
// Inline small functions
|
||||||
|
if (RunInliner)
|
||||||
|
PM.add(createFunctionInliningPass());
|
||||||
|
|
||||||
|
PM.add(createPruneEHPass()); // Remove dead EH info.
|
||||||
|
|
||||||
|
// Optimize globals again if we ran the inliner.
|
||||||
|
if (RunInliner)
|
||||||
|
PM.add(createGlobalOptimizerPass());
|
||||||
|
PM.add(createGlobalDCEPass()); // Remove dead functions.
|
||||||
|
|
||||||
|
// If we didn't decide to inline a function, check to see if we can
|
||||||
|
// transform it to pass arguments by value instead of by reference.
|
||||||
|
PM.add(createArgumentPromotionPass());
|
||||||
|
|
||||||
|
// The IPO passes may leave cruft around. Clean up after them.
|
||||||
|
PM.add(createInstructionCombiningPass());
|
||||||
|
PM.add(createJumpThreadingPass());
|
||||||
|
// Break up allocas
|
||||||
|
PM.add(createScalarReplAggregatesPass());
|
||||||
|
|
||||||
|
// Run a few AA driven optimizations here and now, to cleanup the code.
|
||||||
|
PM.add(createFunctionAttrsPass()); // Add nocapture.
|
||||||
|
PM.add(createGlobalsModRefPass()); // IP alias analysis.
|
||||||
|
|
||||||
|
PM.add(createLICMPass()); // Hoist loop invariants.
|
||||||
|
PM.add(createGVNPass()); // Remove redundancies.
|
||||||
|
PM.add(createMemCpyOptPass()); // Remove dead memcpys.
|
||||||
|
// Nuke dead stores.
|
||||||
|
PM.add(createDeadStoreEliminationPass());
|
||||||
|
|
||||||
|
// Cleanup and simplify the code after the scalar optimizations.
|
||||||
|
PM.add(createInstructionCombiningPass());
|
||||||
|
|
||||||
|
PM.add(createJumpThreadingPass());
|
||||||
|
|
||||||
|
// Delete basic blocks, which optimization passes may have killed.
|
||||||
|
PM.add(createCFGSimplificationPass());
|
||||||
|
|
||||||
|
// Now that we have optimized the program, discard unreachable functions.
|
||||||
|
PM.add(createGlobalDCEPass());
|
||||||
|
}
|
@ -17,6 +17,7 @@
|
|||||||
#include "ToolRunner.h"
|
#include "ToolRunner.h"
|
||||||
#include "llvm/LinkAllPasses.h"
|
#include "llvm/LinkAllPasses.h"
|
||||||
#include "llvm/LLVMContext.h"
|
#include "llvm/LLVMContext.h"
|
||||||
|
#include "llvm/PassManager.h"
|
||||||
#include "llvm/Support/PassNameParser.h"
|
#include "llvm/Support/PassNameParser.h"
|
||||||
#include "llvm/Support/CommandLine.h"
|
#include "llvm/Support/CommandLine.h"
|
||||||
#include "llvm/Support/ManagedStatic.h"
|
#include "llvm/Support/ManagedStatic.h"
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "llvm/Module.h"
|
#include "llvm/Module.h"
|
||||||
|
#include "llvm/PassManager.h"
|
||||||
|
#include "llvm/Analysis/Verifier.h"
|
||||||
#include "llvm/Support/CommandLine.h"
|
#include "llvm/Support/CommandLine.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
#include "llvm/Support/DynamicLibrary.h"
|
#include "llvm/Support/DynamicLibrary.h"
|
||||||
@ -19,7 +21,9 @@
|
|||||||
#include "llvm/Target/TargetMachine.h"
|
#include "llvm/Target/TargetMachine.h"
|
||||||
#include "llvm/Support/PassNameParser.h"
|
#include "llvm/Support/PassNameParser.h"
|
||||||
#include "llvm/Support/PluginLoader.h"
|
#include "llvm/Support/PluginLoader.h"
|
||||||
|
#include "llvm/Transforms/IPO.h"
|
||||||
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
|
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
|
||||||
|
#include "llvm/Transforms/Scalar.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
// Pass Name Options as generated by the PassNameParser
|
// Pass Name Options as generated by the PassNameParser
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include "llvm/ADT/StringExtras.h"
|
#include "llvm/ADT/StringExtras.h"
|
||||||
#include "llvm/ADT/Triple.h"
|
#include "llvm/ADT/Triple.h"
|
||||||
#include "llvm/Analysis/Passes.h"
|
#include "llvm/Analysis/Passes.h"
|
||||||
|
#include "llvm/Analysis/Verifier.h"
|
||||||
#include "llvm/Bitcode/ReaderWriter.h"
|
#include "llvm/Bitcode/ReaderWriter.h"
|
||||||
#include "llvm/MC/MCAsmInfo.h"
|
#include "llvm/MC/MCAsmInfo.h"
|
||||||
#include "llvm/MC/MCContext.h"
|
#include "llvm/MC/MCContext.h"
|
||||||
@ -44,6 +45,7 @@
|
|||||||
#include "llvm/Support/Signals.h"
|
#include "llvm/Support/Signals.h"
|
||||||
#include "llvm/Support/system_error.h"
|
#include "llvm/Support/system_error.h"
|
||||||
#include "llvm/Config/config.h"
|
#include "llvm/Config/config.h"
|
||||||
|
#include "llvm/Transforms/IPO.h"
|
||||||
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
|
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
Reference in New Issue
Block a user