2 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * @brief Implements the Firm interface to debug information.
23 * @author Goetz Lindenmaier, Michael Beck
27 * Firm requires a debugging module fulfilling this interface, else no
28 * debugging information is passed to the backend.
29 * The interface requires a datatype representing the debugging
30 * information. Firm supports administrating a reference to the debug
31 * information in every Firm node. Further Firm optimizations call
32 * routines to propagate debug information from old nodes to new nodes
33 * if the optimization replaces the old ones by the new ones.
35 #ifndef FIRM_DEBUG_DBGINFO_H
36 #define FIRM_DEBUG_DBGINFO_H
38 #include "firm_types.h"
46 * @defgroup debug The Firm interface to debugging support.
54 * An abstract data type containing information for
57 * This opaque data type is not defined anywhere in the Firm library,
58 * but pointers to this type can be stored in Firm nodes.
62 * An enumeration indicating the action performed by a transformation.
66 dbg_opt_ssa, /**< Optimization of the SSA representation, e.g. removal of superfluent Phi nodes. */
67 dbg_opt_auxnode, /**< Removal of unnecessary auxiliary nodes. */
68 dbg_const_eval, /**< A Firm subgraph was evaluated to a single constant. */
69 dbg_opt_cse, /**< A Firm node was replaced due to common subexpression elimination. */
70 dbg_straightening, /**< A Firm subgraph was replaced by a single, existing block. */
71 dbg_if_simplification, /**< The control flow of an if is changed as either the
72 else, the then or both blocks are empty. */
73 dbg_algebraic_simplification, /**< A Firm subgraph was replaced because of an algebraic
75 dbg_write_after_write, /**< A Firm subgraph was replaced because of a write
76 after write optimization. */
77 dbg_write_after_read, /**< A Firm subgraph was replaced because of a write
78 after read optimization. */
79 dbg_read_after_write, /**< A Firm subgraph was replaced because of a read
80 after write optimization. */
81 dbg_read_after_read, /**< A Firm subgraph was replaced because of a read
82 after read optimization. */
83 dbg_read_a_const, /**< A Firm subgraph was replaced because of a read
84 a constant optimization. */
85 dbg_rem_poly_call, /**< Remove polymorphic call. */
86 dbg_dead_code, /**< Removing unreachable code, I.e. blocks that are never executed. */
87 dbg_opt_confirm, /**< A Firm subgraph was replace because of a Confirmation. */
88 dbg_gvn_pre, /**< A Firm node was replace because of the GVN-PRE algorithm. */
89 dbg_combo, /**< A Firm node was replace because of the combo algorithm. */
90 dbg_jumpthreading, /**< A Firm node was replace because of the jumpthreading algorithm. */
91 dbg_backend, /**< A Firm subgraph was replaced because of a Backend transformation */
92 dbg_max /**< Maximum value. */
96 * Converts a debug_action into a string.
98 * @param a the debug action
100 const char *dbg_action_2_str(dbg_action a);
103 * The type of the debug info merge function.
105 * @param new_node the new ir node
106 * @param old_node the old ir node
107 * @param action the action that triggers the merge
111 typedef void merge_pair_func(ir_node *new_node, ir_node *old_node, dbg_action action);
114 * The type of the debug info merge sets function.
116 * @param new_node_array array of new nodes
117 * @param new_num_entries number of entries in new_node_array
118 * @param old_node_array array of old nodes
119 * @param old_num_entries number of entries in old_node_array
120 * @param action the action that triggers the merge
124 typedef void merge_sets_func(ir_node **new_node_array, int new_num_entries, ir_node **old_node_array, int old_num_entries, dbg_action action);
127 * The type of the debug info to human readable string function.
129 * @param buf pointer to a buffer that will hold the info
130 * @param len length of the buffer
131 * @param dbg the debug info
133 * @return Number of written characters to the buffer.
137 typedef unsigned snprint_dbg_func(char *buf, unsigned len, const dbg_info *dbg);
140 * Initializes the debug support.
142 * @param dbg_info_merge_pair see function description
143 * @param dbg_info_merge_sets see function description
144 * @param snprint_dbg see function description
146 * This function takes pointers to two functions that merge the
147 * debug information when a
148 * transformation of a Firm graph is performed.
149 * Firm transformations call one of these functions.
151 * - dbg_info_merge_pair() is called in the following situation:
152 * The optimization replaced the old node by the new one. The new node
153 * might be a recent allocated node not containing any debug information,
154 * or just another node from somewhere in the graph with the same
156 * - dbg_info_merge_sets() is called in the following situation:
157 * The optimization replaced a subgraph by another subgraph. There is no
158 * obviously mapping between single nodes in both subgraphs. The optimization
159 * simply passes two lists to the debug module, one containing the nodes in
160 * the old subgraph, the other containing the nodes in the new subgraph.
161 * The same node can be in both lists.
163 * Further both functions pass an enumeration indicating the action
164 * performed by the transformation, e.g. the kind of optimization performed.
166 * The third argument snprint_dbg is called to convert a debug info into a human readable string.
167 * This string is the dumped in the dumper functions.
169 * Note that if NULL is passed for dbg_info_merge_pair or dbg_info_merge_sets, the default
170 * implementations default_dbg_info_merge_pair() and default_dbg_info_merge_sets() are used.
171 * NULL passed for snprint_dbg means no output.
173 void dbg_init(merge_pair_func *dbg_info_merge_pair, merge_sets_func *dbg_info_merge_sets, snprint_dbg_func *snprint_dbg);
176 * The default merge_pair_func implementation, simply copies the debug info
177 * from the old Firm node to the new one if the new one does not have debug info yet.
179 * @param nw The new Firm node.
180 * @param old The old Firm node.
181 * @param info The action that cause old node to be replaced by new one.
183 void default_dbg_info_merge_pair(ir_node *nw, ir_node *old, dbg_action info);
186 * The default merge_sets_func implementation. If n_old_nodes is equal 1, copies
187 * the debug info from the old node to all new ones (if they do not have one), else does nothing.
189 * @param new_nodes An array of new Firm nodes.
190 * @param n_new_nodes The length of the new_nodes array.
191 * @param old_nodes An array of old (replaced) Firm nodes.
192 * @param n_old_nodes The length of the old_nodes array.
193 * @param info The action that cause old node to be replaced by new one.
195 void default_dbg_info_merge_sets(ir_node **new_nodes, int n_new_nodes,
196 ir_node **old_nodes, int n_old_nodes,
201 /** The type of the debug info retriever function. */
202 typedef const char *(*retrieve_dbg_func)(const dbg_info *dbg, unsigned *line);
205 * Sets a debug info retriever.
207 * @param func the debug retriever function.
209 void ir_set_debug_retrieve(retrieve_dbg_func func);
212 * Retrieve the debug info.
214 const char *ir_retrieve_dbg_info(const dbg_info *dbg, unsigned *line);