wtf?
[libfirm] / ir / ir / irarch.h
1 /**
2  * @file irarch.h
3  * @date 1.10.2004
4  * @author Sebastian Hack
5  * @brief Some machine dependent optimizations.
6  *
7  * $Id$
8  */
9
10 #ifndef __FIRM_IRARCH_H
11 #define __FIRM_IRARCH_H
12
13 #include "irnode.h"
14
15 /**
16  * A parameter structure that drives the machine dependent Firm
17  * optimizations.
18  */
19 typedef struct {
20   int also_use_subs : 1; /**< Use also Subs when resolving muls to shifts */
21
22   int maximum_shifts;    /**< The maximum number of shifts that shall be
23                             inserted for a mul. */
24
25   int highest_shift_amount; /**< The highest shift amount you want to
26                                tolerate. Muls which would require a higher
27                                shift constant are left. */
28
29 } arch_dep_params_t;
30
31 /**
32  * A factory function, that provides architecture parameters for
33  * machine dependent optimizations.
34  */
35 typedef const arch_dep_params_t *(*arch_dep_params_factory_t)(void);
36
37 /**
38  * A default parameter factory for testing purposes.
39  */
40 const arch_dep_params_t *arch_dep_default_factory(void);
41
42 /**
43  * Optimization flags.
44  */
45 typedef enum {
46   arch_dep_none         = 0,
47   arch_dep_mul_to_shift = 1,    /**< optimize Mul into Shift/Add/Sub */
48   arch_dep_div_to_shift = 2,    /**< optimize Div into Shift/Add/Mul */
49   arch_dep_mod_to_shift = 4     /**< optimize Mod into Shift/Add/Mul */
50 } arch_dep_opts_t;
51
52 /**
53  * Initialize the machine dependent optimizations.
54  * @param factory   A factory that delivers parameters for these
55  *                  optimizations. If NULL is passed, or this method
56  *                  is not called, the machine dependent optimizations
57  *                  are not enabled at all.
58  */
59 void arch_dep_init(arch_dep_params_factory_t factory);
60
61 /**
62  * Set the optimizations that shall be applied.
63  * @param opts An optimization bit mask.
64  */
65 void arch_dep_set_opts(arch_dep_opts_t opts);
66
67 /**
68  * Replace Muls with Shifts and Add/Subs.
69  * This function is driven by the 3 parameters:
70  * - also_use_subs
71  * - maximum_shifts
72  * - highest_shift_amount
73  *
74  * If irn is a Mul with a Const, The constant is inspected, if it meets the
75  * requirements of the three variables stated above. If a Shl/Add/Sub
76  * sequence can be generated, that meets these requirements, this expression
77  * is returned. In each other case, irn is returned unmodified.
78  *
79  * @param irn       The Firm node to inspect.
80  * @return          A replacement expression for irn.
81  */
82 ir_node *arch_dep_replace_mul_with_shifts(ir_node *irn);
83
84 /**
85  * Replace Divs with Shifts and Add/Subs.
86  * This function is driven by the 3 parameters:
87  * - also_use_subs
88  * - maximum_shifts
89  * - highest_shift_amount
90  *
91  * If irn is a Div with a Const, The constant is inspected, if it meets the
92  * requirements of the three variables stated above. If a Shl/Add/Sub
93  * sequence can be generated, that meets these requirements, this expression
94  * is returned. In each other case, irn is returned unmodified.
95  *
96  * @param irn       The Firm node to inspect.
97  * @return          A replacement expression for irn.
98  */
99 ir_node *arch_dep_replace_div_with_shifts(ir_node *irn);
100
101 /**
102  * Replace Mods with Shifts and Add/Subs.
103  * This function is driven by the 3 parameters:
104  * - also_use_subs
105  * - maximum_shifts
106  * - highest_shift_amount
107  *
108  * If irn is a Div with a Const, The constant is inspected, if it meets the
109  * requirements of the three variables stated above. If a Shl/Add/Sub
110  * sequence can be generated, that meets these requirements, this expression
111  * is returned. In each other case, irn is returned unmodified.
112  *
113  * @param irn       The Firm node to inspect.
114  * @return          A replacement expression for irn.
115  */
116 ir_node *arch_dep_replace_mod_with_shifts(ir_node *irn);
117
118 /**
119  * Replace Mods with Shifts and Add/Subs.
120  * This function is driven by the 3 parameters:
121  * - also_use_subs
122  * - maximum_shifts
123  * - highest_shift_amount
124  *
125  * If irn is a Div with a Const, The constant is inspected, if it meets the
126  * requirements of the three variables stated above. If a Shl/Add/Sub
127  * sequence can be generated, that meets these requirements, this expression
128  * is returned. In each other case, irn is returned unmodified.
129  *
130  * @param div       After call contains the Firm node div result or NULL.
131  * @param mod       After call contains the Firm node mod result or NULL.
132  * @param irn       The Firm node to inspect.
133  * @return          A replacement expression for irn.
134  */
135 void arch_dep_replace_divmod_with_shifts(ir_node **div, ir_node **mod, ir_node *irn);
136
137 #endif