Converted documentation to doxygen.
[libfirm] / ir / ir / irgopt.h
1 /* Copyright (C) 1998 - 2001 by Universitaet Karlsruhe
2 * All rights reserved.
3 */
4
5 /**
6 * @file irgopt.h
7 *
8 * Optimizations for a whole ir graph, i.e., a procedure.
9 *
10 * @author Christian Schaefer, Goetz Lindenmaier
11 */
12
13 /* $Id$ */
14
15 # ifndef _IRGOPT_H_
16 # define _IRGOPT_H_
17
18 # include "irgraph.h"
19
20 /** Applies local optimizations (see iropt.h) to all nodes in the graph. */
21 void local_optimize_graph (ir_graph *irg);
22
23 /** Performs dead node elimination by copying the ir graph to a new obstack.
24
25    Further removes Bad predecesors from Blocks and the corresponding
26    inputs to Phi nodes.
27    Optimization is only performed if options `optimize' and
28    `opt_dead_node_elimination' are set.
29    The graph may not be in state phase_building.  The outs datasturcture
30    is freed, the outs state set to no_outs.
31    @todo Change this? -> inconsistent.
32
33    Backedge information is conserved.
34    Removes old attributes of nodes.  Sets link field to NULL.
35    Attention: the numbers assigned to nodes if the library is compiled for
36    development/debugging are not conserved by copying. */
37 void dead_node_elimination(ir_graph *irg);
38
39 /** Removes Bad Bad predecesors from Blocks and the corresponding
40    inputs to Phi nodes as in dead_node_elimination but without
41    copying the graph.
42
43    @todo not implemented! */
44 void remove_bad_predecessors(ir_graph *irg);
45
46 /** Inlines a method at the given call site.
47
48    Removes the call node and splits the basic block the call node
49    belongs to.  Inserts a copy of the called graph between these nodes.
50    Assumes that call is a Call node in current_ir_graph and that
51    the type in the Call nodes type attribute is the same as the
52    type of the called graph.
53    Further it assumes that all Phi nodes in a block of current_ir_graph
54    are assembled in a "link" list in the link field of the corresponding
55    block nodes.  Further assumes that all Proj nodes are in a "link" list
56    in the nodes producing the tuple.  (This is only an optical feature
57    for the graph.)  Conserves this feature for the old
58    nodes of the graph.  This precondition can be established by a call to
59    collect_phisprojs(), see irgmod.h.
60    Called_graph must be unequal to current_ir_graph.   Will not inline
61    if they are equal.
62    Sets visited masterflag in current_ir_graph to the max of the flag in
63    current and called graph.
64    Assumes that both, the called and the calling graph are in state
65    "pinned".
66    It is recommended to call local_optimize_graph after inlining as this
67    function leaves a set of obscure Tuple nodes, e.g. a Proj-Tuple-Jmp
68    combination as control flow operation. */
69 void inline_method(ir_node *call, ir_graph *called_graph);
70
71 /** Inlines all small methods at call sites where the called address comes
72    from a Const node that references the entity representing the called
73    method.
74    The size argument is a rough measure for the code size of the method:
75    Methods where the obstack containing the firm graph is smaller than
76    size are inlined.  Further only a limited number of calls are inlined.
77    If the method contains more than 1024 inlineable calls none will be
78    inlined.
79    Inlining is only performed if flags `optimize' and `inlineing' are set.
80    The graph may not be in state phase_building.
81    It is recommended to call local_optimize_graph after inlining as this
82    function leaves a set of obscure Tuple nodes, e.g. a Proj-Tuple-Jmp
83    combination as control flow operation.  */
84 void inline_small_irgs(ir_graph *irg, int size);
85
86 /** Code Placement.  Pinns all floating nodes to a block where they
87    will be executed only if needed.   Depends on the flag opt_global_cse.
88    Graph may not be in phase_building.  Does not schedule control dead
89    code.  Uses dominator information which it computes if the irg is not
90    in state dom_consistent.  Destroys the out information as it moves nodes
91    to other blocks.  Optimizes Tuples in Control edges.
92    @todo This is not tested!
93
94    Call remove_critical_cf_edges() before place_code().  This normalizes
95    the control flow graph so that for all operations a basic block exists
96    where they can be optimally placed.
97
98    @todo A more powerful code placement would move operations past Phi nodes
99    out of loops.  */
100 void place_code(ir_graph *irg);
101
102 /** Control flow optimization.
103  * Removes empty blocks doing if simplifications and loop simplifications.
104  * A block is empty if it contains only a Jmp node and Phi nodes.
105  * Merges single entry single exit blocks with their predecessor
106  * and propagates dead control flow by calling equivalent_node.
107  * Independent of compiler flag it removes Tuples from cf edges,
108  * Bad predecessors form blocks and unnecessary predecessors of End.
109  *
110  * @bug So far destroys backedge information.
111  * @bug Chokes on Id nodes if called in a certain order with other
112  *      optimizations.  Call local_optimize_graph before to remove
113  *      Ids.
114  */
115 void optimize_cf(ir_graph *irg);
116
117
118 /** Places an empty basic block on critical control flow edges thereby
119    removing them.
120    A critical control flow edge is an edge from a block with several
121    control exits to a block with several control entries (See Muchnic
122    p. 407).
123    Is only executed if flag set_opt_critical_edges() is set.
124    @param irg IR Graph
125 */
126 void remove_critical_cf_edges(ir_graph *irg);
127
128 # endif /* _IRGOPT_H_ */