[llvm] r303437 - Rewrite llvm-lto's codegen() using ThinCodeGenerator::run(). NFC-ish.
Adrian Prantl via llvm-commits
llvm-commits at lists.llvm.org
Fri May 19 10:54:58 PDT 2017
Author: adrian
Date: Fri May 19 12:54:58 2017
New Revision: 303437
URL: http://llvm.org/viewvc/llvm-project?rev=303437&view=rev
Log:
Rewrite llvm-lto's codegen() using ThinCodeGenerator::run(). NFC-ish.
Differential Revision: https://reviews.llvm.org/D33360
Modified:
llvm/trunk/tools/llvm-lto/llvm-lto.cpp
Modified: llvm/trunk/tools/llvm-lto/llvm-lto.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-lto/llvm-lto.cpp?rev=303437&r1=303436&r2=303437&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-lto/llvm-lto.cpp (original)
+++ llvm/trunk/tools/llvm-lto/llvm-lto.cpp Fri May 19 12:54:58 2017
@@ -669,24 +669,30 @@ private:
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();
}
}
More information about the llvm-commits
mailing list