Author: Junfeng Dong Date: 2022-03-23T08:55:30-07:00 New Revision: 72acd042bad35f78232f17addc02196a7af1a6e9
URL: https://github.com/llvm/llvm-project/commit/72acd042bad35f78232f17addc02196a7af1a6e9 DIFF: https://github.com/llvm/llvm-project/commit/72acd042bad35f78232f17addc02196a7af1a6e9.diff LOG: Pass split-machine-functions to code generator when flto is used -fsplit-machine-functions is an optimization in codegen phase. when -flto is use, clang generate IR bitcode in .o files, and linker will call into these codegen optimization passes. Current clang driver doesn't pass this option to linker when both -fsplit-machine-functions and -flto are used, so the optimization is silently ignored. My fix generates linker option -plugin-opt=-split-machine-functions for this case. It allows the linker to pass "split-machine-functions" to code generator to turn on that optimization. It works for both gold and lld. Reviewed By: hoy, wenlei Differential Revision: https://reviews.llvm.org/D121969 Added: clang/test/Driver/fsplit-machine-functions2.c Modified: clang/lib/Driver/ToolChains/CommonArgs.cpp Removed: ################################################################################ diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index 2f3dc86eaad1d..156821a6e7854 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -574,6 +574,13 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args, CmdArgs.push_back("-plugin-opt=-data-sections"); } + // Pass an option to enable split machine functions. + if (auto *A = Args.getLastArg(options::OPT_fsplit_machine_functions, + options::OPT_fno_split_machine_functions)) { + if (A->getOption().matches(options::OPT_fsplit_machine_functions)) + CmdArgs.push_back("-plugin-opt=-split-machine-functions"); + } + if (Arg *A = getLastProfileSampleUseArg(Args)) { StringRef FName = A->getValue(); if (!llvm::sys::fs::exists(FName)) diff --git a/clang/test/Driver/fsplit-machine-functions2.c b/clang/test/Driver/fsplit-machine-functions2.c new file mode 100644 index 0000000000000..1b81be084eff9 --- /dev/null +++ b/clang/test/Driver/fsplit-machine-functions2.c @@ -0,0 +1,12 @@ +// Test -fsplit-machine-functions option pass-through with lto +// RUN: %clang -### -target x86_64-unknown-linux -flto -fsplit-machine-functions %s 2>&1 | FileCheck %s -check-prefix=CHECK-PASS + +// Test no pass-through to ld without lto +// RUN: %clang -### -target x86_64-unknown-linux -fsplit-machine-functions %s 2>&1 | FileCheck %s -check-prefix=CHECK-NOPASS + +// Test the mix of -fsplit-machine-functions and -fno-split-machine-functions +// RUN: %clang -### -target x86_64-unknown-linux -flto -fsplit-machine-functions -fno-split-machine-functions %s 2>&1 | FileCheck %s -check-prefix=CHECK-NOPASS +// RUN: %clang -### -target x86_64-unknown-linux -flto -fno-split-machine-functions -fsplit-machine-functions %s 2>&1 | FileCheck %s -check-prefix=CHECK-PASS + +// CHECK-PASS: "-plugin-opt=-split-machine-functions" +// CHECK-NOPASS-NOT: "-plugin-opt=-split-machine-functions" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits