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