[llvm-commits] [llvm] r79309 - in /llvm/trunk/tools/bugpoint: BugDriver.cpp Miscompilation.cpp ToolRunner.cpp ToolRunner.h bugpoint.cpp

Daniel Dunbar daniel at zuster.org
Mon Aug 17 20:35:58 PDT 2009


Author: ddunbar
Date: Mon Aug 17 22:35:57 2009
New Revision: 79309

URL: http://llvm.org/viewvc/llvm-project?rev=79309&view=rev
Log:
Change bugpoint to use Triple to make runtime decisions.
 - This is cleaner, and makes bugpoint match the host instead of the build
   architecture.

 - Patch by Sandeep Patel!

Modified:
    llvm/trunk/tools/bugpoint/BugDriver.cpp
    llvm/trunk/tools/bugpoint/Miscompilation.cpp
    llvm/trunk/tools/bugpoint/ToolRunner.cpp
    llvm/trunk/tools/bugpoint/ToolRunner.h
    llvm/trunk/tools/bugpoint/bugpoint.cpp

Modified: llvm/trunk/tools/bugpoint/BugDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/BugDriver.cpp?rev=79309&r1=79308&r2=79309&view=diff

==============================================================================
--- llvm/trunk/tools/bugpoint/BugDriver.cpp (original)
+++ llvm/trunk/tools/bugpoint/BugDriver.cpp Mon Aug 17 22:35:57 2009
@@ -25,9 +25,14 @@
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/SourceMgr.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvm/System/Host.h"
 #include <memory>
 using namespace llvm;
 
+namespace llvm {
+  Triple TargetTriple;
+}
+
 // Anonymous namespace to define command line options for debugging.
 //
 namespace {
@@ -88,6 +93,20 @@
     Result = 0;
   }
   
+  // If we don't have an override triple, use the first one to configure
+  // bugpoint, or use the host triple if none provided.
+  if (Result) {
+    if (TargetTriple.getTriple().empty()) {
+      Triple TheTriple(Result->getTargetTriple());
+
+      if (TheTriple.getTriple().empty())
+        TheTriple.setTriple(sys::getHostTriple());
+        
+      TargetTriple.setTriple(TheTriple.getTriple());
+    }
+
+    Result->setTargetTriple(TargetTriple.getTriple());  // override the triple
+  }
   return Result;
 }
 

Modified: llvm/trunk/tools/bugpoint/Miscompilation.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/Miscompilation.cpp?rev=79309&r1=79308&r2=79309&view=diff

==============================================================================
--- llvm/trunk/tools/bugpoint/Miscompilation.cpp (original)
+++ llvm/trunk/tools/bugpoint/Miscompilation.cpp Mon Aug 17 22:35:57 2009
@@ -14,6 +14,7 @@
 
 #include "BugDriver.h"
 #include "ListReducer.h"
+#include "ToolRunner.h"
 #include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Instructions.h"
@@ -937,13 +938,13 @@
   outs() << '\n';
   outs() << "The shared object was created with:\n  llc -march=c "
          << SafeModuleBC << " -o temporary.c\n"
-         << "  gcc -xc temporary.c -O2 -o " << SharedObject
-#if defined(sparc) || defined(__sparc__) || defined(__sparcv9)
-         << " -G"            // Compile a shared library, `-G' for Sparc
-#else
-         << " -fPIC -shared"       // `-shared' for Linux/X86, maybe others
-#endif
-         << " -fno-strict-aliasing\n";
+         << "  gcc -xc temporary.c -O2 -o " << SharedObject;
+  if (TargetTriple.getArch() == Triple::sparc)
+    outs() << " -G";              // Compile a shared library, `-G' for Sparc
+  else
+    outs() << " -fPIC -shared";   // `-shared' for Linux/X86, maybe others
+
+  outs() << " -fno-strict-aliasing\n";
 
   return false;
 }

Modified: llvm/trunk/tools/bugpoint/ToolRunner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/ToolRunner.cpp?rev=79309&r1=79308&r2=79309&view=diff

==============================================================================
--- llvm/trunk/tools/bugpoint/ToolRunner.cpp (original)
+++ llvm/trunk/tools/bugpoint/ToolRunner.cpp Mon Aug 17 22:35:57 2009
@@ -604,7 +604,6 @@
 // GCC abstraction
 //
 
-#ifdef __APPLE__
 static bool
 IsARMArchitecture(std::vector<std::string> Args)
 {
@@ -620,7 +619,6 @@
 
   return false;
 }
-#endif
 
 int GCC::ExecuteProgram(const std::string &ProgramFile,
                         const std::vector<std::string> &Args,
@@ -645,13 +643,13 @@
     GCCArgs.push_back("-fno-strict-aliasing");
   } else {
     GCCArgs.push_back("assembler");
-#ifdef __APPLE__
+
     // 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 (!IsARMArchitecture(ArgsForGCC))
+    if ((TargetTriple.getOS() == Triple::Darwin) &&
+        !IsARMArchitecture(ArgsForGCC))
       GCCArgs.push_back("-force_cpusubtype_ALL");
-#endif
   }
   GCCArgs.push_back(ProgramFile.c_str());  // Specify the input filename...
   GCCArgs.push_back("-x");
@@ -677,9 +675,8 @@
 #if defined (HAVE_LINK_R)
   GCCArgs.push_back("-Wl,-R.");            // Search this dir for .so files
 #endif
