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:
Chris Lattner
2001-07-22 04:40:02 +00:00
parent c21d4fcb20
commit aceb9132b7
7 changed files with 139 additions and 151 deletions

View File

@@ -12,29 +12,17 @@
#ifndef LLVM_CODEGEN_INSTR_SELECTION_H #ifndef LLVM_CODEGEN_INSTR_SELECTION_H
#define LLVM_CODEGEN_INSTR_SELECTION_H #define LLVM_CODEGEN_INSTR_SELECTION_H
//************************** System Include Files **************************/
//*************************** User Include Files ***************************/
#include "llvm/Instruction.h" #include "llvm/Instruction.h"
#include <vector>
//************************* Opaque Declarations ****************************/
class CompileContext; class CompileContext;
class Instruction;
class Method; class Method;
class InstrForest; class InstrForest;
class MachineInstruction; class MachineInstr;
class InstructionNode;
class TmpInstruction; class TmpInstruction;
class ConstPoolVal;
enum { DEBUG_TREES_NONE = 0, DEBUG_INSTR_TREES = 1, DEBUG_BURG_TREES = 5 };
//************************ Exported Constants ******************************/
const int DEBUG_INSTR_TREES = 2;
const int DEBUG_BURG_TREES = 5;
//****************** External Function Prototypes **************************/
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// GLOBAL data and an external function that must be implemented // GLOBAL data and an external function that must be implemented
@@ -65,12 +53,12 @@ extern bool ThisIsAChainRule (int eruleno);
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
bool SelectInstructionsForMethod (Method* method, bool SelectInstructionsForMethod (Method* method,
CompileContext& ccontext); CompileContext& ccontext,
int DebugLevel);
// Debugging function to print the generated instructions // Debugging function to print the generated instructions
void PrintMachineInstructions (Method* method, void PrintMachineInstructions (Method* method);
CompileContext& ccontext);
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View File

