twoh updated this revision to Diff 108967.
twoh added a comment.
Update documentation. Please let me know if I need to update other documents as
well. Thanks!
https://reviews.llvm.org/D34796
Files:
docs/ClangCommandLineReference.rst
include/clang/Driver/Options.td
include/clang/Frontend/CodeGenOptions.def
lib/CodeGen/BackendUtil.cpp
lib/Driver/ToolChains/Clang.cpp
lib/Frontend/CompilerInvocation.cpp
test/CodeGen/Inputs/freorder-functions.prof
test/CodeGen/freorder-functions.c
test/Driver/function-sections.c
Index: test/Driver/function-sections.c
===================================================================
--- test/Driver/function-sections.c
+++ test/Driver/function-sections.c
@@ -6,6 +6,8 @@
// CHECK-NODS-NOT: -fdata-sections
// CHECK-US-NOT: -fno-unique-section-names
// CHECK-NOUS: -fno-unique-section-names
+// CHECK-RF-NOT: -fno-reorder-functions
+// CHECK-NORF: -fno-reorder-functions
// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
// RUN: -target i386-unknown-linux \
@@ -72,3 +74,13 @@
// RUN: -target i386-unknown-linux \
// RUN: -fno-unique-section-names \
// RUN: | FileCheck --check-prefix=CHECK-NOUS %s
+
+// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
+// RUN: -target i386-unknown-linux \
+// RUN: -freorder-functions \
+// RUN: | FileCheck --check-prefix=CHECK-RF %s
+
+// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
+// RUN: -target i386-unknown-linux \
+// RUN: -fno-reorder-functions \
+// RUN: | FileCheck --check-prefix=CHECK-NORF %s
Index: test/CodeGen/freorder-functions.c
===================================================================
--- /dev/null
+++ test/CodeGen/freorder-functions.c
@@ -0,0 +1,22 @@
+// REQUIRES: x86-registered-target
+
+// RUN: %clang_cc1 -triple x86_64-pc-linux -S -O3 -ffunction-sections -fprofile-sample-use=%S/Inputs/freorder-functions.prof -o - < %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-pc-linux -S -O3 -ffunction-sections -fprofile-sample-use=%S/Inputs/freorder-functions.prof -fno-reorder-functions -o - < %s | FileCheck --check-prefix=CHECK-NOPREFIX %s
+
+// opt tool option precedes driver option.
+// RUN: %clang_cc1 -triple x86_64-pc-linux -S -O3 -ffunction-sections -fprofile-sample-use=%S/Inputs/freorder-functions.prof -fno-reorder-functions -mllvm -profile-guided-section-prefix=true -o - < %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-pc-linux -S -O3 -ffunction-sections -fprofile-sample-use=%S/Inputs/freorder-functions.prof -freorder-functions -mllvm -profile-guided-section-prefix=false -o - < %s | FileCheck --check-prefix=CHECK-NOPREFIX %s
+
+void hot_func() {
+ return;
+}
+
+void cold_func() {
+ hot_func();
+ return;
+}
+
+// CHECK: .section .text.hot.hot_func,"ax",@progbits
+// CHECK: .section .text.unlikely.cold_func,"ax",@progbits
+// CHECK-NOPREFIX: .section .text.hot_func,"ax",@progbits
+// CHECK-NOPREFIX: .section .text.cold_func,"ax",@progbits
Index: test/CodeGen/Inputs/freorder-functions.prof
===================================================================
--- /dev/null
+++ test/CodeGen/Inputs/freorder-functions.prof
@@ -0,0 +1,5 @@
+hot_func:1000:0
+ 1: 0
+cold_func:0:0
+ 1: 1
+ 2: 1
Index: lib/Frontend/CompilerInvocation.cpp
===================================================================
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -647,6 +647,8 @@
OPT_fno_data_sections, false);
Opts.UniqueSectionNames = Args.hasFlag(OPT_funique_section_names,
OPT_fno_unique_section_names, true);
+ Opts.ReorderFunctions =
+ Args.hasFlag(OPT_freorder_functions, OPT_fno_reorder_functions, true);
Opts.MergeFunctions = Args.hasArg(OPT_fmerge_functions);
Index: lib/Driver/ToolChains/Clang.cpp
===================================================================
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -2899,6 +2899,10 @@
options::OPT_fno_unique_section_names, true))
CmdArgs.push_back("-fno-unique-section-names");
+ if (!Args.hasFlag(options::OPT_freorder_functions,
+ options::OPT_fno_reorder_functions, true))
+ CmdArgs.push_back("-fno-reorder-functions");
+
Args.AddAllArgs(CmdArgs, options::OPT_finstrument_functions);
addPGOAndCoverageFlags(C, D, Output, Args, CmdArgs);
Index: lib/CodeGen/BackendUtil.cpp
===================================================================
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -429,6 +429,7 @@
Options.FunctionSections = CodeGenOpts.FunctionSections;
Options.DataSections = CodeGenOpts.DataSections;
Options.UniqueSectionNames = CodeGenOpts.UniqueSectionNames;
+ Options.ReorderFunctions = CodeGenOpts.ReorderFunctions;
Options.EmulatedTLS = CodeGenOpts.EmulatedTLS;
Options.DebuggerTuning = CodeGenOpts.getDebuggerTuning();
Index: include/clang/Frontend/CodeGenOptions.def
===================================================================
--- include/clang/Frontend/CodeGenOptions.def
+++ include/clang/Frontend/CodeGenOptions.def
@@ -177,6 +177,7 @@
CODEGENOPT(TimePasses , 1, 0) ///< Set when -ftime-report is enabled.
CODEGENOPT(UnrollLoops , 1, 0) ///< Control whether loops are unrolled.
CODEGENOPT(RerollLoops , 1, 0) ///< Control whether loops are rerolled.
+CODEGENOPT(ReorderFunctions , 1, 1) ///< Set when -freorder-functions is enabled.
CODEGENOPT(NoUseJumpTables , 1, 0) ///< Set when -fno-jump-tables is enabled.
CODEGENOPT(UnsafeFPMath , 1, 0) ///< Allow unsafe floating point optzns.
CODEGENOPT(UnwindTables , 1, 0) ///< Emit unwind tables.
Index: include/clang/Driver/Options.td
===================================================================
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1345,6 +1345,12 @@
def frandom_seed_EQ : Joined<["-"], "frandom-seed=">, Group<clang_ignored_f_Group>;
def freg_struct_return : Flag<["-"], "freg-struct-return">, Group<f_Group>, Flags<[CC1Option]>,
HelpText<"Override the default ABI to return small structs in registers">;
+def freorder_functions : Flag <["-"], "freorder-functions">,
+ Group<f_Group>, Flags<[CC1Option]>,
+ HelpText<"Using special subsections for hot/cold functions to improve code "
+ "locality">;
+def fno_reorder_functions : Flag <["-"], "fno-reorder-functions">,
+ Group<f_Group>, Flags<[CC1Option]>;
def frtti : Flag<["-"], "frtti">, Group<f_Group>;
def : Flag<["-"], "fsched-interblock">, Group<clang_ignored_f_Group>;
def fshort_enums : Flag<["-"], "fshort-enums">, Group<f_Group>, Flags<[CC1Option]>,
Index: docs/ClangCommandLineReference.rst
===================================================================
--- docs/ClangCommandLineReference.rst
+++ docs/ClangCommandLineReference.rst
@@ -1745,6 +1745,10 @@
Use unique names for text and data sections (ELF Only)
+.. option:: -freorder-functions, -fno-reorder-functions
+
+Add section prefixes for hot/cold functions
+
.. option:: -funit-at-a-time, -fno-unit-at-a-time
.. option:: -funroll-loops, -fno-unroll-loops
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits