Add a "-gcc-tool-args" option. This option acts like the "-tool-args" option,
authorBill Wendling <isanbard@gmail.com>
Mon, 2 Mar 2009 23:13:18 +0000 (23:13 +0000)
committerBill Wendling <isanbard@gmail.com>
Mon, 2 Mar 2009 23:13:18 +0000 (23:13 +0000)
but passes the arguments to the "gcc" invocation instead of to the "llc"
invocation.

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

tools/bugpoint/ExecutionDriver.cpp
tools/bugpoint/ToolRunner.cpp
tools/bugpoint/ToolRunner.h

index b3c802032d5a7d07206f42f5567329492b135383..640fe2829aeb2d8a83a0f7234ba03e44dc6ff3f0 100644 (file)
@@ -111,6 +111,11 @@ namespace {
   SafeToolArgv("safe-tool-args", cl::Positional,
                cl::desc("<safe-tool arguments>..."),
                cl::ZeroOrMore, cl::PositionalEatsArgs);
+
+  cl::list<std::string>
+  GCCToolArgv("gcc-tool-args", cl::Positional,
+              cl::desc("<gcc-tool arguments>..."),
+              cl::ZeroOrMore, cl::PositionalEatsArgs);
 }
 
 //===----------------------------------------------------------------------===//
