Add createStandardLTOPasses to StandardPasses.h, and move lto and llvm-ld over.

- I know it sounds crazy, but I think all the pass lists are now coalesced into
   StandardPasses.h.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72805 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Daniel Dunbar 2009-06-03 21:06:14 +00:00
parent 9911405183
commit 006a034828
3 changed files with 110 additions and 119 deletions

View File

@ -20,6 +20,8 @@
#define LLVM_SUPPORT_STANDARDPASSES_H
#include "llvm/PassManager.h"
#include "llvm/Analysis/Passes.h"
#include "llvm/Analysis/Verifier.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/IPO.h"
@ -53,6 +55,22 @@ namespace llvm {
bool HaveExceptions,
Pass *InliningPass);
/// createStandardLTOPasses - Add the standard list of module passes suitable
/// for link time optimization.
///
/// Internalize - Run the internalize pass.
/// RunInliner - Use a function inlining pass.
/// RunSecondGlobalOpt - Run the global optimizer pass twice.
/// VerifyEach - Run the verifier after each pass.
//
// FIXME: RunSecondGlobalOpt should go away once we resolve which of LTO or
// llvm-ld is better.
static inline void createStandardLTOPasses(PassManager *PM,
bool Internalize,
bool RunInliner,
bool RunSecondGlobalOpt,
bool VerifyEach);
// Implementations
static inline void createStandardFunctionPasses(FunctionPassManager *PM,
@ -144,6 +162,89 @@ namespace llvm {
PM->add(createConstantMergePass()); // Merge dup global constants
}
}
static inline void addOnePass(PassManager *PM, Pass *P, bool AndVerify) {
PM->add(P);
if (AndVerify)
PM->add(createVerifierPass());
}
static inline void createStandardLTOPasses(PassManager *PM,
bool Internalize,
bool RunInliner,
bool RunSecondGlobalOpt,
bool VerifyEach) {
// 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)
addOnePass(PM, createInternalizePass(true), VerifyEach);
// 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.
addOnePass(PM, createIPSCCPPass(), VerifyEach);
// Now that we internalized some globals, see if we can hack on them!
addOnePass(PM, createGlobalOptimizerPass(), VerifyEach);
// Linking modules together can lead to duplicated global constants, only
// keep one copy of each constant...
addOnePass(PM, createConstantMergePass(), VerifyEach);
// Remove unused arguments from functions...
addOnePass(PM, createDeadArgEliminationPass(), VerifyEach);
// 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.
addOnePass(PM, createInstructionCombiningPass(), VerifyEach);
// Inline small functions
if (RunInliner)
addOnePass(PM, createFunctionInliningPass(), VerifyEach);
addOnePass(PM, createPruneEHPass(), VerifyEach); // Remove dead EH info.
// Optimize globals again.
if (RunSecondGlobalOpt)
addOnePass(PM, createGlobalOptimizerPass(), VerifyEach);
addOnePass(PM, createGlobalDCEPass(), VerifyEach); // 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.
addOnePass(PM, createArgumentPromotionPass(), VerifyEach);
// The IPO passes may leave cruft around. Clean up after them.
addOnePass(PM, createInstructionCombiningPass(), VerifyEach);
addOnePass(PM, createJumpThreadingPass(), VerifyEach);
// Break up allocas
addOnePass(PM, createScalarReplAggregatesPass(), VerifyEach);
// Run a few AA driven optimizations here and now, to cleanup the code.
addOnePass(PM, createFunctionAttrsPass(), VerifyEach); // Add nocapture.
addOnePass(PM, createGlobalsModRefPass(), VerifyEach); // IP alias analysis.
addOnePass(PM, createLICMPass(), VerifyEach); // Hoist loop invariants.
addOnePass(PM, createGVNPass(), VerifyEach); // Remove redundancies.
addOnePass(PM, createMemCpyOptPass(), VerifyEach); // Remove dead memcpys.
// Nuke dead stores.
addOnePass(PM, createDeadStoreEliminationPass(), VerifyEach);
// Cleanup and simplify the code after the scalar optimizations.
addOnePass(PM, createInstructionCombiningPass(), VerifyEach);
addOnePass(PM, createJumpThreadingPass(), VerifyEach);
// Cleanup jump threading.
addOnePass(PM, createPromoteMemoryToRegisterPass(), VerifyEach);
// Delete basic blocks, which optimization passes may have killed...
addOnePass(PM, createCFGSimplificationPass(), VerifyEach);
// Now that we have optimized the program, discard unreachable functions.
addOnePass(PM, createGlobalDCEPass(), VerifyEach);
}
}
#endif

View File

