5 #include "firm_config.h"
19 #define ARCH_OBJ(name,x) typedef struct _arch_ ## name ## _t arch_ ## name ## _t;
20 #include "bearch_obj.def"
25 typedef enum _arch_register_type_t {
26 arch_register_type_none = 0,
27 arch_register_type_write_invariant,
28 arch_register_type_caller_saved, /**< The register must be saved by the caller
29 upon a function call. It thus can be overwritten
30 in the called function. */
31 arch_register_type_callee_saved, /**< The register must be saved by the called function,
32 it thus survives a function call. */
33 arch_register_type_ignore /**< Do not consider this register when allocating. */
34 } arch_register_type_t;
39 struct _arch_register_t {
40 const char *name; /**< The name of the register. */
41 const arch_register_class_t *reg_class; /**< The class the register belongs to. */
42 int index; /**< The index of the register in the class. */
43 arch_register_type_t type; /**< The type of the register. */
46 static INLINE const arch_register_class_t *
47 _arch_register_get_class(const arch_register_t *reg)
49 return reg->reg_class;
52 static INLINE int _arch_register_get_index(const arch_register_t *reg)
57 #define arch_register_get_class(reg) _arch_register_get_class(reg)
58 #define arch_register_get_index(reg) _arch_register_get_index(reg)
61 * A (sub-) set of registers.
63 struct _arch_register_set_t {
64 const struct _arch_register_class_t *reg_class; /**< The register class for this set. */
65 int *regs; /**< An array containing 0/1 at place i
66 whether the register with index i is
70 static INLINE int _arch_register_in_set(const arch_register_set_t *set,
71 const arch_register_t *reg)
73 if(reg->reg_class != set->reg_class)
76 return set->regs[reg->index];
81 * A class of registers.
82 * Like general purpose or floating point.
84 struct _arch_register_class_t {
85 const char *name; /**< The name of the register. */
86 arch_register_set_t *set; /**< A register set containing all registers
88 int n_regs; /**< Number of registers in this class. */
89 const arch_register_t *regs; /**< The array of registers. */
92 #define arch_register_class_n_regs(cls) ((cls)->n_regs)
94 static INLINE const arch_register_t *
95 _arch_register_for_index(const arch_register_class_t *cls, int idx)
97 assert(0 <= idx && idx < cls->n_regs);
98 return &cls->regs[idx];
101 #define arch_register_for_index(cls, idx) \
102 _arch_register_for_index(cls, idx)
105 * Get the register set for a register class.
106 * @param cls The register class.
107 * @return The set containing all registers in the class.
109 #define arch_get_register_set_for_class(cls) ((cls)->set)
114 struct _arch_immediate_t {
115 const char *name; /**< The name of the immediate. */
116 ir_mode *mode; /**< The mode of the immediate. */
120 * The member of an enum.
122 struct _arch_enum_member_t {
123 arch_enum_t *enm; /**< The enum, this member belongs to. */
127 * An enumeration operand type.
129 * Enumeration operand types can be used to describe the variants
130 * of an instruction, like giving the cases for a compare (gt, lt,
131 * eq, ...) some other special attributes of an instruction.
133 struct _arch_enum_t {
134 int n_members; /**< The number of members in this enum. */
135 arch_enum_member_t *members[1]; /**< The array of members. */
138 typedef enum _arch_operand_type_t {
139 #define ARCH_OPERAND_TYPE(name,size_in_irn) arch_operand_type_ ## name,
140 #include "bearch_operand_types.def"
141 #undef ARCH_OPERAND_TYPE
142 arch_operand_type_last
143 } arch_operand_type_t;
148 * The data for the different flavours of operand types.
150 typedef union _arch_operand_data_t {
151 const arch_register_set_t *set; /**< The set of valid registers is directly
152 given. Note, that if an insn has no constraints,
153 the set comprises all registers in the
156 const arch_immediate_t *imm; /**< If the operand is an immediate
157 operand, this describes the kind of
160 const arch_enum_t *enm; /**< Some enumeration value. */
162 int same_as_pos; /**< 'Same as' position for equals. */
163 } arch_operand_data_t;
166 * An operand to an instruction.
168 struct _arch_operand_t {
169 arch_operand_type_t type; /**< The type of the operand. */
170 arch_operand_data_t data; /**< The payload. */
174 * An instruction format.
176 struct _arch_insn_format_t {
177 int n_in; /**< Number of in operands. */
178 int n_out; /**< Number of out operands. */
180 arch_operand_t * const *in_operands; /**< In operands. */
181 arch_operand_t * const *out_operands; /**< Out operands. */
187 struct _arch_insn_t {
188 const arch_insn_format_t *format; /**< The format of the instruction. */
189 ir_op *op; /**< The firm opcode for this insn. */
192 #define arch_insn_is_allocatable(insn,reg) \
193 ((irn)->get_allocatable_regs(irn, cls, NULL) != 0)
196 * Architecture interface.
198 struct _arch_isa_if_t {
201 * Initialize the isa interface.
206 * Get the the number of register classes in the isa.
207 * @return The number of register classes.
209 int (*get_n_reg_class)(void);
212 * Get the i-th register class.
213 * @param i The number of the register class.
214 * @return The register class.
216 const arch_register_class_t *(*get_reg_class)(int i);
219 * Put all registers of a given class which are allocatable to a
220 * certain node into a bitset.
221 * The bitset contains the indices of the registers concerning
222 * the register class @p cls.
223 * @param irn The node.
224 * @param cls The register class.
225 * @param bs The bitset. Can be NULL.
226 * @return The number of registers which are allocatable at this node.
228 int (*get_allocatable_regs)(const ir_node *irn,
229 const arch_register_class_t *cls, struct _bitset_t *bs);
231 int (*is_reg_allocatable)(const ir_node *irn, const arch_register_t *reg);
234 * Get the register class, the value of a node belongs to.
235 * @param irn The node.
236 * @return The register class of the registers which can hold the
237 * value of irn. If the node does not return a value, or possesses no
238 * suitable register class, NULL is returned.
240 const arch_register_class_t *(*get_irn_reg_class)(const ir_node *irn);
245 * Get an op for a name.
246 * @note This method may not be implemented.
247 * @param name The name of the op.
248 * @return The op with that name.
250 ir_op *(*get_op_by_name)(const char *name);
254 * Check, if the value of a node can be stored in a
255 * specific register class.
256 * @param isa The isa.
257 * @param irn The node.
258 * @param cls The register class.
259 * @return 1, if the value can be stored in the register class, 0 if
262 #define arch_isa_irn_has_reg_class(isa, irn, cls) \
263 ((isa)->get_irn_reg_class(irn) == (cls))
266 * Check, if a register is allocatable for an irn.
267 * @param irn The node.
268 * @param reg The register.
269 * @return 1, if the register can be allocated to this node, 0 if not.
271 #define arch_isa_reg_is_allocatable(irn, reg) \
272 ((isa)->is_reg_allocatable(irn, reg))
274 #endif /* _FIRM_BEARCH_H */