3 * File name: ir/opt/opt_osr.h
4 * Purpose: Operator Strength Reduction,
5 * Keith D. Cooper, L. Taylor Simpson, Christopher A. Vick
10 * Copyright: (c) 2006 Universität Karlsruhe
11 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
16 #include "firm_types.h"
18 /** Possible flags for the Operator Scalar Replacement. */
19 typedef enum osr_flags {
20 osr_flag_none = 0, /**< no additional flags */
21 osr_flag_lftr_with_ov_check = 1, /**< do linear function test replacement
22 only if no overflow can occur. */
23 osr_flag_ignore_x86_shift = 2 /**< ignore Multiplications by 2, 4, 8 */
26 /* FirmJNI cannot handle identical enum values... */
28 /** default setting */
29 #define osr_flag_default osr_flag_lftr_with_ov_check
32 * Do the Operator Scalar Replacement optimization and linear
33 * function test replacement for loop control.
34 * Can be switched off using the set_opt_strength_red() flag.
35 * In that case, only remove_phi_cycles() is executed.
37 * @param irg the graph which should be optimized
38 * @param flags set of osr_flags
40 * The linear function replacement test is controlled by the flags.
41 * If the osr_flag_lftr_with_ov_check is set, the replacement is only
42 * done if do overflow can occur.
43 * Otherwise it is ALWAYS done which might be insecure.
47 * for (i = 0; i < 100; ++i)
49 * might be replaced by
51 * for (i = 0; i < 400; i += 4)
55 * for (i = 0; i < 0x7FFFFFFF; ++i)
57 * will not be replaced by
59 * for (i = 0; i < 0xFFFFFFFC; i += 4)
61 * because of overflow.
65 * for (i = 0; i <= 0xF; ++i)
67 * will NOT be transformed into
69 * for (i = 0xFFFFFFF0; i <= 0xFFFFFFFF; ++i)
71 * although here is no direct overflow. The OV occurs when the ++i
72 * is executed (and would created an endless loop here!).
74 * For the same reason, a loop
76 * for (i = 0; i <= 9; i += x)
78 * will NOT be transformed because we cannot estimate whether an overflow
79 * might happen adding x.
81 * Note that i < a + 400 is also not possible with the current implementation
82 * although this might be allowed by other compilers...
84 * Note further that tests for equality can be handled some simpler (but are not
87 * This algorithm destroys the link field of nodes.
89 void opt_osr(ir_graph *irg, unsigned flags);
92 * Removes useless Phi cycles, i.e cycles of Phi nodes with only one
94 * This is automatically done in opt_osr(), so there is no need to call it
97 * @param irg the graph which should be optimized
99 * This algorithm destroys the link field of nodes.
101 void remove_phi_cycles(ir_graph *irg);
103 #endif /* _OPT_OSR_H_ */