Update to LLVM 3.5a.

Change-Id: Ifadecab779f128e62e430c2b4f6ddd84953ed617
diff --git a/tools/bugpoint/BugDriver.cpp b/tools/bugpoint/BugDriver.cpp
index a5436ba..2d1b903 100644
--- a/tools/bugpoint/BugDriver.cpp
+++ b/tools/bugpoint/BugDriver.cpp
@@ -17,7 +17,7 @@
 #include "ToolRunner.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IRReader/IRReader.h"
-#include "llvm/Linker.h"
+#include "llvm/Linker/Linker.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FileUtilities.h"
@@ -122,7 +122,7 @@
   outs() << "Read input file      : '" << Filenames[0] << "'\n";
 
   for (unsigned i = 1, e = Filenames.size(); i != e; ++i) {
-    OwningPtr<Module> M(ParseInputFile(Filenames[i], Context));
+    std::unique_ptr<Module> M(ParseInputFile(Filenames[i], Context));
     if (M.get() == 0) return true;
 
     outs() << "Linking in input file: '" << Filenames[i] << "'\n";
diff --git a/tools/bugpoint/BugDriver.h b/tools/bugpoint/BugDriver.h
index 27b37f4..c01bbe5 100644
--- a/tools/bugpoint/BugDriver.h
+++ b/tools/bugpoint/BugDriver.h
@@ -16,7 +16,7 @@
 #ifndef BUGDRIVER_H
 #define BUGDRIVER_H
 
-#include "llvm/ADT/ValueMap.h"
+#include "llvm/IR/ValueMap.h"
 #include "llvm/Transforms/Utils/ValueMapper.h"
 #include <string>
 #include <vector>
diff --git a/tools/bugpoint/CMakeLists.txt b/tools/bugpoint/CMakeLists.txt
index 0000d97..d71e097 100644
--- a/tools/bugpoint/CMakeLists.txt
+++ b/tools/bugpoint/CMakeLists.txt
@@ -1,5 +1,24 @@
-set(LLVM_LINK_COMPONENTS asmparser instrumentation scalaropts ipo
-  linker bitreader bitwriter irreader vectorize objcarcopts)
+set(LLVM_LINK_COMPONENTS
+  Analysis
+  BitWriter
+  CodeGen
+  Core
+  IPA
+  IPO
+  IRReader
+  InstCombine
+  Instrumentation
+  Linker
+  ObjCARCOpts
+  ScalarOpts
+  Support
+  Target
+  TransformUtils
+  Vectorize
+  )
+
+# Support plugins.
+set(LLVM_NO_DEAD_STRIP 1)
 
 add_llvm_tool(bugpoint
   BugDriver.cpp
@@ -13,3 +32,12 @@
   bugpoint.cpp
   )
 set_target_properties(bugpoint PROPERTIES ENABLE_EXPORTS 1)
+
+if(WITH_POLLY AND LINK_POLLY_INTO_TOOLS)
+  target_link_libraries(bugpoint Polly)
+  if(POLLY_LINK_LIBS)
+    foreach(lib ${POLLY_LINK_LIBS})
+      target_link_libraries(bugpoint ${lib})
+    endforeach(lib)
+  endif(POLLY_LINK_LIBS)
+endif(WITH_POLLY AND LINK_POLLY_INTO_TOOLS)
diff --git a/tools/bugpoint/CrashDebugger.cpp b/tools/bugpoint/CrashDebugger.cpp
index b90fc61..bdaa6c9 100644
--- a/tools/bugpoint/CrashDebugger.cpp
+++ b/tools/bugpoint/CrashDebugger.cpp
@@ -15,15 +15,15 @@
 #include "ListReducer.h"
 #include "ToolRunner.h"
 #include "llvm/ADT/SmallPtrSet.h"
-#include "llvm/Analysis/Verifier.h"
+#include "llvm/IR/CFG.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/ValueSymbolTable.h"
+#include "llvm/IR/Verifier.h"
 #include "llvm/Pass.h"
 #include "llvm/PassManager.h"
-#include "llvm/Support/CFG.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FileUtilities.h"
 #include "llvm/Transforms/Scalar.h"
@@ -52,9 +52,9 @@
     // running the "Kept" passes fail when run on the output of the "removed"
     // passes.  If we return true, we update the current module of bugpoint.
     //
-    virtual TestResult doTest(std::vector<std::string> &Removed,
-                              std::vector<std::string> &Kept,
-                              std::string &Error);
+    TestResult doTest(std::vector<std::string> &Removed,
+                      std::vector<std::string> &Kept,
+                      std::string &Error) override;
   };
 }
 
