annotate gcc/tree-profile.c @ 144:8f4e72ab4e11

fix segmentation fault caused by nothing next cur_op to end
author Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Sun, 23 Dec 2018 21:23:56 +0900
parents 84e7813d76e9
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 /* Calculate branch probabilities, and basic block execution counts.
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2 Copyright (C) 1990-2018 Free Software Foundation, Inc.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 Contributed by James E. Wilson, UC Berkeley/Cygnus Support;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 based on some ideas from Dain Samples of UC Berkeley.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 Further mangling by Bob Manson, Cygnus Support.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 Converted to use trees by Dale Johannesen, Apple Computer.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 This file is part of GCC.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 GCC is free software; you can redistribute it and/or modify it under
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 the terms of the GNU General Public License as published by the Free
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 Software Foundation; either version 3, or (at your option) any later
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 version.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 for more details.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 You should have received a copy of the GNU General Public License
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 along with GCC; see the file COPYING3. If not see
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 <http://www.gnu.org/licenses/>. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 /* Generate basic block profile instrumentation and auxiliary files.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 Tree-based version. See profile.c for overview. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 #include "config.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 #include "system.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 #include "coretypes.h"
111
kono
parents: 67
diff changeset
30 #include "memmodel.h"
kono
parents: 67
diff changeset
31 #include "backend.h"
kono
parents: 67
diff changeset
32 #include "target.h"
kono
parents: 67
diff changeset
33 #include "tree.h"
kono
parents: 67
diff changeset
34 #include "gimple.h"
kono
parents: 67
diff changeset
35 #include "cfghooks.h"
kono
parents: 67
diff changeset
36 #include "tree-pass.h"
kono
parents: 67
diff changeset
37 #include "ssa.h"
kono
parents: 67
diff changeset
38 #include "cgraph.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 #include "coverage.h"
111
kono
parents: 67
diff changeset
40 #include "diagnostic-core.h"
kono
parents: 67
diff changeset
41 #include "fold-const.h"
kono
parents: 67
diff changeset
42 #include "varasm.h"
kono
parents: 67
diff changeset
43 #include "tree-nested.h"
kono
parents: 67
diff changeset
44 #include "gimplify.h"
kono
parents: 67
diff changeset
45 #include "gimple-iterator.h"
kono
parents: 67
diff changeset
46 #include "gimplify-me.h"
kono
parents: 67
diff changeset
47 #include "tree-cfg.h"
kono
parents: 67
diff changeset
48 #include "tree-into-ssa.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 #include "value-prof.h"
111
kono
parents: 67
diff changeset
50 #include "profile.h"
kono
parents: 67
diff changeset
51 #include "tree-cfgcleanup.h"
kono
parents: 67
diff changeset
52 #include "params.h"
kono
parents: 67
diff changeset
53 #include "stringpool.h"
kono
parents: 67
diff changeset
54 #include "attribs.h"
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
55 #include "tree-pretty-print.h"
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
56 #include "langhooks.h"
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
57 #include "stor-layout.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
58
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 static GTY(()) tree gcov_type_node;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 static GTY(()) tree tree_interval_profiler_fn;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 static GTY(()) tree tree_pow2_profiler_fn;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 static GTY(()) tree tree_one_value_profiler_fn;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 static GTY(()) tree tree_indirect_call_profiler_fn;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 static GTY(()) tree tree_average_profiler_fn;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 static GTY(()) tree tree_ior_profiler_fn;
111
kono
parents: 67
diff changeset
66 static GTY(()) tree tree_time_profiler_counter;
kono
parents: 67
diff changeset
67
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
68
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
69 static GTY(()) tree ic_tuple_var;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
70 static GTY(()) tree ic_tuple_counters_field;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
71 static GTY(()) tree ic_tuple_callee_field;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
72
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 /* Do initialization work for the edge profiler. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
74
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 /* Add code:
111
kono
parents: 67
diff changeset
76 __thread gcov* __gcov_indirect_call_counters; // pointer to actual counter
kono
parents: 67
diff changeset
77 __thread void* __gcov_indirect_call_callee; // actual callee address
kono
parents: 67
diff changeset
78 __thread int __gcov_function_counter; // time profiler function counter
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 static void
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
81 init_ic_make_global_vars (void)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 {
111
kono
parents: 67
diff changeset
83 tree gcov_type_ptr;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
84
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
85 gcov_type_ptr = build_pointer_type (get_gcov_type ());
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
86
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
87 tree tuple_type = lang_hooks.types.make_type (RECORD_TYPE);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
88
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
89 /* callee */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
90 ic_tuple_callee_field = build_decl (BUILTINS_LOCATION, FIELD_DECL, NULL_TREE,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
91 ptr_type_node);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
92
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
93 /* counters */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
94 ic_tuple_counters_field = build_decl (BUILTINS_LOCATION, FIELD_DECL,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
95 NULL_TREE, gcov_type_ptr);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
96 DECL_CHAIN (ic_tuple_counters_field) = ic_tuple_callee_field;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
97
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
98 finish_builtin_struct (tuple_type, "indirect_call_tuple",
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
99 ic_tuple_counters_field, NULL_TREE);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
100
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
101 ic_tuple_var
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
102 = build_decl (UNKNOWN_LOCATION, VAR_DECL,
111
kono
parents: 67
diff changeset
103 get_identifier (
kono
parents: 67
diff changeset
104 (PARAM_VALUE (PARAM_INDIR_CALL_TOPN_PROFILE) ?
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
105 "__gcov_indirect_call_topn" :
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
106 "__gcov_indirect_call")),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
107 tuple_type);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
108 TREE_PUBLIC (ic_tuple_var) = 1;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
109 DECL_ARTIFICIAL (ic_tuple_var) = 1;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
110 DECL_INITIAL (ic_tuple_var) = NULL;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
111 DECL_EXTERNAL (ic_tuple_var) = 1;
111
kono
parents: 67
diff changeset
112 if (targetm.have_tls)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
113 set_decl_tls_model (ic_tuple_var, decl_default_tls_model (tuple_type));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
115
111
kono
parents: 67
diff changeset
116 /* Create the type and function decls for the interface with gcov. */
kono
parents: 67
diff changeset
117
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
118 void
111
kono
parents: 67
diff changeset
119 gimple_init_gcov_profiler (void)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 tree interval_profiler_fn_type;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 tree pow2_profiler_fn_type;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 tree one_value_profiler_fn_type;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 tree gcov_type_ptr;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 tree ic_profiler_fn_type;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 tree average_profiler_fn_type;
111
kono
parents: 67
diff changeset
127 const char *profiler_fn_name;
kono
parents: 67
diff changeset
128 const char *fn_name;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
129
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 if (!gcov_type_node)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 {
111
kono
parents: 67
diff changeset
132 const char *fn_suffix
kono
parents: 67
diff changeset
133 = flag_profile_update == PROFILE_UPDATE_ATOMIC ? "_atomic" : "";
kono
parents: 67
diff changeset
134
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 gcov_type_node = get_gcov_type ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 gcov_type_ptr = build_pointer_type (gcov_type_node);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
137
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
138 /* void (*) (gcov_type *, gcov_type, int, unsigned) */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
139 interval_profiler_fn_type
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
140 = build_function_type_list (void_type_node,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
141 gcov_type_ptr, gcov_type_node,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 integer_type_node,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
143 unsigned_type_node, NULL_TREE);
111
kono
parents: 67
diff changeset
144 fn_name = concat ("__gcov_interval_profiler", fn_suffix, NULL);
kono
parents: 67
diff changeset
145 tree_interval_profiler_fn = build_fn_decl (fn_name,
kono
parents: 67
diff changeset
146 interval_profiler_fn_type);
kono
parents: 67
diff changeset
147 free (CONST_CAST (char *, fn_name));
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
148 TREE_NOTHROW (tree_interval_profiler_fn) = 1;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
149 DECL_ATTRIBUTES (tree_interval_profiler_fn)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
150 = tree_cons (get_identifier ("leaf"), NULL,
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
151 DECL_ATTRIBUTES (tree_interval_profiler_fn));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
152
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 /* void (*) (gcov_type *, gcov_type) */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
154 pow2_profiler_fn_type
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
155 = build_function_type_list (void_type_node,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
156 gcov_type_ptr, gcov_type_node,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
157 NULL_TREE);
111
kono
parents: 67
diff changeset
158 fn_name = concat ("__gcov_pow2_profiler", fn_suffix, NULL);
kono
parents: 67
diff changeset
159 tree_pow2_profiler_fn = build_fn_decl (fn_name, pow2_profiler_fn_type);
kono
parents: 67
diff changeset
160 free (CONST_CAST (char *, fn_name));
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
161 TREE_NOTHROW (tree_pow2_profiler_fn) = 1;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
162 DECL_ATTRIBUTES (tree_pow2_profiler_fn)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
163 = tree_cons (get_identifier ("leaf"), NULL,
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
164 DECL_ATTRIBUTES (tree_pow2_profiler_fn));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
165
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
166 /* void (*) (gcov_type *, gcov_type) */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
167 one_value_profiler_fn_type
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 = build_function_type_list (void_type_node,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
169 gcov_type_ptr, gcov_type_node,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 NULL_TREE);
111
kono
parents: 67
diff changeset
171 fn_name = concat ("__gcov_one_value_profiler", fn_suffix, NULL);
kono
parents: 67
diff changeset
172 tree_one_value_profiler_fn = build_fn_decl (fn_name,
kono
parents: 67
diff changeset
173 one_value_profiler_fn_type);
kono
parents: 67
diff changeset
174 free (CONST_CAST (char *, fn_name));
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
175 TREE_NOTHROW (tree_one_value_profiler_fn) = 1;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
176 DECL_ATTRIBUTES (tree_one_value_profiler_fn)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
177 = tree_cons (get_identifier ("leaf"), NULL,
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
178 DECL_ATTRIBUTES (tree_one_value_profiler_fn));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
179
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
180 init_ic_make_global_vars ();
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
181
111
kono
parents: 67
diff changeset
182 /* void (*) (gcov_type, void *) */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
183 ic_profiler_fn_type
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
184 = build_function_type_list (void_type_node,
111
kono
parents: 67
diff changeset
185 gcov_type_node,
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
186 ptr_type_node,
111
kono
parents: 67
diff changeset
187 NULL_TREE);
kono
parents: 67
diff changeset
188 profiler_fn_name = "__gcov_indirect_call_profiler_v2";
kono
parents: 67
diff changeset
189 if (PARAM_VALUE (PARAM_INDIR_CALL_TOPN_PROFILE))
kono
parents: 67
diff changeset
190 profiler_fn_name = "__gcov_indirect_call_topn_profiler";
kono
parents: 67
diff changeset
191
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
192 tree_indirect_call_profiler_fn
111
kono
parents: 67
diff changeset
193 = build_fn_decl (profiler_fn_name, ic_profiler_fn_type);
kono
parents: 67
diff changeset
194
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
195 TREE_NOTHROW (tree_indirect_call_profiler_fn) = 1;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
196 DECL_ATTRIBUTES (tree_indirect_call_profiler_fn)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
197 = tree_cons (get_identifier ("leaf"), NULL,
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
198 DECL_ATTRIBUTES (tree_indirect_call_profiler_fn));
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
199
111
kono
parents: 67
diff changeset
200 tree_time_profiler_counter
kono
parents: 67
diff changeset
201 = build_decl (UNKNOWN_LOCATION, VAR_DECL,
kono
parents: 67
diff changeset
202 get_identifier ("__gcov_time_profiler_counter"),
kono
parents: 67
diff changeset
203 get_gcov_type ());
kono
parents: 67
diff changeset
204 TREE_PUBLIC (tree_time_profiler_counter) = 1;
kono
parents: 67
diff changeset
205 DECL_EXTERNAL (tree_time_profiler_counter) = 1;
kono
parents: 67
diff changeset
206 TREE_STATIC (tree_time_profiler_counter) = 1;
kono
parents: 67
diff changeset
207 DECL_ARTIFICIAL (tree_time_profiler_counter) = 1;
kono
parents: 67
diff changeset
208 DECL_INITIAL (tree_time_profiler_counter) = NULL;
kono
parents: 67
diff changeset
209
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
210 /* void (*) (gcov_type *, gcov_type) */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
211 average_profiler_fn_type
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
212 = build_function_type_list (void_type_node,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
213 gcov_type_ptr, gcov_type_node, NULL_TREE);
111
kono
parents: 67
diff changeset
214 fn_name = concat ("__gcov_average_profiler", fn_suffix, NULL);
kono
parents: 67
diff changeset
215 tree_average_profiler_fn = build_fn_decl (fn_name,
kono
parents: 67
diff changeset
216 average_profiler_fn_type);
kono
parents: 67
diff changeset
217 free (CONST_CAST (char *, fn_name));
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
218 TREE_NOTHROW (tree_average_profiler_fn) = 1;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
219 DECL_ATTRIBUTES (tree_average_profiler_fn)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
220 = tree_cons (get_identifier ("leaf"), NULL,
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
221 DECL_ATTRIBUTES (tree_average_profiler_fn));
111
kono
parents: 67
diff changeset
222 fn_name = concat ("__gcov_ior_profiler", fn_suffix, NULL);
kono
parents: 67
diff changeset
223 tree_ior_profiler_fn = build_fn_decl (fn_name, average_profiler_fn_type);
kono
parents: 67
diff changeset
224 free (CONST_CAST (char *, fn_name));
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
225 TREE_NOTHROW (tree_ior_profiler_fn) = 1;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
226 DECL_ATTRIBUTES (tree_ior_profiler_fn)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
227 = tree_cons (get_identifier ("leaf"), NULL,
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
228 DECL_ATTRIBUTES (tree_ior_profiler_fn));
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
229
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
230 /* LTO streamer needs assembler names. Because we create these decls
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
231 late, we need to initialize them by hand. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
232 DECL_ASSEMBLER_NAME (tree_interval_profiler_fn);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
233 DECL_ASSEMBLER_NAME (tree_pow2_profiler_fn);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
234 DECL_ASSEMBLER_NAME (tree_one_value_profiler_fn);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
235 DECL_ASSEMBLER_NAME (tree_indirect_call_profiler_fn);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
236 DECL_ASSEMBLER_NAME (tree_average_profiler_fn);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
237 DECL_ASSEMBLER_NAME (tree_ior_profiler_fn);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
238 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
239 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
240
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
241 /* Output instructions as GIMPLE trees to increment the edge
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
242 execution count, and insert them on E. We rely on
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
243 gsi_insert_on_edge to preserve the order. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
244
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
245 void
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
246 gimple_gen_edge_profiler (int edgeno, edge e)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
247 {
111
kono
parents: 67
diff changeset
248 tree one;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
249
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
250 one = build_int_cst (gcov_type_node, 1);
111
kono
parents: 67
diff changeset
251
kono
parents: 67
diff changeset
252 if (flag_profile_update == PROFILE_UPDATE_ATOMIC)
kono
parents: 67
diff changeset
253 {
kono
parents: 67
diff changeset
254 /* __atomic_fetch_add (&counter, 1, MEMMODEL_RELAXED); */
kono
parents: 67
diff changeset
255 tree addr = tree_coverage_counter_addr (GCOV_COUNTER_ARCS, edgeno);
kono
parents: 67
diff changeset
256 tree f = builtin_decl_explicit (LONG_LONG_TYPE_SIZE > 32
kono
parents: 67
diff changeset
257 ? BUILT_IN_ATOMIC_FETCH_ADD_8:
kono
parents: 67
diff changeset
258 BUILT_IN_ATOMIC_FETCH_ADD_4);
kono
parents: 67
diff changeset
259 gcall *stmt = gimple_build_call (f, 3, addr, one,
kono
parents: 67
diff changeset
260 build_int_cst (integer_type_node,
kono
parents: 67
diff changeset
261 MEMMODEL_RELAXED));
kono
parents: 67
diff changeset
262 gsi_insert_on_edge (e, stmt);
kono
parents: 67
diff changeset
263 }
kono
parents: 67
diff changeset
264 else
kono
parents: 67
diff changeset
265 {
kono
parents: 67
diff changeset
266 tree ref = tree_coverage_counter_ref (GCOV_COUNTER_ARCS, edgeno);
kono
parents: 67
diff changeset
267 tree gcov_type_tmp_var = make_temp_ssa_name (gcov_type_node,
kono
parents: 67
diff changeset
268 NULL, "PROF_edge_counter");
kono
parents: 67
diff changeset
269 gassign *stmt1 = gimple_build_assign (gcov_type_tmp_var, ref);
kono
parents: 67
diff changeset
270 gcov_type_tmp_var = make_temp_ssa_name (gcov_type_node,
kono
parents: 67
diff changeset
271 NULL, "PROF_edge_counter");
kono
parents: 67
diff changeset
272 gassign *stmt2 = gimple_build_assign (gcov_type_tmp_var, PLUS_EXPR,
kono
parents: 67
diff changeset
273 gimple_assign_lhs (stmt1), one);
kono
parents: 67
diff changeset
274 gassign *stmt3 = gimple_build_assign (unshare_expr (ref),
kono
parents: 67
diff changeset
275 gimple_assign_lhs (stmt2));
kono
parents: 67
diff changeset
276 gsi_insert_on_edge (e, stmt1);
kono
parents: 67
diff changeset
277 gsi_insert_on_edge (e, stmt2);
kono
parents: 67
diff changeset
278 gsi_insert_on_edge (e, stmt3);
kono
parents: 67
diff changeset
279 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
280 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
281
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
282 /* Emits code to get VALUE to instrument at GSI, and returns the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
283 variable containing the value. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
284
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
285 static tree
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
286 prepare_instrumented_value (gimple_stmt_iterator *gsi, histogram_value value)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
287 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
288 tree val = value->hvalue.value;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
289 if (POINTER_TYPE_P (TREE_TYPE (val)))
111
kono
parents: 67
diff changeset
290 val = fold_convert (build_nonstandard_integer_type
kono
parents: 67
diff changeset
291 (TYPE_PRECISION (TREE_TYPE (val)), 1), val);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
292 return force_gimple_operand_gsi (gsi, fold_convert (gcov_type_node, val),
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
293 true, NULL_TREE, true, GSI_SAME_STMT);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
294 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
295
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
296 /* Output instructions as GIMPLE trees to increment the interval histogram
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
297 counter. VALUE is the expression whose value is profiled. TAG is the
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
298 tag of the section for counters, BASE is offset of the counter position. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
299
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
300 void
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
301 gimple_gen_interval_profiler (histogram_value value, unsigned tag, unsigned base)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
302 {
111
kono
parents: 67
diff changeset
303 gimple *stmt = value->hvalue.stmt;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
304 gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
305 tree ref = tree_coverage_counter_ref (tag, base), ref_ptr;
111
kono
parents: 67
diff changeset
306 gcall *call;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
307 tree val;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
308 tree start = build_int_cst_type (integer_type_node,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
309 value->hdata.intvl.int_start);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
310 tree steps = build_int_cst_type (unsigned_type_node,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
311 value->hdata.intvl.steps);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
312
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
313 ref_ptr = force_gimple_operand_gsi (&gsi,
111
kono
parents: 67
diff changeset
314 build_addr (ref),
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
315 true, NULL_TREE, true, GSI_SAME_STMT);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
316 val = prepare_instrumented_value (&gsi, value);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
317 call = gimple_build_call (tree_interval_profiler_fn, 4,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
318 ref_ptr, val, start, steps);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
319 gsi_insert_before (&gsi, call, GSI_NEW_STMT);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
320 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
321
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
322 /* Output instructions as GIMPLE trees to increment the power of two histogram
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
323 counter. VALUE is the expression whose value is profiled. TAG is the tag
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
324 of the section for counters, BASE is offset of the counter position. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
325
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
326 void
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
327 gimple_gen_pow2_profiler (histogram_value value, unsigned tag, unsigned base)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
328 {
111
kono
parents: 67
diff changeset
329 gimple *stmt = value->hvalue.stmt;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
330 gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
331 tree ref_ptr = tree_coverage_counter_addr (tag, base);
111
kono
parents: 67
diff changeset
332 gcall *call;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
333 tree val;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
334
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
335 ref_ptr = force_gimple_operand_gsi (&gsi, ref_ptr,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
336 true, NULL_TREE, true, GSI_SAME_STMT);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
337 val = prepare_instrumented_value (&gsi, value);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
338 call = gimple_build_call (tree_pow2_profiler_fn, 2, ref_ptr, val);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
339 gsi_insert_before (&gsi, call, GSI_NEW_STMT);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
340 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
341
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
342 /* Output instructions as GIMPLE trees for code to find the most common value.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
343 VALUE is the expression whose value is profiled. TAG is the tag of the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
344 section for counters, BASE is offset of the counter position. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
345
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
346 void
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
347 gimple_gen_one_value_profiler (histogram_value value, unsigned tag, unsigned base)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
348 {
111
kono
parents: 67
diff changeset
349 gimple *stmt = value->hvalue.stmt;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
350 gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
351 tree ref_ptr = tree_coverage_counter_addr (tag, base);
111
kono
parents: 67
diff changeset
352 gcall *call;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
353 tree val;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
354
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
355 ref_ptr = force_gimple_operand_gsi (&gsi, ref_ptr,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
356 true, NULL_TREE, true, GSI_SAME_STMT);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
357 val = prepare_instrumented_value (&gsi, value);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
358 call = gimple_build_call (tree_one_value_profiler_fn, 2, ref_ptr, val);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
359 gsi_insert_before (&gsi, call, GSI_NEW_STMT);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
360 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
361
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
362
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
363 /* Output instructions as GIMPLE trees for code to find the most
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
364 common called function in indirect call.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
365 VALUE is the call expression whose indirect callee is profiled.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
366 TAG is the tag of the section for counters, BASE is offset of the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
367 counter position. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
368
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
369 void
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
370 gimple_gen_ic_profiler (histogram_value value, unsigned tag, unsigned base)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
371 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
372 tree tmp1;
111
kono
parents: 67
diff changeset
373 gassign *stmt1, *stmt2, *stmt3;
kono
parents: 67
diff changeset
374 gimple *stmt = value->hvalue.stmt;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
375 gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
376 tree ref_ptr = tree_coverage_counter_addr (tag, base);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
377
111
kono
parents: 67
diff changeset
378 if ( (PARAM_VALUE (PARAM_INDIR_CALL_TOPN_PROFILE) &&
kono
parents: 67
diff changeset
379 tag == GCOV_COUNTER_V_INDIR) ||
kono
parents: 67
diff changeset
380 (!PARAM_VALUE (PARAM_INDIR_CALL_TOPN_PROFILE) &&
kono
parents: 67
diff changeset
381 tag == GCOV_COUNTER_ICALL_TOPNV))
kono
parents: 67
diff changeset
382 return;
kono
parents: 67
diff changeset
383
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
384 ref_ptr = force_gimple_operand_gsi (&gsi, ref_ptr,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
385 true, NULL_TREE, true, GSI_SAME_STMT);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
386
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
387 /* Insert code:
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
388
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
389 stmt1: __gcov_indirect_call.counters = get_relevant_counter_ptr ();
111
kono
parents: 67
diff changeset
390 stmt2: tmp1 = (void *) (indirect call argument value)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
391 stmt3: __gcov_indirect_call.callee = tmp1;
111
kono
parents: 67
diff changeset
392
kono
parents: 67
diff changeset
393 Example:
kono
parents: 67
diff changeset
394 f_1 = foo;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
395 __gcov_indirect_call.counters = &__gcov4.main[0];
111
kono
parents: 67
diff changeset
396 PROF_9 = f_1;
kono
parents: 67
diff changeset
397 __gcov_indirect_call_callee = PROF_9;
kono
parents: 67
diff changeset
398 _4 = f_1 ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
399 */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
400
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
401 tree gcov_type_ptr = build_pointer_type (get_gcov_type ());
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
402
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
403 tree counter_ref = build3 (COMPONENT_REF, gcov_type_ptr,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
404 ic_tuple_var, ic_tuple_counters_field, NULL_TREE);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
405
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
406 stmt1 = gimple_build_assign (counter_ref, ref_ptr);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
407 tmp1 = make_temp_ssa_name (ptr_type_node, NULL, "PROF");
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
408 stmt2 = gimple_build_assign (tmp1, unshare_expr (value->hvalue.value));
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
409 tree callee_ref = build3 (COMPONENT_REF, ptr_type_node,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
410 ic_tuple_var, ic_tuple_callee_field, NULL_TREE);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
411 stmt3 = gimple_build_assign (callee_ref, tmp1);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
412
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
413 gsi_insert_before (&gsi, stmt1, GSI_SAME_STMT);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
414 gsi_insert_before (&gsi, stmt2, GSI_SAME_STMT);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
415 gsi_insert_before (&gsi, stmt3, GSI_SAME_STMT);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
416 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
417
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
418
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
419 /* Output instructions as GIMPLE trees for code to find the most
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
420 common called function in indirect call. Insert instructions at the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
421 beginning of every possible called function.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
422 */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
423
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
424 void
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
425 gimple_gen_ic_func_profiler (void)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
426 {
111
kono
parents: 67
diff changeset
427 struct cgraph_node * c_node = cgraph_node::get (current_function_decl);
kono
parents: 67
diff changeset
428 gcall *stmt1;
kono
parents: 67
diff changeset
429 tree tree_uid, cur_func, void0;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
430
111
kono
parents: 67
diff changeset
431 if (c_node->only_called_directly_p ())
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
432 return;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
433
111
kono
parents: 67
diff changeset
434 gimple_init_gcov_profiler ();
kono
parents: 67
diff changeset
435
kono
parents: 67
diff changeset
436 basic_block entry = ENTRY_BLOCK_PTR_FOR_FN (cfun);
kono
parents: 67
diff changeset
437 basic_block cond_bb = split_edge (single_succ_edge (entry));
kono
parents: 67
diff changeset
438 basic_block update_bb = split_edge (single_succ_edge (cond_bb));
kono
parents: 67
diff changeset
439
kono
parents: 67
diff changeset
440 /* We need to do an extra split in order to not create an input
kono
parents: 67
diff changeset
441 for a possible PHI node. */
kono
parents: 67
diff changeset
442 split_edge (single_succ_edge (update_bb));
kono
parents: 67
diff changeset
443
kono
parents: 67
diff changeset
444 edge true_edge = single_succ_edge (cond_bb);
kono
parents: 67
diff changeset
445 true_edge->flags = EDGE_TRUE_VALUE;
kono
parents: 67
diff changeset
446
kono
parents: 67
diff changeset
447 profile_probability probability;
kono
parents: 67
diff changeset
448 if (DECL_VIRTUAL_P (current_function_decl))
kono
parents: 67
diff changeset
449 probability = profile_probability::very_likely ();
kono
parents: 67
diff changeset
450 else
kono
parents: 67
diff changeset
451 probability = profile_probability::unlikely ();
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
452
111
kono
parents: 67
diff changeset
453 true_edge->probability = probability;
kono
parents: 67
diff changeset
454 edge e = make_edge (cond_bb, single_succ_edge (update_bb)->dest,
kono
parents: 67
diff changeset
455 EDGE_FALSE_VALUE);
kono
parents: 67
diff changeset
456 e->probability = true_edge->probability.invert ();
kono
parents: 67
diff changeset
457
kono
parents: 67
diff changeset
458 /* Insert code:
kono
parents: 67
diff changeset
459
kono
parents: 67
diff changeset
460 if (__gcov_indirect_call_callee != NULL)
kono
parents: 67
diff changeset
461 __gcov_indirect_call_profiler_v2 (profile_id, &current_function_decl);
kono
parents: 67
diff changeset
462
kono
parents: 67
diff changeset
463 The function __gcov_indirect_call_profiler_v2 is responsible for
kono
parents: 67
diff changeset
464 resetting __gcov_indirect_call_callee to NULL. */
kono
parents: 67
diff changeset
465
kono
parents: 67
diff changeset
466 gimple_stmt_iterator gsi = gsi_start_bb (cond_bb);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
467 void0 = build_int_cst (ptr_type_node, 0);
111
kono
parents: 67
diff changeset
468
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
469 tree callee_ref = build3 (COMPONENT_REF, ptr_type_node,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
470 ic_tuple_var, ic_tuple_callee_field, NULL_TREE);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
471
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
472 tree ref = force_gimple_operand_gsi (&gsi, callee_ref, true, NULL_TREE,
111
kono
parents: 67
diff changeset
473 true, GSI_SAME_STMT);
kono
parents: 67
diff changeset
474
kono
parents: 67
diff changeset
475 gcond *cond = gimple_build_cond (NE_EXPR, ref,
kono
parents: 67
diff changeset
476 void0, NULL, NULL);
kono
parents: 67
diff changeset
477 gsi_insert_before (&gsi, cond, GSI_NEW_STMT);
kono
parents: 67
diff changeset
478
kono
parents: 67
diff changeset
479 gsi = gsi_after_labels (update_bb);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
480
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
481 cur_func = force_gimple_operand_gsi (&gsi,
111
kono
parents: 67
diff changeset
482 build_addr (current_function_decl),
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
483 true, NULL_TREE,
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
484 true, GSI_SAME_STMT);
111
kono
parents: 67
diff changeset
485 tree_uid = build_int_cst
kono
parents: 67
diff changeset
486 (gcov_type_node,
kono
parents: 67
diff changeset
487 cgraph_node::get (current_function_decl)->profile_id);
kono
parents: 67
diff changeset
488 stmt1 = gimple_build_call (tree_indirect_call_profiler_fn, 2,
kono
parents: 67
diff changeset
489 tree_uid, cur_func);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
490 gsi_insert_before (&gsi, stmt1, GSI_SAME_STMT);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
491 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
492
111
kono
parents: 67
diff changeset
493 /* Output instructions as GIMPLE tree at the beginning for each function.
kono
parents: 67
diff changeset
494 TAG is the tag of the section for counters, BASE is offset of the
kono
parents: 67
diff changeset
495 counter position and GSI is the iterator we place the counter. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
496
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
497 void
111
kono
parents: 67
diff changeset
498 gimple_gen_time_profiler (unsigned tag, unsigned base)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
499 {
111
kono
parents: 67
diff changeset
500 tree type = get_gcov_type ();
kono
parents: 67
diff changeset
501 basic_block entry = ENTRY_BLOCK_PTR_FOR_FN (cfun);
kono
parents: 67
diff changeset
502 basic_block cond_bb = split_edge (single_succ_edge (entry));
kono
parents: 67
diff changeset
503 basic_block update_bb = split_edge (single_succ_edge (cond_bb));
kono
parents: 67
diff changeset
504
kono
parents: 67
diff changeset
505 /* We need to do an extra split in order to not create an input
kono
parents: 67
diff changeset
506 for a possible PHI node. */
kono
parents: 67
diff changeset
507 split_edge (single_succ_edge (update_bb));
kono
parents: 67
diff changeset
508
kono
parents: 67
diff changeset
509 edge true_edge = single_succ_edge (cond_bb);
kono
parents: 67
diff changeset
510 true_edge->flags = EDGE_TRUE_VALUE;
kono
parents: 67
diff changeset
511 true_edge->probability = profile_probability::unlikely ();
kono
parents: 67
diff changeset
512 edge e
kono
parents: 67
diff changeset
513 = make_edge (cond_bb, single_succ_edge (update_bb)->dest, EDGE_FALSE_VALUE);
kono
parents: 67
diff changeset
514 e->probability = true_edge->probability.invert ();
kono
parents: 67
diff changeset
515
kono
parents: 67
diff changeset
516 gimple_stmt_iterator gsi = gsi_start_bb (cond_bb);
kono
parents: 67
diff changeset
517 tree original_ref = tree_coverage_counter_ref (tag, base);
kono
parents: 67
diff changeset
518 tree ref = force_gimple_operand_gsi (&gsi, original_ref, true, NULL_TREE,
kono
parents: 67
diff changeset
519 true, GSI_SAME_STMT);
kono
parents: 67
diff changeset
520 tree one = build_int_cst (type, 1);
kono
parents: 67
diff changeset
521
kono
parents: 67
diff changeset
522 /* Emit: if (counters[0] != 0). */
kono
parents: 67
diff changeset
523 gcond *cond = gimple_build_cond (EQ_EXPR, ref, build_int_cst (type, 0),
kono
parents: 67
diff changeset
524 NULL, NULL);
kono
parents: 67
diff changeset
525 gsi_insert_before (&gsi, cond, GSI_NEW_STMT);
kono
parents: 67
diff changeset
526
kono
parents: 67
diff changeset
527 gsi = gsi_start_bb (update_bb);
kono
parents: 67
diff changeset
528
kono
parents: 67
diff changeset
529 /* Emit: counters[0] = ++__gcov_time_profiler_counter. */
kono
parents: 67
diff changeset
530 if (flag_profile_update == PROFILE_UPDATE_ATOMIC)
kono
parents: 67
diff changeset
531 {
kono
parents: 67
diff changeset
532 tree ptr = make_temp_ssa_name (build_pointer_type (type), NULL,
kono
parents: 67
diff changeset
533 "time_profiler_counter_ptr");
kono
parents: 67
diff changeset
534 tree addr = build1 (ADDR_EXPR, TREE_TYPE (ptr),
kono
parents: 67
diff changeset
535 tree_time_profiler_counter);
kono
parents: 67
diff changeset
536 gassign *assign = gimple_build_assign (ptr, NOP_EXPR, addr);
kono
parents: 67
diff changeset
537 gsi_insert_before (&gsi, assign, GSI_NEW_STMT);
kono
parents: 67
diff changeset
538 tree f = builtin_decl_explicit (LONG_LONG_TYPE_SIZE > 32
kono
parents: 67
diff changeset
539 ? BUILT_IN_ATOMIC_ADD_FETCH_8:
kono
parents: 67
diff changeset
540 BUILT_IN_ATOMIC_ADD_FETCH_4);
kono
parents: 67
diff changeset
541 gcall *stmt = gimple_build_call (f, 3, ptr, one,
kono
parents: 67
diff changeset
542 build_int_cst (integer_type_node,
kono
parents: 67
diff changeset
543 MEMMODEL_RELAXED));
kono
parents: 67
diff changeset
544 tree result_type = TREE_TYPE (TREE_TYPE (f));
kono
parents: 67
diff changeset
545 tree tmp = make_temp_ssa_name (result_type, NULL, "time_profile");
kono
parents: 67
diff changeset
546 gimple_set_lhs (stmt, tmp);
kono
parents: 67
diff changeset
547 gsi_insert_after (&gsi, stmt, GSI_NEW_STMT);
kono
parents: 67
diff changeset
548 tmp = make_temp_ssa_name (type, NULL, "time_profile");
kono
parents: 67
diff changeset
549 assign = gimple_build_assign (tmp, NOP_EXPR,
kono
parents: 67
diff changeset
550 gimple_call_lhs (stmt));
kono
parents: 67
diff changeset
551 gsi_insert_after (&gsi, assign, GSI_NEW_STMT);
kono
parents: 67
diff changeset
552 assign = gimple_build_assign (original_ref, tmp);
kono
parents: 67
diff changeset
553 gsi_insert_after (&gsi, assign, GSI_NEW_STMT);
kono
parents: 67
diff changeset
554 }
kono
parents: 67
diff changeset
555 else
kono
parents: 67
diff changeset
556 {
kono
parents: 67
diff changeset
557 tree tmp = make_temp_ssa_name (type, NULL, "time_profile");
kono
parents: 67
diff changeset
558 gassign *assign = gimple_build_assign (tmp, tree_time_profiler_counter);
kono
parents: 67
diff changeset
559 gsi_insert_before (&gsi, assign, GSI_NEW_STMT);
kono
parents: 67
diff changeset
560
kono
parents: 67
diff changeset
561 tmp = make_temp_ssa_name (type, NULL, "time_profile");
kono
parents: 67
diff changeset
562 assign = gimple_build_assign (tmp, PLUS_EXPR, gimple_assign_lhs (assign),
kono
parents: 67
diff changeset
563 one);
kono
parents: 67
diff changeset
564 gsi_insert_after (&gsi, assign, GSI_NEW_STMT);
kono
parents: 67
diff changeset
565 assign = gimple_build_assign (original_ref, tmp);
kono
parents: 67
diff changeset
566 gsi_insert_after (&gsi, assign, GSI_NEW_STMT);
kono
parents: 67
diff changeset
567 assign = gimple_build_assign (tree_time_profiler_counter, tmp);
kono
parents: 67
diff changeset
568 gsi_insert_after (&gsi, assign, GSI_NEW_STMT);
kono
parents: 67
diff changeset
569 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
570 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
571
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
572 /* Output instructions as GIMPLE trees to increment the average histogram
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
573 counter. VALUE is the expression whose value is profiled. TAG is the
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
574 tag of the section for counters, BASE is offset of the counter position. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
575
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
576 void
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
577 gimple_gen_average_profiler (histogram_value value, unsigned tag, unsigned base)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
578 {
111
kono
parents: 67
diff changeset
579 gimple *stmt = value->hvalue.stmt;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
580 gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
581 tree ref_ptr = tree_coverage_counter_addr (tag, base);
111
kono
parents: 67
diff changeset
582 gcall *call;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
583 tree val;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
584
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
585 ref_ptr = force_gimple_operand_gsi (&gsi, ref_ptr,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
586 true, NULL_TREE,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
587 true, GSI_SAME_STMT);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
588 val = prepare_instrumented_value (&gsi, value);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
589 call = gimple_build_call (tree_average_profiler_fn, 2, ref_ptr, val);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
590 gsi_insert_before (&gsi, call, GSI_NEW_STMT);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
591 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
592
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
593 /* Output instructions as GIMPLE trees to increment the ior histogram
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
594 counter. VALUE is the expression whose value is profiled. TAG is the
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
595 tag of the section for counters, BASE is offset of the counter position. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
596
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
597 void
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
598 gimple_gen_ior_profiler (histogram_value value, unsigned tag, unsigned base)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
599 {
111
kono
parents: 67
diff changeset
600 gimple *stmt = value->hvalue.stmt;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
601 gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
602 tree ref_ptr = tree_coverage_counter_addr (tag, base);
111
kono
parents: 67
diff changeset
603 gcall *call;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
604 tree val;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
605
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
606 ref_ptr = force_gimple_operand_gsi (&gsi, ref_ptr,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
607 true, NULL_TREE, true, GSI_SAME_STMT);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
608 val = prepare_instrumented_value (&gsi, value);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
609 call = gimple_build_call (tree_ior_profiler_fn, 2, ref_ptr, val);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
610 gsi_insert_before (&gsi, call, GSI_NEW_STMT);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
611 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
612
111
kono
parents: 67
diff changeset
613 #ifndef HAVE_sync_compare_and_swapsi
kono
parents: 67
diff changeset
614 #define HAVE_sync_compare_and_swapsi 0
kono
parents: 67
diff changeset
615 #endif
kono
parents: 67
diff changeset
616 #ifndef HAVE_atomic_compare_and_swapsi
kono
parents: 67
diff changeset
617 #define HAVE_atomic_compare_and_swapsi 0
kono
parents: 67
diff changeset
618 #endif
kono
parents: 67
diff changeset
619
kono
parents: 67
diff changeset
620 #ifndef HAVE_sync_compare_and_swapdi
kono
parents: 67
diff changeset
621 #define HAVE_sync_compare_and_swapdi 0
kono
parents: 67
diff changeset
622 #endif
kono
parents: 67
diff changeset
623 #ifndef HAVE_atomic_compare_and_swapdi
kono
parents: 67
diff changeset
624 #define HAVE_atomic_compare_and_swapdi 0
kono
parents: 67
diff changeset
625 #endif
kono
parents: 67
diff changeset
626
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
627 /* Profile all functions in the callgraph. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
628
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
629 static unsigned int
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
630 tree_profiling (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
631 {
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
632 struct cgraph_node *node;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
633
111
kono
parents: 67
diff changeset
634 /* Verify whether we can utilize atomic update operations. */
kono
parents: 67
diff changeset
635 bool can_support_atomic = false;
kono
parents: 67
diff changeset
636 unsigned HOST_WIDE_INT gcov_type_size
kono
parents: 67
diff changeset
637 = tree_to_uhwi (TYPE_SIZE_UNIT (get_gcov_type ()));
kono
parents: 67
diff changeset
638 if (gcov_type_size == 4)
kono
parents: 67
diff changeset
639 can_support_atomic
kono
parents: 67
diff changeset
640 = HAVE_sync_compare_and_swapsi || HAVE_atomic_compare_and_swapsi;
kono
parents: 67
diff changeset
641 else if (gcov_type_size == 8)
kono
parents: 67
diff changeset
642 can_support_atomic
kono
parents: 67
diff changeset
643 = HAVE_sync_compare_and_swapdi || HAVE_atomic_compare_and_swapdi;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
644
111
kono
parents: 67
diff changeset
645 if (flag_profile_update == PROFILE_UPDATE_ATOMIC
kono
parents: 67
diff changeset
646 && !can_support_atomic)
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
647 {
111
kono
parents: 67
diff changeset
648 warning (0, "target does not support atomic profile update, "
kono
parents: 67
diff changeset
649 "single mode is selected");
kono
parents: 67
diff changeset
650 flag_profile_update = PROFILE_UPDATE_SINGLE;
kono
parents: 67
diff changeset
651 }
kono
parents: 67
diff changeset
652 else if (flag_profile_update == PROFILE_UPDATE_PREFER_ATOMIC)
kono
parents: 67
diff changeset
653 flag_profile_update = can_support_atomic
kono
parents: 67
diff changeset
654 ? PROFILE_UPDATE_ATOMIC : PROFILE_UPDATE_SINGLE;
kono
parents: 67
diff changeset
655
kono
parents: 67
diff changeset
656 /* This is a small-ipa pass that gets called only once, from
kono
parents: 67
diff changeset
657 cgraphunit.c:ipa_passes(). */
kono
parents: 67
diff changeset
658 gcc_assert (symtab->state == IPA_SSA);
kono
parents: 67
diff changeset
659
kono
parents: 67
diff changeset
660 init_node_map (true);
kono
parents: 67
diff changeset
661
kono
parents: 67
diff changeset
662 FOR_EACH_DEFINED_FUNCTION (node)
kono
parents: 67
diff changeset
663 {
kono
parents: 67
diff changeset
664 if (!gimple_has_body_p (node->decl))
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
665 continue;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
666
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
667 /* Don't profile functions produced for builtin stuff. */
111
kono
parents: 67
diff changeset
668 if (DECL_SOURCE_LOCATION (node->decl) == BUILTINS_LOCATION)
kono
parents: 67
diff changeset
669 continue;
kono
parents: 67
diff changeset
670
kono
parents: 67
diff changeset
671 if (lookup_attribute ("no_profile_instrument_function",
kono
parents: 67
diff changeset
672 DECL_ATTRIBUTES (node->decl)))
kono
parents: 67
diff changeset
673 continue;
kono
parents: 67
diff changeset
674 /* Do not instrument extern inline functions when testing coverage.
kono
parents: 67
diff changeset
675 While this is not perfectly consistent (early inlined extern inlines
kono
parents: 67
diff changeset
676 will get acocunted), testsuite expects that. */
kono
parents: 67
diff changeset
677 if (DECL_EXTERNAL (node->decl)
kono
parents: 67
diff changeset
678 && flag_test_coverage)
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
679 continue;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
680
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
681 push_cfun (DECL_STRUCT_FUNCTION (node->decl));
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
682
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
683 if (dump_file)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
684 dump_function_header (dump_file, cfun->decl, dump_flags);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
685
111
kono
parents: 67
diff changeset
686 /* Local pure-const may imply need to fixup the cfg. */
kono
parents: 67
diff changeset
687 if (execute_fixup_cfg () & TODO_cleanup_cfg)
kono
parents: 67
diff changeset
688 cleanup_tree_cfg ();
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
689
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
690 branch_prob ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
691
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
692 if (! flag_branch_probabilities
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
693 && flag_profile_values)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
694 gimple_gen_ic_func_profiler ();
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
695
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
696 if (flag_branch_probabilities
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
697 && flag_profile_values
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
698 && flag_value_profile_transformations)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
699 gimple_value_profile_transformations ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
700
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
701 /* The above could hose dominator info. Currently there is
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
702 none coming in, this is a safety valve. It should be
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
703 easy to adjust it, if and when there is some. */
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
704 free_dominance_info (CDI_DOMINATORS);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
705 free_dominance_info (CDI_POST_DOMINATORS);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
706 pop_cfun ();
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
707 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
708
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
709 /* Drop pure/const flags from instrumented functions. */
111
kono
parents: 67
diff changeset
710 if (profile_arc_flag || flag_test_coverage)
kono
parents: 67
diff changeset
711 FOR_EACH_DEFINED_FUNCTION (node)
kono
parents: 67
diff changeset
712 {
kono
parents: 67
diff changeset
713 if (!gimple_has_body_p (node->decl)
kono
parents: 67
diff changeset
714 || !(!node->clone_of
kono
parents: 67
diff changeset
715 || node->decl != node->clone_of->decl))
kono
parents: 67
diff changeset
716 continue;
kono
parents: 67
diff changeset
717
kono
parents: 67
diff changeset
718 /* Don't profile functions produced for builtin stuff. */
kono
parents: 67
diff changeset
719 if (DECL_SOURCE_LOCATION (node->decl) == BUILTINS_LOCATION)
kono
parents: 67
diff changeset
720 continue;
kono
parents: 67
diff changeset
721
kono
parents: 67
diff changeset
722 node->set_const_flag (false, false);
kono
parents: 67
diff changeset
723 node->set_pure_flag (false, false);
kono
parents: 67
diff changeset
724 }
kono
parents: 67
diff changeset
725
kono
parents: 67
diff changeset
726 /* Update call statements and rebuild the cgraph. */
kono
parents: 67
diff changeset
727 FOR_EACH_DEFINED_FUNCTION (node)
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
728 {
111
kono
parents: 67
diff changeset
729 basic_block bb;
kono
parents: 67
diff changeset
730
kono
parents: 67
diff changeset
731 if (!gimple_has_body_p (node->decl)
kono
parents: 67
diff changeset
732 || !(!node->clone_of
kono
parents: 67
diff changeset
733 || node->decl != node->clone_of->decl))
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
734 continue;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
735
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
736 /* Don't profile functions produced for builtin stuff. */
111
kono
parents: 67
diff changeset
737 if (DECL_SOURCE_LOCATION (node->decl) == BUILTINS_LOCATION)
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
738 continue;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
739
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
740 push_cfun (DECL_STRUCT_FUNCTION (node->decl));
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
741
111
kono
parents: 67
diff changeset
742 FOR_EACH_BB_FN (bb, cfun)
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
743 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
744 gimple_stmt_iterator gsi;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
745 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
746 {
111
kono
parents: 67
diff changeset
747 gimple *stmt = gsi_stmt (gsi);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
748 if (is_gimple_call (stmt))
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
749 update_stmt (stmt);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
750 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
751 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
752
111
kono
parents: 67
diff changeset
753 /* re-merge split blocks. */
kono
parents: 67
diff changeset
754 cleanup_tree_cfg ();
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
755 update_ssa (TODO_update_ssa);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
756
111
kono
parents: 67
diff changeset
757 cgraph_edge::rebuild_edges ();
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
758
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
759 pop_cfun ();
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
760 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
761
111
kono
parents: 67
diff changeset
762 handle_missing_profiles ();
kono
parents: 67
diff changeset
763
kono
parents: 67
diff changeset
764 del_node_map ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
765 return 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
766 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
767
111
kono
parents: 67
diff changeset
768 namespace {
kono
parents: 67
diff changeset
769
kono
parents: 67
diff changeset
770 const pass_data pass_data_ipa_tree_profile =
kono
parents: 67
diff changeset
771 {
kono
parents: 67
diff changeset
772 SIMPLE_IPA_PASS, /* type */
kono
parents: 67
diff changeset
773 "profile", /* name */
kono
parents: 67
diff changeset
774 OPTGROUP_NONE, /* optinfo_flags */
kono
parents: 67
diff changeset
775 TV_IPA_PROFILE, /* tv_id */
kono
parents: 67
diff changeset
776 0, /* properties_required */
kono
parents: 67
diff changeset
777 0, /* properties_provided */
kono
parents: 67
diff changeset
778 0, /* properties_destroyed */
kono
parents: 67
diff changeset
779 0, /* todo_flags_start */
kono
parents: 67
diff changeset
780 TODO_dump_symtab, /* todo_flags_finish */
kono
parents: 67
diff changeset
781 };
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
782
111
kono
parents: 67
diff changeset
783 class pass_ipa_tree_profile : public simple_ipa_opt_pass
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
784 {
111
kono
parents: 67
diff changeset
785 public:
kono
parents: 67
diff changeset
786 pass_ipa_tree_profile (gcc::context *ctxt)
kono
parents: 67
diff changeset
787 : simple_ipa_opt_pass (pass_data_ipa_tree_profile, ctxt)
kono
parents: 67
diff changeset
788 {}
kono
parents: 67
diff changeset
789
kono
parents: 67
diff changeset
790 /* opt_pass methods: */
kono
parents: 67
diff changeset
791 virtual bool gate (function *);
kono
parents: 67
diff changeset
792 virtual unsigned int execute (function *) { return tree_profiling (); }
kono
parents: 67
diff changeset
793
kono
parents: 67
diff changeset
794 }; // class pass_ipa_tree_profile
kono
parents: 67
diff changeset
795
kono
parents: 67
diff changeset
796 bool
kono
parents: 67
diff changeset
797 pass_ipa_tree_profile::gate (function *)
kono
parents: 67
diff changeset
798 {
kono
parents: 67
diff changeset
799 /* When profile instrumentation, use or test coverage shall be performed.
kono
parents: 67
diff changeset
800 But for AutoFDO, this there is no instrumentation, thus this pass is
kono
parents: 67
diff changeset
801 diabled. */
kono
parents: 67
diff changeset
802 return (!in_lto_p && !flag_auto_profile
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
803 && (flag_branch_probabilities || flag_test_coverage
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
804 || profile_arc_flag));
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
805 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
806
111
kono
parents: 67
diff changeset
807 } // anon namespace
kono
parents: 67
diff changeset
808
kono
parents: 67
diff changeset
809 simple_ipa_opt_pass *
kono
parents: 67
diff changeset
810 make_pass_ipa_tree_profile (gcc::context *ctxt)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
811 {
111
kono
parents: 67
diff changeset
812 return new pass_ipa_tree_profile (ctxt);
kono
parents: 67
diff changeset
813 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
814
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
815 #include "gt-tree-profile.h"