[PATCH] D33360: Rewrite llvm-lto's codegen() using ThinCodeGenerator::run(). NFC-ish.

Adrian Prantl via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 19 09:38:50 PDT 2017


aprantl created this revision.
Herald added a subscriber: inglorion.

This patch rewrites llvm-lto's codegen() using ThinCodeGenerator::run().
The change is NFC-ish (if you pass multiple files, the all files will now be codegen'd first and then written to disk instead of writing each module to disk after it has been codegen'd.

This is supposed to make https://reviews.llvm.org/D33151 simpler.


Repository:
  rL LLVM

https://reviews.llvm.org/D33360

Files:
  tools/llvm-lto/llvm-lto.cpp


Index: tools/llvm-lto/llvm-lto.cpp
===================================================================
--- tools/llvm-lto/llvm-lto.cpp
+++ tools/llvm-lto/llvm-lto.cpp
@@ -669,24 +669,30 @@
     if (!ThinLTOIndex.empty())
       errs() << "Warning: -thinlto-index ignored for codegen stage";
 
+    std::vector<std::unique_ptr<MemoryBuffer>> InputBuffers;
     for (auto &Filename : InputFilenames) {
       LLVMContext Ctx;
-      auto TheModule = loadModule(Filename, Ctx);
-
-      auto Buffer = ThinGenerator.codegen(*TheModule);
+      auto InputOrErr = MemoryBuffer::getFile(Filename);
+      error(InputOrErr, "error " + CurrentActivity);
+      InputBuffers.push_back(std::move(*InputOrErr));
+      ThinGenerator.addModule(Filename, InputBuffers.back()->getBuffer());
+    }
+    ThinGenerator.setCodeGenOnly(true);
+    ThinGenerator.run();
+    for (auto BinName :
+         zip(ThinGenerator.getProducedBinaries(), InputFilenames)) {
       std::string OutputName = OutputFilename;
-      if (OutputName.empty()) {
-        OutputName = Filename + ".thinlto.o";
-      }
-      if (OutputName == "-") {
-        outs() << Buffer->getBuffer();
+      if (OutputName.empty())
+        OutputName = std::get<1>(BinName) + ".thinlto.o";
+      else if (OutputName == "-") {
+        outs() << std::get<0>(BinName)->getBuffer();
         return;
       }
 
       std::error_code EC;
       raw_fd_ostream OS(OutputName, EC, sys::fs::OpenFlags::F_None);
       error(EC, "error opening the file '" + OutputName + "'");
-      OS << Buffer->getBuffer();
+      OS << std::get<0>(BinName)->getBuffer();
     }
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33360.99579.patch
Type: text/x-patch
Size: 1621 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170519/d1536dc8/attachment.bin>


More information about the llvm-commits mailing list