@@ -110,9 +110,9 @@
                                   bool (*testFn)(const BugDriver &, Module *))
       : BD(bd), TestFn(testFn) {}
 
-    virtual TestResult doTest(std::vector<GlobalVariable*> &Prefix,
-                              std::vector<GlobalVariable*> &Kept,
-                              std::string &Error) {
+    TestResult doTest(std::vector<GlobalVariable*> &Prefix,
+                      std::vector<GlobalVariable*> &Kept,
+                      std::string &Error) override {
       if (!Kept.empty() && TestGlobalVariables(Kept))
         return KeepSuffix;
       if (!Prefix.empty() && TestGlobalVariables(Prefix))
@@ -180,9 +180,9 @@
                             bool (*testFn)(const BugDriver &, Module *))
       : BD(bd), TestFn(testFn) {}
 
-    virtual TestResult doTest(std::vector<Function*> &Prefix,
-                              std::vector<Function*> &Kept,
-                              std::string &Error) {
+    TestResult doTest(std::vector<Function*> &Prefix,
+                      std::vector<Function*> &Kept,
+                      std::string &Error) override {
       if (!Kept.empty() && TestFuncs(Kept))
         return KeepSuffix;
       if (!Prefix.empty() && TestFuncs(Prefix))
@@ -253,9 +253,9 @@
                          bool (*testFn)(const BugDriver &, Module *))
       : BD(bd), TestFn(testFn) {}
 
-    virtual TestResult doTest(std::vector<const BasicBlock*> &Prefix,
-                              std::vector<const BasicBlock*> &Kept,
-                              std::string &Error) {
+    TestResult doTest(std::vector<const BasicBlock*> &Prefix,
+                      std::vector<const BasicBlock*> &Kept,
+                      std::string &Error) override {
       if (!Kept.empty() && TestBlocks(Kept))
         return KeepSuffix;
       if (!Prefix.empty() && TestBlocks(Prefix))
@@ -362,9 +362,9 @@
                                bool (*testFn)(const BugDriver &, Module *))
       : BD(bd), TestFn(testFn) {}
 
-    virtual TestResult doTest(std::vector<const Instruction*> &Prefix,
-                              std::vector<const Instruction*> &Kept,
-                              std::string &Error) {
+    TestResult doTest(std::vector<const Instruction*> &Prefix,
+                      std::vector<const Instruction*> &Kept,
+                      std::string &Error) override {
       if (!Kept.empty() && TestInsts(Kept))
         return KeepSuffix;
       if (!Prefix.empty() && TestInsts(Prefix))
diff --git a/tools/bugpoint/ExecutionDriver.cpp b/tools/bugpoint/ExecutionDriver.cpp
index c05c8d7..609de03 100644
--- a/tools/bugpoint/ExecutionDriver.cpp
+++ b/tools/bugpoint/ExecutionDriver.cpp
@@ -404,7 +404,7 @@
   // Remove the intermediate C file
   sys::fs::remove(OutputFile);
 
-  return "./" + SharedObjectFile;
+  return SharedObjectFile;
 }
 
 /// createReferenceFile - calls compileProgram and then records the output
diff --git a/tools/bugpoint/ExtractFunction.cpp b/tools/bugpoint/ExtractFunction.cpp
index 2098928..8bcae8a 100644
--- a/tools/bugpoint/ExtractFunction.cpp
+++ b/tools/bugpoint/ExtractFunction.cpp
@@ -13,13 +13,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "BugDriver.h"
-#include "llvm/Analysis/Verifier.h"
-#include "llvm/Assembly/Writer.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/DataLayout.h"
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Module.h"
+#include "llvm/IR/Verifier.h"
 #include "llvm/Pass.h"
 #include "llvm/PassManager.h"
 #include "llvm/Support/CommandLine.h"
@@ -309,7 +308,7 @@
   for (unsigned i = 0, e = F.size(); i != e; ++i) {
     Function *TNOF = cast<Function>(VMap[F[i]]);
     DEBUG(errs() << "Removing function ");
-    DEBUG(WriteAsOperand(errs(), TNOF, false));
+    DEBUG(TNOF->printAsOperand(errs(), false));
     DEBUG(errs() << "\n");
     TestFunctions.insert(cast<Function>(NewVMap[TNOF]));
     DeleteFunctionBody(TNOF);       // Function is now external in this module!
@@ -330,7 +329,7 @@
       if (Function *SafeFn = globalInitUsesExternalBA(GV)) {
         errs() << "*** Error: when reducing functions, encountered "
                   "the global '";
-        WriteAsOperand(errs(), GV, false);
+        GV->printAsOperand(errs(), false);
         errs() << "' with an initializer that references blockaddresses "
                   "from safe function '" << SafeFn->getName()
                << "' and from test function '" << TestFn->getName() << "'.\n";
diff --git a/tools/bugpoint/LLVMBuild.txt b/tools/bugpoint/LLVMBuild.txt
index 0164355..dda8d62 100644
--- a/tools/bugpoint/LLVMBuild.txt
+++ b/tools/bugpoint/LLVMBuild.txt
@@ -19,4 +19,4 @@
 type = Tool
 name = bugpoint
 parent = Tools
-required_libraries = AsmParser BitReader BitWriter IRReader IPO Instrumentation Linker Scalar ObjCARC
+required_libraries = AsmParser BitReader BitWriter CodeGen IRReader IPO Instrumentation Linker Scalar ObjCARC
diff --git a/tools/bugpoint/Makefile b/tools/bugpoint/Makefile
index 2049321..174f8d2 100644
--- a/tools/bugpoint/Makefile
+++ b/tools/bugpoint/Makefile
@@ -10,6 +10,9 @@
 LEVEL := ../..
 TOOLNAME := bugpoint
 LINK_COMPONENTS := asmparser instrumentation scalaropts ipo linker bitreader \
-                   bitwriter irreader vectorize objcarcopts
+                   bitwriter irreader vectorize objcarcopts codegen
+
+# Support plugins.
+NO_DEAD_STRIP := 1
 
 include $(LEVEL)/Makefile.common
diff --git a/tools/bugpoint/Miscompilation.cpp b/tools/bugpoint/Miscompilation.cpp
index 771ec34..fecae60 100644
--- a/tools/bugpoint/Miscompilation.cpp
+++ b/tools/bugpoint/Miscompilation.cpp
@@ -15,13 +15,13 @@
 #include "BugDriver.h"
 #include "ListReducer.h"
 #include "ToolRunner.h"
-#include "llvm/Analysis/Verifier.h"
 #include "llvm/Config/config.h"   // for HAVE_LINK_R
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/Module.h"
-#include "llvm/Linker.h"
+#include "llvm/IR/Verifier.h"
+#include "llvm/Linker/Linker.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FileUtilities.h"
@@ -48,9 +48,9 @@
   public:
     ReduceMiscompilingPasses(BugDriver &bd) : BD(bd) {}
 
-    virtual TestResult doTest(std::vector<std::string> &Prefix,
-                              std::vector<std::string> &Suffix,
-                              std::string &Error);
+    TestResult doTest(std::vector<std::string> &Prefix,
+                      std::vector<std::string> &Suffix,
+                      std::string &Error) override;
   };
 }
 
@@ -128,8 +128,8 @@
   // Ok, so now we know that the prefix passes work, try running the suffix
   // passes on the result of the prefix passes.
   //
-  OwningPtr<Module> PrefixOutput(ParseInputFile(BitcodeResult,
-                                                BD.getContext()));
+  std::unique_ptr<Module> PrefixOutput(
+      ParseInputFile(BitcodeResult, BD.getContext()));
   if (!PrefixOutput) {
     errs() << BD.getToolName() << ": Error reading bitcode file '"
            << BitcodeResult << "'!\n";
@@ -145,7 +145,8 @@
             << "' passes compile correctly after the '"
             << getPassesString(Prefix) << "' passes: ";
 
-  OwningPtr<Module> OriginalInput(BD.swapProgramIn(PrefixOutput.take()));
+  std::unique_ptr<Module> OriginalInput(
+      BD.swapProgramIn(PrefixOutput.release()));
   if (BD.runPasses(BD.getProgram(), Suffix, BitcodeResult, false/*delete*/,
                    true/*quiet*/)) {
     errs() << " Error running this sequence of passes"
@@ -168,7 +169,7 @@
   // Otherwise, we must not be running the bad pass anymore.
   outs() << " yup.\n";      // No miscompilation!
   // Restore orig program & free test.
-  delete BD.swapProgramIn(OriginalInput.take());
+  delete BD.swapProgramIn(OriginalInput.release());
   return NoFailure;
 }
 
@@ -182,9 +183,9 @@
                                           std::string &))
       : BD(bd), TestFn(F) {}
 
-    virtual TestResult doTest(std::vector<Function*> &Prefix,
-                              std::vector<Function*> &Suffix,
-                              std::string &Error) {
+    TestResult doTest(std::vector<Function*> &Prefix,
+                      std::vector<Function*> &Suffix,
+                      std::string &Error) override {
       if (!Suffix.empty()) {
         bool Ret = TestFuncs(Suffix, Error);
         if (!Error.empty())
@@ -467,9 +468,9 @@
                             const std::vector<Function*> &Fns)
       : BD(bd), TestFn(F), FunctionsBeingTested(Fns) {}
 
-    virtual TestResult doTest(std::vector<BasicBlock*> &Prefix,
-                              std::vector<BasicBlock*> &Suffix,
-                              std::string &Error) {
+    TestResult doTest(std::vector<BasicBlock*> &Prefix,
+                      std::vector<BasicBlock*> &Suffix,
+                      std::string &Error) override {
       if (!Suffix.empty()) {
         bool Ret = TestFuncs(Suffix, Error);
         if (!Error.empty())
diff --git a/tools/bugpoint/OptimizerDriver.cpp b/tools/bugpoint/OptimizerDriver.cpp
index 20c609c..f91f493 100644
--- a/tools/bugpoint/OptimizerDriver.cpp
+++ b/tools/bugpoint/OptimizerDriver.cpp
@@ -16,10 +16,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "BugDriver.h"
-#include "llvm/Analysis/Verifier.h"
 #include "llvm/Bitcode/ReaderWriter.h"
 #include "llvm/IR/DataLayout.h"
 #include "llvm/IR/Module.h"
+#include "llvm/IR/Verifier.h"
 #include "llvm/PassManager.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
@@ -71,7 +71,7 @@
 bool BugDriver::writeProgramToFile(const std::string &Filename,
                                    const Module *M) const {
   std::string ErrInfo;
-  tool_output_file Out(Filename.c_str(), ErrInfo, sys::fs::F_Binary);
+  tool_output_file Out(Filename.c_str(), ErrInfo, sys::fs::F_None);
   if (ErrInfo.empty())
     return writeProgramToFileAux(Out, M);
   return true;
diff --git a/tools/bugpoint/ToolRunner.cpp b/tools/bugpoint/ToolRunner.cpp
index 254d997..f0fb4bf 100644
--- a/tools/bugpoint/ToolRunner.cpp
+++ b/tools/bugpoint/ToolRunner.cpp
@@ -178,16 +178,16 @@
       if (Args) { ToolArgs = *Args; }
     }
 
-    virtual int ExecuteProgram(const std::string &Bitcode,
-                               const std::vector<std::string> &Args,
-                               const std::string &InputFile,
-                               const std::string &OutputFile,
-                               std::string *Error,
-                               const std::vector<std::string> &GCCArgs,
-                               const std::vector<std::string> &SharedLibs =
-                               std::vector<std::string>(),
-                               unsigned Timeout = 0,
-                               unsigned MemoryLimit = 0);
+    int ExecuteProgram(const std::string &Bitcode,
+                       const std::vector<std::string> &Args,
+                       const std::string &InputFile,
+                       const std::string &OutputFile,
+                       std::string *Error,
+                       const std::vector<std::string> &GCCArgs,
+                       const std::vector<std::string> &SharedLibs =
+                       std::vector<std::string>(),
+                       unsigned Timeout = 0,
+                       unsigned MemoryLimit = 0) override;
   };
 }
 
@@ -294,22 +294,22 @@
       const std::string &CompilerCmd, std::vector<std::string> CompArgs) :
       CompilerCommand(CompilerCmd), CompilerArgs(CompArgs) {}
 
-    virtual void compileProgram(const std::string &Bitcode,
-                                std::string *Error,
-                                unsigned Timeout = 0,
-                                unsigned MemoryLimit = 0);
+    void compileProgram(const std::string &Bitcode,
+                        std::string *Error,
+                        unsigned Timeout = 0,
+                        unsigned MemoryLimit = 0) override;
 
-    virtual int ExecuteProgram(const std::string &Bitcode,
-                               const std::vector<std::string> &Args,
-                               const std::string &InputFile,
-                               const std::string &OutputFile,
-                               std::string *Error,
-                               const std::vector<std::string> &GCCArgs =
-                               std::vector<std::string>(),
-                               const std::vector<std::string> &SharedLibs =
-                               std::vector<std::string>(),
-                               unsigned Timeout = 0,
-                               unsigned MemoryLimit = 0) {
+    int ExecuteProgram(const std::string &Bitcode,
+                       const std::vector<std::string> &Args,
+                       const std::string &InputFile,
+                       const std::string &OutputFile,
+                       std::string *Error,
+                       const std::vector<std::string> &GCCArgs =
+                       std::vector<std::string>(),
+                       const std::vector<std::string> &SharedLibs =
+                       std::vector<std::string>(),
+                       unsigned Timeout = 0,
+                       unsigned MemoryLimit = 0) override {
       *Error = "Execution not supported with -compile-custom";
       return -1;
     }
@@ -355,16 +355,16 @@
       const std::string &ExecutionCmd, std::vector<std::string> ExecArgs) :
       ExecutionCommand(ExecutionCmd), ExecutorArgs(ExecArgs) {}
 
-    virtual int ExecuteProgram(const std::string &Bitcode,
-                               const std::vector<std::string> &Args,
-                               const std::string &InputFile,
-                               const std::string &OutputFile,
-                               std::string *Error,
-                               const std::vector<std::string> &GCCArgs,
-                               const std::vector<std::string> &SharedLibs =
-                                 std::vector<std::string>(),
-                               unsigned Timeout = 0,
-                               unsigned MemoryLimit = 0);
+    int ExecuteProgram(const std::string &Bitcode,
+                       const std::vector<std::string> &Args,
+                       const std::string &InputFile,
+                       const std::string &OutputFile,
+                       std::string *Error,
+                       const std::vector<std::string> &GCCArgs,
+                       const std::vector<std::string> &SharedLibs =
+                         std::vector<std::string>(),
+                       unsigned Timeout = 0,
+                       unsigned MemoryLimit = 0) override;
   };
 }
 
@@ -406,7 +406,7 @@
 // code borrowed from:
 // http://oopweb.com/CPP/Documents/CPPHOWTO/Volume/C++Programming-HOWTO-7.html
 static void lexCommand(std::string &Message, const std::string &CommandLine,
-                       std::string &CmdPath, std::vector<std::string> Args) {
+                       std::string &CmdPath, std::vector<std::string> &Args) {
 
   std::string Command = "";
   std::string delimiters = " ";
@@ -584,17 +584,17 @@
       if (Args) { ToolArgs = *Args; }
     }
 
-    virtual int ExecuteProgram(const std::string &Bitcode,
-                               const std::vector<std::string> &Args,
-                               const std::string &InputFile,
-                               const std::string &OutputFile,
-                               std::string *Error,
-                               const std::vector<std::string> &GCCArgs =
-                                 std::vector<std::string>(),
-                               const std::vector<std::string> &SharedLibs =
-                                 std::vector<std::string>(),
-                               unsigned Timeout = 0,
-                               unsigned MemoryLimit = 0);
+    int ExecuteProgram(const std::string &Bitcode,
+                       const std::vector<std::string> &Args,
+                       const std::string &InputFile,
+                       const std::string &OutputFile,
+                       std::string *Error,
+                       const std::vector<std::string> &GCCArgs =
+                         std::vector<std::string>(),
+                       const std::vector<std::string> &SharedLibs =
+                         std::vector<std::string>(),
+                       unsigned Timeout = 0,
+                       unsigned MemoryLimit = 0) override;
   };
 }
 
diff --git a/tools/bugpoint/ToolRunner.h b/tools/bugpoint/ToolRunner.h
index bc2be46..38a5835 100644
--- a/tools/bugpoint/ToolRunner.h
+++ b/tools/bugpoint/ToolRunner.h
@@ -168,29 +168,29 @@
   /// compileProgram - Compile the specified program from bitcode to executable
   /// code.  This does not produce any output, it is only used when debugging
   /// the code generator.  Returns false if the code generator fails.
-  virtual void compileProgram(const std::string &Bitcode, std::string *Error,
-                              unsigned Timeout = 0, unsigned MemoryLimit = 0);
+  void compileProgram(const std::string &Bitcode, std::string *Error,
+                      unsigned Timeout = 0, unsigned MemoryLimit = 0) override;
 
-  virtual int ExecuteProgram(const std::string &Bitcode,
-                             const std::vector<std::string> &Args,
-                             const std::string &InputFile,
-                             const std::string &OutputFile,
-                             std::string *Error,
-                             const std::vector<std::string> &GCCArgs =
-                               std::vector<std::string>(),
-                             const std::vector<std::string> &SharedLibs =
-                                std::vector<std::string>(),
-                             unsigned Timeout = 0,
-                             unsigned MemoryLimit = 0);
+  int ExecuteProgram(const std::string &Bitcode,
+                     const std::vector<std::string> &Args,
+                     const std::string &InputFile,
+                     const std::string &OutputFile,
+                     std::string *Error,
+                     const std::vector<std::string> &GCCArgs =
+                       std::vector<std::string>(),
+                     const std::vector<std::string> &SharedLibs =
+                        std::vector<std::string>(),
+                     unsigned Timeout = 0,
+                     unsigned MemoryLimit = 0) override;
 
   /// OutputCode - Compile the specified program from bitcode to code
   /// understood by the GCC driver (either C or asm).  If the code generator
   /// fails, it sets Error, otherwise, this function returns the type of code
   /// emitted.
-  virtual GCC::FileType OutputCode(const std::string &Bitcode,
-                                   std::string &OutFile, std::string &Error,
-                                   unsigned Timeout = 0,
-                                   unsigned MemoryLimit = 0);
+  GCC::FileType OutputCode(const std::string &Bitcode,
+                           std::string &OutFile, std::string &Error,
+                           unsigned Timeout = 0,
+                           unsigned MemoryLimit = 0) override;
 };
 
 } // End llvm namespace
