added nolea option to switch of LEA optimization
[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_gp_regs[REG_R0],
19         &arm_gp_regs[REG_R1],
20         &arm_gp_regs[REG_R2],
21         &arm_gp_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 proj number into a "real" argument position for register
68  * requirements depended 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_irn_machine_op(pred)) {
75                 switch (get_arm_irn_opcode(pred)) {
76
77                 case iro_arm_Loadb:
78                 case iro_arm_Loadbs:
79                 case iro_arm_Loadh:
80                 case iro_arm_Loadhs:
81                 case iro_arm_Load:
82                 case iro_arm_fpaLdf:
83                         if (nr == pn_Load_res)
84                                 return 0;
85                         assert(0 && "unsupported Proj(Load) number");
86                         break;
87                 case iro_arm_Storeb:
88                 case iro_arm_Storebs:
89                 case iro_arm_Storeh:
90                 case iro_arm_Storehs:
91                 case iro_arm_Store:
92                 case iro_arm_fpaStf:
93                         return 0;
94                 case iro_arm_fpaDiv:
95                 case iro_arm_fpaRdv:
96                         if (nr == pn_Quot_res)
97                                 return 0;
98                         assert(0 && "there should be no more Projs for a fDiv");
99                         break;
100                 default:
101                         break;
102                 }
103         }
104
105 //      assert(0 && "unsupported Proj(X)");
106         return nr;
107 }