Author: vitalybuka Date: Fri Feb 16 15:34:16 2018 New Revision: 325410 URL: http://llvm.org/viewvc/llvm-project?rev=325410&view=rev Log: [ThinLTO] Ignore object files with no ThinLTO modules if -fthinlto-index= is set
Summary: ThinLTO compilation may decide not to split module and keep at as regular LTO. In this can this module already processed during indexing and already a part of merged object file. So here we can just skip it. Reviewers: pcc, tejohnson Reviewed By: tejohnson Subscribers: mehdi_amini, inglorion, eraman, cfe-commits Differential Revision: https://reviews.llvm.org/D42680 Modified: cfe/trunk/include/clang/CodeGen/BackendUtil.h cfe/trunk/lib/CodeGen/BackendUtil.cpp cfe/trunk/lib/CodeGen/CodeGenAction.cpp cfe/trunk/test/CodeGen/thinlto_backend.ll Modified: cfe/trunk/include/clang/CodeGen/BackendUtil.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/CodeGen/BackendUtil.h?rev=325410&r1=325409&r2=325410&view=diff ============================================================================== --- cfe/trunk/include/clang/CodeGen/BackendUtil.h (original) +++ cfe/trunk/include/clang/CodeGen/BackendUtil.h Fri Feb 16 15:34:16 2018 @@ -49,6 +49,8 @@ namespace clang { llvm::Expected<llvm::BitcodeModule> FindThinLTOModule(llvm::MemoryBufferRef MBRef); + llvm::BitcodeModule * + FindThinLTOModule(llvm::MutableArrayRef<llvm::BitcodeModule> BMs); } #endif Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=325410&r1=325409&r2=325410&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original) +++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Fri Feb 16 15:34:16 2018 @@ -1025,16 +1025,22 @@ Expected<BitcodeModule> clang::FindThinL // The bitcode file may contain multiple modules, we want the one that is // marked as being the ThinLTO module. - for (BitcodeModule &BM : *BMsOrErr) { - Expected<BitcodeLTOInfo> LTOInfo = BM.getLTOInfo(); - if (LTOInfo && LTOInfo->IsThinLTO) - return BM; - } + if (const BitcodeModule *Bm = FindThinLTOModule(*BMsOrErr)) + return *Bm; return make_error<StringError>("Could not find module summary", inconvertibleErrorCode()); } +BitcodeModule *clang::FindThinLTOModule(MutableArrayRef<BitcodeModule> BMs) { + for (BitcodeModule &BM : BMs) { + Expected<BitcodeLTOInfo> LTOInfo = BM.getLTOInfo(); + if (LTOInfo && LTOInfo->IsThinLTO) + return &BM; + } + return nullptr; +} + static void runThinLTOBackend(ModuleSummaryIndex *CombinedIndex, Module *M, const HeaderSearchOptions &HeaderOpts, const CodeGenOptions &CGOpts, Modified: cfe/trunk/lib/CodeGen/CodeGenAction.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenAction.cpp?rev=325410&r1=325409&r2=325410&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CodeGenAction.cpp (original) +++ cfe/trunk/lib/CodeGen/CodeGenAction.cpp Fri Feb 16 15:34:16 2018 @@ -947,12 +947,21 @@ std::unique_ptr<llvm::Module> CodeGenAct return {}; }; - Expected<llvm::BitcodeModule> BMOrErr = FindThinLTOModule(MBRef); - if (!BMOrErr) - return DiagErrors(BMOrErr.takeError()); - + Expected<std::vector<BitcodeModule>> BMsOrErr = getBitcodeModuleList(MBRef); + if (!BMsOrErr) + return DiagErrors(BMsOrErr.takeError()); + BitcodeModule *Bm = FindThinLTOModule(*BMsOrErr); + // We have nothing to do if the file contains no ThinLTO module. This is + // possible if ThinLTO compilation was not able to split module. Content of + // the file was already processed by indexing and will be passed to the + // linker using merged object file. + if (!Bm) { + auto M = llvm::make_unique<llvm::Module>("empty", *VMContext); + M->setTargetTriple(CI.getTargetOpts().Triple); + return M; + } Expected<std::unique_ptr<llvm::Module>> MOrErr = - BMOrErr->parseModule(*VMContext); + Bm->parseModule(*VMContext); if (!MOrErr) return DiagErrors(MOrErr.takeError()); return std::move(*MOrErr); Modified: cfe/trunk/test/CodeGen/thinlto_backend.ll URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/thinlto_backend.ll?rev=325410&r1=325409&r2=325410&view=diff ============================================================================== --- cfe/trunk/test/CodeGen/thinlto_backend.ll (original) +++ cfe/trunk/test/CodeGen/thinlto_backend.ll Fri Feb 16 15:34:16 2018 @@ -20,6 +20,12 @@ ; CHECK-OBJ-IGNORE-EMPTY: T f1 ; CHECK-OBJ-IGNORE-EMPTY: U f2 +; Ensure we don't fail with index and non-ThinLTO object file, and output must +; be empty file. +; RUN: opt -o %t5.o %s +; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t4.o -x ir %t5.o -c -fthinlto-index=%t.thinlto.bc +; RUN: llvm-nm %t4.o | count 0 + ; Ensure f2 was imported ; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t3.o -x ir %t1.o -c -fthinlto-index=%t.thinlto.bc ; RUN: llvm-nm %t3.o | FileCheck --check-prefix=CHECK-OBJ %s _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits