summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorVitaly Buka <vitalybuka@google.com>2018-02-16 23:34:16 +0000
committerVitaly Buka <vitalybuka@google.com>2018-02-16 23:34:16 +0000
commitc35ff824de59904ff7cc8c93620feacae7947c3b (patch)
treeff12c23f5aa0a907ff6f9dfbbbbd90fa2d6dfd0a /clang
parent373e30a2643c6f1ef0981b0f8a1b0d256fbf2ac7 (diff)
downloadbcm5719-llvm-c35ff824de59904ff7cc8c93620feacae7947c3b.tar.gz
bcm5719-llvm-c35ff824de59904ff7cc8c93620feacae7947c3b.zip
[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
Diffstat (limited to 'clang')
-rw-r--r--clang/include/clang/CodeGen/BackendUtil.h2
-rw-r--r--clang/lib/CodeGen/BackendUtil.cpp16
-rw-r--r--clang/lib/CodeGen/CodeGenAction.cpp19
-rw-r--r--clang/test/CodeGen/thinlto_backend.ll6
4 files changed, 33 insertions, 10 deletions
diff --git a/clang/include/clang/CodeGen/BackendUtil.h b/clang/include/clang/CodeGen/BackendUtil.h
index bb105cb533a..3d1221a43b1 100644
--- a/clang/include/clang/CodeGen/BackendUtil.h
+++ b/clang/include/clang/CodeGen/BackendUtil.h
@@ -49,6 +49,8 @@ namespace clang {
llvm::Expected<llvm::BitcodeModule>
FindThinLTOModule(llvm::MemoryBufferRef MBRef);
+ llvm::BitcodeModule *
+ FindThinLTOModule(llvm::MutableArrayRef<llvm::BitcodeModule> BMs);
}
#endif
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index fc8b5523520..384800e9510 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -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,
diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp
index 6ca69d63cdc..13fa4a83308 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -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);
diff --git a/clang/test/CodeGen/thinlto_backend.ll b/clang/test/CodeGen/thinlto_backend.ll
index 86f30c0374f..40530ec5364 100644
--- a/clang/test/CodeGen/thinlto_backend.ll
+++ b/clang/test/CodeGen/thinlto_backend.ll
@@ -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
OpenPOWER on IntegriCloud