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