dbginfo.h 9.06 KB
Newer Older
Christian Würdig's avatar
Christian Würdig committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*
 * Copyright (C) 1995-2007 University of Karlsruhe.  All right reserved.
 *
 * This file is part of libFirm.
 *
 * This file may be distributed and/or modified under the terms of the
 * GNU General Public License version 2 as published by the Free Software
 * Foundation and appearing in the file LICENSE.GPL included in the
 * packaging of this file.
 *
 * Licensees holding valid libFirm Professional Edition licenses may use
 * this file in accordance with the libFirm Commercial License.
 * Agreement provided with the Software.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE.
 */

20
/*
21
22
23
24
 * Project:     libFIRM
 * File name:   ir/debug/dbginfo.h
 * Purpose:     Implements the Firm interface to debug information.
 * Author:      Goetz Lindenmaier
Michael Beck's avatar
Michael Beck committed
25
 * Modified by: Michael Beck
26
27
28
29
 * Created:     2001
 * CVS-ID:      $Id$
 * Copyright:   (c) 2001-2003 Universität Karlsruhe
 */
Michael Beck's avatar
Michael Beck committed
30
31

/**
Michael Beck's avatar
Michael Beck committed
32
33
34
35
 * @file  dbginfo.h
 *
 *  This is the Firm interface to debugging support.
 *
36
 *  @author Goetz Lindenmaier, Michael Beck
Michael Beck's avatar
Michael Beck committed
37
38
39
40
41
 *
 *  Firm requires a debugging module fulfilling this interface, else no
 *  debugging information is passed to the backend.
 *  The interface requires a datatype representing the debugging
 *  information.  Firm supports administrating a reference to the debug
42
 *  information in every Firm node.  Further Firm optimizations call
Michael Beck's avatar
Michael Beck committed
43
44
45
46
 *  routines to propagate debug information from old nodes to new nodes
 *  if the optimization replaces the old ones by the new ones.
 *
 */
47

Michael Beck's avatar
Michael Beck committed
48
49
#ifndef _DBGINFO_H_
#define _DBGINFO_H_
50

Michael Beck's avatar
Michael Beck committed
51
#include "firm_types.h"
52
53
#include "ident.h"

