2001-07-21 12:42:29 +00:00
|
|
|
// $Id$
|
|
|
|
//***************************************************************************
|
|
|
|
// File:
|
|
|
|
// llc.cpp
|
|
|
|
//
|
|
|
|
// Purpose:
|
|
|
|
// Driver for llc compiler.
|
|
|
|
//
|
|
|
|
// History:
|
|
|
|
// 7/15/01 - Vikram Adve - Created
|
|
|
|
//
|
|
|
|
//**************************************************************************/
|
|
|
|
|
|
|
|
#include "llvm/Module.h"
|
|
|
|
#include "llvm/Method.h"
|
|
|
|
#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-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-08-28 23:23:14 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
NormalizeMethod(Method* method)
|
|
|
|
{
|
|
|
|
NormalizePhiConstantArgs(method);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
CompileModule(Module *M, TargetMachine &target)
|
|
|
|
{
|
2001-07-22 04:40:02 +00:00
|
|
|
bool failed = false;
|
|
|
|
|
2001-08-28 23:23:14 +00:00
|
|
|
for (Module::const_iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI)
|
|
|
|
{
|
|
|
|
Method* method = *MI;
|
|
|
|
|
|
|
|
NormalizeMethod(method);
|
2001-07-22 04:40:02 +00:00
|
|
|
|
2001-08-28 23:23:14 +00:00
|
|
|
failed = SelectInstructionsForMethod(method, target);
|
|
|
|
if (failed)
|
|
|
|
{
|
|
|
|
cerr << "Instruction selection failed for method "
|
|
|
|
<< method->getName() << "\n\n";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
failed = ScheduleInstructionsWithSSA(method, target);
|
|
|
|
if (failed)
|
|
|
|
{
|
|
|
|
cerr << "Instruction scheduling before allocation failed for method "
|
|
|
|
<< method->getName() << "\n\n";
|
|
|
|
break;
|
|
|
|
}
|
2001-07-22 04:40:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return failed;
|
|
|
|
}
|
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-08-28 23:23:14 +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-08-28 23:23:14 +00:00
|
|
|
UltraSparc target;
|
|
|
|
|
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
|
|
|
|
|
|
|
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;
|
|
|
|
}
|