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