forked from OSchip/llvm-project
Simplify the code that adds passes so compilation can stop after any step
llvm-svn: 2775
This commit is contained in:
parent
f8b0668cc1
commit
5aa3a0779e
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue