becopyopt: Inline the thin wrapper nodes_interfere(), so we do not need to fetch...
[libfirm] / include / libfirm / irarch.h
1 /*
2  * This file is part of libFirm.
3  * Copyright (C) 2012 University of Karlsruhe.
4  */
5
6 /**
7  * @file
8  * @brief  Some machine dependent optimizations.
9  * @date   1.10.2004
10  * @author Sebastian Hack
11  */
12 #ifndef FIRM_IR_IRARCH_H
13 #define FIRM_IR_IRARCH_H
14
15 #include "firm_types.h"
16 #include "begin.h"
17
18 /**
19  * @addtogroup iroptimize
20  * @{
21  */
22
23 /**
24  * The Multiplication replacement can consist of the following instructions.
25  */
26 typedef enum insn_kind {
27         LEA,   /**< the LEA instruction */
28         SHIFT, /**< the SHIFT instruction */
29         SUB,   /**< the SUB instruction */
30         ADD,   /**< the ADD instruction */
31         ZERO,  /**< creates a ZERO constant */
32         MUL,   /**< the original MUL instruction */
33         ROOT   /**< the ROOT value that is multiplied */
34 } insn_kind;
35
36 /**
37  * A Callback for evaluating the costs of an instruction.
38  *
39  * @param kind   the instruction
40  * @param mode   the mode of the instruction
41  * @param tv     for MUL instruction, the multiplication constant
42  *
43  * @return the costs of this instruction
44  */
45 typedef int (*evaluate_costs_func)(insn_kind kind, const ir_mode *mode, ir_tarval *tv);
46
47 /**
48  * A parameter structure that drives the machine dependent Firm
49  * optimizations.
50  */
51 typedef struct ir_settings_arch_dep_t {
52         /* Mul optimization */
53         unsigned also_use_subs : 1;    /**< Use also Subs when resolving Muls to shifts */
54         unsigned maximum_shifts;       /**< The maximum number of shifts that shall be inserted for a mul. */
55         unsigned highest_shift_amount; /**< The highest shift amount you want to
56                                             tolerate. Muls which would require a higher
57                                             shift constant are left. */
58         evaluate_costs_func evaluate;  /**< Evaluate the costs of a generated instruction. */
59
60         /* Div/Mod optimization */
61         unsigned allow_mulhs   : 1;    /**< Use the Mulhs operation for division by constant */
62         unsigned allow_mulhu   : 1;    /**< Use the Mulhu operation for division by constant */
63         unsigned max_bits_for_mulh;    /**< Maximum number of bits the Mulh operation can take.
64                                             Modes with higher amount of bits will use Mulh */
65 } ir_settings_arch_dep_t;
66
67 /**
68  * A factory function, that provides architecture parameters for
69  * machine dependent optimizations.
70  */
71 typedef const ir_settings_arch_dep_t *(*arch_dep_params_factory_t)(void);
72
73 /**
74  * Optimization flags.
75  */
76 typedef enum arch_dep_opts_t {
77         arch_dep_none         = 0,
78         arch_dep_mul_to_shift = 1u << 0,  /**< optimize Mul into Shift/Add/Sub */
79         arch_dep_div_by_const = 1u << 1,  /**< optimize Div into Shift/Add/Mulh */
80         arch_dep_mod_by_const = 1u << 2   /**< optimize Mod into Shift/Add/Mulh */
81 } arch_dep_opts_t;
82 ENUM_BITSET(arch_dep_opts_t)
83
84 /**
85  * Sets the optimizations that shall be applied.
86  * @param opts  An optimization bit mask.
87  */
88 FIRM_API void arch_dep_set_opts(arch_dep_opts_t opts);
89
90 /**
91  * Replaces Muls with Lea/Shifts/Add/Subs if these
92  * have smaller costs than the original multiplication.
93  *
94  * @param irn       The Firm node to inspect.
95  * @return          A replacement expression for irn.
96  */
97 FIRM_API ir_node *arch_dep_replace_mul_with_shifts(ir_node *irn);
98
99 /**
100  * Replaces Divs with Shifts and Add/Subs and Mulh.
101  * This function is driven by the 3 parameters:
102  * - allow_mulhu
103  * - allow_mulhs
104  * - max_bits_for_mulh
105  *
106  * If irn is a Div with a Const, the constant is inspected if it meets the
107  * requirements of the variables stated above. If a Shl/Add/Sub/Mulh
108  * sequence can be generated that meets these requirements, this expression
109  * is returned. In each other case irn is returned unmodified.
110  *
111  * @param irn       The Firm node to inspect.
112  * @return          A replacement expression for irn.
113  */
114 FIRM_API ir_node *arch_dep_replace_div_by_const(ir_node *irn);
115
116 /**
117  * Replaces Mods with Shifts and Add/Subs and Mulh.
118  * This function is driven by the 3 parameters:
119  * - allow_mulhu
120  * - allow_mulhs
121  * - max_bits_for_mulh
122  *
123  * If irn is a Mod 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 irn       The Firm node to inspect.
129  * @return          A replacement expression for irn.
130  */
131 FIRM_API ir_node *arch_dep_replace_mod_by_const(ir_node *irn);
132
133 /** @} */
134
135 #include "end.h"
136
137 #endif