summaryrefslogtreecommitdiff
path: root/0313-Add-tracer-transformation-for-static-probabilities.patch
blob: 53d233718de0f2c0015796ce14f49e9b1799840c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
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