2 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
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.
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.
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
22 * @brief Processor architecture specification.
23 * @author Sebastian Hack
26 #ifndef FIRM_BE_BEARCH_H
27 #define FIRM_BE_BEARCH_H
29 #include "firm_types.h"
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;
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;
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
65 } arch_register_type_t;
68 * Put all registers in a class into a bitset.
69 * @param cls The class.
70 * @param bs The bitset. May be NULL.
71 * @return The number of registers in the class.
73 extern int arch_register_class_put(const arch_register_class_t *cls, bitset_t *bs);
75 typedef enum arch_operand_type_t {
76 arch_operand_type_invalid,
77 arch_operand_type_memory,
78 arch_operand_type_register,
79 arch_operand_type_immediate,
80 arch_operand_type_symconst,
81 arch_operand_type_last
82 } arch_operand_type_t;
85 * Different types of register allocation requirements.
87 typedef enum arch_register_req_type_t {
88 arch_register_req_type_none = 0, /**< No register requirement. */
89 arch_register_req_type_normal = 1, /**< All registers in the class are allowed. */
90 arch_register_req_type_limited = 2, /**< Only a real subset of the class is allowed. */
91 arch_register_req_type_should_be_same = 4, /**< The register should be equal to another one at the node. */
92 arch_register_req_type_should_be_different = 8, /**< The register must be unequal from some other at the node. */
93 } arch_register_req_type_t;
95 extern const arch_register_req_t *arch_no_register_req;
98 * Format a register requirements information into a string.
99 * @param buf The string where to put it to.
100 * @param len The size of @p buf.
101 * @param req The requirements structure to format.
102 * @return A pointer to buf.
104 extern char *arch_register_req_format(char *buf, size_t len, const arch_register_req_t *req, const ir_node *node);
107 * Certain node classes which are relevant for the register allocator.
109 typedef enum arch_irn_class_t {
110 arch_irn_class_normal = 1 << 0,
111 arch_irn_class_spill = 1 << 1,
112 arch_irn_class_reload = 1 << 2,
113 arch_irn_class_copy = 1 << 3,
114 arch_irn_class_perm = 1 << 4,
115 arch_irn_class_branch = 1 << 5,
116 arch_irn_class_call = 1 << 6,
117 arch_irn_class_load = 1 << 7,
118 arch_irn_class_store = 1 << 8,
119 arch_irn_class_stackparam = 1 << 9,
123 * Some flags describing a node in more detail.
125 typedef enum arch_irn_flags_t {
126 arch_irn_flags_none = 0, /**< Node flags. */
127 arch_irn_flags_dont_spill = 1, /**< This must not be spilled. */
128 arch_irn_flags_rematerializable = 2, /**< This can be replicated instead of spilled/reloaded. */
129 arch_irn_flags_ignore = 4, /**< Ignore node during register allocation. */
130 arch_irn_flags_modify_sp = 8, /**< I modify the stack pointer. */
131 arch_irn_flags_modify_flags = 16, /**< I modify flags. */
132 arch_irn_flags_last = arch_irn_flags_modify_flags
136 * Get the string representation of a flag.
137 * This functions does not handle or'ed bitmasks of flags.
138 * @param flag The flag.
139 * @return The flag as a string.
141 extern const char *arch_irn_flag_str(arch_irn_flags_t flag);
143 extern const arch_irn_ops_t *arch_get_irn_ops(const arch_env_t *env,
146 extern void arch_set_frame_offset(const arch_env_t *env, ir_node *irn, int bias);
148 extern ir_entity *arch_get_frame_entity(const arch_env_t *env, const ir_node *irn);
149 extern void arch_set_frame_entity(const arch_env_t *env, ir_node *irn, ir_entity *ent);
150 extern int arch_get_sp_bias(const arch_env_t *env, ir_node *irn);
152 extern int arch_get_op_estimated_cost(const arch_env_t *env, const ir_node *irn);
153 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);
154 extern int arch_possible_memory_operand(const arch_env_t *env, const ir_node *irn, unsigned int i);
155 extern void arch_perform_memory_operand(const arch_env_t *env, ir_node *irn, ir_node *spill, unsigned int i);
158 * Get the register requirements for a node.
159 * @param env The architecture environment.
160 * @param req A pointer to a requirements structure, where the data can
162 * @param irn The node.
163 * @param pos The position of the operand you're interested in.
164 * @return A pointer to the register requirements which may <b>not</b>
165 * neccessarily be equal to @p req. If NULL is returned, the
166 * operand was no register operand.
168 extern const arch_register_req_t *
169 arch_get_register_req(const arch_env_t *env, const ir_node *irn, int pos);
172 * Check if an operand is a register operand.
173 * @param env The environment.
174 * @param irn The node.
175 * @param pos The position of the operand.
176 * @return 1, if the operand is significant for register allocation, 0
179 extern int arch_is_register_operand(const arch_env_t *env,
180 const ir_node *irn, int pos);
183 * Get the number of allocatable registers concerning
184 * a register class for an operand of a node.
185 * @param env The environment.
186 * @param irn The node.
187 * @param pos The postition of the node's operand.
188 * @param bs The bitset all allocatable registers shall be put into.
189 * Note, that you can also pass NULL here. If you don't,
190 * make sure, the bitset is as large as the register class
192 * @return The amount of registers allocatable for that operand.
194 extern int arch_get_allocatable_regs(const arch_env_t *env, const ir_node *irn, int pos, bitset_t *bs);
197 * Put all registers which shall not be ignored by the register
198 * allocator in a bit set.
199 * @param env The arch env.
200 * @param cls The register class to consider.
201 * @param bs The bit set to put the registers to.
203 extern void arch_put_non_ignore_regs(const arch_env_t *env, const arch_register_class_t *cls, bitset_t *bs);
206 * Check, if a register is assignable to an operand of a node.
207 * @param env The architecture environment.
208 * @param irn The node.
209 * @param pos The position of the operand.
210 * @param reg The register.
211 * @return 1, if the register might be allocated to the operand 0 if not.
213 extern int arch_reg_is_allocatable(const arch_env_t *env,
214 const ir_node *irn, int pos, const arch_register_t *reg);
217 * Get the register class of an operand of a node.
218 * @param env The architecture environment.
219 * @param irn The node.
220 * @param pos The position of the operand, -1 for the output.
221 * @return The register class of the operand or NULL, if
222 * operand is a non-register operand.
224 extern const arch_register_class_t *
225 arch_get_irn_reg_class(const arch_env_t *env, const ir_node *irn, int pos);
228 * Get the register allocated at a certain output operand of a node.
229 * @param env The arch environment.
230 * @param irn The node.
231 * @return The register allocated for this operand
233 extern const arch_register_t *
234 arch_get_irn_register(const arch_env_t *env, const ir_node *irn);
237 * Set the register for a certain output operand.
238 * @param env The architecture environment.
239 * @param irn The node.
240 * @param idx The index of the output operand.
241 * @param reg The register.
243 extern void arch_set_irn_register(const arch_env_t *env, ir_node *irn,
244 const arch_register_t *reg);
248 * @param env The architecture environment.
249 * @param irn The node.
250 * @return A classification of the node.
252 extern arch_irn_class_t arch_irn_classify(const arch_env_t *env, const ir_node *irn);
254 #define arch_irn_class_is(env, irn, irn_class) ((arch_irn_classify(env, irn) & arch_irn_class_ ## irn_class) != 0)
257 * Get the flags of a node.
258 * @param env The architecture environment.
259 * @param irn The node.
262 extern arch_irn_flags_t arch_irn_get_flags(const arch_env_t *env, const ir_node *irn);
264 #define arch_irn_is(env, irn, flag) ((arch_irn_get_flags(env, irn) & arch_irn_flags_ ## flag) != 0)
266 #define arch_irn_has_reg_class(env, irn, pos, cls) \
267 ((cls) == arch_get_irn_reg_class(env, irn, pos))
269 #define arch_irn_consider_in_reg_alloc(env, cls, irn) \
270 (arch_irn_has_reg_class(env, irn, -1, cls) && !arch_irn_is(env, irn, ignore))
273 * Get the operations of an irn.
274 * @param self The handler from which the method is invoked.
275 * @param irn Some node.
276 * @return Operations for that irn.
278 typedef const void *(arch_get_irn_ops_t)(const ir_node *irn);
281 * Initialize the architecture environment struct.
282 * @param isa The isa which shall be put into the environment.
283 * @param file_handle The file handle
284 * @return The environment.
286 extern arch_env_t *arch_env_init(const arch_isa_if_t *isa,
287 FILE *file_handle, be_main_env_t *main_env);
290 * Register an instruction set architecture
292 void be_register_isa_if(const char *name, const arch_isa_if_t *isa);
294 #endif /* FIRM_BE_BEARCH_H */