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 unsigned comprises_full_class : 1; /**< True, if all registers of the class
91 are contained in this set. */
92 int regs[1]; /**< An array containing 0/1 at place i
93 whether the register with index i is
97 static INLINE int _arch_register_in_set(const arch_register_set_t *set, const arch_register_t *reg)
99 if(reg->reg_class != set->reg_class)
102 return set->regs[reg->index];
107 * A class of registers.
108 * Like general purpose or floating point.
110 struct _arch_register_class_t {
111 arch_header_t header;
112 struct list_head list; /**< list head to list up in the list of all
113 register classes in an isa. */
114 arch_register_set_t *set; /**< A register set containing all registers
116 int n_regs; /**< Number of registers in this class. */
117 arch_register_t *regs[1]; /**< The array of registers. */
120 static INLINE const arch_register_t *_arch_register_for_index(const arch_register_class_t *cls, int idx)
122 assert(0 <= idx && idx <= cls->n_regs);
123 return cls->regs[idx];
127 * Get the register set for a register class.
128 * @param cls The register class.
129 * @return The set containing all registers in the class.
131 static INLINE arch_register_set_t *_arch_get_register_set_for_class(const arch_register_class_t *cls)
139 struct _arch_immediate_t {
140 arch_header_t header;
141 ir_mode *mode; /**< The mode of the immediate. */
145 * The member of an enum.
147 struct _arch_enum_member_t {
148 arch_header_t header; /**< The omnipresent header. */
149 arch_enum_t *enm; /**< The enum, this member belongs to. */
153 * An enumeration operand type.
155 * Enumeration operand types can be used to describe the variants
156 * of an instruction, like giving the cases for a compare (gt, lt,
157 * eq, ...) some other special attributes of an instruction.
159 struct _arch_enum_t {
160 arch_header_t header;
161 int n_members; /**< The number of members in this enum. */
162 arch_enum_member_t *members[1]; /**< The array of members. */
165 typedef enum _arch_operand_type_t {
166 arch_operand_type_ir = 0,
167 arch_operand_type_variadic,
168 arch_operand_type_symconst,
169 arch_operand_type_register_set,
170 arch_operand_type_immediate
171 } arch_operand_type_t;
176 * The data for the different flavours of operand types.
178 typedef union _arch_operand_data_t {
179 arch_register_callback_t *callback; /**< The set of valid registers is determined
180 by a callback function. */
182 const arch_register_set_t *set; /**< The set of valid registers is directly
183 given. Note, that if an insn has no constraints,
184 the set comprises all registers in the
187 const arch_immediate_t *imm; /**< If the operand is an immediate
188 operand, this describes the kind of
191 const arch_enum_t *enm; /**< Some enumeration value. */
192 } arch_operand_data_t;
195 * An operand to an instruction.
197 struct _arch_operand_t {
198 int offset_in_irn_data;
199 arch_operand_type_t type; /**< The type of the operand. */
200 arch_operand_data_t data; /**< The payload. */
204 * An instruction format.
206 struct _arch_insn_format_t {
207 arch_header_t header;
208 int n_in; /**< Number of in operands. */
209 int n_out; /**< Number of out operands. */
212 arch_operand_t operands[1]; /**< Array with operands. */
215 #define arch_get_in_operand(fmt, index) (&((fmt)->operands[(fmt)->n_out + (index)]))
216 #define arch_get_out_operand(fmt, index) (&((fmt)->operands[index]))
221 struct _arch_insn_t {
222 arch_header_t header;
223 const arch_insn_format_t *format; /**< The format of the instruction. */
224 ir_op *op; /**< The firm opcode for this insn. */
228 * This truct is placed into each ir_node which is made from an arch
229 * insn (If the node is made via arch_new node).
231 typedef struct _arch_irn_data_t {
232 unsigned magic; /**< A magic number to tell if node is an
234 const arch_insn_t *insn; /**< The insn this nodes instantiates. */
237 #define _arch_get_irn_data(irn) ((const arch_irn_data_t *) &((irn)->attr))
240 * Check, if an ir node is made by the arch module.
241 * @param irn An ir node.
242 * @return 1 if the node was made via arch_new_node() or 0 otherwise.
244 static INLINE int _arch_is_irn(const ir_node *irn)
246 return _arch_get_irn_data(irn)->magic == ARCH_IRN_FOURCC;
249 static INLINE const arch_insn_t *_arch_irn_get_insn(const ir_node *irn)
251 if(!_arch_is_irn(irn))
254 return _arch_get_irn_data(irn)->insn;
259 * An instruction set architecture.
262 arch_header_t header;
263 struct list_head heads[arch_kind_last]; /**< List heads to list objects created in the
264 context of this isa. Note: some of the list heads
268 struct _arch_implementation_t {
269 const arch_isa_t *isa;
274 #endif /* _FIRM_BEARCH_T_H */