Author: tejohnson Date: Fri Mar 31 17:35:47 2017 New Revision: 299274 URL: http://llvm.org/viewvc/llvm-project?rev=299274&view=rev Log: [ThinLTO] Handle -emit-llvm* in ThinLTO backends
Summary: Use PreCodeGenModuleHook to invoke the correct writer when emitting LLVM IR, returning false to skip codegen from within thinBackend. Reviewers: pcc, mehdi_amini Subscribers: Prazek, cfe-commits Differential Revision: https://reviews.llvm.org/D31534 Added: cfe/trunk/test/CodeGen/thinlto-emit-llvm.c 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=299274&r1=299273&r2=299274&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original) +++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Fri Mar 31 17:35:47 2017 @@ -994,9 +994,30 @@ static void runThinLTOBackend(ModuleSumm Conf.MAttrs = TOpts.Features; Conf.RelocModel = getRelocModel(CGOpts); Conf.CGOptLevel = getCGOptLevel(CGOpts); - Conf.CGFileType = getCodeGenFileType(Action); initTargetOptions(Conf.Options, CGOpts, TOpts, LOpts, HeaderOpts); Conf.SampleProfile = std::move(SampleProfile); + switch (Action) { + case Backend_EmitNothing: + Conf.PreCodeGenModuleHook = [](size_t Task, const Module &Mod) { + return false; + }; + break; + case Backend_EmitLL: + Conf.PreCodeGenModuleHook = [&](size_t Task, const Module &Mod) { + M->print(*OS, nullptr, CGOpts.EmitLLVMUseLists); + return false; + }; + break; + case Backend_EmitBC: + Conf.PreCodeGenModuleHook = [&](size_t Task, const Module &Mod) { + WriteBitcodeToFile(M, *OS, CGOpts.EmitLLVMUseLists); + return false; + }; + break; + default: + Conf.CGFileType = getCodeGenFileType(Action); + break; + } if (Error E = thinBackend( Conf, 0, AddStream, *M, *CombinedIndex, ImportList, ModuleToDefinedGVSummaries[M->getModuleIdentifier()], ModuleMap)) { Added: cfe/trunk/test/CodeGen/thinlto-emit-llvm.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/thinlto-emit-llvm.c?rev=299274&view=auto ============================================================================== --- cfe/trunk/test/CodeGen/thinlto-emit-llvm.c (added) +++ cfe/trunk/test/CodeGen/thinlto-emit-llvm.c Fri Mar 31 17:35:47 2017 @@ -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() { +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits