Make some more inline functions
[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   int allow_mulhs   : 1; /**< Use the Mulhs operation for division by constant */
22   int allow_mulhu   : 1; /**< Use the Mulhu operation for division by constant */
23
24   int maximum_shifts;    /**< The maximum number of shifts that shall be
25                             inserted for a mul. */
26
27   int highest_shift_amount; /**< The highest shift amount you want to
28                                tolerate. Muls which would require a higher
29                                shift constant are left. */
30 } arch_dep_params_t;
31
32 /**
33  * A factory function, that provides architecture parameters for
34  * machine dependent optimizations.
35  */
36 typedef const arch_dep_params_t *(*arch_dep_params_factory_t)(void);
37
38 /**
39  * A default parameter factory for testing purposes.
40  */
41 const arch_dep_params_t *arch_dep_default_factory(void);
42
43 /**
44  * Optimization flags.
45  */
46 typedef enum {
47   arch_dep_none         = 0,
48   arch_dep_mul_to_shift = 1,    /**< optimize Mul into Shift/Add/Sub */
49   arch_dep_div_by_const = 2,    /**< optimize Div into Shift/Add/Mulh */
50   arch_dep_mod_by_const = 4     /**< optimize Mod into Shift/Add/Mulh */
51 } arch_dep_opts_t;
52
53 /**
54  * Initialize the machine dependent optimizations.
55  * @param factory   A factory that delivers parameters for these
56  *                  optimizations. If NULL is passed, or this method
57  *                  is not called, the machine dependent optimizations
58  *                  are not enabled at all.
59  */
60 void arch_dep_init(arch_dep_params_factory_t factory);
61
62 /**
63  * Set the optimizations that shall be applied.
64  * @param opts An optimization bit mask.
65  */
66 void arch_dep_set_opts(arch_dep_opts_t opts);
67
68 /**
69  * Replace Muls with Shifts and Add/Subs.
70  * This function is driven by the 3 parameters:
71  * - also_use_subs
72  * - maximum_shifts
73  * - highest_shift_amount
74  *
75  * If irn is a Mul with a Const, The constant is inspected, if it meets the
76  * requirements of the three variables stated above. If a Shl/Add/Sub
77  * sequence can be generated, that meets these requirements, this expression
78  * is returned. In each other case, irn is returned unmodified.
79  *
80  * @param irn       The Firm node to inspect.
81  * @return          A replacement expression for irn.
82  */
83 ir_node *arch_dep_replace_mul_with_shifts(ir_node *irn);
84
85 /**
86  * Replace Divs with Shifts and Add/Subs and Mulh.
87  * This function is driven by the 3 parameters:
88  * - allow_mulhu
89  * - allow_mulhs
90  *
91  * If irn is a Div with a Const, The constant is inspected, if it meets the
92  * requirements of the variables stated above. If a Shl/Add/Sub/Mulh
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_by_const(ir_node *irn);
100
101 /**
102  * Replace Mods with Shifts and Add/Subs and Mulh.
103  * This function is driven by the 3 parameters:
104  * - allow_mulhu
105  * - allow_mulhs
106  *
107  * If irn is a Mod with a Const, The constant is inspected, if it meets the
108  * requirements of the variables stated above. If a Shl/Add/Sub/Mulh
109  * sequence can be generated, that meets these requirements, this expression
110  * is returned. In each other case, irn is returned unmodified.
111  *
112  * @param irn       The Firm node to inspect.
113  * @return          A replacement expression for irn.
114  */
115 ir_node *arch_dep_replace_mod_by_const(ir_node *irn);
116
117 /**
118  * Replace DivMods with Shifts and Add/Subs and Mulh.
119  * This function is driven by the 3 parameters:
120  * - allow_mulhu
121  * - allow_mulhs
122  *
123  * If irn is a DivMod with a Const, The constant is inspected, if it meets the
124  * requirements of the variables stated above. If a Shl/Add/Sub/Mulh
125  * sequence can be generated, that meets these requirements, this expression
126  * is returned. In each other case, irn is returned unmodified.
127  *
128  * @param div       After call contains the Firm node div result or NULL.
129  * @param mod       After call contains the Firm node mod result or NULL.
130  * @param irn       The Firm node to inspect.
131  */
132 void arch_dep_replace_divmod_by_const(ir_node **div, ir_node **mod, ir_node *irn);
133
134 #endif