@@ -132,7 +137,8 @@ bool BugDriver::initializeExecutionEnvironment() {
   case AutoPick:
     InterpreterSel = RunCBE;
     Interpreter =
-      AbstractInterpreter::createCBE(getToolName(), Message, &ToolArgv);
+      AbstractInterpreter::createCBE(getToolName(), Message, &ToolArgv,
+                                     &GCCToolArgv);
     if (!Interpreter) {
       InterpreterSel = RunJIT;
       Interpreter = AbstractInterpreter::createJIT(getToolName(), Message,
@@ -141,7 +147,7 @@ bool BugDriver::initializeExecutionEnvironment() {
     if (!Interpreter) {
       InterpreterSel = RunLLC;
       Interpreter = AbstractInterpreter::createLLC(getToolName(), Message,
-                                                   &ToolArgv);
+                                                   &ToolArgv, &GCCToolArgv);
     }
     if (!Interpreter) {
       InterpreterSel = RunLLI;
@@ -160,7 +166,7 @@ bool BugDriver::initializeExecutionEnvironment() {
   case RunLLC:
   case LLC_Safe:
     Interpreter = AbstractInterpreter::createLLC(getToolName(), Message,
-                                                 &ToolArgv);
+                                                 &ToolArgv, &GCCToolArgv);
     break;
   case RunJIT:
     Interpreter = AbstractInterpreter::createJIT(getToolName(), Message,
@@ -169,7 +175,7 @@ bool BugDriver::initializeExecutionEnvironment() {
   case RunCBE:
   case CBE_bug:
     Interpreter = AbstractInterpreter::createCBE(getToolName(), Message,
-                                                 &ToolArgv);
+                                                 &ToolArgv, &GCCToolArgv);
     break;
   case Custom:
     Interpreter = AbstractInterpreter::createCustom(getToolName(), Message,
@@ -196,7 +202,8 @@ bool BugDriver::initializeExecutionEnvironment() {
       SafeInterpreterSel = RunLLC;
       SafeToolArgs.push_back("--relocation-model=pic");
       SafeInterpreter = AbstractInterpreter::createLLC(Path, Message,
-                                                       &SafeToolArgs);
+                                                       &SafeToolArgs,
+                                                       &GCCToolArgv);
     }
 
     // In "llc-safe" mode, default to using LLC as the "safe" backend.
@@ -205,7 +212,8 @@ bool BugDriver::initializeExecutionEnvironment() {
       SafeInterpreterSel = RunLLC;
       SafeToolArgs.push_back("--relocation-model=pic");
       SafeInterpreter = AbstractInterpreter::createLLC(Path, Message,
-                                                       &SafeToolArgs);
+                                                       &SafeToolArgs,
+                                                       &GCCToolArgv);
     }
 
     // Pick a backend that's different from the test backend. The JIT and
@@ -215,7 +223,8 @@ bool BugDriver::initializeExecutionEnvironment() {
         InterpreterSel != RunCBE) {
       SafeInterpreterSel = RunCBE;
       SafeInterpreter = AbstractInterpreter::createCBE(Path, Message,
-                                                       &SafeToolArgs);
+                                                       &SafeToolArgs,
+                                                       &GCCToolArgv);
     }
     if (!SafeInterpreter &&
         InterpreterSel != RunLLC &&
@@ -223,7 +232,8 @@ bool BugDriver::initializeExecutionEnvironment() {
       SafeInterpreterSel = RunLLC;
       SafeToolArgs.push_back("--relocation-model=pic");
       SafeInterpreter = AbstractInterpreter::createLLC(Path, Message,
-                                                       &SafeToolArgs);
+                                                       &SafeToolArgs,
+                                                       &GCCToolArgv);
     }
     if (!SafeInterpreter) {
       SafeInterpreterSel = AutoPick;
@@ -233,11 +243,13 @@ bool BugDriver::initializeExecutionEnvironment() {
   case RunLLC:
     SafeToolArgs.push_back("--relocation-model=pic");
     SafeInterpreter = AbstractInterpreter::createLLC(Path, Message,
-                                                     &SafeToolArgs);
+                                                     &SafeToolArgs,
+                                                     &GCCToolArgv);
     break;
   case RunCBE:
     SafeInterpreter = AbstractInterpreter::createCBE(Path, Message,
-                                                     &SafeToolArgs);
+                                                     &SafeToolArgs,
+                                                     &GCCToolArgv);
     break;
   case Custom:
     SafeInterpreter = AbstractInterpreter::createCustom(Path, Message,
@@ -250,7 +262,7 @@ bool BugDriver::initializeExecutionEnvironment() {
   }
   if (!SafeInterpreter) { std::cout << Message << "\nExiting.\n"; exit(1); }
   
-  gcc = GCC::create(getToolName(), Message);
+  gcc = GCC::create(getToolName(), Message, &GCCToolArgv);
   if (!gcc) { std::cout << Message << "\nExiting.\n"; exit(1); }
 
   // If there was an error creating the selected interpreter, quit with error.
@@ -406,7 +418,7 @@ bool BugDriver::createReferenceFile(Module *M, const std::string &Filename) {
   }
   try {
     ReferenceOutputFile = executeProgramSafely(Filename);
-    std::cout << "Reference output is: " << ReferenceOutputFile << "\n\n";
+    std::cout << "\nReference output is: " << ReferenceOutputFile << "\n\n";
   } catch (ToolExecutionError &TEE) {
     std::cerr << TEE.what();
     if (Interpreter != SafeInterpreter) {
index f6a151c337144450dd86e61595da9a186abe1842..7c669ef92e60efb41999c839364459559450a21c 100644 (file)
@@ -344,7 +344,8 @@ int LLC::ExecuteProgram(const std::string &Bitcode,
   FileRemover OutFileRemover(OutputAsmFile);
 
   std::vector<std::string> GCCArgs(ArgsForGCC);
-  GCCArgs.insert(GCCArgs.end(),SharedLibs.begin(),SharedLibs.end());
+  GCCArgs.insert(GCCArgs.end(), SharedLibs.begin(), SharedLibs.end());
+  GCCArgs.insert(GCCArgs.end(), gccArgs.begin(), gccArgs.end());
 
   // Assuming LLC worked, compile the result with GCC and run it.
   return gcc->ExecuteProgram(OutputAsmFile.toString(), Args, GCC::AsmFile,
@@ -356,7 +357,8 @@ int LLC::ExecuteProgram(const std::string &Bitcode,
 ///
 LLC *AbstractInterpreter::createLLC(const std::string &ProgramPath,
                                     std::string &Message,
-                                    const std::vector<std::string> *Args) {
+                                    const std::vector<std::string> *Args,
+                                    const std::vector<std::string> *GCCArgs) {
   std::string LLCPath = FindExecutable("llc", ProgramPath).toString();
   if (LLCPath.empty()) {
     Message = "Cannot find `llc' in executable directory or PATH!\n";
@@ -364,12 +366,12 @@ LLC *AbstractInterpreter::createLLC(const std::string &ProgramPath,
   }
 
   Message = "Found llc: " + LLCPath + "\n";
-  GCC *gcc = GCC::create(ProgramPath, Message);
+  GCC *gcc = GCC::create(ProgramPath, Message, GCCArgs);
   if (!gcc) {
     std::cerr << Message << "\n";
     exit(1);
   }
-  return new LLC(LLCPath, gcc, Args);
+  return new LLC(LLCPath, gcc, Args, GCCArgs);
 }
 
 //===---------------------------------------------------------------------===//
@@ -509,7 +511,8 @@ int CBE::ExecuteProgram(const std::string &Bitcode,
   FileRemover CFileRemove(OutputCFile);
 
   std::vector<std::string> GCCArgs(ArgsForGCC);
-  GCCArgs.insert(GCCArgs.end(),SharedLibs.begin(),SharedLibs.end());
+  GCCArgs.insert(GCCArgs.end(), SharedLibs.begin(), SharedLibs.end());
+
   return gcc->ExecuteProgram(OutputCFile.toString(), Args, GCC::CFile,
                              InputFile, OutputFile, GCCArgs,
                              Timeout, MemoryLimit);
@@ -519,7 +522,8 @@ int CBE::ExecuteProgram(const std::string &Bitcode,
 ///
 CBE *AbstractInterpreter::createCBE(const std::string &ProgramPath,
                                     std::string &Message,
-                                    const std::vector<std::string> *Args) {
+                                    const std::vector<std::string> *Args,
+                                    const std::vector<std::string> *GCCArgs) {
   sys::Path LLCPath = FindExecutable("llc", ProgramPath);
   if (LLCPath.isEmpty()) {
     Message =
@@ -528,7 +532,7 @@ CBE *AbstractInterpreter::createCBE(const std::string &ProgramPath,
   }
 
   Message = "Found llc: " + LLCPath.toString() + "\n";
-  GCC *gcc = GCC::create(ProgramPath, Message);
+  GCC *gcc = GCC::create(ProgramPath, Message, GCCArgs);
   if (!gcc) {
     std::cerr << Message << "\n";
     exit(1);
@@ -551,6 +555,10 @@ int GCC::ExecuteProgram(const std::string &ProgramFile,
 
   GCCArgs.push_back(GCCPath.c_str());
 
+  for (std::vector<std::string>::const_iterator
+         I = gccArgs.begin(), E = gccArgs.end(); I != E; ++I)
+    GCCArgs.push_back(I->c_str());
+
   // Specify -x explicitly in case the extension is wonky
   GCCArgs.push_back("-x");
   if (fileType == CFile) {
@@ -725,7 +733,8 @@ int GCC::MakeSharedObject(const std::string &InputFile, FileType fileType,
 
 /// create - Try to find the `gcc' executable
 ///
-GCC *GCC::create(const std::string &ProgramPath, std::string &Message) {
+GCC *GCC::create(const std::string &ProgramPath, std::string &Message,
+                 const std::vector<std::string> *Args) {
   sys::Path GCCPath = FindExecutable("gcc", ProgramPath);
   if (GCCPath.isEmpty()) {
     Message = "Cannot find `gcc' in executable directory or PATH!\n";
@@ -737,5 +746,5 @@ GCC *GCC::create(const std::string &ProgramPath, std::string &Message) {
     RemoteClientPath = FindExecutable(RemoteClient.c_str(), ProgramPath);
 
   Message = "Found gcc: " + GCCPath.toString() + "\n";
-  return new GCC(GCCPath, RemoteClientPath);
+  return new GCC(GCCPath, RemoteClientPath, Args);
 }
index c7ec1c5da6364f473c8f3044f5b4937f23c542f6..721f66c126cced43f2d887ac000c543657db1f13 100644 (file)
@@ -43,14 +43,19 @@ public:
 // GCC abstraction
 //
 class GCC {
-  sys::Path GCCPath;          // The path to the gcc executable
-  sys::Path RemoteClientPath; // The path to the rsh / ssh executable
-  GCC(const sys::Path &gccPath, const sys::Path &RemotePath)
-    : GCCPath(gccPath), RemoteClientPath(RemotePath) { }
+  sys::Path GCCPath;                // The path to the gcc executable.
+  sys::Path RemoteClientPath;       // The path to the rsh / ssh executable.
+  std::vector<std::string> gccArgs; // GCC-specific arguments.
+  GCC(const sys::Path &gccPath, const sys::Path &RemotePath,
+      const std::vector<std::string> *GCCArgs)
+    : GCCPath(gccPath), RemoteClientPath(RemotePath) {
+    if (GCCArgs) gccArgs = *GCCArgs;
+  }
 public:
   enum FileType { AsmFile, CFile };
 
-  static GCC *create(const std::string &ProgramPath, std::string &Message);
+  static GCC *create(const std::string &ProgramPath, std::string &Message,
+                     const std::vector<std::string> *Args);
 
   /// ExecuteProgram - Execute the program specified by "ProgramFile" (which is
   /// either a .s file, or a .c file, specified by FileType), with the specified
@@ -86,9 +91,11 @@ public:
 class AbstractInterpreter {
 public:
   static CBE *createCBE(const std::string &ProgramPath, std::string &Message,
-                        const std::vector<std::string> *Args = 0);
+                        const std::vector<std::string> *Args = 0,
+                        const std::vector<std::string> *GCCArgs = 0);
   static LLC *createLLC(const std::string &ProgramPath, std::string &Message,
-                        const std::vector<std::string> *Args = 0);
+                        const std::vector<std::string> *Args = 0,
+                        const std::vector<std::string> *GCCArgs = 0);
 
   static AbstractInterpreter* createLLI(const std::string &ProgramPath,
                                         std::string &Message,
@@ -139,14 +146,15 @@ public:
 // CBE Implementation of AbstractIntepreter interface
 //
 class CBE : public AbstractInterpreter {
-  sys::Path LLCPath;          // The path to the `llc' executable
-  std::vector<std::string> ToolArgs; // Extra args to pass to LLC
+  sys::Path LLCPath;                 // The path to the `llc' executable.
+  std::vector<std::string> ToolArgs; // Extra args to pass to LLC.
   GCC *gcc;
 public:
   CBE(const sys::Path &llcPath, GCC *Gcc,
-      const std::vector<std::string> *Args) : LLCPath(llcPath), gcc(Gcc) {
+      const std::vector<std::string> *Args)
+    : LLCPath(llcPath), gcc(Gcc) {
     ToolArgs.clear ();
-    if (Args) { ToolArgs = *Args; }
+    if (Args) ToolArgs = *Args;
   }
   ~CBE() { delete gcc; }
 
@@ -180,14 +188,18 @@ public:
 // LLC Implementation of AbstractIntepreter interface
 //
 class LLC : public AbstractInterpreter {
-  std::string LLCPath;          // The path to the LLC executable
-  std::vector<std::string> ToolArgs; // Extra args to pass to LLC
+  std::string LLCPath;               // The path to the LLC executable.
+  std::vector<std::string> ToolArgs; // Extra args to pass to LLC.
+  std::vector<std::string> gccArgs;  // Extra args to pass to GCC.
   GCC *gcc;
 public:
   LLC(const std::string &llcPath, GCC *Gcc,
-    const std::vector<std::string> *Args) : LLCPath(llcPath), gcc(Gcc) {
-    ToolArgs.clear ();
-    if (Args) { ToolArgs = *Args; }
+      const std::vector<std::string> *Args,
+      const std::vector<std::string> *GCCArgs)
+    : LLCPath(llcPath), gcc(Gcc) {
+    ToolArgs.clear();
+    if (Args) ToolArgs = *Args;
+    if (GCCArgs) gccArgs = *GCCArgs;
   }
   ~LLC() { delete gcc; }