[PATCH] D31534: [ThinLTO] Handle -emit-llvm* in ThinLTO backends
This revision was automatically updated to reflect the committed changes. Closed by commit rL299274: [ThinLTO] Handle -emit-llvm* in ThinLTO backends (authored by tejohnson). Changed prior to commit: https://reviews.llvm.org/D31534?vs=93695=93722#toc Repository: rL LLVM https://reviews.llvm.org/D31534 Files: cfe/trunk/lib/CodeGen/BackendUtil.cpp cfe/trunk/test/CodeGen/thinlto-emit-llvm.c Index: cfe/trunk/test/CodeGen/thinlto-emit-llvm.c === --- cfe/trunk/test/CodeGen/thinlto-emit-llvm.c +++ cfe/trunk/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: cfe/trunk/lib/CodeGen/BackendUtil.cpp === --- cfe/trunk/lib/CodeGen/BackendUtil.cpp +++ cfe/trunk/lib/CodeGen/BackendUtil.cpp @@ -994,9 +994,30 @@ 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 ) { + return false; +}; +break; + case Backend_EmitLL: +Conf.PreCodeGenModuleHook = [&](size_t Task, const Module ) { + M->print(*OS, nullptr, CGOpts.EmitLLVMUseLists); + return false; +}; +break; + case Backend_EmitBC: +Conf.PreCodeGenModuleHook = [&](size_t Task, const Module ) { + 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)) { Index: cfe/trunk/test/CodeGen/thinlto-emit-llvm.c === --- cfe/trunk/test/CodeGen/thinlto-emit-llvm.c +++ cfe/trunk/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: cfe/trunk/lib/CodeGen/BackendUtil.cpp === --- cfe/trunk/lib/CodeGen/BackendUtil.cpp +++ cfe/trunk/lib/CodeGen/BackendUtil.cpp @@ -994,9 +994,30 @@ 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 ) { + return false; +}; +break; + case Backend_EmitLL: +Conf.PreCodeGenModuleHook = [&](size_t Task, const Module ) { + M->print(*OS, nullptr, CGOpts.EmitLLVMUseLists); + return false; +}; +break; + case Backend_EmitBC: +Conf.PreCodeGenModuleHook = [&](size_t Task, const Module ) { + 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)) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D31534: [ThinLTO] Handle -emit-llvm* in ThinLTO backends
pcc accepted this revision. pcc added a comment. This revision is now accepted and ready to land. LGTM https://reviews.llvm.org/D31534 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D31534: [ThinLTO] Handle -emit-llvm* in ThinLTO backends
tejohnson updated this revision to Diff 93695. tejohnson added a comment. Implement review suggestions https://reviews.llvm.org/D31534 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 @@ -994,9 +994,30 @@ 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 ) { + return false; +}; +break; + case Backend_EmitLL: +Conf.PreCodeGenModuleHook = [&](size_t Task, const Module ) { + M->print(*OS, nullptr, CGOpts.EmitLLVMUseLists); + return false; +}; +break; + case Backend_EmitBC: +Conf.PreCodeGenModuleHook = [&](size_t Task, const Module ) { + 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)) { 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 @@ -994,9 +994,30 @@ 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 ) { + return false; +}; +break; + case Backend_EmitLL: +Conf.PreCodeGenModuleHook = [&](size_t Task, const Module ) { + M->print(*OS, nullptr, CGOpts.EmitLLVMUseLists); + return false; +}; +break; + case Backend_EmitBC: +Conf.PreCodeGenModuleHook = [&](size_t Task, const Module ) { + 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)) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D31534: [ThinLTO] Handle -emit-llvm* in ThinLTO backends
pcc added a comment. Why not call `Module::print()` or `WriteBitcodeToFile` directly instead of creating a pass manager? https://reviews.llvm.org/D31534 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D31534: [ThinLTO] Handle -emit-llvm* in ThinLTO backends
tejohnson created this revision. Herald added a subscriber: Prazek. Use PreCodeGenModuleHook to invoke the correct writer when emitting LLVM IR, returning false to skip codegen from within thinBackend. https://reviews.llvm.org/D31534 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 @@ -994,9 +994,36 @@ 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 ) { + return false; +}; +break; + case Backend_EmitLL: +Conf.PreCodeGenModuleHook = [&](size_t Task, const Module ) { + legacy::PassManager PerModulePasses; + PerModulePasses.add( + createPrintModulePass(*OS, "", CGOpts.EmitLLVMUseLists)); + PerModulePasses.run(*M); + return false; +}; +break; + case Backend_EmitBC: +Conf.PreCodeGenModuleHook = [&](size_t Task, const Module ) { + legacy::PassManager PerModulePasses; + PerModulePasses.add( + createBitcodeWriterPass(*OS, CGOpts.EmitLLVMUseLists)); + PerModulePasses.run(*M); + return false; +}; +break; + default: +Conf.CGFileType = getCodeGenFileType(Action); +break; + } if (Error E = thinBackend( Conf, 0, AddStream, *M, *CombinedIndex, ImportList, ModuleToDefinedGVSummaries[M->getModuleIdentifier()], ModuleMap)) { 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 @@ -994,9 +994,36 @@ 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 ) { + return false; +}; +break; + case Backend_EmitLL: +Conf.PreCodeGenModuleHook = [&](size_t Task, const Module ) { + legacy::PassManager PerModulePasses; + PerModulePasses.add( + createPrintModulePass(*OS, "", CGOpts.EmitLLVMUseLists)); + PerModulePasses.run(*M); + return false; +}; +break; + case Backend_EmitBC: +Conf.PreCodeGenModuleHook = [&](size_t Task, const Module ) { + legacy::PassManager PerModulePasses; + PerModulePasses.add( + createBitcodeWriterPass(*OS, CGOpts.EmitLLVMUseLists)); + PerModulePasses.run(*M); + return false; +}; +break; + default: +Conf.CGFileType = getCodeGenFileType(Action); +break; + } if (Error E = thinBackend( Conf, 0, AddStream, *M, *CombinedIndex, ImportList, ModuleToDefinedGVSummaries[M->getModuleIdentifier()], ModuleMap)) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits