[PATCH] D42680: [ThinLTO] Ignore -fthinlto-index= for non-ThinLTO files

2018-02-02 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka updated this revision to Diff 132701.
vitalybuka added a comment.

skip full LTO objects


https://reviews.llvm.org/D42680

Files:
  clang/include/clang/CodeGen/BackendUtil.h
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/test/CodeGen/thinlto_backend.ll


Index: clang/test/CodeGen/thinlto_backend.ll
===
--- clang/test/CodeGen/thinlto_backend.ll
+++ clang/test/CodeGen/thinlto_backend.ll
@@ -20,6 +20,10 @@
 ; 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 run 
non-ThinLTO compilation which
+; 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
+
 ; 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
Index: clang/lib/CodeGen/CodeGenAction.cpp
===
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -947,12 +947,18 @@
   return {};
 };
 
-Expected BMOrErr = FindThinLTOModule(MBRef);
-if (!BMOrErr)
-  return DiagErrors(BMOrErr.takeError());
-
+Expected 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)
+  return {};
 Expected MOrErr =
-BMOrErr->parseModule(*VMContext);
+Bm->parseModule(*VMContext);
 if (!MOrErr)
   return DiagErrors(MOrErr.takeError());
 return std::move(*MOrErr);
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -1025,16 +1025,22 @@
 
   // The bitcode file may contain multiple modules, we want the one that is
   // marked as being the ThinLTO module.
-  for (BitcodeModule  : *BMsOrErr) {
-Expected LTOInfo = BM.getLTOInfo();
-if (LTOInfo && LTOInfo->IsThinLTO)
-  return BM;
-  }
+  if (const BitcodeModule *Bm = FindThinLTOModule(*BMsOrErr))
+return *Bm;
 
   return make_error("Could not find module summary",
  inconvertibleErrorCode());
 }
 
+BitcodeModule *clang::FindThinLTOModule(MutableArrayRef BMs) {
+  for (BitcodeModule  : BMs) {
+Expected LTOInfo = BM.getLTOInfo();
+if (LTOInfo && LTOInfo->IsThinLTO)
+  return 
+  }
+  return nullptr;
+}
+
 static void runThinLTOBackend(ModuleSummaryIndex *CombinedIndex, Module *M,
   const HeaderSearchOptions ,
   const CodeGenOptions ,
Index: clang/include/clang/CodeGen/BackendUtil.h
===
--- clang/include/clang/CodeGen/BackendUtil.h
+++ clang/include/clang/CodeGen/BackendUtil.h
@@ -49,6 +49,8 @@
 
   llvm::Expected
   FindThinLTOModule(llvm::MemoryBufferRef MBRef);
+  llvm::BitcodeModule *
+  FindThinLTOModule(llvm::MutableArrayRef BMs);
 }
 
 #endif


Index: clang/test/CodeGen/thinlto_backend.ll
===
--- clang/test/CodeGen/thinlto_backend.ll
+++ clang/test/CodeGen/thinlto_backend.ll
@@ -20,6 +20,10 @@
 ; 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 run non-ThinLTO compilation which
+; 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
+
 ; 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
Index: clang/lib/CodeGen/CodeGenAction.cpp
===
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -947,12 +947,18 @@
   return {};
 };
 
-Expected BMOrErr = FindThinLTOModule(MBRef);
-if (!BMOrErr)
-  return DiagErrors(BMOrErr.takeError());
-
+Expected 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 

[PATCH] D42680: [ThinLTO] Ignore -fthinlto-index= for non-ThinLTO files

2018-01-30 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

In https://reviews.llvm.org/D42680#991938, @pcc wrote:

> This doesn't seem right to me. In a mixed full/thin LTO link the full LTO 
> module would be compiled during the indexing phase. We don't want to compile 
> it again in the backend as it could lead at best to duplicate symbol errors 
> and at worst to miscompiles of `llvm.type.*` intrinsic calls.


Good point. The build system will presumably expect an output file to be 
generated, so probably just compile an "empty" Module in this case?


https://reviews.llvm.org/D42680



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42680: [ThinLTO] Ignore -fthinlto-index= for non-ThinLTO files

2018-01-30 Thread Peter Collingbourne via Phabricator via cfe-commits
pcc requested changes to this revision.
pcc added a comment.
This revision now requires changes to proceed.

