131 lines
4.6 KiB
Diff
131 lines
4.6 KiB
Diff
|
|
From ed300a0b07e608efb756b623263f014c2cebdf08 Mon Sep 17 00:00:00 2001
|
||
|
|
From: Egorov Ivan WX1280859 <egorov.ivan@huawei-partners.com>
|
||
|
|
Date: Tue, 26 Nov 2024 14:53:59 +0300
|
||
|
|
Subject: [PATCH 6/8] Add tracer transformation for static probabilities
|
||
|
|
|
||
|
|
---
|
||
|
|
gcc/common.opt | 4 ++++
|
||
|
|
gcc/opts.cc | 4 ++++
|
||
|
|
gcc/params.opt | 8 ++++++++
|
||
|
|
gcc/testsuite/gcc.dg/tracer-static-1.c | 28 ++++++++++++++++++++++++++
|
||
|
|
gcc/tracer.cc | 11 ++++++++++
|
||
|
|
5 files changed, 55 insertions(+)
|
||
|
|
create mode 100644 gcc/testsuite/gcc.dg/tracer-static-1.c
|
||
|
|
|
||
|
|
diff --git a/gcc/common.opt b/gcc/common.opt
|
||
|
|
index 96888cf1b..db35391c3 100644
|
||
|
|
--- a/gcc/common.opt
|
||
|
|
+++ b/gcc/common.opt
|
||
|
|
@@ -2990,6 +2990,10 @@ ftracer
|
||
|
|
Common Var(flag_tracer) Optimization
|
||
|
|
Perform superblock formation via tail duplication.
|
||
|
|
|
||
|
|
+ftracer-static
|
||
|
|
+Common Var(flag_tracer_static) Init(0) Optimization
|
||
|
|
+Perform superblock formation via tail duplication for a given bb size.
|
||
|
|
+
|
||
|
|
ftrampolines
|
||
|
|
Common Var(flag_trampolines) Init(0)
|
||
|
|
For targets that normally need trampolines for nested functions, always
|
||
|
|
diff --git a/gcc/opts.cc b/gcc/opts.cc
|
||
|
|
index 84dd8925a..34b84db8f 100644
|
||
|
|
--- a/gcc/opts.cc
|
||
|
|
+++ b/gcc/opts.cc
|
||
|
|
@@ -3180,6 +3180,10 @@ common_handle_option (struct gcc_options *opts,
|
||
|
|
}
|
||
|
|
break;
|
||
|
|
|
||
|
|
+ case OPT_ftracer_static:
|
||
|
|
+ SET_OPTION_IF_UNSET (opts, opts_set, flag_tracer, true);
|
||
|
|
+ break;
|
||
|
|
+
|
||
|
|
case OPT_ftree_vectorize:
|
||
|
|
/* Automatically sets -ftree-loop-vectorize and
|
||
|
|
-ftree-slp-vectorize. Nothing more to do here. */
|
||
|
|
diff --git a/gcc/params.opt b/gcc/params.opt
|
||
|
|
index bb4dc1825..e5472dfc8 100644
|
||
|
|
--- a/gcc/params.opt
|
||
|
|
+++ b/gcc/params.opt
|
||
|
|
@@ -1116,6 +1116,10 @@ The percentage of function, weighted by execution frequency, that must be covere
|
||
|
|
Common Joined UInteger Var(param_tracer_max_code_growth) Init(100) Param Optimization
|
||
|
|
Maximal code growth caused by tail duplication (in percent).
|
||
|
|
|
||
|
|
+-param=tracer-max-not-covered-insns-num=
|
||
|
|
+Common Joined UInteger Var(param_tracer_max_not_covered_insns_num) Init(12) Param Optimization
|
||
|
|
+Maximal number of instructions in the block, that must not be covered by trace formation.
|
||
|
|
+
|
||
|
|
-param=tracer-min-branch-probability=
|
||
|
|
Common Joined UInteger Var(param_tracer_min_branch_probability) Init(50) IntegerRange(0, 100) Param Optimization
|
||
|
|
Stop forward growth if the probability of best edge is less than this threshold (in percent). Used when profile feedback is not available.
|
||
|
|
@@ -1128,6 +1132,10 @@ Stop forward growth if the probability of best edge is less than this threshold
|
||
|
|
Common Joined UInteger Var(param_tracer_min_branch_ratio) Init(10) IntegerRange(0, 100) Param Optimization
|
||
|
|
Stop reverse growth if the reverse probability of best edge is less than this threshold (in percent).
|
||
|
|
|
||
|
|
+-param=tracer-min-not-covered-insns-num=
|
||
|
|
+Common Joined UInteger Var(param_tracer_min_not_covered_insns_num) Init(1) Param Optimization
|
||
|
|
+Minimal number of instructions in the block, that must not be covered by trace formation.
|
||
|
|
+
|
||
|
|
-param=tree-reassoc-width=
|
||
|
|
Common Joined UInteger Var(param_tree_reassoc_width) Param Optimization
|
||
|
|
Set the maximum number of instructions executed in parallel in reassociated tree. If 0, use the target dependent heuristic.
|
||
|
|
diff --git a/gcc/testsuite/gcc.dg/tracer-static-1.c b/gcc/testsuite/gcc.dg/tracer-static-1.c
|
||
|
|
new file mode 100644
|
||
|
|
index 000000000..76c863b48
|
||
|
|
--- /dev/null
|
||
|
|
+++ b/gcc/testsuite/gcc.dg/tracer-static-1.c
|
||
|
|
@@ -0,0 +1,28 @@
|
||
|
|
+/* { dg-do compile } */
|
||
|
|
+/* { dg-options "-O3 -ftracer-static -fdump-tree-tracer" } */
|
||
|
|
+
|
||
|
|
+static __attribute__ ((noinline)) int fib (int n)
|
||
|
|
+{
|
||
|
|
+ if (n < 3)
|
||
|
|
+ return 0;
|
||
|
|
+
|
||
|
|
+ long long fib1 = 0, fib2 = 1;
|
||
|
|
+ long long currentFib = 0;
|
||
|
|
+
|
||
|
|
+ for (int i = 3; i <= n; ++i)
|
||
|
|
+ {
|
||
|
|
+ currentFib = fib1 + fib2;
|
||
|
|
+ fib1 = fib2;
|
||
|
|
+ fib2 = currentFib;
|
||
|
|
+ }
|
||
|
|
+
|
||
|
|
+ return currentFib;
|
||
|
|
+}
|
||
|
|
+
|
||
|
|
+int main (int argc, char** argv)
|
||
|
|
+{
|
||
|
|
+ int n = argc;
|
||
|
|
+ return fib (n);
|
||
|
|
+}
|
||
|
|
+
|
||
|
|
+/* { dg-final { scan-tree-dump-times "BB\\d+ with n = \\d+ will not be covered by tracer formation" 4 "tracer" } } */
|
||
|
|
\ No newline at end of file
|
||
|
|
diff --git a/gcc/tracer.cc b/gcc/tracer.cc
|
||
|
|
index 4d054fe8f..9b1578cd4 100644
|
||
|
|
--- a/gcc/tracer.cc
|
||
|
|
+++ b/gcc/tracer.cc
|
||
|
|
@@ -304,6 +304,17 @@ tail_duplicate (void)
|
||
|
|
{
|
||
|
|
int n;
|
||
|
|
analyze_bb (bb, &n);
|
||
|
|
+
|
||
|
|
+ if (flag_tracer_static && n >= param_tracer_min_not_covered_insns_num
|
||
|
|
+ && n <= param_tracer_max_not_covered_insns_num)
|
||
|
|
+ {
|
||
|
|
+ if (dump_file)
|
||
|
|
+ fprintf (dump_file,
|
||
|
|
+ "BB%d with n = %d will not be covered by tracer formation\n",
|
||
|
|
+ bb->index, n);
|
||
|
|
+ continue;
|
||
|
|
+ }
|
||
|
|
+
|
||
|
|
if (!ignore_bb_p (bb))
|
||
|
|
blocks[bb->index] = heap.insert (-bb->count.to_frequency (cfun), bb);
|
||
|
|
|
||
|
|
--
|
||
|
|
2.33.0
|
||
|
|
|