9258bd431327922eb82c9db924c433fb64440f1b
[oota-llvm.git] / tools / llc / llc.cpp
1 //===------------------------------------------------------------------------===
2 // LLVM 'LLC' UTILITY 
3 //
4 // This is the llc compiler driver.
5 //
6 //===------------------------------------------------------------------------===
7
8 #include "llvm/Bytecode/Reader.h"
9 #include "llvm/Optimizations/Normalize.h"
10 #include "llvm/CodeGen/InstrSelection.h"
11 #include "llvm/CodeGen/InstrScheduling.h"
12 #include "llvm/CodeGen/Sparc.h"
13 #include "llvm/Support/CommandLine.h"
14 #include "llvm/Module.h"
15 #include "llvm/Method.h"
16
17 cl::String InputFilename ("", "Input filename", cl::NoFlags, "-");
18 cl::String OutputFilename("o", "Output filename", cl::NoFlags, "");
19
20 static void NormalizeMethod(Method* method) {
21   NormalizePhiConstantArgs(method);
22 }
23
24
25 static bool CompileModule(Module *M, TargetMachine &Target) {
26   for (Module::const_iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI) {
27     Method *Meth = *MI;
28       
29     NormalizeMethod(Meth);
30       
31     if (SelectInstructionsForMethod(Meth, Target)) {
32       cerr << "Instruction selection failed for method " << Meth->getName()
33            << "\n\n";
34       return true;
35     }
36
37     if (ScheduleInstructionsWithSSA(Meth, Target)) {
38       cerr << "Instruction scheduling before allocation failed for method "
39            << Meth->getName() << "\n\n";
40       return true;
41     }
42   }
43   
44   return false;
45 }
46
47
48
49 //---------------------------------------------------------------------------
50 // Function main()
51 // 
52 // Entry point for the llc compiler.
53 //---------------------------------------------------------------------------
54
55 int main(int argc, char** argv) {
56   cl::ParseCommandLineOptions(argc, argv, " llvm system compiler\n");
57   UltraSparc Target;
58   
59   Module *module = ParseBytecodeFile(InputFilename);
60   if (module == 0) {
61     cerr << "bytecode didn't read correctly.\n";
62     return 1;
63   }
64
65   if (CompileModule(module, Target)) {
66     cerr << "Error compiling " << InputFilename << "!\n";
67     delete module;
68     return 1;
69   }
70   
71   // Clean up and exit
72   delete module;
73   return 0;
74 }