wrapped debugging modules with DEBUG_ONLY
[libfirm] / ir / be / TEMPLATE / TEMPLATE_map_regs.c
1 /**
2  * Register mapping for firm nodes. Stolen from bearch_firm :)
3  * $Id$
4  */
5 #ifdef HAVE_CONFIG_H
6 #include "config.h"
7 #endif
8
9 #include <stdlib.h>
10
11 #include "TEMPLATE_map_regs.h"
12 #include "TEMPLATE_new_nodes.h"
13
14 /* Mapping to store registers in firm nodes */
15
16 struct TEMPLATE_irn_reg_assoc {
17         const ir_node *irn;
18         const arch_register_t *reg;
19 };
20
21 int TEMPLATE_cmp_irn_reg_assoc(const void *a, const void *b, size_t len) {
22         const struct TEMPLATE_irn_reg_assoc *x = a;
23         const struct TEMPLATE_irn_reg_assoc *y = b;
24
25         return x->irn != y->irn;
26 }
27
28 static struct TEMPLATE_irn_reg_assoc *get_irn_reg_assoc(const ir_node *irn, set *reg_set) {
29         struct TEMPLATE_irn_reg_assoc templ;
30         unsigned int hash;
31
32         templ.irn = irn;
33         templ.reg = NULL;
34         hash = HASH_PTR(irn);
35
36         return set_insert(reg_set, &templ, sizeof(templ), hash);
37 }
38
39 void TEMPLATE_set_firm_reg(ir_node *irn, const arch_register_t *reg, set *reg_set) {
40         struct TEMPLATE_irn_reg_assoc *assoc = get_irn_reg_assoc(irn, reg_set);
41         assoc->reg = reg;
42 }
43
44 const arch_register_t *TEMPLATE_get_firm_reg(const ir_node *irn, set *reg_set) {
45         struct TEMPLATE_irn_reg_assoc *assoc = get_irn_reg_assoc(irn, reg_set);
46         return assoc->reg;
47 }
48
49
50
51 /**
52  * Translates the projnum into a "real" argument position for register
53  * requirements dependend on the predecessor.
54  */
55 long TEMPLATE_translate_proj_pos(const ir_node *proj) {
56         ir_node *pred = get_Proj_pred(proj);
57         long nr       = get_Proj_proj(proj);
58
59         if (is_TEMPLATE_Load(pred)) {
60                 if (nr == pn_Load_res)
61                         return 0;
62                 assert(0 && "unsupported Proj(Load) number");
63         }
64         else if (is_TEMPLATE_Store(pred)) {
65                 return 0;
66         }
67         else if (is_TEMPLATE_fDiv(pred)) {
68                 if (nr == pn_Quot_res)
69                         return 0;
70                 else
71                         assert(0 && "there should be no more Projs for a fDiv");
72         }
73
74 //      assert(0 && "unsupported Proj(X)");
75         return nr;
76 }