X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=tools%2Fllvm-ld%2FOptimize.cpp;h=cbdf2f74990a6c9873a434b976857fd6b638ccb9;hb=56867520990a4fea1353d55f71bb74a0126554e6;hp=f53970371cdd56a848f797ac609886e434743500;hpb=dcee9d093fc81bbf47567d73aa46d8d6fe42dec1;p=oota-llvm.git diff --git a/tools/llvm-ld/Optimize.cpp b/tools/llvm-ld/Optimize.cpp index f53970371cd..cbdf2f74990 100644 --- a/tools/llvm-ld/Optimize.cpp +++ b/tools/llvm-ld/Optimize.cpp @@ -2,8 +2,8 @@ // // The LLVM Compiler Infrastructure // -// This file was developed by Reid Spencer and is distributed under the -// University of Illinois Open Source License. See LICENSE.TXT for details. +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // @@ -15,6 +15,7 @@ #include "llvm/PassManager.h" #include "llvm/Analysis/LoadValueNumbering.h" #include "llvm/Analysis/Passes.h" +#include "llvm/Analysis/LoopPass.h" #include "llvm/Analysis/Verifier.h" #include "llvm/Support/CommandLine.h" #include "llvm/System/DynamicLibrary.h" @@ -24,13 +25,16 @@ #include "llvm/Transforms/Scalar.h" #include "llvm/Support/PassNameParser.h" #include "llvm/Support/PluginLoader.h" +#include using namespace llvm; // Pass Name Options as generated by the PassNameParser -static cl::list > +static cl::list OptimizationList(cl::desc("Optimizations available:")); +//Don't verify at the end +static cl::opt DontVerify("disable-verify", cl::ReallyHidden); + // Optimization Enumeration enum OptimizationLevels { OPT_FAST_COMPILE = 1, @@ -73,13 +77,22 @@ static cl::opt DisableInternalize("disable-internalize", static cl::opt VerifyEach("verify-each", cl::desc("Verify intermediate results of all passes")); -static cl::opt Strip("s", - cl::desc("Strip symbol info from executable")); - static cl::alias ExportDynamic("export-dynamic", cl::aliasopt(DisableInternalize), cl::desc("Alias for -disable-internalize")); +static cl::opt Strip("strip-all", + cl::desc("Strip all symbol info from executable")); + +static cl::alias A0("s", cl::desc("Alias for --strip-all"), + cl::aliasopt(Strip)); + +static cl::opt StripDebug("strip-debug", + cl::desc("Strip debugger symbol info from executable")); + +static cl::alias A1("S", cl::desc("Alias for --strip-debug"), + cl::aliasopt(StripDebug)); + // A utility function that adds a pass to the pass manager but will also add // a verifier pass after if we're supposed to verify. static inline void addPass(PassManager &PM, Pass *P) { @@ -108,17 +121,17 @@ void Optimize(Module* M) { // Add an appropriate TargetData instance for this module... addPass(Passes, new TargetData(M)); - // Often if the programmer does not specify proper prototypes for the - // functions they are calling, they end up calling a vararg version of the - // function that does not get a body filled in (the real function has typed - // arguments). This pass merges the two functions. - addPass(Passes, createFunctionResolvingPass()); - 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. - addPass(Passes, createInternalizePass(!DisableInternalize)); + 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()); @@ -127,22 +140,20 @@ void Optimize(Module* M) { // keep one copy of each constant... addPass(Passes, createConstantMergePass()); - // If the -s command line option was specified, strip the symbols out of the - // resulting program to make it smaller. -s is a GLD option that we are - // supporting. - if (Strip) - addPass(Passes, createStripSymbolsPass()); - - // Propagate constants at call sites into the functions they call. - addPass(Passes, createIPConstantPropagationPass()); - // 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 @@ -151,19 +162,22 @@ void Optimize(Module* M) { // 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, to cleanup the code. + // Run a few AA driven optimizations here and now, to cleanup the code. addPass(Passes, createGlobalsModRefPass()); // IP alias analysis + addPass(Passes, createLICMPass()); // Hoist loop invariants - addPass(Passes, createLoadValueNumberingPass()); // GVN for load instrs - addPass(Passes, createGCSEPass()); // Remove common subexprs + 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. + // Delete basic blocks, which optimization passes may have killed... addPass(Passes, createCFGSimplificationPass()); @@ -171,16 +185,19 @@ void Optimize(Module* M) { addPass(Passes, createGlobalDCEPass()); } + // 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 + // that we are supporting; they alias -strip-all and -strip-debug. + if (Strip || StripDebug) + addPass(Passes, createStripSymbolsPass(StripDebug && !Strip)); + // Create a new optimization pass for each one specified on the command line std::auto_ptr target; for (unsigned i = 0; i < OptimizationList.size(); ++i) { const PassInfo *Opt = OptimizationList[i]; if (Opt->getNormalCtor()) addPass(Passes, Opt->getNormalCtor()()); - else if (Opt->getTargetCtor()) { - assert(target.get() && "Could not allocate target machine!"); - addPass(Passes, Opt->getTargetCtor()(*target.get())); - } else + else std::cerr << "llvm-ld: cannot create pass: " << Opt->getPassName() << "\n"; } @@ -190,11 +207,13 @@ void Optimize(Module* M) { if (!DisableOptimizations) { addPass(Passes, createInstructionCombiningPass()); addPass(Passes, createCFGSimplificationPass()); + addPass(Passes, createDeadCodeEliminationPass()); addPass(Passes, createGlobalDCEPass()); } // Make sure everything is still good. - Passes.add(createVerifierPass()); + if (!DontVerify) + Passes.add(createVerifierPass()); // Run our queue of passes all at once now, efficiently. Passes.run(*M);