diff --git a/tools/bugpoint/bugpoint.cpp b/tools/bugpoint/bugpoint.cpp
index 9bc592e..5c03b41 100644
--- a/tools/bugpoint/bugpoint.cpp
+++ b/tools/bugpoint/bugpoint.cpp
@@ -16,12 +16,12 @@
 #include "BugDriver.h"
 #include "ToolRunner.h"
 #include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/LegacyPassNameParser.h"
 #include "llvm/LinkAllIR.h"
 #include "llvm/LinkAllPasses.h"
 #include "llvm/PassManager.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ManagedStatic.h"
-#include "llvm/Support/PassNameParser.h"
 #include "llvm/Support/PluginLoader.h"
 #include "llvm/Support/PrettyStackTrace.h"
 #include "llvm/Support/Process.h"
@@ -34,7 +34,7 @@
 
 using namespace llvm;
 
-static cl::opt<bool> 
+static cl::opt<bool>
 FindBugs("find-bugs", cl::desc("Run many different optimization sequences "
                                "on program to find bugs"), cl::init(false));
 
@@ -63,24 +63,24 @@
 PassList(cl::desc("Passes available:"), cl::ZeroOrMore);
 
 static cl::opt<bool>
-StandardCompileOpts("std-compile-opts", 
+StandardCompileOpts("std-compile-opts",
                    cl::desc("Include the standard compile time optimizations"));
 
 static cl::opt<bool>
-StandardLinkOpts("std-link-opts", 
+StandardLinkOpts("std-link-opts",
                  cl::desc("Include the standard link time optimizations"));
 
 static cl::opt<bool>
 OptLevelO1("O1",
-           cl::desc("Optimization level 1. Similar to llvm-gcc -O1"));
+           cl::desc("Optimization level 1. Identical to 'opt -O1'"));
 
 static cl::opt<bool>
 OptLevelO2("O2",
-           cl::desc("Optimization level 2. Similar to llvm-gcc -O2"));
+           cl::desc("Optimization level 2. Identical to 'opt -O2'"));
 
 static cl::opt<bool>
 OptLevelO3("O3",
-           cl::desc("Optimization level 3. Similar to llvm-gcc -O3"));
+           cl::desc("Optimization level 3. Identical to 'opt -O3'"));
 
 static cl::opt<std::string>
 OverrideTriple("mtriple", cl::desc("Override target triple for module"));
