2 * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * File name: ir/opt/opt_osr.h
23 * Purpose: Operator Strength Reduction,
24 * Keith D. Cooper, L. Taylor Simpson, Christopher A. Vick
25 * Author: Michael Beck
29 * Copyright: (c) 2006 Universität Karlsruhe
34 #include "firm_types.h"
36 /** Possible flags for the Operator Scalar Replacement. */
37 typedef enum osr_flags {
38 osr_flag_none = 0, /**< no additional flags */
39 osr_flag_lftr_with_ov_check = 1, /**< do linear function test replacement
40 only if no overflow can occur. */
41 osr_flag_ignore_x86_shift = 2 /**< ignore Multiplications by 2, 4, 8 */
44 /* FirmJNI cannot handle identical enum values... */
46 /** default setting */
47 #define osr_flag_default osr_flag_lftr_with_ov_check
50 * Do the Operator Scalar Replacement optimization and linear
51 * function test replacement for loop control.
52 * Can be switched off using the set_opt_strength_red() flag.
53 * In that case, only remove_phi_cycles() is executed.
55 * @param irg the graph which should be optimized
56 * @param flags set of osr_flags
58 * The linear function replacement test is controlled by the flags.
59 * If the osr_flag_lftr_with_ov_check is set, the replacement is only
60 * done if do overflow can occur.
61 * Otherwise it is ALWAYS done which might be insecure.
65 * for (i = 0; i < 100; ++i)
67 * might be replaced by
69 * for (i = 0; i < 400; i += 4)
73 * for (i = 0; i < 0x7FFFFFFF; ++i)
75 * will not be replaced by
77 * for (i = 0; i < 0xFFFFFFFC; i += 4)
79 * because of overflow.
83 * for (i = 0; i <= 0xF; ++i)
85 * will NOT be transformed into
87 * for (i = 0xFFFFFFF0; i <= 0xFFFFFFFF; ++i)
89 * although here is no direct overflow. The OV occurs when the ++i
90 * is executed (and would created an endless loop here!).
92 * For the same reason, a loop
94 * for (i = 0; i <= 9; i += x)
96 * will NOT be transformed because we cannot estimate whether an overflow
97 * might happen adding x.
99 * Note that i < a + 400 is also not possible with the current implementation
100 * although this might be allowed by other compilers...
102 * Note further that tests for equality can be handled some simpler (but are not
105 * This algorithm destroys the link field of nodes.
107 void opt_osr(ir_graph *irg, unsigned flags);
110 * Removes useless Phi cycles, i.e cycles of Phi nodes with only one
112 * This is automatically done in opt_osr(), so there is no need to call it
115 * @param irg the graph which should be optimized
117 * This algorithm destroys the link field of nodes.
119 void remove_phi_cycles(ir_graph *irg);
121 #endif /* _OPT_OSR_H_ */