Slimified the bitset implementation a little bit
[libfirm] / include / libfirm / dbginfo.h
1 /*
2  * Copyright (C) 1995-2007 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
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.
10  *
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.
14  *
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
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief     Implements the Firm interface to debug information.
23  * @author    Goetz Lindenmaier, Michael Beck
24  * @date      2001
25  * @version   $Id$
26  * @summary
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.
34  */
35 #ifndef FIRM_DEBUG_DBGINFO_H
36 #define FIRM_DEBUG_DBGINFO_H
37
38 #include "firm_types.h"
39 #include "ident.h"
40
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44
45 /**
46  * @defgroup debug    The Firm interface to debugging support.
47  *
48  * @{
49  */
50
51 /**
52  * @typedef dbg_info
53  *
54  * An abstract data type containing information for
55  * debugging support.
56  *
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.
59  */
60
61 /**
62  * Sets the debug information of a node.
63  *
64  * @param n   The node.
65  * @param db  The debug info.
66  */
67 void set_irn_dbg_info(ir_node *n, dbg_info *db);
68
69 /**
70  * Returns the debug information of an node.
71  *
72  * @param n   The node.
73  */
74 dbg_info *get_irn_dbg_info(const ir_node *n);
75
76 /**
77  * Sets the debug information of an entity.
78  *
79  * @param ent The entity.
80  * @param db  The debug info.
81  */
82 void set_entity_dbg_info(ir_entity *ent, dbg_info *db);
83
84 /**
85  * Returns the debug information of an entity.
86  *
87  * @param ent The entity.
88  */
89 dbg_info *get_entity_dbg_info(const ir_entity *ent);
90
91 /**
92  * Sets the debug information of a type.
93  *
94  * @param tp  The type.
95  * @param db  The debug info.
96  */
97 void set_type_dbg_info(ir_type *tp, dbg_info *db);
98
99 /**
100  * Returns the debug information of a type.
101  *
102  * @param tp  The type.
103  */
104 dbg_info *get_type_dbg_info(const ir_type *tp);
105
106 /**
107  * An enumeration indicating the action performed by a transformation.
108  */
109 typedef enum {
110   dbg_error = 0,
111   dbg_opt_ssa,           /**< Optimization of the SSA representation, e.g. removal of superfluent Phi nodes. */
112   dbg_opt_auxnode,       /**< Removal of unnecessary auxiliary nodes. */
113   dbg_const_eval,        /**< A Firm subgraph was evaluated to a single constant. */
114   dbg_opt_cse,           /**< A Firm node was replaced due to common subexpression elimination. */
115   dbg_straightening,     /**< A Firm subgraph was replaced by a single, existing block. */
116   dbg_if_simplification, /**< The control flow of an if is changed as either the
117                                     else, the then or both blocks are empty. */
118   dbg_algebraic_simplification, /**< A Firm subgraph was replaced because of an algebraic
119                                      simplification. */
120   dbg_write_after_write,        /**< A Firm subgraph was replaced because of a write
121                                      after write optimization. */
122   dbg_write_after_read,         /**< A Firm subgraph was replaced because of a write
123                                      after read optimization. */
124   dbg_read_after_write,         /**< A Firm subgraph was replaced because of a read
125                                      after write optimization. */
126   dbg_read_after_read,          /**< A Firm subgraph was replaced because of a read
127                                      after read optimization. */
128   dbg_read_a_const,             /**< A Firm subgraph was replaced because of a read
129                                      a constant optimization. */
130   dbg_rem_poly_call,            /**< Remove polymorphic call. */
131   dbg_dead_code,                /**< Removing unreachable code, I.e. blocks that are never executed. */
132   dbg_opt_confirm,              /**< A Firm subgraph was replace because of a Confirmation. */
133   dbg_backend,                  /**< A Firm subgraph was replaced because of a Backend transformation */
134   dbg_max                       /**< Maximum value. */
135 } dbg_action;
136
137 /**
138  * Converts a debug_action into a string.
139  *
140  * @param a  the debug action
141  */
142 const char *dbg_action_2_str(dbg_action a);
143
144 /**
145  * The type of the debug info merge function.
146  *
147  * @param new_node    the new ir node
148  * @param old_node    the old ir node
149  * @param action      the action that triggers the merge
150  *
151  * @see dbg_init()
152  */
153 typedef void merge_pair_func(ir_node *new_node, ir_node *old_node, dbg_action action);
154
155 /**
156  * The type of the debug info merge sets function.
157  *
158  * @param new_node_array    array of new nodes
159  * @param new_num_entries   number of entries in new_node_array
160  * @param old_node_array    array of old nodes
161  * @param old_num_entries   number of entries in old_node_array
162  * @param action            the action that triggers the merge
163  *
164  * @see dbg_init()
165  */
166 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);
167
168 /**
169  * The type of the debug info to human readable string function.
170  *
171  * @param buf    pointer to a buffer that will hold the info
172  * @param len    length of the buffer
173  * @param dbg    the debug info
174  *
175  * @return  Number of written characters to the buffer.
176  *
177  * @see dbg_init()
178  */
179 typedef unsigned snprint_dbg_func(char *buf, unsigned len, const dbg_info *dbg);
180
181 /**
182  *  Initializes the debug support.
183  *
184  *  @param dbg_info_merge_pair   see function description
185  *  @param dbg_info_merge_sets   see function description
186  *  @param snprint_dbg           see function description
187  *
188  *  This function takes pointers to two functions that merge the
189  *  debug information when a
190  *  transformation of a Firm graph is performed.
191  *  Firm transformations call one of these functions.
192  *
193  *   - dbg_info_merge_pair() is called in the following situation:
194  *     The optimization replaced the old node by the new one.  The new node
195  *     might be a recent allocated node not containing any debug information,
196  *     or just another node from somewhere in the graph with the same
197  *     semantics.
198  *   - dbg_info_merge_sets() is called in the following situation:
199  *     The optimization replaced a subgraph by another subgraph.  There is no
200  *     obviously mapping between single nodes in both subgraphs.  The optimization
201  *     simply passes two lists to the debug module, one containing the nodes in
202  *     the old subgraph, the other containing the nodes in the new subgraph.
203  *     The same node can be in both lists.
204  *
205  *   Further both functions pass an enumeration indicating the action
206  *   performed by the transformation, e.g. the kind of optimization performed.
207  *
208  * The third argument snprint_dbg is called to convert a debug info into a human readable string.
209  * This string is the dumped in the dumper functions.
210  *
211  * Note that if NULL is passed for dbg_info_merge_pair or dbg_info_merge_sets, the default
212  * implementations default_dbg_info_merge_pair() and default_dbg_info_merge_sets() are used.
213  * NULL passed for snprint_dbg means no output.
214  */
215 void dbg_init(merge_pair_func *dbg_info_merge_pair, merge_sets_func *dbg_info_merge_sets, snprint_dbg_func *snprint_dbg);
216
217 /**
218  * The default merge_pair_func implementation, simply copies the debug info
219  * from the old Firm node to the new one if the new one does not have debug info yet.
220  *
221  * @param nw    The new Firm node.
222  * @param old   The old Firm node.
223  * @param info  The action that cause old node to be replaced by new one.
224  */
225 void default_dbg_info_merge_pair(ir_node *nw, ir_node *old, dbg_action info);
226
227 /**
228  * The default merge_sets_func implementation.  If n_old_nodes is equal 1, copies
229  * the debug info from the old node to all new ones (if they do not have one), else does nothing.
230  *
231  * @param new_nodes     An array of new Firm nodes.
232  * @param n_new_nodes   The length of the new_nodes array.
233  * @param old_nodes     An array of old (replaced) Firm nodes.
234  * @param n_old_nodes   The length of the old_nodes array.
235  * @param info          The action that cause old node to be replaced by new one.
236  */
237 void default_dbg_info_merge_sets(ir_node **new_nodes, int n_new_nodes,
238                             ir_node **old_nodes, int n_old_nodes,
239                             dbg_action info);
240
241 /** @} */
242
243 #ifdef __cplusplus
244 }
245 #endif
246
247 #endif