There are many examples of ``Statistic`` uses, but the basics of using it are as
follows:
-#. Define your statistic like this:
+Define your statistic like this:
- .. code-block:: c++
+.. code-block:: c++
- #define DEBUG_TYPE "mypassname" // This goes before any #includes.
- STATISTIC(NumXForms, "The # of times I did stuff");
+ #define DEBUG_TYPE "mypassname" // This goes before any #includes.
+ STATISTIC(NumXForms, "The # of times I did stuff");
- The ``STATISTIC`` macro defines a static variable, whose name is specified by
- the first argument. The pass name is taken from the ``DEBUG_TYPE`` macro, and
- the description is taken from the second argument. The variable defined
- ("NumXForms" in this case) acts like an unsigned integer.
+The ``STATISTIC`` macro defines a static variable, whose name is specified by
+the first argument. The pass name is taken from the ``DEBUG_TYPE`` macro, and
+the description is taken from the second argument. The variable defined
+("NumXForms" in this case) acts like an unsigned integer.
-#. Whenever you make a transformation, bump the counter:
+Whenever you make a transformation, bump the counter:
- .. code-block:: c++
+.. code-block:: c++
- ++NumXForms; // I did stuff!
+ ++NumXForms; // I did stuff!
That's all you have to do. To get '``opt``' to print out the statistics
gathered, use the '``-stats``' option:
happen or not. For example, there are times the minimization tooling
can only easily give you large testcases. You would like to narrow
your bug down to a specific transformation happening or not happening,
-automatically. This is where debug counters help. They provide a framework
-for making parts of your code only execute a certain number of times.
+automatically, using bisection. This is where debug counters help.
+They provide a framework for making parts of your code only execute a
+certain number of times.
The ``llvm/Support/DebugCounter.h`` (`doxygen
<http://llvm.org/doxygen/DebugCounter_8h_source.html>`__) file
Define your DebugCounter like this:
- .. code-block:: c++
+.. code-block:: c++
- DEBUG_COUNTER(DeleteAnInstruction, "passname-delete-instruction",
- "Controls which instructions get delete").
+ DEBUG_COUNTER(DeleteAnInstruction, "passname-delete-instruction",
+ "Controls which instructions get delete").
- The ``DEBUG_COUNTER`` macro defines a static variable, whose name
- is specified by the first argument. The name of the counter
- (which is used on the command line) is specified by the second
- argument, and the description used in the help is specified by the
- third argument.
+The ``DEBUG_COUNTER`` macro defines a static variable, whose name
+is specified by the first argument. The name of the counter
+(which is used on the command line) is specified by the second
+argument, and the description used in the help is specified by the
+third argument.
Whatever code you want that control, use ``DebugCounter::shouldExecute`` to control it.
- .. code-block:: c++
+.. code-block:: c++
- if (DebugCounter::shouldExecute(DeleteAnInstruction))
- I->eraseFromParent();
+ if (DebugCounter::shouldExecute(DeleteAnInstruction))
+ I->eraseFromParent();
That's all you have to do. Now, using opt, you can control when this code triggers using
the '``--debug-counter``' option. There are two counters provided, ``skip`` and ``count``.
It would delete number ``%2`` and ``%3``.
-A utility is provided in `utils/bisect-skip-count` to binary search skip and count arguments. It can be used to automatically minimize
-the skip and count for a debug-counter variable.
+A utility is provided in `utils/bisect-skip-count` to binary search
+skip and count arguments. It can be used to automatically minimize the
+skip and count for a debug-counter variable.
.. _ViewGraph: