remove dead code, we're requesting TargetMachine::AssemblyFile here.
[oota-llvm.git] / tools / bugpoint / ExtractFunction.cpp
index c2159dea4b032c846a400dfef6785a6c3c9be629..70011a798b924e92801bf87991e42d8850b85323 100644 (file)
@@ -29,6 +29,7 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/FileUtilities.h"
+#include "llvm/Support/raw_ostream.h"
 #include "llvm/System/Path.h"
 #include "llvm/System/Signals.h"
 #include <set>
@@ -36,6 +37,7 @@ using namespace llvm;
 
 namespace llvm {
   bool DisableSimplifyCFG = false;
+  extern cl::opt<std::string> OutputPrefix;
 } // End llvm namespace
 
 namespace {
@@ -72,9 +74,9 @@ Module *BugDriver::deleteInstructionFromProgram(const Instruction *I,
 
   // If this instruction produces a value, replace any users with null values
   if (isa<StructType>(TheInst->getType()))
-    TheInst->replaceAllUsesWith(Context.getUndef(TheInst->getType()));
-  else if (TheInst->getType() != Type::VoidTy)
-    TheInst->replaceAllUsesWith(Context.getNullValue(TheInst->getType()));
+    TheInst->replaceAllUsesWith(UndefValue::get(TheInst->getType()));
+  else if (TheInst->getType() != Type::getVoidTy(I->getContext()))
+    TheInst->replaceAllUsesWith(Constant::getNullValue(TheInst->getType()));
 
   // Remove the instruction from the program.
   TheInst->getParent()->getInstList().erase(TheInst);
@@ -181,15 +183,16 @@ void llvm::DeleteFunctionBody(Function *F) {
 /// as a constant array.
 static Constant *GetTorInit(std::vector<std::pair<Function*, int> > &TorList) {
   assert(!TorList.empty() && "Don't create empty tor list!");
-  LLVMContext &Context = TorList[0].first->getContext();
   std::vector<Constant*> ArrayElts;
   for (unsigned i = 0, e = TorList.size(); i != e; ++i) {
     std::vector<Constant*> Elts;
-    Elts.push_back(ConstantInt::get(Type::Int32Ty, TorList[i].second));
+    Elts.push_back(ConstantInt::get(
+          Type::getInt32Ty(TorList[i].first->getContext()), TorList[i].second));
     Elts.push_back(TorList[i].first);
-    ArrayElts.push_back(ConstantStruct::get(Elts));
+    ArrayElts.push_back(ConstantStruct::get(TorList[i].first->getContext(),
+                                            Elts, false));
   }
-  return ConstantArray::get(Context.getArrayType(ArrayElts[0]->getType(), 
+  return ConstantArray::get(ArrayType::get(ArrayElts[0]->getType(), 
                                            ArrayElts.size()),
                             ArrayElts);
 }
@@ -320,9 +323,7 @@ llvm::SplitFunctionsOutOfModule(Module *M,
 Module *BugDriver::ExtractMappedBlocksFromModule(const
                                                  std::vector<BasicBlock*> &BBs,
                                                  Module *M) {
-  char *ExtraArg = NULL;
-
-  sys::Path uniqueFilename("bugpoint-extractblocks");
+  sys::Path uniqueFilename(OutputPrefix + "-extractblocks");
   std::string ErrMsg;
   if (uniqueFilename.createTemporaryFileOnDisk(true, &ErrMsg)) {
     outs() << "*** Basic Block extraction failed!\n";
@@ -335,9 +336,7 @@ Module *BugDriver::ExtractMappedBlocksFromModule(const
   sys::RemoveFileOnSignal(uniqueFilename);
 
   std::string ErrorInfo;
-  raw_fd_ostream BlocksToNotExtractFile(uniqueFilename.c_str(),
-                                        /*Binary=*/false, /*Force=*/true,
-                                        ErrorInfo);
+  raw_fd_ostream BlocksToNotExtractFile(uniqueFilename.c_str(), ErrorInfo);
   if (!ErrorInfo.empty()) {
     outs() << "*** Basic Block extraction failed!\n";
     errs() << "Error writing list of blocks to not extract: " << ErrorInfo
@@ -358,9 +357,8 @@ Module *BugDriver::ExtractMappedBlocksFromModule(const
   }
   BlocksToNotExtractFile.close();
 
-  const char *uniqueFN = uniqueFilename.c_str();
-  ExtraArg = (char*)malloc(23 + strlen(uniqueFN));
-  strcat(strcpy(ExtraArg, "--extract-blocks-file="), uniqueFN);
+  std::string uniqueFN = "--extract-blocks-file=" + uniqueFilename.str();
+  const char *ExtraArg = uniqueFN.c_str();
 
   std::vector<const PassInfo*> PI;
   std::vector<BasicBlock *> EmptyBBs; // This parameter is ignored.
@@ -369,7 +367,6 @@ Module *BugDriver::ExtractMappedBlocksFromModule(const
 
   if (uniqueFilename.exists())
     uniqueFilename.eraseFromDisk(); // Free disk space
-  free(ExtraArg);
 
   if (Ret == 0) {
     outs() << "*** Basic Block extraction failed, please report a bug!\n";