From aceb9132b7c0f2b22a2e51d523d0bd46f2cb3817 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 22 Jul 2001 04:40:02 +0000 Subject: [PATCH] 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 --- include/llvm/CodeGen/InstrSelection.h | 28 ++---- include/llvm/LLC/CompileContext.h | 42 +-------- lib/CodeGen/InstrSelection/InstrSelection.cpp | 29 +++---- .../SparcV9/InstrSelection/InstrSelection.cpp | 29 +++---- tools/llc/LLCOptions.cpp | 2 +- tools/llc/LLCOptions.h | 74 ++++++++++++++++ tools/llc/llc.cpp | 86 +++++++------------ 7 files changed, 139 insertions(+), 151 deletions(-) create mode 100644 tools/llc/LLCOptions.h diff --git a/include/llvm/CodeGen/InstrSelection.h b/include/llvm/CodeGen/InstrSelection.h index 7538a1532b2..0873003baf5 100644 --- a/include/llvm/CodeGen/InstrSelection.h +++ b/include/llvm/CodeGen/InstrSelection.h @@ -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 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); //--------------------------------------------------------------------------- diff --git a/include/llvm/LLC/CompileContext.h b/include/llvm/LLC/CompileContext.h index 91a448b62d0..29e15777928 100644 --- a/include/llvm/LLC/CompileContext.h +++ b/include/llvm/LLC/CompileContext.h @@ -13,57 +13,23 @@ #ifndef LLVM_LLC_COMPILECONTEXT_H #define LLVM_LLC_COMPILECONTEXT_H -//************************** System Include Files **************************/ - -#include - -//*************************** 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 diff --git a/lib/CodeGen/InstrSelection/InstrSelection.cpp b/lib/CodeGen/InstrSelection/InstrSelection.cpp index aac57575cbd..4843a70dce7 100644 --- a/lib/CodeGen/InstrSelection/InstrSelection.cpp +++ b/lib/CodeGen/InstrSelection/InstrSelection.cpp @@ -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; diff --git a/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp b/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp index aac57575cbd..4843a70dce7 100644 --- a/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp +++ b/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp @@ -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; diff --git a/tools/llc/LLCOptions.cpp b/tools/llc/LLCOptions.cpp index 6ba14277202..1f367a2d183 100644 --- a/tools/llc/LLCOptions.cpp +++ b/tools/llc/LLCOptions.cpp @@ -21,7 +21,7 @@ #include "llvm/Support/ProgramOptions.h" #include "llvm/Support/ProgramOption.h" -#include "llvm/LLC/LLCOptions.h" +#include "LLCOptions.h" //--------------------------------------------------------------------------- diff --git a/tools/llc/LLCOptions.h b/tools/llc/LLCOptions.h new file mode 100644 index 00000000000..cad1d4f9353 --- /dev/null +++ b/tools/llc/LLCOptions.h @@ -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 diff --git a/tools/llc/llc.cpp b/tools/llc/llc.cpp index 6ac3175f2b2..4bf26d5a16f 100644 --- a/tools/llc/llc.cpp +++ b/tools/llc/llc.cpp @@ -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; -} -