llvm.org GIT mirror llvm / 3770b2b
Rewrite llvm-lto's codegen() using ThinCodeGenerator::run(). NFC-ish. Differential Revision: https://reviews.llvm.org/D33360 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@303437 91177308-0d34-0410-b5e6-96231b3b80d8 Adrian Prantl 3 years ago
1 changed file(s) with 15 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
668668 if (!ThinLTOIndex.empty())
669669 errs() << "Warning: -thinlto-index ignored for codegen stage";
670670
671 std::vector> InputBuffers;
671672 for (auto &Filename : InputFilenames) {
672673 LLVMContext Ctx;
673 auto TheModule = loadModule(Filename, Ctx);
674
675 auto Buffer = ThinGenerator.codegen(*TheModule);
674 auto InputOrErr = MemoryBuffer::getFile(Filename);
675 error(InputOrErr, "error " + CurrentActivity);
676 InputBuffers.push_back(std::move(*InputOrErr));
677 ThinGenerator.addModule(Filename, InputBuffers.back()->getBuffer());
678 }
679 ThinGenerator.setCodeGenOnly(true);
680 ThinGenerator.run();
681 for (auto BinName :
682 zip(ThinGenerator.getProducedBinaries(), InputFilenames)) {
676683 std::string OutputName = OutputFilename;
677 if (OutputName.empty()) {
678 OutputName = Filename + ".thinlto.o";
679 }
680 if (OutputName == "-") {
681 outs() << Buffer->getBuffer();
684 if (OutputName.empty())
685 OutputName = std::get<1>(BinName) + ".thinlto.o";
686 else if (OutputName == "-") {
687 outs() << std::get<0>(BinName)->getBuffer();
682688 return;
683689 }
684690
685691 std::error_code EC;
686692 raw_fd_ostream OS(OutputName, EC, sys::fs::OpenFlags::F_None);
687693 error(EC, "error opening the file '" + OutputName + "'");
688 OS << Buffer->getBuffer();
694 OS << std::get<0>(BinName)->getBuffer();
689695 }
690696 }
691697