-#ifdef __sparc__
-  GCCArgs.push_back("-mcpu=v9");
-#endif
+  if (TargetTriple.getArch() == Triple::sparc)
+    GCCArgs.push_back("-mcpu=v9");
   GCCArgs.push_back(0);                    // NULL terminator
 
   outs() << "<gcc>"; outs().flush();
@@ -777,27 +774,27 @@
   GCCArgs.push_back(InputFile.c_str());   // Specify the input filename.
   GCCArgs.push_back("-x");
   GCCArgs.push_back("none");
-#if defined(sparc) || defined(__sparc__) || defined(__sparcv9)
-  GCCArgs.push_back("-G");       // Compile a shared library, `-G' for Sparc
-#elif defined(__APPLE__)
-  // link all source files into a single module in data segment, rather than
-  // generating blocks. dynamic_lookup requires that you set 
-  // MACOSX_DEPLOYMENT_TARGET=10.3 in your env.  FIXME: it would be better for
-  // bugpoint to just pass that in the environment of GCC.
-  GCCArgs.push_back("-single_module");
-  GCCArgs.push_back("-dynamiclib");   // `-dynamiclib' for MacOS X/PowerPC
-  GCCArgs.push_back("-undefined");
-  GCCArgs.push_back("dynamic_lookup");
-#else
-  GCCArgs.push_back("-shared");  // `-shared' for Linux/X86, maybe others
-#endif
+  if (TargetTriple.getArch() == Triple::sparc)
+    GCCArgs.push_back("-G");       // Compile a shared library, `-G' for Sparc
+  else if (TargetTriple.getOS() == Triple::Darwin) {
+    // link all source files into a single module in data segment, rather than
+    // generating blocks. dynamic_lookup requires that you set 
+    // MACOSX_DEPLOYMENT_TARGET=10.3 in your env.  FIXME: it would be better for
+    // bugpoint to just pass that in the environment of GCC.
+    GCCArgs.push_back("-single_module");
+    GCCArgs.push_back("-dynamiclib");   // `-dynamiclib' for MacOS X/PowerPC
+    GCCArgs.push_back("-undefined");
+    GCCArgs.push_back("dynamic_lookup");
+  } else
+    GCCArgs.push_back("-shared");  // `-shared' for Linux/X86, maybe others
+
+  if ((TargetTriple.getArch() == Triple::alpha) ||
+      (TargetTriple.getArch() == Triple::x86_64))
+    GCCArgs.push_back("-fPIC");   // Requires shared objs to contain PIC
+
+  if (TargetTriple.getArch() == Triple::sparc)
+    GCCArgs.push_back("-mcpu=v9");
 
-#if defined(__ia64__) || defined(__alpha__) || defined(__amd64__)
-  GCCArgs.push_back("-fPIC");   // Requires shared objs to contain PIC
-#endif
-#ifdef __sparc__
-  GCCArgs.push_back("-mcpu=v9");
-#endif
   GCCArgs.push_back("-o");
   GCCArgs.push_back(OutputFile.c_str()); // Output to the right filename.
   GCCArgs.push_back("-O2");              // Optimize the program a bit.

Modified: llvm/trunk/tools/bugpoint/ToolRunner.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/ToolRunner.h?rev=79309&r1=79308&r2=79309&view=diff

==============================================================================
--- llvm/trunk/tools/bugpoint/ToolRunner.h (original)
+++ llvm/trunk/tools/bugpoint/ToolRunner.h Mon Aug 17 22:35:57 2009
@@ -17,6 +17,7 @@
 #ifndef BUGPOINT_TOOLRUNNER_H
 #define BUGPOINT_TOOLRUNNER_H
 
+#include "llvm/ADT/Triple.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/SystemUtils.h"
 #include <exception>
@@ -25,6 +26,7 @@
 namespace llvm {
 
 extern cl::opt<bool> SaveTemps;
+extern Triple TargetTriple;
 
 class CBE;
 class LLC;

Modified: llvm/trunk/tools/bugpoint/bugpoint.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/bugpoint.cpp?rev=79309&r1=79308&r2=79309&view=diff

==============================================================================
--- llvm/trunk/tools/bugpoint/bugpoint.cpp (original)
+++ llvm/trunk/tools/bugpoint/bugpoint.cpp Mon Aug 17 22:35:57 2009
@@ -66,6 +66,9 @@
 StandardLinkOpts("std-link-opts", 
                  cl::desc("Include the standard link time optimizations"));
 
+static cl::opt<std::string>
+OverrideTriple("mtriple", cl::desc("Override target triple for module"));
+
 /// BugpointIsInterrupted - Set to true when the user presses ctrl-c.
 bool llvm::BugpointIsInterrupted = false;
 
@@ -98,9 +101,15 @@
   sys::SetInterruptFunction(BugpointInterruptFunction);
 
   LLVMContext& Context = getGlobalContext();
+  // If we have an override, set it and then track the triple we want Modules
+  // to use.
+  if (!OverrideTriple.empty())
+    TargetTriple.setTriple(OverrideTriple);
+  outs() << "override triple is " << OverrideTriple << '\n';
+
   BugDriver D(argv[0], AsChild, FindBugs, TimeoutValue, MemoryLimit, Context);
   if (D.addSources(InputFilenames)) return 1;
-
+  
   AddToDriver PM(D);
   if (StandardCompileOpts) {
     createStandardModulePasses(&PM, 3,





More information about the llvm-commits mailing list