Change swapstructs itf

Add nasty hack to be removed later


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1356 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2001-11-26 18:18:53 +00:00
parent 782b939db1
commit ee6826b5e3

View File

@ -36,6 +36,7 @@ struct {
enum Opts OptID; enum Opts OptID;
Pass *ThePass; Pass *ThePass;
} OptTable[] = { } OptTable[] = {
{ swapstructs, 0 },
{ dce , new opt::DeadCodeElimination() }, { dce , new opt::DeadCodeElimination() },
{ constprop, new opt::ConstantPropogation() }, { constprop, new opt::ConstantPropogation() },
{ inlining , new opt::MethodInlining() }, { inlining , new opt::MethodInlining() },
@ -50,7 +51,6 @@ struct {
{ tracem , new InsertTraceCode(false, true) }, { tracem , new InsertTraceCode(false, true) },
{ print , new PrintModulePass("Current Method: \n",&cerr) }, { print , new PrintModulePass("Current Method: \n",&cerr) },
{ cleangcc , new CleanupGCCOutput() }, { cleangcc , new CleanupGCCOutput() },
{ swapstructs, new SwapStructContents() },
}; };
cl::String InputFilename ("", "Load <arg> file to optimize", cl::NoFlags, "-"); cl::String InputFilename ("", "Load <arg> file to optimize", cl::NoFlags, "-");
@ -82,19 +82,23 @@ int main(int argc, char **argv) {
cl::ParseCommandLineOptions(argc, argv, cl::ParseCommandLineOptions(argc, argv,
" llvm .bc -> .bc modular optimizer\n"); " llvm .bc -> .bc modular optimizer\n");
Module *C = ParseBytecodeFile(InputFilename); // FIXME: Use smartptr
if (C == 0) { Module *M = ParseBytecodeFile(InputFilename);
if (M == 0) {
cerr << "bytecode didn't read correctly.\n"; cerr << "bytecode didn't read correctly.\n";
return 1; return 1;
} }
// FIXME: Absurdly nasty hack.
OptTable[0].ThePass = new PrebuiltStructMutation(M, PrebuiltStructMutation::SortElements);
for (unsigned i = 0; i < OptimizationList.size(); ++i) { for (unsigned i = 0; i < OptimizationList.size(); ++i) {
enum Opts Opt = OptimizationList[i]; enum Opts Opt = OptimizationList[i];
unsigned j; unsigned j;
for (j = 0; j < sizeof(OptTable)/sizeof(OptTable[0]); ++j) { for (j = 0; j < sizeof(OptTable)/sizeof(OptTable[0]); ++j) {
if (Opt == OptTable[j].OptID) { if (Opt == OptTable[j].OptID) {
if (OptTable[j].ThePass->run(C) && !Quiet) if (OptTable[j].ThePass->run(M) && !Quiet)
cerr << OptimizationList.getArgName(Opt) cerr << OptimizationList.getArgName(Opt)
<< " pass made modifications!\n"; << " pass made modifications!\n";
break; break;
@ -111,14 +115,14 @@ int main(int argc, char **argv) {
(Force ? 0 : ios::noreplace)|ios::out); (Force ? 0 : ios::noreplace)|ios::out);
if (!Out->good()) { if (!Out->good()) {
cerr << "Error opening " << OutputFilename << "!\n"; cerr << "Error opening " << OutputFilename << "!\n";
delete C; delete M;
return 1; return 1;
} }
} }
// Okay, we're done now... write out result... // Okay, we're done now... write out result...
WriteBytecodeToFile(C, *Out); WriteBytecodeToFile(M, *Out);
delete C; delete M;
if (Out != &cout) delete Out; if (Out != &cout) delete Out;
return 0; return 0;