updated Header
[libfirm] / ir / opt / opt_osr.h
1 /*
2  * Copyright (C) 1995-2007 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
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.
10  *
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.
14  *
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
17  * PURPOSE.
18  */
19
20 /**
21  * Project:     libFIRM
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
26  * Modified by:
27  * Created:     12.5.2006
28  * CVS-ID:      $Id$
29  * Copyright:   (c) 2006 Universität Karlsruhe
30  */
31 #ifndef _OPT_OSR_H_
32 #define _OPT_OSR_H_
33
34 #include "firm_types.h"
35
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 */
42 } osr_flags;
43
44 /* FirmJNI cannot handle identical enum values... */
45
46 /** default setting */
47 #define osr_flag_default osr_flag_lftr_with_ov_check
48
49 /**
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.
54  *
55  * @param irg    the graph which should be optimized
56  * @param flags  set of osr_flags
57  *
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.
62  *
63  * For instance:
64  *
65  * for (i = 0; i < 100; ++i)
66  *
67  * might be replaced by
68  *
69  * for (i = 0; i < 400; i += 4)
70  *
71  * But
72  *
73  * for (i = 0; i < 0x7FFFFFFF; ++i)
74  *
75  * will not be replaced by
76  *
77  * for (i = 0; i < 0xFFFFFFFC; i += 4)
78  *
79  * because of overflow.
80  *
81  * More bad cases:
82  *
83  * for (i = 0; i <= 0xF; ++i)
84  *
85  * will NOT be transformed into
86  *
87  * for (i = 0xFFFFFFF0; i <= 0xFFFFFFFF; ++i)
88  *
89  * although here is no direct overflow. The OV occurs when the ++i
90  * is executed (and would created an endless loop here!).
91  *
92  * For the same reason, a loop
93  *
94  * for (i = 0; i <= 9; i += x)
95  *
96  * will NOT be transformed because we cannot estimate whether an overflow
97  * might happen adding x.
98  *
99  * Note that i < a + 400 is also not possible with the current implementation
100  * although this might be allowed by other compilers...
101  *
102  * Note further that tests for equality can be handled some simpler (but are not
103  * implemented yet).
104  *
105  * This algorithm destroys the link field of nodes.
106  */
107 void opt_osr(ir_graph *irg, unsigned flags);
108
109 /**
110  * Removes useless Phi cycles, i.e cycles of Phi nodes with only one
111  * non-Phi node.
112  * This is automatically done in opt_osr(), so there is no need to call it
113  * additionally.
114  *
115  * @param irg    the graph which should be optimized
116  *
117  * This algorithm destroys the link field of nodes.
118  */
119 void remove_phi_cycles(ir_graph *irg);
120
121 #endif /* _OPT_OSR_H_ */