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
9 * Copyright: (c) 1998-2003 Universität Karlsruhe
10 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
16 * Optimizations for a whole ir graph, i.e., a procedure.
18 * @author Christian Schaefer, Goetz Lindenmaier
26 /** Applies local optimizations (see iropt.h) to all nodes in the graph. */
27 void local_optimize_graph (ir_graph *irg);
29 /** Performs dead node elimination by copying the ir graph to a new obstack.
31 Further removes Bad predecesors from Blocks and the corresponding
33 Optimization is only performed if options `optimize' and
34 `opt_dead_node_elimination' are set.
35 The graph may not be in state phase_building. The outs datasturcture
36 is freed, the outs state set to no_outs.
37 @todo Change this? -> inconsistent.
39 Backedge information is conserved.
40 Removes old attributes of nodes. Sets link field to NULL.
41 Attention: the numbers assigned to nodes if the library is compiled for
42 development/debugging are not conserved by copying. */
43 void dead_node_elimination(ir_graph *irg);
45 /** Removes Bad Bad predecesors from Blocks and the corresponding
46 inputs to Phi nodes as in dead_node_elimination but without
49 @todo not implemented! */
50 void remove_bad_predecessors(ir_graph *irg);
52 /** Inlines a method at the given call site.
54 Removes the call node and splits the basic block the call node
55 belongs to. Inserts a copy of the called graph between these nodes.
56 Assumes that call is a Call node in current_ir_graph and that
57 the type in the Call nodes type attribute is the same as the
58 type of the called graph.
59 Further it assumes that all Phi nodes in a block of current_ir_graph
60 are assembled in a "link" list in the link field of the corresponding
61 block nodes. Further assumes that all Proj nodes are in a "link" list
62 in the nodes producing the tuple. (This is only an optical feature
63 for the graph.) Conserves this feature for the old
64 nodes of the graph. This precondition can be established by a call to
65 collect_phisprojs(), see irgmod.h.
66 Called_graph must be unequal to current_ir_graph. Will not inline
68 Sets visited masterflag in current_ir_graph to the max of the flag in
69 current and called graph.
70 Assumes that both, the called and the calling graph are in state
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_method(ir_node *call, ir_graph *called_graph);
77 /** Inlines all small methods at call sites where the called address comes
78 from a Const node that references the entity representing the called
80 The size argument is a rough measure for the code size of the method:
81 Methods where the obstack containing the firm graph is smaller than
82 size are inlined. Further only a limited number of calls are inlined.
83 If the method contains more than 1024 inlineable calls none will be
85 Inlining is only performed if flags `optimize' and `inlineing' are set.
86 The graph may not be in state phase_building.
87 It is recommended to call local_optimize_graph after inlining as this
88 function leaves a set of obscure Tuple nodes, e.g. a Proj-Tuple-Jmp
89 combination as control flow operation. */
90 void inline_small_irgs(ir_graph *irg, int size);
92 /** Code Placement. Pinns all floating nodes to a block where they
93 will be executed only if needed. Depends on the flag opt_global_cse.
94 Graph may not be in phase_building. Does not schedule control dead
95 code. Uses dominator information which it computes if the irg is not
96 in state dom_consistent. Destroys the out information as it moves nodes
97 to other blocks. Optimizes Tuples in Control edges.
98 @todo This is not tested!
100 Call remove_critical_cf_edges() before place_code(). This normalizes
101 the control flow graph so that for all operations a basic block exists
102 where they can be optimally placed.
104 @todo A more powerful code placement would move operations past Phi nodes
106 void place_code(ir_graph *irg);
108 /** Control flow optimization.
109 * Removes empty blocks doing if simplifications and loop simplifications.
110 * A block is empty if it contains only a Jmp node and Phi nodes.
111 * Merges single entry single exit blocks with their predecessor
112 * and propagates dead control flow by calling equivalent_node.
113 * Independent of compiler flag it removes Tuples from cf edges,
114 * Bad predecessors form blocks and unnecessary predecessors of End.
116 * @bug So far destroys backedge information.
117 * @bug Chokes on Id nodes if called in a certain order with other
118 * optimizations. Call local_optimize_graph before to remove
121 void optimize_cf(ir_graph *irg);
124 /** Places an empty basic block on critical control flow edges thereby
126 A critical control flow edge is an edge from a block with several
127 control exits to a block with several control entries (See Muchnic
129 Is only executed if flag set_opt_critical_edges() is set.
132 void remove_critical_cf_edges(ir_graph *irg);
134 # endif /* _IRGOPT_H_ */