r325411 - [ThinLTO] Allow indexing to request backend to ignore the module

Vitaly Buka via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 16 15:38:22 PST 2018


Author: vitalybuka
Date: Fri Feb 16 15:38:22 2018
New Revision: 325411

URL: http://llvm.org/viewvc/llvm-project?rev=325411&view=rev
Log:
[ThinLTO] Allow indexing to request backend to ignore the module

Summary:
Gold plugin does not add pass to ThinLTO modules without useful symbols.
In this case ThinLTO can't create corresponding index file and some features, like CFI,
cannot be processes by backed correctly without index.
Given that we don't need the backed output we can request it to avoid
processing the module. This is implemented by this patch using new
"SkipModuleByDistributedBackend" flag.

Reviewers: pcc, tejohnson

Subscribers: mehdi_amini, inglorion, eraman, cfe-commits

Differential Revision: https://reviews.llvm.org/D42995

Added:
    cfe/trunk/test/CodeGen/Inputs/thinlto-distributed-backend-skip.bc   (with props)
    cfe/trunk/test/CodeGen/thinlto-distributed-backend-skip.ll
Modified:
    cfe/trunk/lib/CodeGen/BackendUtil.cpp

Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=325411&r1=325410&r2=325411&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Fri Feb 16 15:38:22 2018
@@ -1153,6 +1153,7 @@ void clang::EmitBackendOutput(Diagnostic
                               const llvm::DataLayout &TDesc, Module *M,
                               BackendAction Action,
                               std::unique_ptr<raw_pwrite_stream> OS) {
+  std::unique_ptr<llvm::Module> EmptyModule;
   if (!CGOpts.ThinLTOIndexFile.empty()) {
     // If we are performing a ThinLTO importing compile, load the function index
     // into memory and pass it into runThinLTOBackend, which will run the
@@ -1170,11 +1171,22 @@ void clang::EmitBackendOutput(Diagnostic
     // A null CombinedIndex means we should skip ThinLTO compilation
     // (LLVM will optionally ignore empty index files, returning null instead
     // of an error).
-    bool DoThinLTOBackend = CombinedIndex != nullptr;
-    if (DoThinLTOBackend) {
-      runThinLTOBackend(CombinedIndex.get(), M, HeaderOpts, CGOpts, TOpts,
-                        LOpts, std::move(OS), CGOpts.SampleProfileFile, Action);
-      return;
+    if (CombinedIndex) {
+      if (!CombinedIndex->skipModuleByDistributedBackend()) {
+        runThinLTOBackend(CombinedIndex.get(), M, HeaderOpts, CGOpts, TOpts,
+                          LOpts, std::move(OS), CGOpts.SampleProfileFile,
+                          Action);
+        return;
+      }
+      // Distributed indexing detected that nothing from the module is needed
+      // for the final linking. So we can skip the compilation. We sill need to
+      // output an empty object file to make sure that a linker does not fail
+      // trying to read it. Also for some features, like CFI, we must skip
+      // the compilation as CombinedIndex does not contain all required
+      // information.
+      EmptyModule = llvm::make_unique<llvm::Module>("empty", M->getContext());
+      EmptyModule->setTargetTriple(M->getTargetTriple());
+      M = EmptyModule.get();
     }
   }
 

Added: cfe/trunk/test/CodeGen/Inputs/thinlto-distributed-backend-skip.bc
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/Inputs/thinlto-distributed-backend-skip.bc?rev=325411&view=auto
==============================================================================
Binary file - no diff available.

Propchange: cfe/trunk/test/CodeGen/Inputs/thinlto-distributed-backend-skip.bc
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: cfe/trunk/test/CodeGen/thinlto-distributed-backend-skip.ll
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/thinlto-distributed-backend-skip.ll?rev=325411&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/thinlto-distributed-backend-skip.ll (added)
+++ cfe/trunk/test/CodeGen/thinlto-distributed-backend-skip.ll Fri Feb 16 15:38:22 2018
@@ -0,0 +1,21 @@
+; REQUIRES: x86-registered-target
+
+; Check that ThinLTO backend respects "SkipModuleByDistributedBackend"
+; flag which can be set by indexing.
+
+; RUN: opt -thinlto-bc -o %t.o %s
+
+; RUN: %clang_cc1 -triple x86_64-grtev4-linux-gnu \
+; RUN:   -fthinlto-index=%S/Inputs/thinlto-distributed-backend-skip.bc \
+; RUN:   -emit-llvm -o - -x ir %t.o | FileCheck %s
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-grtev4-linux-gnu"
+
+; CHECK: "empty"
+; CHECK: target triple =
+; CHECK-NOT: @main
+define i32 @main() {
+entry:
+  ret i32 0
+}




More information about the cfe-commits mailing list