irop: Constify get_op_ops().
[libfirm] / include / libfirm / iroptimize.h
1 /*
2  * This file is part of libFirm.
3  * Copyright (C) 2012 University of Karlsruhe.
4  */
5
6 /**
7  * @file
8  * @brief   Available Optimisations of libFirm.
9  */
10 #ifndef FIRM_IROPTIMIZE_H
11 #define FIRM_IROPTIMIZE_H
12
13 #include "firm_types.h"
14 #include "nodeops.h"
15 #include "begin.h"
16
17 /**
18  * @defgroup iroptimize  Transformations and Optimisations
19  * @{
20  */
21
22 /**
23  * Control flow optimization.
24  *
25  * Removes empty blocks doing if simplifications and loop simplifications.
26  * A block is empty if it contains only a Jmp node and Phi nodes.
27  * Merges single entry single exit blocks with their predecessor
28  * and propagates dead control flow by calling equivalent_node().
29  * Independent of compiler flag it removes Tuples from cf edges,
30  * Bad predecessors from Blocks and Phis, and unnecessary predecessors of End.
31  * Destroys backedge information.
32  */
33 FIRM_API void optimize_cf(ir_graph *irg);
34
35 /**
36  * Creates an ir_graph pass for optimize_cf().
37  *
38  * @param name     the name of this pass or NULL
39  *
40  * @return  the newly created ir_graph pass
41  */
42 FIRM_API ir_graph_pass_t *optimize_cf_pass(const char *name);
43
44 /**
45  * Perform path-sensitive jump threading on the given graph.
46  *
47  * @param irg  the graph
48  */
49 FIRM_API void opt_jumpthreading(ir_graph* irg);
50
51 /**
52  * Creates an ir_graph pass for opt_jumpthreading().
53  *
54  * @param name     the name of this pass or NULL
55  *
56  * @return  the newly created ir_graph pass
57  */
58 FIRM_API ir_graph_pass_t *opt_jumpthreading_pass(const char *name);
59
60 /**
61  * Simplifies boolean expression in the given ir graph.
62  * eg. x < 5 && x < 6 becomes x < 5
63  *
64  * @param irg  the graph
65  */
66 FIRM_API void opt_bool(ir_graph *irg);
67
68 /**
69  * Creates an ir_graph pass for opt_bool().
70  *
71  * @param name     the name of this pass or NULL
72  *
73  * @return  the newly created ir_graph pass
74  */
75 FIRM_API ir_graph_pass_t *opt_bool_pass(const char *name);
76
77 /**
78  * Reduces the number of Conv nodes in the given ir graph.
79  *
80  * @param irg  the graph
81  */
82 FIRM_API void conv_opt(ir_graph *irg);
83
84 /**
85  * Creates an ir_graph pass for conv_opt().
86  *
87  * @param name     the name of this pass or NULL
88  *
89  * @return  the newly created ir_graph pass
90  */
91 FIRM_API ir_graph_pass_t *conv_opt_pass(const char *name);
92
93 /**
94  * A callback that checks whether a entity is an allocation
95  * routine.
96  */
97 typedef int (*check_alloc_entity_func)(ir_entity *ent);
98
99 /**
100  * Performs simple and fast escape analysis for one graph.
101  *
102  * @param irg       the graph
103  * @param callback  a callback function to check whether a
104  *                  given entity is a allocation call
105  */
106 FIRM_API void escape_enalysis_irg(ir_graph *irg,
107                                   check_alloc_entity_func callback);
108
109 /**
110  * Performs simple and fast escape analysis for all graphs.
111  *
112  * This optimization implements a simple and fast but inexact
113  * escape analysis. Some addresses might be marked as 'escaped' even
114  * if they are not.
115  * The advantage is a low memory footprint and fast speed.
116  *
117  * @param run_scalar_replace  if this flag in non-zero, scalar
118  *                            replacement optimization is run on graphs with removed
119  *                            allocation
120  * @param callback            a callback function to check whether a
121  *                            given entity is a allocation call
122  *
123  * This optimization removes allocation which are not used (rare) and replace
124  * allocation that can be proved dead at the end of the graph which stack variables.
125  *
126  * The creation of stack variable allows scalar replacement to be run only
127  * on those graphs that have been changed.
128  *
129  * This is most effective on Java where no other stack variables exists.
130  */
131 FIRM_API void escape_analysis(int run_scalar_replace,
132                               check_alloc_entity_func callback);
133
134 /**
135  * Optimize function calls by handling const functions.
136  *
137  * This optimization first detects all "const functions", i.e.,
138  * IR graphs that neither read nor write memory (and hence did
139  * not create exceptions, as these use memory in Firm).
140  *
141  * The result of calls to such functions depends only on its
142  * arguments, hence those calls are no more pinned.
143  *
144  * This is a rather strong criteria, so do not expect that a
145  * lot of functions will be found. Moreover, all of them might
146  * already be inlined if inlining is activated.
147  * Anyway, it might be good for handling builtin's
148  * even if the later read/write memory (but we know how).
149  *
150  * This optimizations read the irg_const_function property of
151  * entities and and sets the irg_const_function property of
152  * graphs.
153  *
154  * If callee information is valid, we also optimize polymorphic Calls.
155  */
156 FIRM_API void optimize_funccalls(void);
157
158 /**
159  * Creates an ir_prog pass for optimize_funccalls().
160  *
161  * @param name       the name of this pass or NULL
162  * @return  the newly created ir_prog pass
163  */
164 FIRM_API ir_prog_pass_t *optimize_funccalls_pass(const char *name);
165
166 /**
167  * Does Partial Redundancy Elimination combined with
168  * Global Value Numbering.
169  * Can be used to replace place_code() completely.
170  *
171  * Based on VanDrunen and Hosking 2004.
172  *
173  * @param irg  the graph
174  */
175 FIRM_API void do_gvn_pre(ir_graph *irg);
176
177 /**
178  * Creates an ir_graph pass for do_gvn_pre().
179  *
180  * @param name     the name of this pass or NULL
181  *
182  * @return  the newly created ir_graph pass
183  */
184 FIRM_API ir_graph_pass_t *do_gvn_pre_pass(const char *name);
185
186 /**
187  * This function is called to evaluate, if a
188  * mux(@p sel, @p mux_false, @p mux_true) should be built for the current
189  * architecture.
190  * If it returns non-zero, a mux is created, else the code
191  * is not modified.
192  * @param sel        A selector of a Cond.
193  * @param phi_list   phi node to be converted
194  * @param i          First data predecessor involved in if conversion
195  * @param j          Second data predecessor involved in if conversion
196  */
197 typedef int (*arch_allow_ifconv_func)(ir_node *sel, ir_node *mux_false,
198                                       ir_node *mux_true);
199
200 /**
201  * Perform If conversion on a graph.
202  *
203  * @param irg The graph.
204  *
205  * Cannot handle blocks with Bad control predecessors, so call it after control
206  * flow optimization.
207  */
208 FIRM_API void opt_if_conv(ir_graph *irg);
209
210 /**
211  * Creates an ir_graph pass for opt_if_conv().
212  *
213  * @param name     the name of this pass or NULL
214  *
215  * @return  the newly created ir_graph pass
216  */
217 FIRM_API ir_graph_pass_t *opt_if_conv_pass(const char *name);
218
219 /**
220  * Tries to reduce dependencies for memory nodes where possible by parallelizing
221  * them and synchronizing with Sync nodes
222  * @param irg   the graph where memory operations should be parallelized
223  */
224 FIRM_API void opt_parallelize_mem(ir_graph *irg);
225
226 /**
227  * Creates an ir_graph pass for opt_sync().
228  *
229  * @param name     the name of this pass or NULL
230  *
231  * @return  the newly created ir_graph pass
232  */
233 FIRM_API ir_graph_pass_t *opt_parallelize_mem_pass(const char *name);
234
235 /**
236  * Check if we can replace the load by a given const from
237  * the const code irg.
238  *
239  * @param load   the load to replace
240  * @param c      the constant
241  *
242  * @return if the modes match or can be transformed using a reinterpret cast
243  *         returns a copy of the constant (possibly Conv'ed) in the graph where
244  *         the load is.
245  */
246 FIRM_API ir_node *can_replace_load_by_const(const ir_node *load, ir_node *c);
247
248 /**
249  * Load/Store optimization.
250  *
251  * Removes redundant non-volatile Loads and Stores.
252  * May introduce Bad nodes if exceptional control flow
253  * is removed. The following cases are optimized:
254  *
255  * Load without result: A Load which has only a memory use
256  *   is removed.
257  *
258  * Load after Store: A Load after a Store is removed, if
259  *   the Load doesn't have an exception handler OR is in
260  *   the same block as the Store.
261  *
262  * Load after Load: A Load after a Load is removed, if the
263  *   Load doesn't have an exception handler OR is in the
264  *   same block as the previous Load.
265  *
266  * Store before Store: A Store immediately before another
267  *   Store in the same block is removed, if the Store doesn't
268  *   have an exception handler.
269  *
270  * Store after Load: A Store after a Load is removed, if the
271  *   Store doesn't have an exception handler.
272  */
273 FIRM_API void optimize_load_store(ir_graph *irg);
274
275 /**
276  * Creates an ir_graph pass for optimize_load_store().
277  *
278  * @param name     the name of this pass or NULL
279  *
280  * @return  the newly created ir_graph pass
281  */
282 FIRM_API ir_graph_pass_t *optimize_load_store_pass(const char *name);
283
284 /**
285  * New experimental alternative to optimize_load_store.
286  * Based on a dataflow analysis, so load/stores are moved out of loops
287  * where possible
288  */
289 FIRM_API void opt_ldst(ir_graph *irg);
290
291 /**
292  * Creates an ir_graph pass for opt_ldst().
293  *
294  * @param name     the name of this pass or NULL
295  *
296  * @return  the newly created ir_graph pass
297  */
298 FIRM_API ir_graph_pass_t *opt_ldst_pass(const char *name);
299
300 /**
301  * Optimize loops by peeling or unrolling them if beneficial.
302  *
303  * @param irg  The graph whose loops will be processed
304  *
305  * This function did not change the graph, only its frame type.
306  * The layout state of the frame type will be set to layout_undefined
307  * if entities were removed.
308  */
309 FIRM_API void loop_optimization(ir_graph *irg);
310
311 /**
312  * Optimize the frame type of an irg by removing
313  * never touched entities.
314  *
315  * @param irg  The graph whose frame type will be optimized
316  *
317  * This function did not change the graph, only its frame type.
318  * The layout state of the frame type will be set to layout_undefined
319  * if entities were removed.
320  */
321 FIRM_API void opt_frame_irg(ir_graph *irg);
322
323 /**
324  * Creates an ir_graph pass for opt_frame_irg().
325  *
326  * @param name     the name of this pass or NULL
327  *
328  * @return  the newly created ir_graph pass
329  */
330 FIRM_API ir_graph_pass_t *opt_frame_irg_pass(const char *name);
331
332 /** Possible flags for the Operator Scalar Replacement. */
333 typedef enum osr_flags {
334         osr_flag_none               = 0,  /**< no additional flags */
335         osr_flag_lftr_with_ov_check = 1,  /**< do linear function test replacement
336                                                only if no overflow can occur. */
337         osr_flag_ignore_x86_shift   = 2,  /**< ignore Multiplications by 2, 4, 8 */
338         osr_flag_keep_reg_pressure  = 4   /**< do NOT increase register pressure by introducing new
339                                                induction variables. */
340 } osr_flags;
341
342 /** default setting */
343 #define osr_flag_default osr_flag_lftr_with_ov_check
344
345 /**
346  * Performs the Operator Scalar Replacement optimization and linear
347  * function test replacement for loop control.
348  * Can be switched off using the set_opt_strength_red() flag.
349  * In that case, only remove_phi_cycles() is executed.
350  *
351  * @param irg    the graph which should be optimized
352  * @param flags  set of osr_flags
353  *
354  * The linear function replacement test is controlled by the flags.
355  * If the osr_flag_lftr_with_ov_check is set, the replacement is only
356  * done if do overflow can occur.
357  * Otherwise it is ALWAYS done which might be insecure.
358  *
359  * For instance:
360  *
361  * for (i = 0; i < 100; ++i)
362  *
363  * might be replaced by
364  *
365  * for (i = 0; i < 400; i += 4)
366  *
367  * But
368  *
369  * for (i = 0; i < 0x7FFFFFFF; ++i)
370  *
371  * will not be replaced by
372  *
373  * for (i = 0; i < 0xFFFFFFFC; i += 4)
374  *
375  * because of overflow.
376  *
377  * More bad cases:
378  *
379  * for (i = 0; i <= 0xF; ++i)
380  *
381  * will NOT be transformed into
382  *
383  * for (i = 0xFFFFFFF0; i <= 0xFFFFFFFF; ++i)
384  *
385  * although here is no direct overflow. The OV occurs when the ++i
386  * is executed (and would created an endless loop here!).
387  *
388  * For the same reason, a loop
389  *
390  * for (i = 0; i <= 9; i += x)
391  *
392  * will NOT be transformed because we cannot estimate whether an overflow
393  * might happen adding x.
394  *
395  * Note that i < a + 400 is also not possible with the current implementation
396  * although this might be allowed by other compilers...
397  *
398  * Note further that tests for equality can be handled some simpler (but are not
399  * implemented yet).
400  *
401  * This algorithm destroys the link field of nodes.
402  */
403 FIRM_API void opt_osr(ir_graph *irg, unsigned flags);
404
405 /**
406  * Creates an ir_graph pass for remove_phi_cycles().
407  *
408  * @param name     the name of this pass or NULL
409  * @param flags    set of osr_flags
410  *
411  * @return  the newly created ir_graph pass
412  */
413 FIRM_API ir_graph_pass_t *opt_osr_pass(const char *name, unsigned flags);
414
415 /**
416  * Removes useless Phi cycles, i.e cycles of Phi nodes with only one
417  * non-Phi node.
418  * This is automatically done in opt_osr(), so there is no need to call it
419  * additionally.
420  *
421  * @param irg    the graph which should be optimized
422  *
423  * This algorithm destroys the link field of nodes.
424  */
425 FIRM_API void remove_phi_cycles(ir_graph *irg);
426
427 /**
428  * Creates an ir_graph pass for remove_phi_cycles().
429  *
430  * @param name     the name of this pass or NULL
431  *
432  * @return  the newly created ir_graph pass
433  */
434 FIRM_API ir_graph_pass_t *remove_phi_cycles_pass(const char *name);
435
436
437 /** A default threshold. */
438 #define DEFAULT_CLONE_THRESHOLD 20
439
440 /**
441  * Performs procedure cloning. Evaluate a heuristic weight for every
442  * Call(..., Const, ...). If the weight is bigger than threshold,
443  * clone the entity and fix the calls.
444  *
445  * @param threshold   the threshold for cloning
446  *
447  * The threshold is an estimation of how many instructions are saved
448  * when executing a cloned method. If threshold is 0.0, every possible
449  * call is cloned.
450  */
451 FIRM_API void proc_cloning(float threshold);
452
453 /**
454  * Creates an ir_prog pass for proc_cloning().
455  *
456  * @param name        the name of this pass or NULL
457  * @param threshold   the threshold for cloning
458  *
459  * @return  the newly created ir_prog pass
460  */
461 FIRM_API ir_prog_pass_t *proc_cloning_pass(const char *name, float threshold);
462
463 /**
464  * Reassociation.
465  *
466  * Applies Reassociation rules to integer expressions.
467  * Beware: Works only if integer overflow might be ignored, as for C, Java
468  * and for address expression.
469  * Works only if Constant folding is activated.
470  *
471  * Uses loop information to detect loop-invariant (i.e. contant
472  * inside the loop) values.
473  *
474  * See Muchnik 12.3.1 Algebraic Simplification and Reassociation of
475  * Addressing Expressions.
476  */
477 FIRM_API void optimize_reassociation(ir_graph *irg);
478
479 /**
480  * Creates an ir_graph pass for optimize_reassociation().
481  *
482  * @param name     the name of this pass or NULL
483  *
484  * @return  the newly created ir_graph pass
485  */
486 FIRM_API ir_graph_pass_t *optimize_reassociation_pass(const char *name);
487
488 /**
489  * Normalize the Returns of a graph by creating a new End block
490  * with One Return(Phi).
491  * This is the preferred input for the if-conversion.
492  *
493  * In pseudocode, it means:
494  *
495  * if (a)
496  *   return b;
497  * else
498  *   return c;
499  *
500  * is transformed into
501  *
502  * if (a)
503  *   res = b;
504  * else
505  *   res = c;
506  * return res;
507  */
508 FIRM_API void normalize_one_return(ir_graph *irg);
509
510 /**
511  * Creates an ir_graph pass for normalize_one_return().
512  *
513  * @param name     the name of this pass or NULL
514  *
515  * @return  the newly created ir_graph pass
516  */
517 FIRM_API ir_graph_pass_t *normalize_one_return_pass(const char *name);
518
519 /**
520  * Normalize the Returns of a graph by moving
521  * the Returns upwards as much as possible.
522  * This might be preferred for code generation.
523  *
524  * In pseudocode, it means:
525  *
526  * if (a)
527  *   res = b;
528  * else
529  *   res = c;
530  * return res;
531  *
532  * is transformed into
533  *
534  * if (a)
535  *   return b;
536  * else
537  *   return c;
538  */
539 FIRM_API void normalize_n_returns(ir_graph *irg);
540
541 /**
542  * Creates an ir_graph pass for normalize_n_returns().
543  *
544  * @param name     the name of this pass or NULL
545  *
546  * @return  the newly created ir_graph pass
547  */
548 FIRM_API ir_graph_pass_t *normalize_n_returns_pass(const char *name);
549
550 /**
551  * Performs the scalar replacement optimization.
552  * Replaces local compound entities (like structures and arrays)
553  * with atomic values if possible. Does not handle classes yet.
554  *
555  * @param irg  the graph which should be optimized
556  */
557 FIRM_API void scalar_replacement_opt(ir_graph *irg);
558
559 /**
560  * Creates an ir_graph pass for scalar_replacement_opt().
561  *
562  * @param name     the name of this pass or NULL
563  *
564  * @return  the newly created ir_graph pass
565  */
566 FIRM_API ir_graph_pass_t *scalar_replacement_opt_pass(const char *name);
567
568 /**
569  * Optimizes tail-recursion calls by converting them into loops.
570  * Depends on the flag opt_tail_recursion.
571  * Currently supports the following forms:
572  *  - return func();
573  *  - return x + func();
574  *  - return func() - x;
575  *  - return x * func();
576  *  - return -func();
577  *
578  * Does not work for Calls that use the exception stuff.
579  *
580  * @param irg   the graph to be optimized
581  */
582 FIRM_API void opt_tail_rec_irg(ir_graph *irg);
583
584 /**
585  * Creates an ir_graph pass for opt_tail_rec_irg().
586  *
587  * @param name     the name of this pass or NULL
588  *
589  * @return  the newly created ir_graph pass
590  */
591 FIRM_API ir_graph_pass_t *opt_tail_rec_irg_pass(const char *name);
592
593 /**
594  * Optimize tail-recursion calls for all IR-Graphs.
595  * Can currently handle:
596  * - direct return value, i.e. return func().
597  * - additive return value, i.e. return x +/- func()
598  * - multiplicative return value, i.e. return x * func() or return -func()
599  *
600  * The current implementation must be run before optimize_funccalls(),
601  * because it expects the memory edges pointing to calls, which might be
602  * removed by optimize_funccalls().
603  */
604 FIRM_API void opt_tail_recursion(void);
605
606 /**
607  * Creates an ir_prog pass for opt_tail_recursion().
608  *
609  * @param name     the name of this pass or NULL
610  *
611  * @return  the newly created ir_prog pass
612  */
613 FIRM_API ir_prog_pass_t *opt_tail_recursion_pass(const char *name);
614
615 /**
616  * CLiff Click's combo algorithm from
617  *   "Combining Analyses, combining Optimizations".
618  *
619  * Does conditional constant propagation, unreachable code elimination and
620  * optimistic global value numbering at once.
621  *
622  * @param irg  the graph to run on
623  */
624 FIRM_API void combo(ir_graph *irg);
625
626 /**
627  * Creates an ir_graph pass for combo.
628  *
629  * @param name     the name of this pass or NULL
630  *
631  * @return  the newly created ir_graph pass
632  */
633 FIRM_API ir_graph_pass_t *combo_pass(const char *name);
634
635 /** pointer to an optimization function */
636 typedef void (*opt_ptr)(ir_graph *irg);
637
638 /**
639  * Heuristic inliner. Calculates a benefice value for every call and inlines
640  * those calls with a value higher than the threshold.
641  *
642  * @param maxsize             Do not inline any calls if a method has more than
643  *                            maxsize firm nodes.  It may reach this limit by
644  *                            inlining.
645  * @param inline_threshold    inlining threshold
646  * @param after_inline_opt    optimizations performed immediately after inlining
647  *                            some calls
648  */
649 FIRM_API void inline_functions(unsigned maxsize, int inline_threshold,
650                                opt_ptr after_inline_opt);
651
652 /**
653  * Creates an ir_prog pass for inline_functions().
654  *
655  * @param name               the name of this pass or NULL
656  * @param maxsize            Do not inline any calls if a method has more than
657  *                           maxsize firm nodes.  It may reach this limit by
658  *                           inlineing.
659  * @param inline_threshold   inlining threshold
660  * @param after_inline_opt   a function that is called after inlining a
661  *                           procedure. You should run fast local optimisations
662  *                           here which cleanup the graph before further
663  *                           inlining
664  *
665  * @return  the newly created ir_prog pass
666  */
667 FIRM_API ir_prog_pass_t *inline_functions_pass(const char *name,
668                 unsigned maxsize, int inline_threshold, opt_ptr after_inline_opt);
669
670 /**
671  * Combines congruent blocks into one.
672  *
673  * @param irg   The IR-graph to optimize.
674  */
675 FIRM_API void shape_blocks(ir_graph *irg);
676
677 /**
678  * Creates an ir_graph pass for shape_blocks().
679  *
680  * @param name   the name of this pass or NULL
681  *
682  * @return  the newly created ir_graph pass
683  */
684 FIRM_API ir_graph_pass_t *shape_blocks_pass(const char *name);
685
686 /**
687  * Perform loop inversion on a given graph.
688  * Loop inversion transforms a head controlled loop (like while(...) {} and
689  * for(...) {}) into a foot controlled loop (do {} while(...)).
690  */
691 FIRM_API void do_loop_inversion(ir_graph *irg);
692
693 /**
694  * Perform loop unrolling on a given graph.
695  * Loop unrolling multiplies the number loop completely by a number found
696  * through a heuristic.
697  */
698 FIRM_API void do_loop_unrolling(ir_graph *irg);
699
700 /**
701  * Perform loop peeling on a given graph.
702  */
703 FIRM_API void do_loop_peeling(ir_graph *irg);
704
705 /**
706  * Creates an ir_graph pass for loop inversion.
707  *
708  * @param name     the name of this pass or NULL
709  *
710  * @return  the newly created ir_graph pass
711  */
712 FIRM_API ir_graph_pass_t *loop_inversion_pass(const char *name);
713
714 /**
715  * Creates an ir_graph pass for loop unrolling.
716  *
717  * @param name     the name of this pass or NULL
718  *
719  * @return  the newly created ir_graph pass
720  */
721 FIRM_API ir_graph_pass_t *loop_unroll_pass(const char *name);
722
723 /**
724  * Creates an ir_graph pass for loop peeling.
725  *
726  * @param name     the name of this pass or NULL
727  *
728  * @return  the newly created ir_graph pass
729  */
730 FIRM_API ir_graph_pass_t *loop_peeling_pass(const char *name);
731
732 /**
733  * Creates an ir_graph pass for set_vrp_data()
734  *
735  * @param name The name of this pass or NULL
736  *
737  * @return the newly created ir_graph pass
738  */
739 FIRM_API ir_graph_pass_t *set_vrp_pass(const char *name);
740
741 /**
742  * Removes all entities which are unused.
743  *
744  * Unused entities have ir_visibility_local and are not used directly or
745  * indirectly through entities/code visible outside the compilation unit.
746  * This is usually conservative than gc_irgs, but does not respect properties
747  * of object-oriented programs.
748  */
749 FIRM_API void garbage_collect_entities(void);
750
751 /** Pass for garbage_collect_entities */
752 FIRM_API ir_prog_pass_t *garbage_collect_entities_pass(const char *name);
753
754 /**
755  * Performs dead node elimination by copying the ir graph to a new obstack.
756  *
757  *  The major intention of this pass is to free memory occupied by
758  *  dead nodes and outdated analyzes information.  Further this
759  *  function removes Bad predecessors from Blocks and the corresponding
760  *  inputs to Phi nodes.  This opens optimization potential for other
761  *  optimizations.  Further this phase reduces dead Block<->Jmp
762  *  self-cycles to Bad nodes.
763  *
764  *  Dead_node_elimination is only performed if options `optimize' and
765  *  `opt_dead_node_elimination' are set.  The graph may
766  *  not be in state phase_building.  The outs datastructure is freed,
767  *  the outs state set to outs_none.  Backedge information is conserved.
768  *  Removes old attributes of nodes.  Sets link field to NULL.
769  *  Callee information must be freed (irg_callee_info_none).
770  *
771  * @param irg  The graph to be optimized.
772  */
773 FIRM_API void dead_node_elimination(ir_graph *irg);
774
775 /**
776  * Creates an ir_graph pass for dead_node_elimination().
777  *
778  * @param name     the name of this pass or NULL
779  *
780  * @return  the newly created ir_graph pass
781  */
782 FIRM_API ir_graph_pass_t *dead_node_elimination_pass(const char *name);
783
784 /**
785  * Inlines a method at the given call site.
786  *
787  *  Removes the call node and splits the basic block the call node
788  *  belongs to.  Inserts a copy of the called graph between these nodes.
789  *  Assumes that call is a Call node in current_ir_graph and that
790  *  the type in the Call nodes type attribute is the same as the
791  *  type of the called graph.
792  *  Further it assumes that all Phi nodes in a block of current_ir_graph
793  *  are assembled in a "link" list in the link field of the corresponding
794  *  block nodes.  Further assumes that all Proj nodes are in a "link" list
795  *  in the nodes producing the tuple.  (This is only an optical feature
796  *  for the graph.)  Conserves this feature for the old
797  *  nodes of the graph.  This precondition can be established by a call to
798  *  collect_phisprojs(), see irgmod.h.
799  *  As dead_node_elimination this function reduces dead Block<->Jmp
800  *  self-cycles to Bad nodes.
801  *
802  *  Called_graph must be unequal to current_ir_graph.   Will not inline
803  *  if they are equal.
804  *  Sets visited masterflag in current_ir_graph to the max of the flag in
805  *  current and called graph.
806  *  Assumes that both, the called and the calling graph are in state
807  *  "op_pin_state_pinned".
808  *  It is recommended to call local_optimize_graph() after inlining as this
809  *  function leaves a set of obscure Tuple nodes, e.g. a Proj-Tuple-Jmp
810  *  combination as control flow operation.
811  *
812  *  @param call          the call node that should be inlined
813  *  @param called_graph  the IR-graph that is called at call
814  *
815  *  @return zero if method could not be inlined (recursion for instance),
816  *          non-zero if all went ok
817  */
818 FIRM_API int inline_method(ir_node *call, ir_graph *called_graph);
819
820 /**
821  * Code Placement.
822  *
823  * Pins all floating nodes to a block where they
824  * will be executed only if needed.   Depends on the flag opt_global_cse.
825  * Graph may not be in phase_building.  Does not schedule control dead
826  * code.  Uses dominator information which it computes if the irg is not
827  * in state dom_consistent.  Destroys the out information as it moves nodes
828  * to other blocks.  Optimizes Tuples in Control edges.
829  *
830  * Call remove_critical_cf_edges() before place_code().  This normalizes
831  * the control flow graph so that for all operations a basic block exists
832  * where they can be optimally placed.
833  */
834 FIRM_API void place_code(ir_graph *irg);
835
836 /**
837  * Creates an ir_graph pass for place_code().
838  * This pass enables GCSE, runs optimize_graph_df() and finally
839  * place_code();
840  *
841  * @param name     the name of this pass or NULL
842  *
843  * @return  the newly created ir_graph pass
844  */
845 FIRM_API ir_graph_pass_t *place_code_pass(const char *name);
846
847 /**
848  * Determines information about the values of nodes and perform simplifications
849  * using this information.  This optimization performs a data-flow analysis to
850  * find the minimal fixpoint.
851  */
852 FIRM_API void fixpoint_vrp(ir_graph*);
853
854 /**
855  * Creates an ir_graph pass for fixpoint_vrp().
856  * This pass dDetermines information about the values of nodes
857  * and perform simplifications using this information.
858  * This optimization performs a data-flow analysis to
859  * find the minimal fixpoint.
860  *
861  * @param name     the name of this pass or NULL
862  *
863  * @return  the newly created ir_graph pass
864  */
865 FIRM_API ir_graph_pass_t *fixpoint_vrp_irg_pass(const char *name);
866
867 /**
868  * Checks if the value of a node is != 0.
869  *
870  * This is a often needed case, so we handle here Confirm
871  * nodes too.
872  *
873  * @param n        a node representing the value
874  * @param confirm  if n is confirmed to be != 0, returns
875  *                 the the Confirm-node, else NULL
876  */
877 FIRM_API int value_not_zero(const ir_node *n, const ir_node **confirm);
878
879 /**
880  * Checks if the value of a node cannot represent a NULL pointer.
881  *
882  * - If option sel_based_null_check_elim is enabled, all
883  *   Sel nodes can be skipped.
884  * - A SymConst(entity) is NEVER a NULL pointer
885  * - A Const != NULL is NEVER a NULL pointer
886  * - Confirms are evaluated
887  *
888  * @param n        a node representing the value
889  * @param confirm  if n is confirmed to be != NULL, returns
890  *                 the the Confirm-node, else NULL
891  */
892 FIRM_API int value_not_null(const ir_node *n, const ir_node **confirm);
893
894 /**
895  * Checks if the value of a node can be confirmed >= 0 or <= 0,
896  * If the mode of the value did not honor signed zeros, else
897  * check for >= 0 or < 0.
898  *
899  * @param n  a node representing the value
900  */
901 FIRM_API ir_value_classify_sign classify_value_sign(ir_node *n);
902
903 /**
904  * Returns the value of a Cmp if one or both predecessors are Confirm nodes.
905  *
906  * @param cmp       the compare node that will be evaluated
907  * @param left      the left operand of the Cmp
908  * @param right     the right operand of the Cmp
909  * @param relation  the compare relation
910  */
911 FIRM_API ir_tarval *computed_value_Cmp_Confirm(
912         const ir_node *cmp, ir_node *left, ir_node *right, ir_relation relation);
913
914 /** Type of callbacks for creating entities of the compiler library */
915 typedef ir_entity *(*compilerlib_entity_creator_t)(ident *id, ir_type *mt);
916
917 /**
918  * Sets the compilerlib entity creation callback that is used to create
919  * compilerlib function entities.
920  *
921  * @param cb  the new compilerlib entity creation callback
922  */
923 FIRM_API void set_compilerlib_entity_creator(compilerlib_entity_creator_t cb);
924
925 /** Returns the compilerlib entity creation callback. */
926 FIRM_API compilerlib_entity_creator_t get_compilerlib_entity_creator(void);
927
928 /**
929  * Constructs the entity for a given function using the current compilerlib
930  * entity creation callback.
931  *
932  * @param id  the identifier of the compilerlib function
933  * @param mt  the method type of the compilerlib function
934  */
935 FIRM_API ir_entity *create_compilerlib_entity(ident *id, ir_type *mt);
936
937 /** @} */
938
939 #include "end.h"
940
941 #endif