This doesn't seem right to me. In a mixed full/thin LTO link the full LTO 
module would be compiled during the indexing phase. We don't want to compile it 
again in the backend as it could lead at best to duplicate symbol errors and at 
worst to miscompiles of `llvm.type.*` intrinsic calls.


https://reviews.llvm.org/D42680



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42680: [ThinLTO] Ignore -fthinlto-index= for non-ThinLTO files

2018-01-30 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson accepted this revision.
tejohnson added a comment.
This revision is now accepted and ready to land.

LGTM (minor comment fix in test needed)




Comment at: clang/test/CodeGen/thinlto_backend.ll:23
 
+; Ensure we don't fail with index and non-ThinLTO object file, and run 
non-ThinLTO compilation which
+; RUN: opt -o %t5.o %s

Comment line length too long, and sentence isn't complete.


https://reviews.llvm.org/D42680



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42680: [ThinLTO] Ignore -fthinlto-index= for non-ThinLTO files

2018-01-30 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka created this revision.
vitalybuka added reviewers: pcc, tejohnson.
Herald added subscribers: eraman, inglorion, mehdi_amini.

Sometimes -flto=thin can produce regular LTO object files. Then backend may
receive them with -fthinlto-index= flag. Previous behavior was to report
error in this case. To avoid error build system needs to detect that
-flto=thin produced non-ThinLTO output. This can be quite complicated
and inefficient assuming that usually build system does not need to parse
object files.

As workaround we can just ignore -fthinlto-index= and fall-back to
non-ThinLTO version.


https://reviews.llvm.org/D42680

Files:
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/test/CodeGen/thinlto_backend.ll


Index: clang/test/CodeGen/thinlto_backend.ll
===
--- clang/test/CodeGen/thinlto_backend.ll
+++ clang/test/CodeGen/thinlto_backend.ll
@@ -20,6 +20,10 @@
 ; 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 run 
non-ThinLTO compilation which
+; 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
+
 ; 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
Index: clang/lib/CodeGen/CodeGenAction.cpp
===
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -946,16 +946,17 @@
   });
   return {};
 };
-
 Expected BMOrErr = FindThinLTOModule(MBRef);
-if (!BMOrErr)
-  return DiagErrors(BMOrErr.takeError());
-
-Expected MOrErr =
-BMOrErr->parseModule(*VMContext);
-if (!MOrErr)
-  return DiagErrors(MOrErr.takeError());
-return std::move(*MOrErr);
+if (BMOrErr) {
+  Expected MOrErr =
+  BMOrErr->parseModule(*VMContext);
+  if (!MOrErr)
+return DiagErrors(MOrErr.takeError());
+  return std::move(*MOrErr);
+} else {
+  // Suppress error and fall-back to regular parsing.
+  handleAllErrors(BMOrErr.takeError(), [&](ErrorInfoBase ) {});
+}
   }
 
   llvm::SMDiagnostic Err;


Index: clang/test/CodeGen/thinlto_backend.ll
===
--- clang/test/CodeGen/thinlto_backend.ll
+++ clang/test/CodeGen/thinlto_backend.ll
@@ -20,6 +20,10 @@
 ; 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 run non-ThinLTO compilation which
+; 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
+
 ; 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
Index: clang/lib/CodeGen/CodeGenAction.cpp
===
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -946,16 +946,17 @@
   });
   return {};
 };
-
 Expected BMOrErr = FindThinLTOModule(MBRef);
-if (!BMOrErr)
-  return DiagErrors(BMOrErr.takeError());
-
-Expected MOrErr =
-BMOrErr->parseModule(*VMContext);
-if (!MOrErr)
-  return DiagErrors(MOrErr.takeError());
-return std::move(*MOrErr);
+if (BMOrErr) {
+  Expected MOrErr =
+  BMOrErr->parseModule(*VMContext);
+  if (!MOrErr)
+return DiagErrors(MOrErr.takeError());
+  return std::move(*MOrErr);
+} else {
+  // Suppress error and fall-back to regular parsing.
+  handleAllErrors(BMOrErr.takeError(), [&](ErrorInfoBase ) {});
+}
   }
 
   llvm::SMDiagnostic Err;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits