dbgcnt.def 5.8 KB

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