Save temp. bc files when saveTemps flag is true. Use final output file
authorDevang Patel <dpatel@apple.com>
Thu, 26 Oct 2006 20:46:22 +0000 (20:46 +0000)
committerDevang Patel <dpatel@apple.com>
Thu, 26 Oct 2006 20:46:22 +0000 (20:46 +0000)
name supplied by linker to construct temp bc file names.

Remove tabs.

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

include/llvm/LinkTimeOptimizer.h
tools/lto/lto.cpp

index c126bb23620a1a57055257290a2236819c233435..50c1613eb004547935d40dc2a528990ce77e2cde 100644 (file)
@@ -91,8 +91,9 @@ namespace llvm {
                                               NameToSymbolMap &,
                                               std::set<std::string> &) = 0;
     virtual enum LTOStatus optimizeModules(const std::string &,
-                                   std::vector<const char*> &,
-                                   std::string &) = 0;
+                                           std::vector<const char*> &,
+                                           std::string &, bool, 
+                                           const char *) = 0;
     virtual void getTargetTriple(const std::string &, std::string &) = 0;
     virtual void removeModule (const std::string &InputFilename) = 0;
     virtual ~LinkTimeOptimizer() = 0;
@@ -113,8 +114,10 @@ namespace llvm {
                                       std::set<std::string> &references);
     enum LTOStatus optimizeModules(const std::string &OutputFilename,
                                    std::vector<const char*> &exportList,
-                                   std::string &targetTriple);
-    void getTargetTriple(const std::string &InputFilename, std::string &targetTriple);
+                                   std::string &targetTriple, bool saveTemps,
+                                   const char *);
+    void getTargetTriple(const std::string &InputFilename, 
+                         std::string &targetTriple);
     void removeModule (const std::string &InputFilename);
 
     // Constructors and destructors
index b08b1a62dc365d191bd6509644012ed119b3f917..6a7677244e0c939e39cf11490f2ee8d3e82f5ba7 100644 (file)
@@ -129,7 +129,7 @@ LTO::getModule(const std::string &InputFilename)
 /// set corresponding target triplet string.
 void
 LTO::getTargetTriple(const std::string &InputFilename, 
-                                  std::string &targetTriple)
+                     std::string &targetTriple)
 {
   Module *m = getModule(InputFilename);
   if (m)
@@ -142,8 +142,8 @@ LTO::getTargetTriple(const std::string &InputFilename,
 /// Return LTO_READ_SUCCESS if there is no error.
 enum LTOStatus
 LTO::readLLVMObjectFile(const std::string &InputFilename,
-                                      NameToSymbolMap &symbols,
-                                      std::set<std::string> &references)
+                        NameToSymbolMap &symbols,
+                        std::set<std::string> &references)
 {
   Module *m = getModule(InputFilename);
   if (!m)
@@ -316,7 +316,7 @@ LTO::optimize(Module *M, std::ostream &Out,
 
   CodeGenPasses->add(new TargetData(*Target->getTargetData()));
   Target->addPassesToEmitFile(*CodeGenPasses, Out, TargetMachine::AssemblyFile, 
-                            true);
+                              true);
 
   // Run our queue of passes all at once now, efficiently.
   Passes.run(*M);
@@ -337,8 +337,10 @@ LTO::optimize(Module *M, std::ostream &Out,
 /// Return appropriate LTOStatus.
 enum LTOStatus
 LTO::optimizeModules(const std::string &OutputFilename,
-                                   std::vector<const char *> &exportList,
-                                   std::string &targetTriple)
+                     std::vector<const char *> &exportList,
+                     std::string &targetTriple,
+                     bool saveTemps,
+                     const char *FinalOutputFilename)
 {
   if (modules.empty())
     return LTO_NO_WORK;
@@ -352,11 +354,15 @@ LTO::optimizeModules(const std::string &OutputFilename,
     if (theLinker.LinkModules(bigOne, modules[i], errMsg))
       return LTO_MODULE_MERGE_FAILURE;
 
-#if 0
-  // Enable this when -save-temps is used
-  std::ofstream Out("big.bc", io_mode);
-  WriteBytecodeToFile(bigOne, Out, true);
-#endif
+  sys::Path FinalOutputPath(FinalOutputFilename);
+  FinalOutputPath.eraseSuffix();
+
+  if (saveTemps) {
+    std::string tempFileName(FinalOutputPath.c_str());
+    tempFileName += "0.bc";
+    std::ofstream Out(tempFileName.c_str(), io_mode);
+    WriteBytecodeToFile(bigOne, Out, true);
+  }
 
   // Strip leading underscore because it was added to match names
   // seen by linker.
@@ -404,6 +410,13 @@ LTO::optimizeModules(const std::string &OutputFilename,
     return status;
   }
 
+  if (saveTemps) {
+    std::string tempFileName(FinalOutputPath.c_str());
+    tempFileName += "1.bc";
+    std::ofstream Out(tempFileName.c_str(), io_mode);
+    WriteBytecodeToFile(bigOne, Out, true);
+  }
+
   targetTriple = bigOne->getTargetTriple();
 
   // Run GCC to assemble and link the program into native code.