38716632996144de47d661f1082142ebbddbca50
[libfirm] / ir / be / arm / arm_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 "arm_map_regs.h"
12 #include "arm_new_nodes.h"
13
14 #include "gen_arm_regalloc_if.h"
15
16
17 static const arch_register_t *gpreg_param_reg_std[] = {
18         &arm_general_purpose_regs[REG_R0],
19         &arm_general_purpose_regs[REG_R1],
20         &arm_general_purpose_regs[REG_R2],
21         &arm_general_purpose_regs[REG_R3],
22 };
23
24 const arch_register_t *arm_get_RegParam_reg(int n) {
25         assert(n < 4 && n >=0 && "register param > 3 angefordert");
26         return gpreg_param_reg_std[n];
27 }
28
29 /* Mapping to store registers in firm nodes */
30
31 struct arm_irn_reg_assoc {
32         const ir_node *irn;
33         const arch_register_t *reg;
34 };
35
36 int arm_cmp_irn_reg_assoc(const void *a, const void *b, size_t len) {
37         const struct arm_irn_reg_assoc *x = a;
38         const struct arm_irn_reg_assoc *y = b;
39
40         return x->irn != y->irn;
41 }
42
43 static struct arm_irn_reg_assoc *get_irn_reg_assoc(const ir_node *irn, set *reg_set) {
44         struct arm_irn_reg_assoc templ;
45         unsigned int hash;
46
47         templ.irn = irn;
48         templ.reg = NULL;
49         hash = HASH_PTR(irn);
50
51         return set_insert(reg_set, &templ, sizeof(templ), hash);
52 }
53
54 void arm_set_firm_reg(ir_node *irn, const arch_register_t *reg, set *reg_set) {
55         struct arm_irn_reg_assoc *assoc = get_irn_reg_assoc(irn, reg_set);
56         assoc->reg = reg;
57 }
58
59 const arch_register_t *arm_get_firm_reg(const ir_node *irn, set *reg_set) {
60         struct arm_irn_reg_assoc *assoc = get_irn_reg_assoc(irn, reg_set);
61         return assoc->reg;
62 }
63
64
65
66 /**
67  * Translates the projnum into a "real" argument position for register
68  * requirements dependend on the predecessor.
69  */
70 long arm_translate_proj_pos(const ir_node *proj) {
71         ir_node *pred = get_Proj_pred(proj);
72         long nr       = get_Proj_proj(proj);
73
74         if (is_arm_Load(pred) || is_arm_fLoadd(pred) || is_arm_fLoads(pred)) {
75                 if (nr == pn_Load_res)
76                         return 0;
77                 assert(0 && "unsupported Proj(Load) number");
78         }
79         else if (is_arm_Store(pred) || is_arm_fStores(pred) || is_arm_fStored(pred)) {
80                 return 0;
81         }
82         else if (is_arm_fDiv(pred)) {
83                 if (nr == pn_Quot_res)
84                         return 0;
85                 else
86                         assert(0 && "there should be no more Projs for a fDiv");
87         }
88
89 //      assert(0 && "unsupported Proj(X)");
90         return nr;
91 }