mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-12 17:32:19 +00:00
Privatize LLCOptions. It had no business being visible to the entire
program. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@267 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
c21d4fcb20
commit
aceb9132b7
@ -12,29 +12,17 @@
|
||||
#ifndef LLVM_CODEGEN_INSTR_SELECTION_H
|
||||
#define LLVM_CODEGEN_INSTR_SELECTION_H
|
||||
|
||||
//************************** System Include Files **************************/
|
||||
|
||||
//*************************** User Include Files ***************************/
|
||||
|
||||
#include "llvm/Instruction.h"
|
||||
|
||||
//************************* Opaque Declarations ****************************/
|
||||
|
||||
#include <vector>
|
||||
class CompileContext;
|
||||
class Instruction;
|
||||
class Method;
|
||||
class InstrForest;
|
||||
class MachineInstruction;
|
||||
class MachineInstr;
|
||||
class InstructionNode;
|
||||
class TmpInstruction;
|
||||
class ConstPoolVal;
|
||||
|
||||
|
||||
//************************ Exported Constants ******************************/
|
||||
|
||||
const int DEBUG_INSTR_TREES = 2;
|
||||
const int DEBUG_BURG_TREES = 5;
|
||||
|
||||
|
||||
//****************** External Function Prototypes **************************/
|
||||
enum { DEBUG_TREES_NONE = 0, DEBUG_INSTR_TREES = 1, DEBUG_BURG_TREES = 5 };
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// GLOBAL data and an external function that must be implemented
|
||||
@ -65,12 +53,12 @@ extern bool ThisIsAChainRule (int eruleno);
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
bool SelectInstructionsForMethod (Method* method,
|
||||
CompileContext& ccontext);
|
||||
CompileContext& ccontext,
|
||||
int DebugLevel);
|
||||
|
||||
|
||||
// Debugging function to print the generated instructions
|
||||
void PrintMachineInstructions (Method* method,
|
||||
CompileContext& ccontext);
|
||||
void PrintMachineInstructions (Method* method);
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
@ -13,57 +13,23 @@
|
||||
#ifndef LLVM_LLC_COMPILECONTEXT_H
|
||||
#define LLVM_LLC_COMPILECONTEXT_H
|
||||
|
||||
//************************** System Include Files **************************/
|
||||
|
||||
#include <string>
|
||||
|
||||
//*************************** User Include Files ***************************/
|
||||
|
||||
#include "llvm/CodeGen/Sparc.h"
|
||||
#include "llvm/LLC/LLCOptions.h"
|
||||
|
||||
//************************** Forward Declarations **************************/
|
||||
|
||||
class ProgramOptions;
|
||||
#include "llvm/Support/Unique.h"
|
||||
class TargetMachine;
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// class CompileContext
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
class CompileContext: public Unique
|
||||
{
|
||||
class CompileContext: public Unique {
|
||||
private:
|
||||
LLCOptions* options;
|
||||
TargetMachine* targetMachine;
|
||||
|
||||
public:
|
||||
/*ctor*/ CompileContext (int argc, const char **argv, const char** envp);
|
||||
/*dtor*/ virtual ~CompileContext ();
|
||||
|
||||
const LLCOptions& getOptions () const { return *options; }
|
||||
CompileContext(TargetMachine *Target) : targetMachine(Target) {}
|
||||
~CompileContext();
|
||||
|
||||
const TargetMachine& getTarget () const { return *targetMachine; }
|
||||
TargetMachine& getTarget () { return *targetMachine; }
|
||||
};
|
||||
|
||||
|
||||
inline
|
||||
CompileContext::CompileContext(int argc, const char **argv, const char** envp)
|
||||
{
|
||||
options = new LLCOptions(argc, argv, envp);
|
||||
targetMachine = new UltraSparc;
|
||||
}
|
||||
|
||||
|
||||
inline
|
||||
CompileContext::~CompileContext()
|
||||
{
|
||||
delete options;
|
||||
delete targetMachine;
|
||||
}
|
||||
|
||||
//**************************************************************************/
|
||||
|
||||
#endif
|
||||
|
@ -12,22 +12,20 @@
|
||||
|
||||
//*************************** User Include Files ***************************/
|
||||
|
||||
#include "llvm/CodeGen/InstrSelection.h"
|
||||
#include "llvm/Method.h"
|
||||
#include "llvm/BasicBlock.h"
|
||||
#include "llvm/Type.h"
|
||||
#include "llvm/iMemory.h"
|
||||
#include "llvm/Instruction.h"
|
||||
#include "llvm/LLC/CompileContext.h"
|
||||
#include "llvm/CodeGen/InstrForest.h"
|
||||
#include "llvm/CodeGen/MachineInstr.h"
|
||||
#include "llvm/CodeGen/InstrSelection.h"
|
||||
|
||||
|
||||
//************************* Forward Declarations ***************************/
|
||||
|
||||
static bool SelectInstructionsForTree (BasicTreeNode* treeRoot,
|
||||
int goalnt,
|
||||
CompileContext& ccontext);
|
||||
static bool SelectInstructionsForTree(BasicTreeNode* treeRoot, int goalnt,
|
||||
CompileContext& ccontext);
|
||||
|
||||
|
||||
//******************* Externally Visible Functions *************************/
|
||||
@ -38,10 +36,8 @@ static bool SelectInstructionsForTree (BasicTreeNode* treeRoot,
|
||||
// Returns true if instruction selection failed, false otherwise.
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
bool
|
||||
SelectInstructionsForMethod(Method* method,
|
||||
CompileContext& ccontext)
|
||||
{
|
||||
bool SelectInstructionsForMethod(Method* method, CompileContext& ccontext,
|
||||
int DebugLevel) {
|
||||
bool failed = false;
|
||||
|
||||
InstrForest instrForest;
|
||||
@ -63,8 +59,7 @@ SelectInstructionsForMethod(Method* method,
|
||||
// Invoke BURM to label each tree node with a state
|
||||
(void) burm_label(basicNode);
|
||||
|
||||
if (ccontext.getOptions().IntOptionValue(DEBUG_INSTR_SELECT_OPT)
|
||||
>= DEBUG_BURG_TREES)
|
||||
if (DebugLevel >= DEBUG_BURG_TREES)
|
||||
{
|
||||
printcover(basicNode, 1, 0);
|
||||
cerr << "\nCover cost == " << treecost(basicNode, 1, 0) << "\n\n";
|
||||
@ -81,8 +76,7 @@ SelectInstructionsForMethod(Method* method,
|
||||
|
||||
if (!failed)
|
||||
{
|
||||
if ( ccontext.getOptions().IntOptionValue(DEBUG_INSTR_SELECT_OPT)
|
||||
>= DEBUG_INSTR_TREES)
|
||||
if (DebugLevel >= DEBUG_INSTR_TREES)
|
||||
{
|
||||
cout << "\n\n*** Instruction trees for method "
|
||||
<< (method->hasName()? method->getName() : "")
|
||||
@ -90,8 +84,8 @@ SelectInstructionsForMethod(Method* method,
|
||||
instrForest.dump();
|
||||
}
|
||||
|
||||
if (ccontext.getOptions().IntOptionValue(DEBUG_INSTR_SELECT_OPT) > 0)
|
||||
PrintMachineInstructions(method, ccontext);
|
||||
if (DebugLevel >= DEBUG_TREES_NONE)
|
||||
PrintMachineInstructions(method);
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -139,10 +133,7 @@ FoldGetElemChain(const InstructionNode* getElemInstrNode,
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PrintMachineInstructions(Method* method,
|
||||
CompileContext& ccontext)
|
||||
{
|
||||
void PrintMachineInstructions(Method* method) {
|
||||
cout << "\n" << method->getReturnType()
|
||||
<< " \"" << method->getName() << "\"" << endl;
|
||||
|
||||
|
@ -12,22 +12,20 @@
|
||||
|
||||
//*************************** User Include Files ***************************/
|
||||
|
||||
#include "llvm/CodeGen/InstrSelection.h"
|
||||
#include "llvm/Method.h"
|
||||
#include "llvm/BasicBlock.h"
|
||||
#include "llvm/Type.h"
|
||||
#include "llvm/iMemory.h"
|
||||
#include "llvm/Instruction.h"
|
||||
#include "llvm/LLC/CompileContext.h"
|
||||
#include "llvm/CodeGen/InstrForest.h"
|
||||
#include "llvm/CodeGen/MachineInstr.h"
|
||||
#include "llvm/CodeGen/InstrSelection.h"
|
||||
|
||||
|
||||
//************************* Forward Declarations ***************************/
|
||||
|
||||
static bool SelectInstructionsForTree (BasicTreeNode* treeRoot,
|
||||
int goalnt,
|
||||
CompileContext& ccontext);
|
||||
static bool SelectInstructionsForTree(BasicTreeNode* treeRoot, int goalnt,
|
||||
CompileContext& ccontext);
|
||||
|
||||
|
||||
//******************* Externally Visible Functions *************************/
|
||||
@ -38,10 +36,8 @@ static bool SelectInstructionsForTree (BasicTreeNode* treeRoot,
|
||||
// Returns true if instruction selection failed, false otherwise.
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
bool
|
||||
SelectInstructionsForMethod(Method* method,
|
||||
CompileContext& ccontext)
|
||||
{
|
||||
bool SelectInstructionsForMethod(Method* method, CompileContext& ccontext,
|
||||
int DebugLevel) {
|
||||
bool failed = false;
|
||||
|
||||
InstrForest instrForest;
|
||||
@ -63,8 +59,7 @@ SelectInstructionsForMethod(Method* method,
|
||||
// Invoke BURM to label each tree node with a state
|
||||
(void) burm_label(basicNode);
|
||||
|
||||
if (ccontext.getOptions().IntOptionValue(DEBUG_INSTR_SELECT_OPT)
|
||||
>= DEBUG_BURG_TREES)
|
||||
if (DebugLevel >= DEBUG_BURG_TREES)
|
||||
{
|
||||
printcover(basicNode, 1, 0);
|
||||
cerr << "\nCover cost == " << treecost(basicNode, 1, 0) << "\n\n";
|
||||
@ -81,8 +76,7 @@ SelectInstructionsForMethod(Method* method,
|
||||
|
||||
if (!failed)
|
||||
{
|
||||
if ( ccontext.getOptions().IntOptionValue(DEBUG_INSTR_SELECT_OPT)
|
||||
>= DEBUG_INSTR_TREES)
|
||||
if (DebugLevel >= DEBUG_INSTR_TREES)
|
||||
{
|
||||
cout << "\n\n*** Instruction trees for method "
|
||||
<< (method->hasName()? method->getName() : "")
|
||||
@ -90,8 +84,8 @@ SelectInstructionsForMethod(Method* method,
|
||||
instrForest.dump();
|
||||
}
|
||||
|
||||
if (ccontext.getOptions().IntOptionValue(DEBUG_INSTR_SELECT_OPT) > 0)
|
||||
PrintMachineInstructions(method, ccontext);
|
||||
if (DebugLevel >= DEBUG_TREES_NONE)
|
||||
PrintMachineInstructions(method);
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -139,10 +133,7 @@ FoldGetElemChain(const InstructionNode* getElemInstrNode,
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PrintMachineInstructions(Method* method,
|
||||
CompileContext& ccontext)
|
||||
{
|
||||
void PrintMachineInstructions(Method* method) {
|
||||
cout << "\n" << method->getReturnType()
|
||||
<< " \"" << method->getName() << "\"" << endl;
|
||||
|
||||
|
@ -21,7 +21,7 @@
|
||||
|
||||
#include "llvm/Support/ProgramOptions.h"
|
||||
#include "llvm/Support/ProgramOption.h"
|
||||
#include "llvm/LLC/LLCOptions.h"
|
||||
#include "LLCOptions.h"
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
74
tools/llc/LLCOptions.h
Normal file
74
tools/llc/LLCOptions.h
Normal file
@ -0,0 +1,74 @@
|
||||
// $Id$ -*-c++-*-
|
||||
//**************************************************************************/
|
||||
// File:
|
||||
// LLCOptions.h
|
||||
//
|
||||
// Purpose:
|
||||
// Options for the llc compiler.
|
||||
//
|
||||
// History:
|
||||
// 7/15/01 - Vikram Adve - Created
|
||||
//
|
||||
//**************************************************************************/
|
||||
|
||||
#ifndef LLVM_LLC_LLCOPTIONS_H
|
||||
#define LLVM_LLC_LLCOPTIONS_H
|
||||
|
||||
#include "llvm/Support/ProgramOptions.h"
|
||||
#include "llvm/Support/ProgramOption.h"
|
||||
|
||||
const char* const HELP_OPT = "help";
|
||||
const char* const DEBUG_OPT = "d";
|
||||
const char* const QUIET_OPT = "q";
|
||||
const char* const DEBUG_INSTR_SELECT_OPT= "debug_select";
|
||||
const char* const OUTFILENAME_OPT = "o";
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// class LLCOptions
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
class LLCOptions : public ProgramOptions {
|
||||
public:
|
||||
/*ctor*/ LLCOptions (int _argc,
|
||||
const char* _argv[],
|
||||
const char* _envp[]);
|
||||
/*dtor*/ virtual ~LLCOptions ();
|
||||
|
||||
const string& getInputFileName() const { return inputFileName; }
|
||||
|
||||
const string& getOutputFileName() const { return outputFileName; }
|
||||
|
||||
protected:
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Initialize for all our compiler options (called by constructors).
|
||||
//--------------------------------------------------------------------
|
||||
void InitializeOptions();
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Make sure the parse went ok.
|
||||
//--------------------------------------------------------------------
|
||||
void CheckParse();
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Parse arguments after all options are consumed.
|
||||
// This is called after a successful ParseArgs.
|
||||
//--------------------------------------------------------------------
|
||||
virtual void ParseExtraArgs();
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Print message describing which arguments and options are
|
||||
// required, optional, mutually exclusive, ...
|
||||
// called in ProgramOptions::Usage() method
|
||||
//--------------------------------------------------------------------
|
||||
virtual void PrintUsage(ostream& stream) const;
|
||||
|
||||
private:
|
||||
string inputFileName;
|
||||
string outputFileName;
|
||||
};
|
||||
|
||||
//**************************************************************************/
|
||||
|
||||
#endif
|
@ -11,29 +11,39 @@
|
||||
//
|
||||
//**************************************************************************/
|
||||
|
||||
//************************** System Include Files **************************/
|
||||
|
||||
//*************************** User Include Files ***************************/
|
||||
|
||||
#include "llvm/Module.h"
|
||||
#include "llvm/Method.h"
|
||||
#include "llvm/Bytecode/Reader.h"
|
||||
#include "llvm/Bytecode/Writer.h"
|
||||
#include "llvm/CodeGen/InstrForest.h"
|
||||
#include "llvm/CodeGen/InstrSelection.h"
|
||||
#include "llvm/LLC/LLCOptions.h"
|
||||
#include "llvm/LLC/CompileContext.h"
|
||||
#include "llvm/CodeGen/Sparc.h"
|
||||
#include "LLCOptions.h"
|
||||
|
||||
//************************** Forward Declarations **************************/
|
||||
CompileContext::~CompileContext() { delete targetMachine; }
|
||||
|
||||
class Module;
|
||||
class CompileContext;
|
||||
|
||||
|
||||
static bool CompileModule (Module *module,
|
||||
CompileContext& compileContext);
|
||||
|
||||
int DebugInstrSelectLevel = DEBUG_INSTR_TREES;
|
||||
static bool CompileModule(Module *module, CompileContext& ccontext,
|
||||
LLCOptions &Options) {
|
||||
bool failed = false;
|
||||
|
||||
for (Module::MethodListType::const_iterator
|
||||
methodIter = module->getMethodList().begin();
|
||||
methodIter != module->getMethodList().end();
|
||||
++methodIter)
|
||||
{
|
||||
Method* method = *methodIter;
|
||||
|
||||
if (SelectInstructionsForMethod(method, ccontext,
|
||||
Options.IntOptionValue(DEBUG_INSTR_SELECT_OPT)))
|
||||
{
|
||||
failed = true;
|
||||
cerr << "Instruction selection failed for method "
|
||||
<< method->getName() << "\n\n";
|
||||
}
|
||||
}
|
||||
|
||||
return failed;
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
@ -42,26 +52,21 @@ int DebugInstrSelectLevel = DEBUG_INSTR_TREES;
|
||||
// Entry point for the driver.
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
||||
int
|
||||
main(int argc, const char** argv, const char** envp)
|
||||
{
|
||||
CompileContext compileContext(argc, argv, envp);
|
||||
|
||||
Module *module =
|
||||
ParseBytecodeFile(compileContext.getOptions().getInputFileName());
|
||||
int main(int argc, const char** argv, const char** envp) {
|
||||
LLCOptions Options(argc, argv, envp);
|
||||
CompileContext compileContext(new UltraSparc());
|
||||
|
||||
Module *module = ParseBytecodeFile(Options.getInputFileName());
|
||||
if (module == 0) {
|
||||
cerr << "bytecode didn't read correctly.\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool failure = CompileModule(module, compileContext);
|
||||
bool failure = CompileModule(module, compileContext, Options);
|
||||
|
||||
if (failure)
|
||||
{
|
||||
if (failure) {
|
||||
cerr << "Error compiling "
|
||||
<< compileContext.getOptions().getInputFileName() << "!\n";
|
||||
<< Options.getInputFileName() << "!\n";
|
||||
delete module;
|
||||
return 1;
|
||||
}
|
||||
@ -74,30 +79,3 @@ main(int argc, const char** argv, const char** envp)
|
||||
delete module;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static bool
|
||||
CompileModule(Module *module,
|
||||
CompileContext& ccontext)
|
||||
{
|
||||
bool failed = false;
|
||||
|
||||
for (Module::MethodListType::const_iterator
|
||||
methodIter = module->getMethodList().begin();
|
||||
methodIter != module->getMethodList().end();
|
||||
++methodIter)
|
||||
{
|
||||
Method* method = *methodIter;
|
||||
|
||||
if (SelectInstructionsForMethod(method, ccontext))
|
||||
{
|
||||
failed = true;
|
||||
cerr << "Instruction selection failed for method "
|
||||
<< (method->hasName()? method->getName() : "")
|
||||
<< endl << endl;
|
||||
}
|
||||
}
|
||||
|
||||
return failed;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user