diff options
author | Chris Lattner <sabre@nondot.org> | 2002-06-25 15:57:43 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2002-06-25 15:57:43 +0000 |
commit | 624c3e028b1b02da6d23ca0435ea3598dbdd349e (patch) | |
tree | 75e201d6b25a9c947e2fb717d7fe84d8ede3b6b2 /tools/gccas/gccas.cpp | |
parent | bb03efd7e5d86d1786ea1de7accf65e4238f1c0f (diff) | |
download | external_llvm-624c3e028b1b02da6d23ca0435ea3598dbdd349e.zip external_llvm-624c3e028b1b02da6d23ca0435ea3598dbdd349e.tar.gz external_llvm-624c3e028b1b02da6d23ca0435ea3598dbdd349e.tar.bz2 |
Simplify the code that adds passes so compilation can stop after any step
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2775 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/gccas/gccas.cpp')
-rw-r--r-- | tools/gccas/gccas.cpp | 95 |
1 files changed, 66 insertions, 29 deletions
diff --git a/tools/gccas/gccas.cpp b/tools/gccas/gccas.cpp index 3ddef9ad..d7ce20b 100644 --- a/tools/gccas/gccas.cpp +++ b/tools/gccas/gccas.cpp @@ -15,17 +15,69 @@ #include "llvm/Transforms/ConstantMerge.h" #include "llvm/Transforms/ChangeAllocations.h" #include "llvm/Transforms/Scalar.h" +#include "llvm/Analysis/Verifier.h" #include "llvm/Bytecode/WriteBytecodePass.h" #include "Support/CommandLine.h" #include "Support/Signals.h" #include <memory> #include <fstream> -cl::String InputFilename ("", "Parse <arg> file, compile to bytecode", - cl::Required, ""); -cl::String OutputFilename("o", "Override output filename", cl::NoFlags, ""); -cl::Flag StopAtLevelRaise("stopraise", "Stop optimization before level raise", - cl::Hidden); +static cl::String InputFilename ("", "Parse <arg> file, compile to bytecode", + cl::Required, ""); +static cl::String OutputFilename ("o", "Override output filename"); +static cl::Int RunNPasses ("stopAfterNPasses", "Only run the first N " + "passes of gccas", cl::Hidden); +static cl::Flag StopAtLevelRaise("stopraise", "Stop optimization before " + "level raise", cl::Hidden); +static cl::Flag Verify ("verify", "Verify each pass result"); + +static inline void addPass(PassManager &PM, Pass *P) { + static int NumPassesCreated = 0; + + // If we haven't already created the number of passes that was requested... + if (RunNPasses == 0 || RunNPasses > NumPassesCreated) { + // Add the pass to the pass manager... + PM.add(P); + + // If we are verifying all of the intermediate steps, add the verifier... + if (Verify) PM.add(createVerifierPass()); + + // Keep track of how many passes we made for -stopAfterNPasses + ++NumPassesCreated; + } +} + + +void AddConfiguredTransformationPasses(PassManager &PM) { + if (Verify) PM.add(createVerifierPass()); + + addPass(PM, createFunctionResolvingPass()); // Resolve (...) functions + addPass(PM, createConstantMergePass()); // Merge dup global constants + addPass(PM, createDeadInstEliminationPass()); // Remove Dead code/vars + addPass(PM, createRaiseAllocationsPass()); // call %malloc -> malloc inst + addPass(PM, createCleanupGCCOutputPass()); // Fix gccisms + addPass(PM, createIndVarSimplifyPass()); // Simplify indvars + + // Level raise is eternally buggy/in need of enhancements. Allow + // transformation to stop right before it runs. + if (StopAtLevelRaise) return; + + addPass(PM, createRaisePointerReferencesPass());// Eliminate casts + addPass(PM, createPromoteMemoryToRegister()); // Promote alloca's to regs + addPass(PM, createReassociatePass()); // Reassociate expressions + addPass(PM, createInstructionCombiningPass()); // Combine silly seq's + addPass(PM, createDeadInstEliminationPass()); // Kill InstCombine remnants + addPass(PM, createLICMPass()); // Hoist loop invariants + addPass(PM, createGCSEPass()); // Remove common subexprs + addPass(PM, createSCCPPass()); // Constant prop with SCCP + + // Run instcombine after redundancy elimination to exploit opportunities + // opened up by them. + addPass(PM, createInstructionCombiningPass()); + addPass(PM, createAggressiveDCEPass()); // SSA based 'Agressive DCE' + addPass(PM, createCFGSimplificationPass()); // Merge & remove BBs +} + int main(int argc, char **argv) { cl::ParseCommandLineOptions(argc, argv, " llvm .s -> .o assembler for GCC\n"); @@ -68,31 +120,16 @@ int main(int argc, char **argv) { // a little bit. Do this now. // PassManager Passes; - Passes.add(createFunctionResolvingPass()); // Resolve (...) functions - Passes.add(createConstantMergePass()); // Merge dup global constants - Passes.add(createDeadInstEliminationPass()); // Remove Dead code/vars - Passes.add(createRaiseAllocationsPass()); // call %malloc -> malloc inst - Passes.add(createCleanupGCCOutputPass()); // Fix gccisms - Passes.add(createIndVarSimplifyPass()); // Simplify indvars - if (!StopAtLevelRaise) { - Passes.add(createRaisePointerReferencesPass()); // Eliminate casts - Passes.add(createPromoteMemoryToRegister()); // Promote alloca's to regs - Passes.add(createReassociatePass()); // Reassociate expressions - Passes.add(createInstructionCombiningPass()); // Combine silly seq's - Passes.add(createDeadInstEliminationPass()); // Kill InstCombine remnants - Passes.add(createLICMPass()); // Hoist loop invariants - Passes.add(createGCSEPass()); // Remove common subexprs - Passes.add(createSCCPPass()); // Constant prop with SCCP - - // Run instcombine after redundancy elimination to exploit opportunities - // opened up by them. - Passes.add(createInstructionCombiningPass()); - Passes.add(createAggressiveDCEPass()); // SSA based 'Agressive DCE' - Passes.add(createCFGSimplificationPass()); // Merge & remove BBs - } - Passes.add(new WriteBytecodePass(&Out)); // Write bytecode to file... + + // Add all of the transformation passes to the pass manager to do the cleanup + // and optimization of the GCC output. + // + AddConfiguredTransformationPasses(Passes); + + // Write bytecode to file... + Passes.add(new WriteBytecodePass(&Out)); // Run our queue of passes all at once now, efficiently. - Passes.run(M.get()); + Passes.run(*M.get()); return 0; } |