Privatize LLCOptions. It had no business being visible to the entire
authorChris Lattner <sabre@nondot.org>
Sun, 22 Jul 2001 04:40:02 +0000 (04:40 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 22 Jul 2001 04:40:02 +0000 (04:40 +0000)
program.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@267 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/InstrSelection.h
include/llvm/LLC/CompileContext.h
lib/CodeGen/InstrSelection/InstrSelection.cpp
lib/Target/SparcV9/InstrSelection/InstrSelection.cpp
tools/llc/LLCOptions.cpp
tools/llc/LLCOptions.h [new file with mode: 0644]
tools/llc/llc.cpp

index 7538a1532b2a0f771834192230960546d1bd1fc0..0873003baf532687ab4dd960255ef51838b5fb83 100644 (file)
 #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);
 
 
 //---------------------------------------------------------------------------
index 91a448b62d01376a7410a87588c769fb47721f13..29e157779284536e8b4c1e94501ad7e5f64e821b 100644 (file)
 #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
index aac57575cbd2d268533231c34b5673423c1bd129..4843a70dce707ef2381fceb0d7a6f46160a870d3 100644 (file)
 
 //*************************** 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;
   
index aac57575cbd2d268533231c34b5673423c1bd129..4843a70dce707ef2381fceb0d7a6f46160a870d3 100644 (file)
 
 //*************************** 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;
   
index 6ba14277202c718ce150600e28e401bfbd056fcc..1f367a2d18382afcbd4bd8ebcc8b47659655a00d 100644 (file)
@@ -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 (file)
index 0000000..cad1d4f
--- /dev/null
@@ -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
index 6ac3175f2b253fde5272ae88d888fb3b9549c986..4bf26d5a16f7ddb934d1d12c13ee96a5df37387a 100644 (file)
 // 
 //**************************************************************************/
 
-//************************** 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 **************************/
-
-class Module;
-class CompileContext;
+CompileContext::~CompileContext() { delete targetMachine; }
 
-
-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;
-}
-