becopyopt: Inline the thin wrapper nodes_interfere(), so we do not need to fetch...
[libfirm] / include / libfirm / dbginfo.h
1 /*
2  * This file is part of libFirm.
3  * Copyright (C) 2012 University of Karlsruhe.
4  */
5
6 /**
7  * @file
8  * @brief     Implements the Firm interface to debug information.
9  * @author    Goetz Lindenmaier, Michael Beck
10  * @date      2001
11  */
12 #ifndef FIRM_DEBUG_DBGINFO_H
13 #define FIRM_DEBUG_DBGINFO_H
14
15 #include <stdlib.h>
16 #include "firm_types.h"
17 #include "ident.h"
18 #include "begin.h"
19
20 /**
21  * @defgroup dbg_info    Source References
22  *  Firm requires a debugging module fulfilling this interface, else no
23  *  debugging information is passed to the backend.
24  *  The interface requires a datatype representing the debugging
25  *  information.  Firm supports administrating a reference to the debug
26  *  information in every Firm node.  Further Firm optimizations call
27  *  routines to propagate debug information from old nodes to new nodes
28  *  if the optimization replaces the old ones by the new ones.
29  * @{
30  */
31
32 /**
33  * @typedef dbg_info
34  *
35  * An abstract data type containing information for
36  * debugging support.
37  *
38  * This opaque data type is not defined anywhere in the Firm library,
39  * but pointers to this type can be stored in Firm nodes.
40  */
41
42 /**
43  * An enumeration indicating the action performed by a transformation.
44  */
45 typedef enum {
46         dbg_error = 0,
47         dbg_opt_ssa,           /**< Optimization of the SSA representation, e.g. removal of superfluent Phi nodes. */
48         dbg_opt_auxnode,       /**< Removal of unnecessary auxiliary nodes. */
49         dbg_const_eval,        /**< A Firm subgraph was evaluated to a single constant. */
50         dbg_opt_cse,           /**< A Firm node was replaced due to common subexpression elimination. */
51         dbg_straightening,     /**< A Firm subgraph was replaced by a single, existing block. */
52         dbg_if_simplification, /**< The control flow of an if is changed as either the
53                                           else, the then or both blocks are empty. */
54         dbg_algebraic_simplification, /**< A Firm subgraph was replaced because of an algebraic
55                                            simplification. */
56         dbg_write_after_write,        /**< A Firm subgraph was replaced because of a write
57                                            after write optimization. */
58         dbg_write_after_read,         /**< A Firm subgraph was replaced because of a write
59                                            after read optimization. */
60         dbg_read_after_write,         /**< A Firm subgraph was replaced because of a read
61                                            after write optimization. */
62         dbg_read_after_read,          /**< A Firm subgraph was replaced because of a read
63                                            after read optimization. */
64         dbg_read_a_const,             /**< A Firm subgraph was replaced because of a read
65                                            a constant optimization. */
66         dbg_rem_poly_call,            /**< Remove polymorphic call. */
67         dbg_dead_code,                /**< Removing unreachable code, i.e. blocks that are never executed. */
68         dbg_opt_confirm,              /**< A Firm subgraph was replace because of a Confirmation. */
69         dbg_gvn_pre,                  /**< A Firm node was replace because of the GVN-PRE algorithm. */
70         dbg_combo,                    /**< A Firm node was replace because of the combo algorithm. */
71         dbg_jumpthreading,            /**< A Firm node was replace because of the jumpthreading algorithm. */
72         dbg_backend,                  /**< A Firm subgraph was replaced because of a Backend transformation */
73         dbg_max                       /**< Maximum value. */
74 } dbg_action;
75
76 /**
77  * Converts a debug_action into a string.
78  *
79  * @param a  the debug action
80  */
81 FIRM_API const char *dbg_action_2_str(dbg_action a);
82
83 /**
84  * The type of the debug info merge function.
85  *
86  * @param new_node    the new ir node
87  * @param old_node    the old ir node
88  * @param action      the action that triggers the merge
89  *
90  * @see dbg_init()
91  */
92 typedef void merge_pair_func(ir_node *new_node, ir_node *old_node, dbg_action action);
93
94 /**
95  * The type of the debug info merge sets function.
96  *
97  * @param new_node_array    array of new nodes
98  * @param new_num_entries   number of entries in new_node_array
99  * @param old_node_array    array of old nodes
100  * @param old_num_entries   number of entries in old_node_array
101  * @param action            the action that triggers the merge
102  *
103  * @see dbg_init()
104  */
105 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);
106
107 /**
108  *  Initializes the debug support.
109  *
110  *  This function takes pointers to two functions that merge the
111  *  debug information when a
112  *  transformation of a Firm graph is performed.
113  *  Firm transformations call one of these functions.
114  *
115  *   - dbg_info_merge_pair() is called in the following situation:
116  *     The optimization replaced the old node by the new one.  The new node
117  *     might be a recent allocated node not containing any debug information,
118  *     or just another node from somewhere in the graph with the same
119  *     semantics.
120  *   - dbg_info_merge_sets() is called in the following situation:
121  *     The optimization replaced a subgraph by another subgraph.  There is no
122  *     obviously mapping between single nodes in both subgraphs.  The optimization
123  *     simply passes two lists to the debug module, one containing the nodes in
124  *     the old subgraph, the other containing the nodes in the new subgraph.
125  *     The same node can be in both lists.
126  *
127  *   Further both functions pass an enumeration indicating the action
128  *   performed by the transformation, e.g. the kind of optimization performed.
129  */
130 FIRM_API void dbg_init(merge_pair_func *dbg_info_merge_pair,
131                        merge_sets_func *dbg_info_merge_sets);
132
133 /** A sourcecode location */
134 typedef struct src_loc_t {
135         char const *file;    /**< the name of the source (usually a file) */
136         unsigned    line;    /**< line number (starting at 1; 0 if unknown) */
137         unsigned    column;  /**< column number (starting at 1; 0 if unknown) */
138 } src_loc_t;
139
140 /**
141  * The type of the debug info retriever function.
142  *  When given a dbg_info returns the name (usually the filename), line number
143  *  and column number of the definition.
144  *  Any part of the returned information may be NULL/0, which means it is not
145  *  available.
146  */
147 typedef src_loc_t (*retrieve_dbg_func)(dbg_info const *dbg);
148
149 /**
150  * Sets a debug info retriever.
151  *
152  * @param func   the debug retriever function.
153  */
154 FIRM_API void ir_set_debug_retrieve(retrieve_dbg_func func);
155
156 /**
157  * The type of the type debug info retrieve function.
158  * Prints a human readable source representation of a type to an obstack.
159  *  (Used for generating debug info like stabs or dwarf)
160  */
161 typedef void (*retrieve_type_dbg_func)(char *buffer, size_t buffer_size,
162                                        const type_dbg_info *tdbgi);
163
164 /**
165  * Sets global print_type_dbg_info function in firm
166  */
167 FIRM_API void ir_set_type_debug_retrieve(retrieve_type_dbg_func func);
168
169 /**
170  * Retrieve the debug info.
171  */
172 FIRM_API src_loc_t ir_retrieve_dbg_info(dbg_info const *dbg);
173
174 /**
175  * Retrieve type debug info
176  */
177 FIRM_API void ir_retrieve_type_dbg_info(char *buffer, size_t buffer_size,
178                                         const type_dbg_info *tdbgi);
179
180 /** @} */
181
182 #include "end.h"
183
184 #endif