dbgcnt.def revision 1.5.4.1 1 1.1 mrg /* This file contains the list of the debug counter for GCC.
2 1.5.4.1 christos Copyright (C) 2006-2016 Free Software Foundation, Inc.
3 1.1 mrg
4 1.1 mrg This file is part of GCC.
5 1.1 mrg
6 1.1 mrg GCC is free software; you can redistribute it and/or modify it under
7 1.1 mrg the terms of the GNU General Public License as published by the Free
8 1.1 mrg Software Foundation; either version 3, or (at your option) any later
9 1.1 mrg version.
10 1.1 mrg
11 1.1 mrg GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 1.1 mrg WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 1.1 mrg FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 1.1 mrg for more details.
15 1.1 mrg
16 1.1 mrg You should have received a copy of the GNU General Public License
17 1.1 mrg along with GCC; see the file COPYING3. If not see
18 1.1 mrg <http://www.gnu.org/licenses/>. */
19 1.1 mrg
20 1.1 mrg
21 1.1 mrg /* A debug counter provides you a way to count an event
22 1.1 mrg and return false after the counter has exceeded the threshold
23 1.1 mrg specified by the option.
24 1.1 mrg
25 1.1 mrg What is it used for ?
26 1.1 mrg
27 1.1 mrg This is primarily used to speed up the search for the bad transformation
28 1.1 mrg an optimization pass does. By doing a binary search on N,
29 1.1 mrg you can quickly narrow down to one transformation
30 1.1 mrg which is bad, or which triggers the bad behavior downstream
31 1.1 mrg (usually in the form of the badly generated code).
32 1.1 mrg
33 1.1 mrg How does it work ?
34 1.1 mrg
35 1.1 mrg Every time dbg_cnt(named-counter) is called,
36 1.1 mrg the counter is incremented for the named-counter.
37 1.1 mrg And the incremented value is compared against the threshold (limit)
38 1.1 mrg specified by the option.
39 1.1 mrg dbg_cnt () returns true if it is at or below threshold, and false if above.
40 1.1 mrg
41 1.1 mrg How to add a new one ?
42 1.1 mrg
43 1.1 mrg To add a new counter, simply add an entry below with some descriptive name,
44 1.1 mrg and add call(s) to dbg_cnt(your-counter-name) in appropriate places.
45 1.1 mrg Usually, you want to control at the finest granularity
46 1.1 mrg any particular transformation can happen.
47 1.1 mrg e.g. for each instruction in a dead code elimination,
48 1.1 mrg or for each copy instruction in register coalescing,
49 1.1 mrg or constant-propagation for each insn,
50 1.1 mrg or a block straightening, etc.
51 1.1 mrg See dce.c for an example. With the dbg_cnt () call in dce.c,
52 1.1 mrg now a developer can use -fdbg-cnt=dce:N
53 1.1 mrg to stop doing the dead code elimination after N times.
54 1.1 mrg
55 1.1 mrg How to use it ?
56 1.1 mrg
57 1.1 mrg By default, all limits are UINT_MAX.
58 1.1 mrg Since debug count is unsigned int, <= UINT_MAX returns true always.
59 1.1 mrg i.e. dbg_cnt() returns true always regardless of the counter value
60 1.1 mrg (although it still counts the event).
61 1.1 mrg Use -fdbg-cnt=counter1:N,counter2:M,...
62 1.1 mrg which sets the limit for counter1 to N, and the limit for counter2 to M, etc.
63 1.1 mrg e.g. setting a limit to zero will make dbg_cnt () return false *always*.
64 1.1 mrg
65 1.1 mrg The following shell file can then be used to binary search for
66 1.1 mrg exact transformation that causes the bug. A second shell script
67 1.1 mrg should be written, say "tryTest", which exits with 1 if the
68 1.1 mrg compiled program fails and exits with 0 if the program succeeds.
69 1.1 mrg This shell script should take 1 parameter, the value to be passed
70 1.1 mrg to set the counter of the compilation command in tryTest. Then,
71 1.1 mrg assuming that the following script is called binarySearch,
72 1.1 mrg the command:
73 1.1 mrg
74 1.1 mrg binarySearch tryTest
75 1.1 mrg
76 1.1 mrg will automatically find the highest value of the counter for which
77 1.1 mrg the program fails. If tryTest never fails, binarySearch will
78 1.1 mrg produce unpredictable results as it will try to find an upper bound
79 1.1 mrg that does not exist.
80 1.1 mrg
81 1.1 mrg When dbgcnt does hits the limit, it writes a comment in the current
82 1.1 mrg dump_file of the form:
83 1.1 mrg
84 1.1 mrg ***dbgcnt: limit reached for %s.***
85 1.1 mrg
86 1.1 mrg Assuming that the dump file is logging the analysis/transformations
87 1.1 mrg it is making, this pinpoints the exact position in the log file
88 1.1 mrg where the problem transformation is being logged.
89 1.1 mrg
90 1.1 mrg =====================================
91 1.1 mrg #!/bin/bash
92 1.1 mrg
93 1.1 mrg while getopts "l:u:i:" opt
94 1.1 mrg do
95 1.1 mrg case $opt in
96 1.1 mrg l) lb="$OPTARG";;
97 1.1 mrg u) ub="$OPTARG";;
98 1.1 mrg i) init="$OPTARG";;
99 1.1 mrg ?) usage; exit 3;;
100 1.1 mrg esac
101 1.1 mrg done
102 1.1 mrg
103 1.1 mrg shift $(($OPTIND - 1))
104 1.1 mrg echo $@
105 1.1 mrg cmd=${1+"${@}"}
106 1.1 mrg
107 1.1 mrg lb=${lb:=0}
108 1.1 mrg init=${init:=100}
109 1.1 mrg
110 1.1 mrg $cmd $lb
111 1.1 mrg lb_val=$?
112 1.1 mrg if [ -z "$ub" ]; then
113 1.1 mrg # find the upper bound
114 1.1 mrg ub=$(($init + $lb))
115 1.1 mrg true
116 1.1 mrg while [ $? -eq $lb_val ]; do
117 1.1 mrg ub=$(($ub * 10))
118 1.1 mrg #ub=`expr $ub \* 10`
119 1.1 mrg $cmd $ub
120 1.1 mrg done
121 1.1 mrg fi
122 1.1 mrg
123 1.1 mrg echo command: $cmd
124 1.1 mrg
125 1.1 mrg true
126 1.1 mrg while [ `expr $ub - $lb` -gt 1 ]; do
127 1.1 mrg try=$(($lb + ( $ub - $lb ) / 2))
128 1.1 mrg $cmd $try
129 1.1 mrg if [ $? -eq $lb_val ]; then
130 1.1 mrg lb=$try
131 1.1 mrg else
132 1.1 mrg ub=$try
133 1.1 mrg fi
134 1.1 mrg done
135 1.1 mrg
136 1.1 mrg echo lbound: $lb
137 1.1 mrg echo ubound: $ub
138 1.1 mrg
139 1.1 mrg =====================================
140 1.1 mrg
141 1.1 mrg */
142 1.1 mrg
143 1.1 mrg /* Debug counter definitions. */
144 1.1 mrg DEBUG_COUNTER (auto_inc_dec)
145 1.1 mrg DEBUG_COUNTER (ccp)
146 1.1 mrg DEBUG_COUNTER (cfg_cleanup)
147 1.1 mrg DEBUG_COUNTER (cprop)
148 1.5.4.1 christos DEBUG_COUNTER (cse2_move2add)
149 1.1 mrg DEBUG_COUNTER (dce)
150 1.1 mrg DEBUG_COUNTER (dce_fast)
151 1.1 mrg DEBUG_COUNTER (dce_ud)
152 1.1 mrg DEBUG_COUNTER (delete_trivial_dead)
153 1.5 mrg DEBUG_COUNTER (devirt)
154 1.1 mrg DEBUG_COUNTER (df_byte_scan)
155 1.1 mrg DEBUG_COUNTER (dse)
156 1.1 mrg DEBUG_COUNTER (dse1)
157 1.1 mrg DEBUG_COUNTER (dse2)
158 1.5.4.1 christos DEBUG_COUNTER (eipa_sra)
159 1.1 mrg DEBUG_COUNTER (gcse2_delete)
160 1.1 mrg DEBUG_COUNTER (global_alloc_at_func)
161 1.1 mrg DEBUG_COUNTER (global_alloc_at_reg)
162 1.3 mrg DEBUG_COUNTER (graphite_scop)
163 1.1 mrg DEBUG_COUNTER (hoist)
164 1.3 mrg DEBUG_COUNTER (hoist_insn)
165 1.1 mrg DEBUG_COUNTER (ia64_sched2)
166 1.1 mrg DEBUG_COUNTER (if_after_combine)
167 1.1 mrg DEBUG_COUNTER (if_after_reload)
168 1.5.4.1 christos DEBUG_COUNTER (if_conversion)
169 1.5.4.1 christos DEBUG_COUNTER (if_conversion_tree)
170 1.5.4.1 christos DEBUG_COUNTER (ira_move)
171 1.1 mrg DEBUG_COUNTER (local_alloc_for_sched)
172 1.5.4.1 christos DEBUG_COUNTER (merged_ipa_icf)
173 1.1 mrg DEBUG_COUNTER (postreload_cse)
174 1.1 mrg DEBUG_COUNTER (pre)
175 1.1 mrg DEBUG_COUNTER (pre_insn)
176 1.5.4.1 christos DEBUG_COUNTER (registered_jump_thread)
177 1.1 mrg DEBUG_COUNTER (sched2_func)
178 1.1 mrg DEBUG_COUNTER (sched_block)
179 1.5.4.1 christos DEBUG_COUNTER (sched_breakdep)
180 1.1 mrg DEBUG_COUNTER (sched_func)
181 1.1 mrg DEBUG_COUNTER (sched_insn)
182 1.1 mrg DEBUG_COUNTER (sched_region)
183 1.1 mrg DEBUG_COUNTER (sel_sched_cnt)
184 1.1 mrg DEBUG_COUNTER (sel_sched_insn_cnt)
185 1.5.4.1 christos DEBUG_COUNTER (sel_sched_region_cnt)
186 1.1 mrg DEBUG_COUNTER (sms_sched_loop)
187 1.1 mrg DEBUG_COUNTER (split_for_sched2)
188 1.5.4.1 christos DEBUG_COUNTER (store_motion)
189 1.5.4.1 christos DEBUG_COUNTER (stv_conversion)
190 1.1 mrg DEBUG_COUNTER (tail_call)
191 1.5.4.1 christos DEBUG_COUNTER (treepre_insert)
192 1.5.4.1 christos DEBUG_COUNTER (tree_sra)
193 1.5.4.1 christos DEBUG_COUNTER (vect_loop)
194 1.5.4.1 christos DEBUG_COUNTER (vect_slp)
195 1.5.4.1 christos DEBUG_COUNTER (dom_unreachable_edges)
196