3 * File name: ir/debug/dbginfo.h
4 * Purpose: Implements the Firm interface to debug information.
5 * Author: Goetz Lindenmaier
9 * Copyright: (c) 2001-2003 Universität Karlsruhe
10 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
16 * This is the Firm interface to debugging support.
18 * @author Goetz Lindenmaier
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.
35 #ifndef _IR_NODE_TYPEDEF_
36 #define _IR_NODE_TYPEDEF_
37 typedef struct ir_node ir_node;
40 /* to resolve recursion between entity.h and type.h */
41 #ifndef _ENTITY_TYPEDEF_
42 #define _ENTITY_TYPEDEF_
43 typedef struct entity entity;
46 #ifndef _TYPE_TYPEDEF_
47 #define _TYPE_TYPEDEF_
48 typedef struct type type;
52 * @defgroup debug The Firm interface to debugging support.
58 * An abstract data type containing information for
61 * This opaque data type is not defined anywhere in the firm library,
62 * but pointers to this type can be stored in firm nodes.
64 typedef struct dbg_info dbg_info;
67 * Sets the debug information of a node.
69 void set_irn_dbg_info(ir_node *n, dbg_info *db);
72 * Returns the debug information of an node.
74 dbg_info *get_irn_dbg_info(ir_node *n);
77 * Sets the debug information of an entity.
79 void set_entity_dbg_info(entity *ent, dbg_info *db);
82 * Returns the debug information of an entity.
84 dbg_info *get_entity_dbg_info(entity *ent);
87 * Sets the debug information of a type.
89 void set_type_dbg_info(type *tp, dbg_info *db);
92 * Returns the debug information of a type.
94 dbg_info *get_type_dbg_info(type *tp);
97 * An enumeration indicating the action performed by a transformation.
101 dbg_opt_ssa, /**< Optimization of the SSA representation, e.g., removal of superfluent phi nodes. */
102 dbg_opt_auxnode, /**< Removal of unnecessary auxiliary nodes. */
103 dbg_const_eval, /**< A Firm subgraph was evaluated to a single constant. */
104 dbg_opt_cse, /**< A Firm node was replaced due to common subexpression elimination. */
105 dbg_straightening, /**< A Firm subgraph was replaced by a single, existing block. */
106 dbg_if_simplification, /**< The control flow of an if is changed as either the
107 else, the then or both blocks are empty. */
108 dbg_algebraic_simplification, /**< A Firm subgraph was replaced because of an algebraic
110 dbg_write_after_write, /**< A Firm subgraph was replaced because of a write
111 after write optimization. */
112 dbg_write_after_read, /**< A Firm subgraph was replaced because of a write
113 after read optimization. */
114 dbg_read_after_write, /**< A Firm subgraph was replaced because of a read
115 after write optimization. */
116 dbg_read_after_read, /**< A Firm subgraph was replaced because of a read
117 after read optimization. */
118 dbg_read_a_const, /**< A Firm subgraph was replaced because of a read
119 a constant optimization. */
120 dbg_rem_poly_call, /**< Remove polymorphic call. */
121 dbg_dead_code, /**< Removing unreachable code, I.e. blocks that are never executed. */
122 dbg_opt_confirm, /**< A Firm subgraph was replace because of a Confirmation */
123 dbg_max /**< Maximum value. */
129 * Converts enum values to strings.
132 static const char* dbg_action_2_str(dbg_action) __attribute__ ((unused));
135 static const char* dbg_action_2_str(dbg_action a) {
137 case dbg_error: return "dbg_error"; break;
138 case dbg_opt_ssa: return "dbg_opt_ssa"; break;
139 case dbg_opt_auxnode: return "dbg_opt_auxnode"; break;
140 case dbg_const_eval: return "dbg_const_eval"; break;
141 case dbg_opt_cse: return "dbg_opt_cse"; break;
142 case dbg_straightening: return "dbg_straightening"; break;
143 case dbg_if_simplification: return "dbg_if_simplification"; break;
144 case dbg_algebraic_simplification:
145 return "dbg_algebraic_simplification"; break;
146 case dbg_write_after_write: return "dbg_write_after_write"; break;
147 case dbg_write_after_read: return "dbg_write_after_read"; break;
148 case dbg_read_after_write: return "dbg_read_after_write"; break;
149 case dbg_read_after_read: return "dbg_read_after_read"; break;
150 case dbg_read_a_const: return "dbg_read_a_const"; break;
151 case dbg_rem_poly_call: return "dbg_rem_poly_call"; break;
152 case dbg_opt_confirm: return "dbg_opt_confirm"; break;
155 return "string conversion not implemented";
163 * The type of the debug info merge function.
165 * @param new_node the new ir node
166 * @param old_node the old ir node
167 * @param action the action that triggers the merge
171 typedef void merge_pair_func(ir_node *new_node, ir_node *old_node, dbg_action action);
174 * The type of the debug info merge sets function.
176 * @param new_node_array array of new nodes
177 * @param new_num_entries number of entries in new_node_array
178 * @param old_node_array array of old nodes
179 * @param old_num_entries number of entries in old_node_array
180 * @param action the action that triggers the merge
184 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);
187 * The type of the debug info to human readable string function.
189 * @param buf pointer to a buffer that will hold the info
190 * @param len length of the buffer
191 * @param dbg the debug info
193 * @return Number of written characters to the buffer.
197 typedef unsigned snprint_dbg_func(char *buf, unsigned len, const dbg_info *dbg);
200 * Initializes the debug support.
202 * @param dbg_info_merge_pair see function description
203 * @param dbg_info_merge_sets see function description
204 * @param snprint_dbg see function description
206 * This function takes Pointers to two functions that merge the
207 * debug information when a
208 * transformation of a firm graph is performed.
209 * Firm transformations call one of these functions.
211 * - dbg_info_merge_pair() is called in the following situation:
212 * The optimization replaced the old node by the new one. The new node
213 * might be a recent allocated node not containing any debug information,
214 * or just another node from somewhere in the graph with the same
216 * - dbg_info_merge_sets() is called in the following situation:
217 * The optimization replaced a subgraph by another subgraph. There is no
218 * obviously mapping between single nodes in both subgraphs. The optimization
219 * simply passes two lists to the debug module, one containing the nodes in
220 * the old subgraph, the other containing the nodes in the new subgraph.
221 * The same node can be in both lists.
223 * Further both functions pass an enumeration indicating the action
224 * performed by the transformation, e.g. the kind of optimization performed.
226 * The third argument snprint_dbg is called to convert a debug info into a human readable string.
227 * This string is the dumped in the dumper functions.
229 * Note that if NULL is passed for dbg_info_merge_pair or dbg_info_merge_sets, the default
230 * implementations default_dbg_info_merge_pair() and default_dbg_info_merge_sets() are used.
231 * NULL passed for snprint_dbg means no output.
233 void dbg_init(merge_pair_func *dbg_info_merge_pair, merge_sets_func *dbg_info_merge_sets, snprint_dbg_func *snprint_dbg);
238 * The default merge_pair_func implementation, simply copies the debug info
241 void default_dbg_info_merge_pair(ir_node *nw, ir_node *old, dbg_action info);
244 * The default merge_sets_func implementation, does nothing
246 void default_dbg_info_merge_sets(ir_node **new_nodes, int n_new_nodes,
247 ir_node **old_nodes, int n_old_nodes,
250 #endif /* _DBGINFO_H_ */