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