fixed indents
[libfirm] / ir / be / ia32 / ia32_map_regs.c
1 /**
2  * Register mapping for firm nodes. Stolen from bearch_firm :)
3  * $Id$
4  */
5
6 #include <stdlib.h>
7
8 #include "ia32_map_regs.h"
9 #include "ia32_new_nodes.h"
10
11 struct irn_reg_assoc {
12         const ir_node *irn;
13         const arch_register_t *reg;
14 };
15
16 int cmp_irn_reg_assoc(const void *a, const void *b, size_t len) {
17         const struct irn_reg_assoc *x = a;
18         const struct irn_reg_assoc *y = b;
19
20         return !(x->irn == y->irn);
21 }
22
23 static struct irn_reg_assoc *get_irn_reg_assoc(const ir_node *irn, set *reg_set) {
24         struct irn_reg_assoc templ;
25         unsigned int hash;
26
27         templ.irn = irn;
28         templ.reg = NULL;
29         hash = HASH_PTR(irn);
30
31         return set_insert(reg_set, &templ, sizeof(templ), hash);
32 }
33
34 void ia32_set_firm_reg(const arch_irn_ops_t *self, ir_node *irn,
35     const arch_register_t *reg, set *reg_set)
36 {
37         struct irn_reg_assoc *assoc = get_irn_reg_assoc(irn, reg_set);
38         assoc->reg = reg;
39 }
40
41 const arch_register_t *ia32_get_firm_reg(const arch_irn_ops_t *self,
42     const ir_node *irn, set *reg_set)
43 {
44         struct irn_reg_assoc *assoc = get_irn_reg_assoc(irn, reg_set);
45         return assoc->reg;
46 }
47
48
49 /**
50  * Translates the projnum into a "real" argument position for register
51  * requirements dependend on the predecessor.
52  */
53 long translate_proj_pos(const ir_node *proj) {
54         ir_node *first;
55         ir_node *pred = get_Proj_pred(proj);
56         long nr       = get_Proj_proj(proj);
57
58         if (is_ia32_Load(pred)) {
59                 if (nr == pn_Load_res)
60                         return 0;
61                 assert(0 && "unsupported Proj(Load) number");
62         }
63         else if (is_ia32_Store(pred)) {
64                 return 0;
65         }
66         else if (is_ia32_CondJmp(pred) || is_ia32_CondJmp_i(pred)) {
67                 return 0;
68         }
69         else if (is_ia32_SwitchJmp(pred)) {
70                 return 0;
71         }
72         else if (is_ia32_Cltd(pred)) {
73                 if (nr == pn_EAX)
74                         return 0;
75                 if (nr == pn_EDX)
76                         return 1;
77         }
78         else if (is_ia32_DivMod(pred)) {
79                 if (nr == pn_DivMod_res_div || pn_Div_res)
80                         return 0;
81                 if (nr == pn_DivMod_res_mod || pn_Mod_res)
82                         return 1;
83         }
84         else if (is_ia32_Call(pred)) {
85                 return 0;
86         }
87         else if (get_irn_mode(proj) == mode_X && nr == pn_Start_X_initial_exec) {
88                 return 0;
89         }
90         else if (is_Proj(pred)) {
91 //              return nr + translate_proj_pos(pred);
92                 first = get_Proj_pred(pred);
93
94                 if (is_ia32_Call(first))
95                         return 0;
96
97                 assert(0 && "unsupported proj-pos translation Proj(Proj)");
98                 return -1;
99         }
100         else if (get_irn_opcode(pred) == iro_Start) {
101                 return nr;
102         }
103
104         assert(0 && "unsupported Proj(X)");
105         return -1;
106 }