[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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@325411 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Vitaly Buka 2018-02-16 23:38:22 +00:00
parent 4a11be988c
commit 4735edbbaf
3 changed files with 38 additions and 5 deletions

View File

@ -1153,6 +1153,7 @@ void clang::EmitBackendOutput(DiagnosticsEngine &Diags,
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(DiagnosticsEngine &Diags,
// 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();
}
}

View File

@ -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
}