2001-09-07 22:20:50 +00:00
|
|
|
//===------------------------------------------------------------------------===
|
|
|
|
// LLVM 'LLC' UTILITY
|
|
|
|
//
|
|
|
|
// This is the llc compiler driver.
|
|
|
|
//
|
|
|
|
//===------------------------------------------------------------------------===
|
2001-07-21 12:42:29 +00:00
|
|
|
|
|
|
|
#include "llvm/Bytecode/Reader.h"
|
2001-08-28 23:23:14 +00:00
|
|
|
#include "llvm/Optimizations/Normalize.h"
|
2001-07-21 20:58:30 +00:00
|
|
|
#include "llvm/CodeGen/InstrSelection.h"
|
2001-08-28 23:23:14 +00:00
|
|
|
#include "llvm/CodeGen/InstrScheduling.h"
|
2001-07-22 04:40:02 +00:00
|
|
|
#include "llvm/CodeGen/Sparc.h"
|
2001-07-23 17:46:59 +00:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2001-09-07 21:26:31 +00:00
|
|
|
#include "llvm/Module.h"
|
|
|
|
#include "llvm/Method.h"
|
2001-07-23 02:35:57 +00:00
|
|
|
|
2001-07-23 19:27:24 +00:00
|
|
|
cl::String InputFilename ("", "Input filename", cl::NoFlags, "-");
|
2001-07-23 02:35:57 +00:00
|
|
|
cl::String OutputFilename("o", "Output filename", cl::NoFlags, "");
|
|
|
|
|
2001-09-07 21:26:31 +00:00
|
|
|
static void NormalizeMethod(Method* method) {
|
2001-08-28 23:23:14 +00:00
|
|
|
NormalizePhiConstantArgs(method);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-07 21:26:31 +00:00
|
|
|
static bool CompileModule(Module *M, TargetMachine &Target) {
|
|
|
|
for (Module::const_iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI) {
|
|
|
|
Method *Meth = *MI;
|
2001-08-28 23:23:14 +00:00
|
|
|
|
2001-09-07 21:26:31 +00:00
|
|
|
NormalizeMethod(Meth);
|
2001-07-22 04:40:02 +00:00
|
|
|
|
2001-09-07 21:26:31 +00:00
|
|
|
if (SelectInstructionsForMethod(Meth, Target)) {
|
2001-09-07 22:20:50 +00:00
|
|
|
cerr << "Instruction selection failed for method " << Meth->getName()
|
|
|
|
<< "\n\n";
|
2001-09-07 21:26:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
2001-08-28 23:23:14 +00:00
|
|
|
|
2001-09-07 21:26:31 +00:00
|
|
|
if (ScheduleInstructionsWithSSA(Meth, Target)) {
|
|
|
|
cerr << "Instruction scheduling before allocation failed for method "
|
|
|
|
<< Meth->getName() << "\n\n";
|
|
|
|
return true;
|
2001-07-22 04:40:02 +00:00
|
|
|
}
|
2001-09-07 21:26:31 +00:00
|
|
|
}
|
2001-07-22 04:40:02 +00:00
|
|
|
|
2001-09-07 21:26:31 +00:00
|
|
|
return false;
|
2001-07-22 04:40:02 +00:00
|
|
|
}
|
2001-07-21 12:42:29 +00:00
|
|
|
|
|
|
|
|
2001-08-28 23:23:14 +00:00
|
|
|
|
2001-07-21 12:42:29 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// Function main()
|
|
|
|
//
|
2001-08-28 23:23:14 +00:00
|
|
|
// Entry point for the llc compiler.
|
2001-07-21 12:42:29 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2001-09-07 21:26:31 +00:00
|
|
|
int main(int argc, char** argv) {
|
2001-07-23 02:35:57 +00:00
|
|
|
cl::ParseCommandLineOptions(argc, argv, " llvm system compiler\n");
|
2001-09-07 21:26:31 +00:00
|
|
|
UltraSparc Target;
|
2001-08-28 23:23:14 +00:00
|
|
|
|
2001-07-23 19:27:24 +00:00
|
|
|
Module *module = ParseBytecodeFile(InputFilename);
|
2001-07-21 12:42:29 +00:00
|
|
|
if (module == 0) {
|
|
|
|
cerr << "bytecode didn't read correctly.\n";
|
|
|
|
return 1;
|
|
|
|
}
|
2001-08-28 23:23:14 +00:00
|
|
|
|
2001-09-07 21:26:31 +00:00
|
|
|
if (CompileModule(module, Target)) {
|
2001-07-23 19:27:24 +00:00
|
|
|
cerr << "Error compiling " << InputFilename << "!\n";
|
|
|
|
delete module;
|
|
|
|
return 1;
|
|
|
|
}
|
2001-07-21 12:42:29 +00:00
|
|
|
|
|
|
|
// Clean up and exit
|
|
|
|
delete module;
|
|
|
|
return 0;
|
|
|
|
}
|