[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 llvm-svn: 325410
This commit is contained in:
parent
373e30a264
commit
c35ff824de
|
@ -49,6 +49,8 @@ namespace clang {
|
|||
|
||||
llvm::Expected<llvm::BitcodeModule>
|
||||
FindThinLTOModule(llvm::MemoryBufferRef MBRef);
|
||||
llvm::BitcodeModule *
|
||||
FindThinLTOModule(llvm::MutableArrayRef<llvm::BitcodeModule> BMs);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1025,16 +1025,22 @@ Expected<BitcodeModule> clang::FindThinLTOModule(MemoryBufferRef MBRef) {
|
|||
|
||||
// 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,
|
||||
|
|
|
@ -947,12 +947,21 @@ std::unique_ptr<llvm::Module> CodeGenAction::loadModule(MemoryBufferRef MBRef) {
|
|||
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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue