Large scale changes to implement new command line argument facility

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2001-07-23 02:35:57 +00:00
parent a28504313d
commit 8f367bd3c0
32 changed files with 669 additions and 1364 deletions

View File

@@ -29,70 +29,81 @@
using namespace opt;
struct {
const string ArgName, Name;
bool (*OptPtr)(Module *C);
} OptTable[] = {
{ "-dce" , "Dead Code Elimination", DoDeadCodeElimination },
{ "-constprop" , "Constant Propogation", DoConstantPropogation },
{ "-inline" , "Method Inlining", DoMethodInlining },
{ "-strip" , "Strip Symbols", DoSymbolStripping },
{ "-mstrip" , "Strip Module Symbols", DoFullSymbolStripping },
{ "-indvars" , "Simplify Induction Vars",DoInductionVariableCannonicalize },
{ "-sccp" , "Sparse Conditional Constant Prop", DoSCCP },
{ "-cpm" , "Constant Pool Merging", DoConstantPoolMerging },
{ "-adce" , "Agressive DCE", DoADCE },
{ "-raise" , "Raise to Higher Level", DoRaiseRepresentation },
enum Opts {
// Basic optimizations
dce, constprop, inlining, strip, mstrip,
// More powerful optimizations
indvars, sccp, cpm, adce, raise,
};
struct {
enum Opts OptID;
bool (*OptPtr)(Module *C);
} OptTable[] = {
{ dce , DoDeadCodeElimination },
{ constprop, DoConstantPropogation },
{ inlining , DoMethodInlining },
{ strip , DoSymbolStripping },
{ mstrip , DoFullSymbolStripping },
{ indvars , DoInductionVariableCannonicalize },
{ sccp , DoSCCP },
{ cpm , DoConstantPoolMerging },
{ adce , DoADCE },
{ raise , DoRaiseRepresentation },
};
cl::String InputFilename ("", "Load <arg> file to optimize", 0, "-");
cl::String OutputFilename("o", "Override output filename", 0, "");
cl::Flag Force ("f", "Overwrite output files", 0, false);
cl::Flag Quiet ("q", "Don't print modifying pass names", 0, false);
cl::EnumList<enum Opts> OptimizationList(cl::NoFlags,
clEnumVal(dce , "Dead Code Elimination"),
clEnumVal(constprop, "Simple Constant Propogation"),
clEnumValN(inlining , "inline", "Method Inlining"),
clEnumVal(strip , "Strip Symbols"),
clEnumVal(mstrip , "Strip Module Symbols"),
clEnumVal(indvars , "Simplify Induction Variables"),
clEnumVal(sccp , "Sparse Conditional Constant Propogation"),
clEnumVal(cpm , "Constant Pool Merging"),
clEnumVal(adce , "Agressive DCE"),
clEnumVal(raise , "Raise to Higher Level"),
0);
int main(int argc, char **argv) {
ToolCommandLine Opts(argc, argv, false);
bool Quiet = false;
for (int i = 1; i < argc; i++) {
if (string(argv[i]) == string("--help")) {
cerr << argv[0] << " usage:\n"
<< " " << argv[0] << " --help - Print this usage information\n";
for (unsigned j = 0; j < sizeof(OptTable)/sizeof(OptTable[0]); ++j) {
cerr << "\t" << OptTable[j].ArgName << "\t - Enable "
<< OptTable[j].Name << endl;
}
return 1;
} else if (string(argv[i]) == string("-q")) {
Quiet = true; argv[i] = 0;
}
}
ostream *Out = &cout; // Default to printing to stdout...
Module *C = ParseBytecodeFile(Opts.getInputFilename());
cl::ParseCommandLineOptions(argc, argv,
" llvm .bc -> .bc modular optimizer\n");
Module *C = ParseBytecodeFile(InputFilename.getValue());
if (C == 0) {
cerr << "bytecode didn't read correctly.\n";
return 1;
}
for (unsigned i = 0; i < OptimizationList.size(); ++i) {
enum Opts Opt = OptimizationList[i];
for (int i = 1; i < argc; i++) {
if (argv[i] == 0) continue;
unsigned j;
for (j = 0; j < sizeof(OptTable)/sizeof(OptTable[0]); j++) {
if (string(argv[i]) == OptTable[j].ArgName) {
for (j = 0; j < sizeof(OptTable)/sizeof(OptTable[0]); ++j) {
if (Opt == OptTable[j].OptID) {
if (OptTable[j].OptPtr(C) && !Quiet)
cerr << OptTable[j].Name << " pass made modifications!\n";
cerr << OptimizationList.getArgName(Opt)
<< " pass made modifications!\n";
break;
}
}
if (j == sizeof(OptTable)/sizeof(OptTable[0]))
cerr << "'" << argv[i] << "' argument unrecognized: ignored\n";
cerr << "Optimization tables inconsistent!!\n";
}
if (Opts.getOutputFilename() != "-") {
Out = new ofstream(Opts.getOutputFilename().c_str(),
(Opts.getForce() ? 0 : ios::noreplace)|ios::out);
ostream *Out = &cout; // Default to printing to stdout...
if (OutputFilename.getValue() != "") {
Out = new ofstream(OutputFilename.getValue().c_str(),
(Force.getValue() ? 0 : ios::noreplace)|ios::out);
if (!Out->good()) {
cerr << "Error opening " << Opts.getOutputFilename()
<< "!\n";
cerr << "Error opening " << OutputFilename.getValue() << "!\n";
delete C;
return 1;
}