add support for bugpointing the integrated assembler. Something like this
authorChris Lattner <sabre@nondot.org>
Tue, 16 Mar 2010 06:41:47 +0000 (06:41 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 16 Mar 2010 06:41:47 +0000 (06:41 +0000)
works for me: bugpoint Output/bisort.llvm.bc -run-llc-ia -safe-run-llc

This uses llc with the integrated assembler as the test compiler and llc
without it as the safe compiler.

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

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

index feda331177b166a62536526ccf85c0e882a029ca..7228c01567a92b2dbd28685a22b2a4fb85972793 100644 (file)
@@ -28,7 +28,7 @@ namespace {
   // for miscompilation.
   //
   enum OutputType {
-    AutoPick, RunLLI, RunJIT, RunLLC, RunCBE, CBE_bug, LLC_Safe, Custom
+    AutoPick, RunLLI, RunJIT, RunLLC, RunLLCIA, RunCBE, CBE_bug, LLC_Safe,Custom
   };
 
   cl::opt<double>
@@ -45,6 +45,8 @@ namespace {
                                        "Execute with the interpreter"),
                             clEnumValN(RunJIT, "run-jit", "Execute with JIT"),
                             clEnumValN(RunLLC, "run-llc", "Compile with LLC"),
+                            clEnumValN(RunLLCIA, "run-llc-ia",
+                                  "Compile with LLC with integrated assembler"),
                             clEnumValN(RunCBE, "run-cbe", "Compile with CBE"),
                             clEnumValN(CBE_bug,"cbe-bug", "Find CBE bugs"),
                             clEnumValN(LLC_Safe, "llc-safe", "Use LLC for all"),
@@ -168,9 +170,11 @@ bool BugDriver::initializeExecutionEnvironment() {
                                                  &ToolArgv);
     break;
   case RunLLC:
+  case RunLLCIA:
   case LLC_Safe:
     Interpreter = AbstractInterpreter::createLLC(getToolName(), Message,
-                                                 &ToolArgv, &GCCToolArgv);
+                                                 &ToolArgv, &GCCToolArgv,
+                                                 InterpreterSel == RunLLCIA);
     break;
   case RunJIT:
     Interpreter = AbstractInterpreter::createJIT(getToolName(), Message,
@@ -244,10 +248,12 @@ bool BugDriver::initializeExecutionEnvironment() {
     }
     break;
   case RunLLC:
+  case RunLLCIA:
     SafeToolArgs.push_back("--relocation-model=pic");
     SafeInterpreter = AbstractInterpreter::createLLC(Path.c_str(), Message,
                                                      &SafeToolArgs,
-                                                     &GCCToolArgv);
+                                                     &GCCToolArgv,
+                                                SafeInterpreterSel == RunLLCIA);
     break;
   case RunCBE:
     SafeInterpreter = AbstractInterpreter::createCBE(Path.c_str(), Message,
index 645776eafdb9d051d3d0c4071f10691bc7d5f956..62df0f1dff0724de96a986163b9bc4a1cf9b8272 100644 (file)
@@ -141,7 +141,7 @@ static void ProcessFailure(sys::Path ProgPath, const char** Args) {
   for (const char **Arg = Args; *Arg; ++Arg)
     OS << " " << *Arg;
   OS << "\n";
-
+  
   // Rerun the compiler, capturing any error messages to print them.
   sys::Path ErrorFilename("bugpoint.program_error_messages");
   std::string ErrMsg;
@@ -352,7 +352,8 @@ AbstractInterpreter *AbstractInterpreter::createCustom(
 //
 GCC::FileType LLC::OutputCode(const std::string &Bitcode, 
                               sys::Path &OutputAsmFile) {
-  sys::Path uniqueFile(Bitcode+".llc.s");
+  const char *Suffix = (UseIntegratedAssembler ? ".llc.o" : ".llc.s");
+  sys::Path uniqueFile(Bitcode + Suffix);
   std::string ErrMsg;
   if (uniqueFile.makeUnique(true, &ErrMsg)) {
     errs() << "Error making unique filename: " << ErrMsg << "\n";
@@ -360,18 +361,23 @@ GCC::FileType LLC::OutputCode(const std::string &Bitcode,
   }
   OutputAsmFile = uniqueFile;
   std::vector<const char *> LLCArgs;
-  LLCArgs.push_back (LLCPath.c_str());
+  LLCArgs.push_back(LLCPath.c_str());
 
   // Add any extra LLC args.
   for (unsigned i = 0, e = ToolArgs.size(); i != e; ++i)
     LLCArgs.push_back(ToolArgs[i].c_str());
 
-  LLCArgs.push_back ("-o");
-  LLCArgs.push_back (OutputAsmFile.c_str()); // Output to the Asm file
-  LLCArgs.push_back (Bitcode.c_str());      // This is the input bitcode
+  LLCArgs.push_back("-o");
+  LLCArgs.push_back(OutputAsmFile.c_str()); // Output to the Asm file
+  LLCArgs.push_back(Bitcode.c_str());      // This is the input bitcode
+  
+  if (UseIntegratedAssembler)
+    LLCArgs.push_back("-filetype=obj");
+  
   LLCArgs.push_back (0);
 
-  outs() << "<llc>"; outs().flush();
+  outs() << (UseIntegratedAssembler ? "<llc-ia>" : "<llc>");
+  outs().flush();
   DEBUG(errs() << "\nAbout to run:\t";
         for (unsigned i=0, e = LLCArgs.size()-1; i != e; ++i)
           errs() << " " << LLCArgs[i];
@@ -381,7 +387,7 @@ GCC::FileType LLC::OutputCode(const std::string &Bitcode,
                             sys::Path(), sys::Path(), sys::Path()))
     ProcessFailure(sys::Path(LLCPath), &LLCArgs[0]);
 
-  return GCC::AsmFile;                              
+  return UseIntegratedAssembler ? GCC::ObjectFile : GCC::AsmFile;
 }
 
 void LLC::compileProgram(const std::string &Bitcode) {
@@ -400,7 +406,7 @@ int LLC::ExecuteProgram(const std::string &Bitcode,
                         unsigned MemoryLimit) {
 
   sys::Path OutputAsmFile;
-  OutputCode(Bitcode, OutputAsmFile);
+  GCC::FileType FileKind = OutputCode(Bitcode, OutputAsmFile);
   FileRemover OutFileRemover(OutputAsmFile, !SaveTemps);
 
   std::vector<std::string> GCCArgs(ArgsForGCC);
@@ -408,7 +414,7 @@ int LLC::ExecuteProgram(const std::string &Bitcode,
   GCCArgs.insert(GCCArgs.end(), gccArgs.begin(), gccArgs.end());
 
   // Assuming LLC worked, compile the result with GCC and run it.
-  return gcc->ExecuteProgram(OutputAsmFile.str(), Args, GCC::AsmFile,
+  return gcc->ExecuteProgram(OutputAsmFile.str(), Args, FileKind,
                              InputFile, OutputFile, GCCArgs,
                              Timeout, MemoryLimit);
 }
@@ -418,7 +424,8 @@ int LLC::ExecuteProgram(const std::string &Bitcode,
 LLC *AbstractInterpreter::createLLC(const char *Argv0,
                                     std::string &Message,
                                     const std::vector<std::string> *Args,
-                                    const std::vector<std::string> *GCCArgs) {
+                                    const std::vector<std::string> *GCCArgs,
+                                    bool UseIntegratedAssembler) {
   std::string LLCPath =
     FindExecutable("llc", Argv0, (void *)(intptr_t)&createLLC).str();
   if (LLCPath.empty()) {
@@ -432,7 +439,7 @@ LLC *AbstractInterpreter::createLLC(const char *Argv0,
     errs() << Message << "\n";
     exit(1);
   }
-  return new LLC(LLCPath, gcc, Args, GCCArgs);
+  return new LLC(LLCPath, gcc, Args, GCCArgs, UseIntegratedAssembler);
 }
 
 //===---------------------------------------------------------------------===//
@@ -605,17 +612,14 @@ CBE *AbstractInterpreter::createCBE(const char *Argv0,
 // GCC abstraction
 //
 
-static bool
-IsARMArchitecture(std::vector<std::string> Args)
-{
+static bool IsARMArchitecture(std::vector<std::string> Args) {
   for (std::vector<std::string>::const_iterator
          I = Args.begin(), E = Args.end(); I != E; ++I) {
     StringRef S(*I);
     if (!S.equals_lower("-arch")) {
       ++I;
-      if (I != E && !S.substr(0, strlen("arm")).equals_lower("arm")) {
+      if (I != E && !S.substr(0, strlen("arm")).equals_lower("arm"))
         return true;
-      }
     }
   }
 
@@ -634,26 +638,33 @@ int GCC::ExecuteProgram(const std::string &ProgramFile,
 
   GCCArgs.push_back(GCCPath.c_str());
 
+  if (TargetTriple.getArch() == Triple::x86)
+    GCCArgs.push_back("-m32");
+
   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) {
-    GCCArgs.push_back("c");
-    GCCArgs.push_back("-fno-strict-aliasing");
-  } else {
-    GCCArgs.push_back("assembler");
-
-    // For ARM architectures we don't want this flag. bugpoint isn't
-    // explicitly told what architecture it is working on, so we get
-    // it from gcc flags
-    if ((TargetTriple.getOS() == Triple::Darwin) &&
-        !IsARMArchitecture(ArgsForGCC))
-      GCCArgs.push_back("-force_cpusubtype_ALL");
+  if (fileType != ObjectFile) {
+    GCCArgs.push_back("-x");
+    if (fileType == CFile) {
+      GCCArgs.push_back("c");
+      GCCArgs.push_back("-fno-strict-aliasing");
+    } else {
+      GCCArgs.push_back("assembler");
+
+      // For ARM architectures we don't want this flag. bugpoint isn't
+      // explicitly told what architecture it is working on, so we get
+      // it from gcc flags
+      if ((TargetTriple.getOS() == Triple::Darwin) &&
+          !IsARMArchitecture(ArgsForGCC))
+        GCCArgs.push_back("-force_cpusubtype_ALL");
+    }
   }
-  GCCArgs.push_back(ProgramFile.c_str());  // Specify the input filename...
+  
+  GCCArgs.push_back(ProgramFile.c_str());  // Specify the input filename.
+  
   GCCArgs.push_back("-x");
   GCCArgs.push_back("none");
   GCCArgs.push_back("-o");
@@ -765,13 +776,18 @@ int GCC::MakeSharedObject(const std::string &InputFile, FileType fileType,
   
   GCCArgs.push_back(GCCPath.c_str());
 
+  if (TargetTriple.getArch() == Triple::x86)
+    GCCArgs.push_back("-m32");
+
   for (std::vector<std::string>::const_iterator
          I = gccArgs.begin(), E = gccArgs.end(); I != E; ++I)
     GCCArgs.push_back(I->c_str());
 
   // Compile the C/asm file into a shared object
-  GCCArgs.push_back("-x");
-  GCCArgs.push_back(fileType == AsmFile ? "assembler" : "c");
+  if (fileType != ObjectFile) {
+    GCCArgs.push_back("-x");
+    GCCArgs.push_back(fileType == AsmFile ? "assembler" : "c");
+  }
   GCCArgs.push_back("-fno-strict-aliasing");
   GCCArgs.push_back(InputFile.c_str());   // Specify the input filename.
   GCCArgs.push_back("-x");
index 39b0bbfdd5ecdcef0ac17bd98006e0baefcb1e38..0f75e99db4be06e39dfc0492077dca985582ec05 100644 (file)
@@ -58,7 +58,7 @@ class GCC {
     if (GCCArgs) gccArgs = *GCCArgs;
   }
 public:
-  enum FileType { AsmFile, CFile };
+  enum FileType { AsmFile, ObjectFile, CFile };
 
   static GCC *create(std::string &Message,
                      const std::vector<std::string> *Args);
@@ -101,7 +101,8 @@ public:
                         const std::vector<std::string> *GCCArgs = 0);
   static LLC *createLLC(const char *Argv0, std::string &Message,
                         const std::vector<std::string> *Args = 0,
-                        const std::vector<std::string> *GCCArgs = 0);
+                        const std::vector<std::string> *GCCArgs = 0,
+                        bool UseIntegratedAssembler = false);
 
   static AbstractInterpreter* createLLI(const char *Argv0, std::string &Message,
                                         const std::vector<std::string> *Args=0);
@@ -195,11 +196,14 @@ class LLC : public AbstractInterpreter {
   std::vector<std::string> ToolArgs; // Extra args to pass to LLC.
   std::vector<std::string> gccArgs;  // Extra args to pass to GCC.
   GCC *gcc;
+  bool UseIntegratedAssembler;
 public:
   LLC(const std::string &llcPath, GCC *Gcc,
       const std::vector<std::string> *Args,
-      const std::vector<std::string> *GCCArgs)
-    : LLCPath(llcPath), gcc(Gcc) {
+      const std::vector<std::string> *GCCArgs,
+      bool useIntegratedAssembler)
+    : LLCPath(llcPath), gcc(Gcc),
+      UseIntegratedAssembler(useIntegratedAssembler) {
     ToolArgs.clear();
     if (Args) ToolArgs = *Args;
     if (GCCArgs) gccArgs = *GCCArgs;