I was annoyed by the compiler warnings about implicit conversions.
[libfirm] / include / libfirm / irgopt.h
1 /*
2  * Copyright (C) 1995-2008 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   Optimizations for a whole ir graph, i.e., a procedure.
23  * @author  Christian Schaefer, Goetz Lindenmaier, Sebastian Felis
24  * @version $Id$
25  */
26 #ifndef FIRM_IR_IRGOPT_H
27 #define FIRM_IR_IRGOPT_H
28
29 #include "firm_types.h"
30
31 /** Applies local optimizations (see iropt.h) to all nodes reachable from node n.
32  *
33  * @param n The node to be optimized.
34  */
35 void local_optimize_node(ir_node *n);
36
37 /** Applies local optimizations (see iropt.h) to all nodes in the graph.
38  *
39  * @param irg  The graph to be optimized.
40  *
41  * After applying local_optimize_graph() to a IR-graph, Bad nodes
42  * only occur as predecessor of Block and Phi nodes.
43  */
44 void local_optimize_graph(ir_graph *irg);
45
46 /** Applies local optimizations (see iropt.h) to all nodes in the graph.
47  *
48  * After applying optimize_graph_df() to a IR-graph, Bad nodes
49  * only occur as predecessor of Block and Phi nodes.
50  *
51  * This version uses fixpoint iteration.
52  *
53  * @param irg  The graph to be optimized.
54  *
55  * @return non-zero if the optimization could be applied, 0 else
56  */
57 int optimize_graph_df(ir_graph *irg);
58
59 /**
60  * Creates an ir_graph pass for optimize_graph_df().
61  *
62  * @param name     the name of this pass or NULL
63  *
64  * @return  the newly created ir_graph pass
65  */
66 ir_graph_pass_t *optimize_graph_df_pass(const char *name);
67
68 /** Performs dead node elimination by copying the ir graph to a new obstack.
69  *
70  *  The major intention of this pass is to free memory occupied by
71  *  dead nodes and outdated analyzes information.  Further this
72  *  function removes Bad predecessors from Blocks and the corresponding
73  *  inputs to Phi nodes.  This opens optimization potential for other
74  *  optimizations.  Further this phase reduces dead Block<->Jmp
75  *  self-cycles to Bad nodes.
76  *
77  *  Dead_node_elimination is only performed if options `optimize' and
78  *  `opt_dead_node_elimination' are set.  The graph may
79  *  not be in state phase_building.  The outs datasturcture is freed,
80  *  the outs state set to outs_none.  Backedge information is conserved.
81  *  Removes old attributes of nodes.  Sets link field to NULL.
82  *  Callee information must be freed (irg_callee_info_none).
83  *
84  * @param irg  The graph to be optimized.
85  */
86 void dead_node_elimination(ir_graph *irg);
87
88 /**
89  * Creates an ir_graph pass for dead_node_elimination().
90  *
91  * @param name     the name of this pass or NULL
92  *
93  * @return  the newly created ir_graph pass
94  */
95 ir_graph_pass_t *dead_node_elimination_pass(const char *name);
96
97 typedef struct _survive_dce_t survive_dce_t;
98
99 /**
100  * Make a new Survive DCE environment.
101  */
102 survive_dce_t *new_survive_dce(void);
103
104 /**
105  * Free a Survive DCE environment.
106  */
107 void free_survive_dce(survive_dce_t *sd);
108
109 /**
110  * Register a node pointer to be patched upon DCE.
111  * When DCE occurs, the node pointer specified by @p place will be
112  * patched to the new address of the node it is pointing to.
113  *
114  * @param sd    The Survive DCE environment.
115  * @param place The address of the node pointer.
116  */
117 void survive_dce_register_irn(survive_dce_t *sd, ir_node **place);
118
119 /**  Cleans the control flow from Bad predecessors.
120  *
121  * Removes Bad predecessors from Blocks and the corresponding
122  * inputs to Phi nodes as in dead_node_elimination but without
123  * copying the graph.
124  *
125  * Conserves loop information.
126  *
127  * @param irg  The graph to be optimized.
128  */
129 void remove_bad_predecessors(ir_graph *irg);
130
131 /** Inlines a method at the given call site.
132  *
133  *  Removes the call node and splits the basic block the call node
134  *  belongs to.  Inserts a copy of the called graph between these nodes.
135  *  Assumes that call is a Call node in current_ir_graph and that
136  *  the type in the Call nodes type attribute is the same as the
137  *  type of the called graph.
138  *  Further it assumes that all Phi nodes in a block of current_ir_graph
139  *  are assembled in a "link" list in the link field of the corresponding
140  *  block nodes.  Further assumes that all Proj nodes are in a "link" list
141  *  in the nodes producing the tuple.  (This is only an optical feature
142  *  for the graph.)  Conserves this feature for the old
143  *  nodes of the graph.  This precondition can be established by a call to
144  *  collect_phisprojs(), see irgmod.h.
145  *  As dead_node_elimination this function reduces dead Block<->Jmp
146  *  self-cycles to Bad nodes.
147  *
148  *  Called_graph must be unequal to current_ir_graph.   Will not inline
149  *  if they are equal.
150  *  Sets visited masterflag in current_ir_graph to the max of the flag in
151  *  current and called graph.
152  *  Assumes that both, the called and the calling graph are in state
153  *  "op_pin_state_pinned".
154  *  It is recommended to call local_optimize_graph() after inlining as this
155  *  function leaves a set of obscure Tuple nodes, e.g. a Proj-Tuple-Jmp
156  *  combination as control flow operation.
157  *
158  *  @param call          the call node that should be inlined
159  *  @param called_graph  the IR-graph that is called at call
160  *
161  *  @return zero if method could not be inlined (recursion for instance),
162  *          non-zero if all went ok
163  */
164 int inline_method(ir_node *call, ir_graph *called_graph);
165
166 /** Code Placement.
167  *
168  * Pins all floating nodes to a block where they
169  * will be executed only if needed.   Depends on the flag opt_global_cse.
170  * Graph may not be in phase_building.  Does not schedule control dead
171  * code.  Uses dominator information which it computes if the irg is not
172  * in state dom_consistent.  Destroys the out information as it moves nodes
173  * to other blocks.  Optimizes Tuples in Control edges.
174  * @todo This is not tested!
175  *
176  * Call remove_critical_cf_edges() before place_code().  This normalizes
177  * the control flow graph so that for all operations a basic block exists
178  * where they can be optimally placed.
179  *
180  * @todo A more powerful code placement would move operations past Phi nodes
181  * out of loops.
182  */
183 void place_code(ir_graph *irg);
184
185 /**
186  * Creates an ir_graph pass for place_code().
187  * This pass enables GCSE, runs optimize_graph_df() and finally
188  * place_code();
189  *
190  * @param name     the name of this pass or NULL
191  *
192  * @return  the newly created ir_graph pass
193  */
194 ir_graph_pass_t *place_code_pass(const char *name);
195
196 /** Places an empty basic block on critical control flow edges thereby
197  * removing them.
198  *
199  * A critical control flow edge is an edge from a block with several
200  * control exits to a block with several control entries (See Muchnic
201  * p. 407). Exception edges are always ignored.
202  *
203  * @param irg  IR Graph
204  */
205 void remove_critical_cf_edges(ir_graph *irg);
206
207 /** Places an empty basic block on critical control flow edges thereby
208  * removing them.
209  *
210  * A critical control flow edge is an edge from a block with several
211  * control exits to a block with several control entries (See Muchnic
212  * p. 407).
213  *
214  * @param irg                     IR Graph
215  * @param ignore_exception_edges  if non-zero, exception edges will be ignored
216  */
217 void remove_critical_cf_edges_ex(ir_graph *irg, int ignore_exception_edges);
218
219 #endif