@@ -13,57 +13,23 @@
#ifndef LLVM_LLC_COMPILECONTEXT_H #ifndef LLVM_LLC_COMPILECONTEXT_H
#define LLVM_LLC_COMPILECONTEXT_H #define LLVM_LLC_COMPILECONTEXT_H
//************************** System Include Files **************************/ #include "llvm/Support/Unique.h"
#include <string>
//*************************** User Include Files ***************************/
#include "llvm/CodeGen/Sparc.h"
#include "llvm/LLC/LLCOptions.h"
//************************** Forward Declarations **************************/
class ProgramOptions;
class TargetMachine; class TargetMachine;
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// class CompileContext // class CompileContext
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
class CompileContext: public Unique class CompileContext: public Unique {
{
private: private:
LLCOptions* options;
TargetMachine* targetMachine; TargetMachine* targetMachine;
public: public:
/*ctor*/ CompileContext (int argc, const char **argv, const char** envp); CompileContext(TargetMachine *Target) : targetMachine(Target) {}
/*dtor*/ virtual ~CompileContext (); ~CompileContext();
const LLCOptions& getOptions () const { return *options; }
const TargetMachine& getTarget () const { return *targetMachine; } const TargetMachine& getTarget () const { return *targetMachine; }
TargetMachine& getTarget () { 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 #endif

View File

@@ -12,21 +12,19 @@
//*************************** User Include Files ***************************/ //*************************** User Include Files ***************************/
#include "llvm/CodeGen/InstrSelection.h"
#include "llvm/Method.h" #include "llvm/Method.h"
#include "llvm/BasicBlock.h" #include "llvm/BasicBlock.h"
#include "llvm/Type.h" #include "llvm/Type.h"
#include "llvm/iMemory.h" #include "llvm/iMemory.h"
#include "llvm/Instruction.h" #include "llvm/Instruction.h"
#include "llvm/LLC/CompileContext.h" #include "llvm/LLC/CompileContext.h"
#include "llvm/CodeGen/InstrForest.h"
#include "llvm/CodeGen/MachineInstr.h" #include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/InstrSelection.h"
//************************* Forward Declarations ***************************/ //************************* Forward Declarations ***************************/
static bool SelectInstructionsForTree (BasicTreeNode* treeRoot, static bool SelectInstructionsForTree(BasicTreeNode* treeRoot, int goalnt,
int goalnt,
CompileContext& ccontext); CompileContext& ccontext);
@@ -38,10 +36,8 @@ static bool SelectInstructionsForTree (BasicTreeNode* treeRoot,
// Returns true if instruction selection failed, false otherwise. // Returns true if instruction selection failed, false otherwise.
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
bool bool SelectInstructionsForMethod(Method* method, CompileContext& ccontext,
SelectInstructionsForMethod(Method* method, int DebugLevel) {
CompileContext& ccontext)
{
bool failed = false; bool failed = false;
InstrForest instrForest; InstrForest instrForest;
@@ -63,8 +59,7 @@ SelectInstructionsForMethod(Method* method,
// Invoke BURM to label each tree node with a state // Invoke BURM to label each tree node with a state
(void) burm_label(basicNode); (void) burm_label(basicNode);
if (ccontext.getOptions().IntOptionValue(DEBUG_INSTR_SELECT_OPT) if (DebugLevel >= DEBUG_BURG_TREES)
>= DEBUG_BURG_TREES)
{ {
printcover(basicNode, 1, 0); printcover(basicNode, 1, 0);
cerr << "\nCover cost == " << treecost(basicNode, 1, 0) << "\n\n"; cerr << "\nCover cost == " << treecost(basicNode, 1, 0) << "\n\n";
@@ -81,8 +76,7 @@ SelectInstructionsForMethod(Method* method,
if (!failed) if (!failed)
{ {
if ( ccontext.getOptions().IntOptionValue(DEBUG_INSTR_SELECT_OPT) if (DebugLevel >= DEBUG_INSTR_TREES)
>= DEBUG_INSTR_TREES)
{ {
cout << "\n\n*** Instruction trees for method " cout << "\n\n*** Instruction trees for method "
<< (method->hasName()? method->getName() : "") << (method->hasName()? method->getName() : "")
@@ -90,8 +84,8 @@ SelectInstructionsForMethod(Method* method,
instrForest.dump(); instrForest.dump();
} }
if (ccontext.getOptions().IntOptionValue(DEBUG_INSTR_SELECT_OPT) > 0) if (DebugLevel >= DEBUG_TREES_NONE)
PrintMachineInstructions(method, ccontext); PrintMachineInstructions(method);
} }
return false; return false;
@@ -139,10 +133,7 @@ FoldGetElemChain(const InstructionNode* getElemInstrNode,
} }
void void PrintMachineInstructions(Method* method) {
PrintMachineInstructions(Method* method,
CompileContext& ccontext)
{
cout << "\n" << method->getReturnType() cout << "\n" << method->getReturnType()
<< " \"" << method->getName() << "\"" << endl; << " \"" << method->getName() << "\"" << endl;

View File

@@ -12,21 +12,19 @@
//*************************** User Include Files ***************************/ //*************************** User Include Files ***************************/
#include "llvm/CodeGen/InstrSelection.h"
#include "llvm/Method.h" #include "llvm/Method.h"
#include "llvm/BasicBlock.h" #include "llvm/BasicBlock.h"
#include "llvm/Type.h" #include "llvm/Type.h"
#include "llvm/iMemory.h" #include "llvm/iMemory.h"
#include "llvm/Instruction.h" #include "llvm/Instruction.h"
#include "llvm/LLC/CompileContext.h" #include "llvm/LLC/CompileContext.h"
#include "llvm/CodeGen/InstrForest.h"
#include "llvm/CodeGen/MachineInstr.h" #include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/InstrSelection.h"
//************************* Forward Declarations ***************************/ //************************* Forward Declarations ***************************/
static bool SelectInstructionsForTree (BasicTreeNode* treeRoot, static bool SelectInstructionsForTree(BasicTreeNode* treeRoot, int goalnt,
int goalnt,
CompileContext& ccontext); CompileContext& ccontext);
@@ -38,10 +36,8 @@ static bool SelectInstructionsForTree (BasicTreeNode* treeRoot,
// Returns true if instruction selection failed, false otherwise. // Returns true if instruction selection failed, false otherwise.
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
bool bool SelectInstructionsForMethod(Method* method, CompileContext& ccontext,
SelectInstructionsForMethod(Method* method, int DebugLevel) {
CompileContext& ccontext)
{
bool failed = false; bool failed = false;
InstrForest instrForest; InstrForest instrForest;
@@ -63,8 +59,7 @@ SelectInstructionsForMethod(Method* method,
// Invoke BURM to label each tree node with a state // Invoke BURM to label each tree node with a state
(void) burm_label(basicNode); (void) burm_label(basicNode);
if (ccontext.getOptions().IntOptionValue(DEBUG_INSTR_SELECT_OPT) if (DebugLevel >= DEBUG_BURG_TREES)
>= DEBUG_BURG_TREES)
{ {
printcover(basicNode, 1, 0); printcover(basicNode, 1, 0);
cerr << "\nCover cost == " << treecost(basicNode, 1, 0) << "\n\n"; cerr << "\nCover cost == " << treecost(basicNode, 1, 0) << "\n\n";
@@ -81,8 +76,7 @@ SelectInstructionsForMethod(Method* method,
if (!failed) if (!failed)
{ {
if ( ccontext.getOptions().IntOptionValue(DEBUG_INSTR_SELECT_OPT) if (DebugLevel >= DEBUG_INSTR_TREES)
>= DEBUG_INSTR_TREES)
{ {
cout << "\n\n*** Instruction trees for method " cout << "\n\n*** Instruction trees for method "
<< (method->hasName()? method->getName() : "") << (method->hasName()? method->getName() : "")
@@ -90,8 +84,8 @@ SelectInstructionsForMethod(Method* method,
instrForest.dump(); instrForest.dump();
} }
if (ccontext.getOptions().IntOptionValue(DEBUG_INSTR_SELECT_OPT) > 0) if (DebugLevel >= DEBUG_TREES_NONE)
PrintMachineInstructions(method, ccontext); PrintMachineInstructions(method);
} }
return false; return false;
@@ -139,10 +133,7 @@ FoldGetElemChain(const InstructionNode* getElemInstrNode,
} }
void void PrintMachineInstructions(Method* method) {
PrintMachineInstructions(Method* method,
CompileContext& ccontext)
{
cout << "\n" << method->getReturnType() cout << "\n" << method->getReturnType()
<< " \"" << method->getName() << "\"" << endl; << " \"" << method->getName() << "\"" << endl;

View File

@@ -21,7 +21,7 @@
#include "llvm/Support/ProgramOptions.h" #include "llvm/Support/ProgramOptions.h"
#include "llvm/Support/ProgramOption.h" #include "llvm/Support/ProgramOption.h"
#include "llvm/LLC/LLCOptions.h" #include "LLCOptions.h"
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

74
tools/llc/LLCOptions.h Normal file
View 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

View File

@@ -11,29 +11,39 @@
// //
//**************************************************************************/ //**************************************************************************/
//************************** System Include Files **************************/
//*************************** User Include Files ***************************/
#include "llvm/Module.h" #include "llvm/Module.h"
#include "llvm/Method.h" #include "llvm/Method.h"
#include "llvm/Bytecode/Reader.h" #include "llvm/Bytecode/Reader.h"
#include "llvm/Bytecode/Writer.h" #include "llvm/Bytecode/Writer.h"
#include "llvm/CodeGen/InstrForest.h"
#include "llvm/CodeGen/InstrSelection.h" #include "llvm/CodeGen/InstrSelection.h"
#include "llvm/LLC/LLCOptions.h"
#include "llvm/LLC/CompileContext.h" #include "llvm/LLC/CompileContext.h"
#include "llvm/CodeGen/Sparc.h"
#include "LLCOptions.h"
//************************** Forward Declarations **************************/ CompileContext::~CompileContext() { delete targetMachine; }
class Module; static bool CompileModule(Module *module, CompileContext& ccontext,
class CompileContext; LLCOptions &Options) {
bool failed = false;
for (Module::MethodListType::const_iterator
methodIter = module->getMethodList().begin();
methodIter != module->getMethodList().end();
++methodIter)
{
Method* method = *methodIter;
static bool CompileModule (Module *module, if (SelectInstructionsForMethod(method, ccontext,
CompileContext& compileContext); Options.IntOptionValue(DEBUG_INSTR_SELECT_OPT)))
{
failed = true;
cerr << "Instruction selection failed for method "
<< method->getName() << "\n\n";
}
}
int DebugInstrSelectLevel = DEBUG_INSTR_TREES; return failed;
}
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@@ -42,26 +52,21 @@ int DebugInstrSelectLevel = DEBUG_INSTR_TREES;
// Entry point for the driver. // Entry point for the driver.
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
int main(int argc, const char** argv, const char** envp) {
LLCOptions Options(argc, argv, envp);
CompileContext compileContext(new UltraSparc());
int Module *module = ParseBytecodeFile(Options.getInputFileName());
main(int argc, const char** argv, const char** envp)
{
CompileContext compileContext(argc, argv, envp);
Module *module =
ParseBytecodeFile(compileContext.getOptions().getInputFileName());
if (module == 0) { if (module == 0) {
cerr << "bytecode didn't read correctly.\n"; cerr << "bytecode didn't read correctly.\n";
return 1; return 1;
} }
bool failure = CompileModule(module, compileContext); bool failure = CompileModule(module, compileContext, Options);
if (failure) if (failure) {
{
cerr << "Error compiling " cerr << "Error compiling "
<< compileContext.getOptions().getInputFileName() << "!\n"; << Options.getInputFileName() << "!\n";
delete module; delete module;
return 1; return 1;
} }
@@ -74,30 +79,3 @@ main(int argc, const char** argv, const char** envp)
delete module; delete module;
return 0; 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;
}