tejohnson updated this revision to Diff 92324. tejohnson added a comment. As discussed in the review threads for https://reviews.llvm.org/D31114 and https://reviews.llvm.org/D31100, only fall back to clang's output file emission for -emit-llvm and -emit-llvm-bc.
https://reviews.llvm.org/D31101 Files: lib/CodeGen/BackendUtil.cpp test/CodeGen/thinlto-emit-llvm.c Index: test/CodeGen/thinlto-emit-llvm.c =================================================================== --- /dev/null +++ test/CodeGen/thinlto-emit-llvm.c @@ -0,0 +1,10 @@ +// Test to ensure -emit-llvm and -emit-llvm-bc work when invoking the +// ThinLTO backend path. +// RUN: %clang -O2 %s -flto=thin -c -o %t.o +// RUN: llvm-lto -thinlto -o %t %t.o +// RUN: %clang_cc1 -O2 -x ir %t.o -fthinlto-index=%t.thinlto.bc -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 -O2 -x ir %t.o -fthinlto-index=%t.thinlto.bc -emit-llvm-bc -o - | llvm-dis -o - | FileCheck %s + +// CHECK: define void @foo() +void foo() { +} Index: lib/CodeGen/BackendUtil.cpp =================================================================== --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -897,7 +897,8 @@ static void runThinLTOBackend(ModuleSummaryIndex *CombinedIndex, Module *M, std::unique_ptr<raw_pwrite_stream> OS, - std::string SampleProfile) { + std::string SampleProfile, + bool SkipCodeGen) { StringMap<std::map<GlobalValue::GUID, GlobalValueSummary *>> ModuleToDefinedGVSummaries; CombinedIndex->collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries); @@ -949,6 +950,7 @@ }; lto::Config Conf; Conf.SampleProfile = SampleProfile; + Conf.SkipCodeGen = SkipCodeGen; if (Error E = thinBackend( Conf, 0, AddStream, *M, *CombinedIndex, ImportList, ModuleToDefinedGVSummaries[M->getModuleIdentifier()], ModuleMap)) { @@ -984,9 +986,16 @@ // of an error). bool DoThinLTOBackend = CombinedIndex != nullptr; if (DoThinLTOBackend) { - runThinLTOBackend(CombinedIndex.get(), M, std::move(OS), - CGOpts.SampleProfileFile); - return; + bool UsesCodeGen = (Action != Backend_EmitNothing && + Action != Backend_EmitBC && + Action != Backend_EmitLL); + if (UsesCodeGen) { + runThinLTOBackend(CombinedIndex.get(), M, std::move(OS), + CGOpts.SampleProfileFile, /*SkipCodeGen*/false); + return; + } else + runThinLTOBackend(CombinedIndex.get(), M, nullptr, + CGOpts.SampleProfileFile, /*SkipCodeGen*/true); } }
Index: test/CodeGen/thinlto-emit-llvm.c =================================================================== --- /dev/null +++ test/CodeGen/thinlto-emit-llvm.c @@ -0,0 +1,10 @@ +// Test to ensure -emit-llvm and -emit-llvm-bc work when invoking the +// ThinLTO backend path. +// RUN: %clang -O2 %s -flto=thin -c -o %t.o +// RUN: llvm-lto -thinlto -o %t %t.o +// RUN: %clang_cc1 -O2 -x ir %t.o -fthinlto-index=%t.thinlto.bc -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 -O2 -x ir %t.o -fthinlto-index=%t.thinlto.bc -emit-llvm-bc -o - | llvm-dis -o - | FileCheck %s + +// CHECK: define void @foo() +void foo() { +} Index: lib/CodeGen/BackendUtil.cpp =================================================================== --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -897,7 +897,8 @@ static void runThinLTOBackend(ModuleSummaryIndex *CombinedIndex, Module *M, std::unique_ptr<raw_pwrite_stream> OS, - std::string SampleProfile) { + std::string SampleProfile, + bool SkipCodeGen) { StringMap<std::map<GlobalValue::GUID, GlobalValueSummary *>> ModuleToDefinedGVSummaries; CombinedIndex->collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries); @@ -949,6 +950,7 @@ }; lto::Config Conf; Conf.SampleProfile = SampleProfile; + Conf.SkipCodeGen = SkipCodeGen; if (Error E = thinBackend( Conf, 0, AddStream, *M, *CombinedIndex, ImportList, ModuleToDefinedGVSummaries[M->getModuleIdentifier()], ModuleMap)) { @@ -984,9 +986,16 @@ // of an error). bool DoThinLTOBackend = CombinedIndex != nullptr; if (DoThinLTOBackend) { - runThinLTOBackend(CombinedIndex.get(), M, std::move(OS), - CGOpts.SampleProfileFile); - return; + bool UsesCodeGen = (Action != Backend_EmitNothing && + Action != Backend_EmitBC && + Action != Backend_EmitLL); + if (UsesCodeGen) { + runThinLTOBackend(CombinedIndex.get(), M, std::move(OS), + CGOpts.SampleProfileFile, /*SkipCodeGen*/false); + return; + } else + runThinLTOBackend(CombinedIndex.get(), M, nullptr, + CGOpts.SampleProfileFile, /*SkipCodeGen*/true); } }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits