#include "llvm/Bytecode/WriteBytecodePass.h"
#include "llvm/Assembly/PrintModulePass.h"
#include "llvm/Analysis/Verifier.h"
-#include "llvm/Transforms/UnifyMethodExitNodes.h"
#include "llvm/Transforms/ConstantMerge.h"
#include "llvm/Transforms/CleanupGCCOutput.h"
#include "llvm/Transforms/LevelChange.h"
-#include "llvm/Transforms/MethodInlining.h"
-#include "llvm/Transforms/SymbolStripping.h"
+#include "llvm/Transforms/FunctionInlining.h"
#include "llvm/Transforms/ChangeAllocations.h"
#include "llvm/Transforms/IPO/SimpleStructMutation.h"
+#include "llvm/Transforms/IPO/Internalize.h"
#include "llvm/Transforms/IPO/GlobalDCE.h"
-#include "llvm/Transforms/Scalar/DCE.h"
+#include "llvm/Transforms/IPO/PoolAllocate.h"
#include "llvm/Transforms/Scalar/ConstantProp.h"
+#include "llvm/Transforms/Scalar/DCE.h"
+#include "llvm/Transforms/Scalar/DecomposeMultiDimRefs.h"
+#include "llvm/Transforms/Scalar/GCSE.h"
#include "llvm/Transforms/Scalar/IndVarSimplify.h"
#include "llvm/Transforms/Scalar/InstructionCombining.h"
#include "llvm/Transforms/Scalar/PromoteMemoryToRegister.h"
-#include "llvm/Transforms/Scalar/DecomposeMultiDimRefs.h"
+#include "llvm/Transforms/Scalar/SymbolStripping.h"
+#include "llvm/Transforms/Scalar/UnifyFunctionExitNodes.h"
#include "llvm/Transforms/Instrumentation/TraceValues.h"
#include "llvm/Transforms/Instrumentation/ProfilePaths.h"
#include "Support/CommandLine.h"
+#include "Support/Signals.h"
#include <fstream>
#include <memory>
// Opts enum - All of the transformations we can do...
enum Opts {
// Basic optimizations
- dce, die, constprop, inlining, constmerge, strip, mstrip, mergereturn,
+ dce, die, constprop, gcse, inlining, constmerge, strip, mstrip, mergereturn,
// Miscellaneous Transformations
- raiseallocs, cleangcc, lowerrefs,
+ raiseallocs, funcresolve, cleangcc, lowerrefs,
// Printing and verifying...
- print, verify,
+ print, printm, verify,
// More powerful optimizations
indvars, instcombine, sccp, adce, raise, mem2reg,
trace, tracem, paths,
// Interprocedural optimizations...
- globaldce, swapstructs, sortstructs,
+ internalize, globaldce, swapstructs, sortstructs, poolalloc,
};
-static Pass *createPrintMethodPass() {
- return new PrintMethodPass("Current Method: \n", &cerr);
+static Pass *createPrintFunctionPass() {
+ return new PrintFunctionPass("Current Function: \n", &cerr);
+}
+
+static Pass *createPrintModulePass() {
+ return new PrintModulePass(&cerr);
}
// OptTable - Correlate enum Opts to Pass constructors...
enum Opts OptID;
Pass * (*PassCtor)();
} OptTable[] = {
- { dce , createDeadCodeEliminationPass },
- { die , createDeadInstEliminationPass },
- { constprop , createConstantPropogationPass },
- { inlining , createMethodInliningPass },
- { constmerge , createConstantMergePass },
- { strip , createSymbolStrippingPass },
- { mstrip , createFullSymbolStrippingPass },
- { mergereturn, createUnifyMethodExitNodesPass },
-
- { indvars , createIndVarSimplifyPass },
- { instcombine, createInstructionCombiningPass },
- { sccp , createSCCPPass },
- { adce , createAgressiveDCEPass },
+ { dce , createDeadCodeEliminationPass },
+ { die , createDeadInstEliminationPass },
+ { constprop , createConstantPropogationPass },
+ { gcse , createGCSEPass },
+ { inlining , createFunctionInliningPass },
+ { constmerge , createConstantMergePass },
+ { strip , createSymbolStrippingPass },
+ { mstrip , createFullSymbolStrippingPass },
+ { mergereturn, createUnifyFunctionExitNodesPass },
+
+ { indvars , createIndVarSimplifyPass },
+ { instcombine, createInstructionCombiningPass },
+ { sccp , createSCCPPass },
+ { adce , createAgressiveDCEPass },
{ raise , createRaisePointerReferencesPass },
- { mem2reg , newPromoteMemoryToRegister },
+ { mem2reg , createPromoteMemoryToRegister },
+ { lowerrefs, createDecomposeMultiDimRefsPass },
{ trace , createTraceValuesPassForBasicBlocks },
- { tracem , createTraceValuesPassForMethod },
- { paths , createProfilePathsPass },
+ { tracem , createTraceValuesPassForFunction },
+ { paths , createProfilePathsPass },
+
+ { print , createPrintFunctionPass },
+ { printm , createPrintModulePass },
+ { verify , createVerifierPass },
- { print , createPrintMethodPass },
- { verify , createVerifierPass },
+ { raiseallocs, createRaiseAllocationsPass },
+ { cleangcc , createCleanupGCCOutputPass },
+ { funcresolve, createFunctionResolvingPass },
- { raiseallocs, createRaiseAllocationsPass },
- { cleangcc , createCleanupGCCOutputPass },
- { globaldce , createGlobalDCEPass },
+ { internalize, createInternalizePass },
+ { globaldce , createGlobalDCEPass },
{ swapstructs, createSwapElementsPass },
{ sortstructs, createSortElementsPass },
- { lowerrefs, createDecomposeMultiDimRefsPass }
+ { poolalloc , createPoolAllocatePass },
};
+
// Command line option handling code...
//
cl::String InputFilename ("", "Load <arg> file to optimize", cl::NoFlags, "-");
clEnumVal(dce , "Dead Code Elimination"),
clEnumVal(die , "Dead Instruction Elimination"),
clEnumVal(constprop , "Simple constant propogation"),
- clEnumValN(inlining , "inline", "Method integration"),
+ clEnumVal(gcse , "Global Common Subexpression Elimination"),
+ clEnumValN(inlining , "inline", "Function integration"),
clEnumVal(constmerge , "Merge identical global constants"),
clEnumVal(strip , "Strip symbols"),
clEnumVal(mstrip , "Strip module symbols"),
- clEnumVal(mergereturn, "Unify method exit nodes"),
+ clEnumVal(mergereturn, "Unify function exit nodes"),
clEnumVal(indvars , "Simplify Induction Variables"),
clEnumVal(instcombine, "Combine redundant instructions"),
clEnumVal(adce , "Agressive DCE"),
clEnumVal(mem2reg , "Promote alloca locations to registers"),
+ clEnumVal(internalize, "Mark all fn's internal except for main"),
clEnumVal(globaldce , "Remove unreachable globals"),
clEnumVal(swapstructs, "Swap structure types around"),
clEnumVal(sortstructs, "Sort structure elements"),
+ clEnumVal(poolalloc , "Pool allocate disjoint datastructures"),
clEnumVal(raiseallocs, "Raise allocations from calls to instructions"),
clEnumVal(cleangcc , "Cleanup GCC Output"),
+ clEnumVal(funcresolve, "Resolve calls to foo(...) to foo(<concrete types>)"),
clEnumVal(raise , "Raise to Higher Level"),
- clEnumVal(trace , "Insert BB & Method trace code"),
- clEnumVal(tracem , "Insert Method trace code only"),
+ clEnumVal(trace , "Insert BB and Function trace code"),
+ clEnumVal(tracem , "Insert Function trace code only"),
clEnumVal(paths , "Insert path profiling instrumentation"),
- clEnumVal(print , "Print working method to stderr"),
+ clEnumVal(print , "Print working function to stderr"),
+ clEnumVal(printm , "Print working module to stderr"),
clEnumVal(verify , "Verify module is well formed"),
clEnumVal(lowerrefs , "Decompose multi-dimensional structure/array refs to use one index per instruction"),
0);
cerr << "Error opening " << OutputFilename << "!\n";
return 1;
}
+
+ // Make sure that the Output file gets unlink'd from the disk if we get a
+ // SIGINT
+ RemoveFileOnSignal(OutputFilename);
}
// Create a PassManager to hold and optimize the collection of passes we are