b83a0a4243c45ec946fcbedb3bea144dd26775f4
[libfirm] / ir / be / bearch.h
1
2 #ifndef _FIRM_BEARCH_H
3 #define _FIRM_BEARCH_H
4
5 #ifdef __cplusplus
6 extern "C" {
7 #endif
8
9 struct bitset_t;
10
11 /*
12  * Define the types of the arch facility.
13  * All arch object names are stored in bearch_obj.def
14  */
15 #define ARCH_OBJ(x,list) typedef struct _arch_ ## x ## _t arch_ ## x ## _t;
16 #include "bearch_obj.def"
17 #undef ARCH_OBJ
18
19 /**
20  * A callback to determine the set of valid registers.
21  *
22  * @param irn                           The node which represents an instance of the instruction.
23  * @param pos                           The number of the insn's operand to consider.
24  * @param valid_regs    A bitset where all valid registers are put.
25  */
26 typedef void (arch_register_callback_t)(ir_node *irn, int pos, struct bitset_t *valid_regs);
27
28
29 /**
30  * Add a new instruction set architecture.
31  * @param name The name of the isa.
32  * @return The isa object.
33  */
34 arch_isa_t *arch_add_isa(const char *name);
35
36 /**
37  * Add a register class to the isa.
38  * @param isa The isa to add the reg class to.
39  * @param name The name of the register class.
40  * @param n_regs The number of registers in that class.
41  * @param mode The mode of the registers in that class.
42  */
43 arch_register_class_t *arch_add_register_class(arch_isa_t *isa, const char *name, int n_regs);
44
45 /**
46  * Add a register set to an isa.
47  * @param cls The register class the set belongs to.
48  * @param name The name of the register set.
49  * @return The register set.
50  */
51 arch_register_set_t *arch_add_register_set(arch_isa_t *isa,
52                 const arch_register_class_t *cls, const char *name);
53
54 /**
55  * Add a register to a register set.
56  * @param set The register set.
57  * @param index The index of the register in the class.
58  */
59 void arch_register_set_add_register(arch_register_set_t *set, int index);
60
61 /**
62  * Add a register to a register class.
63  * @param cls The register class.
64  * @param index The index of the register (its number within the
65  * class).
66  * @param name The name of the register.
67  * @return The register.
68  */
69 arch_register_t *arch_add_register(arch_register_class_t *cls, int index, const char *name);
70
71 /**
72  * Add an immediate to the instruction set architecture.
73  * @param isa The isa.
74  * @param name The name of the immediate.
75  * @param mode The mode of the immediate.
76  * @return The immediate.
77  */
78 arch_immediate_t *arch_add_immediate(arch_isa_t *isa, const char *name, ir_mode *mode);
79
80 /**
81  * Add an instruction format to an isa.
82  * @param isa The isa.
83  * @param name The name of the instruction format.
84  * @param n_in The number of in operands.
85  * @param n_out The number of out operands.
86  * @return The format.
87  */
88 arch_insn_format_t *arch_add_insn_format(arch_isa_t *isa, const char *name, int n_in, int n_out);
89
90 /**
91  * Add a register set as an operand type.
92  * @param fmt The instruction format whose operand is to be set.
93  * @param pos The position of the operand. Note that input operands are
94  * numbered from 0 to n and output operands from -1 to -m.
95  * @param set The register set.
96  * @return The corresponding operand type.
97  */
98 arch_operand_t *arch_set_operand_register_set(arch_insn_format_t *fmt,
99                 int pos, const arch_register_set_t *set);
100
101 /**
102  * Set the operand to a callback.
103  * @param fmt The instruction format.
104  * @param pos The position of the operand. See also
105  * arch_set_operand_register_set().
106  * @param cb The callback function which decides about the registers to
107  * allocate.
108  * @return The operand.
109  */
110 arch_operand_t *arch_set_operand_callback(arch_insn_format_t *fmt,
111                 int pos, arch_register_callback_t *cb);
112
113 /**
114  * Mark an operand as an immediate.
115  * @param fmt The instructionm format.
116  * @param pos The position. See also arch_set_operand_register_set().
117  * @param imm The immediate which expected.
118  * @return The operand.
119  */
120 arch_operand_t *arch_set_operand_immediate(arch_insn_format_t *fmt,
121                 int pos, const arch_immediate_t *imm);
122
123 /**
124  * Mark an operand as a memory operand.
125  * @param fmt The format.
126  * @param pos The position of the operand.
127  * @return The operand.
128  */
129 arch_operand_t *arch_set_operand_memory(arch_insn_format_t *fmt, int pos);
130
131 /**
132  * Denote, that an operand must equal another.
133  * This only makes sense with registers. Then, this operand must get the
134  * same register as the one denoted by same_as_pos.
135  *
136  * @param fmt The instruction format.
137  * @param pos The position of the operand.
138  * @param same_as_pos The position of the other operand.
139  * @return The operand.
140  */
141 arch_operand_t *arch_set_operand_equals(arch_insn_format_t *fmt, int pos, int same_as_pos);
142
143
144 /**
145  * Add an instruction to the isa.
146  * @param fmt The instructon format.
147  * @param name The name of the instruction.
148  */
149 arch_insn_t *arch_add_insn(arch_insn_format_t *fmt, const char *name);
150
151
152 /**
153  * Find an instruction format.
154  * @param isa The isa.
155  * @param name The name of the instruction format.
156  * @return The instruction format, if it was added before, or NULL if it
157  * is unknown.
158  */
159 arch_insn_format_t *arch_find_insn_format(const arch_isa_t *isa, const char *name);
160
161 /**
162  * Find an isa.
163  * @param name The name of the isa.
164  * @return The isa if it has been added, or NULl if it is unknwon.
165  */
166 arch_isa_t *arch_find_isa(const char *name);
167
168 /**
169  * Find an sintrsuction in the instruction set architecture.
170  * @param isa The instruction set architecture.
171  * @param name The name of the instruction.
172  * @return The instruction or NULL if no such instruction exists.
173  */
174 arch_insn_t *arch_find_insn(const arch_isa_t *isa, const char *name);
175
176 /**
177  * Find a register class of an isa.
178  * @param isa The isa.
179  * @param name The name of the register class.
180  * @return The register class, if it has been added, NULL if it is
181  * unknown.
182  */
183 arch_register_class_t *arch_find_register_class(const arch_isa_t *isa, const char *name);
184
185 /**
186  * Find a register set in an isa.
187  * @param isa The isa.
188  * @param name The name of the register set.
189  * @return The register set or NULL if it does not exist.
190  */
191 arch_register_set_t *arch_find_register_set(const arch_isa_t *isa, const char *name);
192
193 /**
194  * find an immediate registered in some isa.
195  * @param isa The isa.
196  * @param name The name of the immediate.
197  * @return The immediate, or NULL if it did not exist.
198  */
199 arch_immediate_t *arch_find_immediate(const arch_isa_t *isa, const char *name);
200
201 /**
202  * Get the register set for a register class.
203  * Each register class possesses a set containing all registers known in
204  * the class.
205  * @param cls The class.
206  * @return The register set for the register class.
207  */
208 arch_register_set_t *arch_get_register_set_for_class(arch_register_class_t *cls);
209
210 /**
211  * Get a mode which is a placeholder for an unknown mode.
212  * @return Some mode to use, if you don't know which mode you will need,
213  * yet.
214  */
215 ir_mode *arch_get_unknown_mode(void);
216
217 /**
218  * Make a new bare instance of an insn.
219  * @param insn The instruction.
220  * @param irg The graph.
221  * @param arity The number of operands to reserve for the ir_node.
222  * @return An ir node. Its block and operands are set to an Unknown
223  * node.
224  */
225 ir_node *arch_new_node_bare(const arch_insn_t *insn, ir_graph *irg, int arity);
226
227 /**
228  * Make a new instance of an insn.
229  * This functions works like new_ir_node() and uses the op in the
230  * insn.
231  */
232 ir_node *arch_new_node(const arch_insn_t *insn, ir_graph *irg, ir_node *block,
233                 ir_mode *mode, int arity, ir_node **in);
234
235 #ifdef __cplusplus
236 }
237 #endif
238
239 #endif