[PATCH] D31050: [ThinLTO] Clang support for emitting minimized bitcode for thin link
This revision was automatically updated to reflect the committed changes. Closed by commit rL298639: [ThinLTO] Clang support for emitting minimized bitcode for thin link (authored by tejohnson). Changed prior to commit: https://reviews.llvm.org/D31050?vs=92647=92849#toc Repository: rL LLVM https://reviews.llvm.org/D31050 Files: cfe/trunk/include/clang/Driver/CC1Options.td cfe/trunk/include/clang/Frontend/CodeGenOptions.h cfe/trunk/lib/CodeGen/BackendUtil.cpp cfe/trunk/lib/Frontend/CompilerInvocation.cpp cfe/trunk/test/CodeGen/thin_link_bitcode.c Index: cfe/trunk/test/CodeGen/thin_link_bitcode.c === --- cfe/trunk/test/CodeGen/thin_link_bitcode.c +++ cfe/trunk/test/CodeGen/thin_link_bitcode.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -o %t -flto=thin -fthin-link-bitcode=%t.nodebug -triple x86_64-unknown-linux-gnu -emit-llvm-bc -debug-info-kind=limited %s +// RUN: llvm-bcanalyzer -dump %t | FileCheck %s +// RUN: llvm-bcanalyzer -dump %t.nodebug | FileCheck %s --check-prefix=NO_DEBUG +int main (void) { + return 0; +} + +// CHECK: COMPILE_UNIT +// NO_DEBUG-NOT: COMPILE_UNIT Index: cfe/trunk/lib/Frontend/CompilerInvocation.cpp === --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp @@ -641,6 +641,7 @@ << A->getAsString(Args) << "-x ir"; Opts.ThinLTOIndexFile = Args.getLastArgValue(OPT_fthinlto_index_EQ); } + Opts.ThinLinkBitcodeFile = Args.getLastArgValue(OPT_fthin_link_bitcode_EQ); Opts.MSVolatile = Args.hasArg(OPT_fms_volatile); Index: cfe/trunk/lib/CodeGen/BackendUtil.cpp === --- cfe/trunk/lib/CodeGen/BackendUtil.cpp +++ cfe/trunk/lib/CodeGen/BackendUtil.cpp @@ -686,13 +686,28 @@ CodeGenPasses.add( createTargetTransformInfoWrapperPass(getTargetIRAnalysis())); + std::unique_ptr ThinLinkOS; + switch (Action) { case Backend_EmitNothing: break; case Backend_EmitBC: -if (CodeGenOpts.EmitSummaryIndex) - PerModulePasses.add(createWriteThinLTOBitcodePass(*OS)); +if (CodeGenOpts.EmitSummaryIndex) { + if (!CodeGenOpts.ThinLinkBitcodeFile.empty()) { +std::error_code EC; +ThinLinkOS.reset(new llvm::raw_fd_ostream( +CodeGenOpts.ThinLinkBitcodeFile, EC, +llvm::sys::fs::F_None)); +if (EC) { + Diags.Report(diag::err_fe_unable_to_open_output) << CodeGenOpts.ThinLinkBitcodeFile + << EC.message(); + return; +} + } + PerModulePasses.add( + createWriteThinLTOBitcodePass(*OS, ThinLinkOS.get())); +} else PerModulePasses.add( createBitcodeWriterPass(*OS, CodeGenOpts.EmitLLVMUseLists)); Index: cfe/trunk/include/clang/Driver/CC1Options.td === --- cfe/trunk/include/clang/Driver/CC1Options.td +++ cfe/trunk/include/clang/Driver/CC1Options.td @@ -312,6 +312,8 @@ def flto_unit: Flag<["-"], "flto-unit">, HelpText<"Emit IR to support LTO unit features (CFI, whole program vtable opt)">; def fno_lto_unit: Flag<["-"], "fno-lto-unit">; +def fthin_link_bitcode_EQ : Joined<["-"], "fthin-link-bitcode=">, +HelpText<"Write minimized bitcode to for the ThinLTO thin link only">; //===--===// // Dependency Output Options Index: cfe/trunk/include/clang/Frontend/CodeGenOptions.h === --- cfe/trunk/include/clang/Frontend/CodeGenOptions.h +++ cfe/trunk/include/clang/Frontend/CodeGenOptions.h @@ -188,6 +188,11 @@ /// importing. std::string ThinLTOIndexFile; + /// Name of a file that can optionally be written with minimized bitcode + /// to be used as input for the ThinLTO thin link step, which only needs + /// the summary and module symbol table (and not, e.g. any debug metadata). + std::string ThinLinkBitcodeFile; + /// A list of file names passed with -fcuda-include-gpubinary options to /// forward to CUDA runtime back-end for incorporating them into host-side /// object file. Index: cfe/trunk/test/CodeGen/thin_link_bitcode.c === --- cfe/trunk/test/CodeGen/thin_link_bitcode.c +++ cfe/trunk/test/CodeGen/thin_link_bitcode.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -o %t -flto=thin -fthin-link-bitcode=%t.nodebug -triple x86_64-unknown-linux-gnu -emit-llvm-bc -debug-info-kind=limited %s +// RUN: llvm-bcanalyzer -dump %t | FileCheck %s +// RUN: llvm-bcanalyzer -dump %t.nodebug | FileCheck %s --check-prefix=NO_DEBUG +int main (void) { + return 0; +} + +// CHECK: COMPILE_UNIT +// NO_DEBUG-NOT: COMPILE_UNIT Index: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
[PATCH] D31050: [ThinLTO] Clang support for emitting minimized bitcode for thin link
pcc accepted this revision. pcc added a comment. This revision is now accepted and ready to land. LGTM https://reviews.llvm.org/D31050 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D31050: [ThinLTO] Clang support for emitting minimized bitcode for thin link
tejohnson updated this revision to Diff 92647. tejohnson added a comment. Update as per review comments on llvm side patch https://reviews.llvm.org/D31027. https://reviews.llvm.org/D31050 Files: include/clang/Driver/CC1Options.td include/clang/Frontend/CodeGenOptions.h lib/CodeGen/BackendUtil.cpp lib/Frontend/CompilerInvocation.cpp test/CodeGen/thin_link_bitcode.c Index: test/CodeGen/thin_link_bitcode.c === --- /dev/null +++ test/CodeGen/thin_link_bitcode.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -o %t -flto=thin -fthin-link-bitcode=%t.nodebug -triple x86_64-unknown-linux-gnu -emit-llvm-bc -debug-info-kind=limited %s +// RUN: llvm-bcanalyzer -dump %t | FileCheck %s +// RUN: llvm-bcanalyzer -dump %t.nodebug | FileCheck %s --check-prefix=NO_DEBUG +int main (void) { + return 0; +} + +// CHECK: COMPILE_UNIT +// NO_DEBUG-NOT: COMPILE_UNIT Index: lib/Frontend/CompilerInvocation.cpp === --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -641,6 +641,7 @@ << A->getAsString(Args) << "-x ir"; Opts.ThinLTOIndexFile = Args.getLastArgValue(OPT_fthinlto_index_EQ); } + Opts.ThinLinkBitcodeFile = Args.getLastArgValue(OPT_fthin_link_bitcode_EQ); Opts.MSVolatile = Args.hasArg(OPT_fms_volatile); Index: lib/CodeGen/BackendUtil.cpp === --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -682,13 +682,28 @@ CodeGenPasses.add( createTargetTransformInfoWrapperPass(getTargetIRAnalysis())); + std::unique_ptr ThinLinkOS; + switch (Action) { case Backend_EmitNothing: break; case Backend_EmitBC: -if (CodeGenOpts.EmitSummaryIndex) - PerModulePasses.add(createWriteThinLTOBitcodePass(*OS)); +if (CodeGenOpts.EmitSummaryIndex) { + if (!CodeGenOpts.ThinLinkBitcodeFile.empty()) { +std::error_code EC; +ThinLinkOS.reset(new llvm::raw_fd_ostream( +CodeGenOpts.ThinLinkBitcodeFile, EC, +llvm::sys::fs::F_None)); +if (EC) { + Diags.Report(diag::err_fe_unable_to_open_output) << CodeGenOpts.ThinLinkBitcodeFile + << EC.message(); + return; +} + } + PerModulePasses.add( + createWriteThinLTOBitcodePass(*OS, ThinLinkOS.get())); +} else PerModulePasses.add( createBitcodeWriterPass(*OS, CodeGenOpts.EmitLLVMUseLists)); Index: include/clang/Frontend/CodeGenOptions.h === --- include/clang/Frontend/CodeGenOptions.h +++ include/clang/Frontend/CodeGenOptions.h @@ -186,6 +186,11 @@ /// importing. std::string ThinLTOIndexFile; + /// Name of a file that can optionally be written with minimized bitcode + /// to be used as input for the ThinLTO thin link step, which only needs + /// the summary and module symbol table (and not, e.g. any debug metadata). + std::string ThinLinkBitcodeFile; + /// A list of file names passed with -fcuda-include-gpubinary options to /// forward to CUDA runtime back-end for incorporating them into host-side /// object file. Index: include/clang/Driver/CC1Options.td === --- include/clang/Driver/CC1Options.td +++ include/clang/Driver/CC1Options.td @@ -312,6 +312,8 @@ def flto_unit: Flag<["-"], "flto-unit">, HelpText<"Emit IR to support LTO unit features (CFI, whole program vtable opt)">; def fno_lto_unit: Flag<["-"], "fno-lto-unit">; +def fthin_link_bitcode_EQ : Joined<["-"], "fthin-link-bitcode=">, +HelpText<"Write minimized bitcode to for the ThinLTO thin link only">; //===--===// // Dependency Output Options Index: test/CodeGen/thin_link_bitcode.c === --- /dev/null +++ test/CodeGen/thin_link_bitcode.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -o %t -flto=thin -fthin-link-bitcode=%t.nodebug -triple x86_64-unknown-linux-gnu -emit-llvm-bc -debug-info-kind=limited %s +// RUN: llvm-bcanalyzer -dump %t | FileCheck %s +// RUN: llvm-bcanalyzer -dump %t.nodebug | FileCheck %s --check-prefix=NO_DEBUG +int main (void) { + return 0; +} + +// CHECK: COMPILE_UNIT +// NO_DEBUG-NOT: COMPILE_UNIT Index: lib/Frontend/CompilerInvocation.cpp === --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -641,6 +641,7 @@ << A->getAsString(Args) << "-x ir"; Opts.ThinLTOIndexFile = Args.getLastArgValue(OPT_fthinlto_index_EQ); } + Opts.ThinLinkBitcodeFile = Args.getLastArgValue(OPT_fthin_link_bitcode_EQ); Opts.MSVolatile = Args.hasArg(OPT_fms_volatile); Index:
[PATCH] D31050: [ThinLTO] Clang support for emitting minimized bitcode for thin link
tejohnson created this revision. Herald added a subscriber: Prazek. Clang companion patch to LLVM patch https://reviews.llvm.org/D31027, which adds support for emitting minimized bitcode file for use in the thin link step. Add a cc1 option -fthin-link-bitcode= to trigger this behavior. Depends on https://reviews.llvm.org/D31027. https://reviews.llvm.org/D31050 Files: include/clang/Driver/CC1Options.td include/clang/Frontend/CodeGenOptions.h lib/CodeGen/BackendUtil.cpp lib/Frontend/CompilerInvocation.cpp test/CodeGen/thin_link_bitcode.c Index: test/CodeGen/thin_link_bitcode.c === --- /dev/null +++ test/CodeGen/thin_link_bitcode.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -o %t -flto=thin -fthin-link-bitcode=%t.nodebug -triple x86_64-unknown-linux-gnu -emit-llvm-bc -debug-info-kind=limited %s +// RUN: llvm-bcanalyzer -dump %t | FileCheck %s +// RUN: llvm-bcanalyzer -dump %t.nodebug | FileCheck %s --check-prefix=NO_DEBUG +int main (void) { + return 0; +} + +// CHECK: COMPILE_UNIT +// NO_DEBUG-NOT: COMPILE_UNIT Index: lib/Frontend/CompilerInvocation.cpp === --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -641,6 +641,7 @@ << A->getAsString(Args) << "-x ir"; Opts.ThinLTOIndexFile = Args.getLastArgValue(OPT_fthinlto_index_EQ); } + Opts.ThinLinkBitcodeFile = Args.getLastArgValue(OPT_fthin_link_bitcode_EQ); Opts.MSVolatile = Args.hasArg(OPT_fms_volatile); Index: lib/CodeGen/BackendUtil.cpp === --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -688,7 +688,8 @@ case Backend_EmitBC: if (CodeGenOpts.EmitSummaryIndex) - PerModulePasses.add(createWriteThinLTOBitcodePass(*OS)); + PerModulePasses.add( + createWriteThinLTOBitcodePass(*OS, CodeGenOpts.ThinLinkBitcodeFile)); else PerModulePasses.add( createBitcodeWriterPass(*OS, CodeGenOpts.EmitLLVMUseLists)); Index: include/clang/Frontend/CodeGenOptions.h === --- include/clang/Frontend/CodeGenOptions.h +++ include/clang/Frontend/CodeGenOptions.h @@ -186,6 +186,11 @@ /// importing. std::string ThinLTOIndexFile; + /// Name of a file that can optionally be written with minimized bitcode + /// to be used as input for the ThinLTO thin link step, which only needs + /// the summary and module symbol table (and not, e.g. any debug metadata). + std::string ThinLinkBitcodeFile; + /// A list of file names passed with -fcuda-include-gpubinary options to /// forward to CUDA runtime back-end for incorporating them into host-side /// object file. Index: include/clang/Driver/CC1Options.td === --- include/clang/Driver/CC1Options.td +++ include/clang/Driver/CC1Options.td @@ -312,6 +312,8 @@ def flto_unit: Flag<["-"], "flto-unit">, HelpText<"Emit IR to support LTO unit features (CFI, whole program vtable opt)">; def fno_lto_unit: Flag<["-"], "fno-lto-unit">; +def fthin_link_bitcode_EQ : Joined<["-"], "fthin-link-bitcode=">, +HelpText<"Write minimized bitcode to for the ThinLTO thin link only">; //===--===// // Dependency Output Options Index: test/CodeGen/thin_link_bitcode.c === --- /dev/null +++ test/CodeGen/thin_link_bitcode.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -o %t -flto=thin -fthin-link-bitcode=%t.nodebug -triple x86_64-unknown-linux-gnu -emit-llvm-bc -debug-info-kind=limited %s +// RUN: llvm-bcanalyzer -dump %t | FileCheck %s +// RUN: llvm-bcanalyzer -dump %t.nodebug | FileCheck %s --check-prefix=NO_DEBUG +int main (void) { + return 0; +} + +// CHECK: COMPILE_UNIT +// NO_DEBUG-NOT: COMPILE_UNIT Index: lib/Frontend/CompilerInvocation.cpp === --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -641,6 +641,7 @@ << A->getAsString(Args) << "-x ir"; Opts.ThinLTOIndexFile = Args.getLastArgValue(OPT_fthinlto_index_EQ); } + Opts.ThinLinkBitcodeFile = Args.getLastArgValue(OPT_fthin_link_bitcode_EQ); Opts.MSVolatile = Args.hasArg(OPT_fms_volatile); Index: lib/CodeGen/BackendUtil.cpp === --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -688,7 +688,8 @@ case Backend_EmitBC: if (CodeGenOpts.EmitSummaryIndex) - PerModulePasses.add(createWriteThinLTOBitcodePass(*OS)); + PerModulePasses.add( + createWriteThinLTOBitcodePass(*OS, CodeGenOpts.ThinLinkBitcodeFile)); else PerModulePasses.add( createBitcodeWriterPass(*OS,