Do not emit cld in the CopyB prologue. The ABI mandates that DF is cleared, so do...
[libfirm] / ir / be / bearch.h
1 /*
2  * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
6  * This file may be distributed and/or modified under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation and appearing in the file LICENSE.GPL included in the
9  * packaging of this file.
10  *
11  * Licensees holding valid libFirm Professional Edition licenses may use
12  * this file in accordance with the libFirm Commercial License.
13  * Agreement provided with the Software.
14  *
15  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief       Processor architecture specification.
23  * @author      Sebastian Hack
24  * @version     $Id$
25  */
26 #ifndef FIRM_BE_BEARCH_H
27 #define FIRM_BE_BEARCH_H
28
29 #include "firm_types.h"
30 #include "bitset.h"
31 #include "be.h"
32 #include "obst.h"
33
34 typedef struct arch_register_class_t     arch_register_class_t;
35 typedef struct arch_register_req_t       arch_register_req_t;
36 typedef struct arch_register_t           arch_register_t;
37 typedef struct arch_flag_t               arch_flag_t;
38 typedef struct arch_inverse_t            arch_inverse_t;
39 typedef struct arch_isa_if_t             arch_isa_if_t;
40 typedef struct arch_env_t                arch_env_t;
41 typedef struct arch_code_generator_t     arch_code_generator_t;
42 typedef struct arch_code_generator_if_t  arch_code_generator_if_t;
43
44 typedef enum arch_register_class_flags_t {
45         arch_register_class_flag_none      = 0,
46         arch_register_class_flag_manual_ra = 1,  /**< don't do automatic register allocation for this class */
47         arch_register_class_flag_state     = 2
48 } arch_register_class_flags_t;
49
50 typedef enum arch_register_type_t {
51         arch_register_type_none         = 0,
52         arch_register_type_caller_save  = 1,  /**< The register must be saved by the caller
53                                                    upon a function call. It thus can be overwritten
54                                                    in the called function. */
55         arch_register_type_callee_save  = 2,  /**< The register must be saved by the caller
56                                                    upon a function call. It thus can be overwritten
57                                                    in the called function. */
58         arch_register_type_ignore       = 4,  /**< Do not consider this register when allocating. */
59         arch_register_type_joker        = 8,  /**< The emitter can choose an arbitrary register */
60         arch_register_type_virtual      = 16, /**< This is just a virtual register.Virtual registers have
61                                                    nearly no constraints, it is a allowed to have multiple
62                                                    definition for the same register at a point) */
63         arch_register_type_state        = 32, /**< The register represents a state that should be handled by
64                                                    bestate code */
65 } arch_register_type_t;
66
67 typedef enum arch_operand_type_t {
68         arch_operand_type_invalid,
69         arch_operand_type_memory,
70         arch_operand_type_register,
71         arch_operand_type_immediate,
72         arch_operand_type_symconst,
73         arch_operand_type_last
74 } arch_operand_type_t;
75
76 /**
77  * Different types of register allocation requirements.
78  */
79 typedef enum arch_register_req_type_t {
80         arch_register_req_type_none              = 0,  /**< No register requirement. */
81         arch_register_req_type_normal            = 1,  /**< All registers in the class are allowed. */
82         arch_register_req_type_limited           = 2,  /**< Only a real subset of the class is allowed. */
83         arch_register_req_type_should_be_same    = 4,  /**< The register should be equal to another one at the node. */
84         arch_register_req_type_must_be_different = 8,  /**< The register must be unequal from some other at the node. */
85 } arch_register_req_type_t;
86
87 extern const arch_register_req_t *arch_no_register_req;
88
89 /**
90  * Format a register requirements information into a string.
91  * @param buf The string where to put it to.
92  * @param len The size of @p buf.
93  * @param req The requirements structure to format.
94  * @return    A pointer to buf.
95  */
96 extern char *arch_register_req_format(char *buf, size_t len, const arch_register_req_t *req, const ir_node *node);
97
98 /**
99  * Certain node classes which are relevant for the register allocator.
100  */
101 typedef enum arch_irn_class_t {
102         arch_irn_class_normal     = 1 << 0,
103         arch_irn_class_spill      = 1 << 1,
104         arch_irn_class_reload     = 1 << 2,
105         arch_irn_class_remat      = 1 << 3,
106         arch_irn_class_copy       = 1 << 4,
107         arch_irn_class_perm       = 1 << 5,
108         arch_irn_class_branch     = 1 << 6,
109         arch_irn_class_call       = 1 << 7,
110         arch_irn_class_load       = 1 << 8,
111         arch_irn_class_store      = 1 << 9,
112         arch_irn_class_stackparam = 1 << 10,
113 } arch_irn_class_t;
114
115 /**
116  * Some flags describing a node in more detail.
117  */
118 typedef enum arch_irn_flags_t {
119         arch_irn_flags_none             = 0, /**< Node flags. */
120         arch_irn_flags_dont_spill       = 1, /**< This must not be spilled. */
121         arch_irn_flags_rematerializable = 2, /**< This can be replicated instead of spilled/reloaded. */
122         arch_irn_flags_ignore           = 4, /**< Ignore node during register allocation. */
123         arch_irn_flags_modify_sp        = 8, /**< I modify the stack pointer. */
124         arch_irn_flags_modify_flags     = 16, /**< I modify flags. */
125         arch_irn_flags_last             = arch_irn_flags_modify_flags
126 } arch_irn_flags_t;
127
128 /**
129  * Get the string representation of a flag.
130  * This functions does not handle or'ed bitmasks of flags.
131  * @param flag The flag.
132  * @return The flag as a string.
133  */
134 extern const char *arch_irn_flag_str(arch_irn_flags_t flag);
135
136 extern const arch_irn_ops_t *arch_get_irn_ops(const arch_env_t *env,
137                                               const ir_node *irn);
138
139 extern void arch_set_frame_offset(const arch_env_t *env, ir_node *irn, int bias);
140
141 extern ir_entity *arch_get_frame_entity(const arch_env_t *env, const ir_node *irn);
142 extern void arch_set_frame_entity(const arch_env_t *env, ir_node *irn, ir_entity *ent);
143 extern int arch_get_sp_bias(const arch_env_t *env, ir_node *irn);
144
145 extern int arch_get_op_estimated_cost(const arch_env_t *env, const ir_node *irn);
146 extern arch_inverse_t *arch_get_inverse(const arch_env_t *env, const ir_node *irn, int i, arch_inverse_t *inverse, struct obstack *obstack);
147 extern int arch_possible_memory_operand(const arch_env_t *env, const ir_node *irn, unsigned int i);
148 extern void arch_perform_memory_operand(const arch_env_t *env, ir_node *irn, ir_node *spill, unsigned int i);
149
150 /**
151  * Get the register requirements for a node.
152  * @param env The architecture environment.
153  * @param irn The node.
154  * @param pos The position of the operand you're interested in.
155  * @return    A pointer to the register requirements.  If NULL is returned, the
156  *            operand was no register operand.
157  */
158 extern const arch_register_req_t *
159 arch_get_register_req(const arch_env_t *env, const ir_node *irn, int pos);
160
161 /**
162  * Check if an operand is a register operand.
163  * @param env The environment.
164  * @param irn The node.
165  * @param pos The position of the operand.
166  * @return 1, if the operand is significant for register allocation, 0
167  * if not.
168  */
169 extern int arch_is_register_operand(const arch_env_t *env,
170     const ir_node *irn, int pos);
171
172 /**
173  * Get the number of allocatable registers concerning
174  * a register class for an operand of a node.
175  * @param env The environment.
176  * @param irn The node.
177  * @param pos The position of the node's operand.
178  * @param bs  The bitset all allocatable registers shall be put into.
179  *            Note, that you can also pass NULL here. If you don't,
180  *            make sure, the bitset is as large as the register class
181  *            has registers.
182  * @return    The amount of registers allocatable for that operand.
183  */
184 extern int arch_get_allocatable_regs(const arch_env_t *env, const ir_node *irn, int pos, bitset_t *bs);
185
186 /**
187  * Put all registers which shall not be ignored by the register
188  * allocator in a bit set.
189  * @param env The arch env.
190  * @param cls The register class to consider.
191  * @param bs  The bit set to put the registers to.
192  */
193 extern void arch_put_non_ignore_regs(const arch_env_t *env, const arch_register_class_t *cls, bitset_t *bs);
194
195 /**
196  * Check, if a register is assignable to an operand of a node.
197  * @param env The architecture environment.
198  * @param irn The node.
199  * @param pos The position of the operand.
200  * @param reg The register.
201  * @return    1, if the register might be allocated to the operand 0 if not.
202  */
203 extern int arch_reg_is_allocatable(const arch_env_t *env,
204     const ir_node *irn, int pos, const arch_register_t *reg);
205
206 /**
207  * Get the register class of an operand of a node.
208  * @param env The architecture environment.
209  * @param irn The node.
210  * @param pos The position of the operand, -1 for the output.
211  * @return    The register class of the operand or NULL, if
212  *            operand is a non-register operand.
213  */
214 extern const arch_register_class_t *
215 arch_get_irn_reg_class(const arch_env_t *env, const ir_node *irn, int pos);
216
217 /**
218  * Get the register allocated at a certain output operand of a node.
219  * @param env The arch environment.
220  * @param irn The node.
221  * @return    The register allocated for this operand
222  */
223 extern const arch_register_t *
224 arch_get_irn_register(const arch_env_t *env, const ir_node *irn);
225
226 /**
227  * Set the register for a certain output operand.
228  * @param env The architecture environment.
229  * @param irn The node.
230  * @param reg The register.
231  */
232 extern void arch_set_irn_register(const arch_env_t *env, ir_node *irn,
233                                   const arch_register_t *reg);
234
235 /**
236  * Classify a node.
237  * @param env The architecture environment.
238  * @param irn The node.
239  * @return A classification of the node.
240  */
241 extern arch_irn_class_t arch_irn_classify(const arch_env_t *env, const ir_node *irn);
242
243 #define arch_irn_class_is(env, irn, irn_class) ((arch_irn_classify(env, irn) & arch_irn_class_ ## irn_class) != 0)
244
245 /**
246  * Get the flags of a node.
247  * @param env The architecture environment.
248  * @param irn The node.
249  * @return The flags.
250  */
251 extern arch_irn_flags_t arch_irn_get_flags(const arch_env_t *env, const ir_node *irn);
252
253 #define arch_irn_is(env, irn, flag) ((arch_irn_get_flags(env, irn) & arch_irn_flags_ ## flag) != 0)
254
255 #define arch_irn_has_reg_class(env, irn, pos, cls) \
256         ((cls) == arch_get_irn_reg_class(env, irn, pos))
257
258 #define arch_irn_consider_in_reg_alloc(env, cls, irn) \
259         (arch_irn_has_reg_class(env, irn, -1, cls) && !arch_irn_is(env, irn, ignore))
260
261 /**
262  * Get the operations of an irn.
263  * @param self The handler from which the method is invoked.
264  * @param irn Some node.
265  * @return Operations for that irn.
266  */
267 typedef const void *(arch_get_irn_ops_t)(const ir_node *irn);
268
269 /**
270  * Initialize the architecture environment struct.
271  * @param isa           The isa which shall be put into the environment.
272  * @param file_handle   The file handle
273  * @return The environment.
274  */
275 extern arch_env_t *arch_env_init(const arch_isa_if_t *isa,
276                                  FILE *file_handle, be_main_env_t *main_env);
277
278 /**
279  * Register an instruction set architecture
280  */
281 void be_register_isa_if(const char *name, const arch_isa_if_t *isa);
282
283 #endif /* FIRM_BE_BEARCH_H */