removed include
[libfirm] / ir / ir / irgopt.h
1 /*
2  * Project:     libFIRM
3  * File name:   ir/ir/irgopt.h
4  * Purpose:     Optimizations for a whole ir graph, i.e., a procedure.
5  * Author:      Christian Schaefer, Goetz Lindenmaier
6  * Modified by: Sebastian Felis
7  * Created:
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 1998-2003 Universität Karlsruhe
10  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11  */
12
13 /**
14  * @file irgopt.h
15  *
16  * Optimizations for a whole ir graph, i.e., a procedure.
17  *
18  * @author Christian Schaefer, Goetz Lindenmaier
19  */
20
21 # ifndef _IRGOPT_H_
22 # define _IRGOPT_H_
23
24 # include "irgraph.h"
25
26 /** Applies local optimizations (see iropt.h) to all nodes reachable from node n.
27  *
28  * @param n The node to be optimized.
29  */
30 void local_optimize_node(ir_node *n);
31
32 /** Applies local optimizations (see iropt.h) to all nodes in the graph.
33  *
34  * @param irg  The graph to be optimized.
35  *
36  * After appliying local_optimize_graph() to a IR-graph, Bad nodes
37  * only occure as predecessor of Block and Phi nodes.
38  */
39 void local_optimize_graph (ir_graph *irg);
40
41 /** Performs dead node elimination by copying the ir graph to a new obstack.
42  *
43  *  The major intention of this pass is to free memory occupied by
44  *  dead nodes and outdated analyses information.  Further this
45  *  function removes Bad predecesors from Blocks and the corresponding
46  *  inputs to Phi nodes.  This opens optmization potential for other
47  *  optimizations.  Further this phase reduces dead Block<->Jmp
48  *  self-cycles to Bad nodes.
49  *
50  *  Dead_node_elimination is only performed if options `optimize' and
51  *  `opt_dead_node_elimination' are set.  The graph may
52  *  not be in state phase_building.  The outs datasturcture is freed,
53  *  the outs state set to outs_none.  Backedge information is conserved.
54  *  Removes old attributes of nodes.  Sets link field to NULL.
55  *  Callee information must be freed (irg_callee_info_none).
56  *
57  *  Attention: the numbers assigned to nodes if the library is compiled for
58  *  development/debugging are not conserved by copying.
59  *
60  * @param irg  The graph to be optimized.
61  */
62 void dead_node_elimination(ir_graph *irg);
63
64 /**  Cleans the control flow from Bad predecesors.
65  *
66  * Removes Bad predecesors from Blocks and the corresponding
67  * inputs to Phi nodes as in dead_node_elimination but without
68  * copying the graph.
69  *
70  * @param irg  The graph to be optimized.
71  */
72 void remove_bad_predecessors(ir_graph *irg);
73
74 /** Inlines a method at the given call site.
75  *
76  *  Removes the call node and splits the basic block the call node
77  *  belongs to.  Inserts a copy of the called graph between these nodes.
78  *  Assumes that call is a Call node in current_ir_graph and that
79  *  the type in the Call nodes type attribute is the same as the
80  *  type of the called graph.
81  *  Further it assumes that all Phi nodes in a block of current_ir_graph
82  *  are assembled in a "link" list in the link field of the corresponding
83  *  block nodes.  Further assumes that all Proj nodes are in a "link" list
84  *  in the nodes producing the tuple.  (This is only an optical feature
85  *  for the graph.)  Conserves this feature for the old
86  *  nodes of the graph.  This precondition can be established by a call to
87  *  collect_phisprojs(), see irgmod.h.
88  *  As dead_node_elimination this function reduces dead Block<->Jmp
89  *  self-cycles to Bad nodes.
90  *
91  *  Called_graph must be unequal to current_ir_graph.   Will not inline
92  *  if they are equal.
93  *  Sets visited masterflag in current_ir_graph to the max of the flag in
94  *  current and called graph.
95  *  Assumes that both, the called and the calling graph are in state
96  *  "op_pin_state_pinned".
97  *  It is recommended to call local_optimize_graph() after inlining as this
98  *  function leaves a set of obscure Tuple nodes, e.g. a Proj-Tuple-Jmp
99  *  combination as control flow operation.
100  *
101  *  @param call          the call node that should be inlined
102  *  @param called_graph  the IR-graph that is called at call
103  *
104  *  @return zero if method could not be inlined (recursion for instance),
105  *          non-zero if all went ok
106  */
107 int inline_method(ir_node *call, ir_graph *called_graph);
108
109 /** Inlines all small methods at call sites where the called address comes
110  *  from a SymConst node that references the entity representing the called
111  *  method.
112  *
113  *  The size argument is a rough measure for the code size of the method:
114  *  Methods where the obstack containing the firm graph is smaller than
115  *  size are inlined.  Further only a limited number of calls are inlined.
116  *  If the method contains more than 1024 inlineable calls none will be
117  *  inlined.
118  *  Inlining is only performed if flags `optimize' and `inlineing' are set.
119  *  The graph may not be in state phase_building.
120  *  It is recommended to call local_optimize_graph() after inlining as this
121  *  function leaves a set of obscure Tuple nodes, e.g. a Proj-Tuple-Jmp
122  *  combination as control flow operation.
123  */
124 void inline_small_irgs(ir_graph *irg, int size);
125
126
127 /** Inlineing with a different heuristic than inline_small_irgs().
128  *
129  *  Inlines leave functions.  If inlinening creates new leave
130  *  function inlines these, too. (If g calls f, and f calls leave h,
131  *  h is first inlined in f and then f in g.)
132  *
133  *  Then inlines all small functions (this is not recursive).
134  *
135  *  For a heuristic this inlineing uses firm node counts.  It does
136  *  not count auxiliary nodes as Proj, Tuple, End, Start, Id, Sync.
137  *
138  *  @param maxsize   Do not inline any calls if a method has more than
139  *                   maxsize firm nodes.  It may reach this limit by
140  *                   inlineing.
141  *  @param leavesize Inline leave functions if they have less than leavesize
142  *                   nodes.
143  *  @param size      Inline all function smaller than size.
144  */
145 void inline_leave_functions(int maxsize, int leavesize, int size);
146
147 /** Code Placement.
148  *
149  * Pinns all floating nodes to a block where they
150  * will be executed only if needed.   Depends on the flag opt_global_cse.
151  * Graph may not be in phase_building.  Does not schedule control dead
152  * code.  Uses dominator information which it computes if the irg is not
153  * in state dom_consistent.  Destroys the out information as it moves nodes
154  * to other blocks.  Optimizes Tuples in Control edges.
155  * @todo This is not tested!
156  *
157  * Call remove_critical_cf_edges() before place_code().  This normalizes
158  * the control flow graph so that for all operations a basic block exists
159  * where they can be optimally placed.
160  *
161  * @todo A more powerful code placement would move operations past Phi nodes
162  * out of loops.
163  */
164 void place_code(ir_graph *irg);
165
166 /** Places an empty basic block on critical control flow edges thereby
167  * removing them.
168  *
169  * A critical control flow edge is an edge from a block with several
170  * control exits to a block with several control entries (See Muchnic
171  * p. 407).
172  * Is only executed if flag set_opt_critical_edges() is set.
173  *
174  * @param irg IR Graph
175  */
176 void remove_critical_cf_edges(ir_graph *irg);
177
178 # endif /* _IRGOPT_H_ */