4 * @author Sebastian Hack
5 * @brief Some machine dependent optimizations.
10 #ifndef __FIRM_IRARCH_H
11 #define __FIRM_IRARCH_H
16 * A parameter structure that drives the machine dependent Firm
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 */
24 int maximum_shifts; /**< The maximum number of shifts that shall be
25 inserted for a mul. */
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. */
33 * A factory function, that provides architecture parameters for
34 * machine dependent optimizations.
36 typedef const arch_dep_params_t *(*arch_dep_params_factory_t)(void);
39 * A default parameter factory for testing purposes.
41 const arch_dep_params_t *arch_dep_default_factory(void);
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 */
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.
60 void arch_dep_init(arch_dep_params_factory_t factory);
63 * Set the optimizations that shall be applied.
64 * @param opts An optimization bit mask.
66 void arch_dep_set_opts(arch_dep_opts_t opts);
69 * Replace Muls with Shifts and Add/Subs.
70 * This function is driven by the 3 parameters:
73 * - highest_shift_amount
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.
80 * @param irn The Firm node to inspect.
81 * @return A replacement expression for irn.
83 ir_node *arch_dep_replace_mul_with_shifts(ir_node *irn);
86 * Replace Divs with Shifts and Add/Subs and Mulh.
87 * This function is driven by the 3 parameters:
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.
96 * @param irn The Firm node to inspect.
97 * @return A replacement expression for irn.
99 ir_node *arch_dep_replace_div_by_const(ir_node *irn);
102 * Replace Mods with Shifts and Add/Subs and Mulh.
103 * This function is driven by the 3 parameters:
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.
112 * @param irn The Firm node to inspect.
113 * @return A replacement expression for irn.
115 ir_node *arch_dep_replace_mod_by_const(ir_node *irn);
118 * Replace DivMods with Shifts and Add/Subs and Mulh.
119 * This function is driven by the 3 parameters:
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.
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.
132 void arch_dep_replace_divmod_by_const(ir_node **div, ir_node **mod, ir_node *irn);