- remove all irg parameter from node constructors having a block
[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 <stdbool.h>
30
31 #include "firm_types.h"
32 #include "bitset.h"
33 #include "be.h"
34 #include "obst.h"
35
36 typedef struct arch_register_class_t     arch_register_class_t;
37 typedef struct arch_register_req_t       arch_register_req_t;
38 typedef struct arch_register_t           arch_register_t;
39 typedef struct arch_flag_t               arch_flag_t;
40 typedef struct arch_inverse_t            arch_inverse_t;
41 typedef struct arch_isa_if_t             arch_isa_if_t;
42 typedef struct arch_env_t                arch_env_t;
43 typedef struct arch_code_generator_t     arch_code_generator_t;
44 typedef struct arch_code_generator_if_t  arch_code_generator_if_t;
45
46 typedef enum arch_register_class_flags_t {
47         arch_register_class_flag_none      = 0,
48         arch_register_class_flag_manual_ra = 1,  /**< don't do automatic register allocation for this class */
49         arch_register_class_flag_state     = 2
50 } arch_register_class_flags_t;
51
52 typedef enum arch_register_type_t {
53         arch_register_type_none         = 0,
54         arch_register_type_caller_save  = 1,  /**< The register must be saved by the caller
55                                                    upon a function call. It thus can be overwritten
56                                                    in the called function. */
57         arch_register_type_callee_save  = 2,  /**< The register must be saved by the caller
58                                                    upon a function call. It thus can be overwritten
59                                                    in the called function. */
60         arch_register_type_ignore       = 4,  /**< Do not consider this register when allocating. */
61         arch_register_type_joker        = 8,  /**< The emitter can choose an arbitrary register */
62         arch_register_type_virtual      = 16, /**< This is just a virtual register.Virtual registers have
63                                                    nearly no constraints, it is a allowed to have multiple
64                                                    definition for the same register at a point) */
65         arch_register_type_state        = 32, /**< The register represents a state that should be handled by
66                                                    bestate code */
67 } arch_register_type_t;
68
69 /**
70  * Different types of register allocation requirements.
71  */
72 typedef enum arch_register_req_type_t {
73         arch_register_req_type_none              = 0, /**< No register requirement. */
74         arch_register_req_type_normal            = 1U << 0, /**< All registers in the class are allowed. */
75         arch_register_req_type_limited           = 1U << 1, /**< Only a real subset of the class is allowed. */
76         arch_register_req_type_should_be_same    = 1U << 2, /**< The register should be equal to another one at the node. */
77         arch_register_req_type_must_be_different = 1U << 3, /**< The register must be unequal from some other at the node. */
78         arch_register_req_type_ignore            = 1U << 4, /**< ignore while allocating registers */
79         arch_register_req_type_produces_sp       = 1U << 5, /**< the output produces a new value for the stack pointer */
80 } arch_register_req_type_t;
81
82 extern const arch_register_req_t *arch_no_register_req;
83
84 /**
85  * Format a register requirements information into a string.
86  * @param buf The string where to put it to.
87  * @param len The size of @p buf.
88  * @param req The requirements structure to format.
89  * @return    A pointer to buf.
90  */
91 extern char *arch_register_req_format(char *buf, size_t len, const arch_register_req_t *req, const ir_node *node);
92
93 /**
94  * Certain node classes which are relevant for the register allocator.
95  */
96 typedef enum arch_irn_class_t {
97         arch_irn_class_spill      = 1 << 0,
98         arch_irn_class_reload     = 1 << 1,
99         arch_irn_class_remat      = 1 << 2,
100         arch_irn_class_copy       = 1 << 3,
101         arch_irn_class_perm       = 1 << 4,
102         arch_irn_class_branch     = 1 << 5
103 } arch_irn_class_t;
104
105 /**
106  * Some flags describing a node in more detail.
107  */
108 typedef enum arch_irn_flags_t {
109         arch_irn_flags_none             = 0,       /**< Node flags. */
110         arch_irn_flags_dont_spill       = 1U << 0, /**< This must not be spilled. */
111         arch_irn_flags_rematerializable = 1U << 1, /**< This can be replicated instead of spilled/reloaded. */
112         arch_irn_flags_modify_flags     = 1U << 2  /**< I modify flags. */
113 } arch_irn_flags_t;
114
115 void arch_set_frame_offset(ir_node *irn, int bias);
116
117 ir_entity *arch_get_frame_entity(const ir_node *irn);
118 void       arch_set_frame_entity(ir_node *irn, ir_entity *ent);
119 int        arch_get_sp_bias(ir_node *irn);
120
121 int             arch_get_op_estimated_cost(const ir_node *irn);
122 arch_inverse_t *arch_get_inverse(const ir_node *irn, int i, arch_inverse_t *inverse, struct obstack *obstack);
123 int             arch_possible_memory_operand(const ir_node *irn, unsigned int i);
124 void            arch_perform_memory_operand(ir_node *irn, ir_node *spill, unsigned int i);
125
126 /**
127  * Get the register requirements for a node.
128  * @param irn The node.
129  * @param pos The position of the operand you're interested in.
130  * @return    A pointer to the register requirements.  If NULL is returned, the
131  *            operand was no register operand.
132  */
133 const arch_register_req_t *arch_get_register_req(const ir_node *irn, int pos);
134
135 #define arch_get_register_req_out(irn) arch_get_register_req(irn, -1)
136
137 /**
138  * Put all registers which shall not be ignored by the register
139  * allocator in a bit set.
140  * @param cls The register class to consider.
141  * @param bs  The bit set to put the registers to.
142  */
143 extern void arch_put_non_ignore_regs(const arch_register_class_t *cls, bitset_t *bs);
144
145 /**
146  * Check, if a register is assignable to an operand of a node.
147  * @param irn The node.
148  * @param pos The position of the operand.
149  * @param reg The register.
150  * @return    1, if the register might be allocated to the operand 0 if not.
151  */
152 int arch_reg_is_allocatable(const ir_node *irn, int pos, const arch_register_t *reg);
153
154 #define arch_reg_out_is_allocatable(irn, reg) arch_reg_is_allocatable(irn, -1, reg)
155
156 /**
157  * Get the register class of an operand of a node.
158  * @param irn The node.
159  * @param pos The position of the operand, -1 for the output.
160  * @return    The register class of the operand or NULL, if
161  *            operand is a non-register operand.
162  */
163 const arch_register_class_t *arch_get_irn_reg_class(const ir_node *irn, int pos);
164
165 #define arch_get_irn_reg_class_out(irn) arch_get_irn_reg_class(irn, -1)
166
167 /**
168  * Get the register allocated at a certain output operand of a node.
169  * @param irn The node.
170  * @return    The register allocated for this operand
171  */
172 const arch_register_t *arch_get_irn_register(const ir_node *irn);
173 const arch_register_t *arch_irn_get_register(const ir_node *irn, int pos);
174
175 /**
176  * Set the register for a certain output operand.
177  * @param irn The node.
178  * @param reg The register.
179  */
180 void arch_set_irn_register(ir_node *irn, const arch_register_t *reg);
181 void arch_irn_set_register(ir_node *irn, int pos, const arch_register_t *reg);
182
183 /**
184  * Classify a node.
185  * @param irn The node.
186  * @return A classification of the node.
187  */
188 arch_irn_class_t arch_irn_classify(const ir_node *irn);
189
190 #define arch_irn_class_is(irn, irn_class) ((arch_irn_classify(irn) & arch_irn_class_ ## irn_class) != 0)
191
192 /**
193  * Get the flags of a node.
194  * @param irn The node.
195  * @return The flags.
196  */
197 arch_irn_flags_t arch_irn_get_flags(const ir_node *irn);
198
199 void arch_irn_set_flags(ir_node *node, arch_irn_flags_t flags);
200 void arch_irn_add_flags(ir_node *node, arch_irn_flags_t flags);
201
202 #define arch_irn_is(irn, flag) ((arch_irn_get_flags(irn) & arch_irn_flags_ ## flag) != 0)
203
204 /**
205  * Get the operations of an irn.
206  * @param self The handler from which the method is invoked.
207  * @param irn Some node.
208  * @return Operations for that irn.
209  */
210 typedef const void *(arch_get_irn_ops_t)(const ir_node *irn);
211
212 /**
213  * Initialize the architecture environment struct.
214  * @param isa           The isa which shall be put into the environment.
215  * @param file_handle   The file handle
216  * @return The environment.
217  */
218 extern arch_env_t *arch_env_init(const arch_isa_if_t *isa,
219                                  FILE *file_handle, be_main_env_t *main_env);
220
221 /**
222  * Register an instruction set architecture
223  */
224 void be_register_isa_if(const char *name, const arch_isa_if_t *isa);
225
226 #endif /* FIRM_BE_BEARCH_H */