- Bigger refactoring and cleanup in backend:
[libfirm] / ir / be / bearch.h
1 /*
2  * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
6  * This file may be distributed and/or modified under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation and appearing in the file LICENSE.GPL included in the
9  * packaging of this file.
10  *
11  * Licensees holding valid libFirm Professional Edition licenses may use
12  * this file in accordance with the libFirm Commercial License.
13  * Agreement provided with the Software.
14  *
15  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief       Processor architecture specification.
23  * @author      Sebastian Hack
24  * @version     $Id$
25  */
26 #ifndef FIRM_BE_BEARCH_H
27 #define FIRM_BE_BEARCH_H
28
29 #include <stdbool.h>
30
31 #include "firm_types.h"
32 #include "bitset.h"
33 #include "obst.h"
34 #include "raw_bitset.h"
35 #include "irop_t.h"
36
37 #include "be_types.h"
38 #include "beinfo.h"
39 #include "be.h"
40 #include "beirg.h"
41
42 typedef enum arch_register_class_flags_t {
43         arch_register_class_flag_none      = 0,
44         arch_register_class_flag_manual_ra = 1,  /**< don't do automatic register allocation for this class */
45         arch_register_class_flag_state     = 2
46 } arch_register_class_flags_t;
47
48 typedef enum arch_register_type_t {
49         arch_register_type_none         = 0,
50         arch_register_type_caller_save  = 1,  /**< The register must be saved by the caller
51                                                    upon a function call. It thus can be overwritten
52                                                    in the called function. */
53         arch_register_type_callee_save  = 2,  /**< The register must be saved by the caller
54                                                    upon a function call. It thus can be overwritten
55                                                    in the called function. */
56         arch_register_type_ignore       = 4,  /**< Do not consider this register when allocating. */
57         arch_register_type_joker        = 8,  /**< The emitter can choose an arbitrary register */
58         arch_register_type_virtual      = 16, /**< This is just a virtual register.Virtual registers have
59                                                    nearly no constraints, it is a allowed to have multiple
60                                                    definition for the same register at a point) */
61         arch_register_type_state        = 32, /**< The register represents a state that should be handled by
62                                                    bestate code */
63 } arch_register_type_t;
64
65 /**
66  * Different types of register allocation requirements.
67  */
68 typedef enum arch_register_req_type_t {
69         arch_register_req_type_none              = 0, /**< No register requirement. */
70         arch_register_req_type_normal            = 1U << 0, /**< All registers in the class are allowed. */
71         arch_register_req_type_limited           = 1U << 1, /**< Only a real subset of the class is allowed. */
72         arch_register_req_type_should_be_same    = 1U << 2, /**< The register should be equal to another one at the node. */
73         arch_register_req_type_must_be_different = 1U << 3, /**< The register must be unequal from some other at the node. */
74         arch_register_req_type_ignore            = 1U << 4, /**< ignore while allocating registers */
75         arch_register_req_type_produces_sp       = 1U << 5, /**< the output produces a new value for the stack pointer */
76 } arch_register_req_type_t;
77
78 extern const arch_register_req_t *arch_no_register_req;
79
80 /**
81  * Print information about a register requirement in human readable form
82  * @param F   output stream/file
83  * @param req The requirements structure to format.
84  */
85 void arch_dump_register_req(FILE *F, const arch_register_req_t *req,
86                             const ir_node *node);
87
88 /**
89  * Node classification. Mainly used for statistics.
90  */
91 typedef enum arch_irn_class_t {
92         arch_irn_class_spill  = 1 << 0,
93         arch_irn_class_reload = 1 << 1,
94         arch_irn_class_remat  = 1 << 2,
95         arch_irn_class_copy   = 1 << 3,
96         arch_irn_class_perm   = 1 << 4
97 } arch_irn_class_t;
98
99 void arch_set_frame_offset(ir_node *irn, int bias);
100
101 ir_entity *arch_get_frame_entity(const ir_node *irn);
102 void       arch_set_frame_entity(ir_node *irn, ir_entity *ent);
103 int        arch_get_sp_bias(ir_node *irn);
104
105 int             arch_get_op_estimated_cost(const ir_node *irn);
106 arch_inverse_t *arch_get_inverse(const ir_node *irn, int i, arch_inverse_t *inverse, struct obstack *obstack);
107 int             arch_possible_memory_operand(const ir_node *irn, unsigned int i);
108 void            arch_perform_memory_operand(ir_node *irn, ir_node *spill, unsigned int i);
109
110 /**
111  * Get the register requirements for a node.
112  * @note Deprecated API! Preferably use
113  *       arch_get_in_register_req and
114  *       arch_get_out_register_req.
115  *
116  * @param irn The node.
117  * @param pos The position of the operand you're interested in.
118  * @return    A pointer to the register requirements.  If NULL is returned, the
119  *            operand was no register operand.
120  */
121 const arch_register_req_t *arch_get_register_req(const ir_node *irn, int pos);
122
123 /**
124  * Put all registers which shall not be ignored by the register
125  * allocator in a bit set.
126  * @param cls The register class to consider.
127  * @param bs  The bit set to put the registers to.
128  */
129 extern void arch_put_non_ignore_regs(const arch_register_class_t *cls, bitset_t *bs);
130
131 /**
132  * Check, if a register is assignable to an operand of a node.
133  * @param irn The node.
134  * @param pos The position of the operand.
135  * @param reg The register.
136  * @return    1, if the register might be allocated to the operand 0 if not.
137  */
138 int arch_reg_is_allocatable(const ir_node *irn, int pos, const arch_register_t *reg);
139
140 #define arch_reg_out_is_allocatable(irn, reg) arch_reg_is_allocatable(irn, -1, reg)
141
142 /**
143  * Get the register class of an operand of a node.
144  * @param irn The node.
145  * @param pos The position of the operand, -1 for the output.
146  * @return    The register class of the operand or NULL, if
147  *            operand is a non-register operand.
148  */
149 const arch_register_class_t *arch_get_irn_reg_class(const ir_node *irn, int pos);
150
151 #define arch_get_irn_reg_class_out(irn) arch_get_irn_reg_class(irn, -1)
152
153 /**
154  * Get the register allocated at a certain output operand of a node.
155  * @param irn The node.
156  * @return    The register allocated for this operand
157  */
158 const arch_register_t *arch_get_irn_register(const ir_node *irn);
159 const arch_register_t *arch_irn_get_register(const ir_node *irn, int pos);
160
161 /**
162  * Set the register for a certain output operand.
163  * @param irn The node.
164  * @param reg The register.
165  */
166 void arch_set_irn_register(ir_node *irn, const arch_register_t *reg);
167 void arch_irn_set_register(ir_node *irn, int pos, const arch_register_t *reg);
168
169 /**
170  * Classify a node.
171  * @param irn The node.
172  * @return A classification of the node.
173  */
174 arch_irn_class_t arch_irn_classify(const ir_node *irn);
175
176 #define arch_irn_class_is(irn, irn_class) ((arch_irn_classify(irn) & arch_irn_class_ ## irn_class) != 0)
177
178 /**
179  * Get the flags of a node.
180  * @param irn The node.
181  * @return The flags.
182  */
183 arch_irn_flags_t arch_irn_get_flags(const ir_node *irn);
184
185 void arch_irn_set_flags(ir_node *node, arch_irn_flags_t flags);
186 void arch_irn_add_flags(ir_node *node, arch_irn_flags_t flags);
187
188 #define arch_irn_is(irn, flag) ((arch_irn_get_flags(irn) & arch_irn_flags_ ## flag) != 0)
189
190 /**
191  * Get the operations of an irn.
192  * @param self The handler from which the method is invoked.
193  * @param irn Some node.
194  * @return Operations for that irn.
195  */
196 typedef const void *(arch_get_irn_ops_t)(const ir_node *irn);
197
198 /**
199  * Initialize the architecture environment struct.
200  * @param isa           The isa which shall be put into the environment.
201  * @param file_handle   The file handle
202  * @return The environment.
203  */
204 extern arch_env_t *arch_env_init(const arch_isa_if_t *isa,
205                                  FILE *file_handle, be_main_env_t *main_env);
206
207 /**
208  * Register an instruction set architecture
209  */
210 void be_register_isa_if(const char *name, const arch_isa_if_t *isa);
211
212 /**
213  * A register.
214  */
215 struct arch_register_t {
216         const char                  *name;        /**< The name of the register. */
217         const arch_register_class_t *reg_class;   /**< The class the register belongs to. */
218         unsigned                     index;       /**< The index of the register in the class. */
219         arch_register_type_t         type;        /**< The type of the register. */
220         const arch_register_req_t   *single_req;
221 };
222
223 static inline const arch_register_class_t *
224 _arch_register_get_class(const arch_register_t *reg)
225 {
226         return reg->reg_class;
227 }
228
229 static inline
230 unsigned _arch_register_get_index(const arch_register_t *reg)
231 {
232         return reg->index;
233 }
234
235 static inline
236 const char *_arch_register_get_name(const arch_register_t *reg)
237 {
238         return reg->name;
239 }
240
241 #define arch_register_get_class(reg)        _arch_register_get_class(reg)
242 #define arch_register_get_index(reg)        _arch_register_get_index(reg)
243 #define arch_register_get_name(reg)         _arch_register_get_name(reg)
244
245 /**
246  * Convenience macro to check for register type.
247  * @param req   A pointer to register.
248  * @param kind  The kind of type to check for (see arch_register_type_t).
249  * @return      1, If register is of given kind, 0 if not.
250  */
251 #define arch_register_type_is(reg, kind) \
252   (((reg)->type & arch_register_type_ ## kind) != 0)
253
254 /**
255  * A class of registers.
256  * Like general purpose or floating point.
257  */
258 struct arch_register_class_t {
259         unsigned                     index;   /**< index of this register class */
260         const char                  *name;    /**< The name of the register class.*/
261         unsigned                     n_regs;  /**< Number of registers in this
262                                                    class. */
263         ir_mode                     *mode;    /**< The mode of the register class.*/
264         const arch_register_t       *regs;    /**< The array of registers. */
265         arch_register_class_flags_t  flags;   /**< register class flags. */
266         const arch_register_req_t   *class_req;
267 };
268
269 /** return the number of registers in this register class */
270 #define arch_register_class_n_regs(cls) ((cls)->n_regs)
271
272 /** return the largest mode of this register class */
273 #define arch_register_class_mode(cls) ((cls)->mode)
274
275 /** return the name of this register class */
276 #define arch_register_class_name(cls) ((cls)->name)
277
278 /** return the index of this register class */
279 #define arch_register_class_index(cls)  ((cls)->index)
280
281 /** return the register class flags */
282 #define arch_register_class_flags(cls) ((cls)->flags)
283
284 static inline const arch_register_t *
285 _arch_register_for_index(const arch_register_class_t *cls, unsigned idx)
286 {
287         assert(idx < cls->n_regs);
288         return &cls->regs[idx];
289 }
290
291 #define arch_register_for_index(cls, idx)   _arch_register_for_index(cls, idx)
292
293 /**
294  * Convenience macro to check for set constraints.
295  * @param req   A pointer to register requirements.
296  * @param kind  The kind of constraint to check for (see arch_register_req_type_t).
297  * @return      1, If the kind of constraint is present, 0 if not.
298  */
299 #define arch_register_req_is(req, kind) \
300         (((req)->type & (arch_register_req_type_ ## kind)) != 0)
301
302 /**
303  * Expresses requirements to register allocation for an operand.
304  */
305 struct arch_register_req_t {
306         arch_register_req_type_t     type;  /**< The type of the constraint. */
307         const arch_register_class_t *cls;   /**< The register class this constraint belongs to. */
308
309         const unsigned *limited;            /**< allowed register bitset */
310
311         unsigned other_same;                /**< Bitmask of ins which should use the
312                                                  same register (should_be_same). */
313         unsigned other_different;           /**< Bitmask of ins which shall use a
314                                                  different register
315                                                  (must_be_different) */
316 };
317
318 static inline int reg_reqs_equal(const arch_register_req_t *req1,
319                                  const arch_register_req_t *req2)
320 {
321         if (req1 == req2)
322                 return 1;
323
324         if (req1->type != req2->type
325                         || req1->cls != req2->cls
326                         || req1->other_same != req2->other_same
327                         || req1->other_different != req2->other_different)
328                 return 0;
329
330         if (req1->limited != NULL) {
331                 size_t n_regs;
332
333                 if (req2->limited == NULL)
334                         return 0;
335
336                 n_regs = arch_register_class_n_regs(req1->cls);
337                 if (!rbitset_equal(req1->limited, req2->limited, n_regs))
338                         return 0;
339         }
340
341         return 1;
342 }
343
344 /**
345  * An inverse operation returned by the backend
346  */
347 struct arch_inverse_t {
348         int      n;       /**< count of nodes returned in nodes array */
349         int      costs;   /**< costs of this remat */
350
351         /**< nodes for this inverse operation. shall be in
352          *  schedule order. last element is the target value
353          */
354         ir_node  **nodes;
355 };
356
357 struct arch_irn_ops_t {
358
359         /**
360          * Get the register requirements for a given operand.
361          * @param irn The node.
362          * @param pos The operand's position
363          * @return    The register requirements for the selected operand.
364          *            The pointer returned is never NULL.
365          */
366         const arch_register_req_t *(*get_irn_reg_req_in)(const ir_node *irn, int pos);
367
368         /**
369          * Get the register requirements for values produced by a node
370          * @param irn The node.
371          * @param pos The operand's position (0 for most nodes,
372          *                                    0..n for mode_T nodes)
373          * @return    The register requirements for the selected operand.
374          *            The pointer returned is never NULL.
375          */
376         const arch_register_req_t *(*get_irn_reg_req_out)(const ir_node *irn, int pos);
377
378         /**
379          * Classify the node.
380          * @param irn The node.
381          * @return A classification.
382          */
383         arch_irn_class_t (*classify)(const ir_node *irn);
384
385         /**
386          * Get the entity on the stack frame this node depends on.
387          * @param irn  The node in question.
388          * @return The entity on the stack frame or NULL, if the node does not have a
389          *         stack frame entity.
390          */
391         ir_entity *(*get_frame_entity)(const ir_node *irn);
392
393         /**
394          * Set the entity on the stack frame this node depends on.
395          * @param irn  The node in question.
396          * @param ent  The entity to set
397          */
398         void (*set_frame_entity)(ir_node *irn, ir_entity *ent);
399
400         /**
401          * Set the offset of a node carrying an entity on the stack frame.
402          * @param irn  The node.
403          * @param offset The offset of the node's stack frame entity.
404          */
405         void (*set_frame_offset)(ir_node *irn, int offset);
406
407         /**
408          * Returns the delta of the stackpointer for nodes that increment or
409          * decrement the stackpointer with a constant value. (push, pop
410          * nodes on most architectures).
411          * A positive value stands for an expanding stack area, a negative value for
412          * a shrinking one.
413          *
414          * @param irn       The node
415          * @return          0 if the stackpointer is not modified with a constant
416          *                  value, otherwise the increment/decrement value
417          */
418         int (*get_sp_bias)(const ir_node *irn);
419
420         /**
421          * Returns an inverse operation which yields the i-th argument
422          * of the given node as result.
423          *
424          * @param irn       The original operation
425          * @param i         Index of the argument we want the inverse operation to yield
426          * @param inverse   struct to be filled with the resulting inverse op
427          * @param obstack   The obstack to use for allocation of the returned nodes array
428          * @return          The inverse operation or NULL if operation invertible
429          */
430         arch_inverse_t *(*get_inverse)(const ir_node *irn, int i, arch_inverse_t *inverse, struct obstack *obstack);
431
432         /**
433          * Get the estimated cycle count for @p irn.
434          *
435          * @param irn  The node.
436          *
437          * @return     The estimated cycle count for this operation
438          */
439         int (*get_op_estimated_cost)(const ir_node *irn);
440
441         /**
442          * Asks the backend whether operand @p i of @p irn can be loaded form memory internally
443          *
444          * @param irn  The node.
445          * @param i    Index of the argument we would like to know whether @p irn can load it form memory internally
446          *
447          * @return     nonzero if argument can be loaded or zero otherwise
448          */
449         int (*possible_memory_operand)(const ir_node *irn, unsigned int i);
450
451         /**
452          * Ask the backend to assimilate @p reload of operand @p i into @p irn.
453          *
454          * @param irn    The node.
455          * @param spill  The spill.
456          * @param i      The position of the reload.
457          */
458         void (*perform_memory_operand)(ir_node *irn, ir_node *spill, unsigned int i);
459 };
460
461 /**
462  * The code generator interface.
463  */
464 struct arch_code_generator_if_t {
465         /**
466          * Initialize the code generator.
467          * @param birg A backend IRG session.
468          * @return     A newly created code generator.
469          */
470         void *(*init)(be_irg_t *birg);
471
472         /**
473          * return node used as base in pic code addresses
474          */
475         ir_node* (*get_pic_base)(void *self);
476
477         /**
478          * Called before abi introduce.
479          */
480         void (*before_abi)(void *self);
481
482         /**
483          * Called, when the graph is being normalized.
484          */
485         void (*prepare_graph)(void *self);
486
487         /**
488          * Backend may provide an own spiller.
489          * This spiller needs to spill all register classes.
490          */
491         void (*spill)(void *self, be_irg_t *birg);
492
493         /**
494          * Called before register allocation.
495          */
496         void (*before_ra)(void *self);
497
498         /**
499          * Called after register allocation.
500          */
501         void (*after_ra)(void *self);
502
503         /**
504          * Called directly before done is called. This should be the last place
505          * where the irg is modified.
506          */
507         void (*finish)(void *self);
508
509         /**
510          * Called after everything happened. This call should emit the final
511          * assembly code but avoid changing the irg.
512          * The code generator must also be de-allocated here.
513          */
514         void (*done)(void *self);
515 };
516
517 /**
518  * helper macro: call function func from the code generator
519  * if it's implemented.
520  */
521 #define _arch_cg_call(cg, func) \
522 do { \
523         if((cg)->impl->func) \
524                 (cg)->impl->func(cg); \
525 } while(0)
526
527 #define _arch_cg_call_env(cg, env, func) \
528 do { \
529         if((cg)->impl->func) \
530                 (cg)->impl->func(cg, env); \
531 } while(0)
532
533 #define arch_code_generator_before_abi(cg)      _arch_cg_call(cg, before_abi)
534 #define arch_code_generator_prepare_graph(cg)   _arch_cg_call(cg, prepare_graph)
535 #define arch_code_generator_before_ra(cg)       _arch_cg_call(cg, before_ra)
536 #define arch_code_generator_after_ra(cg)        _arch_cg_call(cg, after_ra)
537 #define arch_code_generator_finish(cg)          _arch_cg_call(cg, finish)
538 #define arch_code_generator_done(cg)            _arch_cg_call(cg, done)
539 #define arch_code_generator_spill(cg, birg)     _arch_cg_call_env(cg, birg, spill)
540 #define arch_code_generator_has_spiller(cg)     ((cg)->impl->spill != NULL)
541 #define arch_code_generator_get_pic_base(cg)    \
542         ((cg)->impl->get_pic_base != NULL ? (cg)->impl->get_pic_base(cg) : NULL)
543
544 /**
545  * Code generator base class.
546  */
547 struct arch_code_generator_t {
548         const arch_code_generator_if_t *impl;
549 };
550
551 /**
552  * Architecture interface.
553  */
554 struct arch_isa_if_t {
555         /**
556          * Initialize the isa interface.
557          * @param file_handle  the file handle to write the output to
558          * @return a new isa instance
559          */
560         arch_env_t *(*init)(FILE *file_handle);
561
562         /**
563          * Free the isa instance.
564          */
565         void (*done)(void *self);
566
567         /**
568          * Called directly after initialization. Backend should handle all
569          * intrinsics here.
570          */
571         void (*handle_intrinsics)(void);
572
573         /**
574          * Get the the number of register classes in the isa.
575          * @return The number of register classes.
576          */
577         unsigned (*get_n_reg_class)(void);
578
579         /**
580          * Get the i-th register class.
581          * @param i The number of the register class.
582          * @return The register class.
583          */
584         const arch_register_class_t *(*get_reg_class)(unsigned i);
585
586         /**
587          * Get the register class which shall be used to store a value of a given mode.
588          * @param self The this pointer.
589          * @param mode The mode in question.
590          * @return A register class which can hold values of the given mode.
591          */
592         const arch_register_class_t *(*get_reg_class_for_mode)(const ir_mode *mode);
593
594         /**
595          * Get the ABI restrictions for procedure calls.
596          * @param self        The this pointer.
597          * @param call_type   The call type of the method (procedure) in question.
598          * @param p           The array of parameter locations to be filled.
599          */
600         void (*get_call_abi)(const void *self, ir_type *call_type, be_abi_call_t *abi);
601
602         /**
603          * Get the code generator interface.
604          * @param self The this pointer.
605          * @return     Some code generator interface.
606          */
607         const arch_code_generator_if_t *(*get_code_generator_if)(void *self);
608
609         /**
610          * Get the list scheduler to use. There is already a selector given, the
611          * backend is free to modify and/or ignore it.
612          *
613          * @param self     The isa object.
614          * @param selector The selector given by options.
615          * @return         The list scheduler selector.
616          */
617         const list_sched_selector_t *(*get_list_sched_selector)(const void *self, list_sched_selector_t *selector);
618
619         /**
620          * Get the ILP scheduler to use.
621          * @param self  The isa object.
622          * @return      The ILP scheduler selector
623          */
624         const ilp_sched_selector_t *(*get_ilp_sched_selector)(const void *self);
625
626         /**
627          * Get the necessary alignment for storing a register of given class.
628          * @param self  The isa object.
629          * @param cls   The register class.
630          * @return      The alignment in bytes.
631          */
632         int (*get_reg_class_alignment)(const arch_register_class_t *cls);
633
634         /**
635          * A "static" function, returns the frontend settings
636          * needed for this backend.
637          */
638         const backend_params *(*get_params)(void);
639
640         /**
641          * Returns an 2-dim array of execution units, @p irn can be executed on.
642          * The first dimension is the type, the second the allowed units of this
643          * type.
644          * Each dimension is a NULL terminated list.
645          * @param self  The isa object.
646          * @param irn   The node.
647          * @return An array of allowed execution units.
648          *         exec_unit = {
649          *                       { unit1_of_tp1, ..., unitX1_of_tp1, NULL },
650          *                       ...,
651          *                       { unit1_of_tpY, ..., unitXn_of_tpY, NULL },
652          *                       NULL
653          *                     };
654          */
655         const be_execution_unit_t ***(*get_allowed_execution_units)(const ir_node *irn);
656
657         /**
658          * Return the abstract machine for this isa.
659          * @param self  The isa object.
660          */
661         const be_machine_t *(*get_machine)(const void *self);
662
663         /**
664          * Return an ordered list of irgs where code should be generated for.
665          * If NULL is returned, all irg will be taken into account and they will be
666          * generated in an arbitrary order.
667          * @param self   The isa object.
668          * @param irgs   A flexible array ARR_F of length 0 where the backend can append the desired irgs.
669          * @return A flexible array ARR_F containing all desired irgs in the desired order.
670          */
671         ir_graph **(*get_backend_irg_list)(const void *self, ir_graph ***irgs);
672
673         /**
674          * mark node as rematerialized
675          */
676         void (*mark_remat)(ir_node *node);
677
678         /**
679          * parse an assembler constraint part and set flags according to its nature
680          * advances the *c pointer to point to the last parsed character (so if you
681          * parse a single character don't advance c)
682          */
683         asm_constraint_flags_t (*parse_asm_constraint)(const char **c);
684
685         /**
686          * returns true if the string is a valid clobbered (register) in this
687          * backend
688          */
689         int (*is_valid_clobber)(const char *clobber);
690 };
691
692 #define arch_env_done(env)                             ((env)->impl->done(env))
693 #define arch_env_handle_intrinsics(env)                \
694         do { if((env)->impl->handle_intrinsics != NULL) (env)->impl->handle_intrinsics(); } while(0)
695 #define arch_env_get_n_reg_class(env)                  ((env)->impl->get_n_reg_class())
696 #define arch_env_get_reg_class(env,i)                  ((env)->impl->get_reg_class(i))
697 #define arch_env_get_reg_class_for_mode(env,mode)      ((env)->impl->get_reg_class_for_mode((mode)))
698 #define arch_env_get_call_abi(env,tp,abi)              ((env)->impl->get_call_abi((env), (tp), (abi)))
699 #define arch_env_get_code_generator_if(env)            ((env)->impl->get_code_generator_if((env)))
700 #define arch_env_get_list_sched_selector(env,selector) ((env)->impl->get_list_sched_selector((env), (selector)))
701 #define arch_env_get_ilp_sched_selector(env)           ((env)->impl->get_ilp_sched_selector(env))
702 #define arch_env_get_reg_class_alignment(env,cls)      ((env)->impl->get_reg_class_alignment((cls)))
703 #define arch_env_get_params(env)                       ((env)->impl->get_params())
704 #define arch_env_get_allowed_execution_units(env,irn)  ((env)->impl->get_allowed_execution_units((irn)))
705 #define arch_env_get_machine(env)                      ((env)->impl->get_machine(env))
706 #define arch_env_get_backend_irg_list(env,irgs)        ((env)->impl->get_backend_irg_list((env), (irgs)))
707 #define arch_env_parse_asm_constraint(env,c)           ((env)->impl->parse_asm_constraint((c))
708 #define arch_env_is_valid_clobber(env,clobber)         ((env)->impl->is_valid_clobber((clobber))
709 #define arch_env_mark_remat(env,node) \
710         do { if ((env)->impl->mark_remat != NULL) (env)->impl->mark_remat((node)); } while(0)
711
712 /**
713  * ISA base class.
714  */
715 struct arch_env_t {
716         const arch_isa_if_t   *impl;
717         const arch_register_t *sp;               /** The stack pointer register. */
718         const arch_register_t *bp;               /** The base pointer register. */
719         const arch_register_class_t *link_class; /** The static link pointer register class. */
720         int                    stack_dir;        /** -1 for decreasing, 1 for increasing. */
721         int                    stack_alignment;  /** power of 2 stack alignment */
722         const be_main_env_t   *main_env;         /** the be main environment */
723         int                    spill_cost;       /** cost for a be_Spill node */
724         int                    reload_cost;      /** cost for a be_Reload node */
725 };
726
727 static inline unsigned arch_irn_get_n_outs(const ir_node *node)
728 {
729         backend_info_t *info = be_get_info(node);
730         if (info->out_infos == NULL)
731                 return 0;
732
733         return ARR_LEN(info->out_infos);
734 }
735
736 static inline const arch_irn_ops_t *get_irn_ops_simple(const ir_node *node)
737 {
738         const ir_op          *ops    = get_irn_op(node);
739         const arch_irn_ops_t *be_ops = get_op_ops(ops)->be_ops;
740         assert(!is_Proj(node));
741         return be_ops;
742 }
743
744 static inline const arch_register_req_t *arch_get_register_req_out(
745                 const ir_node *irn)
746 {
747         int                   pos = 0;
748         const arch_irn_ops_t *ops;
749
750         if (is_Proj(irn)) {
751                 pos = get_Proj_proj(irn);
752                 irn = get_Proj_pred(irn);
753         } else if (get_irn_mode(irn) == mode_T) {
754                 return arch_no_register_req;
755         }
756         ops = get_irn_ops_simple(irn);
757         return ops->get_irn_reg_req_out(irn, pos);
758 }
759
760 static inline bool arch_irn_is_ignore(const ir_node *irn)
761 {
762         const arch_register_req_t *req = arch_get_register_req_out(irn);
763         return !!(req->type & arch_register_req_type_ignore);
764 }
765
766 static inline bool arch_irn_consider_in_reg_alloc(
767                 const arch_register_class_t *cls, const ir_node *node)
768 {
769         const arch_register_req_t *req = arch_get_register_req_out(node);
770         return
771                 req->cls == cls &&
772                 !(req->type & arch_register_req_type_ignore);
773 }
774
775 /**
776  * Get register constraints for an operand at position @p
777  */
778 static inline const arch_register_req_t *arch_get_in_register_req(
779                 const ir_node *node, int pos)
780 {
781         const arch_irn_ops_t *ops = get_irn_ops_simple(node);
782         return ops->get_irn_reg_req_in(node, pos);
783 }
784
785 /**
786  * Get register constraint for a produced result (the @p pos result)
787  */
788 static inline const arch_register_req_t *arch_get_out_register_req(
789                 const ir_node *node, int pos)
790 {
791         const arch_irn_ops_t *ops = get_irn_ops_simple(node);
792         return ops->get_irn_reg_req_out(node, pos);
793 }
794
795 #endif /* FIRM_BE_BEARCH_H */