Michael Beck's avatar
Michael Beck committed
54
55
56
57
#ifdef __cplusplus
extern "C" {
#endif

Sebastian Felis's avatar
Sebastian Felis committed
58
/**
Michael Beck's avatar
Michael Beck committed
59
 * @defgroup debug    The Firm interface to debugging support.
Götz Lindenmaier's avatar
Götz Lindenmaier committed
60
 *
Michael Beck's avatar
Michael Beck committed
61
62
63
64
65
66
67
 * @{
 */

/**
 * An abstract data type containing information for
 * debugging support.
 *
68
69
 * This opaque data type is not defined anywhere in the Firm library,
 * but pointers to this type can be stored in Firm nodes.
Götz Lindenmaier's avatar
Götz Lindenmaier committed
70
 */
71
typedef struct dbg_info dbg_info;
Michael Beck's avatar
Michael Beck committed
72
73
74

/**
 * Sets the debug information of a node.
75
76
77
 *
 * @param n   The node.
 * @param db  The debug info.
Michael Beck's avatar
Michael Beck committed
78
 */
Michael Beck's avatar
Michael Beck committed
79
void set_irn_dbg_info(ir_node *n, dbg_info *db);
Michael Beck's avatar
Michael Beck committed
80
81
82

/**
 * Returns the debug information of an node.
83
84
 *
 * @param n   The node.
Michael Beck's avatar
Michael Beck committed
85
 */
Christoph Mallon's avatar
Christoph Mallon committed
86
dbg_info *get_irn_dbg_info(const ir_node *n);
Michael Beck's avatar
Michael Beck committed
87
88
89

/**
 * Sets the debug information of an entity.
90
91
92
 *
 * @param ent The entity.
 * @param db  The debug info.
Michael Beck's avatar
Michael Beck committed
93
 */
94
void set_entity_dbg_info(ir_entity *ent, dbg_info *db);
Michael Beck's avatar
Michael Beck committed
95
96
97

/**
 * Returns the debug information of an entity.
98
99
 *
 * @param ent The entity.
Michael Beck's avatar
Michael Beck committed
100
 */
101
dbg_info *get_entity_dbg_info(const ir_entity *ent);
Michael Beck's avatar
Michael Beck committed
102
103
104

/**
 * Sets the debug information of a type.
105
106
107
 *
 * @param tp  The type.
 * @param db  The debug info.
Michael Beck's avatar
Michael Beck committed
108
 */
109
void set_type_dbg_info(ir_type *tp, dbg_info *db);
Michael Beck's avatar
Michael Beck committed
110
111
112

/**
 * Returns the debug information of a type.
113
114
 *
 * @param tp  The type.
Michael Beck's avatar
Michael Beck committed
115
 */
116
dbg_info *get_type_dbg_info(const ir_type *tp);
Götz Lindenmaier's avatar
Götz Lindenmaier committed
117

Sebastian Felis's avatar
Sebastian Felis committed
118
/**
119
 * An enumeration indicating the action performed by a transformation.
Götz Lindenmaier's avatar
Götz Lindenmaier committed
120
121
122
 */
typedef enum {
  dbg_error = 0,
123
  dbg_opt_ssa,           /**< Optimization of the SSA representation, e.g. removal of superfluent Phi nodes. */
Michael Beck's avatar
Michael Beck committed
124
  dbg_opt_auxnode,       /**< Removal of unnecessary auxiliary nodes. */
125
  dbg_const_eval,        /**< A Firm subgraph was evaluated to a single constant. */
Michael Beck's avatar
Michael Beck committed
126
  dbg_opt_cse,           /**< A Firm node was replaced due to common subexpression elimination. */
127
128
  dbg_straightening,     /**< A Firm subgraph was replaced by a single, existing block. */
  dbg_if_simplification, /**< The control flow of an if is changed as either the
Florian Liekweg's avatar
Florian Liekweg committed
129
                                    else, the then or both blocks are empty. */
Michael Beck's avatar
Michael Beck committed
130
131
132
133
134
135
  dbg_algebraic_simplification, /**< A Firm subgraph was replaced because of an algebraic
                                     simplification. */
  dbg_write_after_write,        /**< A Firm subgraph was replaced because of a write
                                     after write optimization. */
  dbg_write_after_read,         /**< A Firm subgraph was replaced because of a write
                                     after read optimization. */
136
137
  dbg_read_after_write,         /**< A Firm subgraph was replaced because of a read
                                     after write optimization. */
138
  dbg_read_after_read,          /**< A Firm subgraph was replaced because of a read
Michael Beck's avatar
Michael Beck committed
139
140
141
                                     after read optimization. */
  dbg_read_a_const,             /**< A Firm subgraph was replaced because of a read
                                     a constant optimization. */
Götz Lindenmaier's avatar
Götz Lindenmaier committed
142
  dbg_rem_poly_call,            /**< Remove polymorphic call. */
143
  dbg_dead_code,                /**< Removing unreachable code, I.e. blocks that are never executed. */
144
145
  dbg_opt_confirm,              /**< A Firm subgraph was replace because of a Confirmation. */
  dbg_backend,                  /**< A Firm subgraph was replaced because of a Backend transformation */
Michael Beck's avatar
Michael Beck committed
146
  dbg_max                       /**< Maximum value. */
Götz Lindenmaier's avatar
Götz Lindenmaier committed
147
} dbg_action;
Götz Lindenmaier's avatar
Götz Lindenmaier committed
148

Sebastian Felis's avatar
Sebastian Felis committed
149
/**
150
151
152
 * Converts a debug_action into a string.
 *
 * @param a  the debug action
Götz Lindenmaier's avatar
Götz Lindenmaier committed
153
 */
154
const char *dbg_action_2_str(dbg_action a);
155

156
157
158
/**
 * The type of the debug info merge function.
 *
Michael Beck's avatar
Michael Beck committed
159
160
161
162
 * @param new_node    the new ir node
 * @param old_node    the old ir node
 * @param action      the action that triggers the merge
 *
163
164
 * @see dbg_init()
 */
Michael Beck's avatar
Michael Beck committed
165
typedef void merge_pair_func(ir_node *new_node, ir_node *old_node, dbg_action action);
Götz Lindenmaier's avatar
Götz Lindenmaier committed
166

Sebastian Felis's avatar
Sebastian Felis committed
167
/**
Michael Beck's avatar
Michael Beck committed
168
169
170
171
172
173
174
 * The type of the debug info merge sets function.
 *
 * @param new_node_array    array of new nodes
 * @param new_num_entries   number of entries in new_node_array
 * @param old_node_array    array of old nodes
 * @param old_num_entries   number of entries in old_node_array
 * @param action            the action that triggers the merge
175
176
177
 *
 * @see dbg_init()
 */
178
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);
179

