Add calls to NormalizeMethod() and to ScheduleInstructionsWithSSA().
[oota-llvm.git] / tools / llc / llc.cpp
1 // $Id$
2 //***************************************************************************
3 // File:
4 //      llc.cpp
5 // 
6 // Purpose:
7 //      Driver for llc compiler.
8 // 
9 // History:
10 //      7/15/01  -  Vikram Adve  -  Created
11 // 
12 //**************************************************************************/
13
14 #include "llvm/Module.h"
15 #include "llvm/Method.h"
16 #include "llvm/Bytecode/Reader.h"
17 #include "llvm/Optimizations/Normalize.h"
18 #include "llvm/CodeGen/InstrSelection.h"
19 #include "llvm/CodeGen/InstrScheduling.h"
20 #include "llvm/CodeGen/Sparc.h"
21 #include "llvm/Support/CommandLine.h"
22
23 cl::String InputFilename ("", "Input filename", cl::NoFlags, "-");
24 cl::String OutputFilename("o", "Output filename", cl::NoFlags, "");
25
26
27 void
28 NormalizeMethod(Method* method)
29 {
30   NormalizePhiConstantArgs(method);
31 }
32
33
34 static bool
35 CompileModule(Module *M, TargetMachine &target)
36 {
37   bool failed = false;
38   
39   for (Module::const_iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI)
40     {
41       Method* method = *MI;
42       
43       NormalizeMethod(method);
44       
45       failed = SelectInstructionsForMethod(method, target);
46       if (failed)
47         {
48           cerr << "Instruction selection failed for method "
49                << method->getName() << "\n\n";
50           break;
51         }
52
53       failed = ScheduleInstructionsWithSSA(method, target);
54       if (failed)
55         {
56           cerr << "Instruction scheduling before allocation failed for method "
57                << method->getName() << "\n\n";
58           break;
59         }
60     }
61   
62   return failed;
63 }
64
65
66
67 //---------------------------------------------------------------------------
68 // Function main()
69 // 
70 // Entry point for the llc compiler.
71 //---------------------------------------------------------------------------
72
73 int
74 main(int argc, char** argv)
75 {
76   cl::ParseCommandLineOptions(argc, argv, " llvm system compiler\n");
77   UltraSparc target;
78   
79   Module *module = ParseBytecodeFile(InputFilename);
80   if (module == 0) {
81     cerr << "bytecode didn't read correctly.\n";
82     return 1;
83   }
84
85   if (CompileModule(module, target)) {
86     cerr << "Error compiling " << InputFilename << "!\n";
87     delete module;
88     return 1;
89   }
90   
91   // Clean up and exit
92   delete module;
93   return 0;
94 }