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