@ -17,6 +17,7 @@
#include "llvm/Analysis/LoopPass.h"
#include "llvm/Analysis/Verifier.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/StandardPasses.h"
#include "llvm/System/DynamicLibrary.h"
#include "llvm/Target/TargetData.h"
#include "llvm/Target/TargetMachine.h"
@ -91,71 +92,9 @@ void Optimize(Module* M) {
// Add an appropriate TargetData instance for this module...
addPass(Passes, new TargetData(M));
if (!DisableOptimizations) {
// 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 (!DisableInternalize)
addPass(Passes, 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.
addPass(Passes, createIPSCCPPass());
// Now that we internalized some globals, see if we can hack on them!
addPass(Passes, createGlobalOptimizerPass());
// Linking modules together can lead to duplicated global constants, only
// keep one copy of each constant...
addPass(Passes, createConstantMergePass());
// Remove unused arguments from functions...
addPass(Passes, 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.
addPass(Passes, createInstructionCombiningPass());
if (!DisableInline)
addPass(Passes, createFunctionInliningPass()); // Inline small functions
addPass(Passes, createPruneEHPass()); // Remove dead EH info
addPass(Passes, createGlobalOptimizerPass()); // Optimize globals again.
addPass(Passes, 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.
addPass(Passes, createArgumentPromotionPass());
// The IPO passes may leave cruft around. Clean up after them.
addPass(Passes, createInstructionCombiningPass());
addPass(Passes, createJumpThreadingPass()); // Thread jumps.
addPass(Passes, createScalarReplAggregatesPass()); // Break up allocas
// Run a few AA driven optimizations here and now, to cleanup the code.
addPass(Passes, createFunctionAttrsPass()); // Add nocapture
addPass(Passes, createGlobalsModRefPass()); // IP alias analysis
addPass(Passes, createLICMPass()); // Hoist loop invariants
addPass(Passes, createGVNPass()); // Remove redundancies
addPass(Passes, createMemCpyOptPass()); // Remove dead memcpy's
addPass(Passes, createDeadStoreEliminationPass()); // Nuke dead stores
// Cleanup and simplify the code after the scalar optimizations.
addPass(Passes, createInstructionCombiningPass());
addPass(Passes, createJumpThreadingPass()); // Thread jumps.
addPass(Passes, createPromoteMemoryToRegisterPass()); // Cleanup jumpthread.
// Delete basic blocks, which optimization passes may have killed...
addPass(Passes, createCFGSimplificationPass());
// Now that we have optimized the program, discard unreachable functions...
addPass(Passes, createGlobalDCEPass());
}
if (!DisableOptimizations)
createStandardLTOPasses(&Passes, !DisableInternalize, !DisableInline,
/*RunSecondGlobalOpt=*/true, VerifyEach);
// If the -s or -S command line options were specified, strip the symbols out
// of the resulting program to make it smaller. -s and -S are GNU ld options

View File

@ -24,9 +24,10 @@
#include "llvm/ModuleProvider.h"
#include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/SystemUtils.h"
#include "llvm/Support/Mangler.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/StandardPasses.h"
#include "llvm/Support/SystemUtils.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/System/Signals.h"
#include "llvm/Analysis/Passes.h"
@ -389,59 +390,9 @@ bool LTOCodeGenerator::generateAssemblyCode(raw_ostream& out,
// Add an appropriate TargetData instance for this module...
passes.add(new TargetData(*_target->getTargetData()));
// 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.
passes.add(createIPSCCPPass());
// Now that we internalized some globals, see if we can hack on them!
passes.add(createGlobalOptimizerPass());
// Linking modules together can lead to duplicated global constants, only
// keep one copy of each constant...
passes.add(createConstantMergePass());
// Remove unused arguments from functions...
passes.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.
passes.add(createInstructionCombiningPass());
if (!DisableInline)
passes.add(createFunctionInliningPass()); // Inline small functions
passes.add(createPruneEHPass()); // Remove dead EH info
passes.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.
passes.add(createArgumentPromotionPass());
// The IPO passes may leave cruft around. Clean up after them.
passes.add(createInstructionCombiningPass());
passes.add(createJumpThreadingPass()); // Thread jumps.
passes.add(createScalarReplAggregatesPass()); // Break up allocas
// Run a few AA driven optimizations here and now, to cleanup the code.
passes.add(createFunctionAttrsPass()); // Add nocapture
passes.add(createGlobalsModRefPass()); // IP alias analysis
passes.add(createLICMPass()); // Hoist loop invariants
passes.add(createGVNPass()); // Remove common subexprs
passes.add(createMemCpyOptPass()); // Remove dead memcpy's
passes.add(createDeadStoreEliminationPass()); // Nuke dead stores
// Cleanup and simplify the code after the scalar optimizations.
passes.add(createInstructionCombiningPass());
passes.add(createJumpThreadingPass()); // Thread jumps.
passes.add(createPromoteMemoryToRegisterPass()); // Cleanup after threading.
// Delete basic blocks, which optimization passes may have killed...
passes.add(createCFGSimplificationPass());
// Now that we have optimized the program, discard unreachable functions...
passes.add(createGlobalDCEPass());
createStandardLTOPasses(&passes, /*Internalize=*/ false, !DisableInline,
/*RunSecondGlobalOpt=*/ false,
/*VerifyEach=*/ false);
// Make sure everything is still good.
passes.add(createVerifierPass());