changed type for callback
[libfirm] / ir / be / ppc32 / ppc32_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 "ppc32_map_regs.h"
12 #include "ppc32_new_nodes.h"
13
14 /* Mapping to store registers in firm nodes */
15
16 struct ppc32_irn_reg_assoc {
17         const ir_node *irn;
18         const arch_register_t *reg;
19 };
20
21 int ppc32_cmp_irn_reg_assoc(const void *a, const void *b, size_t len) {
22         const struct ppc32_irn_reg_assoc *x = a;
23         const struct ppc32_irn_reg_assoc *y = b;
24
25         return x->irn != y->irn;
26 }
27
28 static struct ppc32_irn_reg_assoc *get_irn_reg_assoc(const ir_node *irn, set *reg_set) {
29         struct ppc32_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 ppc32_set_firm_reg(ir_node *irn, const arch_register_t *reg, set *reg_set) {
40         struct ppc32_irn_reg_assoc *assoc = get_irn_reg_assoc(irn, reg_set);
41         assoc->reg = reg;
42 }
43
44 const arch_register_t *ppc32_get_firm_reg(const ir_node *irn, set *reg_set) {
45         struct ppc32_irn_reg_assoc *assoc = get_irn_reg_assoc(irn, reg_set);
46         return assoc->reg;
47 }
48
49
50 int is_ppc32_Load(const ir_node *n)
51 {
52         ir_op *op = get_irn_op(n);
53         if(op == op_ppc32_Lbz) return 1;
54         if(op == op_ppc32_Lhz) return 1;
55         if(op == op_ppc32_Lha) return 1;
56         if(op == op_ppc32_Lwz) return 1;
57         if(op == op_ppc32_Lfd) return 1;
58         if(op == op_ppc32_Lfs) return 1;
59
60         return 0;
61 }
62
63 int is_ppc32_Store(const ir_node *n)
64 {
65         ir_op *op = get_irn_op(n);
66         if(op == op_ppc32_Stb) return 1;
67         if(op == op_ppc32_Sth) return 1;
68         if(op == op_ppc32_Stw) return 1;
69         if(op == op_ppc32_Stfd) return 1;
70         if(op == op_ppc32_Stfs) return 1;
71
72         return 0;
73 }
74
75
76 /**
77  * Translates the projnum into a "real" argument position for register
78  * requirements dependend on the predecessor.
79  */
80 long ppc32_translate_proj_pos(const ir_node *proj) {
81         ir_node *pred = get_Proj_pred(proj);
82         long nr       = get_Proj_proj(proj);
83
84
85         if (is_ppc32_Load(pred)) {
86                 if (nr == pn_Load_res)
87                         return 0;
88                 assert(0 && "unsupported Proj(Load) number");
89         }
90         else if (is_ppc32_Store(pred)) {
91                 return 0;
92         }
93         else if (is_ppc32_fDiv(pred)) {
94                 if (nr == pn_Quot_res)
95                         return 0;
96                 else
97                         assert(0 && "there should be no more Projs for a fDiv");
98         }
99         else if (is_ppc32_Divw(pred) || is_ppc32_Divwu(pred)) {
100                 if (nr == pn_DivMod_res_div)
101                         return 0;
102                 else
103                         assert(0 && "there should be no more Projs for a ppc32_Divw or ppc32_Divwu");
104         }
105
106         else if(is_ppc32_Cmp(pred))
107                 return 0;
108         else if(is_ppc32_Cmpi(pred))
109                 return 0;
110         else if(is_ppc32_Cmpl(pred))
111                 return 0;
112         else if(is_ppc32_Cmpli(pred))
113                 return 0;
114
115
116
117 //      assert(0 && "unsupported Proj(X)");
118         return nr;
119 }