2 #ifndef _FIRM_BEARCH_T_H
3 #define _FIRM_BEARCH_T_H
5 #include "firm_config.h"
19 #define ARCH_IRN_FOURCC FOURCC('A', 'R', 'C', 'H')
22 * Flags for registers.
27 * The register is invariant concerning writes.
28 * Examples are the 0 registers in RISC architectures.
30 REG_WRITE_INVARIAT = 1
32 } arch_register_flags_t;
35 #define ARCH_OBJ(x,list) arch_kind_##x,
36 #include "bearch_obj.def"
42 * A header which each of the arch structs should posess.
48 struct list_head list;
54 * Get the architecture an arch object belongs to.
55 * @param obj The object.
56 * @return The architecture it belongs to.
58 static INLINE arch_isa_t *arch_obj_get_isa(const void *obj)
60 return ((const arch_header_t *) obj)->isa;
63 typedef enum _arch_register_flag_t {
64 arch_register_flag_none,
65 arch_register_flag_caller_saved, /**< The register must be saved by the caller
66 upon a function call. It thus can be overwritten
67 in the called function. */
68 arch_register_flag_callee_saved, /**< The register must be saved by the called function,
69 it thus survives a function call. */
70 arch_register_flag_ignore /**< Do not consider this register when allocating. */
71 } arch_register_flag_t;
76 struct _arch_register_t {
78 int index; /**< The index of the register in the class. */
79 const arch_register_class_t *reg_class; /**< The class the register belongs to. */
80 arch_register_flag_t flags; /**< Flags describing several properties of
85 * A (sub-) set of registers.
87 struct _arch_register_set_t {
89 const struct _arch_register_class_t *reg_class; /**< The register class for this set. */
90 char regs[1]; /**< An array containing 0/1 at place i
91 whether the register with index i is
95 static INLINE int _arch_register_in_set(const arch_register_set_t *set, const arch_register_t *reg)
97 if(reg->reg_class != set->reg_class)
100 return set->regs[reg->index];
105 * A class of registers.
106 * Like general purpose or floating point.
108 struct _arch_register_class_t {
109 arch_header_t header;
110 struct list_head list; /**< list head to list up in the list of all
111 register classes in an isa. */
112 arch_register_set_t *set; /**< A register set containing all registers
114 int n_regs; /**< Number of registers in this class. */
115 arch_register_t *regs[1]; /**< The array of registers. */
118 static INLINE const arch_register_t *_arch_register_for_index(const arch_register_class_t *cls, int idx)
120 assert(0 <= idx && idx <= cls->n_regs);
121 return cls->regs[idx];
125 * Get the register set for a register class.
126 * @param cls The register class.
127 * @return The set containing all registers in the class.
129 static INLINE arch_register_set_t *_arch_get_register_set_for_class(const arch_register_class_t *cls)
137 struct _arch_immediate_t {
138 arch_header_t header;
139 ir_mode *mode; /**< The mode of the immediate. */
143 * The member of an enum.
145 struct _arch_enum_member_t {
146 arch_header_t header; /**< The omnipresent header. */
147 arch_enum_t *enm; /**< The enum, this member belongs to. */
151 * An enumeration operand type.
153 * Enumeration operand types can be used to describe the variants
154 * of an instruction, like giving the cases for a compare (gt, lt,
155 * eq, ...) some other special attributes of an instruction.
157 struct _arch_enum_t {
158 arch_header_t header;
159 int n_members; /**< The number of members in this enum. */
160 arch_enum_member_t *members[1]; /**< The array of members. */
163 typedef enum _arch_operand_type_t {
164 #define ARCH_OPERAND_TYPE(name,size_in_irn) arch_operand_type_ ## name,
165 #include "bearch_operand_types.def"
166 #undef ARCH_OPERAND_TYPE
167 arch_operand_type_last
168 } arch_operand_type_t;
173 * The data for the different flavours of operand types.
175 typedef union _arch_operand_data_t {
176 arch_register_callback_t *callback; /**< The set of valid registers is determined
177 by a callback function. */
179 const arch_register_set_t *set; /**< The set of valid registers is directly
180 given. Note, that if an insn has no constraints,
181 the set comprises all registers in the
184 const arch_immediate_t *imm; /**< If the operand is an immediate
185 operand, this describes the kind of
188 const arch_enum_t *enm; /**< Some enumeration value. */
190 int same_as_pos; /**< 'Same as' position for equals. */
191 } arch_operand_data_t;
194 * An operand to an instruction.
196 struct _arch_operand_t {
197 arch_operand_type_t type; /**< The type of the operand. */
198 arch_operand_data_t data; /**< The payload. */
202 * An instruction format.
204 struct _arch_insn_format_t {
205 arch_header_t header;
206 int n_in; /**< Number of in operands. */
207 int n_out; /**< Number of out operands. */
209 arch_operand_t operands[1]; /**< Array with operands. */
213 * Transform the position into an offset which is suitable to
214 * index the operands array in the format.
217 * operand: in0 in1 in2 ... out0 out1 out2
218 * position: 0 1 2 -1 -2 -3
220 #define arch_inout_to_index(fmt, pos) ((pos) >= 0 ? (pos) : -((pos) + 1) + (fmt)->n_in)
222 #define arch_get_in_operand(fmt, pos) (&((fmt)->operands[arch_inout_to_index(fmt, pos)]))
223 #define arch_get_out_operand(fmt, pos) (&((fmt)->operands[arch_inout_to_index(fmt, -((pos) + 1))]))
229 struct _arch_insn_t {
230 arch_header_t header;
231 const arch_insn_format_t *format; /**< The format of the instruction. */
232 ir_op *op; /**< The firm opcode for this insn. */
236 * This truct is placed into each ir_node which is made from an arch
237 * insn (If the node is made via arch_new node).
239 typedef struct _arch_irn_data_t {
240 unsigned magic; /**< A magic number to tell if node is an
242 const arch_insn_t *insn; /**< The insn this nodes instantiates. */
245 #define _arch_get_irn_data(irn) ((const arch_irn_data_t *) &((irn)->attr))
248 * Check, if an ir node is made by the arch module.
249 * @param irn An ir node.
250 * @return 1 if the node was made via arch_new_node() or 0 otherwise.
252 static INLINE int _arch_is_irn(const ir_node *irn)
254 return _arch_get_irn_data(irn)->magic == ARCH_IRN_FOURCC;
257 static INLINE const arch_insn_t *_arch_irn_get_insn(const ir_node *irn)
259 if(!_arch_is_irn(irn))
262 return _arch_get_irn_data(irn)->insn;
267 * An instruction set architecture.
270 arch_header_t header;
271 struct list_head heads[arch_kind_last]; /**< List heads to list objects created in the
272 context of this isa. Note: some of the list heads
276 struct _arch_implementation_t {
277 const arch_isa_t *isa;
282 #endif /* _FIRM_BEARCH_T_H */