180
181
182
183
184
185
186
187
188
189
190
191
192
/**
 * The type of the debug info to human readable string function.
 *
 * @param buf    pointer to a buffer that will hold the info
 * @param len    length of the buffer
 * @param dbg    the debug info
 *
 * @return  Number of written characters to the buffer.
 *
 * @see dbg_init()
 */
typedef unsigned snprint_dbg_func(char *buf, unsigned len, const dbg_info *dbg);

193
/**
Michael Beck's avatar
Michael Beck committed
194
 *  Initializes the debug support.
195
 *
Michael Beck's avatar
Michael Beck committed
196
197
 *  @param dbg_info_merge_pair   see function description
 *  @param dbg_info_merge_sets   see function description
198
 *  @param snprint_dbg           see function description
199
 *
200
 *  This function takes pointers to two functions that merge the
Michael Beck's avatar
Michael Beck committed
201
 *  debug information when a
202
 *  transformation of a Firm graph is performed.
Michael Beck's avatar
Michael Beck committed
203
 *  Firm transformations call one of these functions.
Götz Lindenmaier's avatar
Götz Lindenmaier committed
204
205
 *
 *   - dbg_info_merge_pair() is called in the following situation:
206
207
208
209
 *     The optimization replaced the old node by the new one.  The new node
 *     might be a recent allocated node not containing any debug information,
 *     or just another node from somewhere in the graph with the same
 *     semantics.
Götz Lindenmaier's avatar
Götz Lindenmaier committed
210
 *   - dbg_info_merge_sets() is called in the following situation:
211
 *     The optimization replaced a subgraph by another subgraph.  There is no
Michael Beck's avatar
Michael Beck committed
212
 *     obviously mapping between single nodes in both subgraphs.  The optimization
213
214
215
216
217
218
 *     simply passes two lists to the debug module, one containing the nodes in
 *     the old subgraph, the other containing the nodes in the new subgraph.
 *     The same node can be in both lists.
 *
 *   Further both functions pass an enumeration indicating the action
 *   performed by the transformation, e.g. the kind of optimization performed.
219
 *
Michael Beck's avatar
Michael Beck committed
220
221
 * The third argument snprint_dbg is called to convert a debug info into a human readable string.
 * This string is the dumped in the dumper functions.
222
223
224
 *
 * Note that if NULL is passed for dbg_info_merge_pair or dbg_info_merge_sets, the default
 * implementations default_dbg_info_merge_pair() and default_dbg_info_merge_sets() are used.
Michael Beck's avatar
Michael Beck committed
225
 * NULL passed for snprint_dbg means no output.
Götz Lindenmaier's avatar
Götz Lindenmaier committed
226
 */
227
void dbg_init(merge_pair_func *dbg_info_merge_pair, merge_sets_func *dbg_info_merge_sets, snprint_dbg_func *snprint_dbg);
Götz Lindenmaier's avatar
Götz Lindenmaier committed
228

229
230
/**
 * The default merge_pair_func implementation, simply copies the debug info
231
232
233
234
235
 * from the old Firm node to the new one if the new one does not have debug info yet.
 *
 * @param nw    The new Firm node.
 * @param old   The old Firm node.
 * @param info  The action that cause old node to be replaced by new one.
236
237
238
239
 */
void default_dbg_info_merge_pair(ir_node *nw, ir_node *old, dbg_action info);

/**
240
241
242
243
244
245
246
247
 * The default merge_sets_func implementation.  If n_old_nodes is equal 1, copies
 * the debug info from the old node to all new ones (if they do not have one), else does nothing.
 *
 * @param new_nodes     An array of new Firm nodes.
 * @param n_new_nodes   The length of the new_nodes array.
 * @param old_nodes     An array of old (replaced) Firm nodes.
 * @param n_old_nodes   The length of the old_nodes array.
 * @param info          The action that cause old node to be replaced by new one.
248
249
250
251
252
 */
void default_dbg_info_merge_sets(ir_node **new_nodes, int n_new_nodes,
                            ir_node **old_nodes, int n_old_nodes,
                            dbg_action info);

253
254
/** @} */

Michael Beck's avatar
Michael Beck committed
255
256
257
258
#ifdef __cplusplus
}
#endif

259
#endif /* _DBGINFO_H_ */