@@ -100,8 +100,8 @@
     BugDriver &D;
   public:
     AddToDriver(BugDriver &_D) : FunctionPassManager(0), D(_D) {}
-    
-    virtual void add(Pass *P) {
+
+    void add(Pass *P) override {
       const void *ID = P->getPassID();
       const PassInfo *PI = PassRegistry::getPassRegistry()->getPassInfo(ID);
       D.addPass(PI->getPassArgument());
@@ -109,13 +109,19 @@
   };
 }
 
+#ifdef LINK_POLLY_INTO_TOOLS
+namespace polly {
+void initializePollyPasses(llvm::PassRegistry &Registry);
+}
+#endif
+
 int main(int argc, char **argv) {
 #ifndef DEBUG_BUGPOINT
   llvm::sys::PrintStackTraceOnErrorSignal();
   llvm::PrettyStackTraceProgram X(argc, argv);
   llvm_shutdown_obj Y;  // Call llvm_shutdown() on exit.
 #endif
-  
+
   // Initialize passes
   PassRegistry &Registry = *PassRegistry::getPassRegistry();
   initializeCore(Registry);
@@ -129,7 +135,11 @@
   initializeInstCombine(Registry);
   initializeInstrumentation(Registry);
   initializeTarget(Registry);
-  
+
+#ifdef LINK_POLLY_INTO_TOOLS
+  polly::initializePollyPasses(Registry);
+#endif
+
   cl::ParseCommandLineOptions(argc, argv,
                               "LLVM automatic testcase reducer. See\nhttp://"
                               "llvm.org/cmds/bugpoint.html"
@@ -158,7 +168,7 @@
   BugDriver D(argv[0], FindBugs, TimeoutValue, MemoryLimit,
               UseValgrind, Context);
   if (D.addSources(InputFilenames)) return 1;
-  
+
   AddToDriver PM(D);
   if (StandardCompileOpts) {
     PassManagerBuilder Builder;
@@ -166,7 +176,7 @@
     Builder.Inliner = createFunctionInliningPass();
     Builder.populateModulePassManager(PM);
   }
-      
+
   if (StandardLinkOpts) {
     PassManagerBuilder Builder;
     Builder.populateLTOPassManager(PM, /*Internalize=*/true,