diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/llvm-config/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tools/llvm-ld/Optimize.cpp | 69 | ||||
-rw-r--r-- | tools/lto/LTOCodeGenerator.cpp | 59 | ||||
-rw-r--r-- | tools/opt/opt.cpp | 147 |
4 files changed, 30 insertions, 246 deletions
diff --git a/tools/llvm-config/CMakeLists.txt b/tools/llvm-config/CMakeLists.txt index 29287ab..2cfd6bb 100644 --- a/tools/llvm-config/CMakeLists.txt +++ b/tools/llvm-config/CMakeLists.txt @@ -87,7 +87,6 @@ add_custom_command(OUTPUT ${FINAL_LIBDEPS} DEPENDS ${LIBDEPS} COMMENT "Checking for cyclic dependencies between LLVM libraries.") -string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) set(C_FLGS "${CMAKE_C_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}") set(CXX_FLGS "${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}") set(CPP_FLGS "${CMAKE_CPP_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}") diff --git a/tools/llvm-ld/Optimize.cpp b/tools/llvm-ld/Optimize.cpp index f788f06..a4ca951 100644 --- a/tools/llvm-ld/Optimize.cpp +++ b/tools/llvm-ld/Optimize.cpp @@ -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 diff --git a/tools/lto/LTOCodeGenerator.cpp b/tools/lto/LTOCodeGenerator.cpp index d3a3f7f..03a11b6 100644 --- a/tools/lto/LTOCodeGenerator.cpp +++ b/tools/lto/LTOCodeGenerator.cpp @@ -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()); diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp index 680353a..0c36e21 100644 --- a/tools/opt/opt.cpp +++ b/tools/opt/opt.cpp @@ -28,6 +28,7 @@ #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/PluginLoader.h" +#include "llvm/Support/StandardPasses.h" #include "llvm/Support/Streams.h" #include "llvm/Support/SystemUtils.h" #include "llvm/Support/raw_ostream.h" @@ -266,79 +267,16 @@ inline void addPass(PassManager &PM, Pass *P) { /// OptLevel - Optimization Level void AddOptimizationPasses(PassManager &MPM, FunctionPassManager &FPM, unsigned OptLevel) { - - if (OptLevel == 0) - return; - - FPM.add(createCFGSimplificationPass()); - if (OptLevel == 1) - FPM.add(createPromoteMemoryToRegisterPass()); - else - FPM.add(createScalarReplAggregatesPass()); - FPM.add(createInstructionCombiningPass()); - - if (UnitAtATime) - MPM.add(createRaiseAllocationsPass()); // call %malloc -> malloc inst - MPM.add(createCFGSimplificationPass()); // Clean up disgusting code - MPM.add(createPromoteMemoryToRegisterPass()); // Kill useless allocas - if (UnitAtATime) { - MPM.add(createGlobalOptimizerPass()); // OptLevel out global vars - MPM.add(createGlobalDCEPass()); // Remove unused fns and globs - MPM.add(createIPConstantPropagationPass()); // IP Constant Propagation - MPM.add(createDeadArgEliminationPass()); // Dead argument elimination - } - MPM.add(createInstructionCombiningPass()); // Clean up after IPCP & DAE - MPM.add(createCFGSimplificationPass()); // Clean up after IPCP & DAE - if (UnitAtATime) { - MPM.add(createPruneEHPass()); // Remove dead EH info - MPM.add(createFunctionAttrsPass()); // Deduce function attrs - } - if (OptLevel > 1) - MPM.add(createFunctionInliningPass()); // Inline small functions - if (OptLevel > 2) - MPM.add(createArgumentPromotionPass()); // Scalarize uninlined fn args - if (!DisableSimplifyLibCalls) - MPM.add(createSimplifyLibCallsPass()); // Library Call Optimizations - MPM.add(createInstructionCombiningPass()); // Cleanup for scalarrepl. - MPM.add(createJumpThreadingPass()); // Thread jumps. - MPM.add(createCFGSimplificationPass()); // Merge & remove BBs - MPM.add(createScalarReplAggregatesPass()); // Break up aggregate allocas - MPM.add(createInstructionCombiningPass()); // Combine silly seq's - MPM.add(createCondPropagationPass()); // Propagate conditionals - 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()); - MPM.add(createLoopIndexSplitPass()); // Split loop index - MPM.add(createInstructionCombiningPass()); - MPM.add(createIndVarSimplifyPass()); // Canonicalize indvars - MPM.add(createLoopDeletionPass()); // Delete dead loops - if (OptLevel > 1) - MPM.add(createLoopUnrollPass()); // Unroll small loops - MPM.add(createInstructionCombiningPass()); // Clean up after the unroller - 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(createCondPropagationPass()); // Propagate conditionals - MPM.add(createDeadStoreEliminationPass()); // Delete dead stores - MPM.add(createAggressiveDCEPass()); // Delete dead instructions - MPM.add(createCFGSimplificationPass()); // Merge & remove BBs - - if (UnitAtATime) { - MPM.add(createStripDeadPrototypesPass()); // Get rid of dead prototypes - MPM.add(createDeadTypeEliminationPass()); // Eliminate dead types - } - - if (OptLevel > 1 && UnitAtATime) - MPM.add(createConstantMergePass()); // Merge dup global constants - - return; + createStandardFunctionPasses(&FPM, OptLevel); + + llvm::Pass *InliningPass = OptLevel > 1 ? createFunctionInliningPass() : 0; + createStandardModulePasses(&MPM, OptLevel, + /*OptimizeSize=*/ false, + UnitAtATime, + /*UnrollLoops=*/ OptLevel > 1, + !DisableSimplifyLibCalls, + /*HaveExceptions=*/ true, + InliningPass); } void AddStandardCompilePasses(PassManager &PM) { @@ -352,59 +290,16 @@ void AddStandardCompilePasses(PassManager &PM) { if (DisableOptimizations) return; - addPass(PM, createRaiseAllocationsPass()); // call %malloc -> malloc inst - addPass(PM, createCFGSimplificationPass()); // Clean up disgusting code - addPass(PM, createPromoteMemoryToRegisterPass());// Kill useless allocas - addPass(PM, createGlobalOptimizerPass()); // Optimize out global vars - addPass(PM, createGlobalDCEPass()); // Remove unused fns and globs - addPass(PM, createIPConstantPropagationPass());// IP Constant Propagation - addPass(PM, createDeadArgEliminationPass()); // Dead argument elimination - addPass(PM, createInstructionCombiningPass()); // Clean up after IPCP & DAE - addPass(PM, createCFGSimplificationPass()); // Clean up after IPCP & DAE - - addPass(PM, createPruneEHPass()); // Remove dead EH info - addPass(PM, createFunctionAttrsPass()); // Deduce function attrs - - if (!DisableInline) - addPass(PM, createFunctionInliningPass()); // Inline small functions - addPass(PM, createArgumentPromotionPass()); // Scalarize uninlined fn args - - addPass(PM, createSimplifyLibCallsPass()); // Library Call Optimizations - addPass(PM, createInstructionCombiningPass()); // Cleanup for scalarrepl. - addPass(PM, createJumpThreadingPass()); // Thread jumps. - addPass(PM, createCFGSimplificationPass()); // Merge & remove BBs - addPass(PM, createScalarReplAggregatesPass()); // Break up aggregate allocas - addPass(PM, createInstructionCombiningPass()); // Combine silly seq's - addPass(PM, createCondPropagationPass()); // Propagate conditionals - - addPass(PM, createTailCallEliminationPass()); // Eliminate tail calls - addPass(PM, createCFGSimplificationPass()); // Merge & remove BBs - addPass(PM, createReassociatePass()); // Reassociate expressions - addPass(PM, createLoopRotatePass()); - addPass(PM, createLICMPass()); // Hoist loop invariants - addPass(PM, createLoopUnswitchPass()); // Unswitch loops. - addPass(PM, createLoopIndexSplitPass()); // Index split loops. - // FIXME : Removing instcombine causes nestedloop regression. - addPass(PM, createInstructionCombiningPass()); - addPass(PM, createIndVarSimplifyPass()); // Canonicalize indvars - addPass(PM, createLoopDeletionPass()); // Delete dead loops - addPass(PM, createLoopUnrollPass()); // Unroll small loops - addPass(PM, createInstructionCombiningPass()); // Clean up after the unroller - addPass(PM, createGVNPass()); // Remove redundancies - addPass(PM, createMemCpyOptPass()); // Remove memcpy / form memset - addPass(PM, createSCCPPass()); // Constant prop with SCCP - - // Run instcombine after redundancy elimination to exploit opportunities - // opened up by them. - addPass(PM, createInstructionCombiningPass()); - addPass(PM, createCondPropagationPass()); // Propagate conditionals - - addPass(PM, createDeadStoreEliminationPass()); // Delete dead stores - addPass(PM, createAggressiveDCEPass()); // Delete dead instructions - addPass(PM, createCFGSimplificationPass()); // Merge & remove BBs - addPass(PM, createStripDeadPrototypesPass()); // Get rid of dead prototypes - addPass(PM, createDeadTypeEliminationPass()); // Eliminate dead types - addPass(PM, createConstantMergePass()); // Merge dup global constants + llvm::Pass *InliningPass = !DisableInline ? createFunctionInliningPass() : 0; + + // -std-compile-opts adds the same module passes as -O3. + createStandardModulePasses(&PM, 3, + /*OptimizeSize=*/ false, + /*UnitAtATime=*/ true, + /*UnrollLoops=*/ true, + /*SimplifyLibCalls=*/ true, + /*HaveExceptions=*/ true, + InliningPass); } } // anonymous namespace |