blob: 9258bd431327922eb82c9db924c433fb64440f1b [file] [log] [blame]
Chris Lattner2cf137b2001-09-07 22:20:50 +00001//===------------------------------------------------------------------------===
2// LLVM 'LLC' UTILITY
3//
4// This is the llc compiler driver.
5//
6//===------------------------------------------------------------------------===
Vikram S. Adve2d94a342001-07-21 12:42:29 +00007
Vikram S. Adve2d94a342001-07-21 12:42:29 +00008#include "llvm/Bytecode/Reader.h"
Vikram S. Adve799aed02001-08-28 23:23:14 +00009#include "llvm/Optimizations/Normalize.h"
Chris Lattnerdd511762001-07-21 20:58:30 +000010#include "llvm/CodeGen/InstrSelection.h"
Vikram S. Adve799aed02001-08-28 23:23:14 +000011#include "llvm/CodeGen/InstrScheduling.h"
Chris Lattner9c0f8f22001-07-22 04:40:02 +000012#include "llvm/CodeGen/Sparc.h"
Chris Lattnere2472bb2001-07-23 17:46:59 +000013#include "llvm/Support/CommandLine.h"
Chris Lattnered226062001-09-07 21:26:31 +000014#include "llvm/Module.h"
15#include "llvm/Method.h"
Chris Lattner0af24642001-07-23 02:35:57 +000016
Chris Lattnerab0cc402001-07-23 19:27:24 +000017cl::String InputFilename ("", "Input filename", cl::NoFlags, "-");
Chris Lattner0af24642001-07-23 02:35:57 +000018cl::String OutputFilename("o", "Output filename", cl::NoFlags, "");
19
Chris Lattnered226062001-09-07 21:26:31 +000020static void NormalizeMethod(Method* method) {
Vikram S. Adve799aed02001-08-28 23:23:14 +000021 NormalizePhiConstantArgs(method);
22}
23
24
Chris Lattnered226062001-09-07 21:26:31 +000025static bool CompileModule(Module *M, TargetMachine &Target) {
26 for (Module::const_iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI) {
27 Method *Meth = *MI;
Chris Lattner9c0f8f22001-07-22 04:40:02 +000028
Chris Lattnered226062001-09-07 21:26:31 +000029 NormalizeMethod(Meth);
Vikram S. Adve799aed02001-08-28 23:23:14 +000030
Chris Lattnered226062001-09-07 21:26:31 +000031 if (SelectInstructionsForMethod(Meth, Target)) {
Chris Lattner2cf137b2001-09-07 22:20:50 +000032 cerr << "Instruction selection failed for method " << Meth->getName()
33 << "\n\n";
Chris Lattnered226062001-09-07 21:26:31 +000034 return true;
Chris Lattner9c0f8f22001-07-22 04:40:02 +000035 }
Chris Lattnered226062001-09-07 21:26:31 +000036
37 if (ScheduleInstructionsWithSSA(Meth, Target)) {
38 cerr << "Instruction scheduling before allocation failed for method "
39 << Meth->getName() << "\n\n";
40 return true;
41 }
42 }
Chris Lattner9c0f8f22001-07-22 04:40:02 +000043
Chris Lattnered226062001-09-07 21:26:31 +000044 return false;
Chris Lattner9c0f8f22001-07-22 04:40:02 +000045}
Vikram S. Adve2d94a342001-07-21 12:42:29 +000046
47
Vikram S. Adve799aed02001-08-28 23:23:14 +000048
Vikram S. Adve2d94a342001-07-21 12:42:29 +000049//---------------------------------------------------------------------------
50// Function main()
51//
Vikram S. Adve799aed02001-08-28 23:23:14 +000052// Entry point for the llc compiler.
Vikram S. Adve2d94a342001-07-21 12:42:29 +000053//---------------------------------------------------------------------------
54
Chris Lattnered226062001-09-07 21:26:31 +000055int main(int argc, char** argv) {
Chris Lattner0af24642001-07-23 02:35:57 +000056 cl::ParseCommandLineOptions(argc, argv, " llvm system compiler\n");
Chris Lattnered226062001-09-07 21:26:31 +000057 UltraSparc Target;
Vikram S. Adve799aed02001-08-28 23:23:14 +000058
Chris Lattnerab0cc402001-07-23 19:27:24 +000059 Module *module = ParseBytecodeFile(InputFilename);
Vikram S. Adve2d94a342001-07-21 12:42:29 +000060 if (module == 0) {
61 cerr << "bytecode didn't read correctly.\n";
62 return 1;
63 }
Vikram S. Adve799aed02001-08-28 23:23:14 +000064
Chris Lattnered226062001-09-07 21:26:31 +000065 if (CompileModule(module, Target)) {
Chris Lattnerab0cc402001-07-23 19:27:24 +000066 cerr << "Error compiling " << InputFilename << "!\n";
67 delete module;
68 return 1;
69 }
Vikram S. Adve2d94a342001-07-21 12:42:29 +000070
71 // Clean up and exit
72 delete module;
73 return 0;
74}