tejohnson created this revision. Herald added subscribers: Prazek, mehdi_amini.
We noticed that when invoking the thinBackend via clang (for the distributed build case) that flags like -ffunction-sections and -emit-llvm were not having the intended effect. This could have been fixed by setting up the TargetOptions and the CodeGenFileType in the LTO Config, but since clang already has handling for all of this, it is straightforward to just let it do the handling (just below the early return after runThinLTOBackend being removed here). Depends on https://reviews.llvm.org/D31100. https://reviews.llvm.org/D31101 Files: lib/CodeGen/BackendUtil.cpp test/CodeGen/function-sections.c Index: test/CodeGen/function-sections.c =================================================================== --- test/CodeGen/function-sections.c +++ test/CodeGen/function-sections.c @@ -9,6 +9,12 @@ // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -S -fdata-sections -o - < %s | FileCheck %s --check-prefix=DATA_SECT // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -S -fno-data-sections -fdata-sections -o - < %s | FileCheck %s --check-prefix=DATA_SECT +// Try again through a clang invocation of the ThinLTO backend. +// RUN: %clang -O2 %s -flto=thin -c -o %t.o +// RUN: llvm-lto -thinlto -o %t %t.o +// RUN: %clang -O2 -x ir %t.o -fthinlto-index=%t.thinlto.bc -S -ffunction-sections -o - | FileCheck %s --check-prefix=FUNC_SECT +// RUN: %clang -O2 -x ir %t.o -fthinlto-index=%t.thinlto.bc -S -fdata-sections -o - | FileCheck %s --check-prefix=DATA_SECT + const int hello = 123; void world() {} @@ -22,7 +28,7 @@ // FUNC_SECT: section .rodata, // FUNC_SECT: hello: -// DATA_SECT-NOT: section +// DATA_SECT-NOT: .section // DATA_SECT: world: // DATA_SECT: .section .rodata.hello, // DATA_SECT: hello: Index: lib/CodeGen/BackendUtil.cpp =================================================================== --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -896,7 +896,6 @@ } static void runThinLTOBackend(ModuleSummaryIndex *CombinedIndex, Module *M, - std::unique_ptr<raw_pwrite_stream> OS, std::string SampleProfile) { StringMap<std::map<GlobalValue::GUID, GlobalValueSummary *>> ModuleToDefinedGVSummaries; @@ -944,13 +943,11 @@ OwnedImports.push_back(std::move(*MBOrErr)); } - auto AddStream = [&](size_t Task) { - return llvm::make_unique<lto::NativeObjectStream>(std::move(OS)); - }; lto::Config Conf; Conf.SampleProfile = SampleProfile; + Conf.SkipCodeGen = true; if (Error E = thinBackend( - Conf, 0, AddStream, *M, *CombinedIndex, ImportList, + Conf, 0, nullptr, *M, *CombinedIndex, ImportList, ModuleToDefinedGVSummaries[M->getModuleIdentifier()], ModuleMap)) { handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) { errs() << "Error running ThinLTO backend: " << EIB.message() << '\n'; @@ -983,11 +980,8 @@ // (LLVM will optionally ignore empty index files, returning null instead // of an error). bool DoThinLTOBackend = CombinedIndex != nullptr; - if (DoThinLTOBackend) { - runThinLTOBackend(CombinedIndex.get(), M, std::move(OS), - CGOpts.SampleProfileFile); - return; - } + if (DoThinLTOBackend) + runThinLTOBackend(CombinedIndex.get(), M, CGOpts.SampleProfileFile); } EmitAssemblyHelper AsmHelper(Diags, HeaderOpts, CGOpts, TOpts, LOpts, M);
Index: test/CodeGen/function-sections.c =================================================================== --- test/CodeGen/function-sections.c +++ test/CodeGen/function-sections.c @@ -9,6 +9,12 @@ // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -S -fdata-sections -o - < %s | FileCheck %s --check-prefix=DATA_SECT // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -S -fno-data-sections -fdata-sections -o - < %s | FileCheck %s --check-prefix=DATA_SECT +// Try again through a clang invocation of the ThinLTO backend. +// RUN: %clang -O2 %s -flto=thin -c -o %t.o +// RUN: llvm-lto -thinlto -o %t %t.o +// RUN: %clang -O2 -x ir %t.o -fthinlto-index=%t.thinlto.bc -S -ffunction-sections -o - | FileCheck %s --check-prefix=FUNC_SECT +// RUN: %clang -O2 -x ir %t.o -fthinlto-index=%t.thinlto.bc -S -fdata-sections -o - | FileCheck %s --check-prefix=DATA_SECT + const int hello = 123; void world() {} @@ -22,7 +28,7 @@ // FUNC_SECT: section .rodata, // FUNC_SECT: hello: -// DATA_SECT-NOT: section +// DATA_SECT-NOT: .section // DATA_SECT: world: // DATA_SECT: .section .rodata.hello, // DATA_SECT: hello: Index: lib/CodeGen/BackendUtil.cpp =================================================================== --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -896,7 +896,6 @@ } static void runThinLTOBackend(ModuleSummaryIndex *CombinedIndex, Module *M, - std::unique_ptr<raw_pwrite_stream> OS, std::string SampleProfile) { StringMap<std::map<GlobalValue::GUID, GlobalValueSummary *>> ModuleToDefinedGVSummaries; @@ -944,13 +943,11 @@ OwnedImports.push_back(std::move(*MBOrErr)); } - auto AddStream = [&](size_t Task) { - return llvm::make_unique<lto::NativeObjectStream>(std::move(OS)); - }; lto::Config Conf; Conf.SampleProfile = SampleProfile; + Conf.SkipCodeGen = true; if (Error E = thinBackend( - Conf, 0, AddStream, *M, *CombinedIndex, ImportList, + Conf, 0, nullptr, *M, *CombinedIndex, ImportList, ModuleToDefinedGVSummaries[M->getModuleIdentifier()], ModuleMap)) { handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) { errs() << "Error running ThinLTO backend: " << EIB.message() << '\n'; @@ -983,11 +980,8 @@ // (LLVM will optionally ignore empty index files, returning null instead // of an error). bool DoThinLTOBackend = CombinedIndex != nullptr; - if (DoThinLTOBackend) { - runThinLTOBackend(CombinedIndex.get(), M, std::move(OS), - CGOpts.SampleProfileFile); - return; - } + if (DoThinLTOBackend) + runThinLTOBackend(CombinedIndex.get(), M, CGOpts.SampleProfileFile); } EmitAssemblyHelper AsmHelper(Diags, HeaderOpts, CGOpts, TOpts, LOpts, M);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits