snehasish updated this revision to Diff 289805.
snehasish added a comment.
Add warning when option is enabled without profile.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D87047/new/
https://reviews.llvm.org/D87047
Files:
clang/docs/ClangCommandLineReference.rst
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Basic/DiagnosticFrontendKinds.td
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/CodeGen/split-machine-functions.c
clang/test/Driver/fsplit-machine-functions.c
Index: clang/test/Driver/fsplit-machine-functions.c
===================================================================
--- /dev/null
+++ clang/test/Driver/fsplit-machine-functions.c
@@ -0,0 +1,4 @@
+// RUN: %clang -### -fsplit-machine-functions %s -c 2>&1 | FileCheck -check-prefix=CHECK-OPT %s
+// RUN: %clang -### -fsplit-machine-functions -fno-split-machine-functions %s -c 2>&1 | FileCheck -check-prefix=CHECK-NOOPT %s
+// CHECK-OPT: "-fsplit-machine-functions"
+// CHECK-NOOPT-NOT: "-fsplit-machine-functions"
Index: clang/test/CodeGen/split-machine-functions.c
===================================================================
--- /dev/null
+++ clang/test/CodeGen/split-machine-functions.c
@@ -0,0 +1,34 @@
+// REQUIRES: x86-registered-target
+
+// RUN: echo "foo" > %t.proftext
+// RUN: echo "# Func Hash:" >> %t.proftext
+// RUN: echo "11262309905" >> %t.proftext
+// RUN: echo "# Num Counters:" >> %t.proftext
+// RUN: echo "2" >> %t.proftext
+// RUN: echo "# Counter Values:" >> %t.proftext
+// RUN: echo "1000000" >> %t.proftext
+// RUN: echo "0" >> %t.proftext
+// RUN: llvm-profdata merge -o %t.profdata %t.proftext
+// RUN: %clang_cc1 -triple x86_64 -O3 -S -fprofile-instrument-use-path=%t.profdata -fsplit-machine-functions -o - < %s | FileCheck %s
+
+__attribute__((noinline)) int foo(int argc) {
+ if (argc % 2 == 0) {
+ exit(argc);
+ } else {
+ return argc + 1;
+ }
+}
+
+int main(int argc, char *argv[]) {
+ int total = 0;
+ for (int i = 0; i < 1000000; ++i) {
+ total += foo(argc);
+ }
+ printf("%d\n", total);
+}
+
+// CHECK: .section .text.hot.,"ax",@progbits
+// CHECK: foo:
+// CHECK: section .text.unlikely.foo,"ax",@progbits
+// CHECK: foo.cold:
+// CHECK: callq exit@PLT
Index: clang/lib/Frontend/CompilerInvocation.cpp
===================================================================
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -998,6 +998,8 @@
Opts.UniqueInternalLinkageNames =
Args.hasArg(OPT_funique_internal_linkage_names);
+ Opts.SplitMachineFunctions = Args.hasArg(OPT_fsplit_machine_functions);
+
Opts.MergeFunctions = Args.hasArg(OPT_fmerge_functions);
Opts.NoUseJumpTables = Args.hasArg(OPT_fno_jump_tables);
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4255,6 +4255,8 @@
options::OPT_fno_unique_section_names,
options::OPT_funique_basic_block_section_names,
options::OPT_fno_unique_basic_block_section_names,
+ options::OPT_fsplit_machine_functions,
+ options::OPT_fno_split_machine_functions,
options::OPT_mrestrict_it,
options::OPT_mno_restrict_it,
options::OPT_mstackrealign,
@@ -4905,6 +4907,10 @@
options::OPT_fno_unique_basic_block_section_names, false))
CmdArgs.push_back("-funique-basic-block-section-names");
+ if (Args.hasFlag(options::OPT_fsplit_machine_functions,
+ options::OPT_fno_split_machine_functions, false))
+ CmdArgs.push_back("-fsplit-machine-functions");
+
Args.AddLastArg(CmdArgs, options::OPT_finstrument_functions,
options::OPT_finstrument_functions_after_inlining,
options::OPT_finstrument_function_entry_bare);
Index: clang/lib/CodeGen/BackendUtil.cpp
===================================================================
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -514,6 +514,13 @@
Options.BBSectionsFuncListBuf = std::move(*MBOrErr);
}
+ if (CodeGenOpts.SplitMachineFunctions) {
+ if (CodeGenOpts.getProfileUse() != CodeGenOptions::ProfileNone)
+ Options.EnableMachineFunctionSplitter = true;
+ else
+ Diags.Report(diag::warn_fe_machine_function_splitter_missing_profile);
+ }
+
Options.FunctionSections = CodeGenOpts.FunctionSections;
Options.DataSections = CodeGenOpts.DataSections;
Options.UniqueSectionNames = CodeGenOpts.UniqueSectionNames;
Index: clang/include/clang/Driver/Options.td
===================================================================
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1989,6 +1989,12 @@
defm unique_section_names : OptOutFFlag<"unique-section-names",
"", "Don't use unique names for text and data sections">;
+def fsplit_machine_functions : Flag <["-"], "fsplit-machine-functions">,
+ Group<f_Group>, Flags<[CC1Option]>,
+ HelpText<"Split machine functions using profile information (x86-elf only)">;
+def fno_split_machine_functions: Flag <["-"], "fno-split-machine-functions">,
+ Group<f_Group>;
+
defm strict_return : OptOutFFlag<"strict-return", "",
"Don't treat control flow paths that fall off the end of a non-void function as unreachable">;
Index: clang/include/clang/Basic/DiagnosticFrontendKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -119,6 +119,9 @@
def err_fe_unable_to_load_basic_block_sections_file : Error<
"unable to load basic block sections function list: '%0'">;
+def warn_fe_machine_function_splitter_missing_profile : Warning<
+ "ignored -fsplit-machine-functions, no profile provided via -fprofile-use">;
+
def warn_fe_serialized_diag_merge_failure : Warning<
"unable to merge a subprocess's serialized diagnostics">,
InGroup<SerializedDiagnostics>;
Index: clang/include/clang/Basic/CodeGenOptions.def
===================================================================
--- clang/include/clang/Basic/CodeGenOptions.def
+++ clang/include/clang/Basic/CodeGenOptions.def
@@ -162,6 +162,7 @@
CODEGENOPT(NullPointerIsValid , 1, 0) ///< Assume Null pointer deference is defined.
CODEGENOPT(CorrectlyRoundedDivSqrt, 1, 0) ///< -cl-fp32-correctly-rounded-divide-sqrt
CODEGENOPT(UniqueInternalLinkageNames, 1, 0) ///< Internal Linkage symbols get unique names.
+CODEGENOPT(SplitMachineFunctions, 1, 0) ///< Split machine functions using profile information.
/// When false, this attempts to generate code as if the result of an
/// overflowing conversion matches the overflowing behavior of a target's native
Index: clang/docs/ClangCommandLineReference.rst
===================================================================
--- clang/docs/ClangCommandLineReference.rst
+++ clang/docs/ClangCommandLineReference.rst
@@ -2128,6 +2128,10 @@
Enables splitting of the LTO unit
+.. option:: -fsplit-machine-functions, -fno-split-machine-functions
+
+Split machine functions using profile information (x86-elf only)
+
.. option:: -fsplit-stack
.. option:: -fstack-clash-protection
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits