2 * Copyright (C) 1995-2007 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.
52 * An abstract data type containing information for
55 * This opaque data type is not defined anywhere in the Firm library,
56 * but pointers to this type can be stored in Firm nodes.
58 typedef struct dbg_info dbg_info;
61 * Sets the debug information of a node.
64 * @param db The debug info.
66 void set_irn_dbg_info(ir_node *n, dbg_info *db);
69 * Returns the debug information of an node.
73 dbg_info *get_irn_dbg_info(const ir_node *n);
76 * Sets the debug information of an entity.
78 * @param ent The entity.
79 * @param db The debug info.
81 void set_entity_dbg_info(ir_entity *ent, dbg_info *db);
84 * Returns the debug information of an entity.
86 * @param ent The entity.
88 dbg_info *get_entity_dbg_info(const ir_entity *ent);
91 * Sets the debug information of a type.
94 * @param db The debug info.
96 void set_type_dbg_info(ir_type *tp, dbg_info *db);
99 * Returns the debug information of a type.
101 * @param tp The type.
103 dbg_info *get_type_dbg_info(const ir_type *tp);
106 * An enumeration indicating the action performed by a transformation.
110 dbg_opt_ssa, /**< Optimization of the SSA representation, e.g. removal of superfluent Phi nodes. */
111 dbg_opt_auxnode, /**< Removal of unnecessary auxiliary nodes. */
112 dbg_const_eval, /**< A Firm subgraph was evaluated to a single constant. */
113 dbg_opt_cse, /**< A Firm node was replaced due to common subexpression elimination. */
114 dbg_straightening, /**< A Firm subgraph was replaced by a single, existing block. */
115 dbg_if_simplification, /**< The control flow of an if is changed as either the
116 else, the then or both blocks are empty. */
117 dbg_algebraic_simplification, /**< A Firm subgraph was replaced because of an algebraic
119 dbg_write_after_write, /**< A Firm subgraph was replaced because of a write
120 after write optimization. */
121 dbg_write_after_read, /**< A Firm subgraph was replaced because of a write
122 after read optimization. */
123 dbg_read_after_write, /**< A Firm subgraph was replaced because of a read
124 after write optimization. */
125 dbg_read_after_read, /**< A Firm subgraph was replaced because of a read
126 after read optimization. */
127 dbg_read_a_const, /**< A Firm subgraph was replaced because of a read
128 a constant optimization. */
129 dbg_rem_poly_call, /**< Remove polymorphic call. */
130 dbg_dead_code, /**< Removing unreachable code, I.e. blocks that are never executed. */
131 dbg_opt_confirm, /**< A Firm subgraph was replace because of a Confirmation. */
132 dbg_backend, /**< A Firm subgraph was replaced because of a Backend transformation */
133 dbg_max /**< Maximum value. */
137 * Converts a debug_action into a string.
139 * @param a the debug action
141 const char *dbg_action_2_str(dbg_action a);
144 * The type of the debug info merge function.
146 * @param new_node the new ir node
147 * @param old_node the old ir node
148 * @param action the action that triggers the merge
152 typedef void merge_pair_func(ir_node *new_node, ir_node *old_node, dbg_action action);
155 * The type of the debug info merge sets function.
157 * @param new_node_array array of new nodes
158 * @param new_num_entries number of entries in new_node_array
159 * @param old_node_array array of old nodes
160 * @param old_num_entries number of entries in old_node_array
161 * @param action the action that triggers the merge
165 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);
168 * The type of the debug info to human readable string function.
170 * @param buf pointer to a buffer that will hold the info
171 * @param len length of the buffer
172 * @param dbg the debug info
174 * @return Number of written characters to the buffer.
178 typedef unsigned snprint_dbg_func(char *buf, unsigned len, const dbg_info *dbg);
181 * Initializes the debug support.
183 * @param dbg_info_merge_pair see function description
184 * @param dbg_info_merge_sets see function description
185 * @param snprint_dbg see function description
187 * This function takes pointers to two functions that merge the
188 * debug information when a
189 * transformation of a Firm graph is performed.
190 * Firm transformations call one of these functions.
192 * - dbg_info_merge_pair() is called in the following situation:
193 * The optimization replaced the old node by the new one. The new node
194 * might be a recent allocated node not containing any debug information,
195 * or just another node from somewhere in the graph with the same
197 * - dbg_info_merge_sets() is called in the following situation:
198 * The optimization replaced a subgraph by another subgraph. There is no
199 * obviously mapping between single nodes in both subgraphs. The optimization
200 * simply passes two lists to the debug module, one containing the nodes in
201 * the old subgraph, the other containing the nodes in the new subgraph.
202 * The same node can be in both lists.
204 * Further both functions pass an enumeration indicating the action
205 * performed by the transformation, e.g. the kind of optimization performed.
207 * The third argument snprint_dbg is called to convert a debug info into a human readable string.
208 * This string is the dumped in the dumper functions.
210 * Note that if NULL is passed for dbg_info_merge_pair or dbg_info_merge_sets, the default
211 * implementations default_dbg_info_merge_pair() and default_dbg_info_merge_sets() are used.
212 * NULL passed for snprint_dbg means no output.
214 void dbg_init(merge_pair_func *dbg_info_merge_pair, merge_sets_func *dbg_info_merge_sets, snprint_dbg_func *snprint_dbg);
217 * The default merge_pair_func implementation, simply copies the debug info
218 * from the old Firm node to the new one if the new one does not have debug info yet.
220 * @param nw The new Firm node.
221 * @param old The old Firm node.
222 * @param info The action that cause old node to be replaced by new one.
224 void default_dbg_info_merge_pair(ir_node *nw, ir_node *old, dbg_action info);
227 * The default merge_sets_func implementation. If n_old_nodes is equal 1, copies
228 * the debug info from the old node to all new ones (if they do not have one), else does nothing.
230 * @param new_nodes An array of new Firm nodes.
231 * @param n_new_nodes The length of the new_nodes array.
232 * @param old_nodes An array of old (replaced) Firm nodes.
233 * @param n_old_nodes The length of the old_nodes array.
234 * @param info The action that cause old node to be replaced by new one.
236 void default_dbg_info_merge_sets(ir_node **new_nodes, int n_new_nodes,
237 ir_node **old_nodes, int n_old_nodes,