implement some localopt rules for And(Cmp(a,0), Cmp(b,0))
[libfirm] / include / libfirm / iropt.h
1 /*
2  * Copyright (C) 1995-2008 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  * @file
22  * @brief   iropt --- optimizations of an ir node.
23  * @author  Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Michael Beck
24  * @version $Id$
25  */
26 #ifndef FIRM_IR_IROPT_H
27 #define FIRM_IR_IROPT_H
28
29 #include "firm_types.h"
30 #include "begin.h"
31
32 /**
33  * The Floating point model.
34  *
35  * Several basic properties are defined:
36  * - fp_explicit_rounding
37  * - fp_strict_algebraic
38  * - fp_contradictions
39  * - fp_strict_eval_order
40  * - fp_exceptions
41  * - fp_environment_access
42  *
43  * From those basic properties three general models are defined,
44  * compatible to the VC8 compiler:
45  * - fp_model_precise:
46  *     Default mode. Associative and distributive law forbidden unless a transformation
47  *     is guaranteed to produce the same result.
48  *     No FPU environment access. No FP exception semantics.
49  * - fp_model_strict:
50  *     Slowest mode. Additionally to fp_model_precise allows correct handling of
51  *     FP exceptions and FPU environment access.
52  * - fp_model_fast:
53  *     Fastest mode. Associative and distributive law allowed at the expense
54  *     of floating point accuracy and correctness. Explicit rounding is disabled.
55  */
56 typedef enum fp_model_t {
57         fp_explicit_rounding  = (1u << 0),  /**< Explicit rounding at assignments, typecasts, return
58                                           and function calls. Conv nodes may NOT be removed, even
59                                           if they look useless. */
60         fp_strict_algebraic   = (1u << 1),  /**< Strict adherence to non-associative and non-distributive
61                                           algebra unless the same result is guaranteed. */
62         fp_contradictions     = (1u << 2),  /**< FP contradictions are enabled. Only for backend. */
63         fp_strict_eval_order  = (1u << 3),  /**< FP instructions must be strict evaluated in given order. */
64         fp_exceptions         = (1u << 4),  /**< FP exceptions are supported. No reordering that changes
65                                           the exception flow are allowed. Backends must generate
66                                           synchronized exception code. */
67         fp_environment_access = (1u << 5),  /**< FPU environment can be accessed. Even Constant folding
68                                           cannot be done. */
69
70         /** Precise floating point model. Default. */
71         fp_model_precise = fp_explicit_rounding|fp_strict_algebraic|fp_contradictions,
72         /** Strict floating point model. */
73         fp_model_strict  = fp_explicit_rounding|fp_strict_algebraic|fp_strict_eval_order|
74                            fp_exceptions|fp_environment_access,
75         /** Fast floating point model. */
76         fp_model_fast    = fp_contradictions
77 } fp_model_t;
78
79 /** If the expression referenced can be evaluated statically
80  *  computed_value returns a tarval representing the result.
81  *  Else returns tarval_bad. */
82 FIRM_API ir_tarval *computed_value(const ir_node *n);
83
84 /** Applies all optimizations to n that are expressible as a pattern
85  *  in Firm, i.e., they need not a walk of the graph.
86  *  Returns a better node for n.  Does not free n -- other nodes could
87  *  reference n.
88  *
89  *  An equivalent optimization is applied in the constructors defined in
90  *  ircons.ch.  There n is freed if a better node could be found.
91  */
92 FIRM_API ir_node *optimize_in_place(ir_node *n);
93
94 /**
95  * checks wether 1 value is the negated other value
96  */
97 FIRM_API int ir_is_negated_value(const ir_node *a, const ir_node *b);
98
99 /**
100  * (conservatively) approximates all possible relations when comparing
101  * the value @p left and @p right
102  */
103 FIRM_API ir_relation ir_get_possible_cmp_relations(const ir_node *left,
104                                                    const ir_node *right);
105
106 /**
107  * tests wether a given Cmp node is an equal/not-equal test with 0
108  * (this is a bit tricky because it has to catch x!=0 for the signed case and
109  *  x>0 for the unsigned case)
110  */
111 FIRM_API int ir_is_equality_cmp_0(const ir_node *node);
112
113 #include "end.h"
114
115 #endif