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 */
22 int maximum_shifts; /**< The maximum number of shifts that shall be
23 inserted for a mul. */
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. */
32 * A factory function, that provides architecture parameters for
33 * machine dependent optimizations.
35 typedef const arch_dep_params_t *(*arch_dep_params_factory_t)(void);
38 * A default parameter factory for testing purposes.
40 const arch_dep_params_t *arch_dep_default_factory(void);
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 */
52 * Initialize the machine dependent optimizations.
53 * @param factory A factory that delivers parameters for these
54 * optimizations. If NULL is passed, or this method
55 * is not called, the machine dependent optimizations
56 * are not enabled at all.
58 void arch_dep_init(arch_dep_params_factory_t factory);
61 * Set the optimizations that shall be applied.
62 * @param opts An optimization bit mask.
64 void arch_dep_set_opts(arch_dep_opts_t opts);
67 * Replace Muls with Shifts and Add/Subs.
68 * This function is driven by the 3 parameters:
71 * - highest_shift_amount
73 * If irn is a Mul with a Const, The constant is inspected, if it meets the
74 * requirements of the three variables stated above. If a Shl/Add/Sub
75 * sequence can be generated, that meets these requirements, this expression
76 * is returned. In each other case, irn is returned unmodified.
78 * @param irn The Firm node to inspect.
79 * @return A replacement expression for irn.
81 ir_node *arch_dep_replace_mul_with_shifts(ir_node *irn);
84 * Replace Divs with Shifts and Add/Subs.
85 * This function is driven by the 3 parameters:
88 * - highest_shift_amount
90 * If irn is a Div with a Const, The constant is inspected, if it meets the
91 * requirements of the three variables stated above. If a Shl/Add/Sub
92 * sequence can be generated, that meets these requirements, this expression
93 * is returned. In each other case, irn is returned unmodified.
95 * @param irn The Firm node to inspect.
96 * @return A replacement expression for irn.
98 ir_node *arch_dep_replace_div_with_shifts(ir_node *irn);