implemented scc algorithm. Added datastructure to mark
[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
63 /* Inlines all small methods at call sites where the called address comes
64    from a Const node that references the entity representing the called
65    method.
66    The size argument is a rough measure for the code size of the method:
67    Methods where the obstack containing the firm graph is smaller than
68    size are inlined.  Further only a limited number of calls are inlined.
69    If the method contains more than 1024 inlineable calls none will be
70    inlined.
71    Inlining is only performed if flags `optimize' and `inlineing' are set.
72    The graph may not be in state phase_building.
73    It is recommended to call local_optimize_graph after inlining as this
74    function leaves a set of obscure Tuple nodes, e.g. a Proj-Tuple-Jmp
75    combination as control flow operation.  */
76 void inline_small_irgs(ir_graph *irg, int size);
77
78 /* Code Placement.  Pinns all floating nodes to a block where they
79    will be executed only if needed.   Depends on the flag opt_global_cse.
80    Graph may not be in phase_building.  Does not schedule control dead
81    code.  Uses dominator information which it computes if the irg is not
82    in state dom_consistent.  Destroys the out information as it moves nodes
83    to other blocks.  Optimizes Tuples in Control edges. (@@@ This
84    is not tested!)
85    @@@ A more powerful code placement would move operations past Phi nodes
86    out of loops.  Further the control flow should be normalized before
87    computing the dominator information so that there exists an optimal block
88    for all operations. */
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 /********************************************************************/
101 void optimize_cf(ir_graph *irg);
102
103
104 # endif /* _IRGOPT_H_ */