e017d8e3659661b5b284e96d768ad32a9c4d5bf2
[libfirm] / ir / be / bearch.h
1 #ifndef _FIRM_BEARCH_H
2 #define _FIRM_BEARCH_H
3
4 #include "firm_config.h"
5
6 #ifdef WITH_LIBCORE
7 #include <libcore/lc_opts.h>
8 #endif
9
10 #include "firm_types.h"
11
12 #include "bitset.h"
13
14 #include "belistsched.h"
15 #include "beilpsched.h"
16 #include "beabi_t.h"
17 #include "bearch_t.h"
18 #include "be_t.h"
19 #include "bemachine.h"
20 #include "beirg.h"
21
22 struct _be_node_factory_t;
23
24 typedef enum _arch_register_type_t {
25   arch_register_type_none         = 0,
26   arch_register_type_caller_save  = 1,  /**< The register must be saved by the caller
27                                              upon a function call. It thus can be overwritten
28                                              in the called function. */
29   arch_register_type_callee_save  = 2,  /**< The register must be saved by the caller
30                                              upon a function call. It thus can be overwritten
31                                              in the called function. */
32   arch_register_type_ignore       = 4,  /**< Do not consider this register when allocating. */
33   arch_register_type_joker        = 8,  /**< The emitter can choose an arbitrary register */
34   arch_register_type_virtual      = 16, /**< This is just a virtual register  */
35 } arch_register_type_t;
36
37 /**
38  * Convenience macro to check for register type.
39  * @param req   A pointer to register.
40  * @param kind  The kind of type to check for (see arch_register_type_t).
41  * @return      1, If register is of given kind, 0 if not.
42  */
43 #define arch_register_type_is(reg, kind) \
44   (((reg)->type & arch_register_type_ ## kind) != 0)
45
46 /**
47  * A register.
48  */
49 struct _arch_register_t {
50   const char                  *name;        /**< The name of the register. */
51   const arch_register_class_t *reg_class;   /**< The class the register belongs to. */
52   int                         index;        /**< The index of the register in the class. */
53   arch_register_type_t        type;         /**< The type of the register. */
54   void                        *data;        /**< Custom data. */
55 };
56
57 static INLINE const arch_register_class_t *
58 _arch_register_get_class(const arch_register_t *reg)
59 {
60   return reg->reg_class;
61 }
62
63 static INLINE int _arch_register_get_index(const arch_register_t *reg)
64 {
65   return reg->index;
66 }
67
68 static INLINE const char *_arch_register_get_name(const arch_register_t *reg)
69 {
70         return reg->name;
71 }
72
73 #define arch_register_get_class(reg)      _arch_register_get_class(reg)
74 #define arch_register_get_index(reg)      _arch_register_get_index(reg)
75 #define arch_register_get_name(reg)       _arch_register_get_name(reg)
76
77 /**
78  * A class of registers.
79  * Like general purpose or floating point.
80  */
81 struct _arch_register_class_t {
82   const char *name;               /**< The name of the register class. */
83   int n_regs;                     /**< Number of registers in this class. */
84   ir_mode *mode;                  /**< The mode of the register class. */
85   const arch_register_t *regs;    /**< The array of registers. */
86 };
87
88 /** return the number of registers in this register class */
89 #define arch_register_class_n_regs(cls) ((cls)->n_regs)
90
91 /** return the largest mode of this register class */
92 #define arch_register_class_mode(cls) ((cls)->mode)
93
94 /** return the name of this register class */
95 #define arch_register_class_name(cls) ((cls)->name)
96
97 /**
98  * Put all registers in a class into a bitset.
99  * @param cls The class.
100  * @param bs The bitset. May be NULL.
101  * @return The number of registers in the class.
102  */
103 extern int arch_register_class_put(const arch_register_class_t *cls, bitset_t *bs);
104
105 static INLINE const arch_register_t *
106 _arch_register_for_index(const arch_register_class_t *cls, int idx)
107 {
108   assert(0 <= idx && idx < cls->n_regs);
109   return &cls->regs[idx];
110 }
111
112 #define arch_register_for_index(cls, idx) \
113   _arch_register_for_index(cls, idx)
114
115 typedef enum _arch_operand_type_t {
116   arch_operand_type_invalid,
117   arch_operand_type_memory,
118   arch_operand_type_register,
119   arch_operand_type_immediate,
120   arch_operand_type_symconst,
121   arch_operand_type_last
122 } arch_operand_type_t;
123
124 /**
125  * Different types of register allocation requirements.
126  */
127 typedef enum _arch_register_req_type_t {
128   arch_register_req_type_none = 0,        /**< No register requirement. */
129
130   arch_register_req_type_normal = 1,      /**< All registers in the class
131                                                are allowed. */
132
133   arch_register_req_type_limited = 2,     /**< Only a real subset of
134                                                the class is allowed. */
135
136   arch_register_req_type_should_be_same = 4,       /**< The register should be equal
137                                                         another one at the node. */
138
139   arch_register_req_type_should_be_different = 8,  /**< The register must be unequal
140                                                         to some other at the node. */
141
142   arch_register_req_type_should_be_different_from_all = 16, /**< The register must be different from
143                                                         all in's at the node */
144 } arch_register_req_type_t;
145
146 /**
147  * Convenience macro to check for set constraints.
148  * @param req   A pointer to register requirements.
149  * @param kind  The kind of constraint to check for (see arch_register_req_type_t).
150  * @return      1, If the kind of constraint is present, 0 if not.
151  */
152 #define arch_register_req_is(req, kind) \
153         (((req)->type & (arch_register_req_type_ ## kind)) != 0)
154
155 /**
156  * Expresses requirements to register allocation for an operand.
157  */
158 typedef struct _arch_register_req_t {
159         arch_register_req_type_t type;          /**< The type of the constraint. */
160         const arch_register_class_t *cls;       /**< The register class this constraint belongs to. */
161
162         void (*limited)(void *limited_env, bitset_t *bs);
163                                           /**< In case of the 'limited'
164                                             constraint, this function
165                                             must put all allowable
166                                             registers in the bitset and
167                                             return the number of registers
168                                             in the bitset. */
169
170         void *limited_env;                    /**< This must passed to limited. */
171
172         ir_node *other_same;                      /**< The other which shall have the same reg
173                                                                                     as this one. (for case should_be_same). */
174
175         ir_node *other_different;             /**< The other node from which this one's register
176                                                                                     must be different (case must_be_different). */
177 } arch_register_req_t;
178
179 /**
180  * Format a register requirements information into a string.
181  * @param buf The string where to put it to.
182  * @param len The size of @p buf.
183  * @param req The requirements structure to format.
184  * @return    A pointer to buf.
185  */
186 extern char *arch_register_req_format(char *buf, size_t len, const arch_register_req_t *req);
187
188
189 /**
190  * Certain node classes which are relevant for the register allocator.
191  */
192 typedef enum _arch_irn_class_t {
193   arch_irn_class_normal     = 1 << 0,
194   arch_irn_class_spill      = 1 << 1,
195   arch_irn_class_reload     = 1 << 2,
196   arch_irn_class_copy       = 1 << 3,
197   arch_irn_class_perm       = 1 << 4,
198   arch_irn_class_branch     = 1 << 5,
199   arch_irn_class_call       = 1 << 6,
200   arch_irn_class_const      = 1 << 7,
201   arch_irn_class_load       = 1 << 8,
202   arch_irn_class_store      = 1 << 9,
203   arch_irn_class_stackparam = 1 << 10,
204 } arch_irn_class_t;
205
206 /**
207  * An inverse operation returned by the backend
208  */
209 typedef struct _arch_inverse_t {
210         int      n;       /**< count of nodes returned in nodes array */
211         int      costs;   /**< costs of this remat */
212
213         /**< nodes for this inverse operation. shall be in
214          *  schedule order. last element is the target value
215          */
216         ir_node  **nodes;
217 } arch_inverse_t;
218
219 /**
220  * Some flags describing a node in more detail.
221  */
222 typedef enum _arch_irn_flags_t {
223         arch_irn_flags_none             = 0, /**< Node flags. */
224         arch_irn_flags_dont_spill       = 1, /**< This must not be spilled. */
225         arch_irn_flags_rematerializable = 2, /**< This can be replicated instead of spilled/reloaded. */
226         arch_irn_flags_ignore           = 4, /**< Ignore node during register allocation. */
227         arch_irn_flags_modify_sp        = 8, /**< I modify the stack pointer. */
228         arch_irn_flags_last             = arch_irn_flags_modify_sp
229 } arch_irn_flags_t;
230
231 /**
232  * Get the string representation of a flag.
233  * This functions does not handle or'ed bitmasks of flags.
234  * @param flag The flag.
235  * @return The flag as a string.
236  */
237 extern const char *arch_irn_flag_str(arch_irn_flags_t flag);
238
239 struct _arch_irn_ops_if_t {
240
241   /**
242    * Get the register requirements for a given operand.
243    * @param self The self pointer.
244    * @param irn The node.
245    * @param pos The operand's position
246          *                                              (-1 for the result of the node, 0..n for the input
247          *                                              operands).
248    * @return    The register requirements for the selected operand.
249    *            The pointer returned is never NULL.
250    */
251   const arch_register_req_t *(*get_irn_reg_req)(const void *self,
252       arch_register_req_t *req, const ir_node *irn, int pos);
253
254   /**
255    * Set the register for an output operand.
256    * @param irn The node.
257    * @param reg The register allocated to that operand.
258    * @note      If the operand is not a register operand,
259    *            the call is ignored.
260    */
261   void (*set_irn_reg)(const void *self, ir_node *irn, const arch_register_t *reg);
262
263   /**
264    * Get the register allocated for an output operand.
265    * @param irn The node.
266    * @return    The register allocated at that operand. NULL, if
267    *            the operand was no register operand or
268    *            @c arch_register_invalid, if no register has yet been
269    *            allocated for this node.
270    */
271   const arch_register_t *(*get_irn_reg)(const void *self, const ir_node *irn);
272
273   /**
274    * Classify the node.
275    * @param irn The node.
276    * @return A classification.
277    */
278   arch_irn_class_t (*classify)(const void *self, const ir_node *irn);
279
280   /**
281    * Get the flags of a node.
282    * @param self The irn ops themselves.
283    * @param irn The node.
284    * @return A set of flags.
285    */
286   arch_irn_flags_t (*get_flags)(const void *self, const ir_node *irn);
287
288   /**
289    * Get the entity on the stack frame this node depends on.
290    * @param self The this pointer.
291    * @param irn  The node in question.
292    * @return The entity on the stack frame or NULL, if the node does not have a
293    *         stack frame entity.
294    */
295   ir_entity *(*get_frame_entity)(const void *self, const ir_node *irn);
296
297   /**
298    * Set the entity on the stack frame this node depends on.
299    * @param self The this pointer.
300    * @param irn  The node in question.
301    * @param ent  The entity to set
302    */
303   void (*set_frame_entity)(const void *self, ir_node *irn, ir_entity *ent);
304
305   /**
306    * Set the offset of a node carrying an entity on the stack frame.
307    * @param self The this pointer.
308    * @param irn  The node.
309    * @param offset The offset of the node's stack frame entity.
310    */
311   void (*set_frame_offset)(const void *self, ir_node *irn, int offset);
312
313   /**
314    * Returns the delta of the stackpointer for nodes that increment or
315    * decrement the stackpointer with a constant value. (push, pop
316    * nodes on most architectures).
317    * A positive value stands for an expanding stack area, a negative value for
318    * a shrinking one.
319    *
320    * @param self      The this pointer
321    * @param irn       The node
322    * @return          0 if the stackpointer is not modified with a constant
323    *                  value, otherwise the increment/decrement value
324    */
325   int (*get_sp_bias)(const void *self, const ir_node *irn);
326
327   /**
328    * Returns an inverse operation which yields the i-th argument
329    * of the given node as result.
330    *
331    * @param self      The this pointer.
332    * @param irn       The original operation
333    * @param i         Index of the argument we want the inverse operation to yield
334    * @param inverse   struct to be filled with the resulting inverse op
335    * @param obstack   The obstack to use for allocation of the returned nodes array
336    * @return          The inverse operation or NULL if operation invertible
337    */
338   arch_inverse_t *(*get_inverse)(const void *self, const ir_node *irn, int i, arch_inverse_t *inverse, struct obstack *obstack);
339
340   /**
341    * Get the estimated cycle count for @p irn.
342    *
343    * @param self The this pointer.
344    * @param irn  The node.
345    *
346    * @return     The estimated cycle count for this operation
347    */
348   int (*get_op_estimated_cost)(const void *self, const ir_node *irn);
349
350   /**
351    * Asks the backend whether operand @p i of @p irn can be loaded form memory internally
352    *
353    * @param self The this pointer.
354    * @param irn  The node.
355    * @param i    Index of the argument we would like to know whether @p irn can load it form memory internally
356    *
357    * @return     nonzero if argument can be loaded or zero otherwise
358    */
359   int (*possible_memory_operand)(const void *self, const ir_node *irn, unsigned int i);
360
361   /**
362    * Ask the backend to assimilate @p reload of operand @p i into @p irn.
363    *
364    * @param self   The this pointer.
365    * @param irn    The node.
366    * @param spill  The spill.
367    * @param i      The position of the reload.
368    */
369   void (*perform_memory_operand)(const void *self, ir_node *irn, ir_node *spill, unsigned int i);
370 };
371
372 /**
373  * irn_ops base class.
374  */
375 struct _arch_irn_ops_t {
376         const arch_irn_ops_if_t *impl;
377 };
378
379 extern const arch_irn_ops_t *arch_get_irn_ops(const arch_env_t *env, const ir_node *irn);
380
381 extern void arch_set_frame_offset(const arch_env_t *env, ir_node *irn, int bias);
382
383 extern ir_entity *arch_get_frame_entity(const arch_env_t *env, ir_node *irn);
384 extern void arch_set_frame_entity(const arch_env_t *env, ir_node *irn, ir_entity *ent);
385 extern int arch_get_sp_bias(const arch_env_t *env, ir_node *irn);
386
387 extern int arch_get_op_estimated_cost(const arch_env_t *env, const ir_node *irn);
388 extern arch_inverse_t *arch_get_inverse(const arch_env_t *env, const ir_node *irn, int i, arch_inverse_t *inverse, struct obstack *obstack);
389 extern int arch_possible_memory_operand(const arch_env_t *env, const ir_node *irn, unsigned int i);
390 extern void arch_perform_memory_operand(const arch_env_t *env, ir_node *irn, ir_node *spill, unsigned int i);
391
392 /**
393  * Get the register requirements for a node.
394  * @param env The architecture environment.
395  * @param req A pointer to a requirements structure, where the data can
396  *            be put into.
397  * @param irn The node.
398  * @param pos The position of the operand you're interested in.
399  * @return    A pointer to the register requirements which may <b>not</b>
400  *            neccessarily be equal to @p req. If NULL is returned, the
401  *            operand was no register operand.
402  */
403 extern const arch_register_req_t *
404 arch_get_register_req(const arch_env_t *env, arch_register_req_t *req,
405     const ir_node *irn, int pos);
406
407 /**
408  * Check if an operand is a register operand.
409  * @param env The environment.
410  * @param irn The node.
411  * @param pos The position of the operand.
412  * @return 1, if the operand is significant for register allocation, 0
413  * if not.
414  */
415 extern int arch_is_register_operand(const arch_env_t *env,
416     const ir_node *irn, int pos);
417
418 /**
419  * Get the number of allocatable registers concerning
420  * a register class for an operand of a node.
421  * @param env The environment.
422  * @param irn The node.
423  * @param pos The postition of the node's operand.
424  * @param bs  The bitset all allocatable registers shall be put into.
425  *            Note, that you can also pass NULL here. If you don't,
426  *            make sure, the bitset is as large as the register class
427  *            has registers.
428  * @return    The amount of registers allocatable for that operand.
429  */
430 extern int arch_get_allocatable_regs(const arch_env_t *env, const ir_node *irn, int pos, bitset_t *bs);
431
432 /**
433  * Put all registers which shall not be ignored by the register
434  * allocator in a bit set.
435  * @param env The arch env.
436  * @param cls The register class to consider.
437  * @param bs  The bit set to put the registers to.
438  */
439 extern void arch_put_non_ignore_regs(const arch_env_t *env, const arch_register_class_t *cls, bitset_t *bs);
440
441 /**
442  * Check, if a register is assignable to an operand of a node.
443  * @param env The architecture environment.
444  * @param irn The node.
445  * @param pos The position of the operand.
446  * @param reg The register.
447  * @return    1, if the register might be allocated to the operand 0 if not.
448  */
449 extern int arch_reg_is_allocatable(const arch_env_t *env,
450     const ir_node *irn, int pos, const arch_register_t *reg);
451
452 /**
453  * Get the register class of an operand of a node.
454  * @param env The architecture environment.
455  * @param irn The node.
456  * @param pos The position of the operand, -1 for the output.
457  * @return    The register class of the operand or NULL, if
458  *            operand is a non-register operand.
459  */
460 extern const arch_register_class_t *
461 arch_get_irn_reg_class(const arch_env_t *env, const ir_node *irn, int pos);
462
463 /**
464  * Get the register allocated at a certain output operand of a node.
465  * @param env The arch environment.
466  * @param irn The node.
467  * @return    The register allocated for this operand
468  */
469 extern const arch_register_t *
470 arch_get_irn_register(const arch_env_t *env, const ir_node *irn);
471
472 /**
473  * Set the register for a certain output operand.
474  * @param env The architecture environment.
475  * @param irn The node.
476  * @param idx The index of the output operand.
477  * @param reg The register.
478  */
479 extern void arch_set_irn_register(const arch_env_t *env, ir_node *irn,
480                 const arch_register_t *reg);
481
482 /**
483  * Classify a node.
484  * @param env The architecture environment.
485  * @param irn The node.
486  * @return A classification of the node.
487  */
488 extern arch_irn_class_t arch_irn_classify(const arch_env_t *env, const ir_node *irn);
489
490 #define arch_irn_class_is(env, irn, irn_class) ((arch_irn_classify(env, irn) & arch_irn_class_ ## irn_class) != 0)
491
492 /**
493  * Get the flags of a node.
494  * @param env The architecture environment.
495  * @param irn The node.
496  * @return The flags.
497  */
498 extern arch_irn_flags_t arch_irn_get_flags(const arch_env_t *env, const ir_node *irn);
499
500 #define arch_irn_is(env, irn, flag) ((arch_irn_get_flags(env, irn) & arch_irn_flags_ ## flag) != 0)
501
502 #define arch_irn_has_reg_class(env, irn, pos, cls) \
503   ((cls) == arch_get_irn_reg_class(env, irn, pos))
504
505 #define arch_irn_consider_in_reg_alloc(env, cls, irn) \
506         (arch_irn_has_reg_class(env, irn, -1, cls) && !arch_irn_is(env, irn, ignore))
507
508 /**
509  * Somebody who can be asked about IR nodes.
510  */
511 struct _arch_irn_handler_t {
512
513   /**
514     * Get the operations of an irn.
515     * @param self The handler from which the method is invoked.
516     * @param irn Some node.
517     * @return Operations for that irn.
518     */
519   const void *(*get_irn_ops)(const arch_irn_handler_t *handler,
520       const ir_node *irn);
521 };
522
523 /**
524  * The code generator interface.
525  */
526 struct _arch_code_generator_if_t {
527         /**
528          * Initialize the code generator.
529          * @param birg A backend IRG session.
530          * @return     A newly created code generator.
531          */
532         void *(*init)(be_irg_t *birg);
533
534         /**
535          * Called before abi introduce.
536          */
537         void (*before_abi)(void *self);
538
539         /**
540          * Called, when the graph is being normalized.
541          */
542         void (*prepare_graph)(void *self);
543
544         /**
545          * Backend may provide an own spiller.
546          * This spiller needs to spill all register classes.
547          */
548         void (*spill)(void *self, be_irg_t *birg);
549
550         /**
551          * Called before scheduling.
552          */
553         void (*before_sched)(void *self);
554
555         /**
556          * Called before register allocation.
557          */
558         void (*before_ra)(void *self);
559
560         /**
561          * Called after register allocation.
562          */
563         void (*after_ra)(void *self);
564
565         /**
566          * Called directly before done is called. This should be the last place
567          * where the irg is modified.
568          */
569         void (*finish)(void *self);
570
571         /**
572          * Called after everything happened. This call should emit the final
573          * assembly code but avoid changing the irg.
574          * The code generator must also be de-allocated here.
575          */
576         void (*done)(void *self);
577 };
578
579 /**
580  * helper macro: call function func from the code generator
581  * if it's implemented.
582  */
583 #define _arch_cg_call(cg, func) \
584 do { \
585         if((cg)->impl->func) \
586                 (cg)->impl->func(cg); \
587 } while(0)
588
589 #define _arch_cg_call_env(cg, env, func) \
590 do { \
591         if((cg)->impl->func) \
592                 (cg)->impl->func(cg, env); \
593 } while(0)
594
595 #define arch_code_generator_before_abi(cg)      _arch_cg_call(cg, before_abi)
596 #define arch_code_generator_prepare_graph(cg)   _arch_cg_call(cg, prepare_graph)
597 #define arch_code_generator_before_sched(cg)    _arch_cg_call(cg, before_sched)
598 #define arch_code_generator_before_ra(cg)       _arch_cg_call(cg, before_ra)
599 #define arch_code_generator_after_ra(cg)        _arch_cg_call(cg, after_ra)
600 #define arch_code_generator_finish(cg)          _arch_cg_call(cg, finish)
601 #define arch_code_generator_done(cg)            _arch_cg_call(cg, done)
602 #define arch_code_generator_spill(cg, birg)     _arch_cg_call_env(cg, birg, spill)
603 #define arch_code_generator_has_spiller(cg)     ((cg)->impl->spill != NULL)
604
605 /**
606  * Code generator base class.
607  */
608 struct _arch_code_generator_t {
609         const arch_code_generator_if_t *impl;
610 };
611
612 /**
613  * ISA base class.
614  */
615 struct _arch_isa_t {
616         const arch_isa_if_t   *impl;
617         const arch_register_t *sp;        /** The stack pointer register. */
618         const arch_register_t *bp;        /** The base pointer register. */
619         const int             stack_dir;  /** -1 for decreasing, 1 for increasing. */
620         const be_main_env_t   *main_env;  /** the be main environment */
621 };
622
623 #define arch_isa_stack_dir(isa)  ((isa)->stack_dir)
624 #define arch_isa_sp(isa)         ((isa)->sp)
625 #define arch_isa_bp(isa)         ((isa)->bp)
626
627 /**
628  * Architecture interface.
629  */
630 struct _arch_isa_if_t {
631         /**
632          * Initialize the isa interface.
633          * @param file_handle  the file handle to write the output to
634          * @param main_env     the be main environment
635          * @return a new isa instance
636          */
637         void *(*init)(FILE *file_handle);
638
639         /**
640          * Free the isa instance.
641          */
642         void (*done)(void *self);
643
644         /**
645          * Get the the number of register classes in the isa.
646          * @return The number of register classes.
647          */
648         int (*get_n_reg_class)(const void *self);
649
650         /**
651          * Get the i-th register class.
652          * @param i The number of the register class.
653          * @return The register class.
654          */
655         const arch_register_class_t *(*get_reg_class)(const void *self, int i);
656
657         /**
658          * Get the register class which shall be used to store a value of a given mode.
659          * @param self The this pointer.
660          * @param mode The mode in question.
661          * @return A register class which can hold values of the given mode.
662          */
663         const arch_register_class_t *(*get_reg_class_for_mode)(const void *self, const ir_mode *mode);
664
665         /**
666          * Get the ABI restrictions for procedure calls.
667          * @param self        The this pointer.
668          * @param method_type The type of the method (procedure) in question.
669          * @param p           The array of parameter locations to be filled.
670          */
671         void (*get_call_abi)(const void *self, ir_type *method_type, be_abi_call_t *abi);
672
673         /**
674          * The irn handler for this architecture.
675          * The irn handler is registered by the Firm back end
676          * when the architecture is initialized.
677          * (May be NULL).
678          */
679         const arch_irn_handler_t *(*get_irn_handler)(const void *self);
680
681         /**
682          * Get the code generator interface.
683          * @param self The this pointer.
684          * @return     Some code generator interface.
685          */
686         const arch_code_generator_if_t *(*get_code_generator_if)(void *self);
687
688         /**
689          * Get the list scheduler to use. There is already a selector given, the
690          * backend is free to modify and/or ignore it.
691          *
692          * @param self     The isa object.
693          * @param selector The selector given by options.
694          * @return         The list scheduler selector.
695          */
696         const list_sched_selector_t *(*get_list_sched_selector)(const void *self, list_sched_selector_t *selector);
697
698         /**
699          * Get the ILP scheduler to use.
700          * @param self  The isa object.
701          * @return      The ILP scheduler selector
702          */
703         const ilp_sched_selector_t *(*get_ilp_sched_selector)(const void *self);
704
705         /**
706          * Get the necessary alignment for storing a register of given class.
707          * @param self  The isa object.
708          * @param cls   The register class.
709          * @return      The alignment in bytes.
710          */
711         int (*get_reg_class_alignment)(const void *self, const arch_register_class_t *cls);
712
713         /**
714          * A "static" function, returns the frontend settings
715          * needed for this backend.
716          */
717         const backend_params *(*get_params)(void);
718
719         /**
720          * Returns an 2-dim array of execution units, @p irn can be executed on.
721          * The first dimension is the type, the second the allowed units of this type.
722          * Each dimension is a NULL terminated list.
723          * @param self  The isa object.
724          * @param irn   The node.
725          * @return An array of allowed execution units.
726          *         exec_unit = {
727          *                       { unit1_of_tp1, ..., unitX1_of_tp1, NULL },
728          *                       ...,
729          *                       { unit1_of_tpY, ..., unitXn_of_tpY, NULL },
730          *                       NULL
731          *                     };
732          */
733         const be_execution_unit_t ***(*get_allowed_execution_units)(const void *self, const ir_node *irn);
734
735         /**
736          * Return the abstract machine for this isa.
737          * @param self  The isa object.
738          */
739         const be_machine_t *(*get_machine)(const void *self);
740
741         /**
742          * Return an ordered list of irgs where code should be generated for.
743          * If NULL is returned, all irg will be taken into account and they will be
744          * generated in an arbitrary order.
745          * @param self   The isa object.
746          * @param irgs   A flexible array ARR_F of length 0 where the backend cann append the desired irgs.
747          * @return A flexible array ARR_F containing all desired irgs in the desired order.
748          */
749         ir_graph **(*get_backend_irg_list)(const void *self, ir_graph **irgs);
750 };
751
752 #define arch_isa_get_n_reg_class(isa)                  ((isa)->impl->get_n_reg_class(isa))
753 #define arch_isa_get_reg_class(isa,i)                  ((isa)->impl->get_reg_class(isa, i))
754 #define arch_isa_get_irn_handler(isa)                  ((isa)->impl->get_irn_handler(isa))
755 #define arch_isa_get_call_abi(isa,tp,abi)              ((isa)->impl->get_call_abi((isa), (tp), (abi)))
756 #define arch_isa_get_reg_class_for_mode(isa,mode)      ((isa)->impl->get_reg_class_for_mode((isa), (mode)))
757 #define arch_isa_make_code_generator(isa,irg)          ((isa)->impl->make_code_generator((isa), (irg)))
758 #define arch_isa_get_reg_class_alignment(isa, cls)     ((isa)->impl->get_reg_class_alignment((isa), (cls)))
759 #define arch_isa_get_allowed_execution_units(isa, irn) ((isa)->impl->get_allowed_execution_units((isa), (irn)))
760 #define arch_isa_get_machine(isa)                      ((isa)->impl->get_machine((isa)))
761 #define arch_isa_get_backend_irg_list(isa, irgs)       ((isa)->impl->get_backend_irg_list((isa), (irgs)))
762
763 #define ARCH_MAX_HANDLERS         8
764
765 /**
766  * Environment for the architecture infrastructure.
767  * Keep this everywhere you're going.
768  */
769 struct _arch_env_t {
770   const struct _be_node_factory_t *node_factory;  /**< The node factory for be nodes. */
771   arch_isa_t *isa;                                /**< The isa about which everything is. */
772
773   arch_irn_handler_t const *handlers[ARCH_MAX_HANDLERS]; /**< The handlers are organized as
774                                                            a stack. */
775
776   int handlers_tos;                                   /**< The stack pointer of the handler
777                                                         stack. */
778 };
779
780 /**
781  * Get the isa of an arch environment.
782  * @param env The environment.
783  * @return The isa with which the env was initialized with.
784  */
785 #define arch_env_get_isa(env)   ((env)->isa)
786
787 /**
788  * Initialize the architecture environment struct.
789  * @param isa           The isa which shall be put into the environment.
790  * @param file_handle   The file handle
791  * @return The environment.
792  */
793 extern arch_env_t *arch_env_init(arch_env_t *env, const arch_isa_if_t *isa, FILE *file_handle, be_main_env_t *main_env);
794
795 /**
796  * Add a node handler to the environment.
797  * @param env The environment.
798  * @param handler A node handler.
799  * @return The environment itself.
800  */
801 extern arch_env_t *arch_env_push_irn_handler(arch_env_t *env, const arch_irn_handler_t *handler);
802
803 /**
804  * Remove a node handler from the handler stack.
805  * @param env The architecture environment.
806  * @return The popped handler.
807  */
808 extern const arch_irn_handler_t *arch_env_pop_irn_handler(arch_env_t *env);
809
810 /**
811  * Register an instruction set architecture
812  */
813 void be_register_isa_if(const char *name, const arch_isa_if_t *isa);
814
815 #endif /* _FIRM_BEARCH_H */